/* 밤의 고속도로 한 벌뿐이다. 밝은 테마는 두지 않는다. */
:root {
  color-scheme: dark;
  --asphalt: #1C2027;
  --asphalt-2: #262B34;
  --lane-blue: #2E6BFF;
  --led-amber: #FFB23F;
  --led-off: rgba(255, 178, 63, 0.10);
  --sign-white: #F4F6F8;
  --muted: #9AA3AF;
  --tunnel: #FF9A3C;
  --line: rgba(244, 246, 248, 0.14);
  --font-display: 'Do Hyeon', 'IBM Plex Sans KR', system-ui, sans-serif;
  --font-body: 'IBM Plex Sans KR', system-ui, -apple-system, 'Apple SD Gothic Neo', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
  --halo: 0 0 2px rgba(28, 32, 39, 0.95), 0 0 6px rgba(28, 32, 39, 0.9), 0 1px 14px rgba(28, 32, 39, 0.85), 0 0 30px rgba(28, 32, 39, 0.6);
  --gutter: 16px;
  --topbar-h: 64px;
}

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

/* display를 준 요소도 hidden이면 숨는다. 없으면 오류 상자·말풍선이 늘 보인다. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--asphalt);
  color: var(--sign-white);
  font-family: var(--font-body);
  word-break: keep-all;
  overflow-wrap: break-word;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

body {
  overflow: hidden;
  overscroll-behavior: none;
}

/* 아주 낮은 화면(가로로 눕힌 휴대폰)에서는 글이 잘리지 않게 세로로만 넘긴다. */
@media (max-height: 520px) {
  body { overflow-x: hidden; overflow-y: auto; }
}

button { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--lane-blue);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ── 배경: 도로와 원이 쌓이는 캔버스 ───────────────── */
.scene {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
}

.road {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(to bottom, rgba(12, 14, 18, 0.55), rgba(12, 14, 18, 0) 22%),
    var(--asphalt);
}

/* 버스전용차로 파란 점선. 화면 양옆에 차로 경계처럼 두 줄을 두고, 천천히 아래로 흘러 달리는 느낌만 준다.
   한 줄만 두면 넓은 화면에서 숫자판 모서리에 붙은 얼룩처럼 보였다. */
.lane {
  position: absolute;
  top: 0;
  bottom: 0;
  left: max(14px, 7%);
  right: max(14px, 7%);
  opacity: 0.32;
  background-image:
    repeating-linear-gradient(to bottom, var(--lane-blue) 0 46px, transparent 46px 104px),
    repeating-linear-gradient(to bottom, var(--lane-blue) 0 46px, transparent 46px 104px);
  background-size: 6px 104px, 6px 104px;
  background-repeat: repeat-y, repeat-y;
  background-position: left 0, right 0;
  animation: lane-flow 2.6s linear infinite;
}

@keyframes lane-flow {
  from { background-position: left 0, right 0; }
  to { background-position: left 104px, right 104px; }
}

.tunnel-lights {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 72px;
  display: none;
  background-size: 72px 220px;
  animation: tunnel-flow 2.4s linear infinite;
}
.tunnel-lights.left {
  left: 0;
  background-image: radial-gradient(ellipse 30px 46px at 0 50%, rgba(255, 154, 60, 0.55), rgba(255, 154, 60, 0.12) 55%, rgba(255, 154, 60, 0) 100%);
}
.tunnel-lights.right {
  right: 0;
  background-image: radial-gradient(ellipse 30px 46px at 100% 50%, rgba(255, 154, 60, 0.55), rgba(255, 154, 60, 0.12) 55%, rgba(255, 154, 60, 0) 100%);
}

@keyframes tunnel-flow {
  from { background-position: 0 0; }
  to { background-position: 0 220px; }
}

body[data-place="namsan3"] .lane { display: none; }
body[data-place="namsan3"] .tunnel-lights { display: block; }
body[data-place="namsan3"] .road {
  background:
    linear-gradient(to right, rgba(255, 154, 60, 0.06), rgba(255, 154, 60, 0) 18%, rgba(255, 154, 60, 0) 82%, rgba(255, 154, 60, 0.06)),
    linear-gradient(to bottom, rgba(12, 14, 18, 0.55), rgba(12, 14, 18, 0) 22%),
    var(--asphalt);
}

