* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #000;
  color: #d9d4c7;
  font-family: Georgia, "Times New Roman", serif;
  user-select: none;
  -webkit-user-select: none;
}

.hidden { display: none !important; }

#stage { position: fixed; inset: 0; z-index: 0; }
#stage canvas { display: block; width: 100%; height: 100%; }

/* ---------- экранные эффекты ---------- */
#vignette {
  position: fixed; inset: 0; z-index: 5; pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0) 38%, rgba(0,0,0,0.88) 100%);
  opacity: 0.55;
}
#redflash {
  position: fixed; inset: 0; z-index: 6; pointer-events: none; opacity: 0;
  background: radial-gradient(ellipse at center, rgba(120,0,0,0) 35%, rgba(150,0,0,0.85) 100%);
}
#grain {
  position: fixed; inset: 0; z-index: 7; pointer-events: none;
  width: 100%; height: 100%;
  image-rendering: pixelated;
  opacity: 0.09;
  mix-blend-mode: overlay;
}
#blackfade, #whitefade {
  position: fixed; inset: 0; z-index: 20; pointer-events: none; opacity: 0;
}
#blackfade { background: #000; }
#whitefade { background: #fff; z-index: 21; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; transition: opacity 1s; }
#hud.dim { opacity: 0.15; }

#keys {
  position: absolute; top: 22px; left: 24px;
  display: flex; gap: 10px;
}
.slot {
  position: relative; width: 22px; height: 36px; display: block;
  opacity: 0.28; filter: grayscale(1);
  transition: opacity 0.4s, filter 0.4s, transform 0.4s;
}
.slot::before {              /* кольцо ключа */
  content: ""; position: absolute; left: 3px; top: 0; width: 16px; height: 16px;
  border: 4px solid #d8b04a; border-radius: 50%;
}
.slot::after {               /* стержень и зубцы */
  content: ""; position: absolute; left: 9px; top: 15px; width: 4px; height: 20px; background: #d8b04a;
  box-shadow: 5px 12px 0 0 #d8b04a, 5px 6px 0 -1px #d8b04a;
}
.slot.on {
  opacity: 1; transform: scale(1.08);
  filter: drop-shadow(0 0 6px rgba(255, 200, 80, 0.9));
}

#meters { position: absolute; bottom: 24px; left: 24px; display: flex; flex-direction: column; gap: 8px; }
.meter-row { display: flex; align-items: center; gap: 10px; }
.meter-row label { width: 64px; font-size: 11px; letter-spacing: 2px; color: #8a857a; }
.meter {
  width: 150px; height: 7px; background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.18); border-radius: 2px; overflow: hidden;
  transition: opacity 0.5s;
}
.meter i { display: block; height: 100%; width: 100%; background: #cfc9b4; transition: width 0.15s linear; }
.meter.low i { background: #b3121a; animation: blink 0.8s infinite; }
#sta { opacity: 0; }
#sta i { background: #9aa7a0; }

#crouch-ind {
  position: absolute; bottom: 24px; right: 24px; font-size: 11px; letter-spacing: 3px; color: #8a857a;
  opacity: 0; transition: opacity 0.3s;
}
#hold {
  position: absolute; left: 50%; top: 64%; width: 220px; height: 6px; transform: translateX(-50%);
  background: rgba(255,255,255,0.12); border: 1px solid rgba(255,255,255,0.3); opacity: 0;
}
#hold.show { opacity: 1; }
#hold i { display: block; height: 100%; width: 0; background: #d8b04a; }
#note-n { font-size: 12px; letter-spacing: 2px; margin-bottom: 10px; opacity: 0.6; }

