:root {
  --ink: #14110f;
  --ink-2: #1d1916;
  --ink-3: #2a241f;
  --line: #3a322b;
  --paper: #efe6d8;
  --paper-dim: #b8ab99;
  --muted: #8d8173;
  --signal: #ff4b2b;
  --gold: #f2b134;
  --up: #7fd18b;
  --down: #ff7a66;
  --display: 'Anton', 'Impact', 'Arial Narrow', sans-serif;
  --body: 'Gowun Dodum', 'Malgun Gothic', 'Apple SD Gothic Neo', sans-serif;
  --mono: 'IBM Plex Mono', 'Consolas', monospace;
  --dock-h: 0px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background:
    radial-gradient(1200px 500px at 85% -10%, rgba(255, 75, 43, .13), transparent 60%),
    repeating-linear-gradient(0deg, rgba(255,255,255,.012) 0 1px, transparent 1px 3px),
    var(--ink);
  color: var(--paper); font-family: var(--body); font-size: 15px; line-height: 1.5; min-height: 100vh;
}
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--gold); color: var(--ink); padding: 6px 10px; z-index: 50; }
.skip:focus { left: 8px; }
a { color: var(--gold); }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* 헤더 */
.masthead { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px clamp(16px, 3vw, 36px) 14px; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand-mark { font-family: var(--display); font-size: 34px; line-height: 1; color: var(--ink); background: var(--signal); padding: 6px 8px 4px; transform: rotate(-4deg); box-shadow: 4px 4px 0 var(--gold); }
h1 { font-family: var(--display); font-weight: 400; letter-spacing: .02em; font-size: clamp(22px, 3vw, 30px); margin: 0; line-height: 1.1; }
.brand-sub { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; font-family: var(--mono); }
.status-pill { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--ink-2); border-radius: 999px; padding: 7px 14px; cursor: pointer; font-size: 13px; max-width: 46vw; }
.status-pill span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.status-pill[data-level="ok"] .dot { background: var(--up); box-shadow: 0 0 10px var(--up); }
.status-pill[data-level="busy"] .dot { background: var(--gold); animation: pulse 1.2s infinite; }
.status-pill[data-level="warn"] .dot { background: var(--down); }
@keyframes pulse { 50% { opacity: .3; } }

/* 레이아웃 */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 28px; padding: 20px clamp(16px, 3vw, 36px) 40px; align-items: start; }
.main { min-width: 0; }

