:root {
  --bg: #08080a;
  --sidebar: #0c0c10;
  --panel: #12121a;
  --border: rgba(255, 255, 255, 0.07);
  --text: #f4f4f5;
  --muted: #71717a;
  --purple: #6366f1;
  --purple-dim: rgba(99, 102, 241, 0.14);
  --purple-border: rgba(99, 102, 241, 0.35);
  --green: #22c55e;
}

* { box-sizing: border-box; }

body.vehicle-mapper {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  height: 100vh;
}

.mapper-shell {
  display: grid;
  grid-template-columns: 340px 1fr;
  height: calc(100vh - var(--site-header-h, 88px));
  max-height: calc(100vh - var(--site-header-h, 88px));
  overflow: hidden;
}

/* ── Sidebar ── */
.mapper-sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
}

.sidebar-head {
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-head h1 {
  margin: 0 0 4px;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.sidebar-head p {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

.side-block {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.block-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

.block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.block-head .block-label { margin-bottom: 0; }

.sel-badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--purple-dim);
  color: #a5b4fc;
  border: 1px solid var(--purple-border);
}

.sel-badge.has-selection {
  background: rgba(99, 102, 241, 0.28);
  color: #c7d2fe;
}

.sel-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 8px;
}

.text-btn {
  background: none;
  border: none;
  color: var(--purple);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

.text-btn:hover { text-decoration: underline; }

.sel-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  min-height: 64px;
  max-height: 120px;
  overflow-y: auto;
}

.sel-box-title {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 4px;
}

.sel-ids {
  font-size: 12px;
  line-height: 1.55;
  color: #e0e7ff;
  word-break: break-word;
  font-variant-numeric: tabular-nums;
}

/* File upload */
.file-upload-compact { text-align: center; }

.upload-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 16px 12px;
  border: 1.5px dashed var(--purple-border);
  border-radius: 10px;
  background: var(--purple-dim);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: border-color 0.15s, background 0.15s;
}

.upload-btn:hover {
  border-color: var(--purple);
  background: rgba(99, 102, 241, 0.22);
}

.upload-icon {
  font-size: 18px;
  color: var(--purple);
}

.upload-hint {
  margin: 6px 0 0;
  font-size: 11px;
  color: var(--muted);
}

.file-loaded-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}

.file-loaded-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.status-pill {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 7px;
  border-radius: 4px;
  width: fit-content;
}

.status-pill.loaded {
  background: rgba(34, 197, 94, 0.15);
  color: var(--green);
  border: 1px solid rgba(34, 197, 94, 0.35);
}

.file-name {
  font-size: 12px;
  font-weight: 600;
  word-break: break-all;
}

.file-size {
  font-size: 11px;
  color: var(--muted);
}

.icon-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 4px;
  line-height: 1;
  border-radius: 4px;
}

.icon-btn:hover {
  color: #f87171;
  background: rgba(248, 113, 113, 0.1);
}

.inline-err {
  margin: 6px 0 0;
  font-size: 11px;
  color: #f87171;
}

/* Layout details */
.side-details {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  padding: 0;
  border-bottom: none;
}

.side-details summary {
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  list-style: none;
  border-bottom: 1px solid var(--border);
  user-select: none;
}

.side-details summary::-webkit-details-marker { display: none; }

.side-details summary::after {
  content: "▾";
  float: right;
  font-size: 10px;
}

.side-details[open] summary::after { content: "▴"; }

.layout-fields {
  padding: 10px 16px;
  overflow-y: auto;
  max-height: 180px;
}

.mini-field {
  display: block;
  margin-bottom: 10px;
  font-size: 11px;
  color: var(--muted);
}

.mini-field span {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}

.mini-field strong { color: var(--text); }

.mini-field input[type="range"] {
  width: 100%;
  accent-color: var(--purple);
}

.mini-field.inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.mini-field input[type="number"] {
  width: 52px;
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
}

.mini-toggles {
  display: flex;
  gap: 14px;
  margin-bottom: 10px;
  font-size: 11px;
  color: var(--muted);
}

.mini-toggles input { accent-color: var(--purple); }

