:root {
  --ink: #161321;
  --muted: #605b70;
  --paper: #f6f4fb;
  --panel: #ffffff;
  --line: rgba(38, 31, 58, 0.13);
  --purple: #713df2;
  --purple-deep: #4d22b8;
  --blue: #1677f2;
  --soft-blue: #eef5ff;
  --good: #0f7a55;
  --danger: #b42318;
  --shadow: 0 20px 50px rgba(35, 25, 74, 0.13);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 0%, rgba(113, 61, 242, 0.13), transparent 30rem),
    radial-gradient(circle at 82% 8%, rgba(22, 119, 242, 0.12), transparent 32rem),
    var(--paper);
}

button, input, select, textarea { font: inherit; }
button, input, select, textarea, a { outline-offset: 4px; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 3px solid rgba(22, 119, 242, 0.34);
}

.studio-topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 72px;
  padding: 0.6rem clamp(1rem, 3vw, 2rem);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--ink);
  text-decoration: none;
  font-weight: 900;
}

.brand img {
  width: 46px;
  height: 46px;
  object-fit: contain;
}

.studio-topbar nav {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.studio-topbar nav a {
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 800;
}

.studio-topbar nav a:hover { background: rgba(113, 61, 242, 0.08); color: var(--purple-deep); }

.designer-app {
  display: grid;
  grid-template-columns: 86px minmax(290px, 360px) minmax(460px, 1fr) minmax(250px, 320px);
  gap: 0;
  height: calc(100vh - 72px - 86px);
  min-height: 660px;
}

.tool-rail,
.side-panel,
.canvas-area,
.summary-panel {
  min-width: 0;
  border-right: 1px solid var(--line);
}

.tool-rail {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1rem 0.55rem;
  background: #fff;
}

.tool-button {
  display: grid;
  justify-items: center;
  gap: 0.35rem;
  width: 100%;
  min-height: 72px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
  cursor: pointer;
}

.tool-button span {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: #f0eef9;
  color: var(--purple-deep);
  font-weight: 950;
}

.tool-button.active,
.tool-button:hover {
  border-color: rgba(113, 61, 242, 0.24);
  background: linear-gradient(180deg, rgba(113, 61, 242, 0.1), rgba(22, 119, 242, 0.06));
  color: var(--ink);
}

.side-panel,
.summary-panel {
  padding: 1rem;
  background: rgba(255, 255, 255, 0.94);
}

.panel-head {
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 0.35rem;
  color: var(--purple-deep);
  font-size: 0.74rem;
  font-weight: 950;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1, h2 {
  margin: 0;
  letter-spacing: 0;
  line-height: 1.08;
}

h1 { font-size: clamp(1.8rem, 2.4vw, 2.35rem); }
h2 { font-size: 1rem; }

.panel-head p,
.note {
  color: var(--muted);
  line-height: 1.5;
}

.panel-section {
  display: none;
  padding-top: 1rem;
}

.panel-section.active { display: block; }

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.65rem;
}

.section-title span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 850;
}

.product-list {
  display: grid;
  gap: 0.65rem;
  max-height: min(38vh, 420px);
  overflow: auto;
  padding-right: 0.25rem;
}

.product-card {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr);
  gap: 0.75rem;
  width: 100%;
  min-height: 94px;
  padding: 0.65rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  text-align: left;
  cursor: pointer;
}

.product-card[aria-pressed="true"] {
  border-color: rgba(113, 61, 242, 0.58);
  box-shadow: 0 14px 26px rgba(113, 61, 242, 0.12);
}

.product-card img {
  width: 78px;
  height: 78px;
  border-radius: 8px;
  object-fit: cover;
  background: #f6f4fb;
}

.product-card strong {
  display: block;
  margin-top: 0.1rem;
}

.product-card span,
.product-card small {
  display: block;
  color: var(--muted);
  line-height: 1.35;
}

.color-block { margin-top: 1rem; }

.color-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.color-swatch {
  width: 36px;
  height: 36px;
  border: 2px solid #fff;
  border-radius: 999px;
  background: var(--swatch);
  box-shadow: 0 0 0 1px rgba(38, 31, 58, 0.24);
  cursor: pointer;
}

.color-swatch[aria-checked="true"] {
  box-shadow: 0 0 0 3px rgba(113, 61, 242, 0.42);
}

label {
  display: grid;
  gap: 0.4rem;
  margin: 0.8rem 0;
  font-weight: 850;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0.75rem 0.8rem;
}

textarea { resize: vertical; min-height: 130px; }

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.canvas-area {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(244, 247, 255, 0.86)),
    #eef2fb;
}

.canvas-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.8);
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.view-toggle {
  display: inline-flex;
  padding: 0.25rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.view-toggle button {
  min-width: 82px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  padding: 0.55rem 0.8rem;
  color: var(--muted);
  font-weight: 900;
  cursor: pointer;
}

.view-toggle button.active {
  background: linear-gradient(135deg, var(--purple), var(--blue));
  color: #fff;
}

.canvas-status {
  min-width: 0;
  color: var(--muted);
  font-weight: 800;
}

.canvas-shell {
  display: grid;
  place-items: center;
  min-height: 0;
  padding: clamp(0.75rem, 2vw, 1.4rem);
}

#designCanvas {
  width: min(100%, 78vh, 900px);
  max-height: calc(100vh - 230px);
  aspect-ratio: 1;
  border: 1px solid rgba(38, 31, 58, 0.12);
  border-radius: 8px;
  background: #f8f8fb;
  box-shadow: var(--shadow);
}

