/* IBM Plex Mono — three static cuts (regular, semibold, bold), latin subset,
   about 15 KB each, from Fontsource via jsDelivr. OFL-1.1, free to use.
   There is no variable build of the mono, hence one file per weight; the
   interface only ever asks for these three.
   Loaded from a CDN so it works in both the Vite and the standalone setup —
   build.py swaps these URLs for its own vendored copies. */
@font-face {
  font-family: "IBM Plex Mono";
  src: url("../fonts/IBMPlexMono-Regular.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "IBM Plex Mono";
  src: url("../fonts/IBMPlexMono-SemiBold.woff2") format("woff2");
  font-weight: 600;
  font-display: swap;
}

@font-face {
  font-family: "IBM Plex Mono";
  src: url("../fonts/IBMPlexMono-Bold.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

/* Only the interface and its grounds change with the theme — the part colours
   come from the palette and stay put, so the paint you pick is the paint you
   see either way.

   Tokens are declared three times on purpose: the media query follows the OS,
   and the two [data-theme] blocks let the toggle override it in whichever
   direction the OS is pointing. */
:root {
  --paper: #efe9df;
  --surface: #ffffff;
  --line: #d8d1c4;
  --line-soft: #e7e1d6;
  --ink: #20202b;
  --ink-mid: #5a5a66;
  --ink-soft: #918f93;
  --ink-invert: #ffffff;   /* text that sits on --ink */
  /* Text on the paint colour. Not themed — the accent is the same in both —
     but it does follow the palette: white is thin on MOLTEN, so applyPalette
     overwrites this with whichever of charcoal or white reads better. The
     value here matches the first palette so there is no flash before JS runs. */
  --on-accent: #20202b;

  /* The two stage corners — the counter on the left, the palette on the right
     — are laid out from one set of numbers so their labels always sit on the
     same line. Both are anchored by their bottom, so the row beneath the label
     has to be the same height in each; --dock-row fixes it, and the numeral or
     the dots centre inside it whatever their own size. */
  --dock-bottom: 62px;  /* clear of the rotation dial */
  --dock-row: 24px;     /* the numeral / dots row */
  --dock-gap: 6px;      /* label to that row */
  --ring: rgba(32, 32, 43, 0.28);
  --wash: rgba(32, 32, 43, 0.04);
  --line-strong: #c3baa9;
  /* The first palette's paint. JS overwrites this the moment it runs, but the
     value has to match — a different colour here shows as a flash of the wrong
     accent (the Export button especially) before the script takes over. */
  --accent: #f05e2d;

  --font: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #16161d;
    --surface: #23232d;
    --line: #343442;
    --line-soft: #1e1e26;
    --ink: #efe9df;
    --ink-mid: #a3a2ad;
    --ink-soft: #6b6a77;
    --ink-invert: #16161d;
    --ring: rgba(255, 255, 255, 0.3);
    --wash: rgba(255, 255, 255, 0.06);
    --line-strong: #494957;
  }
}

:root[data-theme="dark"] {
  --paper: #16161d;
  --surface: #23232d;
  --line: #343442;
  --line-soft: #1e1e26;
  --ink: #efe9df;
  --ink-mid: #a3a2ad;
  --ink-soft: #6b6a77;
  --ink-invert: #16161d;
  --ring: rgba(255, 255, 255, 0.3);
  --wash: rgba(255, 255, 255, 0.06);
  --line-strong: #494957;
}

:root[data-theme="light"] {
  --paper: #efe9df;
  --surface: #ffffff;
  --line: #d8d1c4;
  --line-soft: #e7e1d6;
  --ink: #20202b;
  --ink-mid: #5a5a66;
  --ink-soft: #918f93;
  --ink-invert: #ffffff;
  --ring: rgba(32, 32, 43, 0.28);
  --wash: rgba(32, 32, 43, 0.04);
  --line-strong: #c3baa9;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

#app {
  /* Nothing here is text worth selecting, and a drag that starts on the
     canvas would otherwise sweep a selection across the panel. */
  user-select: none;
  -webkit-user-select: none;
  display: grid;
  grid-template-columns: 1fr 320px;
  grid-template-rows: 44px 1fr; /* top bar is exactly one button tall */
  grid-template-areas:
    "topbar topbar"
    "stage  panel";
  height: 100%;
}

/* =========================== top bar =========================== */

.topbar {
  grid-area: topbar;
  /* Right column matches the panel below, so the three action buttons line up
     exactly over it — logo left, controls right, no dividing rule. The buttons
     fill the bar's height (no inset above or below). */
  display: grid;
  grid-template-columns: 1fr 320px;
  align-items: stretch;
  padding-left: 18px;
}

/* Holds the wordmark logo, which inherits this colour via currentColor. */
.mark {
  display: inline-flex;
  align-items: center;
  color: var(--accent);
  transition: color 0.25s;
}

.logo {
  display: block;
  height: 21px; /* ~ the width the old text logo occupied */
  width: auto;
}

.actions {
  display: flex;
  align-items: stretch;
  gap: 0;        /* joined into one segmented control, split by hairlines */
  height: 100%;
}

/* Buttons carry an icon and a label; on desktop both show, on mobile the label
   drops and the icon takes over (see the narrow-view block). */
.act .ico {
  display: inline-flex;
  align-items: center;
}

.act .ico svg { display: block; }

.act {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;              /* icon ↔ word */
  flex: 1;               /* three equal thirds spanning the panel width */
  height: 100%;
  padding: 0 6px;
  font: inherit;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--ink);
  /* Clickable, so it sits in --surface against the background-toned top bar.
     Square, split by the same hairline the number cells use. */
  background: var(--surface);
  border: 0;
  border-left: 1px solid var(--line);
  border-bottom: 1px solid var(--line); /* the line under the segmented bar */
  border-radius: 0;
  cursor: pointer;
  transition: background 0.14s, color 0.14s;
}

.act:hover {
  background: var(--wash);
}

/* Export is the one action that produces the deliverable, so it carries the
   paint colour while everything else stays quiet. Keeps the shared hairline on
   its left so the segment split reads the same as the others. */
.act-primary {
  color: var(--on-accent);
  background: var(--accent);
  transition: background 0.25s, opacity 0.14s;
}

.act-primary:hover {
  background: var(--accent);
  filter: brightness(1.08);
}

.act.active {
  color: var(--ink-invert);
  background: var(--ink);
}

.act.active:hover { background: var(--ink); }

.act:disabled {
  opacity: 0.55;
  cursor: default;
  filter: none;
}

.dots {
  display: inline-flex;
  gap: 3px;
}

.dots i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px var(--ring);
}

