:root {
  --bg: #0e1116; --panel: #161b22; --panel2: #1c232d; --line: #2a3140;
  --fg: #e6edf3; --muted: #9aa7b8; --accent: #4f8cff; --warn: #f5b301; --err: #ef5da8;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font-family: system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--fg); display: flex; flex-direction: column; }

/* Header */
header { display: flex; align-items: center; gap: 24px; padding: 12px 20px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { display: flex; align-items: baseline; gap: 10px; }
h1 { margin: 0; font-size: 20px; }
.badge { font-size: 10px; background: var(--accent); color: #fff; padding: 2px 6px; border-radius: 4px; vertical-align: middle; }
.ver { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.modes { display: flex; gap: 4px; margin-left: auto; }
.mode { background: none; border: none; color: var(--muted); padding: 8px 14px; cursor: pointer; border-radius: 6px; font-size: 14px; }
.mode:hover { background: var(--panel2); color: var(--fg); }
.mode.active { background: var(--accent); color: #fff; }
.links { display: flex; gap: 12px; font-size: 13px; }
.links a { color: var(--accent); text-decoration: none; }

/* Layout */
.layout { flex: 1; display: grid; grid-template-columns: 270px 1fr 250px; min-height: 0; }
.sidebar, .results { background: var(--panel); overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 18px; }
.sidebar { border-right: 1px solid var(--line); }
.results { border-left: 1px solid var(--line); }
.stage { position: relative; padding: 16px; display: flex; align-items: center; justify-content: center; overflow: hidden; }

.panel-block { display: flex; flex-direction: column; gap: 8px; }
.block-title { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }

select, input[type="number"], input[type="range"] { background: var(--panel2); color: var(--fg); border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; font-size: 13px; width: 100%; }
select option:disabled { color: #5b6573; }

/* Controls */
.ctrl { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.ctrl > label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.ctrl-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ctrl-row input[type="range"] { flex: 1; padding: 0; }
.ctrl-row input[type="number"] { width: 70px; }
.chip { display: inline-flex; align-items: center; gap: 3px; font-size: 12px; color: var(--fg); background: var(--panel2); border: 1px solid var(--line); border-radius: 4px; padding: 3px 7px; cursor: pointer; }

/* Parts */
.parts { display: flex; flex-direction: column; gap: 4px; max-height: 160px; overflow-y: auto; }
.parts-empty { color: var(--muted); font-size: 12px; padding: 4px; }
.part-row { display: flex; align-items: center; gap: 6px; background: var(--panel2); border-radius: 4px; padding: 4px 6px; }
.part-id { flex: 1; font-size: 12px; }
.part-qty { width: 56px; }
.part-del { background: none; border: none; color: var(--err); cursor: pointer; font-size: 16px; line-height: 1; }
.parts-actions { margin-top: 6px; }
.btn-file { display: inline-block; font-size: 12px; color: var(--accent); cursor: pointer; border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; text-align: center; }

.run-btn { margin-top: auto; background: var(--accent); color: #fff; border: none; border-radius: 8px; padding: 11px; font-size: 15px; cursor: pointer; }
.run-btn:disabled { opacity: 0.5; cursor: progress; }

/* Stage */
canvas { max-width: 100%; max-height: 100%; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); cursor: grab; }
canvas:active { cursor: grabbing; }
.stage-hint { position: absolute; top: 20px; left: 20px; font-size: 11px; color: var(--muted); pointer-events: none; background: rgba(14,17,22,.7); padding: 3px 8px; border-radius: 4px; }
.tooltip { position: absolute; pointer-events: none; background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 6px 9px; font-size: 12px; z-index: 10; white-space: nowrap; }
.sheet-tabs { position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; gap: 4px; }
.sheet-tab { background: var(--panel2); border: 1px solid var(--line); color: var(--muted); border-radius: 4px; padding: 4px 10px; font-size: 12px; cursor: pointer; }
.sheet-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Results */
.metrics { font-size: 13px; color: var(--fg); line-height: 1.7; }
.metrics .row { display: flex; justify-content: space-between; }
.metrics .k { color: var(--muted); }
.metrics .warn { color: var(--warn); }
.metrics .err { color: var(--err); }
.utilbar { height: 8px; background: var(--panel2); border-radius: 4px; overflow: hidden; }
.utilbar span { display: block; height: 100%; background: var(--accent); transition: width .3s; }
.legend { display: flex; flex-direction: column; gap: 5px; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.legend-swatch { width: 14px; height: 14px; border-radius: 3px; }
.export-actions { display: flex; gap: 8px; }
.btn { flex: 1; background: var(--panel2); color: var(--fg); border: 1px solid var(--line); border-radius: 6px; padding: 8px; font-size: 13px; cursor: pointer; }
.btn:hover { border-color: var(--accent); }

/* Responsive */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; grid-auto-rows: min-content; }
  .sidebar, .results { border: none; border-bottom: 1px solid var(--line); }
  .stage { min-height: 420px; }
}
