*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f4f1eb;
  --surface: rgba(250, 248, 244, 0.92);
  --surface-solid: #fbfaf7;
  --surface-soft: #eeebe7;
  --border: rgba(28, 25, 21, 0.10);
  --border-strong: rgba(28, 25, 21, 0.18);
  --text: #171411;
  --muted: #9c958b;
  --muted-strong: #6d665e;
  --accent: #d65338;
  --active-ring: rgba(28, 25, 21, 0.22);
  --shadow: 0 28px 90px rgba(61, 52, 39, 0.18);
  --mono: 'Roboto Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

html { min-height: 100%; background: var(--bg); }

body {
  min-height: 100vh;
  overflow: auto;
  color: var(--text);
  font-family: var(--sans);
  background:
    radial-gradient(circle at 46% 52%, rgba(255,255,255,0.92) 0 22%, rgba(244,241,235,0.84) 42%, rgba(224,215,203,0.82) 100%),
    linear-gradient(135deg, #faf9f6 0%, #eee8df 100%);
}

button { font: inherit; color: inherit; }

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(380px, 30vw, 484px);
  min-height: 100vh;
}

/* Studio */
.studio {
  position: relative;
  min-width: 0;
  min-height: 100vh;
  padding: 38px clamp(26px, 3vw, 64px) 34px;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  overflow: hidden;
}

.studio::after {
  content: '';
  position: absolute;
  left: 18%;
  right: 10%;
  bottom: -7%;
  height: 28%;
  pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(206,78,48,0.13), rgba(206,78,48,0) 70%);
  filter: blur(12px);
}

.section-label,
.config-kicker,
.spec-label {
  font-family: var(--mono);
  letter-spacing: 0.28em;
  text-transform: uppercase;
}

.viewer {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: clamp(28px, 6vh, 86px) 0 clamp(34px, 8vh, 104px);
}

.car-stage { width: min(100%, 1120px); transform: translateY(-1.5vh); }
.model-frame { position: relative; }

#challenger-3d {
  width: 100%;
  height: clamp(430px, 62vh, 720px);
  display: block;
  border: 0;
  border-radius: 32px;
  overflow: hidden;
  background: transparent;
  filter: drop-shadow(0 35px 56px rgba(77, 64, 48, 0.16));
}

.model-loading {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: #34302a;
  background: rgba(250,248,244,0.72);
  border: 1px dashed rgba(28,25,21,0.22);
  border-radius: 28px;
  backdrop-filter: blur(10px);
  transition: opacity 0.22s ease, visibility 0.22s ease;
}
.model-loading[data-state="loaded"] { opacity: 0; visibility: hidden; pointer-events: none; }
.model-loading[data-state="error"] { color: #8f1f18; }
.model-loading strong { display: block; font-size: 12px; letter-spacing: 0.16em; text-transform: uppercase; }
.model-loading span { display: block; margin-top: 4px; color: var(--muted-strong); font-size: 13px; }
.loader-ring { width: 28px; height: 28px; border-radius: 50%; border: 3px solid rgba(32,32,32,0.12); border-top-color: #202020; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.asset-credit { margin: 8px auto 0; max-width: 840px; color: rgba(110,102,92,0.72); font-size: 10px; line-height: 1.4; text-align: center; }

.studio-actions { position: absolute; z-index: 4; right: 30px; bottom: 26px; display: grid; gap: 13px; }
.round-action,
.footer-reset {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.9);
  background: rgba(255,255,255,0.78);
  box-shadow: 0 12px 28px rgba(52,43,32,0.12), inset 0 0 0 1px rgba(28,25,21,0.04);
  color: #766f66;
  font-size: 30px;
  cursor: pointer;
  backdrop-filter: blur(14px);
}
.round-action:disabled { opacity: 0.72; cursor: not-allowed; font-size: 21px; }
.round-action:not(:disabled):hover,
.footer-reset:hover { transform: translateY(-1px); }

.studio-spec-strip {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: flex-end;
  gap: clamp(16px, 1.7vw, 26px);
  width: min(100%, 920px);
  padding-bottom: 2px;
}
.spec { min-width: 92px; }
.spec-engine { min-width: 300px; flex: 1; }
.spec-value { font-family: var(--mono); font-size: clamp(16px, 1.28vw, 24px); line-height: 1.05; letter-spacing: 0.01em; white-space: nowrap; }
.spec-value small { font-family: var(--sans); font-size: 12px; color: var(--muted-strong); letter-spacing: 0; }
.spec-label { margin-top: 9px; color: var(--muted); font-weight: 700; font-size: 10px; }
.spec-divider { width: 1px; height: 34px; background: rgba(28,25,21,0.12); align-self: flex-end; margin-bottom: 2px; }

/* Configurator */
.configurator {
  position: relative;
  z-index: 5;
  min-height: 100vh;
  padding: 24px 20px 24px 0;
  display: flex;
  align-items: stretch;
}

.config-card {
  width: 100%;
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.72);
  border-radius: 34px;
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
}

