:root {
  --bg: #070d0f;
  --ink: #e8f2f4;
  --muted: #8aa0a6;
  --accent: #3ec6c9;
  --accent-dim: rgba(62, 198, 201, 0.18);
  --danger: #d46a6a;
  --panel: rgba(8, 16, 18, 0.78);
  --line: rgba(232, 242, 244, 0.12);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --font-ui: "IBM Plex Sans KR", sans-serif;
  --font-display: "Syne", "IBM Plex Sans KR", sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  overflow: hidden;
  touch-action: manipulation;
  user-select: none;
}

#app {
  position: relative;
  width: 100%;
  max-width: 480px;
  height: 100%;
  height: 100dvh;
  margin: 0 auto;
  background: #000;
  overflow: hidden;
  box-shadow: 0 0 80px rgba(0,0,0,.6);
}

#stage {
  position: absolute;
  inset: 0;
  z-index: 0;
}

.layer {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  transition: opacity .7s ease, filter .7s ease, transform 8s ease;
}

#bg-layer {
  transform: scale(1.08);
  filter: saturate(1.05) contrast(1.05);
}
#bg-layer.kenburns {
  animation: kenburns 14s ease-in-out infinite alternate;
}
@keyframes kenburns {
  from { transform: scale(1.05) translate3d(0,0,0); }
  to { transform: scale(1.16) translate3d(-2%, -1%, 0); }
}

#cg-layer {
  opacity: 0;
  pointer-events: none;
  z-index: 2;
}
#cg-layer.show { opacity: 1; }

#char-layer {
  z-index: 3;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  pointer-events: none;
  padding-bottom: 28%;
}
.char {
  display: none;
  max-height: 62%;
  width: auto;
  max-width: 78%;
  object-fit: contain;
  filter: drop-shadow(0 18px 30px rgba(0,0,0,.55));
  opacity: 0;
  transform: translateY(18px);
  transition: opacity .45s ease, transform .45s ease, filter .35s ease;
}
.char.show {
  display: block;
  opacity: 1;
  transform: translateY(0);
}
.char.dim { filter: brightness(.45) saturate(.7) drop-shadow(0 18px 30px rgba(0,0,0,.55)); }
.char.glitch {
  animation: glitch 0.45s steps(2, end) infinite;
}
@keyframes glitch {
  0% { transform: translate(0,0); }
  25% { transform: translate(-3px, 1px); }
  50% { transform: translate(2px, -2px); }
  75% { transform: translate(-1px, 2px); }
  100% { transform: translate(0,0); }
}

#particle-canvas {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  opacity: .55;
}

#vignette {
  position: absolute;
  inset: 0;
  z-index: 5;
  background:
    radial-gradient(ellipse at center, transparent 40%, rgba(0,0,0,.55) 100%),
    linear-gradient(to top, rgba(0,0,0,.72) 0%, transparent 42%);
  pointer-events: none;
}

.screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: none;
  flex-direction: column;
}
.screen.active { display: flex; }
.screen.overlay {
  z-index: 40;
  background: rgba(0,0,0,.62);
  backdrop-filter: blur(8px);
  align-items: center;
  justify-content: center;
  padding: 24px;
}

/* Title */
#screen-title {
  z-index: 20;
  justify-content: flex-end;
  padding: calc(24px + var(--safe-top)) 28px calc(36px + var(--safe-bottom));
  background:
    linear-gradient(to top, rgba(7,13,15,.92) 18%, rgba(7,13,15,.15) 58%, rgba(7,13,15,.35) 100%);
}
.title-glow {
  position: absolute;
  width: 70%;
  height: 40%;
  left: 15%;
  top: 18%;
  background: radial-gradient(circle, rgba(62,198,201,.22), transparent 70%);
  filter: blur(20px);
  pointer-events: none;
}
.title-eyebrow {
  margin: 0 0 10px;
  letter-spacing: .28em;
  text-transform: uppercase;
  font-size: 11px;
  color: var(--accent);
}
.title-logo {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(36px, 10vw, 56px);
  letter-spacing: .02em;
  line-height: .95;
  word-break: keep-all;
}
.title-logo span { color: var(--accent); }
.title-tag {
  margin: 18px 0 28px;
  color: var(--muted);
  font-weight: 300;
  line-height: 1.7;
  font-size: 15px;
}
.title-actions { display: grid; gap: 10px; }
.title-hint {
  margin: 18px 0 0;
  font-size: 12px;
  color: rgba(138,160,166,.75);
  text-align: center;
}

.btn {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 14px;
  padding: 14px 16px;
  font: 500 15px/1.2 var(--font-ui);
  cursor: pointer;
  transition: transform .15s ease, background .2s ease, border-color .2s ease;
}
.btn:active { transform: scale(.98); }
.btn.primary {
  background: linear-gradient(135deg, #1e4f52, #2a7d80);
  border-color: rgba(62,198,201,.45);
}
.btn.ghost { background: transparent; }
.icon-btn {
  background: rgba(0,0,0,.35);
  border: 1px solid var(--line);
  color: var(--ink);
  width: 40px;
  height: 40px;
  border-radius: 12px;
  font-size: 16px;
}

/* Game HUD */
.hud {
  position: absolute;
  top: calc(12px + var(--safe-top));
  left: 14px;
  right: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 15;
  pointer-events: none;
}
.hud-actions { pointer-events: auto; }
#chapter-label {
  font-size: 11px;
  letter-spacing: .22em;
  color: rgba(232,242,244,.72);
  background: rgba(0,0,0,.35);
  border: 1px solid var(--line);
  padding: 7px 10px;
  border-radius: 999px;
}

