/* Garage view: 3D stage, stats board, parts panel. Layout: docs/design-plan.md, "Garage". */

/* Desktop: the view fills the window under the header; only the panel scrolls. */
#view-garage:not([hidden]) {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--header-h));
}
#view-garage .sunstrip { flex: none; background: var(--c-raised); border-bottom: 1px solid var(--c-line); }
/* Long car names shrink to fit the strip (down to 48 px) before they get an ellipsis. */
#view-garage .sunstrip__title {
  font-size: clamp(var(--t-5), calc((100vw - 18rem) / (var(--chars, 12) * 0.95)), var(--t-6));
}
.garage__class { font-weight: var(--wt-bold); }

.garage {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--panel-w);
}

/* ---------- stage ---------- */
.stage { position: relative; min-height: 0; overflow: hidden; }
.stage__canvas { position: absolute; inset: 0; }
.stage__canvas canvas { width: 100%; height: 100%; }
.stage__back {
  position: absolute;
  top: var(--s-4);
  left: var(--s-4);
  background: var(--c-scrim);
}
.stage__back:hover { background: var(--c-raised-2); }
.garage-msg {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: var(--s-5);
  color: var(--c-chrome);
}

/* ---------- stats: a translucent timing board on the canvas ---------- */
.stats {
  position: absolute;
  left: var(--s-4);
  bottom: var(--s-4);
  max-width: calc(100% - 2 * var(--s-4)); /* never wider than the stage; the bars give way */
  padding: var(--s-3) var(--s-4);
  background: var(--c-scrim);
  backdrop-filter: blur(6px);
  border: 1px solid var(--c-line);
  border-radius: var(--r-container);
}
.stats__list { display: grid; gap: var(--s-1); padding: 0; list-style: none; }
.stat {
  display: grid;
  grid-template-columns: 7rem 2.2em minmax(3rem, 11rem) 2.2em 2.6em;
  align-items: center;
  column-gap: var(--s-3);
  font-size: var(--t-2);
}
.stat__label { font-family: var(--f-display); font-weight: 500; }
.stat__short { display: none; }
.stat__stock { text-align: right; color: var(--c-chrome); }
.stat__tuned { text-align: right; font-weight: var(--wt-bold); }
.stat__delta { font-size: var(--t-1); color: var(--c-chrome); }
.stat--gain .stat__tuned, .stat--gain .stat__delta { color: var(--c-seaglass); }
.stat__bar {
  position: relative;
  height: 6px;
  border-radius: 3px;
  background: var(--c-line-strong);
  overflow: hidden;
}
.stat__fill, .stat__change { position: absolute; top: 0; bottom: 0; }
.stat__fill { left: 0; background: var(--c-chalk); transition: width var(--dur) var(--ease); }
.stat--gain .stat__change { background: var(--c-seaglass); }
/* A loss: the part given up stays as a hatched outline, so it reads without colour. */
.stat--loss .stat__change {
  background: repeating-linear-gradient(-45deg, var(--c-chrome) 0 2px, transparent 2px 4px);
}

/* ---------- parts panel ---------- */
.gpanel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--c-asphalt);
  border-left: 1px solid var(--c-line);
}
.gpanel__parts { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.panel__tabs { position: sticky; top: 0; z-index: 1; background: var(--c-asphalt); }
.panel__empty { padding: var(--s-5) var(--s-4); }
.gpanel__foot {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--s-4);
  padding: var(--s-3) var(--s-4);
  background: var(--c-asphalt);
  border-top: 1px solid var(--c-line);
}
.gpanel__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  padding: var(--s-3) var(--s-4);
  border-top: 1px solid var(--c-line);
}
.actions__item { display: contents; }
.actions-pop { width: min(20rem, calc(100vw - 2 * var(--s-3))); }
.actions-form { display: grid; gap: var(--s-2); }
.saved { display: grid; gap: var(--s-2); }
.saved__row { display: flex; align-items: center; gap: var(--s-2); }
.saved__name { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
/* The build sheet only exists on paper (css/print.css shows it). */
.sheet { display: none; }
.gpanel__label { font-family: var(--f-display); font-weight: var(--wt-bold); }
.gpanel__total { font-size: var(--t-4); }

.acc__h { font: inherit; }

/* Option row: the radio button plus a separate shop line (which holds links). */
.option-row {
  border-left: 3px solid transparent;
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.option-row:hover { background: var(--c-raised); }
.option-row.is-on { border-left-color: var(--c-sodium); background: var(--c-raised); }
.option-row .option,
.option-row .option:hover,
.option-row .option[aria-checked="true"] { border-left: 0; background: none; }
.option-row .option { padding-left: calc(var(--s-4) - 3px); }
.option-row .option__meta { font-size: var(--t-1); }
.option__shop {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-1) var(--s-2);
  /* lines up with the option name: row padding + radio dot + column gap */
  padding: 0 var(--s-4) var(--s-2) calc(var(--s-4) - 3px + 1rem + var(--s-3));
  font-size: var(--t-1);
  color: var(--c-chrome);
}
.shops-btn {
  padding: 0;
  font-size: var(--t-1);
  color: var(--c-chalk);
  background: none;
  border: 0;
  text-decoration: underline dotted var(--c-chrome);
  text-underline-offset: 3px;
}
.shops-btn:hover { color: var(--c-sodium); }

/* Colour categories: a swatch grid, then the picked colour's name, price and shops. */
.swatch-wrap { padding: var(--s-2) var(--s-4) var(--s-3); }
.swatches {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(2.5rem, 1fr));
  gap: var(--s-2);
}
.swatch {
  aspect-ratio: 1;
  background: var(--swatch);
  border: 1px solid var(--c-line-strong);
  border-radius: var(--r-control);
  transition: box-shadow var(--dur) var(--ease);
}
.swatch--stock {
  grid-column: span 2;
  aspect-ratio: auto;
  font-family: var(--f-display);
  font-size: var(--t-1);
  font-weight: 600;
  color: var(--c-chrome);
  background: var(--c-raised);
}
.swatch--stock::after { content: "Stock"; }
.swatch[aria-checked="true"] { box-shadow: 0 0 0 2px var(--c-asphalt), 0 0 0 4px var(--c-sodium); }
.swatch--stock[aria-checked="true"] { color: var(--c-sodium); }
.swatch:focus-visible { outline-offset: 6px; }
.swatch-info { margin-top: var(--s-3); font-size: var(--t-2); }
.swatch-info__row { display: flex; justify-content: space-between; gap: var(--s-3); }
.swatch-info .option__shop { padding: var(--s-1) 0 0; }

