:root {
  --bg: #03060c;
  --ink: #e4ebf1;
  --ink-dim: #8e9aa6;
  --ink-faint: #45505b;
  --warm: #ffc56b;
  --cold: #9fd3ff;
  --panel: rgba(10, 15, 22, 0.93);
  --line: rgba(214, 228, 240, 0.14);
  --serif: 'IBM Plex Serif', Georgia, serif;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
  touch-action: none;
}

.hidden { display: none !important; }

#game { position: fixed; inset: 0; display: block; image-rendering: pixelated; }

.vignette {
  position: fixed; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(0, 0, 0, 0.65) 100%);
}

.fade {
  position: fixed; inset: 0; pointer-events: none;
  background: #000; opacity: 0; transition: opacity 1.2s ease;
}
.fade.on { opacity: 1; }

/* ---------- HUD ---------- */
.hud {
  position: fixed; left: 0; right: 0; top: 0;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  padding: max(14px, env(safe-area-inset-top)) 16px 0;
  pointer-events: none;
  opacity: 0; transition: opacity 0.6s;
}
body.playing .hud { opacity: 1; }

.goal {
  max-width: min(420px, 60vw);
  font-size: 15px; line-height: 1.25;
  font-style: italic;
  color: var(--ink);
  text-shadow: 0 1px 6px #000;
}
.goal-label {
  display: block;
  font: 600 10px var(--mono); font-style: normal;
  letter-spacing: 0.2em; text-transform: uppercase;
  color: var(--cold); opacity: 0.8;
  margin-bottom: 3px;
}
.goal.pulse #goalText { animation: goalIn 1.6s ease; }
@keyframes goalIn { from { opacity: 0; letter-spacing: 0.06em; } to { opacity: 1; letter-spacing: 0; } }

.hud-right { display: flex; align-items: center; gap: 10px; pointer-events: auto; }

