:root {
  --bg: #efebe4;
  --ink: #2b2622;
  --muted: #7a7065;
  --card: #fbf9f5;
  --line: #ddd5c9;
  --green: #3fae5a;
  --amber: #e9a23b;
  --red: #d64933;
  --accent: #ffd25e;
  --rust: #b0612e;
  --lcd: #18201b;
  --lcd-off: #3f4a43;
  --lcd-on: #a9f5b5;
  --focus: #4a7dff;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button { font: inherit; color: inherit; }

.layout {
  max-width: 1480px;
  margin: 0 auto;
  padding: 24px 16px;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 330px;
  grid-template-areas: "config stage sim";
  gap: 24px;
  align-items: start;
}
.config { grid-area: config; }
.stage-wrap { grid-area: stage; }
.sim { grid-area: sim; }

.card {
  display: grid;
  gap: 16px;
  padding: 20px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(60, 40, 20, .08);
}
.card-title, .group h3 {
  margin: 0;
  font-size: 13px;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--muted);
}
.card-title span, .group h3 span { opacity: .6; margin-left: .4em; }
.group { display: grid; gap: 10px; }
.group h3 { font-size: 11px; }

/* ---------- 3D stage ---------- */

.stage-wrap {
  position: sticky;
  top: 24px;
  height: calc(100vh - 48px);
  height: calc(100dvh - 48px);
  min-height: 520px;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
}
.stage {
  position: relative;
  min-height: 0;
  border-radius: 20px;
  outline: none;
  cursor: grab;
  touch-action: pan-y;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  /* Soft edges, so a long shadow fades out instead of stopping at the canvas border. */
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 7%, #000 93%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 7%, #000 93%, transparent);
}
.stage:focus-visible { box-shadow: 0 0 0 3px var(--focus); }
.stage[data-hover="wheel"] { cursor: grab; }
.stage[data-hover="button"] { cursor: pointer; }
.stage.grabbing, .stage.orbiting { cursor: grabbing; }
.stage-msg {
  position: absolute;
  inset: 0;
  margin: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  padding: 24px;
}
.stage-tip { margin: 6px 0 0; text-align: center; font-size: 12px; color: var(--muted); }
.stage-tip span { display: block; opacity: .75; }

/* Drop zone while dragging a wheel or a colour */
.stage::after {
  content: "";
  position: absolute;
  inset: 6px;
  border: 2px dashed transparent;
  border-radius: 18px;
  pointer-events: none;
  transition: border-color .15s, background-color .15s;
}
.dnd .stage::after { border-color: rgba(176, 97, 46, .35); }
.dnd .stage.drop-over::after { border-color: var(--rust); background: rgba(255, 210, 94, .07); }

.drop-label {
  position: fixed;
  z-index: 60;
  transform: translate(-50%, calc(-100% - 46px));
  padding: 6px 12px;
  border-radius: 99px;
  background: var(--ink);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .18);
}
.drop-label.invalid { background: var(--red); }

.ghost {
  position: fixed;
  z-index: 50;
  margin: 0;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(1.06) rotate(-3deg);
  box-shadow: 0 14px 34px rgba(60, 40, 20, .28);
  transition: transform .15s, opacity .15s;
}
.ghost.over { transform: translate(-50%, -50%) scale(.72); opacity: .9; }
.ghost.back { transition: left .25s ease-in, top .25s ease-in, opacity .25s, transform .25s; opacity: 0; }

.ripple {
  position: fixed;
  z-index: 55;
  width: 24px;
  height: 24px;
  margin: -12px 0 0 -12px;
  border: 3px solid var(--accent);
  border-radius: 50%;
  pointer-events: none;
  animation: ripple .6s ease-out forwards;
}
@keyframes ripple {
  from { transform: scale(.4); opacity: 1; }
  to { transform: scale(4); opacity: 0; }
}

/* ---------- Configurator ---------- */

.models { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.models button {
  display: grid;
  gap: 2px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  text-align: left;
  cursor: pointer;
}
.models small { font-size: 12px; color: var(--muted); line-height: 1.25; }
.models button[aria-pressed="true"] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }

.wheels { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tile {
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 4px;
  min-width: 0;
  padding: 10px 8px 9px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  cursor: grab;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.tile:hover { border-color: #c8bba8; }
.tile .icon { width: 42px; height: 42px; color: #8a5a2b; }
.tile .icon svg { width: 100%; height: 100%; display: block; }
.tile .t { min-width: 0; display: grid; line-height: 1.2; }
.tile b { font-size: 14px; }
.tile small { font-size: 11px; color: var(--muted); }
.tile em {
  margin-top: 3px;
  font-size: 11px;
  font-style: normal;
  line-height: 1.25;
  color: #a06a00;
}
.tile.active { border-color: #f0b93a; background: #fff8e6; box-shadow: inset 0 0 0 1px #f0b93a; }

.targets { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.targets button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  padding: 5px 10px 5px 6px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: #fff;
  font-size: 13px;
  cursor: pointer;
}
.targets button[aria-pressed="true"] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.targets button[hidden] { display: none; }
.dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .18);
}

/* Finishes: one quiet matrix per family (powder coat 6 × 3, wood and metal one row each). */
.swatches { display: grid; gap: 12px; }
.matrix { display: grid; gap: 6px; }
.matrix h4 {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
}
.matrix h4 span { opacity: .6; font-weight: 500; }
.matrix h4::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.matrix .grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 34px));
  gap: 6px;
}
.swatch {
  aspect-ratio: 1;
  width: 100%;
  padding: 0;
  border: 0;
  border-radius: 7px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12), 0 1px 2px rgba(60, 40, 20, .1);
  cursor: grab;
  touch-action: pan-y;
  user-select: none;
  -webkit-touch-callout: none;
  transition: transform .1s, opacity .15s, box-shadow .15s;
}
.swatch:hover { transform: translateY(-1px) scale(1.08); }
.swatch.used { box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12), 0 0 0 2px var(--card), 0 0 0 4px var(--ink); }
.swatch.elsewhere { opacity: .7; }
.swatch.elsewhere:hover { opacity: 1; }
.swatch:disabled { opacity: .15; cursor: not-allowed; transform: none; }
.swatch.ghost { width: 34px; }
.color-name { margin: 0; min-height: 2.6em; font-size: 13px; color: var(--muted); }
.color-name b { color: var(--ink); }

