:root {
  --bg: #f5f4fa; --panel: #ffffff; --ink: #1b1830; --muted: #5d5a72; --line: #e2dfee;
  --accent: #5b3fd1; --accent-ink: #ffffff; --accent-soft: #ece8fc; --bad: #b3261e; --bad-soft: #fbe4e2;
  --good: #1f7a4a; --good-soft: #e1f3e8; --warn: #8a5a00; --meter-bg: #e7e4f1; --focus: #5b3fd1;
  --radius: 14px; --shadow: 0 1px 2px rgba(20, 15, 50, .06), 0 6px 24px rgba(20, 15, 50, .06);
  --c0: #5b3fd1; --c1: #e0603a; --c2: #1f9d74; --c3: #d79b00; --c4: #2a7fd4; --c5: #c2378f; --c6: #6b8e23; --c7: #8b5a2b; --c8: #008b8b; --c9: #7a7a7a;
}
:root[data-theme="dark"] {
  --bg: #0f0e17; --panel: #1a1826; --ink: #ebe9f5; --muted: #a3a0b8; --line: #2e2b40;
  --accent: #a593ff; --accent-ink: #120d2b; --accent-soft: #272144; --bad: #ff9c94; --bad-soft: #3c1f1e;
  --good: #6fd39b; --good-soft: #183326; --warn: #ffc56b; --meter-bg: #2b2840; --focus: #b9aaff; --shadow: none;
  --c0: #a593ff; --c1: #ff8a63; --c2: #4fd1a5; --c3: #f5c242; --c4: #6cb2ff; --c5: #ff7cc6; --c6: #a6cf5a; --c7: #d4a373; --c8: #4fd6d6; --c9: #b5b5b5;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.warn { color: var(--warn); margin: 6px 0 0; min-height: 1.2em; }
.warn.bad { color: var(--bad); }

.topbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 16px; max-width: 1320px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand-name { font-weight: 750; font-size: 1.15rem; letter-spacing: -.01em; }
.pill { font-size: .78rem; padding: 3px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.top-link { font-size: .9rem; text-decoration: none; color: var(--muted); }
.icon-btn { border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 10px; width: 40px; height: 40px; display: grid; place-items: center; cursor: pointer; }

.wrap { max-width: 1320px; margin: 0 auto; padding: 0 16px 32px; }
.hero { padding: 14px 0 6px; }
.hero h1 { font-size: clamp(1.55rem, 4vw, 2.3rem); line-height: 1.15; margin: 0 0 8px; letter-spacing: -.02em; }
.lede { margin: 0 0 16px; max-width: 48rem; color: var(--muted); font-size: 1.05rem; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.status-line { margin: 12px 0 0; font-size: .92rem; color: var(--muted); }
body.has-project .hero .lede, body.has-project .hero-actions { display: none; }
body.has-project .hero h1 { font-size: 1.3rem; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 10px; padding: 10px 16px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; min-height: 44px; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-ghost { background: transparent; }
.btn-small { padding: 6px 12px; min-height: 36px; font-size: .9rem; }
.btn-wide { width: 100%; margin-top: 12px; }
.btn-danger { color: var(--bad); }
.btn-danger:hover:not(:disabled) { border-color: var(--bad); background: var(--bad-soft); }
.link-btn { border: 0; background: none; color: var(--accent); font: inherit; font-size: .85rem; cursor: pointer; padding: 4px 6px; min-height: 32px; }

.banner { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; justify-content: space-between; background: var(--accent-soft); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 14px; margin: 12px 0; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; margin: 12px 0; min-width: 0; }

.projbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.proj-name { font: inherit; font-weight: 700; font-size: 1.05rem; border: 1px solid transparent; background: transparent; color: var(--ink); border-radius: 8px; padding: 6px 8px; min-width: 0; flex: 1 1 200px; }
.proj-name:hover, .proj-name:focus { border-color: var(--line); background: var(--bg); }
.projbar select, .cam-controls select, .fields select, .fields input { font: inherit; font-size: .92rem; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--ink); min-height: 36px; max-width: 100%; }
.projbar-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.save-state { flex-basis: 100%; margin: 0; }

.grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr) minmax(0, 1fr); gap: 0 14px; align-items: start; }
@media (max-width: 1100px) { .grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } .grid > .col:first-child { grid-column: 1 / -1; } }
@media (max-width: 720px) { .grid { grid-template-columns: minmax(0, 1fr); } }
.col-head { display: flex; align-items: center; gap: 10px; justify-content: space-between; margin-bottom: 8px; }
.col-head h2 { margin: 0; font-size: 1.15rem; display: flex; align-items: center; gap: 8px; }
.step { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: .9rem; }
.h3 { font-size: 1rem; margin: 16px 0 6px; }
.badge { font-size: .78rem; padding: 2px 10px; border-radius: 999px; background: var(--meter-bg); color: var(--muted); font-weight: 600; }
.badge.ok { background: var(--good-soft); color: var(--good); }
.badge.stale { background: var(--bad-soft); color: var(--bad); }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }

