/* Motorklang — "cyber" direction after the 2026 Roadster: faceted panels, Ano white on
 * near-black, visor gold as the one accent, red only for the redline and the light bar.
 * Design notes: docs/plans/2026-10-16-motorklang-ui.md */

:root {
  --bg: #06070a;
  --surface: #0e1015;
  --tile: #141820;
  --tile-press: #1b2029;
  --edge: rgba(238, 240, 242, 0.13);
  --text: #eef0f2;
  --muted: #7d8592;
  --gold: #d6a84f;
  --gold-fill: #1c180f;
  --red: #ff2b2b;
  --green: #39d98a;
  --cut: 12px;
  --ui: "Chakra Petch", system-ui, sans-serif;
  --mark: "Michroma", "Chakra Petch", sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  background:
    radial-gradient(120% 90% at 30% 40%, rgba(214, 168, 79, 0.05), transparent 60%),
    linear-gradient(rgba(255, 255, 255, 0.022) 1px, transparent 1px) 0 0 / 48px 48px,
    linear-gradient(90deg, rgba(255, 255, 255, 0.022) 1px, transparent 1px) 0 0 / 48px 48px,
    var(--bg);
  color: var(--text);
  font: 400 17px/1.4 var(--ui);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  overflow-x: hidden;
}

button { font: inherit; color: inherit; touch-action: manipulation; }

/* Faceted surfaces: the element itself is the hairline edge, ::before the fill, both cut. */
.picker, .dock, .engine, .btn, .segmented, .chip {
  position: relative;
  isolation: isolate;
  border: 0;
  background: var(--edge);
  --fill: var(--surface);
  clip-path: polygon(var(--cut) 0, 100% 0, 100% calc(100% - var(--cut)),
    calc(100% - var(--cut)) 100%, 0 100%, 0 var(--cut));
}
.picker::before, .dock::before, .engine::before, .btn::before, .segmented::before, .chip::before {
  content: "";
  position: absolute;
  inset: 1px;
  z-index: -1;
  background: var(--fill);
  clip-path: polygon(calc(var(--cut) - 0.5px) 0, 100% 0, 100% calc(100% - var(--cut) + 0.5px),
    calc(100% - var(--cut) + 0.5px) 100%, 0 100%, 0 calc(var(--cut) - 0.5px));
}