/* шкафчик: дверца с горизонтальными щелями */
#slits {
  position: fixed; inset: 0; z-index: 8; pointer-events: none; background: #030202;
  -webkit-mask-image: repeating-linear-gradient(180deg, #000 0 30px, transparent 30px 40px);
  mask-image: repeating-linear-gradient(180deg, #000 0 30px, transparent 30px 40px);
}

/* пролог */
#prologue {
  position: fixed; inset: 0; z-index: 25; background: radial-gradient(ellipse at 50% 85%, #10141c 0%, #030405 70%);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
#pro-rain { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#pro-house { position: absolute; bottom: 0; left: 50%; width: min(900px, 120vw); transform: translateX(-50%); opacity: 0.9; transition: transform 2.5s ease-in, opacity 2.5s; }
#pro-house.fall { transform: translateX(-50%) translateY(40%); opacity: 0; }
#pro-win { filter: drop-shadow(0 0 8px #e8b24a); }
#pro-text {
  position: relative; max-width: min(720px, 86vw); text-align: center; z-index: 2;
  font-size: clamp(22px, 3.2vw, 34px); line-height: 1.5; font-style: italic; color: #d4cfbf;
  text-shadow: 0 0 14px #000; opacity: 0; transition: opacity 1.2s; margin-bottom: 26vh;
}
#pro-text.in { opacity: 1; }
#pro-hint { position: absolute; bottom: 24px; right: 24px; z-index: 3; display: flex; gap: 10px; }
#pro-hint button { font-size: 13px; padding: 6px 12px; opacity: 0.6; }
#pro-go { position: absolute; bottom: 20vh; z-index: 3; margin: 0; }

#journal { background: rgba(0,0,0,0.88); z-index: 29; }
.journal { max-width: 640px; text-align: left; max-height: 86vh; overflow: auto; }
.journal h2 { font-size: 30px; }
.journal h2 small { font-size: 14px; color: #8a857a; letter-spacing: 2px; }
#journal-list p { margin: 12px 0; padding: 12px 14px; background: #b9ad90; color: #231b12; font-family: "Courier New", monospace; font-size: 15px; line-height: 1.45; }

.settings { margin: 6px auto 16px; max-width: 360px; text-align: left; color: #8f8a7b; font-size: 14px; }
.settings summary { cursor: pointer; text-align: center; letter-spacing: 2px; text-transform: uppercase; font-size: 12px; margin-bottom: 8px; }
.settings label { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 6px 0; }
.settings input { width: 150px; accent-color: #b3121a; }
.hint { font-size: 14px; color: #7f7a6c; font-style: italic; margin: -8px 0 20px; line-height: 1.5; }
.dim { opacity: 0.6; font-size: 15px; }

#cross {
  position: absolute; left: 50%; top: 50%; width: 4px; height: 4px; margin: -2px 0 0 -2px;
  border-radius: 50%; background: rgba(255,255,255,0.5);
}

#prompt {
  position: absolute; left: 50%; top: 58%; transform: translateX(-50%);
  font-size: 20px; letter-spacing: 1px; text-shadow: 0 0 8px #000, 0 0 3px #000;
  opacity: 0; transition: opacity 0.2s;
}
#prompt.show { opacity: 1; }
#prompt.bad { color: #d86a60; }

#msg {
  position: absolute; left: 50%; bottom: 14%; transform: translateX(-50%);
  max-width: 80%; text-align: center;
  font-size: 22px; font-style: italic; text-shadow: 0 0 10px #000, 0 0 4px #000;
  opacity: 0; transition: opacity 0.5s;
}
#msg.show { opacity: 1; }
#msg.bad { color: #e07a70; }

#note {
  position: absolute; left: 50%; top: 26%; transform: translateX(-50%) rotate(-1.2deg);
  width: min(460px, 82vw); padding: 24px 28px;
  background: #b9ad90; color: #231b12;
  font-family: "Courier New", Courier, monospace; font-size: 17px; line-height: 1.5;
  box-shadow: 0 8px 40px rgba(0,0,0,0.9);
  opacity: 0; transition: opacity 0.6s;
}
#note.show { opacity: 0.96; }

/* ---------- экраны ---------- */
.screen {
  position: fixed; inset: 0; z-index: 30;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0.55), rgba(0,0,0,0.94));
  padding: 20px;
}
#dead { background: rgba(0, 0, 0, 0.96); }
#win { background: rgba(255, 255, 255, 0.96); color: #1a1710; }