/* classes */
.classes { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.cls { border: 1px solid var(--line); border-left: 5px solid var(--cc, var(--accent)); border-radius: 12px; padding: 10px; background: var(--panel); }
.cls.dragover { background: var(--accent-soft); border-style: dashed; }
.cls-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cls-name { font: inherit; font-weight: 650; border: 1px solid transparent; background: transparent; color: var(--ink); border-radius: 8px; padding: 4px 6px; flex: 1 1 140px; min-width: 0; }
.cls-name:hover, .cls-name:focus { border-color: var(--line); background: var(--bg); }
.cls-count { font-size: .82rem; color: var(--muted); white-space: nowrap; }
.cls-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 6px; margin-top: 8px; max-height: 196px; overflow-y: auto; }
.thumb { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--meter-bg); border: 2px solid transparent; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.pending::after { content: ""; position: absolute; inset: 0; background: rgba(255,255,255,.45); }
:root[data-theme="dark"] .thumb.pending::after { background: rgba(0,0,0,.45); }
.thumb.wrong { border-color: var(--bad); }
.thumb .x { position: absolute; top: 2px; right: 2px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; font-size: 14px; line-height: 22px; padding: 0; cursor: pointer; opacity: 0; }
.thumb:hover .x, .thumb .x:focus-visible { opacity: 1; }
@media (hover: none) { .thumb .x { opacity: .85; } }
.thumb .tag { position: absolute; left: 0; right: 0; bottom: 0; font-size: .66rem; line-height: 1.3; padding: 1px 3px; background: rgba(0,0,0,.65); color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty-cls { font-size: .85rem; color: var(--muted); margin: 8px 0 0; }

/* camera */
.camera { border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 10px; background: var(--bg); }
.video-box { position: relative; width: 100%; max-width: 420px; margin: 0 auto 8px; aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: #000; }
.video-box video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); display: block; }
.video-box.back video { transform: none; }
.rec-dot { position: absolute; top: 8px; left: 8px; background: #d22; color: #fff; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.cam-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.hold-btn { user-select: none; -webkit-user-select: none; touch-action: none; }
.hold-btn.active { background: #d22; border-color: #d22; color: #fff; }

/* train */
.choice { border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px 10px; margin: 0 0 10px; }
.choice legend { font-size: .85rem; font-weight: 650; color: var(--muted); padding: 0 4px; }
.opt { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; cursor: pointer; }
.opt input { margin-top: 5px; accent-color: var(--accent); width: 18px; height: 18px; }
.advanced summary { cursor: pointer; font-weight: 600; font-size: .92rem; padding: 6px 0; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px 12px; margin: 6px 0 10px; }
.fields label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); }
.fields label.check { flex-direction: row; align-items: center; gap: 8px; grid-column: 1 / -1; color: var(--ink); }
.progress { margin-top: 12px; }
.stages { list-style: none; display: flex; flex-wrap: wrap; gap: 4px 14px; padding: 0; margin: 0 0 8px; font-size: .85rem; color: var(--muted); }
.stages li::before { content: "\25CB"; margin-right: 5px; }
.stages li.active { color: var(--ink); font-weight: 600; }
.stages li.active::before { content: "\25D4"; color: var(--accent); }
.stages li.done::before { content: "\2713"; color: var(--good); }
.stages li.skipped { text-decoration: line-through; }
.meter { height: 8px; background: var(--meter-bg); border-radius: 999px; overflow: hidden; }
.meter span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.kpi { background: var(--bg); border-radius: 10px; padding: 8px 10px; display: flex; flex-direction: column; }
.kpi-v { font-size: 1.35rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.kpi-l { font-size: .75rem; color: var(--muted); }
.loss { width: 100%; height: 70px; margin-top: 8px; }
.loss path { fill: none; stroke: var(--accent); stroke-width: 2; }
.loss text { fill: var(--muted); font-size: 10px; }
.loss line { stroke: var(--line); }
.cm-wrap { overflow-x: auto; }
.cm { border-collapse: collapse; font-size: .82rem; font-variant-numeric: tabular-nums; }
.cm th, .cm td { padding: 4px 6px; text-align: center; border: 1px solid var(--line); min-width: 34px; }
.cm th { font-weight: 600; color: var(--muted); max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cm th.rowh { text-align: left; }
.cm td.diag { font-weight: 700; }
.cm td.miss { color: var(--bad); font-weight: 700; }
.cm td.rec { color: var(--muted); }

/* try it */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.tab { border: 0; background: none; font: inherit; font-weight: 600; color: var(--muted); padding: 8px 12px; cursor: pointer; border-bottom: 3px solid transparent; min-height: 40px; }
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.small-tabs .tab { font-size: .85rem; padding: 6px 10px; min-height: 34px; }
.drop { display: block; border: 2px dashed var(--line); border-radius: 12px; padding: 18px; text-align: center; color: var(--muted); cursor: pointer; }
.drop.dragover { border-color: var(--accent); background: var(--accent-soft); }
.tests { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 6px; max-height: 300px; overflow-y: auto; }
.tests li { display: grid; grid-template-columns: 48px minmax(0, 1fr); gap: 10px; align-items: center; padding: 4px; border-radius: 8px; }
.tests li.sel { background: var(--accent-soft); }
.tests img { width: 48px; height: 48px; object-fit: cover; border-radius: 6px; }
.tests .t-name { font-size: .8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tests button { all: unset; cursor: pointer; display: contents; }
.bars { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.bar { display: grid; grid-template-columns: minmax(70px, 34%) minmax(0, 1fr) 3.4em; gap: 8px; align-items: center; font-size: .9rem; }
.bar .lbl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.bar .track { height: 18px; background: var(--meter-bg); border-radius: 6px; overflow: hidden; }
.bar .fill { height: 100%; width: 0; background: var(--cc, var(--accent)); transition: width .15s; }
.bar .pct { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.bar.top .pct { color: var(--ink); font-weight: 700; }
.export { border-top: 1px solid var(--line); margin-top: 16px; }
.code { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px; font-size: .74rem; line-height: 1.45; max-height: 260px; overflow: auto; white-space: pre; }

.about .how { padding-left: 1.2rem; margin: 0; display: grid; gap: 6px; }
.foot { max-width: 1320px; margin: 0 auto; padding: 8px 16px 32px; color: var(--muted); font-size: .85rem; }
.foot p { margin: 4px 0; }
