/* ═══════════════════════════════════════════════════════════
   김아람 — 관측 갑판 (Observation Deck)
   three.js 우주 위의 HUD. 어두운 단일 테마는 의도된 선택.
   ═══════════════════════════════════════════════════════════ */

:root {
  --bg-0: #04070D;
  --bg-1: #070C16;
  --ink-0: #E8EEF7;
  --ink-1: #A9B4C4;
  --ink-2: #6D7887;
  --line: rgba(169, 180, 196, .16);
  --line-soft: rgba(169, 180, 196, .09);
  --star: #9FD4EC;
  --star-glow: rgba(159, 212, 236, .55);
  --mark: #58B9DF;
  --ref: rgba(169, 180, 196, .30);
  --hud-bg: rgba(5, 9, 16, .78);

  --serif: 'Noto Serif KR', 'Apple SD Gothic Neo', serif;
  --sans: 'Pretendard Variable', Pretendard, -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', sans-serif;
  --mono: 'SF Mono', ui-monospace, 'JetBrains Mono', Menlo, Consolas, monospace;

  --ease-out: cubic-bezier(.22, 1, .36, 1);
}

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

html, body { height: 100%; }

body {
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.8;
  color: var(--ink-1);
  background: radial-gradient(120% 90% at 72% -10%, var(--bg-1) 0%, var(--bg-0) 58%) fixed var(--bg-0);
  word-break: keep-all;
  overflow: hidden;
}

::selection { background: rgba(159, 212, 236, .24); color: var(--ink-0); }

:focus-visible { outline: 1px solid var(--star); outline-offset: 3px; }

a { color: var(--star); text-decoration: none; }
a:hover { text-decoration: underline; }
.serif { font-family: var(--serif); }
em { font-style: normal; color: var(--ink-0); }
strong { color: var(--ink-0); font-weight: 600; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

.noscript {
  position: fixed; inset: 0; z-index: 200;
  display: grid; place-content: center; gap: 12px;
  background: var(--bg-0); text-align: center; padding: 24px;
}

/* ── 우주 캔버스 ── */
#deck { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#deck.interactive { cursor: pointer; }

.grain {
  position: fixed; inset: -50%; z-index: 90; pointer-events: none; opacity: .04;
  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' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 240px;
}

/* ── 별 글리프 ── */
.star-glyph {
  display: inline-block; width: 9px; height: 9px; background: var(--star);
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
  animation: twinkle 4.5s ease-in-out infinite;
  flex: none;
}
.star-glyph.big { width: 18px; height: 18px; }
@keyframes twinkle {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .55; transform: scale(.82); }
}

/* ── 부팅 ── */
.boot {
  position: fixed; inset: 0; z-index: 150;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  background: var(--bg-0);
  transition: opacity 1s var(--ease-out), visibility 1s;
  pointer-events: none;
}
.boot.done { opacity: 0; visibility: hidden; }
.boot-line {
  font-family: var(--mono); font-size: 12px; letter-spacing: .22em; color: var(--ink-2);
  animation: bootPulse 1.6s ease-in-out infinite;
}
@keyframes bootPulse { 50% { opacity: .4; } }

/* ── HUD 공통 ── */
.hud-top, .roster, .hint, .panel, .chat { z-index: 100; }

.hud-top {
  position: fixed; top: 0; left: 0; right: 0;
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 18px clamp(16px, 3vw, 40px);
  pointer-events: none;
}
.hud-top > * { pointer-events: auto; }
.wordmark {
  font-family: var(--serif); font-size: 17px; font-weight: 600; color: var(--ink-0);
}
.wordmark:hover { text-decoration: none; }
.hud-status {
  margin-top: 4px;
  font-family: var(--mono); font-size: 10.5px; letter-spacing: .14em; color: var(--ink-2);
}
.hud-nav { display: flex; gap: 8px; }
.hud-nav button {
  font-family: var(--mono); font-size: 12px; letter-spacing: .1em; color: var(--ink-2);
  padding: 10px 16px; border: 1px solid transparent;
  transition: color .3s, border-color .3s, background-color .3s;
}
.hud-nav button:hover { color: var(--ink-0); border-color: var(--line); }
.hud-nav button.active { color: var(--star); border-color: var(--line); background: var(--hud-bg); }

