:root {
  --bg: #f7f7f5; --surface: #ffffff; --ink: #1d1d1b; --muted: #6b6b66; --line: #e6e5e0;
  --grid: #eeede8; --accent: #2563d9; --accent-soft: #e8effc; --up: #1a7f4b; --warn: #a15c00;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615; --surface: #1f1f1d; --ink: #ecebe6; --muted: #a09f99; --line: #33332f;
    --grid: #2a2a27; --accent: #6b9cf5; --accent-soft: #1f2b44; --up: #4cc38a; --warn: #e0a050;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", sans-serif; }
button, input { font: inherit; color: inherit; }
a { color: inherit; }
.muted { color: var(--muted); }
.top { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: center; justify-content: space-between;
  padding: 16px 24px 0; max-width: 1200px; margin: 0 auto; }
.brand { display: flex; gap: 12px; align-items: baseline; }
h1 { font-size: 20px; margin: 0; }
.tabs { display: flex; gap: 4px; }
.tabs button { border: 0; background: none; padding: 8px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 0 0 1px var(--line); }
.banner { max-width: 1200px; margin: 12px auto 0; padding: 8px 24px; color: var(--warn); }
.filters { display: flex; flex-wrap: wrap; gap: 8px 16px; padding: 12px 24px; max-width: 1200px; margin: 0 auto; }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: 6px; cursor: pointer; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
.seg.sub { margin-bottom: 4px; }
main { max-width: 1200px; margin: 0 auto; padding: 0 24px 48px; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 12px; }

/* 요약 */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.tile .label { color: var(--muted); font-size: 13px; }
.tile .num { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; }
.tile .sub { color: var(--muted); font-size: 12px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card h2 { font-size: 15px; margin: 0 0 10px; }
.mini { display: grid; grid-template-columns: 22px 1fr auto; gap: 4px 8px; align-items: center; padding: 6px 0;
  border-top: 1px solid var(--grid); cursor: pointer; }
.mini:first-of-type { border-top: 0; }
.mini .rank { color: var(--muted); font-variant-numeric: tabular-nums; }
.mini .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini .ch { color: var(--muted); font-size: 12px; grid-column: 2; }
.mini .v { font-variant-numeric: tabular-nums; font-weight: 600; grid-row: span 2; text-align: right; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; background: var(--surface); font-size: 13px; }
.chip b { font-weight: 600; margin-left: 4px; color: var(--up); }

/* 영상 목록 */
.list { display: flex; flex-direction: column; gap: 8px; }
.row { display: grid; grid-template-columns: 28px 128px 1fr 120px 110px; gap: 12px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; cursor: pointer; }
.row:hover { border-color: var(--accent); }
.row .rank { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.row img { width: 128px; height: 72px; object-fit: cover; border-radius: 6px; background: var(--grid); }
.row.short img { object-fit: cover; }
.row .t { font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.row .meta { color: var(--muted); font-size: 12px; }
.row .val { text-align: right; font-variant-numeric: tabular-nums; }
.row .val strong { font-size: 17px; display: block; }
.row .val span { color: var(--muted); font-size: 12px; }
.badge { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 4px; border: 1px solid var(--line); color: var(--muted); margin-right: 4px; }
@media (max-width: 720px) {
  .row { grid-template-columns: 96px 1fr; }
  .row .rank, .row .spark { display: none; }
  .row img { width: 96px; height: 54px; }
  .row .val { grid-column: 2; text-align: left; }
}

/* 채널 표 */
#ch-search { width: 100%; max-width: 320px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); margin-bottom: 10px; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--grid); text-align: right; white-space: nowrap; }
th:first-child, td:first-child, th:nth-child(2), td:nth-child(2) { text-align: left; }
th { font-weight: 600; color: var(--muted); font-size: 12px; cursor: pointer; user-select: none; position: sticky; top: 0; background: var(--surface); }
th[aria-sort] { color: var(--ink); }
tr:hover td { background: var(--accent-soft); cursor: pointer; }
td.name { max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.pos { color: var(--up); }

/* 단어 */
.words { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.wrow { display: grid; grid-template-columns: 1fr 70px 90px; gap: 8px; align-items: center; padding: 5px 0; border-top: 1px solid var(--grid); }
.wrow .w { font-weight: 600; }
.wrow .n { text-align: right; font-variant-numeric: tabular-nums; }
.wrow .n small { color: var(--muted); display: block; font-size: 11px; }

/* 그래프 */
svg text { fill: var(--muted); font-size: 11px; }
.spark .ln { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.spark .dot { fill: var(--accent); }
.bars rect { fill: var(--accent); opacity: .35; }
.bars rect.cur { opacity: 1; }
.chart .grid line { stroke: var(--grid); }
.chart .ln { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.chart .cross { stroke: var(--muted); stroke-dasharray: 3 3; }
.chart .pt { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }

/* 상세 창 */
.detail { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.detail[hidden] { display: none; }
.detail-box { background: var(--surface); border-radius: 14px; width: min(720px, 100%); max-height: 90vh; overflow: auto; padding: 20px; position: relative; }
.detail-box h3 { margin: 0 32px 4px 0; font-size: 17px; }
.close { position: absolute; top: 10px; right: 12px; border: 0; background: none; font-size: 24px; cursor: pointer; color: var(--muted); }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin: 14px 0; }
.facts div { background: var(--bg); border-radius: 8px; padding: 8px 10px; }
.facts small { display: block; color: var(--muted); }
.facts b { font-variant-numeric: tabular-nums; }
.tip { position: fixed; pointer-events: none; background: var(--ink); color: var(--surface); padding: 6px 9px; border-radius: 6px; font-size: 12px; z-index: 20; white-space: nowrap; }
.empty { color: var(--muted); padding: 24px; text-align: center; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }
