/* ---------- 디자인 토큰 ---------- */
:root {
  color-scheme: dark;
  --bg: #14152A;          /* 공연장 조명이 꺼진 밤 */
  --surface: #1E2040;
  --line: #2E3160;
  --text: #EEEDF7;
  --muted: #9A9CC0;

  --fri: #FF7A5C;         /* 요일별 색: 하루 단위로 정보를 구분 */
  --sat: #4FA3FF;
  --sun: #F5C33B;
  --day: var(--fri);

  --sing: #FF9466;        /* 응원 종류별 색 */
  --call: #C08CFF;
  --clap: #5CC2FF;
  --wave: #FF72B6;
  --towel: #5FD38A;
  --jump: #FFD43B;

  --ja: "Noto Sans JP", "Pretendard Variable", sans-serif;
  --ko: "Pretendard Variable", Pretendard, system-ui, sans-serif;
  --radius: 14px;
}
/* 라이트 테마: 기기 설정이 라이트이고 직접 다크를 고르지 않았을 때, 또는 직접 라이트를 골랐을 때 (assets/theme.js) */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #F3F3F8; --surface: #FFFFFF; --line: #DCDCEA;
    --text: #17182E; --muted: #63658A;
    --fri: #E2532F; --sat: #2272D9; --sun: #B98500;
    --sing: #D9622E; --call: #8A4FD6; --clap: #1C8AC9; --wave: #D23C86; --towel: #1F9A55; --jump: #9A7400;
  }
}
:root[data-theme="light"] {
    color-scheme: light;
    --bg: #F3F3F8; --surface: #FFFFFF; --line: #DCDCEA;
    --text: #17182E; --muted: #63658A;
    --fri: #E2532F; --sat: #2272D9; --sun: #B98500;
    --sing: #D9622E; --call: #8A4FD6; --clap: #1C8AC9; --wave: #D23C86; --towel: #1F9A55; --jump: #9A7400;
}
:root[data-theme="dark"] { color-scheme: dark; }
[data-day="fri"] { --day: var(--fri); }
[data-day="sat"] { --day: var(--sat); }
[data-day="sun"] { --day: var(--sun); }

/* ---------- 기본 ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--ko); line-height: 1.5;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
a { color: inherit; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--day); outline-offset: 2px; }
.loading, .empty { color: var(--muted); padding: 48px 20px; text-align: center; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; text-decoration: none; letter-spacing: -0.02em; }
.brand span { color: var(--muted); font-weight: 600; }
.unofficial { font-size: 12px; color: var(--muted); }
.topbar-right { display: flex; align-items: center; gap: 10px; min-width: 0; }
.theme-toggle { flex: none; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
  color: var(--text); font-size: 12px; font-weight: 700; cursor: pointer; white-space: nowrap; }
main { max-width: 1280px; margin: 0 auto; padding: 0 20px 120px; outline: none; }

/* ---------- 홈: 요일 탭 + 타임테이블 ---------- */
.hero { padding: 40px 0 24px; }
.hero h1 { font-size: clamp(36px, 7vw, 72px); line-height: 1; margin: 0; letter-spacing: -0.04em; font-weight: 900; }
.hero p { color: var(--muted); margin: 12px 0 0; }

.days { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 24px 0 16px; }
.day-tab {
  display: flex; align-items: baseline; gap: 10px; padding: 14px 16px;
  border: 1px solid var(--line); border-radius: var(--radius);
  text-decoration: none; background: var(--surface);
}
.day-tab b { font-size: 28px; font-weight: 900; color: var(--day); }
.day-tab span { color: var(--muted); font-size: 14px; }
.day-tab[aria-current="page"] { background: var(--day); border-color: var(--day); }
.day-tab[aria-current="page"] b, .day-tab[aria-current="page"] span { color: var(--bg); }

