:root {
  --paper: rgb(245 242 237); /* sampled from the car render's background */
  --paper-deep: oklch(92.5% 0.014 85);
  --ink: oklch(22% 0.012 70);
  --ink-soft: oklch(45% 0.012 70);
  --line: oklch(84% 0.012 80);
  --accent: oklch(57% 0.17 38);
  --serif: "Instrument Serif", "Times New Roman", serif;
  --sans: "Geist", system-ui, sans-serif;
  --mono: "Geist Mono", ui-monospace, monospace;
  --bar-h: 68px;
  --foot-h: 44px;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 400 14px/1.4 var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
a { color: inherit; }
ul { list-style: none; margin: 0; padding: 0; }

/* ---------- bar ---------- */
.bar {
  height: var(--bar-h);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 clamp(16px, 2.4vw, 36px);
  position: relative;
  z-index: 5;
}
.mark {
  font: 400 26px/1 var(--serif);
  letter-spacing: -0.01em;
  text-decoration: none;
}
.mark em { font-style: italic; }

.fits { display: flex; align-items: center; gap: 14px; }
.fits-label { font: 400 12px/1 var(--mono); color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.08em; }
.fits ul { display: flex; gap: 4px; }
.fits button {
  white-space: nowrap;
  font: 500 13px/1 var(--sans);
  color: var(--ink-soft);
  background: none;
  border: 0;
  padding: 9px 12px;
  border-radius: 99px;
  cursor: pointer;
  display: inline-flex; align-items: baseline; gap: 6px;
}
.fits button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.fits button:disabled { cursor: default; }
.fits button small { font: 400 10px/1 var(--mono); letter-spacing: 0.04em; opacity: 0.7; }

.tally { justify-self: end; display: flex; align-items: center; gap: 18px; font-size: 13px; }
.tally-count b { font-weight: 600; font-variant-numeric: tabular-nums; }
.tally-total { font: 400 13px/1 var(--mono); color: var(--ink-soft); min-width: 3.5em; text-align: right; }
.cta {
  text-decoration: none;
  font-weight: 500;
  padding: 10px 16px;
  border: 1px solid var(--ink);
  border-radius: 99px;
  transition: background 0.2s, color 0.2s;
}
.cta:hover { background: var(--ink); color: var(--paper); }
.bump { animation: bump 0.45s var(--ease-out); }
@keyframes bump { 40% { transform: translateY(-3px); color: var(--accent); } }

/* ---------- stage ---------- */
.stage {
  position: relative;
  height: calc(100vh - var(--bar-h) - var(--foot-h));
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 clamp(16px, 3vw, 48px);
}

/* Two halves of one line, parted by the car's bonnet. */
.giant {
  position: absolute;
  top: 1.5vh;
  left: clamp(16px, 3vw, 48px);
  right: clamp(16px, 3vw, 48px);
  margin: 0;
  display: flex;
  justify-content: space-between;
  font: 400 clamp(88px, 10.4vw, 176px)/0.86 var(--serif);
  letter-spacing: -0.035em;
  white-space: nowrap;
  pointer-events: none;
  user-select: none;
}
.giant em { font-style: italic; }

.car {
  position: relative;
  margin: 0;
  height: min(calc(100vh - var(--bar-h) - var(--foot-h) - 24px), 860px);
  aspect-ratio: var(--car-ar, 2 / 3);
  justify-self: center;
  z-index: 2;
}
.car-img, .layers img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
/* The render's own background is the page colour; feather its edges so the frame disappears. */
.car-img {
  --fx: linear-gradient(90deg, transparent, #000 6%, #000 94%, transparent);
  --fy: linear-gradient(180deg, transparent, #000 2.5%, #000 96%, transparent);
  -webkit-mask-image: var(--fx), var(--fy);
  -webkit-mask-composite: source-in;
          mask-image: var(--fx), var(--fy);
          mask-composite: intersect;
}
.layers img { opacity: 0; transition: opacity 0.28s ease; }
.layers img.on { opacity: 1; }
.layers .landed { position: absolute; height: auto; inset: auto; object-fit: initial; opacity: 1; }

.pins { position: absolute; inset: 0; pointer-events: none; }
.pin {
  position: absolute;
  transform: translate(-20%, -80%);
  pointer-events: auto;
  font: 500 10px/1 var(--mono);
  background: var(--ink);
  color: var(--paper);
  border: 0;
  padding: 4px 6px;
  border-radius: 99px;
  cursor: pointer;
  animation: pin-in 0.4s var(--ease-out) both;
}
.pin:hover { background: var(--accent); }
.pin::after { content: " ×"; opacity: 0; transition: opacity 0.15s; }
.pin:hover::after { opacity: 1; }
@keyframes pin-in { from { opacity: 0; transform: translate(-20%, -40%); } }

/* ---------- pieces (knolling around the car) ---------- */
.pieces {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(20px, 3.2vh, 40px) clamp(16px, 2vw, 32px);
  align-content: center;
  z-index: 3;
}
.pieces.left { padding-right: clamp(12px, 2vw, 40px); }
.pieces.right { padding-left: clamp(12px, 2vw, 40px); }

.piece { position: relative; }
.piece button {
  all: unset;
  display: block;
  width: 100%;
  cursor: pointer;
}
.piece .shot {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
}
.piece .shot img {
  max-width: 88%;
  max-height: 88%;
  filter: drop-shadow(0 6px 8px rgb(40 30 10 / 0.16));
  transition: transform 0.35s var(--ease-out), filter 0.35s var(--ease-out), opacity 0.3s;
}
.piece button:hover .shot img,
.piece button:focus-visible .shot img {
  transform: translateY(-6px);
  filter: drop-shadow(0 16px 16px rgb(40 30 10 / 0.2));
}
.piece button:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 6px; }

.piece .label {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  grid-template-areas: "num name name" ". state price";
  row-gap: 6px;
  align-items: baseline;
  border-top: 1px solid var(--line);
  padding-top: 9px;
  margin-top: 4px;
}
.piece .num { grid-area: num; font: 400 11px/1 var(--mono); color: var(--ink-soft); }
.piece .name { grid-area: name; font: 400 24px/1 var(--serif); letter-spacing: -0.01em; }
.piece .price { grid-area: price; font: 400 12px/1 var(--mono); }
.piece .state { grid-area: state; font: 400 11px/1.2 var(--mono); color: var(--ink-soft); }

.piece.in .shot img { opacity: 0.16; filter: grayscale(1); transform: none; }
.piece.in .state { color: var(--accent); }
.piece.busy { pointer-events: none; }

.hint {
  position: absolute;
  left: 50%;
  bottom: 1.4vh;
  transform: translateX(-50%);
  margin: 0;
  font: 400 12px/1 var(--mono);
  color: var(--ink-soft);
  z-index: 4;
  transition: opacity 0.4s;
}
.hint span { color: var(--ink); }
.hint.gone { opacity: 0; }

/* ---------- foot ---------- */
.foot {
  height: var(--foot-h);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 clamp(16px, 2.4vw, 36px);
  font: 400 11px/1 var(--mono);
  color: var(--ink-soft);
}
.foot p { margin: 0; }

/* ---------- entrance ---------- */
.car .car-img { animation: rise 1.1s var(--ease-out) both; }
.piece { animation: drop 0.7s var(--ease-out) both; animation-delay: calc(0.35s + var(--i) * 70ms); }
@keyframes rise { from { opacity: 0; transform: translateY(24px) scale(0.985); } }
@keyframes drop { from { opacity: 0; transform: translateY(-18px); } }

/* ---------- small screens: car on top, pieces in a strip below ---------- */
@media (max-width: 900px) {
  body { overflow: auto; }
  .bar { grid-template-columns: 1fr auto; height: auto; padding-top: 14px; padding-bottom: 10px; row-gap: 10px; }
  .fits { grid-column: 1 / -1; grid-row: 2; overflow-x: auto; scrollbar-width: none; }
  .tally { grid-column: 2; grid-row: 1; gap: 12px; }
  .tally-total { display: none; }
  .stage { height: auto; grid-template-columns: 1fr; padding-bottom: 24px; }
  .car { height: min(62vh, calc((100vw - 32px) * 1.5)); max-width: 100%; }
  .pieces { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px 12px; padding: 0 !important; }
  .pieces.left { margin-top: 12px; }
  .pieces.right { margin-top: 16px; }
  .piece .name { font-size: 17px; }
  .piece .label { grid-template-columns: 1fr; gap: 4px; }
  .piece .num { display: none; }
  .giant { position: static; grid-row: 1; font-size: 21vw; margin: 4px 0 8px; }
  .car { grid-row: 2; }
  .pieces.left { grid-row: 3; }
  .pieces.right { grid-row: 4; }
  .hint { position: static; transform: none; text-align: center; margin-top: 18px; }
  .foot { height: auto; flex-direction: column; gap: 8px; padding-bottom: 20px; text-align: center; }
}

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