.config-header { padding: 30px 34px 22px; border-bottom: 1px solid var(--border); }
.config-header h1 { font-size: clamp(24px, 1.7vw, 29px); line-height: 1; letter-spacing: -0.055em; font-weight: 800; }
.config-kicker { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin-top: 13px; color: var(--muted-strong); font-size: 12px; }
.accent-pill { padding: 5px 14px; border-radius: 999px; color: var(--accent); background: rgba(214,83,56,0.13); letter-spacing: 0.18em; font-weight: 700; }

.config-scroll { min-height: 0; overflow-y: auto; overflow-x: hidden; scrollbar-width: thin; }
.config-scroll::-webkit-scrollbar { width: 8px; }
.config-scroll::-webkit-scrollbar-thumb { background: rgba(28,25,21,0.14); border-radius: 999px; }

.config-section { padding: 23px 34px; border-bottom: 1px solid var(--border); }
.section-label { margin-bottom: 18px; color: var(--muted-strong); font-weight: 700; font-size: 12px; }
.color-name-display { margin: -8px 0 15px; color: var(--muted-strong); font-size: 13px; }
.color-swatches { display: flex; flex-wrap: wrap; gap: 13px; }
.color-swatch {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.16);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.22), 0 4px 10px rgba(0,0,0,0.10);
  cursor: pointer;
}
.color-swatch.active { outline: 3px solid var(--text); outline-offset: 4px; }

.option-block + .option-block { margin-top: 23px; }
.option-label { display: block; margin-bottom: 12px; color: var(--muted); font-size: 12px; font-weight: 800; letter-spacing: 0.095em; text-transform: uppercase; }
.option-pills { display: flex; gap: 10px; flex-wrap: wrap; }
.option-pill {
  min-height: 42px;
  border: 0;
  border-radius: 14px;
  padding: 0 18px;
  background: var(--surface-soft);
  color: var(--muted-strong);
  font-weight: 800;
  cursor: pointer;
  transition: color 0.18s ease, background 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}
