:root {
  --white: #ffffff;
  --page: #fbfbfb;
  --ink: #171719;
  --muted: #747478;
  --line: #e4e4e6;
  --navy: #293146;
  --font: Arial, "Helvetica Neue", Helvetica, sans-serif;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(17, 17, 19, 0.045);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font);
}

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

.mobile-tabs { display: none; }

button:focus-visible,
input:focus-visible + .toggle {
  outline: 2px solid #43506e;
  outline-offset: 3px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: 74px 1fr;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(300px, 360px) 1fr minmax(270px, 320px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  position: relative;
  z-index: 20;
}

.brand,
.header-price {
  display: flex;
  align-items: center;
}

.brand {
  padding: 0 28px;
  color: var(--ink);
  text-decoration: none;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.025em;
}

.topbar-center {
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
}

.header-price {
  justify-content: space-between;
  padding: 0 26px;
}

.header-price span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
}

.header-price strong {
  font-size: 21px;
  letter-spacing: -0.04em;
}

.configurator {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(310px, 360px) minmax(500px, 1fr) minmax(285px, 320px);
  grid-template-areas: "controls stage summary";
}

.controls-panel,
.summary-panel {
  min-width: 0;
  background: var(--white);
  position: relative;
  z-index: 5;
}

.controls-panel {
  grid-area: controls;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}

.control-section { padding: 28px; }
.color-section { border-bottom: 1px solid var(--line); }
.detail-section { padding-bottom: 20px; }

.section-title {
  display: flex;
  align-items: baseline;
  gap: 5px;
  margin-bottom: 24px;
}

.section-title > span,
.section-title h1,
.section-title h2 {
  margin: 0;
  font-size: 15px;
  line-height: 1.2;
  font-weight: 700;
}

.color-grid {
  display: grid;
  grid-template-columns: repeat(2, 102px);
  gap: 18px;
}

.color-choice {
  border: 0;
  background: transparent;
  padding: 0;
  display: grid;
  gap: 10px;
  text-align: center;
  cursor: pointer;
  text-transform: uppercase;
  font-size: 10px;
  font-weight: 500;
}

.swatch {
  width: 102px;
  height: 94px;
  display: grid;
  place-items: center;
  border: 3px solid var(--white);
  border-radius: 10px;
  outline: 1px solid transparent;
  outline-offset: 2px;
  position: relative;
  overflow: hidden;
}

.swatch::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(125deg, transparent 28%, rgba(255,255,255,.12), transparent 70%);
}

.swatch-navy { background: #293146; }
.swatch-black { background: #171719; }
.color-choice.is-selected .swatch { outline-color: var(--ink); }

.checkmark {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--white);
  box-shadow: 0 2px 10px rgba(0,0,0,.08);
  position: relative;
  z-index: 1;
  opacity: 0;
}

.checkmark::after {
  content: "";
  position: absolute;
  left: 7px;
  top: 6px;
  width: 7px;
  height: 4px;
  border-left: 1.5px solid var(--ink);
  border-bottom: 1.5px solid var(--ink);
  transform: rotate(-45deg);
}

.color-choice.is-selected .checkmark { opacity: 1; }

.option-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  background: var(--white);
}

.option-row {
  min-height: 86px;
  padding: 10px 16px 10px 11px;
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: 68px 1fr 38px;
  align-items: center;
  gap: 11px;
  cursor: pointer;
  transition: background 160ms ease;
}

