*,
*::before,
*::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

html {
  color-scheme: dark;
  scroll-behavior: smooth;
}

body {
  background: var(--color-bg);
  color: var(--color-ink);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.6;
  word-break: keep-all;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  transition: background-color 0.7s ease, color 0.7s ease;
}

body.is-booting { overflow: hidden; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ---------- canvas + atmosphere overlays ---------- */

#space {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100vh;
  display: block;
  z-index: 0;
  opacity: 1;
  transition: opacity 1.2s ease;
}

.is-booting #space { opacity: 0; }

.grain {
  position: fixed;
  inset: -50%;
  z-index: 2;
  pointer-events: none;
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.vignette {
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(ellipse at center, transparent 38%, rgba(2, 3, 8, 0.95) 100%);
}

.whiteout {
  position: fixed;
  inset: 0;
  z-index: 45;
  pointer-events: none;
  opacity: 0;
  background: #f6f8ff;
}

/* ---------- boot ---------- */

.boot {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-content: center;
  gap: 1.4rem;
  text-align: center;
  background: #05070f;
  color: oklch(95% 0.01 260);
  transition: opacity 0.9s var(--ease-in-out), visibility 0.9s;
}

.boot-star {
  justify-self: center;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  /* 위성 비콘과 동일한 빨간불(흰 코어 + 빨간 헤일로) — 수미상관 */
  background: radial-gradient(circle, #fff 25%, #ff5545 80%);
  box-shadow: 0 0 18px 5px rgba(255, 69, 54, 0.85);
  animation: boot-breathe 2.2s var(--ease-in-out) infinite;
}

.boot-sub {
  margin: 0;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.32em;
  text-indent: 0.32em;
  opacity: 0.4;
  transition: opacity 0.28s ease;
}

body:not(.is-booting) .boot {
  opacity: 0;
  visibility: hidden;
}

@keyframes boot-breathe {
  0%, 100% { opacity: 0.4; transform: scale(0.9); }
  50% { opacity: 1; transform: scale(1.15); }
}

/* ---------- HUD (SOUND 토글만) ---------- */

.hud {
  position: fixed;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  justify-content: flex-end;
  align-items: baseline;
  gap: 1rem;
  padding-inline: var(--space-edge);
  pointer-events: none;
  transition: opacity 0.8s ease 0.3s, transform 0.8s var(--ease-out-expo) 0.3s;
}

.hud-top { top: clamp(0.9rem, 2.5vh, 1.6rem); }

.is-booting .hud {
  opacity: 0;
  transform: translateY(6px);
}

.hud-sound {
  pointer-events: auto;
  border: 0;
  background: transparent;
  padding: 0.3rem 0;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.16em;
  color: var(--color-muted);
  cursor: pointer;
  transition: color var(--duration-fast) ease;
}

.hud-sound:hover,
.hud-sound:focus-visible { color: var(--color-ink); }

.hud-sound:focus-visible {
  outline: 1px solid var(--accent-ice);
  outline-offset: 4px;
}

/* ---------- 포트폴리오 바로가기 (우측 하단) ---------- */

/* 기본 = 아주 작은 아이콘. 호버 시 라벨이 펼쳐진다 */
.jump-portfolio {
  position: fixed;
  right: var(--space-edge);
  bottom: clamp(1rem, 3vh, 1.8rem);
  z-index: 26;
  display: inline-flex;
  align-items: center;
  padding: 0.5rem;
  border: 1px solid var(--glass-line);
  border-radius: var(--radius-pill);
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--color-faint);
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.16em;
  cursor: pointer;
  transition: color var(--duration-fast) ease, border-color var(--duration-fast) ease,
              padding 0.4s var(--ease-out-expo), opacity 0.6s ease, transform 0.6s var(--ease-out-expo);
}

.jp-icon {
  display: inline-flex;
  width: 1.1em;
  justify-content: center;
  font-size: 0.85rem;
  line-height: 1;
}

.jp-label {
  max-width: 0;
  opacity: 0;
  overflow: hidden;
  white-space: nowrap;
  margin: 0;
  transition: max-width 0.4s var(--ease-out-expo), opacity 0.3s ease, margin 0.4s var(--ease-out-expo);
}

.jump-portfolio:hover,
.jump-portfolio:focus-visible {
  color: var(--color-ink);
  border-color: var(--accent-ice);
  padding: 0.5rem 0.95rem;
}

.jump-portfolio:hover .jp-label,
.jump-portfolio:focus-visible .jp-label {
  max-width: 14rem;
  opacity: 1;
  margin-right: 0.5rem;
}

.jump-portfolio:hover .jp-icon { transform: translateX(2px); transition: transform var(--duration-normal) var(--ease-out-expo); }

.jump-portfolio:focus-visible {
  outline: 1px solid var(--accent-ice);
  outline-offset: 3px;
}

/* 부팅 중 · 인트로를 벗어나면 숨김 (메인 화면에서만 노출) */
.is-booting .jump-portfolio,
.jump-portfolio.is-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
}

