:root {
  --bg: #0d0e14;
  --bg-2: #14161f;
  --panel: #191b26;
  --panel-2: #1f2230;
  --line: #2a2e40;
  --text: #e9ebf3;
  --muted: #8f95ab;
  --accent: #64e0c8;
  --accent-2: #ff6a5c;
  --radius: 14px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "JetBrains Mono", "Cascadia Mono", Consolas, monospace;
}

:root[data-theme="light"] {
  --bg: #f3f4f8;
  --bg-2: #e9ebf2;
  --panel: #ffffff;
  --panel-2: #eef0f6;
  --line: #d6d9e3;
  --text: #171923;
  --muted: #626981;
  --accent: #0f9d84;
  --accent-2: #e5533f;
}
:root[data-theme="light"] .topbar { background: var(--panel); }
:root[data-theme="light"] .stage { background: #e4e6ee; background-image: radial-gradient(rgba(0,0,0,.06) 1px, transparent 1px); }
:root[data-theme="light"] .btn.primary { color: #fff; }
:root[data-theme="light"] .tool { background: rgba(255,255,255,.8); color: var(--text); border-color: rgba(0,0,0,.12); }
:root[data-theme="light"] .tool:hover { background: #fff; }

* { box-sizing: border-box; }

html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; line-height: 1.45; }
body { min-height: 100vh; display: flex; flex-direction: column; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-bottom: 10px; }
p { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 22px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #12141d, var(--bg));
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand h1 { font-size: 18px; }
.brand p { color: var(--muted); font-size: 12.5px; }
.logo {
  width: 36px; height: 36px; border-radius: 10px; flex: none;
  background:
    radial-gradient(circle at 50% 50%, var(--accent-2) 0 5px, transparent 6px),
    linear-gradient(var(--panel-2), var(--panel-2)) padding-box;
  border: 3px solid var(--accent); box-shadow: 0 0 0 1px #000 inset;
}
.topbar-right { display: flex; align-items: center; gap: 12px; }
.badge {
  font-family: var(--mono); font-size: 11.5px; padding: 4px 9px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel); color: var(--muted);
}
.badge.webgpu { color: var(--accent); border-color: rgba(100,224,200,.4); }
.badge.wasm { color: #ffc56a; border-color: rgba(255,197,106,.4); }
.gh { font-size: 13px; color: var(--muted); }

.layout {
  flex: 1; display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 18px;
  padding: 18px 22px; width: 100%; max-width: 1500px; margin: 0 auto;
}
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.controls { padding: 16px; display: flex; flex-direction: column; gap: 18px; align-self: start; position: sticky; top: 14px; }
.controls section { display: flex; flex-direction: column; gap: 8px; }
.hint { color: var(--muted); font-size: 12.5px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.mono { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.icon-btn { border: 1px solid var(--line); background: var(--panel); color: var(--muted); border-radius: 999px; width: 28px; height: 28px; font-size: 14px; line-height: 1; }
.icon-btn:hover { color: var(--text); }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; background: var(--bg-2); border-radius: 10px; border: 1px solid var(--line); }
.seg button { border: 0; background: transparent; border-radius: 7px; padding: 8px 6px; color: var(--muted); font-weight: 600; font-size: 13px; transition: background .15s, color .15s; }
.seg button:hover { color: var(--text); }
.seg button.active { background: var(--panel-2); color: var(--text); box-shadow: 0 1px 0 rgba(255,255,255,.04) inset, 0 2px 8px rgba(0,0,0,.35); }
.seg.small button { padding: 7px 6px; font-size: 12.5px; }
#task-tabs { grid-auto-flow: row; grid-template-columns: repeat(3, 1fr); }
#task-tabs button { padding: 8px 2px; font-size: 12.5px; }

.btn {
  border: 1px solid var(--line); background: var(--panel-2); border-radius: 9px; padding: 9px 13px;
  font-weight: 600; font-size: 13px; flex: 1; transition: filter .15s, transform .05s;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: #062a24; border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.live { background: var(--accent-2); color: #fff; border-color: transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; filter: none; }
.btn.small { padding: 5px 9px; font-size: 12px; flex: none; }
.btn.rec { background: var(--accent-2); color: #fff; border-color: transparent; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { filter: brightness(1.35); } }
.video-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.video-controls input[type="range"] { flex: 1; min-width: 80px; }
.check.small { font-size: 12px; }

.samples { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 4px; }
.samples button { padding: 0; border: 2px solid transparent; border-radius: 8px; overflow: hidden; background: var(--bg-2); aspect-ratio: 4/3; }
.samples button:hover, .samples button.active { border-color: var(--accent); }
.samples img { width: 100%; height: 100%; object-fit: cover; display: block; }

.slider, .select, .check { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.slider span, .select span { display: flex; justify-content: space-between; color: var(--muted); }
.slider output { font-family: var(--mono); color: var(--text); }
input[type="range"] { width: 100%; accent-color: var(--accent); margin: 0; }
textarea { font: inherit; background: var(--bg-2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; resize: vertical; width: 100%; }
select { font: inherit; background: var(--bg-2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; }
.check { flex-direction: row; align-items: center; gap: 8px; }
.check input { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }

.advanced { border-top: 1px solid var(--line); padding-top: 10px; }
.advanced summary { cursor: pointer; color: var(--muted); font-size: 12.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; }
.advanced > :not(summary) { margin-top: 10px; }

.status { gap: 6px; }
.progress { height: 5px; border-radius: 999px; background: var(--bg-2); overflow: hidden; }
#progress-bar { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), #7bd0ff); transition: width .15s; }
#status-text { font-size: 12.5px; color: var(--muted); font-family: var(--mono); min-height: 1.4em; }
#status-text.error { color: var(--accent-2); }

.stage-wrap { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.stage {
  position: relative; background: #07080c; border: 1px solid var(--line); border-radius: var(--radius);
  min-height: 420px; display: grid; place-items: center; overflow: hidden;
  background-image: radial-gradient(rgba(255,255,255,.035) 1px, transparent 1px); background-size: 22px 22px;
}
#canvas { max-width: 100%; max-height: min(78vh, 900px); display: block; border-radius: 4px; }
#canvas.empty { display: none; }
.dropzone { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; color: var(--muted); pointer-events: none; }
.dropzone strong { display: block; font-size: 17px; color: var(--text); margin-bottom: 4px; }
.dropzone.hidden { display: none; }
.stage.dragover { outline: 2px dashed var(--accent); outline-offset: -8px; }
.stage-tools { position: absolute; right: 12px; top: 12px; display: flex; gap: 6px; }
.stage.drawline { cursor: crosshair; }
.editor-bar { position: absolute; left: 12px; right: 12px; bottom: 12px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; background: rgba(10,11,16,.82); color: #dfe3ee; border-radius: 10px; padding: 8px 12px; font-size: 12.5px; backdrop-filter: blur(8px); }
.editor-bar select { padding: 4px 8px; font-size: 12.5px; max-width: 180px; }
.editor-bar kbd { background: #2a2e40; padding: 1px 5px; border-radius: 4px; font-family: var(--mono); }
.editor-bar button { margin-left: auto; }
.editor-bar button + button { margin-left: 0; }
.counter { position: absolute; left: 12px; top: 12px; background: rgba(10,11,16,.78); color: #fff; border-radius: 10px; padding: 8px 12px; font-family: var(--mono); font-size: 13px; line-height: 1.5; backdrop-filter: blur(8px); }
.counter b { color: var(--accent); }
.grid-view { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.grid-view figure { margin: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.grid-view canvas { width: 100%; display: block; }
.grid-view figcaption { padding: 8px 12px; font-size: 12.5px; display: flex; justify-content: space-between; color: var(--muted); }
.grid-view figcaption b { color: var(--text); }
.grid-view .pending { padding: 30px; text-align: center; color: var(--muted); }
.tool { border: 1px solid rgba(255,255,255,.12); background: rgba(10,11,16,.72); backdrop-filter: blur(8px); color: var(--text); border-radius: 8px; padding: 6px 10px; font-size: 12.5px; font-weight: 600; }
.tool:hover { background: rgba(30,32,45,.9); }
.tool:disabled { opacity: .4; }
.tool.on { background: var(--accent); color: #062a24; border-color: transparent; }

.stats { display: flex; flex-wrap: wrap; gap: 18px; font-size: 13px; color: var(--muted); font-family: var(--mono); padding: 0 4px; }
.stats b { color: var(--text); font-weight: 600; }
.stats .dim { margin-left: auto; }

.results { padding: 14px 16px; }
.legend { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 6px 14px; }
.legend li { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.legend .sw { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.legend .v { margin-left: auto; font-family: var(--mono); color: var(--muted); }
.legend .empty { color: var(--muted); grid-column: 1 / -1; }

.foot { padding: 14px 22px 24px; color: var(--muted); font-size: 12px; text-align: center; border-top: 1px solid var(--line); }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 14px; }
  .controls { position: static; }
  .brand p { display: none; }
  .stage { min-height: 260px; }
}

.pc-overlay { position: fixed; inset: 0; z-index: 50; background: #0b0c12; }
.pc-overlay canvas { width: 100%; height: 100%; display: block; }
.pc-bar { position: absolute; top: 12px; left: 12px; right: 12px; display: flex; gap: 14px; align-items: center; flex-wrap: wrap; color: #cfd3e0; font-size: 13px; }
.pc-bar label { display: flex; align-items: center; gap: 6px; background: rgba(10,11,16,.7); padding: 6px 10px; border-radius: 8px; }
.pc-bar button { margin-left: auto; }
