:root {
  color-scheme: dark;
  --bg: #090a0d;
  --panel: #101318;
  --text: #d8d6ca;
  --muted: #858178;
  --edge: #2a3137;
  --accent: #c9d8ef;
  --danger: #b05050;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at 50% 0%, #1a2028 0, transparent 34rem),
    linear-gradient(180deg, #050608 0%, var(--bg) 70%);
  color: var(--text);
  font-family: ui-serif, Georgia, "Times New Roman", serif;
}
button { font: inherit; }

.page-shell { width: min(920px, 100%); margin: 0 auto; padding: 28px 18px 52px; }

.game {
  border: 1px solid var(--edge);
  background: #101318c7;
  box-shadow: 0 22px 80px #0000006b;
}
.game-title {
  display: flex; align-items: baseline; justify-content: space-between; gap: 16px;
  padding: 14px 18px; border-bottom: 1px solid var(--edge);
  color: #ece7d6; letter-spacing: 0.06em; text-transform: uppercase;
}
.game-title span { font-size: 1rem; }
.title-right { display: flex; align-items: baseline; gap: 14px; }
.game-title small { color: var(--muted); font-family: var(--mono); font-size: .7rem; text-transform: none; letter-spacing: 0; }
#mute-btn {
  padding: 3px 10px; border: 1px solid #3b4650; border-radius: 3px;
  background: #151a21; color: var(--muted); cursor: pointer;
  font: .7rem var(--mono); text-transform: none;
}
#mute-btn:hover { border-color: var(--accent); color: var(--text); }

