:root {
  --bg: #15181c; --panel: #1e2228; --panel2: #252a31; --line: #323942; --text: #dfe4ea; --muted: #8b96a3;
  --accent: #4aa3ff; --accent2: #2d7fd6; --danger: #ff6b6b; --ok: #5ccf86; --chip: #2b313a;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #e9edf1; --panel: #f7f9fb; --panel2: #eef2f6; --line: #d3dae2; --text: #1d2430; --muted: #66717e;
  --accent: #1f7ae0; --accent2: #1866bd; --chip: #e3e8ee; color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 13px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; }
body { display: grid; grid-template-rows: 44px 1fr auto; overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 5px 10px; cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent2); border-color: var(--accent2); color: #fff; }
button.danger { color: var(--danger); }
button.icon { padding: 5px 8px; }
input, textarea, select { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; }
input:focus, textarea:focus { outline: none; border-color: var(--accent); }
code { background: var(--panel2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
h3 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); display: flex; gap: 6px; align-items: baseline; }
h4 { margin: 14px 0 6px; font-size: 12px; color: var(--muted); }
.hint { color: var(--muted); font-size: 12px; }
.row { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }

.topbar { display: flex; align-items: center; gap: 10px; padding: 0 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; display: flex; gap: 6px; align-items: center; white-space: nowrap; }
.logo { color: var(--accent); font-size: 18px; }
.build-name { width: 280px; background: transparent; border-color: transparent; font-weight: 600; }
.build-name:hover:not(:disabled) { border-color: var(--line); }
.seg { display: flex; }
.seg button { border-radius: 0; margin-left: -1px; }
.seg button:first-child { border-radius: 6px 0 0 6px; }
.seg button:last-child { border-radius: 0 6px 6px 0; }
.toggle { display: flex; gap: 5px; align-items: center; white-space: nowrap; color: var(--muted); }
.menu { position: relative; }
.menu-list { position: absolute; right: 0; top: calc(100% + 4px); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 4px; z-index: 20; min-width: 220px; box-shadow: 0 8px 24px #0006; max-height: 60vh; overflow: auto; }
.menu.up .menu-list { top: auto; bottom: calc(100% + 4px); left: 0; right: auto; }
.menu-list a { display: block; padding: 6px 10px; border-radius: 5px; cursor: pointer; }
.menu-list a:hover { background: var(--panel2); }
.menu-list a small { display: block; color: var(--muted); }

.layout { display: grid; grid-template-columns: 270px 1fr 290px; min-height: 0; }
.sidebar, .inspector { background: var(--panel); min-height: 0; display: flex; flex-direction: column; }
.sidebar { border-right: 1px solid var(--line); }
.inspector { border-left: 1px solid var(--line); }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; border: 0; border-radius: 0; background: none; padding: 9px 4px; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.tab { padding: 10px; overflow: auto; flex: 1; min-height: 0; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.list li:hover { background: var(--panel2); }
.list li.active { background: color-mix(in srgb, var(--accent) 18%, transparent); }
.list li .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list li .sub { color: var(--muted); font-size: 11px; }
.list li .acts { display: none; gap: 2px; }
.list li:hover .acts { display: flex; }
.list li .acts button { padding: 1px 6px; font-size: 11px; }
.search { width: 100%; margin-bottom: 6px; }
.swatch { width: 22px; height: 22px; border-radius: 3px; flex: none; image-rendering: pixelated; background-size: 100% auto; background-position: top; border: 1px solid #0003; }

.drop { display: flex; flex-direction: column; gap: 4px; padding: 16px; border: 2px dashed var(--line); border-radius: 10px; text-align: center; cursor: pointer; margin-bottom: 8px; }
.drop span { color: var(--muted); font-size: 12px; }
.drop.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.badge { font-size: 10px; padding: 1px 6px; border-radius: 9px; background: var(--chip); color: var(--muted); text-transform: uppercase; }

.viewport { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
.viewport canvas { display: block; width: 100%; height: 100%; }
.overlay { position: absolute; pointer-events: none; }
.stats { left: 10px; bottom: 10px; background: #000a; color: #fff; padding: 4px 8px; border-radius: 6px; font-size: 12px; }
.stats:empty { display: none; }
.empty { inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; color: var(--muted); }
.empty h2 { color: var(--text); margin: 0 0 6px; }
.empty code { margin-top: 8px; pointer-events: auto; user-select: all; }
.tooltip { background: #000c; color: #fff; padding: 5px 8px; border-radius: 6px; font-size: 12px; white-space: nowrap; transform: translate(14px, 14px); }
.tooltip b { color: #9fd0ff; }
.clip { right: 10px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: auto; background: #000a; color: #fff; padding: 8px 6px; border-radius: 8px; font-size: 12px; }
.clip input { writing-mode: vertical-lr; direction: rtl; height: 200px; width: 18px; padding: 0; }
.isolate { top: 10px; left: 50%; transform: translateX(-50%); pointer-events: auto; background: var(--accent2); color: #fff; padding: 4px 10px; border-radius: 14px; cursor: pointer; }

.panel { padding: 12px; border-bottom: 1px solid var(--line); }
.panel.grow { flex: 1; overflow: auto; border-bottom: 0; }
.feature-form label { display: block; color: var(--muted); font-size: 11px; margin: 8px 0 3px; }
.feature-form input[type=text], .feature-form textarea { width: 100%; }
.feature-form textarea { min-height: 180px; font: 12px/1.4 ui-monospace, Menlo, monospace; resize: vertical; }
.feature-form .err { color: var(--danger); font-size: 12px; margin-top: 4px; white-space: pre-wrap; }
.feature-form .desc { color: var(--muted); font-size: 12px; margin: 4px 0; }
.materials .count { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; text-align: right; }

.timeline { background: var(--panel); border-top: 1px solid var(--line); display: flex; align-items: stretch; height: 78px; }
.tl-controls { display: flex; gap: 4px; align-items: center; padding: 0 10px; border-right: 1px solid var(--line); }
.tl-controls button { padding: 5px 8px; }
.tl-track { flex: 1; display: flex; align-items: center; gap: 2px; padding: 0 10px; overflow-x: auto; }
.chip { flex: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; width: 64px; height: 56px; border-radius: 8px; background: var(--chip); border: 1px solid transparent; cursor: pointer; position: relative; user-select: none; }
.chip .ic { font-size: 18px; line-height: 1; }
.chip .nm { font-size: 10px; max-width: 58px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.chip.sel { border-color: var(--accent); }
.chip.off { opacity: .45; text-decoration: line-through; }
.chip.future { opacity: .3; }
.chip.err::after { content: "!"; position: absolute; top: 2px; right: 5px; color: var(--danger); font-weight: 700; }
.chip.dragging { opacity: .4; }
.marker { flex: none; width: 6px; height: 56px; border-radius: 3px; background: var(--accent); cursor: ew-resize; margin: 0 2px; }
.marker.drop-target { background: var(--ok); }
.flash { animation: flash .8s ease-out; }
@keyframes flash { from { box-shadow: 0 0 0 3px var(--ok); } to { box-shadow: 0 0 0 0 transparent; } }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: 40vh 1fr; }
  .sidebar { display: none; }
  .inspector { border-left: 0; border-top: 1px solid var(--line); }
  .build-name { width: 140px; }
  .seg, .toggle { display: none; }
}