.primary-action,
.secondary-action {
  min-height: 44px;
  border-radius: 8px;
  padding: 0.7rem 1rem;
  font-weight: 950;
  cursor: pointer;
}

.primary-action {
  border: 0;
  color: #fff;
  background: linear-gradient(135deg, var(--purple), var(--blue));
  box-shadow: 0 16px 32px rgba(77, 34, 184, 0.2);
}

.secondary-action {
  border: 1px solid rgba(113, 61, 242, 0.24);
  color: var(--purple-deep);
  background: rgba(113, 61, 242, 0.08);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  box-shadow: none;
}

.summary-panel {
  border-right: 0;
}

.mini-preview {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8f8fb;
  overflow: hidden;
}

#miniCanvas {
  display: block;
  width: 100%;
  aspect-ratio: 1;
}

dl { margin: 1rem 0; }
dl div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--line);
}
dt { color: var(--muted); font-weight: 800; }
dd { margin: 0; font-weight: 950; text-align: right; }

.progress-checkout {
  position: sticky;
  bottom: 0;
  z-index: 18;
  display: grid;
  grid-template-columns: minmax(360px, 0.9fr) minmax(520px, 1.1fr);
  gap: 1rem;
  align-items: center;
  padding: 0.75rem clamp(1rem, 3vw, 2rem);
  border-top: 1px solid var(--line);
  background: #fff;
  box-shadow: 0 -16px 34px rgba(35, 25, 74, 0.08);
}

.stepper {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.55rem;
  max-width: 560px;
}

.step {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-weight: 950;
}

.step.active {
  border-color: rgba(113, 61, 242, 0.5);
  color: var(--purple-deep);
  background: rgba(113, 61, 242, 0.08);
}

.checkout-form {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 110px 170px;
  grid-template-rows: auto auto;
  gap: 0.35rem 0.75rem;
  align-items: end;
}

.checkout-form label { margin: 0; }

.checkout-form label[for="variantSelect"] {
  grid-column: 1;
  grid-row: 1;
}

#variantSelect {
  grid-column: 1;
  grid-row: 2;
}

.checkout-form label[for="quantityInput"] {
  grid-column: 2;
  grid-row: 1;
}

#quantityInput {
  grid-column: 2;
  grid-row: 2;
}

#checkoutButton {
  grid-column: 3;
  grid-row: 1 / 3;
  align-self: stretch;
}

#checkoutMessage {
  grid-column: 1 / -1;
  margin: 0;
}

@media (max-width: 1240px) {
  .designer-app {
    grid-template-columns: 76px minmax(260px, 330px) minmax(420px, 1fr);
  }

  .summary-panel {
    grid-column: 2 / -1;
    display: grid;
    grid-template-columns: 180px minmax(0, 1fr) 260px;
    gap: 1rem;
    border-top: 1px solid var(--line);
  }

  .summary-panel dl {
    margin: 0;
  }
}

@media (max-width: 900px) {
  .studio-topbar { position: static; align-items: flex-start; flex-direction: column; }
  .designer-app {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 0;
  }
  .tool-rail {
    position: sticky;
    top: 0;
    z-index: 12;
    display: grid;
    grid-template-columns: repeat(5, minmax(62px, 1fr));
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 0.6rem;
    overflow-x: auto;
  }
  .tool-button { min-height: 62px; }
  .side-panel, .canvas-area, .summary-panel { border-right: 0; }
  .canvas-area { order: 2; }
  .side-panel { order: 3; }
  .summary-panel { order: 4; }
  .product-list { max-height: none; }
  .canvas-area { min-height: 640px; }
  #designCanvas { width: min(100%, 620px); max-height: none; }
  .summary-panel {
    grid-column: auto;
    grid-template-columns: 120px minmax(0, 1fr);
  }
  .summary-panel .note { grid-column: 1 / -1; }
  .progress-checkout { grid-template-columns: 1fr; }
  .progress-checkout {
    max-width: 100vw;
    overflow: hidden;
  }
  .checkout-form {
    grid-template-columns: 1fr;
    grid-template-rows: none;
  }
  .checkout-form label[for="variantSelect"],
  #variantSelect,
  .checkout-form label[for="quantityInput"],
  #quantityInput,
  #checkoutButton {
    grid-column: 1;
    grid-row: auto;
  }
}

@media (max-width: 560px) {
  .brand span { font-size: 0.95rem; }
  .studio-topbar nav a { padding: 0.45rem 0.55rem; }
  .tool-button { font-size: 0.68rem; }
  .product-card { grid-template-columns: 72px minmax(0, 1fr); }
  .product-card img { width: 72px; height: 72px; }
  .canvas-toolbar,
  .toolbar-actions {
    align-items: stretch;
    flex-direction: column;
  }
  .view-toggle { width: 100%; }
  .view-toggle button { flex: 1; }
  .stepper { grid-template-columns: 1fr; }
  .summary-panel { grid-template-columns: 1fr; }
  .mini-preview { max-width: 180px; }
}
  .canvas-shell {
    overflow: hidden;
    padding: 0.75rem;
  }
  #designCanvas {
    width: min(100%, calc(100vw - 1.5rem));
  }
  #checkoutMessage {
    overflow-wrap: anywhere;
    max-width: calc(100vw - 2rem);
  }
