/* Stagger Paint Booth.
 *
 * Consumes styles/tokens.css, the same token file the Stagger site uses. No
 * colour or size is hard coded here.
 *
 * DENSITY IS THE POINT, same as the site: 13px body, nothing larger than the
 * brand lockup, 2-4px radii, a 44px header. If something starts growing, that
 * is the bug. Racing red is punctuation only: the render button, the selected
 * layer, focus. It never fills a panel.
 */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-snug);
}

body { display: flex; flex-direction: column; }

button, input, select { font: inherit; color: inherit; }

:focus-visible {
  outline: var(--focus-ring-width) solid var(--accent);
  outline-offset: var(--focus-ring-offset);
}

/* ------------------------------------------------------------------ header */

.topbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--header-height);
  padding: 0 var(--space-4);
  background: var(--header-bar);
  border-bottom: 1px solid var(--border);
  flex: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex: 0 0 auto;
}

.brand-lockup {
  display: block;
  width: auto;
  height: 26px;
}

.brand-tool {
  padding-left: var(--space-3);
  border-left: 1px solid var(--bar-border);
  color: var(--bar-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  white-space: nowrap;
}

.spacer { flex: 1; }

.bar-label {
  color: var(--bar-muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  margin-left: var(--space-2);
}

.status {
  color: var(--bar-muted);
  font-size: var(--text-sm);
  margin-right: var(--space-2);
  max-width: 22rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------------------------------------------------------------- controls */

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--control-height-sm);
  padding: 0 var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--duration-fast) var(--ease),
    border-color var(--duration-fast) var(--ease),
    color var(--duration-fast) var(--ease);
}

button:hover { background: var(--surface-hover); }

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}

button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

button.danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}

/* A latched toggle reads like a selected layer row, not like a filled panel. */
button[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text);
}

button[aria-pressed="true"]:hover { background: var(--accent-soft); }

button[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
}

button[disabled]:hover { background: var(--surface); }

input[type="text"], input[type="number"], select {
  width: 100%;
  min-height: var(--control-height-sm);
  padding: var(--space-1) var(--space-3);
  background: var(--surface-sunken);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  transition: border-color var(--duration-fast) var(--ease);
}

input[type="text"]:hover, input[type="number"]:hover, select:hover { border-color: var(--text); }

input[type="color"] {
  width: 100%;
  height: var(--control-height);
  padding: 2px;
  background: var(--surface-sunken);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  cursor: pointer;
}

input[type="range"] { width: 100%; accent-color: var(--accent); }
input[type="checkbox"] { accent-color: var(--accent); }

/* ------------------------------------------------------------------ layout */

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr var(--sidebar-width);
  min-height: 0;
}

.panel {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: var(--space-4);
  overflow-y: auto;
}

.panel.right { border-right: 0; border-left: 1px solid var(--border); }

.panel h2 {
  margin: 0 0 var(--space-3);
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--muted);
}

.divider {
  height: 1px;
  background: var(--border);
  margin: var(--space-5) 0 var(--space-4);
}

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-bottom: var(--space-3);
  flex: 1;
  min-width: 0;
}

.field label {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--muted);
}

.row { display: flex; gap: var(--space-3); align-items: center; }

.check-row {
  gap: var(--space-2);
  margin: var(--space-2) 0 var(--space-3);
  font-size: var(--text-base);
  cursor: pointer;
}

.color-row { align-items: flex-start; }
.color-row input[type="color"] { width: 3rem; flex: none; }

.hint {
  color: var(--muted);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  margin: 0 0 var(--space-3);
}

/* ---------------------------------------------------------------- swatches */

.swatches {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-1);
  flex: 1;
}

.swatch {
  min-height: 0;
  height: 1.25rem;
  padding: 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
}

/* ----------------------------------------------------------- sticker tiles */

.sticker-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-1);
}

.sticker-tile {
  position: relative;
  aspect-ratio: 1;
  min-height: 0;
  padding: var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  overflow: hidden;
}

.sticker-tile img { max-width: 100%; max-height: 100%; object-fit: contain; }

.sticker-tile.upload {
  color: var(--muted);
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}

.tile-remove {
  position: absolute;
  top: 1px;
  right: 4px;
  color: var(--muted);
  font-size: var(--text-xs);
  line-height: 1;
}

.tile-remove:hover { color: var(--danger); }

/* ------------------------------------------------------------------- stage */

.stage-wrap { position: relative; min-width: 0; background: var(--surface-sunken); }

#stage { width: 100%; height: 100%; display: block; touch-action: none; }