/* ---------- waypoint dots ---------- */

.waypoints {
  position: fixed;
  right: clamp(0.7rem, 2vw, 1.4rem);
  top: 50%;
  transform: translateY(-50%);
  z-index: 25;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  transition: opacity 0.8s ease 0.5s;
}

.is-booting .waypoints { opacity: 0; }

.waypoints button {
  position: relative;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.waypoints button::after {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--color-faint);
  transition: background var(--duration-fast) ease, box-shadow var(--duration-fast) ease,
              transform var(--duration-normal) var(--ease-out-expo);
}

.waypoints button:hover::after,
.waypoints button:focus-visible::after {
  background: var(--color-ink);
  transform: scale(1.5);
}

.waypoints button.is-active::after {
  background: var(--accent-ice);
  box-shadow: 0 0 10px 1px var(--accent-ice);
  transform: scale(1.6);
}

.waypoints button span {
  position: absolute;
  right: 26px;
  top: 50%;
  transform: translateY(-50%) translateX(6px);
  font-family: var(--font-mono);
  font-size: 0.58rem;
  letter-spacing: 0.22em;
  color: var(--color-muted);
  opacity: 0;
  white-space: nowrap;
  pointer-events: none;
  transition: opacity var(--duration-fast) ease, transform var(--duration-normal) var(--ease-out-expo);
}

.waypoints button:hover span,
.waypoints button:focus-visible span {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
}

.waypoints button:focus-visible {
  outline: 1px solid var(--accent-ice);
  outline-offset: 2px;
  border-radius: 50%;
}

/* ---------- stages: 컷별 스크롤 배분 (콘티 v3, 1스크롤 ≈ 100vh) ---------- */

main { position: relative; z-index: 10; }

.stage { position: relative; }

/* 텍스트 컷은 전부 160vh(핀 걸림 60vh)로 통일 — 머무르는 시간 동일 */
.stage-intro { min-height: 150vh; }    /* 컷01 */
#s-drift1 { min-height: 160vh; }       /* 컷02 */
#s-drift2 { min-height: 160vh; }       /* 컷03 */
.stage-pain { min-height: 380vh; }     /* 컷04 — 빈 우주에 "애매한 결과물"만 오래 (문장→핵심어→스르륵) */
.stage-dive { min-height: 550vh; }     /* 컷05 — 텍스트당 여유, 마지막 텍스트 체류는 절반 */
.stage-cross { min-height: 280vh; }    /* 컷06 — 워프 + 통과 후 무언의 호흡 */
.stage-reveal { min-height: 160vh; }   /* 컷07 */
.stage-identity { min-height: 160vh; } /* 컷08 */
.stage-system { min-height: 240vh; }   /* 컷10 ★ (실수로 지나치지 않게 여유) */
.stage-pact { min-height: 160vh; }     /* 컷11 — 턴 */
.stage-pact2 { min-height: 160vh; }    /* 컷11b — 같은 항로 */
.stage-travel { min-height: 100vh; }   /* 컷12 — 항행 (접근은 원래대로, 속도 이슈는 컷11 턴이었음) */
.stage-contact { min-height: 160vh; }  /* 컷13 */

/* ---------- intro ---------- */

.intro-pin {
  position: sticky;
  top: 0;
  min-height: 100vh;
  display: grid;
  place-content: center;
  text-align: center;
  padding-inline: var(--space-edge);
}

