.viz-root {
  color-scheme: light;
  --page: #f6f6f7;
  --surface-1: #ffffff;
  --surface-2: #f2f2f3;
  --text-primary: #191919;
  --text-secondary: #666666;
  --grid: #ececec;
  --axis: #c2c2c2;
  --border: rgba(11, 11, 11, 0.08);
  --series-1: #257de0;
  --series-2: #f47230;
  --series-3: #00b894;
  --good: #0aac23;
  --good-text: #006c10;
  --critical: #dc3c3d;
  --warning: #fbb315;
  --accent-wash: rgba(37, 125, 224, 0.10);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .viz-root {
    color-scheme: dark;
    --page: #0b0b0b; --surface-1: #191919; --surface-2: #232323;
    --text-primary: #efefef; --text-secondary: #9c9c9c;
    --grid: #2a2a2a; --axis: #474747; --border: rgba(255, 255, 255, 0.08);
    --series-1: #338ced; --series-2: #e76624; --series-3: #00a888;
    --good-text: #53c556; --accent-wash: rgba(51, 140, 237, 0.16); --shadow: none;
  }
}
:root[data-theme="dark"] .viz-root {
  color-scheme: dark;
  --page: #0b0b0b; --surface-1: #191919; --surface-2: #232323;
  --text-primary: #efefef; --text-secondary: #9c9c9c;
  --grid: #2a2a2a; --axis: #474747; --border: rgba(255, 255, 255, 0.08);
  --series-1: #338ced; --series-2: #e76624; --series-3: #00a888;
  --good-text: #53c556; --accent-wash: rgba(51, 140, 237, 0.16); --shadow: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
.viz-root {
  min-height: 100vh;
  background: var(--page);
  color: var(--text-primary);
  font: 14px/1.55 "Pretendard", system-ui, -apple-system, "Segoe UI", "Malgun Gothic", sans-serif;
  letter-spacing: -0.01em;
}
a { color: var(--series-1); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--text-secondary); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
hr { border: 0; border-top: 1px solid var(--grid); margin: 16px 0; }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 20px;
  padding: 0 28px; height: 56px;
  background: color-mix(in srgb, var(--surface-1) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; margin-right: auto; }
.brand h1 { font-size: 15px; margin: 0; font-weight: 700; white-space: nowrap; }
.brand h1::before { content: "▶"; display: inline-block; margin-right: 8px; color: var(--critical); font-size: 12px; transform: translateY(-1px); }
#channel { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-left: 12px; border-left: 1px solid var(--border); }
nav { display: flex; gap: 2px; height: 100%; }
nav a {
  display: flex; align-items: center; padding: 0 14px; color: var(--text-secondary);
  font-weight: 600; border-bottom: 2px solid transparent; text-decoration: none !important;
}
nav a:hover { color: var(--text-primary); }
nav a.on { color: var(--text-primary); border-bottom-color: var(--series-1); }

button {
  font: inherit; font-weight: 600; cursor: pointer; border-radius: 8px; padding: 7px 14px;
  border: 1px solid var(--border); background: var(--surface-1); color: var(--text-primary);
}
button:hover { background: var(--surface-2); }
button.primary { background: var(--series-1); border-color: transparent; color: #fff; }
button.primary:hover { filter: brightness(1.05); }
button.ghost { background: transparent; }
button:disabled { opacity: .5; cursor: default; }
#theme { padding: 6px 10px; }
input[type=text], select {
  font: inherit; padding: 8px 10px; border-radius: 8px; min-width: 0;
  border: 1px solid var(--border); background: var(--surface-1); color: var(--text-primary);
}

/* ---------- chips ---------- */
.badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; font-weight: 600; white-space: nowrap; }
.badge.demo { background: var(--warning); color: #0b0b0b; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
  font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-primary); border: 1px solid transparent;
}
.chip .g { font-size: 11px; }
.chip.dashed { background: transparent; color: var(--text-secondary); border: 1px dashed var(--axis); }
.chip.ok .g, .chip.ok { color: var(--good-text); }
.chip-winner { background: var(--accent-wash); }
.chip-winner .g { color: var(--series-1); }
.chip-hidden_gem .g { color: var(--series-2); }
.chip-click_only .g { color: var(--text-secondary); }
.chip-ad_boost { background: transparent; border-color: var(--border); color: var(--text-secondary); }
.chip-ad_boost .g { color: var(--warning); }
.pill { font-size: 12px; padding: 1px 8px; border-radius: 6px; background: var(--surface-2); font-weight: 600; }