.gate { color: var(--muted); font-size: 14px; margin: 0 0 12px; }
.stage-filter { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.stage-filter button {
  padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: transparent; cursor: pointer; font-size: 14px; font-weight: 600;
}
.stage-filter button[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.stage-tag, .now-tag {
  display: inline-block; font-style: normal; font-size: 11px; font-weight: 700;
  padding: 2px 7px; border-radius: 6px; margin-right: 8px; vertical-align: 3px;
}
.stage-wonder { background: var(--day); color: var(--bg); }
.stage-livet { border: 1px solid var(--day); color: var(--day); }
.now-tag { background: var(--text); color: var(--bg); }
.slot.is-now { background: var(--surface); border-radius: var(--radius); }
.search {
  width: 100%; padding: 12px 14px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit;
}
.timetable { list-style: none; padding: 0; margin: 16px 0 0; }
.slot {
  display: grid; grid-template-columns: 88px 1fr auto; gap: 16px; align-items: center;
  padding: 16px 4px; border-bottom: 1px solid var(--line); text-decoration: none;
}
.slot:hover .slot-name { color: var(--day); }
.slot-time { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--day); }
.slot-time small { display: block; color: var(--muted); font-weight: 500; font-size: 12px; }
.slot-name { font-size: 18px; font-weight: 700; }
.slot-name small { display: block; font-family: var(--ja); font-size: 13px; color: var(--muted); font-weight: 500; }
.slot-count { font-size: 13px; color: var(--muted); white-space: nowrap; }
.slot-count.has { color: var(--text); }

/* ---------- 아티스트 페이지 ---------- */
.crumb { display: inline-block; margin: 24px 0 8px; color: var(--muted); text-decoration: none; font-size: 14px; }
.artist-head h1 { font-size: clamp(30px, 5vw, 52px); margin: 0; letter-spacing: -0.03em; line-height: 1.1; }
.artist-head p { color: var(--muted); margin: 8px 0 0; }
.song-list { list-style: none; padding: 0; margin: 24px 0; }
.song-list a { display: block; padding: 14px 4px; border-bottom: 1px solid var(--line); text-decoration: none; }
.song-list b { font-family: var(--ja); font-size: 18px; }
.song-list span { display: block; color: var(--muted); font-size: 14px; }

/* ---------- 곡 페이지 ---------- */
.song-page { display: grid; grid-template-columns: 220px minmax(0, 1fr) minmax(0, 1.1fr); gap: 32px; padding-top: 24px; }
.side { position: sticky; top: 72px; align-self: start; max-height: calc(100vh - 96px); overflow: auto; }
.side h2 { font-size: 14px; margin: 0 0 8px; color: var(--muted); font-weight: 600; }
.side a { display: block; padding: 10px 12px; border-left: 3px solid transparent; text-decoration: none; font-size: 14px; }
.side a small { display: block; color: var(--muted); font-family: var(--ja); font-size: 12px; }
.side a[aria-current="page"] { border-color: var(--day); background: var(--surface); font-weight: 700; }

.stage-col { position: sticky; top: 72px; align-self: start; }
.song-title { font-family: var(--ja); font-size: clamp(28px, 4vw, 44px); font-weight: 900; margin: 0; line-height: 1.15; letter-spacing: -0.02em; }
.song-sub { color: var(--muted); margin: 4px 0 16px; }
.player { aspect-ratio: 16 / 9; border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.player iframe { width: 100%; height: 100%; border: 0; display: block; }
.player-empty { display: grid; place-items: center; height: 100%; color: var(--muted); font-size: 14px; padding: 16px; text-align: center; }
.hint { font-size: 13px; color: var(--muted); margin: 10px 0; }
.legend { display: flex; flex-wrap: wrap; gap: 6px; }

.cue { --c: var(--muted); border-radius: 8px; padding: 1px 8px; font-weight: 800; background: color-mix(in srgb, var(--c) 18%, transparent); color: var(--c); }
.cue-sing { --c: var(--sing); } .cue-call { --c: var(--call); }
.cue-clap { --c: var(--clap); } .cue-wave { --c: var(--wave); }
.cue-towel { --c: var(--towel); } .cue-jump { --c: var(--jump); }
/* 칠해진 가사 앞의 이름표 (진한 바탕 + 배경색 글자로 뒤집어서 가사와 구분) */
.cue-tag { display: inline-block; font-size: .58em; font-weight: 800; line-height: 1.5; padding: 0 6px; margin-right: 6px;
  border-radius: 6px; background: var(--c); color: var(--bg); vertical-align: .22em; white-space: nowrap; letter-spacing: 0; }
.cue-badge { font-size: .62em; padding: 2px 7px; margin-right: 4px; vertical-align: .2em; white-space: nowrap; }
.legend .cue { font-size: 13px; padding: 4px 10px; }

.lyrics { list-style: none; padding: 0; margin: 0; overflow-wrap: anywhere; }
.section-label { color: var(--muted); font-size: 13px; font-weight: 700; margin: 28px 0 4px; padding-left: 12px; }
.line {
  padding: 12px; border-radius: var(--radius); cursor: pointer;
  border-left: 3px solid transparent; transition: background-color .2s;
}
.line:hover { background: var(--surface); }
.line.is-current {
  background: color-mix(in srgb, var(--day) 16%, var(--bg)); border-left-color: var(--day);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--day) 45%, transparent);
}
.line .ja { font-family: var(--ja); font-weight: 700; font-size: 19px; margin: 0; }
.line .pron { font-size: 22px; font-weight: 700; color: var(--day); margin: 2px 0; }
.line .ko { font-size: 14px; color: var(--muted); margin: 0; }
.line .note { font-size: 16px; margin: 0; }
.line .t { float: right; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* 범례 줄 + 오른쪽 작은 자동 스크롤 버튼 (가사 위에 떠 있지 않게) */
.stage-tools { display: flex; gap: 8px; align-items: center; justify-content: space-between; margin-top: 10px; }
.stage-tools .legend { flex: 1; min-width: 0; }
.autoscroll {
  flex: none; padding: 5px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; white-space: nowrap;
}
.autoscroll[aria-pressed="true"] { background: var(--day); color: var(--bg); border-color: var(--day); }

.mobile-only { display: none; }
/* ---------- 오프라인 ---------- */
.player { position: relative; }
.player-note { position: absolute; inset: 0; margin: 0; background: var(--surface); }
.player-note[hidden] { display: none; }
.player.is-offline { aspect-ratio: auto; height: auto; min-height: 0; }
.player.is-offline .player-note { position: static; }
/* 곡 탭: 모바일에서 영상 아래 가로 목록 (데스크톱은 왼쪽 곡 목록을 씀) */
.song-tabs { display: none; }
.player.is-offline .player-empty { padding: 20px 16px; }
.autoscroll[hidden] { display: none; }
.offline-bar { margin: 0; padding: 8px 16px; text-align: center; font-size: 13px; font-weight: 600;
  background: color-mix(in srgb, var(--sun) 22%, var(--bg)); color: var(--text); border-bottom: 1px solid var(--line); }
.offline-bar[hidden] { display: none; }
.offline-save { margin-top: 28px; padding: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.offline-save[hidden] { display: none; }
.offline-save p { margin: 0; flex: 1; min-width: 220px; line-height: 1.5; }
.offline-save small { display: block; color: var(--muted); font-size: 13px; }
.offline-save button { padding: 10px 16px; border-radius: 10px; border: 1px solid var(--day); background: var(--day); color: var(--bg);
  font: inherit; font-weight: 700; cursor: pointer; white-space: nowrap; }
.offline-save button.quiet { background: transparent; color: var(--text); border-color: var(--line); }
.offline-save button:disabled { opacity: .6; cursor: default; }
footer.site { color: var(--muted); font-size: 13px; padding: 40px 0; border-top: 1px solid var(--line); margin-top: 40px; }

/* ---------- 모바일 ---------- */
@media (max-width: 960px) {
  /* 곡 페이지: 화면을 위(영상·곡 탭)와 아래(가사) 두 칸으로 나누고, 가사는 아래 칸 안에서만 스크롤
     → 가사가 영상 뒤로 들어갈 수 없음 */
  body[data-page="song"] { overflow: hidden; }
  body[data-page="song"] main { padding-bottom: 0; }
  .song-page { display: flex; flex-direction: column; gap: 0; padding-top: 10px;
    height: calc(100vh - var(--topbar-h, 49px)); height: calc(100dvh - var(--topbar-h, 49px)); }
  .stage-col { position: static; align-self: stretch; width: 100%; flex: none; min-width: 0; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
  .song-title, .song-sub { display: none; }
  .lyrics { flex: 1; min-height: 0; min-width: 0; overflow-y: auto; overscroll-behavior: contain; position: relative;
    padding-top: 6px; padding-bottom: calc(45vh + env(safe-area-inset-bottom)); }   /* 마지막 줄도 맨 위까지 올라오게 */
  .side { display: none; }
  .mobile-only { display: inline-block; margin: 12px 0 4px; }
  .player { max-height: 28vh; aspect-ratio: auto; height: 28vh; }
  .song-title { font-size: 24px; }
  .hint { display: none; }
  /* 글씨·여백을 줄여 가사 공간 확보 */
  .topbar { padding: 8px 14px; }
  .brand { font-size: 15px; }
  .unofficial { display: none; }
  main { padding-left: 14px; padding-right: 14px; }
  .song-page { padding-top: 8px; }
  .line { padding: 8px 10px; border-radius: 10px; }
  .line .ja { font-size: 15px; }
  .line .pron { font-size: 18px; margin: 1px 0; }
  .line .ko { font-size: 12.5px; }
  .line .note { font-size: 14px; }
  .line .t { font-size: 11px; }
  .section-label { margin: 16px 0 2px; font-size: 12px; }
  .song-tabs a { padding: 5px 10px; font-size: 12.5px; }
  .autoscroll { padding: 4px 10px; font-size: 12px; }
  .song-tabs { display: flex; gap: 6px; overflow-x: auto; margin: 8px 0 0; padding-bottom: 2px; scrollbar-width: none; }
  .song-tabs[hidden] { display: none; }
  .song-tabs::-webkit-scrollbar { display: none; }
  .song-tabs a { flex: none; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); text-decoration: none;
    font-size: 13px; font-weight: 600; white-space: nowrap; color: var(--muted); }
  .song-tabs a[aria-current="page"] { background: var(--day); border-color: var(--day); color: var(--bg); }
  /* 돌아가기 칩은 탭을 옆으로 넘겨도 왼쪽에 붙어 있게 */
  .song-tabs a.back { position: sticky; left: 0; z-index: 1; color: var(--text); border-style: dashed; background: var(--bg);
    box-shadow: 8px 0 8px -4px var(--bg); }
  .stage-tools { margin-top: 8px; }
  /* 범례는 한 줄로 (넘치면 옆으로 넘김) → 가사 칸을 줄이지 않게 */
  .stage-tools .legend { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .stage-tools .legend::-webkit-scrollbar { display: none; }
  .stage-tools .legend .cue { flex: none; font-size: 12px; padding: 3px 8px; }
  .slot { grid-template-columns: 64px 1fr; }
  .slot-count { grid-column: 2; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