.intro-inner {
  transition: opacity 0.9s ease 0.5s, transform 0.9s var(--ease-out-expo) 0.5s;
}

.is-booting .intro-inner {
  opacity: 0;
  transform: translateY(14px);
}

.intro-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(2.6rem, 1.6rem + 5vw, 5.4rem);
  letter-spacing: -0.02em;
  line-height: 1.05;
}

.scroll-cue {
  position: absolute;
  left: 50%;
  bottom: 7vh;
  transform: translateX(-50%);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.3em;
  color: var(--color-faint);
  animation: hint-pulse 3.2s ease-in-out infinite;
}

.scroll-cue-arrow {
  display: inline-block;
  animation: cue-drop 2.2s var(--ease-in-out) infinite;
}

@keyframes hint-pulse {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 0.9; }
}

@keyframes cue-drop {
  0%, 100% { transform: translateY(-2px); }
  50% { transform: translateY(3px); }
}

/* ---------- 공용 라인 핀 + 등장 ---------- */

.line-pin {
  position: sticky;
  top: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  text-align: center;
  padding-inline: var(--space-edge);
}

/* 밝은 배경(은하·성운) 위 가독성 — 카피 뒤 소프트 다크 비네트 공통 적용 */
.beat-line,
.pain-quote,
.reveal-line,
.identity-block,
.pact-block,
.pact2-line {
  padding: 1.1em 2em;
  border-radius: 999px;
  background: radial-gradient(ellipse closest-side, rgba(5, 7, 15, 0.52), rgba(5, 7, 15, 0.26) 58%, transparent);
}

.beat-line,
.pain-quote,
.reveal-line,
.identity-block,
.pact2-line {
  opacity: 0;
  transform: translateY(26px);
  filter: blur(6px);
  transition: opacity 1.1s ease, transform 1.1s var(--ease-out-expo), filter 1.1s ease;
}

.is-visible .beat-line,
.is-visible .pain-quote,
.is-visible .reveal-line,
.is-visible .identity-block,
.is-visible .pact2-line {
  opacity: 1;
  transform: translateY(0);
  filter: blur(0);
}

/* 컷02·03 — 표류 독백 */
.beat-line {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--text-copy);
  line-height: 1.7;
  text-shadow: 0 2px 24px rgba(3, 5, 12, 0.8);
}

/* 컷03 마지막 줄 — 스크롤 진행에 맞춰 페이드인 (main.js가 is-on 토글) */
.beat-strong {
  display: block;
  margin-top: 1.1em;
  font-weight: 600;
  opacity: 0;
  transform: translateY(12px);
  filter: blur(5px);
  transition: opacity 0.9s ease, transform 0.9s var(--ease-out-expo), filter 0.9s ease;
}

.beat-strong.is-on {
  opacity: 1;
  transform: translateY(0);
  filter: blur(0);
}

/* 컷04 — 페인의 정점, 대형 타이포 */
.pain-quote { margin: 0; }

.pain-quote p {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-copy);
  line-height: 1.6;
  letter-spacing: -0.015em;
}

/* 강조 하이라이트 — 크기는 그대로, 색·굵기로만 */
.hl {
  font-style: normal;
  font-weight: 600;
  color: var(--accent-ice);
}

/* 컷04 3단계: 문장 전체 → "애매한 결과물"만 잔류 → 흩어지듯 페이드아웃 (main.js 스크롤 연동) */
.pain-rest {
  transition: opacity 0.9s ease, filter 0.9s ease;
}

.pain-quote.is-core .pain-rest {
  opacity: 0;
  filter: blur(7px);
}

.pain-core {
  display: inline-block;
  transition: opacity 1.5s ease, filter 1.5s ease,
              letter-spacing 1.5s var(--ease-out-expo), transform 1.5s ease;
}

.pain-quote.is-gone .pain-core {
  opacity: 0;
  filter: blur(12px);
  letter-spacing: 0.45em;
  transform: translateY(-14px);
}

/* 컷05 — 탈출 시퀀스 (블랙홀과 겹치지 않게 상단 배치) */
.dive-pin {
  align-items: start;
  padding-top: 13vh;
}

.dive-lines {
  grid-area: 1 / 1;
  display: grid;
  gap: 1.15rem;
  transition: opacity 0.6s ease;
}

