:root {
  --bg: #1a1a1d;
  --panel: rgba(28, 28, 32, 0.92);
  --panel-solid: #1c1c20;
  --line: #2c2c33;
  --txt: #e6e6e8;
  --muted: #9a9aa3;
  --accent: #d62828;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--txt);
  font-family: -apple-system, "Segoe UI", system-ui, sans-serif;
  font-size: 13px;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.45), transparent);
  z-index: 5;
  pointer-events: none;
}
#topbar .title {
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--muted);
}
#topbar .controls {
  display: flex;
  gap: 8px;
  align-items: center;
  pointer-events: auto;
}
#topbar button,
#topbar .toggle {
  padding: 6px 12px;
  border-radius: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--txt);
  font-size: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
#topbar button:hover { background: #2c2c33; }
#topbar .toggle input { accent-color: var(--accent); margin: 0; }

#sidepanel {
  position: fixed;
  top: 56px;
  right: 16px;
  width: 240px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  z-index: 4;
  backdrop-filter: blur(6px);
}
#sidepanel .row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 0;
  font-size: 12px;
}
#sidepanel .label { color: var(--muted); }
#sidepanel .value { color: var(--txt); font-weight: 500; text-align: right; }
#sidepanel .hint {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

#filmstrip {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--panel-solid);
  border-top: 1px solid var(--line);
  z-index: 5;
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 8px 12px 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 6px 12px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.tab.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.tab:hover:not(.active) { color: var(--txt); border-color: #444; }

.films {
  display: flex;
  gap: 6px;
  padding: 10px 12px 14px;
  overflow-x: auto;
  scrollbar-width: thin;
}
.films::-webkit-scrollbar { height: 8px; }
.films::-webkit-scrollbar-thumb { background: #444; border-radius: 4px; }

.swatch {
  flex-shrink: 0;
  width: 64px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  text-align: center;
  border-radius: 6px;
  padding: 4px;
  border: 2px solid transparent;
  transition: transform 0.12s ease;
}
.swatch:hover { transform: translateY(-2px); }
.swatch.active { border-color: var(--accent); }
.swatch .chip {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 4px;
  margin-bottom: 4px;
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.06), 0 1px 4px rgba(0,0,0,0.4);
}
/* finish overlays — gloss = sheen, satin = soft band, matte = flat, metallic = grain */
.swatch.t1 .chip::after,   /* gloss */
.swatch.t9 .chip::after,
.swatch.t12 .chip::after,
.swatch.t2 .chip::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.45) 0%, rgba(255,255,255,0) 45%);
}
.swatch.t4 .chip::after,
.swatch.t11 .chip::after,
.swatch.t22 .chip::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.18) 0%, rgba(255,255,255,0) 70%);
}
.swatch.t2 .chip::before,
.swatch.t11 .chip::before,
.swatch.t5 .chip::before,
.swatch.t9 .chip::before,
.swatch.t12 .chip::before,
.swatch.t22 .chip::before {
  content: ""; position: absolute; inset: 0;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(255,255,255,0.15) 0 1px, transparent 1px),
    radial-gradient(circle at 70% 60%, rgba(255,255,255,0.1) 0 1px, transparent 1px),
    radial-gradient(circle at 50% 80%, rgba(255,255,255,0.12) 0 1px, transparent 1px);
  background-size: 8px 8px, 11px 11px, 6px 6px;
}
.swatch .name {
  font-size: 10px;
  color: var(--txt);
  line-height: 1.2;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}
.swatch .type {
  font-size: 9px;
  color: var(--muted);
  margin-top: 1px;
}

/* ───────── vehicle picker ───────── */
#topbar #vehBtn {
  font-weight: 500;
}
#topbar #vehBtn .caret {
  margin-left: 4px;
  color: var(--muted);
  font-size: 10px;
}

#vehiclePicker {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
}
#vehiclePicker.hidden { display: none; }
#vehBackdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
}
#vehModal {
  position: relative;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 10px;
  width: min(900px, 92vw);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#vehHeader {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}
#vehSearch {
  flex: 1;
  background: #0f0f12;
  border: 1px solid var(--line);
  color: var(--txt);
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 6px;
  outline: none;
}
#vehSearch:focus { border-color: var(--accent); }
#vehClose {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 22px;
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  line-height: 1;
}
#vehClose:hover { background: var(--line); color: var(--txt); }
#vehicleGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
  padding: 12px;
  overflow-y: auto;
}
.vcard {
  background: #16161a;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: transform 0.1s ease, border-color 0.1s ease;
  color: var(--txt);
  font: inherit;
  text-align: center;
}
.vcard:hover { border-color: #555; transform: translateY(-2px); }
.vcard.active { border-color: var(--accent); background: #1f1416; }
.vcard img {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: contain;
  background: #0a0a0c;
  border-radius: 4px;
}
.vcard .vname {
  font-size: 11px;
  line-height: 1.25;
}

#loading {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
  transition: opacity 0.3s ease;
}
#loading.hidden { opacity: 0; pointer-events: none; }
#loading .spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #333;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 14px;
}
#loading .msg { color: var(--muted); font-size: 12px; }
@keyframes spin { to { transform: rotate(360deg); } }