/* ---------- layout ---------- */
main { max-width: 1200px; margin: 0 auto; padding: 28px 28px 72px; }
.pagehead { margin-bottom: 20px; }
h2 { font-size: 22px; margin: 0 0 4px; font-weight: 700; letter-spacing: -0.02em; }
h3 { font-size: 15px; margin: 0; font-weight: 700; }
.lede { color: var(--text-secondary); margin: 0; max-width: 760px; }
.card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px;
  padding: 20px 22px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.card.flush { padding: 0; overflow: hidden; }
.cardhead { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.cardhead .muted { font-size: 12px; }
.grid { display: grid; gap: 16px; }
.grid > .card { margin-bottom: 0; }
.grid + .card, .grid + .grid, .card + .grid { margin-top: 16px; }
.g2 { grid-template-columns: 1fr 1fr; }
.g4 { grid-template-columns: repeat(4, 1fr); }
.g5 { grid-template-columns: repeat(5, 1fr); }
.g5 .tile .value { font-size: 24px; }
@media (max-width: 1100px) { .g5 { grid-template-columns: repeat(3, 1fr); } }

/* 로그인 · 공유 모드 */
.gate { max-width: 520px; margin: 64px auto; }
.gate > button { margin-top: 16px; }
.gate input[type=text] { flex: 1; min-width: 220px; }
button.google { display: inline-flex; align-items: center; gap: 10px; padding: 10px 18px; font-size: 15px; }
.g-logo { display: inline-flex; width: 22px; height: 22px; border-radius: 50%; align-items: center; justify-content: center;
  font-weight: 800; font-size: 13px; color: #fff; background: conic-gradient(#ea4335 0 25%, #fbbc05 0 50%, #34a853 0 75%, #4285f4 0); }
.req-status { margin: 12px 0 0; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.adm td { white-space: normal; }
.adm td.r { white-space: nowrap; }
p.pad, .card .pad { padding: 16px 20px; margin: 0; }
.gate input[type=email] { flex: 1; min-width: 220px; font: inherit; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-1); color: var(--text-primary); }
.user { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.breqs { display: grid; gap: 6px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--grid); }
.breq { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* 제목 패턴 */
.ptable td:first-child { font-weight: 600; white-space: nowrap; }
.ptable th.grp { vertical-align: bottom; }
.ptable td { vertical-align: top; }
.small-chip { font-size: 11px; padding: 0 6px; }
.pbar { display: block; width: 72px; height: 6px; background: var(--surface-2); border-radius: 999px; position: relative; overflow: hidden; }
.pbar span { position: absolute; left: 0; top: 0; bottom: 0; background: var(--series-1); border-radius: 999px; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.gallery.vert { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.gitem { display: flex; flex-direction: column; gap: 4px; color: inherit; min-width: 0; }
.gitem:hover { text-decoration: none; }
.gitem:hover .gt { text-decoration: underline; }
.gthumb { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 8px; background: var(--surface-2); display: block; }
.gallery.vert .gthumb { aspect-ratio: 9 / 16; }
.gt { font-size: 13px; font-weight: 600; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* 하나의 전체를 나눈 막대 (tall segmented bar) */
.segbar-row { display: grid; grid-template-columns: 72px 1fr; align-items: center; gap: 12px; margin-bottom: 10px; }
.segbar-label { font-size: 12px; color: var(--text-secondary); font-weight: 600; }
.segbar { display: flex; gap: 2px; height: 28px; }
.segbar > div { border-radius: 4px; color: #fff; font-size: 12px; font-weight: 600; display: flex; align-items: center; padding-left: 8px; min-width: 0; white-space: nowrap; overflow: hidden; }
.tiles { margin-bottom: 16px; }
@media (max-width: 960px) { .g2, .g4 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 640px) { .g2, .g4 { grid-template-columns: 1fr; } .top { padding: 0 16px; } #channel { display: none; } main { padding: 20px 16px 60px; } }

/* ---------- tiles ---------- */
.tile {
  display: block; background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px;
  padding: 16px 18px; box-shadow: var(--shadow); color: inherit; min-width: 0;
}
.tile.link:hover { border-color: var(--series-1); text-decoration: none; }
.tile .label { color: var(--text-secondary); font-size: 12px; font-weight: 600; }
.tile .value { font-size: 28px; font-weight: 700; margin-top: 4px; letter-spacing: -0.02em; line-height: 1.2; }
.tile .value small { font-size: 14px; font-weight: 600; color: var(--text-secondary); margin-left: 3px; }
.tile .note { color: var(--text-secondary); font-size: 12px; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- table ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar.pad { padding: 16px 20px; margin: 0; border-bottom: 1px solid var(--grid); }
.toolbar h3 { margin-right: auto; }
.toolbar .grow { flex: 1; min-width: 240px; max-width: 640px; }
.check { color: var(--text-secondary); font-size: 13px; display: flex; gap: 6px; align-items: center; cursor: pointer; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button { border: 0; border-radius: 7px; background: transparent; color: var(--text-secondary); padding: 5px 12px; font-size: 13px; }
.seg button.on { background: var(--surface-1); color: var(--text-primary); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--grid); vertical-align: middle; }
th { font-size: 12px; color: var(--text-secondary); font-weight: 600; white-space: nowrap; background: var(--surface-1); }
tbody tr:last-child td { border-bottom: 0; }
td.r, th.r { text-align: right; }
td.c, th.c { text-align: center; width: 36px; }
td { white-space: nowrap; }
#tbl tbody tr { cursor: pointer; }
#tbl tbody tr:hover { background: var(--surface-2); }

.vcell { display: flex; align-items: center; gap: 12px; min-width: 0; }
.vt { display: flex; flex-direction: column; min-width: 0; }
.vcell .t { font-weight: 600; max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.vcell .d { color: var(--text-secondary); font-size: 12px; }
.thumb { width: 72px; height: 40px; border-radius: 6px; object-fit: cover; flex: none; background: var(--surface-2); display: block; }
.thumb.vert { width: 40px; height: 56px; }
.thumb.lg { width: 176px; height: 99px; border-radius: 10px; }
.stack { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.stack.l { align-items: flex-start; }
.xbar { display: flex; align-items: center; gap: 6px; }
.xbar .track { width: 56px; height: 6px; background: var(--surface-2); border-radius: 999px; position: relative; }
.xbar .fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 999px; background: var(--series-1); }
.xbar .mid { position: absolute; top: -3px; bottom: -3px; width: 1px; background: var(--axis); }
.xbar .muted { font-size: 12px; min-width: 32px; text-align: right; }
.gap-up { color: var(--good-text); font-weight: 600; }

/* ---------- charts ---------- */
svg { display: block; overflow: visible; }
svg text { fill: var(--text-secondary); font-size: 11px; font-family: inherit; }
svg .grid line { stroke: var(--grid); stroke-width: 1; }
svg .axis { stroke: var(--axis); stroke-width: 1; }
svg .ref { stroke: var(--axis); stroke-width: 1; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--text-secondary); margin-top: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
.legend i.sq { border-radius: 2px; }
.legend i.ring { background: transparent; border: 2px solid var(--series-1); width: 11px; height: 11px; }

.tip {
  position: fixed; pointer-events: none; z-index: 20; max-width: 360px;
  background: var(--surface-1); color: var(--text-primary); border: 1px solid var(--border);
  border-radius: 10px; padding: 9px 11px; font-size: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.14);
}
.tip b { font-weight: 700; }
.tip .q { color: var(--text-secondary); margin-top: 4px; line-height: 1.5; }

/* ---------- video page ---------- */
.vhead { display: flex; gap: 20px; align-items: flex-start; margin-bottom: 20px; }
.vhead h2 { margin-bottom: 2px; }
.vhead .meta { color: var(--text-secondary); font-size: 13px; }
.warn { margin: 10px 0 0; font-size: 13px; color: var(--text-primary); background: color-mix(in srgb, var(--warning) 14%, transparent); padding: 6px 10px; border-radius: 8px; display: inline-block; }
@media (max-width: 640px) { .vhead { flex-direction: column; } }

.scene.vert { display: grid; grid-template-columns: 280px 1fr; gap: 20px; align-items: center; }
.scene.vert .player { margin: 0; }
.player.vert { aspect-ratio: 9 / 16; min-width: 0; max-width: 280px; width: 100%; }
@media (max-width: 760px) { .scene.vert { grid-template-columns: 1fr; } .scene.vert .player { margin: 0 auto; } }
.thumb.lg.vert { width: 72px; height: 128px; }
.back { font-weight: 600; font-size: 13px; color: var(--text-secondary); white-space: nowrap; }
.back:hover { color: var(--text-primary); text-decoration: none; }
#sync { white-space: nowrap; }
#sync.spin .ico { display: inline-block; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#channel { color: var(--text-primary); }
#channel:hover { text-decoration: none; }
#channel:hover b { text-decoration: underline; }
.player { position: relative; max-width: min(620px, calc((100vh - 470px) * 16 / 9)); min-width: 320px; margin: 0 auto 18px; aspect-ratio: 16 / 9; border-radius: 12px; overflow: hidden; background: #000; }
.player iframe, .player #yt { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.player-msg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 24px; color: #cfcfcf; font-size: 13px; }
button.seek {
  font: inherit; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface-1); color: var(--text-primary); cursor: pointer;
}
button.seek:hover { border-color: var(--series-1); color: var(--series-1); background: var(--surface-1); }
.para .ts button.seek { align-self: flex-start; margin-bottom: 2px; }

.drop-h::before { content: "▼ "; color: var(--critical); }
.hold-h::before { content: "▲ "; color: var(--good); }
h3 .muted { font-weight: 500; font-size: 12px; margin-left: 4px; }
.card > h3 { margin-bottom: 14px; }
.seglist { display: grid; gap: 10px; }
.segitem { border-radius: 10px; padding: 12px 14px; background: var(--surface-2); }
.segitem .head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }
.segitem .k { font-weight: 700; }
.segitem.drop .k { color: var(--critical); }
.segitem.hold .k { color: var(--good-text); }
.segitem .pill { background: var(--surface-1); }
.quote { margin: 0; color: var(--text-primary); line-height: 1.6; }
.segitem .quote { cursor: pointer; }
.quote.clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.quote::before { content: "“"; color: var(--text-secondary); }
.quote::after { content: "”"; color: var(--text-secondary); }
.empty { color: var(--text-secondary); padding: 20px; text-align: center; border: 1px dashed var(--axis); border-radius: 10px; }

.transcript { max-height: 360px; overflow: auto; font-size: 13px; padding-right: 6px; }
.para { display: grid; grid-template-columns: 88px 1fr; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--grid); line-height: 1.6; }
.para:last-child { border-bottom: 0; }
.para .ts { color: var(--text-secondary); display: flex; flex-direction: column; font-size: 12px; }
.para .ts b { color: var(--text-primary); font-weight: 600; }

/* ---------- compare / connect ---------- */
.field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.field select { width: 100%; font-weight: 400; }
.cmp td:first-child { color: var(--text-secondary); white-space: nowrap; width: 140px; padding-left: 22px; }
.cmp th:first-child { padding-left: 22px; }
.cmp td, .cmp th { white-space: normal; }
.cmp .vcell .t { max-width: 320px; white-space: normal; }
pre.log { background: var(--surface-2); padding: 10px; border-radius: 8px; max-height: 240px; overflow: auto; font-size: 12px; white-space: pre-wrap; margin: 12px 0 0; }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 4px; font-size: 12.5px; }
ol.steps { margin: 0; padding-left: 20px; }
ol.steps li { margin-bottom: 8px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row input[type=text] { flex: 1; min-width: 260px; }
