:root {
  color-scheme: light;
  --bg: #f4f4f2; --surface-1: #fcfcfb; --border: #e3e2de;
  --text-primary: #0b0b0b; --text-secondary: #52514e; --text-muted: #8a8984;
  --grid: #ecebe7; --axis: #c9c8c2;
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
  --series-5: #e87ba4; --series-6: #008300; --series-7: #4a3aa7; --series-8: #e34948; --other: #b5b4ae; --none: #dcdbd6;
  --up: #e34948; --down: #2a78d6; --accent: #2a78d6;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110; --surface-1: #1a1a19; --border: #2e2e2c;
    --text-primary: #ffffff; --text-secondary: #c3c2b7; --text-muted: #8f8e86;
    --grid: #262624; --axis: #45443f;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
    --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767; --other: #5c5b56; --none: #3a3a37;
    --up: #e66767; --down: #3987e5; --accent: #3987e5;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface-1: #1a1a19; --border: #2e2e2c;
  --text-primary: #ffffff; --text-secondary: #c3c2b7; --text-muted: #8f8e86;
  --grid: #262624; --axis: #45443f;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
  --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767; --other: #5c5b56; --none: #3a3a37;
  --up: #e66767; --down: #3987e5; --accent: #3987e5;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text-primary); font: 14px/1.45 system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif; }
[hidden] { display: none !important; }
a { color: var(--accent); }
.muted { color: var(--text-muted); } .small { font-size: 12px; } .err { color: var(--up); min-height: 1em; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; border-radius: 8px; padding: 8px 14px; background: var(--accent); color: #fff; font-weight: 600; }
button.ghost { background: transparent; border: 1px solid var(--border); color: var(--text-secondary); font-weight: 500; }
select, input { background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 340px; background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px; padding: 24px; display: grid; gap: 10px; }
.login-card h1 { margin: 0; font-size: 20px; }

#app { max-width: 1280px; margin: 0 auto; padding: 0 16px 32px; }
.top { position: sticky; top: 0; z-index: 5; background: var(--bg); display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; padding: 14px 0 10px; }
.brand { font-weight: 700; font-size: 17px; }
.tag { font-size: 11px; background: var(--series-4); color: #000; border-radius: 4px; padding: 1px 6px; vertical-align: middle; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
#cat { max-width: 240px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { background: transparent; color: var(--text-secondary); border-radius: 0; padding: 7px 12px; font-weight: 500; }
.seg button.on { background: var(--text-primary); color: var(--surface-1); }
.seg.small button { padding: 4px 10px; font-size: 12px; }
.warn { background: color-mix(in srgb, var(--series-4) 18%, var(--surface-1)); border: 1px solid var(--series-4); border-radius: 8px; padding: 8px 12px; margin-bottom: 12px; font-size: 13px; }

.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 12px; }
.kpi { background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.kpi .k { font-size: 12px; color: var(--text-secondary); }
.kpi .v { font-size: 22px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .s { font-size: 12px; color: var(--text-muted); }

.panel { background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; padding: 14px; margin-bottom: 12px; min-width: 0; }
.ph { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.ph h2 { margin: 0; font-size: 15px; }
.grid2 { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 12px; }
.grid2 .panel, .grid3 .panel { margin-bottom: 0; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 12px 0; }

.tablewrap { max-height: 520px; overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; table-layout: fixed; }
#rankTable th:nth-child(1) { width: 42px; } #rankTable th:nth-child(2) { width: 54px; } #rankTable th:nth-child(4) { width: 88px; } #rankTable th:nth-child(5) { width: 110px; } #rankTable th:nth-child(6) { width: 96px; }
td.g { color: var(--text-secondary); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
td.g.none, .meta .none { color: var(--text-muted); }
th { position: sticky; top: 0; background: var(--surface-1); text-align: left; font-weight: 600; color: var(--text-secondary); font-size: 12px; padding: 6px; border-bottom: 1px solid var(--border); }
td { padding: 6px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
td.r { font-weight: 700; font-variant-numeric: tabular-nums; width: 40px; }
td.d { width: 52px; font-variant-numeric: tabular-nums; font-size: 12px; }
td.n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.a { color: var(--text-secondary); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
th { white-space: nowrap; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--grid); }
tbody tr.sel td.n { font-weight: 700; }
tbody tr.sel td:first-child { box-shadow: inset 3px 0 0 var(--selc, var(--accent)); }
.upt { color: var(--up); } .downt { color: var(--down); } .newt { color: var(--series-4); font-weight: 700; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; min-height: 26px; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); border-radius: 999px; padding: 2px 6px 2px 8px; font-size: 12px; color: var(--text-primary); }
.chip .x { background: transparent; color: var(--text-muted); padding: 0 4px; font-weight: 400; }
.sw { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }
.chart { width: 100%; min-height: 260px; }
.chart svg { display: block; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .dlabel { fill: var(--text-secondary); font-size: 11px; }
.chart .dlabel .sw { font-size: 10px; }
.chart .ring { stroke: var(--surface-1); stroke-width: 2; }
.chart .cross { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 3 3; }
.viz-empty { display: grid; place-items: center; min-height: 240px; color: var(--text-muted); font-size: 13px; text-align: center; padding: 16px; }
.viz-tip { position: absolute; display: none; pointer-events: none; z-index: 10; background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: 0 4px 16px rgba(0,0,0,.15); min-width: 150px; max-width: 280px; }
.viz-tip .tt { color: var(--text-secondary); margin-bottom: 4px; }
.viz-tip div { display: flex; align-items: center; gap: 2px; white-space: nowrap; }
.viz-tip b { margin-left: auto; padding-left: 12px; font-variant-numeric: tabular-nums; }
.viz-tip.wide { min-width: 280px; max-width: 480px; }
.hover-tip .tipinfo { display: block; white-space: normal; }
.hover-tip .kv span { white-space: nowrap; }
.viz-tip .pct { width: 44px; text-align: right; color: var(--text-secondary); font-variant-numeric: tabular-nums; flex: none; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; }

.movers { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.movers li { display: flex; gap: 8px; align-items: center; padding: 5px 0; border-bottom: 1px solid var(--grid); cursor: pointer; }
.movers li .info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.movers li .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.movers li .meta { font-size: 11px; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.movers li .rk { color: var(--text-muted); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.movers li .dv { width: 48px; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.movers .none { color: var(--text-muted); cursor: default; }
footer { text-align: center; padding: 8px 0; }

@media (max-width: 600px) {
  #rankTable th:nth-child(4), td.a, #rankTable th:nth-child(6), #rankTable td:nth-child(6) { display: none; }
}
@media (max-width: 900px) {
  .grid2, .grid3 { grid-template-columns: minmax(0, 1fr); }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  #cat { max-width: 100%; flex: 1 1 100%; }
  .top { position: static; }
}

/* 점유율 (원형) */
.sharewrap { display: flex; gap: 24px; align-items: flex-start; flex-wrap: wrap; }
.piebox { flex: 0 0 280px; min-height: 200px; position: relative; }
.piebox svg.pie path, .piebox svg.pie circle { cursor: pointer; transition: opacity .12s; }
.sharetable { flex: 1 1 280px; table-layout: auto; }
.sharetable td, .sharetable th { padding: 5px 6px; }
.sharetable td.num { text-align: right; font-variant-numeric: tabular-nums; }
.sharetable th:nth-child(3), .sharetable th:nth-child(4) { text-align: right; }
.sharetable th:first-child { width: 16px; }
.sharetable tbody tr { cursor: default; }
@media (max-width: 600px) { .piebox { flex-basis: 100%; display: flex; justify-content: center; } }

/* 기타 장르 모달 */
.sharetable tr.clickable { cursor: pointer; }
.sharetable tr.clickable td:nth-child(2) { text-decoration: underline; text-decoration-style: dotted; text-underline-offset: 3px; }
.sharetable tr.clickable:hover { background: var(--grid); }
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.45); display: grid; place-items: center; padding: 16px; }
.modal-card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; padding: 16px; width: 100%; max-width: 520px; max-height: 80vh; display: flex; flex-direction: column; }
.modal-body { overflow: auto; }
.modal-card .ph button { padding: 4px 10px; }
#modalTable td:first-child { width: 48px; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
#modalTable th:first-child { width: 48px; }
.hover-tip { position: fixed; z-index: 60; max-width: 480px; }
.hover-tip:has(.tipcard) { width: 420px; max-width: calc(100vw - 16px); box-sizing: border-box; }
.hover-tip .tipcard { display: flex; gap: 10px; align-items: flex-start; }
.hover-tip img.thumb { flex: none; width: 84px; height: 112px; object-fit: cover; border-radius: 8px; background: var(--grid); }
.hover-tip .tipinfo { min-width: 0; flex: 1; }
.hover-tip .kv { display: grid; grid-template-columns: 72px 1fr; gap: 8px; align-items: start; white-space: normal; margin: 2px 0; }
.hover-tip .kv span { color: var(--text-secondary); }
.hover-tip .kv b { margin: 0; padding: 0; font-weight: 600; word-break: break-all; }
.hover-tip .nm2 { overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.hover-tip .pct { width: 52px; text-align: right; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.sharetable tr[data-tip]:hover { background: var(--grid); }
.calwrap { position: relative; }
#calBtn { padding: 7px 10px; line-height: 1.2; }
#calBtn.on { border-color: var(--accent); color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.calpop { position: absolute; right: 0; top: calc(100% + 6px); z-index: 40; background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.18); width: max-content; max-width: calc(100vw - 32px); }
.calrow { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px; }
.calrow label { display: grid; gap: 4px; font-size: 12px; color: var(--text-secondary); }
.calbtns { display: flex; justify-content: flex-end; gap: 8px; }
.calbtns button { padding: 6px 14px; }
.calpop .err { margin: 6px 0; }