/* Light bar along the top edge: the Roadster's full-length taillight, used as a shift light. */
.lightbar { position: fixed; top: 0; left: 0; right: 0; height: 4px; background: #160607; z-index: 10; }
.lightbar i {
  position: absolute; inset: 0;
  background: var(--red);
  box-shadow: 0 0 14px 2px rgba(255, 43, 43, 0.65);
  transform: scaleX(0);
  transform-origin: center;
}
.lightbar.flash i { animation: flash 0.14s steps(2, jump-none) infinite; }
@keyframes flash { 50% { opacity: 0.2; } }

.app {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.08fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "top top" "cluster picker" "dock dock";
  gap: 14px 22px;
  padding: 16px 18px 16px;
  max-width: 1600px;
  margin: 0 auto;
}

/* Top bar */
.topbar { grid-area: top; display: flex; align-items: center; justify-content: space-between; min-height: 44px; }
.brand { font: 400 14px var(--mark); letter-spacing: 0.32em; text-transform: uppercase; }

.chip {
  --cut: 9px;
  display: inline-flex; align-items: center; gap: 10px;
  min-height: 40px; padding: 0 18px;
  color: var(--muted); font-size: 15px; font-weight: 500;
  max-width: 62%;
}
.chip #status { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-dot { width: 8px; height: 8px; background: #4a505a; flex: none; transform: rotate(45deg); }
.chip[data-state="live"] { color: var(--text); }
.chip[data-state="live"] .chip-dot { background: var(--green); box-shadow: 0 0 10px var(--green); }
.chip[data-state="demo"] { color: var(--text); }
.chip[data-state="demo"] .chip-dot { background: var(--gold); box-shadow: 0 0 10px var(--gold); }
.chip[data-state="warn"] { color: #f2b25c; }
.chip[data-state="warn"] .chip-dot { background: #f2b25c; }
.chip[data-state="load"] .chip-dot { background: var(--text); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.25; } }

/* Cluster */
.cluster {
  grid-area: cluster;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; min-height: 0;
}

.prnd { display: flex; gap: 24px; font-size: 20px; font-weight: 600; color: #3a3f48; }
.prnd span { min-width: 16px; text-align: center; transition: color 0.2s, text-shadow 0.2s; }
.prnd span.on { color: var(--text); text-shadow: 0 0 12px rgba(238, 240, 242, 0.5); }

.tach-host { width: min(100%, 60vh, 520px); aspect-ratio: 1; }
.tach { width: 100%; height: 100%; display: block; overflow: visible; }

.tach-frame { fill: rgba(14, 16, 21, 0.6); stroke: var(--edge); stroke-width: 1; }
.tach-inner { fill: none; stroke: rgba(238, 240, 242, 0.06); stroke-width: 1; }
.tach-segs { filter: url(#segGlow); }
.seg { fill: #171b23; transition: fill 0.05s; }
.seg.gold { fill: #211d14; }
.seg.red { fill: #2c1214; }
.seg.on.white { fill: var(--text); }
.seg.on.gold { fill: var(--gold); }
.seg.on.red { fill: var(--red); }
.over-redline .seg.on { fill: var(--red); }
.tach-tick { stroke: #4a505a; stroke-width: 2; }
.tach-tick.red { stroke: var(--red); }
.tach-num { font: 500 15px var(--ui); fill: var(--muted); }
.tach-num.red { fill: var(--red); }
.tach-hud path { fill: none; stroke: rgba(238, 240, 242, 0.28); stroke-width: 1.5; }
.tach-speed { font: 300 112px var(--ui); fill: var(--text); letter-spacing: -0.01em; }
.tach-unit { font: 500 15px var(--ui); fill: var(--muted); letter-spacing: 0.12em; }
.tach-rpm { font: 500 17px var(--ui); fill: var(--muted); font-variant-numeric: tabular-nums; }
.tach-gear polygon { fill: var(--gold-fill); stroke: var(--gold); stroke-width: 1.5; }
.tach-gear text { font: 600 30px var(--ui); fill: var(--text); }
.over-redline .tach-gear polygon { stroke: var(--red); fill: rgba(255, 43, 43, 0.14); }

/* Power bar: coasting grows left in green, load grows right in white — segmented like LEDs. */
.power {
  display: grid; grid-template-columns: 1fr 2fr; gap: 6px;
  width: min(78%, 380px); height: 8px;
}
.power > div {
  background: #171b23; position: relative; overflow: hidden;
  -webkit-mask: repeating-linear-gradient(90deg, #000 0 9px, transparent 9px 12px);
  mask: repeating-linear-gradient(90deg, #000 0 9px, transparent 9px 12px);
}
.power i { position: absolute; top: 0; bottom: 0; transition: width 0.08s linear; width: 0; }
.power-regen i { right: 0; background: var(--green); }
.power-drive i { left: 0; background: var(--text); }

.sound-name { margin: 6px 0 0; color: var(--muted); font-size: 16px; min-height: 1.4em; }

/* Picker */
.picker {
  --cut: 18px;
  grid-area: picker;
  padding: 16px; display: flex; flex-direction: column; gap: 12px; min-height: 0;
}

.segmented {
  --cut: 10px; --fill: var(--bg);
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  padding: 5px; gap: 5px;
}
.segmented button {
  position: relative;
  min-height: 52px; border: 0; background: transparent;
  color: var(--muted); font-size: 18px; font-weight: 600; letter-spacing: 0.04em; cursor: pointer;
  clip-path: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
}
.segmented button[aria-selected="true"] { background: var(--tile); color: var(--text); }
.segmented button[aria-selected="true"]::after {
  content: ""; position: absolute; left: 30%; right: 30%; bottom: 6px; height: 2px;
  background: var(--gold); box-shadow: 0 0 8px var(--gold);
}

.tiles {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px;
  overflow-y: auto; align-content: start; min-height: 0;
}

.engine {
  --fill: var(--tile);
  display: flex; flex-direction: column; justify-content: center; gap: 2px;
  min-height: 92px; padding: 12px 16px;
  text-align: left; cursor: pointer;
  transition: transform 0.08s ease;
}
.engine:active { transform: scale(0.97); --fill: var(--tile-press); }
.engine[aria-checked="true"] { background: var(--gold); --fill: var(--gold-fill); }
.engine-badge { font-size: 28px; font-weight: 600; line-height: 1.05; letter-spacing: 0.02em; }
.engine[aria-checked="true"] .engine-badge { color: var(--gold); text-shadow: 0 0 14px rgba(214, 168, 79, 0.45); }
.engine-name { font-size: 15px; font-weight: 600; line-height: 1.2; }
.engine-detail {
  color: var(--muted); font-size: 13px; line-height: 1.25;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.engine.loading::after {
  content: ""; position: absolute; left: 16px; right: 16px; bottom: 8px; height: 2px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  background-size: 200% 100%; animation: sweep 1s linear infinite;
}
@keyframes sweep { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* Dock */
.dock {
  --cut: 18px;
  grid-area: dock;
  display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 0.8fr) minmax(0, 1fr); gap: 12px;
  align-items: center;
  padding: 10px;
}

.volume { display: flex; align-items: center; gap: 12px; padding: 0 10px; min-height: 64px; }
.volume svg { width: 28px; height: 28px; flex: none; fill: var(--text); }
.volume svg .wave { fill: none; stroke: var(--text); stroke-width: 1.8; stroke-linecap: square; }

input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 60px; background: transparent; margin: 0; cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  background: linear-gradient(90deg, var(--text) var(--fill, 80%), #2a2f38 var(--fill, 80%));
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 30px; height: 40px; margin-top: -17px;
  background: var(--text);
  clip-path: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
}
input[type="range"]::-moz-range-track { height: 6px; background: #2a2f38; }
input[type="range"]::-moz-range-progress { height: 6px; background: var(--text); }
input[type="range"]::-moz-range-thumb { width: 30px; height: 40px; border: 0; border-radius: 2px; background: var(--text); }

.btn {
  --cut: 14px;
  min-height: 68px; cursor: pointer;
  font-size: 20px; font-weight: 600; letter-spacing: 0.08em;
  transition: transform 0.08s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--gold); --fill: var(--gold); color: #120e05; }
.btn-primary.running { background: var(--text); --fill: var(--text); color: #0b0c0f; }
.btn-ghost { --fill: var(--tile); color: var(--text); }
.btn-ghost.running { background: var(--text); --fill: var(--text); color: #0b0c0f; }
button:disabled { opacity: 0.45; cursor: default; }

button:focus-visible, input:focus-visible { outline: 3px solid var(--gold); outline-offset: -3px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* Phones and narrow windows: one column, controls stay at the thumb. */
@media (max-width: 820px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto auto;
    grid-template-areas: "top" "cluster" "picker" "dock";
    padding-bottom: 12px;
  }
  .tach-host { width: min(100%, 420px); }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); overflow: visible; }
  .dock { position: sticky; bottom: 8px; grid-template-columns: 1fr 1fr; }
  .volume { grid-column: 1 / -1; }
  .chip { max-width: 70%; }
}