.pit {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: pan-y;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.tags {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.tag {
  position: absolute;
  top: calc(var(--topbar-h) + 6px);
  transform: translateX(-50%);
  padding: 3px 9px 3px 7px;
  border-radius: 999px;
  background: rgba(28, 32, 39, 0.88);
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
  white-space: nowrap;
  color: var(--sign-white);
  display: flex;
  align-items: center;
  gap: 6px;
  animation: tag-life 1.7s ease-out forwards;
}
.tag::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c, var(--led-amber));
}

@keyframes tag-life {
  0% { opacity: 0; transform: translate(-50%, -6px); }
  14% { opacity: 1; transform: translate(-50%, 0); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, 10px); }
}

/* ── 윗줄 ──────────────────────────────────────────── */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: max(12px, env(safe-area-inset-top)) max(var(--gutter), env(safe-area-inset-right)) 8px max(var(--gutter), env(safe-area-inset-left));
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }

.place-switch, .actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}
.actions { margin-left: auto; justify-content: flex-end; }

.pill, .ghost {
  appearance: none;
  -webkit-appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(38, 43, 52, 0.9);
  color: var(--sign-white);
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s;
}
.pill:hover, .ghost:hover { border-color: rgba(244, 246, 248, 0.34); }
.pill[aria-pressed="true"] {
  color: var(--led-amber);
  border-color: rgba(255, 178, 63, 0.6);
  background: rgba(58, 46, 26, 0.92);
}
.ghost[aria-pressed="true"] { border-color: rgba(255, 178, 63, 0.5); }
.ghost.small { min-height: 32px; padding: 0 12px; font-size: 13px; }
.ghost:disabled { opacity: 0.45; cursor: default; }
.ghost:disabled:hover { border-color: var(--line); }

/* ── 가운데 문장 ───────────────────────────────────── */
.stage {
  position: relative;
  z-index: 2;
  min-height: 100%;
  padding: calc(var(--topbar-h) + clamp(6px, 3.5vh, 44px)) var(--gutter) 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  pointer-events: none;
  /* 문장 뒤 어둠(hero::before)이 옆으로 넘쳐 휴대폰 화면 폭을 늘리지 않게 자른다. */
  overflow-x: hidden;
  overflow-x: clip;
}
.stage button { pointer-events: auto; }

.hero {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 100%;
}
/* 원이 뒤로 쌓여도 글이 읽히도록 문장 뒤만 살짝 어둡게. */
.hero::before {
  content: '';
  position: absolute;
  inset: -14% -16% -18%;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(closest-side, rgba(28, 32, 39, 0.66), rgba(28, 32, 39, 0.4) 55%, rgba(28, 32, 39, 0));
}

.demo-badge {
  margin: 0 0 10px;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--led-amber);
  color: #1C2027;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  box-shadow: 0 0 0 3px rgba(28, 32, 39, 0.7);
}

.headline {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(4px, 1vh, 12px);
  font-family: var(--font-display);
  font-weight: 400;
  line-height: 1.1;
  color: var(--sign-white);
  text-shadow: var(--halo);
  letter-spacing: -0.005em;
}
.line { display: block; font-size: clamp(27px, 4.1vw, 56px); }
.line-number {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 0.22em;
  max-width: 100%;
}
.led {
  display: block;
  flex: none;
  filter: drop-shadow(0 6px 24px rgba(0, 0, 0, 0.45));
}
/* `명이`의 밑줄을 판 바닥이 아니라 LED 글자 맨 아래 점에 맞춘다(--led-foot은 app.js가 잰다). */
.unit { flex: none; line-height: 1; padding-bottom: calc(var(--led-foot, 0px) - 0.04em); }

.line-number.beat { animation: beat 0.5s cubic-bezier(0.3, 1.6, 0.5, 1); }
@keyframes beat {
  0% { transform: scale(1); }
  35% { transform: scale(1.035); }
  100% { transform: scale(1); }
}

.meta-row {
  margin-top: clamp(12px, 2.4vh, 22px);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px 10px;
  padding: 4px 4px 4px 14px;
  border-radius: 22px;
  background: rgba(28, 32, 39, 0.84);
  border: 1px solid rgba(244, 246, 248, 0.08);
  max-width: 100%;
}
.meta {
  margin: 0;
  font-size: 14px;
  color: #C3C9D1;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0 4px;
}
.meta time, .meta .num { font-family: var(--font-mono); font-size: 13px; color: var(--sign-white); }
.cta { display: flex; gap: 6px; }