.option-pill:hover { color: var(--text); background: #fff; }
.option-pill.active { color: var(--text); background: #fff; box-shadow: 0 7px 18px rgba(28,25,21,0.09), inset 0 0 0 1px var(--active-ring); transform: translateY(-1px); }
.option-pill:disabled { opacity: 0.55; cursor: wait; }
.option-pill:focus-visible,
.color-swatch:focus-visible,
.share-btn:focus-visible,
.footer-reset:focus-visible,
.round-action:focus-visible { outline: 2px solid rgba(28,25,21,0.32); outline-offset: 3px; }

.segmented {
  position: relative;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 0;
  padding: 4px;
  border-radius: 14px;
  background: var(--surface-soft);
  overflow: hidden;
}
.segmented::before {
  content: '';
  position: absolute;
  z-index: 0;
  top: 4px;
  bottom: 4px;
  left: 4px;
  width: calc((100% - 8px) / var(--option-count, 2));
  border-radius: 12px;
  background: var(--surface-solid);
  box-shadow: 0 4px 12px rgba(28,25,21,0.10), inset 0 0 0 1px var(--active-ring);
  transform: translateX(calc(var(--active-index, 0) * 100%));
  transition: transform 220ms cubic-bezier(.2,.8,.2,1), box-shadow 180ms ease;
}
.segmented .option-pill { position: relative; z-index: 1; min-width: 0; width: 100%; border-radius: 12px; background: transparent; box-shadow: none; transform: none; }
.segmented .option-pill.active { background: transparent; box-shadow: none; transform: none; }

#caliper-options .option-pill {
  width: 40px;
  min-width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  border-radius: 50%;
  overflow: hidden;
  text-indent: -999px;
  border: 1px solid rgba(0,0,0,0.16);
}
#caliper-options .option-pill:nth-child(1) { background: #cf3a2e; }
#caliper-options .option-pill:nth-child(2) { background: #15161a; }
#caliper-options .option-pill:nth-child(3) { background: #bfc4c7; }
#caliper-options .option-pill:nth-child(4) { background: #f0c33f; }
#caliper-options .option-pill.active { outline: 3px solid var(--text); outline-offset: 4px; box-shadow: inset 0 0 0 5px rgba(255,255,255,0.24); }

.toggle-list { margin-top: 6px; }
.toggle-block { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 18px; padding: 16px 0; border-bottom: 1px solid var(--border); }
.toggle-block:first-of-type { padding-top: 0; }
.toggle-block:last-of-type { border-bottom: 0; padding-bottom: 0; }
.toggle-copy strong { display: block; font-size: 15px; line-height: 1.2; }
.toggle-copy small { display: block; margin-top: 5px; color: var(--muted); font-size: 13px; }
.toggle-options { position: relative; width: 58px; height: 34px; border-radius: 999px; background: rgba(28,25,21,0.16); flex-wrap: nowrap; overflow: hidden; }
.toggle-options .option-pill { position: absolute; inset: 0; min-height: 0; padding: 0; border-radius: 999px; color: transparent; background: transparent; box-shadow: none; }
.toggle-options .option-pill:first-child.active { background: var(--accent); }
.toggle-options .option-pill:first-child.active::after,
.toggle-options .option-pill:last-child.active::after { content: ''; position: absolute; top: 4px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 2px 7px rgba(0,0,0,0.18); }
.toggle-options .option-pill:first-child.active::after { right: 4px; }
.toggle-options .option-pill:last-child.active { background: rgba(28,25,21,0.16); }
.toggle-options .option-pill:last-child.active::after { left: 4px; }
.toggle-options .option-pill:not(.active) { width: 50%; z-index: 2; }
.toggle-options .option-pill:first-child:not(.active) { right: 0; left: auto; }
.toggle-options .option-pill:last-child:not(.active) { left: 0; right: auto; }

.configured-footer { padding: 24px 34px 30px; background: rgba(255,255,255,0.46); box-shadow: 0 -1px 0 var(--border); }
.footer-topline { display: flex; justify-content: space-between; gap: 18px; align-items: flex-end; margin-bottom: 20px; }
.price { margin-top: -10px; font-family: var(--mono); font-size: 36px; line-height: 1; letter-spacing: -0.06em; }
.build-summary { display: grid; gap: 7px; color: var(--muted); font-size: 13px; text-align: right; }
.footer-actions { display: grid; grid-template-columns: 1fr; gap: 14px; }
.share-btn { height: 62px; border: 0; border-radius: 15px; background: #1c1916; color: #fff; font-weight: 800; font-size: 17px; cursor: pointer; box-shadow: 0 12px 24px rgba(28,25,21,0.18); }
.footer-reset { width: 62px; height: 62px; border-radius: 16px; font-size: 29px; background: rgba(255,255,255,0.76); }

.visual-notes, .accuracy-status, .source-line, .trim-list { display: none; }

@media (max-width: 1120px) {
  .app { grid-template-columns: minmax(0, 1fr) 390px; }
  .studio { padding-left: 28px; padding-right: 28px; }
  .configurator { padding-right: 14px; }
  .config-header, .config-section, .configured-footer { padding-left: 24px; padding-right: 24px; }
}

@media (max-width: 860px) {
  html,
  body { height: 100%; overflow: hidden; }

  .app {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(260px, 42dvh) minmax(0, 1fr);
    height: 100dvh;
    min-height: 100dvh;
    overflow: hidden;
  }

  .studio {
    min-height: 0;
    height: 100%;
    padding: 10px 12px 8px;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    overflow: hidden;
  }

  .viewer {
    min-height: 0;
    padding: 0;
    align-items: center;
  }

  .car-stage {
    width: 100%;
    transform: none;
  }

  #challenger-3d {
    height: min(35dvh, 330px);
    min-height: 220px;
    border-radius: 22px;
  }

  .asset-credit { display: none; }

  .studio-actions {
    right: 14px;
    bottom: 74px;
    gap: 8px;
  }

  .round-action {
    width: 42px;
    height: 42px;
    font-size: 22px;
  }

  .round-action:disabled { display: none; }

  .studio-spec-strip { display: none; }

  .configurator {
    min-height: 0;
    height: 100%;
    padding: 0 8px 8px;
    align-items: stretch;
    overflow: hidden;
  }

  .config-card {
    height: 100%;
    max-height: none;
    border-radius: 24px 24px 20px 20px;
  }

  .config-header {
    padding-top: 20px;
    padding-bottom: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
  }

  .config-header h1 { font-size: 24px; }

  .config-kicker {
    margin-top: 0;
    font-size: 10px;
    gap: 8px;
    flex-shrink: 0;
  }

  .accent-pill { padding: 4px 10px; }

  .config-scroll {
    min-height: 0;
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .config-section { padding-top: 18px; padding-bottom: 18px; }
  .configured-footer { padding-top: 14px; padding-bottom: max(14px, env(safe-area-inset-bottom)); }
  .share-btn { height: 52px; }
}

@media (max-width: 520px) {
  .config-header, .config-section, .configured-footer { padding-left: 18px; padding-right: 18px; }
  .option-pill { padding-left: 12px; padding-right: 12px; font-size: 13px; }
  .segmented .option-pill { font-size: 12px; }
}