.uv-thumb {
  display: block;
  width: calc(100% - 32px);
  margin: 0 16px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

/* Footer */
.sidebar-foot {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.btn-generate {
  width: 100%;
  padding: 12px 16px;
  border: none;
  border-radius: 8px;
  background: linear-gradient(135deg, #4f46e5, #6366f1);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

.btn-generate:hover:not(:disabled) {
  opacity: 0.92;
  transform: translateY(-1px);
}

.btn-generate:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.sidebar-guides {
  padding: 8px 16px 12px;
  flex-shrink: 0;
}

.guide-link {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.guide-link:hover { color: var(--text); }

/* ── Viewport ── */
.mapper-viewport {
  position: relative;
  display: flex;
  flex-direction: column;
  background: #040406;
  overflow: hidden;
  min-height: 0;
}

.view-tabs {
  display: flex;
  gap: 4px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.35);
  flex-shrink: 0;
}

.view-tab {
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.view-tab:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.view-tab.active {
  color: #e0e7ff;
  background: var(--purple-dim);
  border-color: var(--purple-border);
}

.view-panel {
  display: none;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

.view-panel.active { display: flex; }

#view-uv.active {
  display: grid;
  grid-template-columns: 1fr 160px;
}

.uv-stage {
  position: relative;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}

#uv-atlas-canvas {
  max-width: 100%;
  max-height: calc(100vh - var(--site-header-h, 88px) - 120px);
  width: auto;
  height: auto;
  aspect-ratio: 1;
  border-radius: 8px;
  border: 1px solid var(--border);
  box-shadow: 0 8px 32px rgba(0,0,0,0.45);
  cursor: crosshair;
}

.uv-rail {
  border-left: 1px solid var(--border);
  padding: 14px 12px;
  background: rgba(0,0,0,0.25);
  overflow-y: auto;
}

.uv-rail-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}

.uv-hints {
  margin: 0 0 14px;
  padding: 0;
  list-style: none;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.7;
}

.uv-hints kbd {
  display: inline-block;
  min-width: 4.5em;
  font-size: 10px;
  font-family: ui-monospace, monospace;
  color: #c7d2fe;
}

.active-chart {
  font-size: 11px;
  font-weight: 600;
  color: #a5b4fc;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--purple-dim);
  border: 1px solid var(--purple-border);
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stat-cell {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  text-align: center;
}

.stat-val {
  display: block;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.stat-lbl {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.btn-secondary-foot {
  width: 100%;
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.btn-secondary-foot:hover:not(:disabled) { color: var(--text); border-color: var(--purple-border); }
.btn-secondary-foot:disabled { opacity: 0.35; cursor: not-allowed; }

#view-3d.active { flex-direction: column; }
#view-paint.active { flex-direction: column; }

.paint-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 12px;
  gap: 10px;
}

.paint-toolbar-wide { flex-shrink: 0; }

.paint-canvas-wide {
  flex: 1;
  min-height: 200px;
  aspect-ratio: auto;
}

.viewer-3d {
  position: relative;
  flex: 1;
  min-height: 0;
  width: 100%;
}

.viewer-3d canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.viewport-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 1;
}

.viewport-empty.hidden { display: none; }

.empty-inner {
  text-align: center;
  padding: 24px;
}

.empty-title {
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 600;
  color: #52525b;
}

.empty-hint {
  margin: 0;
  font-size: 12px;
  color: #3f3f46;
}

.viewport-hints {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  z-index: 2;
  pointer-events: none;
}

.viewport-hints span {
  font-size: 10px;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid var(--border);
  padding: 4px 8px;
  border-radius: 6px;
}

.preview-status {
  position: absolute;
  bottom: 14px;
  left: 14px;
  margin: 0;
  font-size: 12px;
  color: var(--purple);
  background: rgba(0, 0, 0, 0.65);
  border: 1px solid var(--purple-border);
  padding: 7px 12px;
  border-radius: 8px;
  z-index: 2;
}

.preview-status.err { color: #f87171; border-color: rgba(248, 113, 113, 0.35); }

/* ── Modals ── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal.hidden { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
}

.modal-card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  max-width: 440px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  z-index: 1;
}

.modal-card h2 {
  margin: 0 0 10px;
  font-size: 1.1rem;
}

.modal-text {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}

.modal-close:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.how-steps {
  margin: 12px 0;
  padding-left: 1.2rem;
  display: grid;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.45;
}

.how-steps strong {
  display: block;
  color: var(--text);
  margin-bottom: 2px;
}

.how-note {
  margin: 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(248, 113, 113, 0.08);
  border: 1px solid rgba(248, 113, 113, 0.22);
  font-size: 12px;
  color: #fca5a5;
}

.post-steps {
  margin: 16px 0 0;
  padding-left: 1.2rem;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.55;
}

.hidden { display: none !important; }

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88em;
  background: rgba(255, 255, 255, 0.06);
  padding: 1px 5px;
  border-radius: 4px;
}

.side-block.dimmed {
  opacity: 0.45;
  pointer-events: none;
}

.summary-tag {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #a5b4fc;
  margin-left: 6px;
}

.side-note {
  margin: 0 0 10px;
  font-size: 11px;
  line-height: 1.45;
  color: var(--muted);
}

.live-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #86efac;
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.28);
  padding: 2px 7px;
  border-radius: 999px;
}

.paint-block {
  flex-shrink: 0;
}

.paint-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.paint-toolbar input[type="color"] {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
}

.paint-size {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--muted);
  flex: 1;
  min-width: 120px;
}

.paint-size input { flex: 1; }

.paint-canvas-wrap {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #121218;
  aspect-ratio: 1;
}

#paint-canvas {
  display: block;
  width: 100%;
  height: auto;
  cursor: crosshair;
  touch-action: none;
}

.btn-secondary {
  width: 100%;
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--purple-border);
  background: rgba(99, 102, 241, 0.12);
  color: #c7d2fe;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.btn-secondary:hover:not(:disabled) {
  background: rgba(99, 102, 241, 0.22);
}

.btn-secondary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.paint-block.dimmed {
  opacity: 0.45;
  pointer-events: none;
}

.mapper-viewport.drag-over::after {
  content: "";
  position: absolute;
  inset: 12px;
  border: 2px dashed var(--purple);
  border-radius: 12px;
  pointer-events: none;
  z-index: 3;
}

/* ── Coming soon gate ── */
.coming-soon-banner {
  position: fixed;
  inset: var(--site-header-h, 88px) 0 0 0;
  z-index: 8000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(8, 8, 10, 0.88);
  backdrop-filter: blur(10px);
}

.coming-soon-card {
  max-width: 420px;
  width: 100%;
  text-align: center;
  padding: 36px 28px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--panel);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.45);
}

.coming-soon-badge {
  display: inline-block;
  margin-bottom: 14px;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #fcd34d;
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.35);
}

.coming-soon-card h2 {
  margin: 0 0 10px;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.coming-soon-card p {
  margin: 0;
  font-size: 14px;
  line-height: 1.55;
  color: var(--muted);
}

.coming-soon-locked {
  pointer-events: none;
  user-select: none;
  filter: blur(2px) saturate(0.7);
  opacity: 0.35;
}

/* ── Single-page studio layout ── */
body.vehicle-studio {
  overflow: hidden;
  height: 100vh;
}

.studio-shell {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: calc(100vh - var(--site-header-h, 88px));
  max-height: calc(100vh - var(--site-header-h, 88px));
  overflow: hidden;
}

.studio-sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
}

.studio-stage {
  position: relative;
  display: flex;
  flex-direction: column;
  background: #040406;
  overflow: hidden;
  min-height: 0;
}

.studio-stage .viewer-3d {
  position: absolute;
  inset: 0;
  flex: none;
}

.stage-hints {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  z-index: 2;
  pointer-events: none;
}

.stage-hints span {
  font-size: 10px;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid var(--border);
  padding: 4px 8px;
  border-radius: 6px;
}

.live-hint {
  color: #86efac !important;
  border-color: rgba(34, 197, 94, 0.28) !important;
}

.livery-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}

.livery-tab {
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.livery-tab:hover { color: var(--text); border-color: var(--purple-border); }
.livery-tab.active {
  color: #e0e7ff;
  background: var(--purple-dim);
  border-color: var(--purple-border);
}

.livery-tab.add {
  min-width: 32px;
  padding: 6px 10px;
  color: var(--purple);
}

.tool-row {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.tool-btn {
  flex: 1;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.tool-btn:hover { color: var(--text); }
.tool-btn.active {
  color: #e0e7ff;
  background: var(--purple-dim);
  border-color: var(--purple-border);
}

.tool-panel { margin-bottom: 10px; }

.tool-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.studio-input {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
}

.studio-input:focus {
  outline: none;
  border-color: var(--purple-border);
}

.btn-action {
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: 8px;
  background: linear-gradient(135deg, #4f46e5, #6366f1);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.btn-action:hover { opacity: 0.92; }

.texture-map-wrap {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #121218;
  margin: 10px 0 8px;
}

.texture-map-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
}

#thumb-canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  cursor: crosshair;
  touch-action: none;
}

.hidden-canvas {
  position: fixed;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.uv-mini {
  display: block;
  width: 100%;
  margin: 8px 0;
  border-radius: 6px;
  border: 1px solid var(--border);
}

@media (max-width: 820px) {
  body.vehicle-mapper,
  body.vehicle-studio { overflow: auto; height: auto; }
  .mapper-shell,
  .studio-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 55vh;
    height: auto;
    max-height: none;
  }
  .mapper-sidebar,
  .studio-sidebar { max-height: none; }
  .sel-box { max-height: 80px; }
}