.stale-tag {
  margin-left: 4px;
  padding: 1px 7px;
  border-radius: 4px;
  border: 1px solid rgba(255, 178, 63, 0.55);
  color: var(--led-amber);
  font-size: 12px;
  line-height: 1.5;
}

.empty-note {
  margin: 14px 0 0;
  max-width: 30em;
  font-size: 15px;
  line-height: 1.55;
  color: var(--sign-white);
  text-shadow: var(--halo);
}

.error-box {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px 14px;
  padding: 12px 14px 12px 18px;
  border-radius: 16px;
  background: rgba(38, 43, 52, 0.95);
  border: 1px solid rgba(255, 138, 122, 0.45);
  max-width: 100%;
}
.error-box p { margin: 0; font-size: 15px; line-height: 1.5; }

body[data-state="loading"] .meta-row .cta,
body[data-state="error"] .meta-row { display: none; }

/* ── 떠 있는 것들 ──────────────────────────────────── */
.tip {
  position: fixed;
  z-index: 5;
  left: 0;
  top: 0;
  transform: translate(-50%, calc(-100% - 14px));
  padding: 7px 11px;
  border-radius: 10px;
  background: rgba(38, 43, 52, 0.97);
  border: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  font-size: 13px;
  line-height: 1.4;
  white-space: nowrap;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 7px;
}
.tip .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }

.toast {
  position: fixed;
  z-index: 6;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--sign-white);
  color: var(--asphalt);
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast:empty { display: none; }

/* ── 어떻게 셌나요? ────────────────────────────────── */
.sheet {
  width: min(560px, calc(100vw - 32px));
  max-height: min(84dvh, 760px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--asphalt-2);
  color: var(--sign-white);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
  overflow: auto;
  overscroll-behavior: contain;
}
.sheet::backdrop { background: rgba(10, 12, 16, 0.62); }
.sheet[open] { animation: sheet-in 0.22s ease-out; }
@keyframes sheet-in {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: none; }
}