.stage-hud {
  position: absolute;
  left: var(--space-4);
  bottom: var(--space-4);
  display: flex;
  gap: var(--space-2);
  align-items: center;
  color: var(--muted);
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}

/* ----------------------------------------------------------- transform bar */

.move-panel {
  position: absolute;
  left: 50%;
  bottom: var(--space-4);
  transform: translateX(-50%);
  width: min(42rem, calc(100% - var(--space-10)));
  padding: var(--space-3) var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.move-panel.hidden, .hidden { display: none !important; }

.mp-head {
  display: flex;
  gap: var(--space-4);
  align-items: center;
  margin-bottom: var(--space-3);
}

.mp-head span {
  flex: 1;
  min-width: 0;
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mp-head label {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  color: var(--muted);
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}

.mp-head input { width: 4.5rem; }

.mp-sliders {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.mp-sliders label {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  color: var(--muted);
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}

.mp-buttons { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; }
.mp-buttons input[type="color"] { width: 2rem; height: var(--control-height-sm); flex: none; }

/* ---------------------------------------------------------- template panel */

.template-overlay {
  position: absolute;
  top: var(--space-4);
  right: var(--space-4);
  padding: var(--space-3);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

#templateCanvas {
  display: block;
  width: min(44vh, 30rem);
  height: min(44vh, 30rem);
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
}

.template-bar { justify-content: space-between; margin-top: var(--space-3); }
.template-bar .check-row { margin: 0; font-size: var(--text-sm); }

/* ------------------------------------------------------------------ layers */

.layer-list { list-style: none; margin: 0; padding: 0; }

.layer-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-1) var(--space-2);
  margin-bottom: 1px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  cursor: pointer;
}

.layer-item:hover { background: var(--surface-hover); }

.layer-item.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.layer-item .thumb {
  width: 1.75rem;
  height: 1.75rem;
  flex: none;
  border-radius: var(--radius-sm);
  background: var(--bg);
}

.layer-item .name {
  flex: 1;
  min-width: 0;
  font-size: var(--text-sm);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layer-tag {
  padding: 0 var(--space-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}

.layer-item .eye {
  min-height: 0;
  padding: 1px var(--space-2);
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}

.layer-item .eye:hover { background: var(--pill-hover); color: var(--text); }

/* ------------------------------------------------------------------- misc */

.track-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-bottom: var(--space-3);
}

.track-list label {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  font-size: var(--text-base);
  cursor: pointer;
}

.log {
  padding: var(--space-3);
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: var(--leading-normal);
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 13rem;
  overflow-y: auto;
}

/* ---------------------------------------------------------------- mod picker
 * A file input cannot be styled, so the real control is a label that looks
 * like a button with the input hidden inside it. That is also what keeps the
 * native folder picker working: the click has to reach the input itself.
 */
.file-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--control-height-sm);
  padding: 0 var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease),
    border-color var(--duration-fast) var(--ease);
}

.file-btn:hover { background: var(--surface-hover); }
.file-btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.file-btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.file-btn.wide { display: flex; width: 100%; margin-top: var(--space-2); }
.file-btn input[type="file"] { display: none; }
.file-btn:has(input:disabled) { opacity: 0.5; cursor: default; }

#modCar { max-width: 12rem; }

.mod-info {
  padding: var(--space-3);
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: var(--text-xs);
  line-height: var(--leading-normal);
  color: var(--muted);
  word-break: break-word;
}

.mod-info strong { color: var(--text); font-weight: var(--weight-semibold); }

/* The stage before a car is loaded. It sits over the (empty) canvas rather
   than replacing it so the renderer keeps its size and never has to be
   rebuilt when the first mod arrives. */
.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-6);
  text-align: center;
  background: var(--surface-sunken);
  z-index: 2;
}

.empty-state h2 {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  color: var(--text);
}

.empty-state p {
  margin: 0;
  max-width: 34rem;
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  color: var(--muted);
}

/* ------------------------------------------------------------ painted parts */
.panel h3.sub {
  margin: var(--space-4) 0 var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text);
}

.sheet-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  max-height: 11rem;
  overflow-y: auto;
}

.sheet-list .check-row {
  margin: 0;
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  color: var(--muted);
}

/* The transform bar's name doubles as the text field for a number already on
   the car, so it has to sit at the same size as the label it replaces. */
#mpText {
  width: 8rem;
  min-height: var(--control-height-sm);
  padding: 0 var(--space-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  color: var(--text);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
}

#mpText:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

#rideHeightValue { color: var(--muted); font-family: var(--font-mono); }