/* 주차 바 */
.weekbar { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "title controls" "search search"; gap: 14px 20px; align-items: end; padding-bottom: 16px; border-bottom: 2px solid var(--paper); }
.week-title { grid-area: title; min-width: 0; }
.eyebrow { font-family: var(--mono); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--signal); }
#weekLabel { font-family: var(--display); font-weight: 400; font-size: clamp(28px, 3.6vw, 44px); line-height: 1.05; margin: 4px 0 6px; letter-spacing: .01em; }
.week-meta { margin: 0; color: var(--paper-dim); font-size: 13px; font-family: var(--mono); }
.week-meta .tag { display: inline-block; border: 1px solid var(--line); padding: 0 6px; margin-right: 6px; border-radius: 3px; }
.week-meta .tag.official { border-color: var(--gold); color: var(--gold); }
.week-meta .tag.warn { border-color: var(--down); color: var(--down); }
.week-controls { grid-area: controls; display: flex; gap: 8px; align-items: center; }
.search { grid-area: search; display: flex; gap: 8px; }
.search input { flex: 1; min-width: 0; }
.field select, input[type=search], input[type=url] { background: var(--ink-2); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; min-height: 40px; }
.field.grow select { min-width: 170px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 14px; background: var(--ink-3); border: 1px solid var(--line); border-radius: 6px; cursor: pointer; text-decoration: none; color: var(--paper); white-space: nowrap; transition: background .15s, border-color .15s, transform .1s; }
.btn:hover:not(:disabled) { border-color: var(--paper-dim); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; pointer-events: none; }
.btn.icon { padding: 8px 12px; }
.btn.primary { background: var(--signal); border-color: var(--signal); color: #160b07; font-weight: 700; }
.btn.ghost { background: transparent; }
.btn.link { color: var(--gold); }

.notice { margin: 14px 0 0; padding: 10px 14px; border-left: 3px solid var(--gold); background: rgba(242,177,52,.08); font-size: 13.5px; }
.notice.warn { border-color: var(--down); background: rgba(255,122,102,.08); }

/* 차트 목록 */
.chart { margin-top: 6px; }
.empty { color: var(--muted); padding: 40px 0; text-align: center; }
.row { display: grid; grid-template-columns: 64px 40px 52px minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 10px 4px; border-bottom: 1px solid var(--line); animation: rise .35s both; }
.row:hover { background: rgba(255,255,255,.025); }
.row.playing { background: linear-gradient(90deg, rgba(255,75,43,.16), transparent 70%); }
.row.playing .rank { color: var(--signal); }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.rank { font-family: var(--display); font-size: 34px; line-height: 1; text-align: right; color: var(--paper); }
.row:nth-child(-n+10) .rank { font-size: 40px; }
.move { font-family: var(--mono); font-size: 11px; text-align: center; line-height: 1.2; color: var(--muted); }
.move.up { color: var(--up); } .move.down { color: var(--down); } .move.new { color: var(--gold); font-weight: 600; }
.art { width: 52px; height: 52px; border-radius: 4px; background: var(--ink-3) center/cover; display: grid; place-items: center; color: var(--line); font-family: var(--display); font-size: 18px; overflow: hidden; }
.art img { width: 100%; height: 100%; object-fit: cover; display: block; }
.info { min-width: 0; }
.song { font-weight: 700; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.artist { color: var(--paper-dim); font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stats { font-family: var(--mono); font-size: 11px; color: var(--muted); margin-top: 2px; }
.stats b { color: var(--paper-dim); font-weight: 600; }
.actions { display: flex; gap: 6px; align-items: center; }
.play { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--ink-2); cursor: pointer; display: grid; place-items: center; font-size: 14px; }
.play:hover { border-color: var(--signal); color: var(--signal); }
.vstate { font-family: var(--mono); font-size: 10.5px; padding: 2px 5px; border-radius: 3px; border: 1px solid var(--line); color: var(--muted); cursor: pointer; background: none; min-height: 28px; }
.vstate.matched, .vstate.manual { color: var(--up); border-color: rgba(127,209,139,.4); }
.vstate.unmatched, .vstate.error { color: var(--down); border-color: rgba(255,122,102,.4); }
.gap-row { padding: 10px 4px; border-bottom: 1px dashed var(--line); color: var(--down); font-size: 13px; font-family: var(--mono); }
.search-head { display: flex; justify-content: space-between; align-items: center; margin: 14px 0 4px; }
.search-head h3 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 24px; }

/* 플레이어 도크 */
.dock { position: sticky; top: 16px; background: var(--ink-2); border: 1px solid var(--line); border-radius: 10px; padding: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.45); z-index: 20; }
.dock-head { display: flex; justify-content: space-between; gap: 10px; align-items: start; margin-bottom: 10px; }
.now { display: flex; flex-direction: column; min-width: 0; }
.now strong { font-size: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.now-artist { color: var(--paper-dim); font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.screen-wrap { min-width: 200px; }
.screen { position: relative; width: 100%; aspect-ratio: 16 / 9; min-height: 200px; background: #000; border-radius: 6px; overflow: hidden; }
.screen iframe, #ytPlayer { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.screen-idle { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 20px; color: var(--muted); font-size: 13px; background: repeating-radial-gradient(circle at 50% 50%, #0b0908 0 2px, #12100e 2px 4px); }
.screen.has-video .screen-idle { display: none; }
.transport { display: grid; grid-template-columns: 1fr 1.2fr 1fr; gap: 8px; margin-top: 10px; align-items: center; }
.toggle { grid-column: 1 / -1; display: flex; gap: 8px; align-items: center; font-size: 13.5px; color: var(--paper-dim); }
.toggle input { width: 18px; height: 18px; accent-color: var(--signal); }
.dock-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 8px; }
.queue-info { font-family: var(--mono); font-size: 11.5px; color: var(--muted); text-align: right; }
.player-msg { min-height: 1.2em; margin: 8px 0 0; font-size: 13px; color: var(--gold); }
.player-msg.err { color: var(--down); }
.video-source { margin-top: 6px; font-size: 12.5px; color: var(--paper-dim); }
.video-source summary { cursor: pointer; color: var(--muted); font-family: var(--mono); font-size: 11.5px; }
.video-source div { padding-top: 6px; word-break: break-word; }

/* 상태 시트 */
.sheet { width: min(760px, calc(100vw - 24px)); max-height: 86vh; background: var(--ink-2); color: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 0; }
.sheet.small { width: min(520px, calc(100vw - 24px)); }
.sheet::backdrop { background: rgba(0,0,0,.65); backdrop-filter: blur(2px); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--ink-2); }
.sheet-head h2, .sheet-body h2 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 24px; }
.sheet-body { padding: 16px 18px 20px; display: flex; flex-direction: column; gap: 12px; }
.sheet-body input { width: 100%; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 14px; font-size: 13.5px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.sheet h3 { margin: 10px 0 4px; font-size: 14px; color: var(--signal); font-family: var(--mono); letter-spacing: .08em; }
.ok { color: var(--up); } .bad { color: var(--down); } .muted { color: var(--muted); }
.row-end { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.progress { height: 6px; background: var(--ink-3); border-radius: 3px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--signal); }

/* 반응형 */
@media (max-width: 1080px) {
  .layout { grid-template-columns: minmax(0, 1fr) 360px; gap: 18px; }
}
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; padding-bottom: calc(var(--dock-h) + 24px); }
  .weekbar { grid-template-columns: 1fr; grid-template-areas: "title" "controls" "search"; }
  .week-controls { flex-wrap: wrap; }
  .week-controls .grow { flex: 1; }
  .field.grow select { min-width: 0; width: 100%; }
  .dock { position: fixed; left: 0; right: 0; bottom: 0; top: auto; border-radius: 12px 12px 0 0; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); max-height: 80vh; overflow: auto; }
  .screen-wrap { width: min(100%, 420px); margin: 0 auto; }
  .dock.collapsed .screen-wrap, .dock.collapsed .video-source, .dock.collapsed .dock-foot, .dock.collapsed .toggle { display: none; }
  .dock.collapsed .transport { margin-top: 4px; }
  .dock-head { margin-bottom: 6px; }
  .transport { grid-template-columns: 1fr 1.2fr 1fr auto; margin-top: 8px; }
  .toggle { grid-column: auto; font-size: 12.5px; gap: 4px; }
  .dock-foot { margin-top: 6px; }
  .dock-foot .btn { min-height: 34px; padding: 4px 10px; }
  .player-msg { margin-top: 4px; }
  .player-msg:empty { display: none; }
  .video-source { display: none; }
  .status-pill { max-width: 40vw; }
}
@media (max-width: 520px) {
  .masthead { padding-top: 12px; }
  .brand-sub { display: none; }
  .brand-mark { display: none; }
  .brand { min-width: 0; overflow: hidden; }
  h1 { font-size: 19px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .masthead { gap: 10px; }
  .status-pill { padding: 6px 10px; font-size: 12px; max-width: 52vw; flex: none; }
  .week-controls { gap: 6px; }
  .week-controls .btn.icon { padding: 8px 10px; }
  .field select { padding: 8px 6px; }
  .row { grid-template-columns: 40px 30px minmax(0, 1fr) auto; gap: 8px; }
  .art { display: none; }
  .rank, .row:nth-child(-n+10) .rank { font-size: 26px; }
  .song { font-size: 15px; }
  .kv { grid-template-columns: 1fr; }
  .kv dt { margin-top: 6px; }
}
@media (min-width: 861px) { #collapseDock { display: none; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* 이어 듣기(화면 이탈·잠금 후 복귀, 새로 연 경우 복원) */
[hidden] { display: none !important; }
.resume { position: relative; border: 1px solid var(--gold); background: rgba(242,177,52,.08); border-radius: 8px; padding: 8px 44px 8px 10px; margin: 0 0 10px; }
.resume-text { margin: 0 0 6px; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.resume-text .eyebrow { color: var(--gold); margin-right: 4px; }
.resume-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.resume-actions .btn { min-height: 40px; padding: 6px 12px; }
.resume-actions .btn.icon { position: absolute; top: 4px; right: 4px; min-height: 34px; padding: 4px 10px; }
