:root {
  color-scheme: light;
  --bg: #f7f7f5; --surface: #ffffff; --surface-2: #f0efec; --line: #e2e1dc; --line-2: #cfcdc6;
  --text: #161614; --text-2: #52514e; --muted: #6e6d68;
  --accent: #2a78d6; --accent-ink: #ffffff; --accent-soft: #e5effb;
  --error: #b42318;
  --stage: #ecebe7;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948; --s-other: #8a8984;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --line: #2e2e2c; --line-2: #3d3d3a;
    --text: #f4f4f2; --text-2: #c3c2b7; --muted: #9a9991;
    --accent: #3987e5; --accent-ink: #ffffff; --accent-soft: #1d2a3b;
    --error: #ff8a80; --stage: #0d0d0c;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767; --s-other: #8a8984;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --line: #2e2e2c; --line-2: #3d3d3a;
  --text: #f4f4f2; --text-2: #c3c2b7; --muted: #9a9991;
  --accent: #3987e5; --accent-ink: #ffffff; --accent-soft: #1d2a3b;
  --error: #ff8a80; --stage: #0d0d0c;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767; --s-other: #8a8984;
  --shadow: 0 1px 2px rgba(0,0,0,.4);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
[hidden] { display: none !important; }
a { color: var(--accent); }
h1, h2 { margin: 0; letter-spacing: -0.01em; }
h1 { font-size: clamp(22px, 3.2vw, 30px); line-height: 1.2; }
h2 { font-size: 15px; font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--error); }

.top { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.back { color: var(--text-2); text-decoration: none; font-size: 14px; }
.back:hover { color: var(--text); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; margin-right: auto; }
.logo { width: 22px; height: 22px; color: var(--accent); }
.icon-btn { width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text-2); display: grid; place-items: center; cursor: pointer; }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { color: var(--text); border-color: var(--line-2); }

.wrap { max-width: 1240px; margin: 0 auto; padding: 20px 16px 40px; }
.intro { margin: 4px 0 16px; }
.intro p { margin: 6px 0 0; color: var(--text-2); max-width: 70ch; }

.tabs { display: inline-flex; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 12px; margin-bottom: 14px; }
.tabs button { border: 0; background: transparent; color: var(--text-2); font: inherit; font-weight: 600; padding: 8px 18px; border-radius: 9px; cursor: pointer; min-height: 40px; }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; align-items: start; }
@media (max-width: 900px) { .layout { grid-template-columns: minmax(0, 1fr); } }

.stage { position: relative; background: var(--stage); border-radius: var(--radius); min-height: 340px; display: grid; place-items: center; overflow: hidden; border: 1px solid var(--line); }
.stage:has(> .view:not([hidden])) { min-height: 0; }
.stage.over { outline: 3px dashed var(--accent); outline-offset: -8px; }
.view { display: block; max-width: 100%; max-height: 72vh; width: auto; height: auto; }
.drop, .cam-start { text-align: center; padding: 32px 20px; color: var(--text-2); max-width: 520px; }
.drop svg, .cam-start svg { width: 48px; height: 48px; color: var(--muted); }
.drop-title { font-weight: 600; color: var(--text); margin: 8px 0 12px; }
.drop-actions { display: flex; justify-content: center; gap: 8px; }
.examples { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px; margin-top: 18px; }
.examples > span { flex-basis: 100%; }
.ex { display: flex; flex-direction: column; align-items: center; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 6px; cursor: pointer; color: var(--text); font: inherit; font-size: 13px; }
.ex img { width: 96px; height: 64px; object-fit: cover; border-radius: 8px; display: block; }
.ex:hover { border-color: var(--accent); }

.loading { position: absolute; inset: 0; display: grid; place-items: center; background: color-mix(in srgb, var(--stage) 80%, transparent); }
.loading-card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; width: min(360px, 90%); box-shadow: var(--shadow); }
.loading-card p { margin: 0 0 8px; }
.bar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 3px; transition: width .2s; }

.stage-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin: 10px 0 12px; }
.status { color: var(--text-2); font-size: 14px; font-variant-numeric: tabular-nums; min-height: 21px; }
.stage-actions { display: flex; flex-wrap: wrap; gap: 6px; }