.panel { text-align: center; max-width: 560px; width: 100%; }
.panel.small { max-width: 440px; }

h1 {
  font-size: clamp(56px, 11vw, 120px);
  letter-spacing: 0.18em; text-indent: 0.18em; font-weight: normal;
  color: #c9c2ae; text-shadow: 0 0 24px rgba(180, 20, 26, 0.55);
  animation: flicker 6s infinite;
}
h2 { font-size: 44px; letter-spacing: 0.15em; font-weight: normal; margin-bottom: 14px; }
h2.blood { color: #b3121a; text-shadow: 0 0 20px rgba(179, 18, 26, 0.7); }

.tag { margin: 18px 0 26px; font-size: 18px; line-height: 1.55; color: #a39d8c; }
.light .tag { color: #4a463a; }
.tag b { color: #d9d4c7; }
.light .tag b { color: #1a1710; }

button {
  font-family: inherit; cursor: pointer;
  background: transparent; color: #cfc9b4;
  border: 1px solid #5c574b; padding: 8px 16px; font-size: 16px; letter-spacing: 1px;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}
button:hover { background: rgba(255,255,255,0.08); border-color: #a39d8c; }
button.on { border-color: #b3121a; color: #fff; background: rgba(179, 18, 26, 0.25); }
button:disabled { opacity: 0.4; cursor: not-allowed; }

button.big {
  font-size: 22px; padding: 14px 44px; margin: 8px 0 24px;
  border-color: #8c1118; color: #e8e2d0;
  background: rgba(140, 17, 24, 0.25);
}
button.big:hover { background: rgba(179, 18, 26, 0.5); border-color: #d42a33; }
.light button.big { color: #1a1710; border-color: #1a1710; background: transparent; }
.light button.big:hover { background: rgba(0,0,0,0.08); }

.diff { display: flex; align-items: center; justify-content: center; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.diff span { color: #8a857a; margin-right: 6px; font-size: 14px; letter-spacing: 2px; text-transform: uppercase; }

.controls {
  list-style: none; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 22px;
  text-align: left; font-size: 15px; color: #8f8a7b; margin: 0 auto 18px; max-width: 460px;
}
.controls b { color: #d9d4c7; font-weight: normal; border: 1px solid #4a463a; padding: 0 6px; border-radius: 3px; margin-right: 6px; }

.warn { font-size: 13px; color: #6e6a5e; line-height: 1.5; margin-top: 8px; }
.warn.err { color: #d86a60; }

#debug {
  display: none; position: fixed; top: 6px; right: 8px; z-index: 40;
  font: 12px monospace; color: #7f7; background: rgba(0,0,0,0.6); padding: 3px 6px;
}

@keyframes blink { 50% { opacity: 0.35; } }
@keyframes flicker {
  0%, 18%, 22%, 62%, 64%, 100% { opacity: 1; }
  20%, 63% { opacity: 0.55; }
  21% { opacity: 0.9; }
}

@media (max-width: 560px) {
  .controls { grid-template-columns: 1fr; }
  #msg { font-size: 18px; }
}

#bottles {
  position: absolute; top: 28px; left: 210px; font-size: 12px; letter-spacing: 2px; color: #8fd6a0;
  text-shadow: 0 0 6px #000;
}
.row { display: flex; gap: 10px; justify-content: center; margin: -8px 0 20px; flex-wrap: wrap; }
#mapview { background: rgba(0,0,0,0.82); z-index: 29; }
.mapp { max-width: none; width: auto; }
.mapp h2 { font-size: 26px; }
#map-canvas { display: block; margin: 0 auto 10px; box-shadow: 0 8px 40px #000; transform: rotate(-0.6deg); max-width: 92vw; }

/* сенсорное управление */
#touch { display: none; }
body.touch #touch { display: block; position: fixed; inset: 0; z-index: 12; touch-action: none; }
body.touch #cross { display: none; }
#t-stick {
  position: fixed; width: 130px; height: 130px; border-radius: 50%;
  left: calc(18px + env(safe-area-inset-left, 0px));
  bottom: calc(18px + env(safe-area-inset-bottom, 0px) + var(--tg-safe-area-inset-bottom, 0px));
  border: 2px solid rgba(255,255,255,0.3); background: rgba(255,255,255,0.06); opacity: 0.55; pointer-events: none;
  transition: opacity 0.2s;
}
#t-knob { position: absolute; left: 37px; top: 37px; width: 56px; height: 56px; border-radius: 50%; background: rgba(255,255,255,0.25); }
#t-buttons {
  position: absolute; right: 16px; bottom: 16px; width: 240px;
  display: flex; flex-direction: row-reverse; flex-wrap: wrap-reverse; align-items: flex-end; gap: 12px;
}
#t-buttons .tbtn { width: 62px; height: 62px; border-radius: 50%; font-size: 11px; }
#t-buttons #t-use { width: 86px; height: 86px; }
#t-stick.run { border-color: rgba(212, 42, 51, 0.8); }
#t-stick.run #t-knob { background: rgba(212, 42, 51, 0.45); }
body.touch * { -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
#t-top { position: absolute; right: 14px; top: 14px; display: flex; gap: 8px; }
.tbtn {
  height: 54px; border-radius: 10px; font-size: 12px; letter-spacing: 0; padding: 0 4px;
  background: rgba(20,18,16,0.55); color: #e8e2d0; border: 1px solid rgba(255,255,255,0.25);
}
#t-top .tbtn { height: 40px; padding: 0 12px; }
#t-use { font-size: 22px; font-weight: bold; border-color: #d8b04a; }
#t-use.ready { font-size: 13px; }
.tbtn.on, .tbtn.lit { background: rgba(179, 18, 26, 0.55); border-color: #d42a33; }
body.touch #meters { bottom: auto; top: 70px; }
body.touch #msg { bottom: 34%; font-size: 17px; }
body.touch #crouch-ind { display: none; }

/* ---------- телефон и Telegram ---------- */
.hello { color: #b3121a; font-style: italic; margin: -10px 0 14px; min-height: 1em; }
#btn-continue { display: block; margin: 0 auto 10px; }
#btn-continue + #btn-start { font-size: 18px; padding: 10px 34px; background: transparent; }
#t-use.ready { background: rgba(216, 176, 74, 0.35); font-size: 14px; }
#rotate {
  display: none; position: fixed; inset: 0; z-index: 60; background: #000; color: #cfc9b4;
  flex-direction: column; align-items: center; justify-content: center; gap: 24px; font-size: 18px; text-align: center; padding: 30px;
}
#rotate .phone {
  width: 46px; height: 80px; border: 3px solid #cfc9b4; border-radius: 9px; animation: turn 2.2s ease-in-out infinite;
}
@keyframes turn { 0%, 30% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }
@media (orientation: portrait) { body.touch #rotate { display: flex; } }

/* безопасные зоны: вырез экрана и кнопки Telegram в полноэкранном режиме */
body.touch #hud, body.touch #touch {
  top: calc(env(safe-area-inset-top, 0px) + var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px));
  left: env(safe-area-inset-left, 0px);
  right: env(safe-area-inset-right, 0px);
  bottom: env(safe-area-inset-bottom, 0px);
}
#stage, #stage canvas { width: 100vw !important; height: 100vh !important; }
@supports (height: 100dvh) { #stage, #stage canvas { height: 100dvh !important; } }
body.touch .screen { padding-top: calc(20px + var(--tg-content-safe-area-inset-top, 0px) + var(--tg-safe-area-inset-top, 0px)); }
body.touch .panel { max-height: 100%; overflow-y: auto; }
body.touch h1 { font-size: clamp(40px, 9vw, 80px); }
body.touch .controls { display: none; }
body.touch .tag { margin: 10px 0 14px; font-size: 16px; }
body.touch button.big { margin: 4px 0 14px; }
@media (max-height: 420px) {
  body.touch #menu .warn { display: none; }
  body.touch #stats { display: block; }
}
body.touch:not(.playing) #touch { display: none; }

/* ---------- v5: задача, здоровье, сейф, достижения ---------- */
#objective {
  position: absolute; top: 18px; left: 50%; transform: translateX(-50%);
  font-size: 13px; letter-spacing: 2px; color: #b8b19e; text-shadow: 0 0 6px #000; white-space: nowrap;
}
#hp { position: absolute; top: 64px; left: 24px; display: flex; gap: 6px; }
#hp i {
  width: 14px; height: 14px; display: block; transform: rotate(45deg); background: rgba(120,20,24,0.25);
  border: 1px solid rgba(200,40,40,0.5);
}
#hp i.on { background: #a3141c; box-shadow: 0 0 8px rgba(220,30,30,0.7); }
body.touch #hp { top: 58px; }
body.touch #meters { top: 84px; }
body.touch #objective { top: 6px; font-size: 11px; }

#keypad { position: fixed; inset: 0; z-index: 28; display: flex; align-items: center; justify-content: flex-end; padding: 16px 6vw; pointer-events: none; }
.kp-box {
  pointer-events: auto; position: relative; width: 230px; padding: 16px; border-radius: 10px;
  background: rgba(14, 14, 13, 0.94); border: 1px solid #3c3a33; box-shadow: 0 10px 40px #000; text-align: center;
}
.kp-title { font-size: 12px; letter-spacing: 4px; color: #8a857a; }
#kp-display {
  font: bold 30px "Courier New", monospace; color: #ff4a2a; background: #0a0202; margin: 8px 0 4px; padding: 6px;
  border: 1px solid #3a1010; letter-spacing: 4px; text-shadow: 0 0 8px rgba(255,60,30,0.7);
}
#kp-display.bad { animation: shake 0.4s; color: #fff; }
#kp-known { font-size: 12px; color: #b8b19e; margin-bottom: 10px; letter-spacing: 1px; }
.kp-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.kp-grid button { height: 46px; font-size: 20px; padding: 0; border-radius: 8px; background: #1d1c19; }
.kp-grid button:active { background: #3a1a12; }
#kp-hint { font-size: 11px; color: #6e6a5e; margin-top: 8px; line-height: 1.4; }
.kp-x { position: absolute; right: 6px; top: 4px; border: 0; font-size: 22px; padding: 2px 8px; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
body.touch .kp-grid button { height: 40px; }
@media (max-height: 420px) { .kp-box { width: 210px; padding: 10px; } #kp-display { font-size: 24px; } .kp-grid button { height: 36px !important; } }

#toast {
  position: fixed; top: 64px; left: 50%; transform: translate(-50%, -20px); z-index: 45; pointer-events: none;
  padding: 10px 22px; background: rgba(12,10,8,0.92); border: 1px solid #8c6a1a; color: #e8d6a0; font-size: 17px;
  opacity: 0; transition: opacity 0.4s, transform 0.4s; text-align: center;
}
#toast small { display: block; font-size: 10px; letter-spacing: 3px; color: #b0904a; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.ach summary span { color: #b3121a; }
#ach-list { list-style: none; max-height: 220px; overflow-y: auto; }
#ach-list li { display: flex; flex-direction: column; padding: 5px 0; border-bottom: 1px solid #23211c; opacity: 0.45; }
#ach-list li.on { opacity: 1; }
#ach-list li.on b { color: #e8c86a; }
#ach-list b { font-weight: normal; font-size: 14px; color: #cfc9b4; }
#ach-list span { font-size: 12px; color: #7f7a6c; }

body.touch #prompt { top: 24%; font-size: 15px; }