/* ── 대상 목록 (좌하단) ── */
.roster {
  position: fixed; left: clamp(16px, 3vw, 40px); bottom: clamp(16px, 3vh, 36px);
  min-width: 240px;
  border: 1px solid var(--line);
  background: var(--hud-bg);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: 14px 0 6px;
}
.roster-title {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: .18em; color: var(--ink-2);
  padding: 0 16px 10px; border-bottom: 1px solid var(--line-soft);
}
.roster-title .en { margin-left: 8px; opacity: .55; }
.roster-row {
  display: flex; align-items: center; gap: 12px;
  width: 100%; text-align: left;
  padding: 9px 16px;
  transition: background-color .25s, color .25s;
}
.roster-row .no { font-family: var(--mono); font-size: 10.5px; color: var(--ink-2); width: 20px; flex: none; }
.roster-row .nm { font-size: 13.5px; color: var(--ink-1); flex: 1; }
.roster-row .dot {
  width: 7px; height: 7px; flex: none;
  transform: rotate(45deg) scale(.8);
  background: transparent; border: 1px solid var(--dotc, var(--ink-2));
  opacity: .75;
  transition: all .3s;
}
.roster-row:hover, .roster-row.hovered { background: rgba(159, 212, 236, .07); }
.roster-row:hover .nm, .roster-row.hovered .nm { color: var(--ink-0); }
.roster-row.focused .nm { color: var(--star); }
.roster-row.focused .dot, .roster-row.hovered .dot {
  background: var(--dotc, var(--star)); border-color: var(--dotc, var(--star));
  box-shadow: 0 0 10px var(--dotc, var(--star-glow));
  opacity: 1;
}

/* ── 조작 안내 ── */
.hint {
  position: fixed; bottom: clamp(16px, 3vh, 36px); left: 50%; transform: translateX(-50%);
  font-family: var(--mono); font-size: 11px; letter-spacing: .1em; color: var(--ink-2);
  background: var(--hud-bg); border: 1px solid var(--line-soft);
  padding: 10px 18px; white-space: nowrap;
  opacity: 0; transition: opacity 1s var(--ease-out);
  pointer-events: none;
}
.hint.show { opacity: 1; }

/* ── 타겟팅 레티클 ── */
.reticle {
  position: fixed; left: 0; top: 0;
  width: 64px; height: 64px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  opacity: 0; transition: opacity .25s;
}
.reticle.show { opacity: 1; }
.reticle i {
  position: absolute; width: 14px; height: 14px;
  border: 1px solid var(--star);
  filter: drop-shadow(0 0 4px var(--star-glow));
}
.reticle i:nth-child(1) { top: 0; left: 0; border-right: 0; border-bottom: 0; }
.reticle i:nth-child(2) { top: 0; right: 0; border-left: 0; border-bottom: 0; }
.reticle i:nth-child(3) { bottom: 0; left: 0; border-right: 0; border-top: 0; }
.reticle i:nth-child(4) { bottom: 0; right: 0; border-left: 0; border-top: 0; }
.reticle-name {
  position: absolute; top: calc(100% + 10px); left: 50%; transform: translateX(-50%);
  font-family: var(--mono); font-size: 11px; letter-spacing: .12em; color: var(--star);
  white-space: nowrap;
  text-shadow: 0 0 8px var(--star-glow);
}