.dnd-hint {
  margin: 0;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  border-radius: 12px;
  background: #f3eee6;
  font-size: 13px;
}
.dnd-hint svg { flex: none; width: 22px; fill: none; stroke: var(--rust); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.dnd-hint small { display: block; color: var(--muted); }
.spec { margin: 0; font-size: 12px; color: var(--muted); }
.reset {
  justify-self: start;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: transparent;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}
.reset:hover { color: var(--ink); border-color: #c8bba8; }

:is(.models button, .tile, .targets button, .swatch, .langs button, .reset):focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* ---------- Simulation panel ---------- */

.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.brand { display: grid; gap: 6px; }
.logo { display: block; width: 132px; height: auto; }
h1 { margin: 0; font-size: 13px; letter-spacing: .2em; text-transform: uppercase; color: var(--muted); }

.power {
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 99px;
  background: #e6e0d6;
  color: var(--muted);
  white-space: nowrap;
}
.power::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 6px;
  border-radius: 50%;
  background: #b5ab9e;
}
[data-power="on"] .power { background: #dcefdc; color: #2d7a3e; }
[data-power="on"] .power::before { background: var(--green); box-shadow: 0 0 6px var(--green); }

.battery { display: flex; align-items: center; gap: 10px; }
.bolt { width: 22px; flex: none; fill: var(--amber); opacity: .18; transition: opacity .15s; }
.battery.charging .bolt { opacity: 1; }
.cell {
  position: relative;
  flex: 1;
  height: 44px;
  margin-right: 8px;
  padding: 3px;
  border: 3px solid var(--ink);
  border-radius: 8px;
}
.cell::after {
  content: "";
  position: absolute;
  right: -10px;
  top: 50%;
  width: 6px;
  height: 16px;
  margin-top: -8px;
  border-radius: 0 3px 3px 0;
  background: var(--ink);
}
.cell::before {
  content: "";
  position: absolute;
  inset: 3px;
  z-index: 1;
  background: repeating-linear-gradient(90deg, transparent 0 calc(10% - 2px), var(--card) calc(10% - 2px) 10%);
}
.fill { width: 0; height: 100%; border-radius: 3px; background: var(--green); transition: background-color .3s; }
[data-level="mid"] .fill { background: var(--amber); }
[data-level="low"] .fill { background: var(--red); }
.talk { margin: -10px 0 0 32px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.pct { min-width: 3.2em; text-align: right; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }

.display {
  display: grid;
  gap: 6px;
  min-height: 96px;
  padding: 14px 16px;
  border-radius: 10px;
  background: var(--lcd);
  color: var(--lcd-off);
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
}
[data-power="on"] .display { color: var(--lcd-on); text-shadow: 0 0 6px rgba(140, 255, 160, .45); }
.line1 { min-height: 1.4em; font-size: 17px; }
.line2 { min-height: 1.4em; font-size: 13px; letter-spacing: .08em; text-transform: uppercase; opacity: .8; }
.progress { height: 4px; border-radius: 2px; overflow: hidden; background: rgba(255, 255, 255, .07); }
.progress > div { width: 0; height: 100%; background: currentColor; }

.langs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.langs button {
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 8px 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  font-size: 13px;
  cursor: pointer;
}
.langs b {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 34px;
  height: 26px;
  padding: 0 6px;
  border-radius: 99px;
  background: #e9ecef;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .15);
  font-size: 12px;
}
.langs button[aria-pressed="true"] { border-color: #f0b93a; background: #fff8e6; }
.langs button[aria-pressed="true"] b { background: var(--accent); }
.langs button.playing b::before { content: "▶"; font-size: 8px; }

.hint { margin: 0; font-size: 14px; color: var(--muted); }
.hint span { opacity: .8; }
.hint.nudge { animation: nudge .5s; color: var(--red); }
@keyframes nudge {
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

/* ---------- Narrower screens ---------- */

@media (max-width: 1180px) {
  .layout {
    grid-template-columns: minmax(0, 1fr) 340px;
    grid-template-areas: "stage sim" "stage config";
  }
}

@media (max-width: 760px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "stage" "sim" "config";
    gap: 16px;
  }
  .stage-wrap { position: relative; top: 0; height: 64vh; height: 64dvh; min-height: 380px; }
}

@media (prefers-reduced-motion: reduce) {
  .ripple, .hint.nudge { animation: none; }
}