/* Inventory */
.inventory {
  position: sticky; top: 0; z-index: 2;
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px;
  padding: 10px 18px; border-bottom: 1px solid var(--edge); background: #080b10;
}
.inv-slot {
  display: flex; align-items: center; gap: 10px; min-height: 42px;
  padding: 7px 10px; border: 1px solid #2f3942; border-radius: 4px;
  background: #0c1015; transition: border-color .16s ease, background .16s ease;
}
.inv-slot--active { border-color: #6f7f8c; background: #131922; }
.inv-slot--empty { color: var(--muted); }
.inv-dot {
  flex: 0 0 10px; width: 10px; height: 10px; border-radius: 50%;
  border: 1px solid #4a5560; background: transparent;
}
.inv-slot--active .inv-dot { background: #c7a95a; border-color: #c7a95a; box-shadow: 0 0 8px #c7a95a66; }
.inv-text { display: grid; gap: 1px; min-width: 0; }
.inv-name { font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inv-state { color: var(--muted); font: .68rem/1.2 var(--mono); }

/* Story */
.story { padding: 22px 18px 4px; }
.story p { max-width: 70ch; margin: 0 0 1rem; font-size: clamp(1.05rem, 1rem + .35vw, 1.26rem); line-height: 1.7; }
.story p.dead { color: #e4b1aa; }
.story .act-header {
  margin: 26px 0 18px; padding-top: 18px; border-top: 1px solid var(--edge);
  color: #ece7d6; font: .8rem var(--mono); letter-spacing: .18em; text-transform: uppercase;
}
.story .act-header:first-child { margin-top: 0; padding-top: 0; border-top: none; }

/* Choices */
.choices { display: grid; gap: 10px; padding: 8px 18px 22px; }
.choice-button {
  width: 100%; max-width: 620px; min-height: 44px; padding: 10px 14px;
  border: 1px solid #3b4650; border-radius: 4px; background: #151a21;
  color: var(--text); text-align: left; cursor: pointer;
}
.choice-button:hover, .choice-button:focus-visible {
  border-color: var(--accent); outline: none; background: #1c2530;
}
.choice-button:disabled { cursor: wait; opacity: .58; }

/* Endings */
.ending-block { margin: 8px 0 14px; padding: 16px; border: 1px solid #4a3535; background: #16100f; max-width: 620px; }
.ending-block.win { border-color: #3e4a35; background: #10140d; }
.ending-title { margin: 0 0 6px; font-size: 1.2rem; color: #e4b1aa; }
.ending-block.win .ending-title { color: #c3d3a8; }
.ending-count { margin: 0; color: var(--muted); font: .72rem var(--mono); }

/* Inline scenes */
.inline-scene { width: fit-content; max-width: 100%; margin: 20px 0 28px; border: 1px solid #3a4650; background: #050608; }
.scene-frame { position: relative; width: 640px; max-width: 100%; }
.scene-frame canvas {
  display: block; width: 100%; height: auto; aspect-ratio: 16 / 9;
  touch-action: none; background: #030406; cursor: crosshair;
}
.scene-hud {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: space-between; gap: 8px; padding: 8px;
  color: #e7e4d4; font: 12px/1.3 var(--mono);
  text-shadow: 0 1px 0 #000, 0 0 6px #000; pointer-events: none; z-index: 2;
}
.scene-hud .hud-warn { color: #f0a0a0; }
.scene-vignette {
  position: absolute; inset: 0; pointer-events: none; opacity: 0;
  background: radial-gradient(ellipse at center, transparent 42%, #6d0f0f 130%);
  transition: opacity .25s linear;
}
.scene-note {
  padding: 8px 10px 10px; color: var(--muted);
  font: 12px/1.4 var(--mono); border-top: 1px solid #1e252c; max-width: 640px;
}
.scene-result {
  display: flex; align-items: center; justify-content: center;
  min-height: 90px; padding: 14px; font: 13px var(--mono); letter-spacing: .12em;
  text-transform: uppercase;
}
.scene-result.ok { color: #c3d3a8; }
.scene-result.fail { color: #e4b1aa; }

.status-line { max-width: 70ch; color: var(--muted); font: .82rem/1.4 var(--mono); }

/* Отладочная панель сцены (под кадром, не поверх) */
.dbg-panel[hidden] { display: none; }
.dbg-panel {
  display: grid; gap: 7px;
  padding: 10px; border-top: 1px solid #1e252c;
  background: #0a0e13; color: var(--text); font: 11px/1.3 var(--mono);
}
.dbg-head { color: #c7a95a; letter-spacing: .08em; text-transform: uppercase; }
.dbg-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; align-items: center; }
.dbg-row input { grid-column: 1 / 3; width: 100%; accent-color: #c7a95a; }
.dbg-val { color: #c7a95a; }
.dbg-reset {
  justify-self: start; padding: 3px 12px; cursor: pointer;
  border: 1px solid #3a4650; border-radius: 3px;
  background: #151a21; color: var(--muted); font: 11px var(--mono);
}
.dbg-reset:hover { color: var(--text); border-color: var(--accent); }

/* Title screen */
.title-screen {
  position: fixed; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(circle at 50% 20%, #141b24 0, transparent 40rem),
    linear-gradient(180deg, #030405 0%, #08090c 100%);
}
.title-screen.hidden { display: none; }
.title-box { max-width: 560px; padding: 32px; text-align: center; }
.title-box h1 {
  margin: 0 0 10px; font-size: clamp(2rem, 6vw, 3.2rem);
  letter-spacing: .14em; color: #ece7d6; font-weight: 600;
  text-shadow: 0 0 40px #22303f;
}
.title-sub { margin: 0 0 30px; color: var(--muted); font-style: italic; }
.title-buttons { display: grid; gap: 12px; justify-items: center; margin-bottom: 26px; }
.title-btn {
  min-width: 260px; padding: 12px 20px; cursor: pointer;
  border: 1px solid #3b4650; border-radius: 4px;
  background: #151a21; color: var(--text); font-size: 1.05rem;
}
.title-btn:hover, .title-btn:focus-visible { border-color: var(--accent); background: #1c2530; outline: none; }
.title-btn--dim { font-size: .88rem; color: var(--muted); min-width: 200px; padding: 8px 16px; }

/* Панель кнопок отладки под сценой */
.dbg-bar {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 8px 10px; border-top: 1px solid #1e252c; background: #0a0e13;
}
.dbg-btn {
  padding: 5px 10px; cursor: pointer;
  border: 1px solid #3a4650; border-radius: 3px;
  background: #151a21; color: var(--muted); font: 11px var(--mono);
}
.dbg-btn:hover { color: var(--text); border-color: var(--accent); }
.title-endings { margin: 0 0 18px; color: #c7a95a; font: .78rem var(--mono); }
.title-hint { margin: 0; color: var(--muted); font: .72rem/1.6 var(--mono); }

@media (max-width: 620px) {
  .page-shell { padding: 12px 8px 30px; }
  .game-title { align-items: flex-start; flex-direction: column; gap: 6px; }
  .story, .choices, .inventory { padding-left: 12px; padding-right: 12px; }
}
@media (max-width: 430px) {
  .inventory { grid-template-columns: 1fr; }
}

/* Сцена «Тропа с фонарём»: субтитры, заставка, кнопки для касаний */
.fc-caption {
  position: absolute; left: 8px; right: 8px; top: 8px; z-index: 2;
  display: flex; flex-direction: column; align-items: center; gap: 4px; pointer-events: none;
  font: 12px/1.3 var(--mono); color: #e7e4d4; text-shadow: 0 1px 0 #000, 0 0 6px #000;
}
.fc-caption span { padding: 2px 6px; background: #000a; transition: opacity .5s ease; text-align: center; }
.fc-caption .fc-tip { color: #f1d58e; }
.fc-fade { position: absolute; inset: 0; background: #000; opacity: 0; pointer-events: none; }
.fc-overlay {
  position: absolute; inset: 0; z-index: 3;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  padding: 16px; background: #000000d0; text-align: center; color: var(--text);
}
.fc-overlay strong { font-size: 15px; letter-spacing: .1em; text-transform: uppercase; color: #ece7d6; }
.fc-overlay .fc-line { max-width: 46ch; font: 12px/1.45 var(--mono); }
.fc-overlay button, .fc-controls button {
  min-height: 36px; padding: 6px 12px; cursor: pointer;
  border: 1px solid #3b4650; border-radius: 4px; background: #151a21; color: var(--text);
  font: 12px/1.2 var(--mono); touch-action: none; user-select: none; -webkit-user-select: none;
}
.fc-overlay button:hover, .fc-overlay button:focus-visible,
.fc-controls button:hover, .fc-controls button:focus-visible { border-color: var(--accent); outline: none; background: #1c2530; }
.fc-controls { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 10px 0; max-width: 640px; }
.fc-controls .fc-walk { flex: 1 1 120px; }
.fc-controls button[aria-pressed="true"] { border-color: var(--accent); background: #1c2530; }
.fc-touch { display: none; }
@media (pointer: coarse) { .fc-keys { display: none; } .fc-touch { display: block; } }
@media (max-width: 520px) {
  .fc-overlay { gap: 6px; padding: 8px; }
  .fc-overlay .fc-line { font-size: 11px; line-height: 1.35; }
  .fc-overlay strong { font-size: 13px; }
}
.ending-link { display: block; text-decoration: none; }

/* Гравюры поверх кадра: рука с фонарём, ружьё */
.scene-frame { overflow: hidden; }
.fc-hand {
  position: absolute; right: -1%; bottom: -6%; width: 25%; z-index: 1;
  pointer-events: none; user-select: none; -webkit-user-drag: none;
  transform-origin: 80% 100%;
}
.fp-gun {
  position: absolute; left: 66%; bottom: -17%; width: 25%; z-index: 1;
  pointer-events: none; user-select: none; -webkit-user-drag: none;
  margin-left: -12.5%; filter: brightness(.6); rotate: -10deg; transition: transform .08s ease-out;
}

/* Гравюры в интерфейсе: шапка, инвентарь, иллюстрации, иконки */
.masthead { border-bottom: 1px solid var(--edge); background: #0d0c0a; line-height: 0; }
.masthead img { width: 100%; height: auto; aspect-ratio: 4 / 1; filter: sepia(.15) brightness(.78) contrast(1.05); }
.title-art { display: block; width: 100%; height: auto; margin: 0 0 18px; filter: sepia(.15) brightness(.85); border: 1px solid var(--edge); }
#mute-btn { display: inline-flex; align-items: center; gap: 6px; }
#mute-btn img { width: 16px; height: 16px; object-fit: contain; filter: invert(.85); }
.inv-icon {
  flex: 0 0 34px; width: 34px; height: 28px; object-fit: contain;
  filter: invert(.86) sepia(.25); opacity: .35; transition: opacity .16s ease;
}
.inv-slot--active .inv-icon { opacity: 1; }
.story-art { margin: 6px 0 18px; max-width: 640px; line-height: 0; }
.story-art img { width: 100%; height: auto; border: 1px solid #3a4650; filter: sepia(.12) brightness(.92); }
.story-art--photo { max-width: 260px; }
.story-art--photo img { border: none; filter: drop-shadow(0 6px 18px #000a) brightness(.95); }
.story-art--ending img { border-color: #4a3535; }
.story-art--ending.win img { border-color: #3e4a35; filter: sepia(.08) brightness(1); }
.ui-icon { width: 18px; height: 18px; object-fit: contain; vertical-align: -4px; margin-right: 7px; filter: invert(.82); }
.ending-count .ui-icon { width: 15px; height: 15px; vertical-align: -3px; opacity: .8; }