.warm { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; pointer-events: none; }
.warm-label { font: 600 10px var(--mono); letter-spacing: 0.2em; text-transform: uppercase; color: var(--ink-dim); }
.warm-bar { width: 96px; height: 6px; border: 1px solid var(--line); border-radius: 3px; overflow: hidden; background: rgba(0, 0, 0, 0.5); }
.warm-fill { height: 100%; background: linear-gradient(90deg, #c4462c, #ff9a3c 45%, #ffc56b); transition: width 0.3s linear; }
.warm-fill.low { background: #c4462c; animation: blink 0.9s infinite; }
.warm.empty .warm-label { color: #e0664a; }
.temp { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; pointer-events: none; }
.temp-label { font: 600 10px var(--mono); letter-spacing: 0.2em; text-transform: uppercase; color: var(--ink-dim); }
#tempText { font: 600 17px var(--mono); color: var(--cold); transition: color 0.4s; }
#tempText.bitter { color: #ff7a5c; animation: blink 0.9s infinite; }
#tempText.mild { color: #ffc56b; }
@keyframes blink { 50% { opacity: 0.4; } }

.icon-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 50%;
  background: rgba(10, 12, 16, 0.6); color: var(--ink);
  cursor: pointer; position: relative;
}
.icon-btn:hover { border-color: var(--cold); color: var(--cold); }
.icon-btn.fresh::after {
  content: ''; position: absolute; top: 2px; right: 2px;
  width: 8px; height: 8px; border-radius: 50%; background: var(--cold);
  box-shadow: 0 0 8px var(--cold);
}

.prompt {
  position: fixed; left: 0; top: 0;
  display: flex; align-items: center; gap: 6px;
  padding: 4px 9px 4px 5px;
  border-radius: 4px;
  background: rgba(8, 9, 12, 0.78);
  border: 1px solid var(--line);
  font: 400 14px var(--serif);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0; transition: opacity 0.2s;
}
.prompt.on { opacity: 1; }
.prompt .key {
  font: 600 11px var(--mono);
  padding: 1px 6px; border-radius: 3px;
  background: var(--ink); color: #111;
}
body.touch .prompt { display: none; }

.act-btn {
  position: fixed; right: 20px; bottom: max(24px, env(safe-area-inset-bottom));
  min-width: 96px; height: 56px; padding: 0 18px;
  border-radius: 28px;
  border: 1px solid rgba(159, 211, 255, 0.5);
  background: rgba(12, 22, 34, 0.8);
  color: var(--cold);
  font: 600 15px var(--serif);
  display: none;
}
body.touch .act-btn.on { display: block; }

.joy {
  position: fixed; width: 104px; height: 104px; margin: -52px 0 0 -52px;
  border-radius: 50%; border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  pointer-events: none; opacity: 0; transition: opacity 0.15s;
}
.joy.on { opacity: 1; }
.joy-knob {
  position: absolute; left: 50%; top: 50%;
  width: 40px; height: 40px; margin: -20px 0 0 -20px;
  border-radius: 50%; background: rgba(233, 228, 214, 0.25);
}

.toast {
  position: fixed; left: 50%; top: 18%;
  transform: translate(-50%, -8px);
  max-width: min(460px, calc(100vw - 32px));
  padding: 9px 16px;
  border-radius: 4px;
  background: rgba(10, 11, 14, 0.85);
  border: 1px solid rgba(159, 211, 255, 0.25);
  font: italic 400 15px var(--serif);
  text-align: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.35s, transform 0.35s;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- dialogue ---------- */
.dialogue {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: center;
  padding: 0 16px max(18px, env(safe-area-inset-bottom));
  opacity: 0; pointer-events: none; transform: translateY(12px);
  transition: opacity 0.25s, transform 0.25s;
}
.dialogue.on { opacity: 1; pointer-events: auto; transform: none; }
.dlg-box {
  position: relative;
  width: min(720px, 100%);
  padding: 16px 20px 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 1px solid rgba(169, 216, 230, 0.35);
  border-radius: 6px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
  cursor: pointer;
}
.dialogue.narration .dlg-box { border-top-color: rgba(159, 211, 255, 0.3); }
.dlg-who {
  font: 600 11px var(--mono); letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--cold); margin-bottom: 6px;
}
.dlg-who:empty { display: none; }
.dlg-text { font-size: 18px; line-height: 1.4; min-height: 2.8em; white-space: pre-wrap; }
.dialogue.narration .dlg-text { font-style: italic; color: #cfdbe5; }
.dlg-choices { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.dlg-choices:empty { display: none; }
.choice {
  display: flex; align-items: baseline; gap: 10px;
  text-align: left;
  padding: 9px 12px;
  border: 1px solid var(--line); border-radius: 4px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--ink);
  font: 400 16px var(--serif);
  cursor: pointer;
}
.choice:hover { border-color: var(--cold); background: rgba(159, 211, 255, 0.07); }
.choice .n { font: 600 11px var(--mono); color: var(--cold); opacity: 0.8; }
.dlg-next {
  position: absolute; right: 14px; bottom: 6px;
  color: var(--cold); font-size: 16px;
  opacity: 0;
}
.dlg-next.on { opacity: 1; animation: nudge 1.2s infinite; }
@keyframes nudge { 50% { transform: translateY(3px); } }

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  background: rgba(3, 4, 6, 0.6);
  backdrop-filter: blur(3px);
  opacity: 0; pointer-events: none; transition: opacity 0.25s;
}
.overlay.on { opacity: 1; pointer-events: auto; }
.panel {
  width: min(560px, 100%);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 20px 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  user-select: text; -webkit-user-select: text;
}
.panel.small { width: min(320px, 100%); display: flex; flex-direction: column; gap: 10px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.panel-title { font-size: 22px; font-weight: 600; }
.panel-title.center { text-align: center; margin-bottom: 6px; }
.close { background: none; border: 0; color: var(--ink-dim); font-size: 28px; cursor: pointer; line-height: 1; }
.close:hover { color: var(--ink); }

.j-section { padding: 12px 0; border-top: 1px solid var(--line); }
.j-label {
  font: 600 10px var(--mono); letter-spacing: 0.2em; text-transform: uppercase;
  color: var(--cold); opacity: 0.8; margin-bottom: 6px;
}
.j-count { font: 400 13px var(--mono); color: var(--ink); }
.j-goal { font-size: 16px; font-style: italic; }
.j-items { display: flex; flex-wrap: wrap; gap: 6px; }
.item { padding: 3px 10px; border: 1px solid var(--line); border-radius: 12px; font-size: 14px; }
.j-notes { display: flex; flex-direction: column; gap: 6px; }
.note { border: 1px solid var(--line); border-radius: 4px; background: rgba(255, 255, 255, 0.02); }
.note summary { padding: 9px 12px; cursor: pointer; font-size: 16px; font-weight: 600; list-style: none; }
.note summary::-webkit-details-marker { display: none; }
.note summary::before { content: '›'; display: inline-block; width: 14px; color: var(--cold); transition: transform 0.2s; }
.note[open] summary::before { transform: rotate(90deg); }
.note.clue { border-color: rgba(159, 211, 255, 0.35); }
.note.clue summary { color: var(--cold); }
.note .body { padding: 0 14px 12px 26px; font-size: 15px; line-height: 1.5; white-space: pre-wrap; color: #c9d5df; }
.empty { color: var(--ink-dim); font-style: italic; }

.btn {
  display: block; width: 100%;
  padding: 12px 18px;
  border: 1px solid rgba(159, 211, 255, 0.45);
  border-radius: 4px;
  background: rgba(159, 211, 255, 0.08);
  color: var(--cold);
  font: 600 17px var(--serif);
  text-align: center; text-decoration: none;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}
.btn:hover { background: rgba(159, 211, 255, 0.16); border-color: var(--cold); }
.btn.ghost { border-color: var(--line); background: transparent; color: var(--ink-dim); }
.btn.ghost:hover { color: var(--ink); border-color: var(--ink-faint); }

/* ---------- screens ---------- */
.screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  opacity: 0; pointer-events: none; transition: opacity 0.8s;
}
.screen.on { opacity: 1; pointer-events: auto; }
.menu { background: radial-gradient(ellipse at 50% 40%, rgba(3, 6, 12, 0.25), rgba(3, 6, 12, 0.88)); }
.menu-inner { width: min(380px, 100%); text-align: center; }
.logo {
  font-weight: 600; line-height: 1;
  font-size: clamp(46px, 13vw, 72px); letter-spacing: 0.02em;
  color: var(--ink);
  text-shadow: 0 0 28px rgba(159, 211, 255, 0.35);
}
.logo span { color: var(--cold); }
.menu-sub { margin: 14px 0 30px; font-size: 17px; font-style: italic; color: var(--ink-dim); }
.menu-btns { display: flex; flex-direction: column; gap: 10px; }
.lang-switch { display: flex; gap: 6px; padding: 4px; border-radius: 6px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.03); }
.lang-switch button {
  flex: 1; padding: 8px; border: 0; border-radius: 4px; background: none; cursor: pointer;
  color: var(--ink-dim); font: 400 15px var(--serif);
}
.lang-switch button.on { background: rgba(159, 211, 255, 0.14); color: var(--ink); }
.menu-found { margin-top: 18px; min-height: 14px; font: 400 11px var(--mono); letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-dim); }
.controls { margin-top: 22px; font: 400 11px/1.7 var(--mono); color: var(--ink-faint); letter-spacing: 0.04em; }
.touch-only { display: none; }
body.touch .touch-only { display: block; }
body.touch .desktop-only { display: none; }

.intro { background: #000; cursor: pointer; }
.intro-text {
  max-width: 560px;
  font-size: clamp(20px, 4vw, 27px); font-style: italic; line-height: 1.4;
  text-align: center;
  opacity: 0; transition: opacity 1.1s ease;
}
.intro-text.on { opacity: 1; }

.end { background: rgba(0, 0, 0, 0.92); }
.end-title { font: 600 12px var(--mono); letter-spacing: 0.4em; text-transform: uppercase; color: var(--cold); }
.end-sub { font-size: clamp(38px, 11vw, 60px); font-weight: 600; margin: 4px 0 14px; }
.end-text { font-size: 17px; font-style: italic; text-align: left; white-space: pre-wrap; color: #c9d5df; line-height: 1.4; }
.end { overflow-y: auto; align-items: flex-start; }
.end-inner { width: min(560px, 100%); margin: auto; padding: 24px 0; }
.end-stats { margin: 22px 0 6px; padding-top: 14px; border-top: 1px solid var(--line); font: 400 11px var(--mono); letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-dim); }
.end-more { margin-bottom: 22px; font: 400 11px var(--mono); letter-spacing: 0.3em; text-transform: uppercase; color: var(--ink-dim); }

@media (max-width: 520px) {
  .goal { font-size: 15px; max-width: 54vw; }
  .warm-bar { width: 70px; }
  .dlg-text { font-size: 16px; }
  .choice { font-size: 15px; }
}

/* ---------- night cutscenes ---------- */
.letterbox {
  position: fixed; left: 0; right: 0; height: 13vh;
  background: #000; pointer-events: none;
  transform: scaleY(0); transition: transform 0.9s ease;
  z-index: 5;
}
.letterbox.top { top: 0; transform-origin: top; }
.letterbox.bottom {
  bottom: 0; transform-origin: bottom;
  display: flex; align-items: center; justify-content: center;
  padding: 0 16px env(safe-area-inset-bottom);
}
body.cutscene .letterbox { transform: scaleY(1); pointer-events: auto; }
.subtitle {
  max-width: min(680px, calc(100vw - 120px));
  font: italic 400 17px/1.4 var(--serif); color: #dfe7ee; text-align: center;
  opacity: 0; transition: opacity 0.5s;
}
.subtitle.on { opacity: 1; }
.skip-btn {
  position: absolute; right: 16px; bottom: max(12px, env(safe-area-inset-bottom));
  background: none; border: 0; cursor: pointer;
  font: 400 11px var(--mono); letter-spacing: 0.15em; text-transform: uppercase; color: var(--ink-faint);
  opacity: 0; transition: opacity 0.6s 1.5s;
}
body.cutscene .skip-btn { opacity: 1; }
.skip-btn:hover { color: var(--ink-dim); }
@media (max-width: 520px) { .subtitle { font-size: 15px; max-width: calc(100vw - 32px); margin-bottom: 18px; } }