.dive-lines.is-dim { opacity: 0; } /* 벗어나죠 등장 시 텍스트123 완전 아웃 */

.dive-line {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--text-copy);
  color: var(--color-muted);
  opacity: 0;
  transform: translateY(16px);
  filter: blur(4px);
  transition: opacity 0.7s ease, transform 0.7s var(--ease-out-expo), filter 0.7s ease;
}

.dive-line.is-on {
  opacity: 1;
  transform: translateY(0);
  filter: blur(0);
}

.dive-escape {
  grid-area: 1 / 1;
  place-self: center; /* 가르강튀아 정중앙 */
  margin: 0;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: var(--text-copy);
  letter-spacing: -0.02em;
  opacity: 0;
  transform: scale(0.94);
  filter: blur(8px);
  transition: opacity 0.8s ease, transform 0.8s var(--ease-out-expo), filter 0.8s ease;
}

.dive-escape.is-on {
  opacity: 1;
  transform: scale(1);
  filter: blur(0);
  color: var(--accent-ice);
  /* 뒤판 없음(그림자가 BH를 가림) — 어두운 텍스트 셰도우만 겹겹이 */
  text-shadow: 0 1px 4px rgba(5, 7, 15, 0.95),
               0 2px 16px rgba(5, 7, 15, 0.9),
               0 4px 44px rgba(5, 7, 15, 0.75),
               0 0 26px color-mix(in srgb, var(--accent-ice) 45%, transparent);
}

/* 컷07 — 반전 */
.reveal-line {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--text-copy);
  line-height: 1.7;
  letter-spacing: -0.01em;
  text-shadow: 0 2px 28px rgba(3, 5, 12, 0.85);
}

/* 컷08 — 다짐 */
.identity-line {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--text-copy);
  letter-spacing: -0.01em;
  line-height: 1.7;
  text-shadow: 0 2px 30px rgba(3, 5, 12, 0.85);
}

/* 컷11 — 제안 (턴 완료 후 스크롤 연동 등장, main.js가 is-on 토글) */
.pact-block {
  opacity: 0;
  transform: translateY(26px);
  filter: blur(6px);
  transition: opacity 1.1s ease, transform 1.1s var(--ease-out-expo), filter 1.1s ease;
}

.pact-block.is-on {
  opacity: 1;
  transform: translateY(0);
  filter: blur(0);
}

.pact-line {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--text-copy);
  line-height: 1.7;
  letter-spacing: -0.01em;
  text-shadow: 0 2px 26px rgba(3, 5, 12, 0.85);
}

/* 컷11b — 같은 항로 (감동 컷, 히어로) */
.pact2-line {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: var(--text-copy);
  line-height: 1.4;
  letter-spacing: -0.015em;
  text-shadow: 0 2px 28px rgba(3, 5, 12, 0.85);
}

/* ---------- system act (컷10) ---------- */

.system-pin {
  position: sticky;
  top: 0;
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  padding: 14vh var(--space-edge) 0;
  pointer-events: none;
}

.system-head {
  max-width: 480px;
  opacity: 0;
  transform: translateY(24px);
  transition: opacity 0.9s ease, transform 0.9s var(--ease-out-expo);
}

.is-visible .system-head {
  opacity: 1;
  transform: translateY(0);
}

.system-title {
  margin: 0.5rem 0 0.6rem;
  font-family: var(--font-display);
  font-size: var(--text-copy);
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.25;
  text-shadow: 0 2px 24px rgba(3, 5, 12, 0.85);
}

.system-sub {
  margin: 0;
  font-size: var(--text-base);
  color: var(--accent-ice);
  text-shadow: 0 0 18px color-mix(in srgb, var(--accent-ice) 40%, transparent),
               0 2px 18px rgba(3, 5, 12, 0.9);
}

.system-sub-star {
  display: inline-block;
  margin-right: 0.3rem;
  animation: hint-pulse 2.6s ease-in-out infinite;
}

/* ---------- 별 라벨 (system act) ---------- */