.btn { font: inherit; font-size: 14px; font-weight: 600; border-radius: 10px; border: 1px solid var(--line-2); background: var(--surface); color: var(--text); padding: 8px 14px; cursor: pointer; min-height: 40px; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.06); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover:not(:disabled) { color: var(--text); border-color: var(--line-2); }
.btn:disabled { opacity: .45; cursor: default; }
button:focus-visible, input:focus-visible, tr:focus-visible, .ex:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.ex-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: -4px 0 14px; }
.strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 12px; }
.thumb { flex: 0 0 auto; width: 88px; border: 2px solid transparent; border-radius: 10px; background: var(--surface); padding: 3px; cursor: pointer; color: var(--text-2); font: inherit; font-size: 11px; }
.thumb img { width: 100%; height: 56px; object-fit: cover; border-radius: 7px; display: block; }
.thumb .tn { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.thumb.on { border-color: var(--accent); color: var(--text); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.card > h2 { margin-bottom: 10px; }
.side .card:last-child { margin-bottom: 0; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 11px; }
.seg button { border: 0; background: transparent; color: var(--text-2); font: inherit; font-weight: 600; padding: 7px 10px; border-radius: 8px; cursor: pointer; min-height: 40px; display: flex; flex-direction: column; align-items: center; line-height: 1.2; }
.seg button small { font-weight: 500; font-size: 11px; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.small-seg button { min-height: 32px; padding: 4px 10px; font-size: 13px; }
#modelNote { margin: 8px 0 12px; }

.slider { display: block; margin: 10px 0; }
.slider span { display: flex; justify-content: space-between; font-size: 14px; font-weight: 600; }
.slider output { font-weight: 600; color: var(--text-2); font-variant-numeric: tabular-nums; }
.slider input { width: 100%; accent-color: var(--accent); margin: 6px 0 0; height: 28px; }
.toggles { display: flex; gap: 18px; margin-top: 8px; font-size: 14px; }
.toggles input { accent-color: var(--accent); width: 18px; height: 18px; vertical-align: -3px; margin-right: 6px; }

.total { font-size: 14px; color: var(--text-2); }
.total b { font-size: 22px; color: var(--text); font-variant-numeric: tabular-nums; }
.table-scroll { overflow-x: auto; }
.counts-scroll { max-height: 300px; overflow-y: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.tbl th { text-align: left; font-weight: 600; color: var(--text-2); font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 7px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl .num { text-align: right; }
.tbl tbody tr { cursor: pointer; }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl tbody tr.on { background: var(--accent-soft); }
#seriesTable tbody tr { cursor: default; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 8px; vertical-align: 0; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip { font: inherit; font-size: 13px; border: 1px solid var(--line-2); background: var(--surface); color: var(--text-2); border-radius: 999px; padding: 5px 12px; cursor: pointer; min-height: 32px; }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.search { width: 100%; font: inherit; font-size: 14px; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--surface); color: var(--text); min-height: 40px; }
.class-list { max-height: 260px; overflow-y: auto; margin-top: 8px; display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
@media (max-width: 900px) { .class-list { grid-template-columns: 1fr 1fr 1fr; } }
@media (max-width: 520px) { .class-list { grid-template-columns: 1fr 1fr; } }
.cls { display: flex; align-items: center; gap: 6px; font-size: 13px; padding: 4px 0; cursor: pointer; min-height: 30px; }
.cls input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; flex: 0 0 auto; }
.cls span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cls .cnt { font-style: normal; font-size: 12px; color: var(--text-2); font-weight: 600; font-variant-numeric: tabular-nums; }

.chart-wrap { position: relative; }
.chart { width: 100%; height: 220px; display: block; touch-action: pan-y; }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .cross { stroke: var(--line-2); stroke-width: 1; }
.tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--line-2); border-radius: 10px; padding: 8px 10px; font-size: 12px; box-shadow: var(--shadow); min-width: 140px; z-index: 2; }
.tip-h { font-weight: 600; margin-bottom: 4px; color: var(--text-2); }
.tip-row { display: flex; align-items: center; gap: 6px; }
.tip-row span { flex: 1; color: var(--text-2); }
.tip-row b { font-variant-numeric: tabular-nums; color: var(--text); }
.tip-row i, .legend i { display: inline-block; width: 10px; height: 3px; border-radius: 2px; }
.legend { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--text-2); }
.legend li { display: flex; align-items: center; gap: 6px; }
.legend b { color: var(--text); font-variant-numeric: tabular-nums; }

.about { margin-top: 28px; max-width: 76ch; color: var(--text-2); }
.about h2 { color: var(--text); margin-bottom: 6px; }
.about p { margin: 0 0 10px; }
.foot { border-top: 1px solid var(--line); padding: 18px 16px 28px; text-align: center; color: var(--muted); font-size: 13px; }
.foot p { margin: 4px 0; }