/* ============================ stage ============================ */

.stage {
  grid-area: stage;
  position: relative;
  overflow: hidden;
  /* The canvas renders transparent, so the ground colour is CSS — one --paper
     shared by the stage, top bar and panel, seamless in both themes. */
  background: var(--paper);
}

#viewport {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none; /* let the turntable own drag gestures */
}

#viewport.grabbing { cursor: grabbing; }

/* Oversized figure, the way the reference layouts lead with a numeral. */
/* The numeral is sized in JS to match the label's width exactly — see
   fitReadout(). Both must be inline-block so they measure as text, not as
   full-width blocks. Letter-spacing is in em so it scales with the fit. */
/* Label on top, number below — mirrors the palette dock opposite it, so the
   number lines up with the palette dots along the same baseline. */
.readout {
  position: absolute;
  left: 18px; /* aligns with the logo above */
  bottom: var(--dock-bottom);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--dock-gap);
  pointer-events: none;
}

/* Sized and tracked to read as a number rather than a caption; the fixed row
   height keeps it from pushing its label off the palette's line as it grows. */
.readout-num {
  display: flex;
  align-items: center;
  height: var(--dock-row);
  font-size: 22px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  line-height: 1;
  white-space: nowrap;
  color: var(--accent);
  transition: color 0.25s;
}


/* Palette switch, sitting opposite the readout. */
.palette-dock {
  position: absolute;
  right: 18px; /* same inset as the topbar buttons above */
  bottom: var(--dock-bottom);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--dock-gap);
  padding: 0;
  font: inherit;
  background: transparent;
  border: 0;
  cursor: pointer;
}

/* The two corner labels are one style — same size, weight, tracking and
   colour token — so they read as a pair in either theme. Only the palette one
   answers to hover, being the only one that is a button. */