.option-row:last-child { border-bottom: 0; }
.option-row:hover { background: #fafafa; }
.option-preview { width: 68px; height: 60px; }
.option-copy { display: grid; gap: 5px; }
.option-copy strong { font-size: 12px; font-weight: 600; }
.option-copy small { color: var(--muted); font-size: 9px; line-height: 1.35; }

.option-row input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle {
  width: 38px;
  height: 22px;
  border: 1px solid #c8c8cc;
  border-radius: 20px;
  background: var(--white);
  position: relative;
  transition: background 160ms ease, border-color 160ms ease;
}

.toggle::after {
  content: "";
  position: absolute;
  left: 2px;
  top: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #8b8b90;
  transition: transform 160ms ease, background 160ms ease;
}

.option-row input:checked + .toggle {
  background: var(--ink);
  border-color: var(--ink);
}

.option-row input:checked + .toggle::after {
  transform: translateX(16px);
  background: var(--white);
}

.reset-button {
  width: 230px;
  min-height: 49px;
  margin: auto auto 28px;
  border: 0;
  border-radius: 8px;
  color: var(--white);
  background: var(--ink);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

.reset-button:hover { background: #303034; }

.product-stage {
  grid-area: stage;
  min-width: 0;
  min-height: 650px;
  background: var(--white);
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
}

.canvas-viewport {
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
}

.canvas-viewport:active { cursor: grabbing; }

.canvas-transform {
  width: min(98%, 760px);
  aspect-ratio: 1;
  transform-origin: center;
  will-change: transform;
  transition: transform 180ms ease;
}

.canvas-transform.is-dragging { transition: none; }
#product-canvas { display: block; width: 100%; height: 100%; }

.loading-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  background: var(--white);
  z-index: 4;
  transition: opacity 200ms ease, visibility 200ms ease;
}

.loading-state.is-hidden { opacity: 0; visibility: hidden; }
.loading-state > span { width: 52px; height: 2px; background: var(--line); overflow: hidden; position: relative; }
.loading-state > span::after { content: ""; position: absolute; inset: 0; width: 50%; background: var(--ink); animation: load 900ms infinite ease-in-out; }
.loading-state p { margin: 0; font-size: 9px; font-weight: 600; }
@keyframes load { from { transform: translateX(-110%); } to { transform: translateX(210%); } }

.stage-toolbar {
  height: 48px;
  display: flex;
  margin: 0 auto 24px;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: var(--white);
  box-shadow: var(--shadow);
}

.stage-toolbar button,
.stage-toolbar > span {
  width: 48px;
  border: 0;
  border-right: 1px solid var(--line);
  background: var(--white);
  display: grid;
  place-items: center;
}

.stage-toolbar > span { width: 60px; font-size: 9px; font-weight: 600; }
.stage-toolbar button { cursor: pointer; }
.stage-toolbar button:hover { background: #fafafa; }
.stage-toolbar > :last-child { border-right: 0; }
.stage-toolbar svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

.summary-panel {
  grid-area: summary;
  border-left: 1px solid var(--line);
  padding: 20px 17px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.summary-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--white);
  box-shadow: var(--shadow);
}

.summary-heading {
  min-height: 56px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.summary-heading h2 { margin: 0; font-size: 13px; font-weight: 600; }
.summary-heading span { color: var(--muted); font-size: 10px; font-weight: 600; }

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

.active-list li {
  min-height: 66px;
  padding: 8px 14px 8px 10px;
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: 48px 1fr auto;
  align-items: center;
  gap: 9px;
  font-size: 11px;
}

.active-list li:last-child { border-bottom: 0; }
.active-list li > span:last-child { color: var(--muted); font-size: 9px; }
.active-list .empty-state { display: flex; min-height: 78px; padding: 18px 16px; color: var(--muted); line-height: 1.5; }
.summary-preview { width: 48px; height: 46px; }

.color-summary { padding: 16px; }
.summary-label { display: block; margin-bottom: 15px; font-size: 9px; font-weight: 600; }
.selected-color { display: flex; align-items: center; gap: 12px; }
.selected-color-dot { width: 48px; height: 48px; border-radius: 50%; background: var(--navy); box-shadow: inset 0 0 0 1px rgba(0,0,0,.06); }
.selected-color div { display: grid; gap: 5px; }
.selected-color strong { font-size: 12px; font-weight: 600; }
.selected-color small { color: var(--muted); font-size: 9px; }

.pricing-card { margin-top: auto; }
.price-row { min-height: 48px; padding: 0 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; font-size: 10px; }
.price-row strong { font-size: 10px; }
.price-total-row { min-height: 72px; padding: 0 16px; display: flex; align-items: center; justify-content: space-between; background: var(--ink); color: var(--white); font-size: 11px; font-weight: 600; }
.price-total-row strong { font-size: 24px; letter-spacing: -.04em; }
.prototype-note { margin: 0 4px; color: var(--muted); font-size: 9px; line-height: 1.5; text-align: center; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 18px); z-index: 100; padding: 11px 15px; border-radius: 8px; color: var(--white); background: var(--ink); font-size: 10px; opacity: 0; pointer-events: none; transition: opacity 180ms ease, transform 180ms ease; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

.price-pulse { animation: price-pulse 220ms ease-out; }
@keyframes price-pulse { 50% { opacity: .45; transform: translateY(-1px); } }

@media (max-width: 1120px) {
  .topbar { grid-template-columns: 320px 1fr 270px; }
  .configurator { grid-template-columns: 320px minmax(440px, 1fr); grid-template-areas: "controls stage" "summary summary"; }
  .summary-panel { border-left: 0; border-top: 1px solid var(--line); display: grid; grid-template-columns: 1fr .8fr 1fr; align-items: start; }
  .pricing-card { margin: 0; }
  .prototype-note { grid-column: 3; }
}

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

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

  .topbar { grid-template-columns: 1fr auto; position: relative; top: auto; }
  .brand { padding: 0 16px; font-size: 14px; }
  .topbar-center { display: none; }
  .header-price { padding: 0 16px; border-left: 1px solid var(--line); gap: 10px; }
  .header-price span { display: none; }
  .header-price strong { font-size: 18px; }

  .configurator {
    min-height: 0;
    overflow: hidden;
    grid-template-columns: 1fr;
    grid-template-rows: clamp(300px, 44dvh, 400px) 52px minmax(0, 1fr);
    grid-template-areas: "stage" "tabs" "panel";
  }

  .product-stage {
    min-height: 0;
    border-bottom: 1px solid var(--line);
    grid-template-rows: minmax(0, 1fr) 48px;
  }

  .canvas-transform {
    width: min(82vw, calc(44dvh - 56px));
    height: auto;
    max-width: 100%;
  }

  .stage-toolbar {
    height: 44px;
    margin: 0 auto 4px;
    box-shadow: none;
  }

  .stage-toolbar button,
  .stage-toolbar > span { width: 48px; min-height: 44px; }
  .stage-toolbar > span { width: 62px; }
  .stage-toolbar [data-action="fullscreen"] { display: none; }

  .mobile-tabs {
    grid-area: tabs;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    position: relative;
    z-index: 9;
    border-bottom: 1px solid var(--line);
    background: var(--white);
  }

  .mobile-tabs button {
    min-width: 0;
    min-height: 52px;
    padding: 0 8px;
    border: 0;
    border-right: 1px solid var(--line);
    background: var(--white);
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    position: relative;
  }

  .mobile-tabs button:last-child { border-right: 0; }
  .mobile-tabs button:focus-visible { outline-offset: -3px; }
  .mobile-tabs button[aria-selected="true"] { color: var(--ink); }
  .mobile-tabs button[aria-selected="true"]::after {
    content: "";
    position: absolute;
    left: 18px;
    right: 18px;
    bottom: -1px;
    height: 2px;
    background: var(--ink);
  }

  .mobile-tabs span {
    min-width: 18px;
    height: 18px;
    margin-left: 4px;
    padding: 0 5px;
    border-radius: 9px;
    display: inline-grid;
    place-items: center;
    background: var(--ink);
    color: var(--white);
    font-size: 9px;
  }

  .controls-panel,
  .summary-panel {
    grid-area: panel;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    border: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .controls-panel { border-right: 0; }
  .control-section { padding: 20px 18px 24px; }
  .section-title { margin-bottom: 18px; }
  .section-title > span { display: none; }
  .section-title h1,
  .section-title h2 { font-size: 14px; }

  .color-section { border-bottom: 0; }
  .color-grid { grid-template-columns: repeat(2, minmax(104px, 124px)); gap: 16px; }
  .swatch { width: 100%; height: 88px; }
  .color-choice { min-height: 118px; font-size: 10px; }

  .detail-section { padding-top: 14px; }
  .option-card { border-radius: 12px; box-shadow: none; }
  .option-row {
    min-height: 76px;
    grid-template-columns: 60px 1fr 44px;
    gap: 10px;
    padding: 7px 14px 7px 8px;
  }
  .option-preview { width: 60px; height: 54px; }
  .option-copy strong { font-size: 12px; }
  .option-copy small { font-size: 9px; }
  .toggle { width: 44px; height: 26px; }
  .toggle::after { width: 20px; height: 20px; }
  .option-row input:checked + .toggle::after { transform: translateX(18px); }
  .reset-button { display: none; }

  .summary-panel {
    display: flex;
    padding: 16px 18px calc(18px + env(safe-area-inset-bottom));
    gap: 12px;
  }
  .summary-card { width: 100%; border-radius: 12px; box-shadow: none; flex: 0 0 auto; }
  .summary-heading { min-height: 48px; }
  .active-list li { min-height: 60px; }
  .active-list .empty-state { min-height: 62px; }
  .color-summary { padding: 14px 16px; }
  .selected-color-dot { width: 42px; height: 42px; }
  .pricing-card { margin-top: 0; }
  .price-total-row { min-height: 64px; }
  .prototype-note { margin: 0 4px; }
  body[data-mobile-panel="color"] .detail-section,
  body[data-mobile-panel="overview"] .controls-panel { display: none; }
  body[data-mobile-panel="details"] .color-section,
  body[data-mobile-panel="overview"] .controls-panel { display: none; }
  body:not([data-mobile-panel="overview"]) .summary-panel { display: none; }

  .toast { bottom: calc(20px + env(safe-area-inset-bottom)); }
}

@media (max-width: 760px) and (max-height: 700px) and (orientation: portrait) {
  .app-shell { grid-template-rows: 52px minmax(0, 1fr); }
  .configurator { grid-template-rows: clamp(250px, 42dvh, 300px) 48px minmax(0, 1fr); }
  .brand { font-size: 12px; }
  .header-price strong { font-size: 16px; }
  .mobile-tabs button { min-height: 48px; }
  .stage-toolbar { height: 40px; }
  .stage-toolbar button,
  .stage-toolbar > span { min-height: 40px; }
  .option-row { min-height: 68px; }
}

@media (max-width: 900px) and (orientation: landscape) and (max-height: 520px) {
  html,
  body { height: 100%; overflow: hidden; }
  .app-shell { height: 100dvh; min-height: 0; grid-template-rows: 48px minmax(0, 1fr); }
  .topbar { grid-template-columns: 1fr auto; }
  .brand { padding: 0 16px; font-size: 12px; }
  .topbar-center,
  .header-price span { display: none; }
  .header-price { padding: 0 16px; border-left: 1px solid var(--line); }
  .header-price strong { font-size: 16px; }
  .configurator {
    min-height: 0;
    grid-template-columns: 52% 48%;
    grid-template-rows: 48px minmax(0, 1fr);
    grid-template-areas: "stage tabs" "stage panel";
    overflow: hidden;
  }
  .product-stage { min-height: 0; border-right: 1px solid var(--line); grid-template-rows: minmax(0, 1fr) 44px; }
  .canvas-transform { width: min(47vw, calc(100dvh - 96px)); height: auto; max-width: 100%; }
  .stage-toolbar { height: 40px; margin: 0 auto 4px; }
  .stage-toolbar button,
  .stage-toolbar > span { min-height: 40px; }
  .stage-toolbar [data-action="fullscreen"] { display: none; }
  .mobile-tabs { grid-area: tabs; display: grid; grid-template-columns: repeat(3, 1fr); border-bottom: 1px solid var(--line); }
  .mobile-tabs button { min-height: 48px; border: 0; border-right: 1px solid var(--line); background: var(--white); font-size: 10px; }
  .mobile-tabs span { margin-left: 3px; }
  .controls-panel,
  .summary-panel { grid-area: panel; min-height: 0; overflow-y: auto; border: 0; }
  .control-section { padding: 14px 16px; }
  .section-title { margin-bottom: 12px; }
  .section-title > span { display: none; }
  .color-grid { grid-template-columns: repeat(2, 104px); }
  .swatch { width: 104px; height: 76px; }
  .option-row { min-height: 65px; }
  .reset-button { display: none; }
  .summary-panel { display: flex; padding: 12px 14px; }
  .pricing-card { margin-top: 0; }
  body[data-mobile-panel="color"] .detail-section,
  body[data-mobile-panel="details"] .color-section,
  body[data-mobile-panel="overview"] .controls-panel { display: none; }
  body:not([data-mobile-panel="overview"]) .summary-panel { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