/* ── 상세 패널 ── */
.panel {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(500px, 100vw);
  background: rgba(5, 9, 16, .92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-left: 1px solid var(--line);
  transform: translateX(102%);
  transition: transform .7s var(--ease-out);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.panel.open { transform: translateX(0); }
.panel-head {
  padding: 16px clamp(20px, 4vw, 32px);
  border-bottom: 1px solid var(--line-soft);
  flex: none;
}
.panel-back {
  font-family: var(--mono); font-size: 12px; letter-spacing: .1em; color: var(--ink-2);
  transition: color .3s;
}
.panel-back:hover { color: var(--star); }
.panel-body {
  padding: clamp(24px, 4vh, 40px) clamp(20px, 4vw, 32px) 48px;
  overflow-y: auto; overscroll-behavior: contain;
  scrollbar-width: thin; scrollbar-color: var(--line) transparent;
}

.p-eyebrow {
  font-family: var(--mono); font-size: 11px; letter-spacing: .18em; color: var(--star);
  margin-bottom: 14px;
}
.p-eyebrow .wip {
  margin-left: 8px; padding: 2px 7px;
  border: 1px solid var(--line); color: var(--ink-2); font-size: 10px;
}
.p-title {
  font-size: clamp(24px, 5vw, 32px); font-weight: 400; line-height: 1.45;
  color: var(--ink-0); letter-spacing: -.01em;
}
.p-sub { margin-top: 10px; color: var(--ink-1); font-size: 14.5px; }
.p-sub.mono-sub { font-family: var(--mono); font-size: 12px; letter-spacing: .06em; color: var(--ink-2); }
.p-block { margin-top: 30px; }
.p-label {
  font-family: var(--mono); font-size: 10.5px; font-weight: 400; letter-spacing: .2em;
  color: var(--ink-2);
  padding-top: 12px; border-top: 1px solid var(--line);
  margin-bottom: 12px;
}
.p-block p { font-size: 14.5px; line-height: 1.9; text-wrap: pretty; }
.p-quote {
  font-size: 17px; font-weight: 300; line-height: 1.8; color: var(--ink-0);
  margin: 14px 0;
}
.p-note {
  margin-top: 14px;
  font-family: var(--mono); font-size: 11px; line-height: 1.8; color: var(--ink-2);
}
.p-facts { list-style: none; }
.p-facts li {
  padding: 10px 0; border-top: 1px solid var(--line-soft);
  font-size: 13.5px; line-height: 1.8;
}
.p-plaque {
  margin-top: 30px; border: 1px solid var(--line);
  padding: 16px 18px; display: flex; flex-direction: column; gap: 8px;
}
.p-plaque > div { display: flex; gap: 14px; align-items: baseline; }
.p-plaque dt {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: .14em; color: var(--ink-2);
  flex: 0 0 40px;
}
.p-plaque dd { font-size: 12.5px; color: var(--ink-1); line-height: 1.7; }

/* 지표 바 — 단일 계열 + 회색 기준선 */
.metrics { margin-top: 4px; }
.metric {
  display: grid; grid-template-columns: minmax(84px, 110px) 1fr auto;
  align-items: center; gap: 12px; padding: 6px 0;
}
.m-name { font-family: var(--mono); font-size: 10.5px; color: var(--ink-2); }
.m-track { display: block; height: 5px; background: var(--line-soft); overflow: hidden; }
.m-fill {
  display: block; height: 100%; width: var(--w, 0%);
  background: var(--mark); border-radius: 0 3px 3px 0;
  transform: scaleX(0); transform-origin: 0 50%;
  transition: transform 1.1s var(--ease-out); transition-delay: var(--d, 0s);
}
.metric.ref .m-fill { background: var(--ref); }
.metrics.in .m-fill { transform: scaleX(1); }
.m-val {
  font-family: var(--mono); font-size: 12px; font-variant-numeric: tabular-nums;
  color: var(--ink-0); min-width: 48px; text-align: right;
}

/* 연보 (패널 내) */
.p-timeline { list-style: none; margin-top: 26px; }
.p-timeline li {
  display: flex; gap: 16px;
  padding: 13px 0; border-top: 1px solid var(--line-soft);
}
.p-timeline .y {
  font-family: var(--mono); font-size: 11px; letter-spacing: .12em; color: var(--star);
  flex: 0 0 44px; padding-top: 4px;
}
.p-timeline .t { font-size: 16px; color: var(--ink-0); }
.p-timeline .n { margin-top: 2px; font-size: 13px; color: var(--ink-1); }

/* ── 교신 채널 ── */
.chat {
  position: fixed; right: clamp(16px, 3vw, 40px); bottom: clamp(16px, 3vh, 36px);
  width: min(360px, calc(100vw - 32px));
  height: min(480px, calc(100dvh - 120px));
  display: flex; flex-direction: column;
  background: rgba(5, 9, 16, .92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  transform: translateY(14px);
  opacity: 0; visibility: hidden;
  transition: opacity .45s var(--ease-out), transform .45s var(--ease-out), visibility .45s;
}
.chat.open { opacity: 1; visibility: visible; transform: none; }
.chat-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--line-soft); flex: none;
}
.chat-name { font-size: 13.5px; font-weight: 600; color: var(--ink-0); line-height: 1.3; }
.chat-sub { font-family: var(--mono); font-size: 10px; letter-spacing: .08em; color: var(--ink-2); }
.chat-close {
  margin-left: auto; font-size: 18px; color: var(--ink-2); padding: 4px 8px;
  transition: color .3s;
}
.chat-close:hover { color: var(--ink-0); }
.chat-log {
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
  padding: 16px; display: flex; flex-direction: column; gap: 10px;
  scrollbar-width: thin; scrollbar-color: var(--line) transparent;
}
.msg {
  max-width: 86%;
  padding: 9px 13px;
  font-size: 13.5px; line-height: 1.7;
  border: 1px solid var(--line-soft);
  white-space: pre-line;
}
.msg.ai { align-self: flex-start; background: rgba(159, 212, 236, .05); color: var(--ink-1); }
.msg.me { align-self: flex-end; background: rgba(169, 180, 196, .07); color: var(--ink-0); }
.msg.ai b { color: var(--star); font-weight: 600; }
.chat-chips {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 0 16px 10px; flex: none;
}
.chat-chips button {
  font-family: var(--mono); font-size: 11px; color: var(--ink-2);
  border: 1px solid var(--line-soft); padding: 5px 10px;
  transition: color .25s, border-color .25s;
}
.chat-chips button:hover { color: var(--star); border-color: var(--line); }
.chat-form {
  display: flex; gap: 8px; padding: 12px 16px 14px;
  border-top: 1px solid var(--line-soft); flex: none;
}
.chat-form input {
  flex: 1; background: rgba(169, 180, 196, .06);
  border: 1px solid var(--line-soft); color: var(--ink-0);
  font: inherit; font-size: 13.5px; padding: 9px 12px; outline: none;
}
.chat-form input:focus { border-color: var(--line); }
.chat-form input::placeholder { color: var(--ink-2); }
.chat-form button {
  font-family: var(--mono); font-size: 14px; color: var(--star);
  border: 1px solid var(--line-soft); padding: 0 14px;
  transition: border-color .25s;
}
.chat-form button:hover { border-color: var(--star); }

/* 패널이 열려 있으면 교신 창을 그 왼쪽으로 비켜준다 */
@media (min-width: 721px) {
  body.panel-open .chat { right: calc(min(500px, 100vw) + 20px); }
}

/* ── 반응형 ── */
@media (max-width: 720px) {
  .roster { min-width: 0; left: 12px; right: auto; bottom: 12px; max-width: 60vw; }
  .roster-row { padding: 7px 12px; }
  .roster-row .nm { font-size: 12px; }
  .hint { display: none; }
  .panel { width: 100vw; }
  .chat {
    right: 12px; left: 12px; bottom: 12px; width: auto;
    height: min(420px, calc(100dvh - 100px));
  }
  .hud-nav button { padding: 6px 10px; font-size: 11px; }
}

/* ── 모션 감소 ── */
@media (prefers-reduced-motion: reduce) {
  .star-glyph, .boot-line { animation: none; }
  .panel, .chat, .m-fill, .reticle, .hint { transition: none; }
  .metrics .m-fill { transform: scaleX(1); }
}