.readout-label,
.palette-dock-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-soft);
  transition: color 0.14s;
}

.palette-dock:hover .palette-dock-label { color: var(--ink); }

.palette-dock .dots {
  align-items: center;
  height: var(--dock-row); /* the counter's row, so the labels stay level */
}

.palette-dock .dots i {
  width: 13px;
  height: 13px;
}

/* ------------------------- rotation dial ------------------------- */

.dial {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 42px;
  border-top: 1px solid var(--line);
  pointer-events: none;
}

/* 48 minor ticks = one every 7.5°, 4 major = one every 90°. Percentage
   stops keep them locked to the scale however wide the stage gets. */
.dial-minor,
.dial-major {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
}

.dial-minor {
  height: 6px;
  background: repeating-linear-gradient(
    to right,
    var(--line) 0 1px,
    transparent 1px calc(100% / 48)
  );
}

.dial-major {
  height: 12px;
  background: repeating-linear-gradient(
    to right,
    var(--ink-soft) 0 1px,
    transparent 1px calc(100% / 4)
  );
}

.dial-mark {
  position: absolute;
  top: 0;
  left: 0;
  width: 2px;
  height: 18px;
  margin-left: -1px;
  background: var(--accent);
  transition: background 0.25s;
}

.dial-labels {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 9px;
  display: flex;
  justify-content: space-between;
  padding: 0 2px;
  font-size: 9px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
}

#loading {
  position: absolute;
  left: 26px;
  top: 20px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-soft);
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

#loading.visible { opacity: 1; }

/* ============================ panel ============================ */

/* No padding of its own: rows span the full width so each row's colour rail
   can sit near the left edge, and the Random button insets itself. */
.panel {
  grid-area: panel;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow-y: auto;
  /* Inactive ground: the panel body reads as background, so the interactive
     bits (selected cells, the input, the Random bar) stand out in --surface. */
  background: var(--paper);
  border-left: 1px solid var(--line);
}

.row {
  position: relative;
  display: flex;
  align-items: stretch; /* the number cells fill the row height */
  justify-content: space-between;
  gap: 10px;
  min-height: 44px;
  padding: 0 0 0 20px; /* labels inset to the right of the colour rail */
  /* Same hairline as the dividers between cells, so the grid reads as one. */
  border-bottom: 1px solid var(--line);
}

/* Vertical colour rail inside the panel, flush to its left edge — the rail-less
   Nameplate row now reads as intentional (its label just sits over the gutter).
   Colour is set from the palette in JS. */
.rail {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 8px;
}

.row-name {
  display: inline-flex;
  align-items: center; /* the row no longer centres it */
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink);
}

/* Number selector: bare cells split by hairlines — no outer box and no
   vertical padding, so each cell fills the row height edge to edge. Only the
   dividers between cells remain. */
.variants {
  display: inline-flex;
  flex: none;
}

.variants button {
  flex: none;
  width: 39px; /* fixed so every cell is exactly equal (~4px wider than before) */
  padding: 0;
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.16em;
  color: var(--ink-soft);
  /* Cells are the interactive grid, so they stay white; the panel ground
     behind the labels is what recedes to the background tone. */
  background: var(--surface);
  border: 0;
  border-left: 1px solid var(--line);
  cursor: pointer;
  transition: background 0.14s, color 0.14s;
}
/* The first cell keeps its left divider too, matching the ones between cells. */

.variants button:hover {
  color: var(--ink);
  background: var(--wash);
}

/* Selected cell carries the palette's paint colour — the one active accent. */
.variants button.active {
  color: var(--on-accent);
  background: var(--accent);
  transition: background 0.25s;
}

.variants button.active:hover {
  background: var(--accent);
}

/* Waiting on that variant's model — a quiet pulse, not a spinner. */
.variants button.pending {
  color: var(--ink);
  animation: cell-pending 0.9s ease-in-out infinite;
}

@keyframes cell-pending {
  0%, 100% { background: var(--surface); }
  50%      { background: var(--wash); }
}

/* Full-width bar flush to the panel edges — no radius, no side inset. Framed top
   and bottom so it reads as a button against the background-toned panel. */
