:root {
  --bg: #0b0d12;
  --bg2: #10131a;
  --card: #151922;
  --card2: #1b202b;
  --ink: #e9ecf2;
  --muted: #8d95a5;
  --line: #262c38;
  --accent: #2dd4bf;
  --accent-ink: #04201c;
  --accent-dim: rgba(45, 212, 191, 0.16);
  --warn: #f5b84b;
  --bad: #ff7a6b;
  --good: #2dd4bf;
  --radius: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
code { font-size: 0.88em; background: var(--card2); padding: 1px 5px; border-radius: 5px; }
.wrap { max-width: 1240px; margin: 0 auto; padding: 0 16px; }
[hidden] { display: none !important; }

/* header */
.top { background: linear-gradient(180deg, #0f1420 0%, var(--bg) 100%); border-bottom: 1px solid var(--line); }
.topbar { display: flex; gap: 20px; justify-content: space-between; align-items: flex-start; padding-top: 16px; padding-bottom: 8px; }
.brand h1 { margin: 0; font-size: 24px; letter-spacing: -0.02em; }
.brand .sub { margin: 4px 0 0; color: var(--muted); max-width: 640px; font-size: 14px; }
.statusbox { min-width: 260px; max-width: 360px; }
.status { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.status .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.status.ready .dot { background: var(--accent); box-shadow: 0 0 0 4px var(--accent-dim); }
.status.loading .dot { background: var(--warn); animation: blink 1s infinite; }
.status.error .dot { background: var(--bad); }
@keyframes blink { 50% { opacity: .3; } }
.chips { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.chip { font-size: 12px; padding: 2px 9px; border-radius: 999px; background: var(--card2); color: var(--muted); border: 1px solid var(--line); }
.chip:empty { display: none; }
.chip.safe { color: var(--accent); border-color: rgba(45,212,191,.35); background: var(--accent-dim); }
.progress { height: 4px; background: var(--line); border-radius: 2px; margin-top: 8px; overflow: hidden; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width .25s ease; }
.warn { color: var(--warn); font-size: 12px; margin: 6px 0 0; }
.tabs { display: flex; gap: 2px; overflow-x: auto; }
.tab { background: none; border: none; color: var(--muted); padding: 10px 14px; font: inherit; font-weight: 600; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tab.active { color: var(--ink); border-bottom-color: var(--accent); }

/* buttons and fields */
button { font: inherit; cursor: pointer; border-radius: 10px; padding: 8px 14px; border: 1px solid var(--line); background: var(--card2); color: var(--ink); transition: background .15s, border-color .15s, transform .1s; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:active:not(:disabled) { transform: scale(.98); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; width: 100%; margin-top: 10px; }
button.primary.inline { width: auto; margin-top: 0; }
button.ghost { background: transparent; }
button.small { padding: 4px 10px; font-size: 13px; }
select, input[type=text], textarea { font: inherit; color: var(--ink); background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 7px 10px; width: 100%; }
select:focus, input:focus, textarea:focus { outline: 2px solid var(--accent-dim); border-color: var(--accent); }
textarea { resize: vertical; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 13px; }
input[type=range] { accent-color: var(--accent); width: 100%; }
.note { color: var(--muted); font-size: 13px; margin: 8px 0; }

/* live layout */
.view { padding-top: 16px; padding-bottom: 16px; }
.livegrid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 18px; align-items: start; }
@media (max-width: 900px) { .livegrid { grid-template-columns: 1fr; } }
.sources { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.src.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.stage { position: relative; aspect-ratio: 4 / 3; background: #05070a; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.stage video, .stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.stage video { opacity: 0; }
.stage.camera video { opacity: 1; }
.stage.camera canvas { opacity: 0; }
.stage.mirror video { transform: scaleX(-1); }
.badge { position: absolute; top: 12px; left: 12px; display: flex; align-items: center; gap: 8px; background: rgba(5,7,10,.72); color: var(--ink); border: 1px solid rgba(45,212,191,.45); padding: 5px 11px; border-radius: 999px; font-size: 12.5px; font-weight: 600; backdrop-filter: blur(6px); }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 0 rgba(45,212,191,.7); animation: pulse 1.6s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 9px rgba(45,212,191,0); } 100% { box-shadow: 0 0 0 0 rgba(45,212,191,0); } }
.hud { position: absolute; top: 12px; right: 12px; background: rgba(5,7,10,.72); padding: 5px 10px; border-radius: 999px; font-size: 12.5px; font-variant-numeric: tabular-nums; color: var(--muted); }
.hud span:not(.sep):not(.unit) { color: var(--ink); font-weight: 700; }
.hud .sep { opacity: .4; margin: 0 4px; }
.overlay { position: absolute; left: 12px; right: 12px; bottom: 12px; display: flex; align-items: center; gap: 14px; background: rgba(5,7,10,.74); border: 1px solid var(--line); border-radius: 16px; padding: 10px 14px; backdrop-filter: blur(8px); }
.ring { width: 76px; height: 76px; flex: none; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 10; }
.ring-bg { stroke: rgba(255,255,255,.08); }
.ring-fg { stroke: var(--accent); stroke-linecap: round; stroke-dasharray: 326.73; stroke-dashoffset: 326.73; transition: stroke-dashoffset .35s ease, stroke .35s; }
.overlay.uncertain .ring-fg { stroke: var(--warn); }
.ovtext { min-width: 0; }
.ovq { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ovlabel { font-size: clamp(22px, 4.2vw, 36px); font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.overlay.uncertain .ovlabel { color: var(--warn); }
.ovpct { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.idle { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 6px; background: radial-gradient(ellipse at center, rgba(45,212,191,.10), rgba(5,7,10,.85) 70%); padding: 16px; }
.idle p { color: var(--muted); font-size: 13px; margin: 0; }
button.big { background: var(--accent); color: var(--accent-ink); border: none; font-weight: 800; font-size: 17px; padding: 14px 26px; border-radius: 999px; box-shadow: 0 8px 30px rgba(45,212,191,.25); }
.controls { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-top: 10px; }
.controls label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 3px; flex: 1; min-width: 120px; }
.gate { display: flex; gap: 10px; align-items: center; margin-top: 12px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; flex-wrap: wrap; }
.gate > div { display: flex; flex-direction: column; flex: 1; min-width: 90px; }
.gnum { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }
.gnum.accent { color: var(--accent); }
.gnum.warnc { color: var(--warn); }
.glab { font-size: 12px; color: var(--muted); }

/* cards */
.cardhead { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.cardhead h2 { margin: 0 0 10px; font-size: 17px; }
.cards { display: grid; gap: 12px; }
.dcard { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; transition: border-color .25s, box-shadow .25s; }
.dcard.primary { border-color: rgba(45,212,191,.55); box-shadow: 0 0 0 1px rgba(45,212,191,.15) inset; }
.dcard.uncertain { border-color: rgba(245,184,75,.55); }
.dtop { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.dtitle { font-weight: 700; font-size: 14.5px; }
.dact { display: flex; gap: 4px; flex: none; }
.dact button { padding: 2px 8px; font-size: 12px; border-radius: 8px; }
.dverdict { margin: 6px 0 8px; font-size: 13px; color: var(--muted); min-height: 20px; }
.dverdict b { color: var(--accent); font-size: 15px; }
.dcard.uncertain .dverdict b { color: var(--warn); }
.obar { display: grid; grid-template-columns: minmax(70px, 34%) 1fr 48px; gap: 8px; align-items: center; margin: 4px 0; font-size: 13px; }
.obar .k { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.obar.top .k { color: var(--ink); font-weight: 600; }
.obar .track { height: 12px; background: rgba(255,255,255,.06); border-radius: 6px; overflow: hidden; position: relative; }
.obar .fill { height: 100%; width: 0; background: #3a4558; border-radius: 6px; transition: width .35s cubic-bezier(.2,.8,.2,1), background .3s; }
.obar.top .fill { background: var(--accent); }
.dcard.uncertain .obar.top .fill { background: var(--warn); }
.obar .p { text-align: right; font-variant-numeric: tabular-nums; font-size: 12.5px; }
.thr { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.thr input { flex: 1; }
.thr .tv { width: 34px; text-align: right; color: var(--ink); font-variant-numeric: tabular-nums; }
.dstats { font-size: 12px; color: var(--muted); margin-top: 4px; }
.dedit { margin-top: 8px; display: grid; gap: 6px; }
.templates { margin-top: 16px; }
.templates h3 { font-size: 14px; margin: 0 0 8px; color: var(--muted); font-weight: 600; }
.tpls { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.tpls button { font-size: 13px; padding: 5px 11px; border-radius: 999px; }

/* single / samples */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 800px) { .grid2 { grid-template-columns: 1fr; } }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; }
.panel h2 { margin: 0 0 12px; font-size: 17px; }
.wide { grid-column: 1 / -1; }
.subtabs { display: flex; gap: 4px; margin-bottom: 10px; flex-wrap: wrap; }
.subtab { padding: 5px 12px; font-size: 13px; }
.subtab.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.col { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; font-size: 13px; color: var(--muted); }
.drop { display: block; border: 1px dashed var(--line); border-radius: 10px; padding: 12px; color: var(--muted); cursor: pointer; margin: 8px 0; font-size: 13px; }
.drop input { display: block; margin-bottom: 4px; max-width: 100%; color: var(--ink); }
#imagePreview, #videoPreview { max-width: 100%; max-height: 300px; border-radius: 10px; display: block; margin-top: 8px; }
#audioPreview { width: 100%; margin-top: 8px; }
.seg { display: flex; gap: 16px; font-size: 14px; }
.seg input { accent-color: var(--accent); }
.adv { margin: 10px 0; border-top: 1px solid var(--line); padding-top: 8px; }
.adv summary { cursor: pointer; color: var(--muted); font-size: 14px; }
.decision { font-size: 22px; margin: 0 0 10px; font-weight: 800; }
.decision b { color: var(--accent); }
.meta { color: var(--muted); font-size: 13px; margin-top: 10px; }
.prompts { margin-top: 8px; font-size: 12px; color: var(--muted); }
.prompts pre { white-space: pre-wrap; word-break: break-word; background: var(--bg2); border: 1px solid var(--line); padding: 8px; border-radius: 8px; color: var(--ink); }
.btnrow { display: flex; gap: 8px; flex-wrap: wrap; }
.summary { margin: 12px 0; font-size: 16px; }
.summary b { color: var(--accent); }
.tablewrap { overflow-x: auto; margin-top: 8px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; }
td.ok { color: var(--accent); font-weight: 700; }
td.no { color: var(--bad); font-weight: 700; }
.prose { max-width: 860px; }
.prose li { margin: 4px 0; }
.prose h3 { margin: 18px 0 6px; font-size: 15px; }
.foot { color: var(--muted); font-size: 12.5px; padding-bottom: 24px; }
@media (max-width: 600px) {
  .topbar { flex-direction: column; gap: 8px; }
  .statusbox { min-width: 0; max-width: none; width: 100%; }
  .brand .sub { display: none; }
  .ring { width: 58px; height: 58px; }
  .stage { aspect-ratio: 3 / 4; }
  .badge { font-size: 11.5px; padding: 4px 9px; left: 8px; top: 8px; }
  .hud { top: 44px; left: 8px; right: auto; font-size: 11.5px; }
  .overlay { left: 8px; right: 8px; bottom: 8px; gap: 10px; padding: 8px 10px; }
}

/* egg check */
.egggrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; margin: 12px 0; }
.eggthumb { padding: 6px; display: flex; flex-direction: column; gap: 4px; align-items: stretch; font-size: 12px; color: var(--muted); }
.eggthumb img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; background: #000; display: block; }
.btnrow .drop.inline { display: inline-block; margin: 0; padding: 8px 12px; }
.eggresult { display: grid; grid-template-columns: minmax(120px, 220px) 1fr; gap: 16px; align-items: start; margin: 12px 0; }
.eggresult img { width: 100%; border-radius: 10px; background: #000; }
@media (max-width: 560px) { .eggresult { grid-template-columns: 1fr; } }
.okc { color: var(--good); font-weight: 600; margin-left: 6px; }
.noc { color: var(--bad); font-weight: 600; margin-left: 6px; }
img.mini { width: 32px; height: 32px; object-fit: cover; border-radius: 4px; vertical-align: middle; margin-right: 6px; }
.dctx { display: block; font-size: 12px; font-weight: 400; color: var(--muted); }
.dedit input + input { margin-top: 6px; }