#nameplate {
  position: absolute;
  left: 18px;
  bottom: calc(196px + var(--safe-bottom));
  z-index: 16;
  padding: 6px 12px;
  border-radius: 10px;
  background: rgba(62,198,201,.16);
  border: 1px solid rgba(62,198,201,.35);
  font-size: 13px;
  font-weight: 500;
}

.textbox {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: calc(16px + var(--safe-bottom));
  min-height: 168px;
  padding: 18px 18px 28px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(10,18,20,.72), rgba(7,12,14,.9));
  border: 1px solid var(--line);
  backdrop-filter: blur(14px);
  z-index: 16;
}
#speaker {
  font-size: 13px;
  color: var(--accent);
  margin-bottom: 8px;
  min-height: 1em;
  font-weight: 600;
}
#dialogue {
  margin: 0;
  font-size: 15.5px;
  line-height: 1.75;
  font-weight: 400;
  white-space: pre-wrap;
  word-break: keep-all;
}
#next-cue {
  position: absolute;
  right: 16px;
  bottom: 12px;
  color: var(--accent);
  animation: blink 1.1s infinite;
  opacity: 0;
}
#next-cue.show { opacity: 1; }
@keyframes blink {
  0%, 100% { opacity: .25; transform: translateY(0); }
  50% { opacity: 1; transform: translateY(3px); }
}

.choices {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: calc(200px + var(--safe-bottom));
  display: grid;
  gap: 10px;
  z-index: 18;
}
.choice-btn {
  text-align: left;
  border: 1px solid rgba(62,198,201,.28);
  background: rgba(8, 18, 20, .82);
  color: var(--ink);
  border-radius: 14px;
  padding: 14px 16px;
  font: 400 14.5px/1.45 var(--font-ui);
  backdrop-filter: blur(10px);
}
.choice-btn:active {
  background: var(--accent-dim);
  border-color: var(--accent);
}

/* Cinematic */
#screen-cine {
  z-index: 30;
  background: #000;
  align-items: stretch;
  justify-content: flex-end;
}
#cine-video, .cine-fallback {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background-size: cover;
  background-position: center;
}
.cine-fallback.kenburns {
  animation: kenburns 10s ease-in-out infinite alternate;
}
#cine-caption {
  position: relative;
  z-index: 2;
  margin: 0 18px calc(28px + var(--safe-bottom));
  padding: 16px 18px;
  border-radius: 16px;
  background: rgba(0,0,0,.55);
  border: 1px solid var(--line);
  font-size: 15px;
  line-height: 1.7;
  min-height: 3.4em;
  backdrop-filter: blur(8px);
}
.cine-skip {
  position: absolute;
  top: calc(14px + var(--safe-top));
  right: 14px;
  z-index: 3;
  padding: 8px 12px;
  font-size: 12px;
  letter-spacing: .12em;
}

.panel {
  width: min(100%, 360px);
  background: rgba(10,16,18,.94);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 22px;
  display: grid;
  gap: 10px;
}
.panel.wide { width: min(100%, 420px); max-height: 80vh; overflow: auto; }
.panel h2 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 24px;
}
.save-note { margin: 4px 0 0; color: var(--muted); font-size: 12px; min-height: 1em; }

.gallery-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 8px;
}
.gallery-item {
  aspect-ratio: 3/4;
  border-radius: 12px;
  background-size: cover;
  background-position: center;
  border: 1px solid var(--line);
  position: relative;
  overflow: hidden;
}
.gallery-item.locked {
  filter: grayscale(1) brightness(.25);
}
.gallery-item span {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 8px;
  font-size: 11px;
  background: linear-gradient(transparent, rgba(0,0,0,.8));
}

#screen-ending {
  z-index: 35;
  align-items: flex-end;
  justify-content: flex-end;
  padding: 28px;
  background: linear-gradient(to top, rgba(0,0,0,.88), rgba(0,0,0,.25));
}
.ending-card { width: 100%; }
.ending-eyebrow {
  letter-spacing: .28em;
  color: var(--accent);
  font-size: 11px;
  margin: 0 0 10px;
}
#ending-title {
  font-family: var(--font-display);
  font-size: 34px;
  margin: 0 0 14px;
}
#ending-body {
  color: var(--muted);
  line-height: 1.75;
  margin: 0 0 24px;
  font-size: 15px;
}

.fx-flash { animation: flash .45s ease; }
@keyframes flash {
  0% { filter: brightness(1); }
  40% { filter: brightness(2.2); }
  100% { filter: brightness(1); }
}
.fx-shake { animation: shake .5s ease; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

@media (min-width: 900px) {
  #app { border-left: 1px solid #111; border-right: 1px solid #111; }
}
