* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Courier New', monospace;
  background: #0f1320;
  min-height: 100vh;
  padding: 8px;
  user-select: none;
  color: #fff;
  image-rendering: pixelated;
}
h1 {
  text-align: center;
  text-shadow: 3px 3px 0 #000, 4px 4px 0 #c8741a;
  margin-bottom: 6px;
  font-size: 24px;
  color: #f5b041;
  letter-spacing: 2px;
}
.hud {
  background: #1a1f33;
  border: 3px solid #c8741a;
  color: #f5b041;
  padding: 6px 16px;
  margin: 0 auto 8px;
  max-width: 700px;
  display: flex;
  gap: 25px;
  justify-content: center;
  font-size: 14px;
  font-weight: bold;
}

/* ===== ЗДАНИЕ ===== */
.building-wrapper {
  max-width: 900px;
  margin: 0 auto;
  background: #1a1f33;
  border: 4px solid #c8741a;
  box-shadow: 0 0 20px rgba(200,116,26,0.3);
  overflow-y: auto;
  overflow-x: hidden;
  height: 65vh;
  min-height: 480px;
}
.building-wrapper::-webkit-scrollbar { width: 10px; }
.building-wrapper::-webkit-scrollbar-track { background: #0f1320; }
.building-wrapper::-webkit-scrollbar-thumb { background: #c8741a; }

.building {
  position: relative;
  width: 100%;
  background: #1a1f33;
}

/* ===== ЭТАЖ ===== */
.floor {
  height: 70px;
  position: relative;
  display: flex;
}
.floor-num {
  width: 44px;
  background: #0f1320;
  color: #f5b041;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: bold;
  border-right: 2px solid #c8741a;
  flex-shrink: 0;
  z-index: 2;
}
.floor-corridor {
  flex: 1;
  position: relative;
}

/* ===== КИРПИЧНАЯ ПЛАТФОРМА ===== */
.brick-platform {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 22px;
  background:
    linear-gradient(180deg,
      #f5b041 0%, #f5b041 2px,
      transparent 2px, transparent 100%),
    repeating-linear-gradient(90deg,
      transparent 0 30px,
      rgba(0,0,0,0.5) 30px 32px),
    repeating-linear-gradient(0deg,
      #8b3a1a 0 10px,
      rgba(0,0,0,0.4) 10px 12px,
      #b8551f 12px 22px),
    linear-gradient(180deg, #c8741a 0%, #8b3a0e 100%);
  box-shadow:
    inset 0 2px 0 rgba(255,200,100,0.4),
    inset 0 -2px 0 rgba(0,0,0,0.5);
}
.brick-platform::before {
  content: '';
  position: absolute;
  left: 0; right: 0;
  top: 12px;
  height: 10px;
  background: repeating-linear-gradient(90deg,
    transparent 0 15px,
    rgba(0,0,0,0.5) 15px 17px,
    transparent 17px 30px);
  pointer-events: none;
}
.brick-platform::after {
  content: '';
  position: absolute;
  left: 0; right: 0;
  top: 0;
  height: 2px;
  background: repeating-linear-gradient(90deg,
    #ffd97a 0 4px,
    #f5b041 4px 30px);
}
.brick-platform.notch-left {
  left: -8px;
}

.floor.zero .floor-num {
  background: #f5b041;
  color: #000;
}

/* ===== ШАХТА ЛИФТА ===== */
.elevator-shaft {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 16px;
  width: 38px;
  background: #000;
  border-left: 3px solid #c8741a;
  border-right: 3px solid #c8741a;
  z-index: 1;
}

/* ===== КАБИНА ЛИФТА ===== */
.elevator {
  position: absolute;
  right: 19px;
  width: 32px;
  height: 50px;
  background:
    linear-gradient(180deg,
      #d8d8d8 0%,
      #a0a0a0 50%,
      #707070 100%);
  border: 2px solid #c8741a;
  box-shadow:
    inset 1px 1px 0 rgba(255,255,255,0.5),
    inset -1px -1px 0 rgba(0,0,0,0.5),
    0 0 8px rgba(200,116,26,0.6);
  z-index: 5;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  overflow: hidden;
}
.elevator::before {
  content: '';
  position: absolute;
  top: 2px;
  bottom: 2px;
  left: 2px;
  right: 2px;
  background: repeating-linear-gradient(0deg,
    rgba(0,0,0,0.25) 0 1px,
    transparent 1px 4px);
  pointer-events: none;
  z-index: 3;
}

.elevator-door {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  background: linear-gradient(180deg, #909090 0%, #555 100%);
  transition: transform 0.5s ease;
  z-index: 2;
}
.elevator-door.left { left: 0; }
.elevator-door.right { right: 0; }
.elevator.doors-open .elevator-door.left  { transform: translateX(-100%); }
.elevator.doors-open .elevator-door.right { transform: translateX(100%); }

.elevator-light {
  position: absolute;
  top: -3px;
  left: 50%;
  transform: translateX(-50%);
  width: 10px;
  height: 3px;
  background: #ff5252;
  box-shadow: 0 0 6px #ff5252;
  z-index: 4;
}
.elevator.moving .elevator-light {
  animation: blink 0.4s steps(1) infinite;
}
@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0.2; }
}

.elevator-passenger {
  position: relative;
  width: 18px;
  height: 26px;
  z-index: 1;
  margin-bottom: 2px;
  opacity: 0;
  transition: opacity 0.3s;
}
.elevator-passenger.show { opacity: 1; }

/* ===== ПАССАЖИР ===== */
.passenger {
  position: absolute;
  width: 26px;
  height: 36px;
  transition: left 2.8s linear, top 0.6s ease, opacity 0.3s;
  z-index: 4;
  image-rendering: pixelated;
}
.passenger.fast {
  transition: left 0.7s linear, top 0.6s ease, opacity 0.3s;
}
.pixel-person {
  position: relative;
  width: 100%;
  height: 100%;
}
.pixel-grid {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(11, 1fr);
}
.pixel-grid div { width: 100%; height: 100%; }

.px-skin   { background: #ffcc99; }
.px-hair   { background: var(--hair-color, #b71c1c); }
.px-eye    { background: #000; }
.px-shirt  { background: var(--shirt-color, #d32f2f); }
.px-pants  { background: #2c2c2c; }
.px-shoe   { background: #1a1a1a; }
.px-empty  { background: transparent; }

.passenger.walking .frame-1 { animation: f1 0.6s steps(1) infinite; }
.passenger.walking .frame-2 { animation: f2 0.6s steps(1) infinite; }
@keyframes f1 {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}
@keyframes f2 {
  0%, 49% { opacity: 0; }
  50%, 100% { opacity: 1; }
}
.frame-1, .frame-2 {
  position: absolute;
  inset: 0;
}
.frame-2 { opacity: 0; }

/* ===== МОНСТР ===== */
.monster {
  position: absolute;
  width: 32px;
  height: 38px;
  z-index: 5;
  image-rendering: pixelated;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
.monster.show { opacity: 1; }

.monster-grid {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(10, 1fr);
}
.monster-grid div { width: 100%; height: 100%; }

.mx-empty { background: transparent; }
.mx-body  { background: #4a148c; }
.mx-eye   { background: #fff; }
.mx-pupil { background: #c8741a; }
.mx-tooth { background: #fff; }
.mx-claw  { background: #1a1a1a; }
.mx-mouth { background: #1a0033; }

.monster .frame-1 { animation: mf1 0.4s steps(1) infinite; }
.monster .frame-2 { animation: mf2 0.4s steps(1) infinite; }
@keyframes mf1 {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}
@keyframes mf2 {
  0%, 49% { opacity: 0; }
  50%, 100% { opacity: 1; }
}
.monster .frame-1, .monster .frame-2 {
  position: absolute;
  inset: 0;
}
.monster .frame-2 { opacity: 0; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}
.building.shake { animation: shake 0.5s; }

/* ===== ОБЛАЧКО ===== */
.bubble {
  position: absolute;
  background: #fff;
  border: 3px solid #000;
  border-radius: 4px;
  padding: 5px 10px;
  font-size: 14px;
  font-weight: bold;
  color: #000;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.3s, left 2.8s linear, top 0.6s ease;
  z-index: 6;
  pointer-events: none;
  box-shadow: 3px 3px 0 #000;
}
.bubble.fast {
  transition: opacity 0.3s, left 0.7s linear, top 0.6s ease;
}
.bubble::after {
  content: '';
  position: absolute;
  bottom: -8px;
  left: 12px;
  width: 10px;
  height: 10px;
  background: #fff;
  border-right: 3px solid #000;
  border-bottom: 3px solid #000;
  transform: rotate(45deg);
  transition: left 0.2s, right 0.2s;
}
.bubble.left-side::after {
  left: auto;
  right: 12px;
}
.bubble.show { opacity: 1; }

/* ===== УПРАВЛЕНИЕ ===== */
.controls {
  margin: 10px auto 0;
  max-width: 600px;
  background: #1a1f33;
  border: 3px solid #c8741a;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}
.controls label {
  font-weight: bold;
  color: #f5b041;
  font-size: 14px;
}
.controls input {
  width: 100px;
  padding: 8px;
  font-size: 20px;
  text-align: center;
  background: #0f1320;
  color: #f5b041;
  border: 2px solid #c8741a;
  font-weight: bold;
  font-family: 'Courier New', monospace;
}
.controls input:focus { outline: none; box-shadow: 0 0 8px #f5b041; }
.controls button {
  padding: 8px 18px;
  font-size: 14px;
  font-weight: bold;
  background: #c8741a;
  color: #fff;
  border: 2px solid #f5b041;
  cursor: pointer;
  font-family: 'Courier New', monospace;
  text-transform: uppercase;
}
.controls button:hover:not(:disabled) { background: #f5b041; color: #000; }
.controls button:active:not(:disabled) { transform: translate(2px, 2px); }
.controls button:disabled { background: #555; border-color: #777; cursor: not-allowed; }
.feedback {
  margin: 6px auto 0;
  max-width: 800px;
  text-align: center;
  min-height: 22px;
  font-size: 14px;
  font-weight: bold;
  text-shadow: 2px 2px 0 #000;
}

/* ===== ЭКРАНЫ ===== */
.win-screen, .game-over-screen {
  position: fixed; inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.win-screen { background: rgba(0,0,0,0.85); }
.game-over-screen { background: rgba(80,0,0,0.92); }
.win-screen.show, .game-over-screen.show { display: flex; }
.win-card, .game-over-card {
  padding: 30px 50px;
  text-align: center;
  border: 4px solid;
}
.win-card {
  background: #1a1f33;
  border-color: #c8741a;
  color: #f5b041;
  box-shadow: 0 0 40px rgba(200,116,26,0.5);
}
.game-over-card {
  background: #1a0a0a;
  border-color: #ff5252;
  color: #ff5252;
  box-shadow: 0 0 40px rgba(255,82,82,0.5);
}
.win-card h2, .game-over-card h2 {
  font-size: 32px;
  margin-bottom: 12px;
  text-shadow: 3px 3px 0 #000;
}
.win-card h2 { text-shadow: 3px 3px 0 #c8741a; }
.win-card p, .game-over-card p { font-size: 16px; margin-bottom: 10px; color: #fff; }
.win-card button, .game-over-card button {
  margin-top: 10px;
  padding: 10px 24px;
  font-size: 14px;
  border: 2px solid;
  cursor: pointer;
  font-weight: bold;
  font-family: 'Courier New', monospace;
  text-transform: uppercase;
}
.win-card button {
  background: #c8741a;
  color: #fff;
  border-color: #f5b041;
}
.win-card button:hover { background: #f5b041; color: #000; }
.game-over-card button {
  background: #ff5252;
  color: #fff;
  border-color: #fff;
}
.game-over-card button:hover { background: #fff; color: #ff5252; }

/* ============ МЕНЮ ============ */
.hidden { display: none !important; }

.main-menu {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.menu-container {
  width: 100%;
  max-width: 560px;
  background: #1a1f33;
  border: 4px solid #c8741a;
  box-shadow: 0 0 30px rgba(200,116,26,0.4);
  padding: 30px 24px;
}
.menu-title {
  font-size: 36px;
  text-align: center;
  color: #f5b041;
  text-shadow: 3px 3px 0 #000, 4px 4px 0 #c8741a;
  letter-spacing: 3px;
  margin-bottom: 8px;
}
.menu-subtitle {
  text-align: center;
  color: #f5b041;
  font-size: 14px;
  margin-bottom: 24px;
  opacity: 0.85;
  letter-spacing: 1px;
}
.menu-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 14px;
  background: #0f1320;
  border: 3px solid #c8741a;
  color: #f5b041;
  padding: 14px 18px;
  font-family: 'Courier New', monospace;
  font-size: 15px;
  font-weight: bold;
  text-align: left;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 1px;
  transition: transform 0.1s, background 0.2s;
}
.menu-item:hover:not(.locked) {
  background: #c8741a;
  color: #fff;
}
.menu-item:active:not(.locked) {
  transform: translate(2px, 2px);
}
.menu-item.locked {
  opacity: 0.5;
  cursor: not-allowed;
  border-color: #555;
  color: #888;
}
.menu-num {
  width: 32px;
  height: 32px;
  background: #c8741a;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  border: 2px solid #f5b041;
  flex-shrink: 0;
}
.menu-item.locked .menu-num {
  background: #555;
  border-color: #777;
}
.menu-text { flex: 1; }
.menu-icon { font-size: 20px; }
.menu-hint {
  text-align: center;
  color: #888;
  font-size: 12px;
  margin-top: 20px;
}

/* Кнопка возврата в меню */
.top-bar {
  max-width: 900px;
  margin: 0 auto 8px;
  display: flex;
  justify-content: flex-start;
}
.back-btn {
  background: #1a1f33;
  border: 3px solid #c8741a;
  color: #f5b041;
  padding: 6px 14px;
  font-family: 'Courier New', monospace;
  font-size: 13px;
  font-weight: bold;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.back-btn:hover { background: #c8741a; color: #fff; }
.back-btn:active { transform: translate(2px, 2px); }