.panel-action {
  margin: 0;
  padding: 14px;
  font: inherit;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--surface);
  border: 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  cursor: pointer;
  transition: background 0.14s, border-color 0.14s;
}

/* Two stacked bars share one rule between them, not two. */
.panel-action + .panel-action { border-top: 0; }

/* Hover, and the Assembly toggle while the car is apart, paint the same fill a
   chosen variant cell gets — so the toggle needs no second label to read. */
.panel-action:hover,
.panel-action.is-on {
  color: var(--on-accent);
  background: var(--accent);
  border-color: var(--accent);
}

/* License plate as its own row: label on the left like the categories, the
   input filling the right (aligned to the number cells above). No rounding.
   The Random bar below carries the separator, so this row drops its own bottom
   border to avoid a double line. */
.plate-row { border-bottom: 0; }

.plate-input {
  flex: none;
  width: 195px; /* 5 × 39px cells — right edge flush, left edge under the cells */
  align-self: stretch; /* fill the row height */
  padding: 0 12px;
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--surface); /* an editable field — active, so it's white */
  border: 0;
  border-left: 1px solid var(--line); /* divider, matching the cells */
  border-radius: 0;
  outline: none;
  transition: background 0.14s;
}

.plate-input::placeholder {
  color: var(--ink-soft);
  font-weight: 600;
}

.plate-input:focus {
  border-left-color: var(--line-strong);
}

/* Print view hands the whole width to the bed. The parts list is gone rather
   than disabled — its buttons drive the assembly, which isn't on screen, so
   leaving them there invites changes that appear to do nothing.
   No transition here on purpose: the stage width is read straight after the
   class flips, to fit the camera to the new aspect. */
#app.print-mode { grid-template-columns: 1fr 0px; }

#app.print-mode .panel { display: none; }

/* ========================== narrow view ========================= */

@media (max-width: 760px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: 44px 1fr auto; /* same bar as desktop — the logo sits at one height everywhere */
    grid-template-areas:
      "topbar"
      "stage"
      "panel";
  }

  /* The desktop top bar aligns its buttons to the side panel; on a phone that
     panel is full width, so fall back to logo-left / icons-right. The three
     buttons go hard into the top-right corner, so the bar keeps its inset only
     on the logo side. */
  .topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 0 0 14px;
  }

  .actions {
    height: auto;
    align-self: flex-start; /* flush with the top edge */
  }

  #app.print-mode {
    grid-template-columns: 1fr;
    grid-template-rows: 44px 1fr 0;
  }

  .panel {
    max-height: 58vh;
    overflow-y: auto; /* the phone panel scrolls; rails sit inside it anyway */
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  /* The rotation dial is dropped on a phone — the turntable still works by
     touch, and losing the ruler gives the model more room. The readout and
     palette then sit lower, where the dial used to be. */
  .dial { display: none; }
  /* No dial to clear on a phone, so both corners drop close to the panel. */
  :root { --dock-bottom: 12px; }

  /* A touch smaller on a phone; the row it sits in is unchanged, so its label
     stays level with the palette's. */
  .readout-num { font-size: 20px; }

  /* 38px row, 1px of which is the bottom divider. */
  .row { min-height: 38px; }

  /* No room for words on a phone: the buttons swap their label for their icon.
     Export stays filled; theme and print share the moon's colour and don't
     react to touch (a tap would otherwise leave them stuck in a hover state).
     They are the same cells as the variant grid below — same width, same
     height, same hairlines, no rounding and no gaps — just with an icon in
     them. The rails sit inside the full-width panel rather than hanging off
     its edge. */
  .rail { left: 0; }

  .act {
    flex: none;
    width: 39px;   /* one variant cell */
    height: 37px;  /* 38px row less its bottom hairline */
    padding: 0;
    justify-content: center;
    border: 0;
    border-left: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    border-radius: 0;
  }

  .act .lbl { display: none; }
  .act .ico { display: inline-flex; }

  .act:not(.act-primary),
  .act:not(.act-primary):hover {
    color: var(--ink-mid);
    background: var(--surface);
    border-color: var(--line);
  }
}

/* ======================= assembly (experiment) ======================= */

/* The assembly page reuses the shell, but its top bar holds a back link and
   two actions rather than the configurator's three. */

.mark[href] { text-decoration: none; }