.sheet-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 12px 22px;
  background: var(--asphalt-2);
  border-bottom: 1px solid rgba(244, 246, 248, 0.08);
}
.sheet-head h2 { margin: 0; font-family: var(--font-display); font-weight: 400; font-size: 26px; }
.sheet-body { padding: 6px 22px 24px; font-size: 15px; line-height: 1.6; }
.sheet-body h3 {
  margin: 22px 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.sheet-body p { margin: 8px 0; }
.sheet-body .facts { font-family: var(--font-mono); font-size: 14px; color: var(--led-amber); }
.sheet-body .note { font-size: 14px; color: #C3C9D1; }
.sheet-body .mono { font-family: var(--font-mono); font-size: 13px; color: #C3C9D1; }

.routes {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.routes th, .routes td { padding: 7px 0; border-bottom: 1px solid rgba(244, 246, 248, 0.07); }
.routes thead th { font-weight: 500; color: var(--muted); font-size: 12px; text-align: left; }
.routes tbody th { font-weight: 500; text-align: left; }
.routes th.n, .routes td.n { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.routes td.n { padding-left: 12px; }
.route-name { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; }
.route-name i { width: 10px; height: 10px; border-radius: 3px; flex: none; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; padding: 0; list-style: none; }
.chips li {
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 13px;
  background: rgba(28, 32, 39, 0.6);
}
.sources { margin: 6px 0; padding-left: 18px; font-size: 14px; color: #C3C9D1; }
.sources li { margin: 2px 0; }

/* 설명 창 맨 아래: 숫자의 출처인 메트로렌즈로 가는 조용한 길. */
.sheet-foot {
  margin: 0 22px 24px;
  padding-top: 16px;
  border-top: 1px solid rgba(244, 246, 248, 0.08);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  font-size: 14px;
  line-height: 1.55;
}
.sheet-foot p { margin: 0; color: #C3C9D1; }
.foot-cta {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 8px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 178, 63, 0.45);
  background: rgba(28, 32, 39, 0.6);
  color: var(--sign-white);
  font-weight: 500;
  text-decoration: none;
}
.foot-cta::after { content: '↗'; margin-left: 8px; color: var(--led-amber); }
.foot-cta:hover { border-color: var(--led-amber); }
.foot-sub { color: #C3C9D1; font-size: 13px; text-underline-offset: 3px; }
.foot-sub:hover { color: var(--sign-white); }

/* ── 공유 창 ───────────────────────────────────────── */
.share-note {
  margin: 4px 0 12px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 178, 63, 0.4);
  background: rgba(58, 46, 26, 0.5);
  font-size: 14px;
  line-height: 1.5;
}
/* 카드가 오기 전에도 1200×630 자리를 잡아 둔다. 창이 불러오는 도중에 늘었다 줄지 않게. */
.share-card {
  position: relative;
  margin: 4px 0 14px;
  aspect-ratio: 1200 / 630;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  background:
    radial-gradient(circle, rgba(255, 178, 63, 0.10) 1.6px, transparent 2.2px) 0 0 / 14px 14px,
    #0B0E13;
  display: grid;
  place-items: center;
}
.share-card img { display: block; width: 100%; height: 100%; object-fit: cover; }
.card-status { position: absolute; margin: 0; padding: 0 16px; text-align: center; font-size: 13px; color: #C3C9D1; }

.field { display: flex; flex-direction: column; gap: 6px; margin: 0 0 12px; }
.field label { font-size: 13px; font-weight: 600; color: #C3C9D1; }
.field-hint { font-weight: 400; color: var(--muted); }
.field select {
  appearance: none;
  -webkit-appearance: none;
  min-height: 42px;
  padding: 0 38px 0 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%239AA3AF' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 14px center,
    var(--asphalt);
  color: var(--sign-white);
  font: inherit;
  font-size: 15px;
}
.field select:hover { border-color: rgba(244, 246, 248, 0.34); }

.share-text {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(28, 32, 39, 0.7);
  font-size: 14px;
  line-height: 1.5;
  color: var(--sign-white);
}
/* 숨긴 단추(데모의 이미지 저장 등)가 있으면 남은 단추끼리 폭을 나눠 갖는다. */
.share-actions { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 8px; }
.btn {
  appearance: none;
  -webkit-appearance: none;
  min-height: 44px;
  padding: 0 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(28, 32, 39, 0.7);
  color: var(--sign-white);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}
.btn:hover { border-color: rgba(244, 246, 248, 0.34); }
.btn.primary { background: var(--led-amber); border-color: var(--led-amber); color: #1C2027; font-weight: 600; }
.btn.primary:hover { background: #FFC266; }
.btn:disabled { opacity: 0.45; cursor: default; }

/* ── 친구가 보낸 순간 ─────────────────────────────────── */
.moment-banner {
  position: fixed;
  z-index: 4;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100vw - 32px);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px 8px 16px;
  border-radius: 16px;
  border: 1px solid rgba(255, 178, 63, 0.4);
  background: rgba(38, 43, 52, 0.96);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  animation: banner-in 0.3s ease-out;
}
.moment-banner p { margin: 0; font-size: 14px; line-height: 1.45; color: var(--sign-white); }
.moment-banner .up { color: var(--led-amber); }
.banner-close {
  appearance: none;
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--sign-white);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.banner-close:hover { border-color: rgba(244, 246, 248, 0.34); }
@keyframes banner-in {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to { opacity: 1; transform: translateX(-50%); }
}
/* 띠가 떠 있으면 알림(토스트)을 그 위로 올린다. */
body.has-banner .toast { bottom: calc(max(16px, env(safe-area-inset-bottom)) + 72px); }

@media (max-width: 640px) {
  .pill, .ghost { min-height: 34px; padding: 0 11px; font-size: 13px; }
  .ghost.small { min-height: 32px; }
  .topbar { gap: 6px; padding-top: max(10px, env(safe-area-inset-top)); }
  .sheet {
    width: 100%;
    max-width: 100%;
    margin: auto 0 0;
    border-radius: 20px 20px 0 0;
    border-bottom: 0;
    max-height: 86dvh;
  }
  .sheet[open] { animation-name: sheet-up; }
  .meta-row { padding: 6px 8px; border-radius: 18px; }
  .meta { font-size: 13px; }
  .sheet-body { padding: 6px 16px 20px; }
  .sheet-foot { margin: 0 16px 20px; }
  .share-actions { gap: 6px; }
  .btn { padding: 0 6px; font-size: 14px; }
  .moment-banner { width: auto; left: 16px; right: 16px; transform: none; animation-name: banner-up; }
  .moment-banner p { font-size: 13px; }
}
@keyframes banner-up {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}
@keyframes sheet-up {
  from { transform: translateY(40px); opacity: 0.4; }
  to { transform: none; opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .lane, .tunnel-lights { animation: none; }
  .tag, .sheet[open], .line-number.beat, .moment-banner { animation: none; }
  .toast { transition: none; }
}
