:root {
  color-scheme: dark;
  --bg: #191416;
  --panel: #251e20;
  --line: #463538;
  --text: #f5e9d8;
  --muted: #c2afa5;
  --accent: #efcb95;
  --intake: #a4ccc4;
  --compression: #c7b0d7;
  --power: #e1ba7c;
  --exhaust: #dfa39a;
  font: 16px/1.45 system-ui, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 0; background: radial-gradient(ellipse at top left, #33232a 0%, var(--bg) 62%); color: var(--text); }
button, input, select { font: inherit; }
button, select { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }

.dashboard { max-width: 1248px; margin: 0 auto; padding: clamp(18px, 4vw, 48px); }
.page-header { display: flex; justify-content: space-between; align-items: end; gap: 16px; margin-bottom: 28px; }
h1 { margin: 0; font-size: clamp(1.65rem, 5vw, 3rem); line-height: 1.05; letter-spacing: -.045em; }
h2 { margin: 0; font-size: .95rem; font-weight: 650; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1fr) 305px; gap: 16px; align-items: stretch; }
.sidebar { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }

.panel { min-width: 0; border: 1px solid var(--line); border-radius: 18px; background: var(--panel); box-shadow: 0 12px 32px #0f090b55; overflow: hidden; }
.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 56px; padding: 10px 18px; border-bottom: 1px solid var(--line); }
.engine-panel { display: flex; flex-direction: column; }
.status { display: flex; align-items: center; gap: 7px; white-space: nowrap; font-size: .75rem; color: var(--muted); }
.status::before { content: ""; width: 7px; height: 7px; background: currentColor; border-radius: 50%; }
.status[data-state="running"] { color: var(--accent); }
.status[data-state="limiting"], .status[data-state="starting"] { color: var(--power); }
.status[data-state="stalled"] { color: var(--exhaust); }

.stage { position: relative; flex: 1 0 auto; min-height: 365px; background-color: #241b20; background-image: radial-gradient(ellipse at center, #4a3326a0, transparent 72%), radial-gradient(#956b5942 1px, transparent 1px); background-size: 100% 100%, 24px 24px; }
canvas { display: block; position: absolute; inset: 0; width: 100%; height: 100%; }
.legend { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 0; padding: 14px 18px; list-style: none; border-top: 1px solid var(--line); }
.legend li { display: flex; align-items: center; gap: 8px; min-height: 38px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px; background: #2f2426; color: var(--text); font-size: .82rem; }
.legend li span { flex: 0 0 4px; height: 14px; border-radius: 3px; background: var(--stroke-color); }
.intake { --stroke-color: var(--intake); }
.compression { --stroke-color: var(--compression); }
.power { --stroke-color: var(--power); }
.exhaust { --stroke-color: var(--exhaust); }
.cutaway-footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 18px; border-top: 1px solid var(--line); }
.firing { display: flex; align-items: baseline; flex-wrap: wrap; gap: 5px 12px; margin: 0; color: var(--muted); font-size: .77rem; }
.firing span { color: var(--text); font: .83rem ui-monospace, monospace; }

.tachometer { position: relative; width: min(100%, 257px); margin: 10px auto 4px; }
.tachometer svg { display: block; width: 100%; height: auto; fill: none; }
.gauge-track { stroke: #4b3b3e; stroke-width: 8; }
.gauge-redline { stroke: var(--exhaust); stroke-width: 8; stroke-dasharray: 0 90 10 0; }
.gauge-progress { stroke: var(--accent); stroke-width: 8; stroke-dasharray: 0 100; }
.gauge-ticks { stroke: var(--panel); stroke-width: 9; stroke-dasharray: .5 9.5; }
.tach-value { position: absolute; inset: auto 0 23%; text-align: center; }
.tach-value strong { display: block; font: 640 clamp(1.8rem, 5vw, 2.7rem)/1.1 ui-monospace, monospace; letter-spacing: -.065em; }
.tach-value span, .tach-scale, small { color: var(--muted); font-size: .72rem; }
.tach-value span { font-weight: 700; letter-spacing: .16em; }
.tach-scale { position: absolute; inset: auto 12% 0; display: flex; justify-content: space-between; font-family: ui-monospace, monospace; }
.metrics { display: grid; grid-template-columns: 1fr 1fr; margin: 0; border-top: 1px solid var(--line); }
.metrics div { padding: 10px 18px 12px; }
.metrics div:nth-child(even) { border-left: 1px solid var(--line); }
.metrics div:nth-child(n + 3) { border-top: 1px solid var(--line); }
.metrics dt, .gearbox legend, .slider label, .control-label { color: var(--muted); font-size: .79rem; }
.metrics dd { margin: 3px 0 0; font: 600 1.2rem ui-monospace, monospace; }
small { font-weight: 500; }
#temperature[data-hot] { color: var(--exhaust); }

.control-body { display: grid; gap: 8px; padding: 15px 18px 18px; }
.control-body select { width: 100%; min-height: 44px; padding: 0 10px; border: 1px solid #685158; border-radius: 7px; background: #32272a; color: var(--text); }
.control-hint { margin: -2px 0 5px; color: var(--muted); font-size: .72rem; }
.gearbox { min-width: 0; border: 0; padding: 0; margin: 0; }
.gearbox legend { padding: 0; margin-bottom: 6px; }
.gear-options { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 4px; }
.gear-options label { position: relative; cursor: pointer; }
.gear-options input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.gear-options span { display: grid; min-height: 44px; place-items: center; border: 1px solid #685158; border-radius: 6px; background: #32272a; font: 600 .85rem ui-monospace, monospace; }
.gear-options label:hover span { background: #46353a; }
.gear-options input:checked + span { border-color: var(--accent); background: #4a3729; color: var(--accent); }
.gear-options input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.slider { display: grid; grid-template-columns: 1fr auto; align-items: center; margin-top: 5px; }
.slider output { color: var(--accent); font: .82rem ui-monospace, monospace; }
input[type="range"] { grid-column: 1 / -1; margin: 0; width: 100%; min-height: 40px; accent-color: var(--accent); cursor: pointer; }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 13px; border-radius: 7px; font-size: .83rem; font-weight: 700; white-space: nowrap; }
.sound-button, .slow-button, .view-button { border: 1px solid #685158; background: var(--panel); color: var(--text); flex-shrink: 0; }
.sound-button[aria-pressed="true"], .slow-button[aria-pressed="true"], .view-button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.sound-button:hover, .slow-button:hover, .view-button:hover { background: #3a2c2d; }
.sound-icon { width: 13px; height: 13px; background: currentColor; clip-path: polygon(0 30%, 35% 30%, 74% 0, 74% 100%, 35% 70%, 0 70%); }
.ignition-button {
  --ignition-accent: var(--accent);
  --ignition-edge: #816244;
  --ignition-surface: #48372c;
  --ignition-hover: #594235;
  display: grid;
  grid-template-columns: 38px 1fr 38px;
  gap: 10px;
  min-height: 58px;
  margin-top: 6px;
  padding: 8px 10px;
  border: 1px solid var(--ignition-edge);
  border-radius: 12px;
  background: linear-gradient(var(--ignition-surface), #2b211f);
  box-shadow: inset 0 1px rgb(255 255 255 / 6%), 0 3px 6px rgb(0 0 0 / 22%);
  color: var(--ignition-accent);
  font-size: .91rem;
  letter-spacing: .015em;
}
.ignition-button[aria-pressed="true"] {
  --ignition-accent: #ffc0b4;
  --ignition-edge: #79514b;
  --ignition-surface: #3a2927;
  --ignition-hover: #49302d;
  background-image: linear-gradient(var(--ignition-surface), #261e1d);
}
.ignition-button:hover { --ignition-surface: var(--ignition-hover); }
.ignition-button:active { box-shadow: inset 0 2px 5px rgb(0 0 0 / 38%); }
.ignition-button:focus-visible { outline-color: var(--ignition-accent); }
.ignition-icon {
  position: relative;
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid var(--ignition-edge);
  border-radius: 50%;
  background: rgb(0 0 0 / 20%);
}
.ignition-icon::before {
  content: "";
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
}
.ignition-icon::after {
  content: "";
  position: absolute;
  top: 8px;
  width: 2px;
  height: 9px;
  border-radius: 2px;
  background: currentColor;
}
.ignition-light {
  justify-self: center;
  width: 7px;
  height: 7px;
  border: 1px solid var(--ignition-edge);
  border-radius: 50%;
  background: #151918;
}
.ignition-button[aria-pressed="true"] .ignition-light {
  border-color: currentColor;
  background: currentColor;
  box-shadow: 0 0 8px rgb(255 192 180 / 35%);
}

footer { margin-top: 14px; color: var(--muted); font-size: .77rem; }

@media (max-width: 860px) {
  .dashboard-grid { grid-template-columns: minmax(0, 1fr); }
  .sidebar { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
  .stage { min-height: 400px; }
}
@media (max-width: 540px) {
  .page-header { align-items: center; margin-bottom: 19px; }
  .sidebar { grid-template-columns: minmax(0, 1fr); }
  .stage { min-height: 385px; }
  .legend { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.stage canvas[hidden], .legend[hidden], .firing[hidden] { display: none; }