/* ---------- phone and narrow tablet: stage on top, stats as one line, the panel below ----------
   860px: below it, the stage beside a 380px panel is too narrow for the stats board
   (it needs about 372px), so the whole garage stacks. The strip follows base.css's phone setting. */
@media (max-width: 860px) {
  #view-garage:not([hidden]) { display: block; height: auto; }
  #view-garage .sunstrip { flex-wrap: wrap; row-gap: 0; padding: var(--s-4); }
  #view-garage .sunstrip__title { flex-basis: 100%; font-size: clamp(1.65rem, 6vw, 2.25rem); font-stretch: 110%; white-space: normal; }
  #view-garage .sunstrip__meta { font-size: var(--t-2); gap: var(--s-3); }
  .garage { display: block; }
  .stage { overflow: visible; }
  .stage__canvas { position: relative; height: 45vh; }
  .stage__back { top: var(--s-3); left: var(--s-3); }
  .stats {
    position: static;
    max-width: none;
    padding: var(--s-2) var(--s-4);
    background: var(--c-raised);
    backdrop-filter: none;
    border-width: 1px 0;
    border-radius: 0;
  }
  .stats__list { display: flex; gap: var(--s-4); overflow-x: auto; }
  .stat { display: flex; align-items: baseline; gap: var(--s-1); white-space: nowrap; }
  .stat__label, .stat__stock, .stat__bar, .stat__delta { display: none; }
  .stat__short { display: inline; font-family: var(--f-display); color: var(--c-chrome); }
  .gpanel { border-left: 0; }
  .gpanel__parts { overflow: visible; }
  .panel__tabs { overflow-x: auto; }
  .panel__tabs .tab { flex: 1 0 auto; }
  .gpanel__foot { position: sticky; bottom: 0; z-index: 2; }
}
@media (pointer: coarse) {
  .shops-btn, .option__shop .link { padding-block: var(--s-2); }
}

.gpanel__scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.garage__equipment, .preview { padding: var(--s-4); }
.preview { display: grid; gap: var(--s-3); border-bottom: 1px solid var(--c-line); }
.preview h2, .equipment h2 { font-size: var(--t-4); }
.preview__field { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); }
.preview__field select { min-width: 0; max-width: 65%; }
.preview__field input[type=color] { width: 3rem; height: 2rem; cursor: pointer; }
.preview__status:empty { display: none; }
.garage-msg { pointer-events: none; }
.equipment { max-width: 52rem; }
.equipment > p { margin-block: var(--s-2) var(--s-4); color: var(--c-chrome); }
.equipment details { border-top: 1px solid var(--c-line); }
.equipment summary { cursor: pointer; padding: var(--s-3) 0; font-weight: var(--wt-bold); }
.equipment ul { padding: 0; list-style: none; }
.equipment li { padding: var(--s-2) var(--s-3); overflow-wrap: anywhere; }
.equipment li:nth-child(odd) { background: var(--c-raised); }
.equipment small { display: block; color: var(--c-chrome); }

@media (max-width: 860px) {
  .gpanel__scroll { overflow: visible; }
}

.paint-controls { min-width: 0; margin: .8rem 0; padding: .6rem; border: 1px solid currentColor; border-radius: .4rem; }
.paint-controls legend { padding: 0 .4rem; font-weight: 600; }
.paint-controls [hidden] { display: none; }
.paint-controls .input { min-width: 0; max-width: 100%; }
.paint-swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(30px, 1fr)); gap: 4px; max-height: 10rem; overflow: auto; margin: .5rem 0; }
.paint-swatches button { height: 30px; border: 1px solid #888; border-radius: 4px; cursor: pointer; }
.paint-swatches button[aria-pressed=true] { box-shadow: inset 0 0 0 2px white, inset 0 0 0 4px black; }
