:root {
  --bg: #050607;
  --ink: #e9eef0;
  --muted: #8b979c;
  --accent: #7fe3dc; /* 스토리 맵의 청록색 */
  --line: rgba(127, 227, 220, 0.35);
  --ratio: 640 / 297; /* 영상 원본 화면비(아나모픽 1920x1080, SAR 40:33) */
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body {
  font-family: "IBM Plex Sans KR", system-ui, sans-serif;
  font-weight: 300;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

#app {
  height: 100%;
  display: grid;
  place-items: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#stage {
  position: relative;
  width: min(100vw, calc(100vh * 640 / 297));
  width: min(100vw, calc(100dvh * 640 / 297));
  aspect-ratio: var(--ratio);
  background: #000;
  overflow: hidden;
}

.layer {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: fill; /* 무대 비율 = 영상 표시 비율이므로 그대로 채움 */
  opacity: 0;
  transition: opacity .35s ease;
}
.layer.on { opacity: 1; }

/* ── 선택 버튼(영상 속 쪽지 위에 투명하게 겹침) */
#hotspots { position: absolute; inset: 0; pointer-events: none; }
.spot {
  position: absolute;
  pointer-events: auto;
  border: 0; padding: 0; margin: 0;
  background: transparent;
  border-radius: 14px;
  cursor: pointer;
  outline: 1.5px solid transparent;
  outline-offset: 2px;
  transition: outline-color .2s, box-shadow .2s, background .2s;
  animation: spotIn .5s ease both;
}
.spot:hover, .spot:focus-visible {
  outline-color: var(--accent);
  box-shadow: 0 0 0 6px rgba(127,227,220,.12), 0 0 40px rgba(127,227,220,.25);
  background: rgba(127,227,220,.06);
}
.spot .key {
  position: absolute; top: -10px; left: -10px;
  width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center;
  font: 500 12px/1 "IBM Plex Sans KR", sans-serif;
  color: #031312; background: var(--accent);
  opacity: 0; transform: scale(.7);
  transition: opacity .2s, transform .2s;
}
.spot:hover .key, .spot:focus-visible .key, body.kbd .spot .key { opacity: 1; transform: none; }
.spot.chosen { background: rgba(127,227,220,.25); outline-color: var(--accent); }
body.debug .spot { outline: 1px dashed #ff4d6d; background: rgba(255,77,109,.15); }
@keyframes spotIn { from { opacity: 0; } to { opacity: 1; } }

.hint {
  position: absolute; left: 50%; top: 9%;
  transform: translateX(-50%);
  padding: .45em 1em;
  font-size: clamp(11px, 1.15vw, 15px);
  letter-spacing: .04em;
  color: var(--ink);
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(6px);
  border: 1px solid var(--line);
  border-radius: 999px;
  pointer-events: none;
  animation: spotIn .6s ease both;
}

/* ── 시작/엔딩 화면 */
.screen {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: clamp(8px, 1.6vw, 18px);
  text-align: center;
  padding: 4%;
  background:
    radial-gradient(120% 90% at 50% 40%, rgba(5,6,7,.35), rgba(5,6,7,.92) 70%),
    rgba(5,6,7,.55);
  backdrop-filter: blur(2px);
  z-index: 5;
  animation: spotIn .6s ease both;
}
.screen[hidden] { display: none; }
.eyebrow {
  margin: 0;
  font-size: clamp(10px, 1vw, 13px);
  letter-spacing: .35em; text-transform: uppercase;
  color: var(--accent);
}
h1, h2 {
  margin: 0;
  font-family: "Gowun Batang", serif;
  font-weight: 700;
  letter-spacing: -.01em;
}
h1 { font-size: clamp(28px, 5vw, 64px); }
h2 { font-size: clamp(22px, 3.4vw, 44px); }
.lede { margin: 0; color: var(--muted); font-size: clamp(12px, 1.3vw, 17px); line-height: 1.7; }
.sub { margin: 0; color: var(--muted); font-size: clamp(11px, 1vw, 14px); min-height: 1em; }
.row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

button { font: inherit; color: inherit; }
.primary, .ghost {
  padding: .8em 1.8em;
  border-radius: 999px;
  font-size: clamp(13px, 1.2vw, 16px);
  font-weight: 500;
  cursor: pointer;
  transition: transform .15s, background .2s, color .2s;
}
.primary { border: 1px solid var(--accent); background: var(--accent); color: #031312; }
.primary:hover { transform: translateY(-1px); background: #a6f0ea; }
.ghost { border: 1px solid var(--line); background: transparent; color: var(--ink); }
.ghost:hover { border-color: var(--accent); }

.dots { list-style: none; display: flex; gap: 10px; padding: 0; margin: 4px 0 0; }
.dots li {
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 500;
  border: 1px solid var(--line); color: var(--muted);
}
.dots li.got { background: rgba(127,227,220,.15); color: var(--accent); border-color: var(--accent); }
.dots li.now { background: var(--accent); color: #031312; }

.path {
  list-style: none; margin: 6px 0 0; padding: 0;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 0;
  max-width: 90%;
  font-size: clamp(10px, .95vw, 13px);
  color: var(--muted);
}
.path li { display: flex; align-items: center; }
.path li + li::before { content: ""; width: 18px; border-top: 1px dashed var(--line); margin: 0 6px; }
.path li.pick { color: var(--accent); }

#spinner {
  position: absolute; left: 50%; top: 50%;
  width: 34px; height: 34px; margin: -17px;
  border: 2px solid rgba(255,255,255,.15); border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .9s linear infinite;
  z-index: 4;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── 하단 조작바: 마우스를 움직일 때만 보임 */
#controls {
  position: fixed; left: 50%; bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(720px, calc(100vw - 32px));
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  background: rgba(10,12,13,.7);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 999px;
  transition: opacity .4s, transform .4s;
  z-index: 10;
}
#controls[hidden] { display: none; }
body.idle #controls { opacity: 0; transform: translate(-50%, 8px); pointer-events: none; }
body.idle { cursor: none; }
.icon {
  flex: none;
  width: 34px; height: 34px; border-radius: 50%;
  border: 0; background: transparent; cursor: pointer;
  font-size: 14px; color: var(--ink);
}
.icon:hover { background: rgba(255,255,255,.08); }
.icon:disabled { opacity: .3; cursor: default; background: none; }
#progress { flex: 1; height: 3px; background: rgba(255,255,255,.12); border-radius: 3px; overflow: hidden; }
#bar { height: 100%; width: 0; background: var(--accent); }
#sceneName {
  flex: none; max-width: 34%;
  font-size: 12px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

@media (max-width: 560px) {
  #sceneName { display: none; }
}

/* 세로 모바일: 가로로 돌리라고 안내 */
@media (orientation: portrait) and (max-width: 820px) {
  #app::after {
    content: "가로로 돌리면 더 크게 볼 수 있어요";
    position: fixed; left: 0; right: 0; bottom: 90px;
    text-align: center; font-size: 12px; color: var(--muted);
  }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ───────── 메인 포스터 ───────── */
body.on-landing { background: #f1efea; }
#landing { position: fixed; inset: 0; overflow: hidden; background: #f1efea; }
#landing[hidden] { display: none; }
#poster { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#posterImg { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

/* 포스터 속 글자 위 클릭 영역 */
.word {
  position: absolute;
  display: block;
  border: 0; padding: 0; margin: 0;
  background: transparent;
  cursor: pointer;
  border-radius: 6px;
  outline: none;
  z-index: 2;
}
.word::after {
  /* 마우스를 올리면 글자 밑에 빨간 손글씨 밑줄 느낌 */
  content: "";
  position: absolute; left: 4%; right: 4%; bottom: -8%;
  height: 3px; border-radius: 3px;
  background: #e0242b;
  transform: scaleX(0); transform-origin: left;
  transition: transform .25s ease;
}
.word:hover::after, .word:focus-visible::after { transform: scaleX(1); }
.word .tip {
  position: absolute; left: 50%; top: calc(100% + 14px);
  transform: translate(-50%, -4px);
  white-space: nowrap;
  padding: .35em .8em;
  font: 400 clamp(11px, 1vw, 14px)/1 "Special Elite", "IBM Plex Sans KR", monospace;
  color: #f1efea; background: #111;
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.word:hover .tip, .word:focus-visible .tip { opacity: 1; transform: translate(-50%, 0); }

.landing-hint {
  position: absolute; left: 50%; bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  margin: 0;
  padding: .55em 1.1em;
  font: 400 clamp(11px, 1vw, 13px)/1.2 "Special Elite", "IBM Plex Sans KR", monospace;
  letter-spacing: .02em;
  color: #222;
  background: rgba(241,239,234,.82);
  border: 1px solid rgba(0,0,0,.12);
  white-space: nowrap;
  pointer-events: none;
  z-index: 2;
  animation: hintBlink 3.2s steps(1) infinite;
}
.landing-hint b { color: #e0242b; font-weight: 400; }
@keyframes hintBlink { 0%, 92% { opacity: 1; } 94% { opacity: .2; } 96% { opacity: 1; } 98% { opacity: .4; } }
.collected {
  position: absolute; right: 16px; top: 14px; margin: 0;
  font: 400 12px/1 "Special Elite", monospace; color: #555;
  z-index: 2;
}
#app[hidden] { display: none; }

/* ── Figma와 똑같이: 선택 영역은 보이지 않고, 그 자리에서 커서만 손가락으로 */
.spot, .spot:hover, .spot:focus-visible, .spot.chosen {
  background: transparent; outline: none; box-shadow: none; animation: none;
}
.spot:focus-visible { outline: 1px dashed rgba(127,227,220,.6); } /* 키보드 탭 이동 시에만 */
.spot .key { display: none; }
body.debug .spot { outline: 1px dashed #ff4d6d; background: rgba(255,77,109,.15); }

/* ── 스토리 맵 오버레이(영상은 뒤에서 계속 재생) */
#mapOverlay {
  position: absolute; inset: 0; z-index: 3;
  background: rgba(0, 0, 0, .55);
}
#mapOverlay[hidden] { display: none; }
#mapOverlay img { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