.node {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  padding: 0.5rem 0.8rem;
  border: 0;
  background: transparent;
  color: var(--color-ink);
  font-family: var(--font-display);
  cursor: pointer;
  will-change: transform;
  transform-origin: left center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.45s ease, color 0.7s ease;
  --accent: var(--accent-ice);
}

.node[data-accent="teal"] { --accent: var(--accent-teal); }
.node[data-accent="violet"] { --accent: var(--accent-violet); }
.node[data-accent="ice"] { --accent: var(--accent-ice); }
.node[data-accent="alert"] { --accent: var(--accent-alert); }
.node[data-accent="gold"] { --accent: var(--accent-gold); }

body.in-system:not(.is-away) .node {
  opacity: 1;
  pointer-events: auto;
}

.node-meta {
  display: flex;
  align-items: baseline;
  gap: 0.55rem;
  text-align: left;
}

.node-title {
  font-size: clamp(0.95rem, 0.88rem + 0.4vw, 1.25rem);
  font-weight: 500;
  white-space: nowrap;
  text-shadow: 0 1px 14px rgba(3, 5, 12, 0.9);
  transition: letter-spacing var(--duration-normal) var(--ease-out-expo),
              color var(--duration-normal) ease;
}

.node:hover .node-title,
.node:focus-visible .node-title {
  letter-spacing: 0.05em;
  color: var(--accent);
}

.node:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 5px;
  border-radius: var(--radius-pill);
}

/* ---------- 이스터에그 게임 (콕핏 유성 방어전) ---------- */

body.is-gaming { overflow: hidden; }

.game {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: #020409;
  cursor: crosshair;
}

.game[hidden] { display: none; }

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* 콕핏 프레임 — 비네트 + 창틀 기둥 + 대시보드 실루엣 */
.game-cockpit {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(to top, #0b0f1c 0%, rgba(11, 15, 28, 0.85) 7%, transparent 16%),
    radial-gradient(ellipse at center 42%, transparent 52%, rgba(2, 4, 9, 0.92) 100%);
}

.game-cockpit::before,
.game-cockpit::after {
  content: "";
  position: absolute;
  top: -6%;
  bottom: 10%;
  width: clamp(46px, 7vw, 110px);
  background: linear-gradient(90deg, #0a0e1a, #141a2c 55%, #0a0e1a);
  box-shadow: 0 0 34px rgba(0, 0, 0, 0.8);
}

.game-cockpit::before { left: -1%; transform: rotate(7deg); }
.game-cockpit::after { right: -1%; transform: rotate(-7deg); }

.game-hud {
  position: absolute;
  top: clamp(0.9rem, 2.5vh, 1.6rem);
  left: 0;
  right: 0;
  display: flex;
  align-items: baseline;
  gap: 1.4rem;
  padding-inline: var(--space-edge);
  font-family: var(--font-mono);
  letter-spacing: 0.14em;
}

.game-score { margin: 0; color: var(--accent-teal); font-size: var(--text-sm); }
.game-lives { margin: 0; color: var(--accent-alert); font-size: var(--text-sm); letter-spacing: 0.3em; }

.game-exit {
  margin-left: auto;
  border: 1px solid var(--glass-line);
  border-radius: var(--radius-pill);
  background: rgba(9, 13, 28, 0.6);
  color: var(--color-muted);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.16em;
  padding: 0.45rem 1rem;
  cursor: pointer;
  transition: color var(--duration-fast) ease, border-color var(--duration-fast) ease;
}

.game-exit:hover,
.game-exit:focus-visible { color: var(--color-ink); border-color: var(--accent-ice); }

.game-hint {
  position: absolute;
  left: 50%;
  bottom: 3.2vh;
  transform: translateX(-50%);
  margin: 0;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.2em;
  color: var(--color-faint);
  animation: hint-pulse 3s ease-in-out infinite;
}

/* ---------- noscript ---------- */

.noscript-box {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-content: center;
  gap: 0.4rem;
  text-align: center;
  background: #05070f;
  color: oklch(95% 0.01 260);
}

.noscript-box a { color: #9db8ff; }

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  html { scroll-behavior: auto; }
}

/* ---------- mobile ---------- */

@media (max-width: 720px) {
  .waypoints { gap: 0.65rem; }
  .waypoints button span { display: none; }

  .system-pin { padding-top: 11vh; }
}
