:root {
  --bg: #f4f2ef;
  --surface: #ffffff;
  --ink: #1b1a19;
  --ink-2: #57534e;
  --ink-3: #8a847d;
  --line: #e4e0da;
  --accent: #8b1d1d;
  --accent-ink: #ffffff;
  --accent-soft: #f6e9e7;
  --stage-a: #fbfaf8;
  --stage-b: #ebe7e1;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }

/* ---------- Top bar ---------- */
.topbar {
  height: 60px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: .01em; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--ink); color: #fff; font-weight: 800; font-size: 17px;
}
.brand-text em { font-style: normal; color: var(--ink-3); font-weight: 500; margin-left: 4px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.proto-badge {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em;
  color: var(--accent); background: var(--accent-soft);
  padding: 4px 8px; border-radius: 999px;
}

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid transparent; border-radius: 10px;
  padding: 10px 16px; font-weight: 600; font-size: 14px;
  cursor: pointer; transition: background .15s, border-color .15s, opacity .15s;
  white-space: nowrap;
}
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #761616; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { background: #f1eeea; }
.btn[disabled] { opacity: .45; cursor: default; }
.btn:focus-visible, .chip:focus-visible, .swatch:focus-visible, .card:focus-visible, .steps button:focus-visible, .seg button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 440px;
  min-height: calc(100vh - 60px);
}

/* ---------- Stage / preview ---------- */
.stage {
  background: radial-gradient(120% 90% at 50% 35%, var(--stage-a) 0%, var(--stage-b) 100%);
  position: sticky; top: 60px;
  height: calc(100vh - 60px);
  display: flex;
}
.stage-inner { flex: 1; display: flex; flex-direction: column; padding: 20px 28px 16px; min-width: 0; }
.preview { position: relative; flex: 1; min-height: 0; overflow: hidden; }
.preview-layers { position: absolute; inset: 0; }
.preview-layers .frame { position: absolute; inset: 0; transition: opacity .28s ease; }
.preview-layers img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain;
  /* the renders are 1920×1080 with generous margins – zoom in a bit */
  transform: scale(1.35); transform-origin: 50% 52%;
  user-select: none; -webkit-user-drag: none;
}
.preview-loading {
  position: absolute; right: 8px; top: 8px; opacity: 0; transition: opacity .2s;
  pointer-events: none;
}
.preview-loading.on { opacity: 1; }
.preview-loading span {
  display: block; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid rgba(0,0,0,.15); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.stage-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 8px; flex-wrap: wrap; }
.seg { display: inline-flex; background: rgba(255,255,255,.7); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button {
  border: 0; background: transparent; padding: 7px 14px; border-radius: 8px;
  font-size: 13px; font-weight: 600; color: var(--ink-2); cursor: pointer;
}
.seg button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.stage-tools { display: flex; gap: 8px; }
.stage-tools .btn { background: rgba(255,255,255,.7); }
.color-note { margin: 10px 0 0; font-size: 12px; color: var(--ink-3); }

/* ---------- Panel ---------- */
.panel {
  background: var(--surface);
  border-left: 1px solid var(--line);
  display: flex; flex-direction: column;
  min-height: calc(100vh - 60px);
  min-width: 0;
}
.steps {
  display: flex; gap: 4px; overflow-x: auto; padding: 14px 16px 0;
  border-bottom: 1px solid var(--line);
  scrollbar-width: none;
}
.steps::-webkit-scrollbar { display: none; }
.steps button {
  flex: 0 0 auto; border: 0; background: transparent; cursor: pointer;
  padding: 8px 10px 12px; font-size: 13px; font-weight: 600; color: var(--ink-3);
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.steps button .n {
  display: inline-grid; place-items: center; width: 18px; height: 18px; margin-right: 6px;
  border-radius: 50%; font-size: 11px; background: #efebe6; color: var(--ink-2);
}
.steps button.done .n { background: var(--ink); color: #fff; }
.steps button[aria-current="step"] { color: var(--ink); border-bottom-color: var(--accent); }
.steps button[aria-current="step"] .n { background: var(--accent); color: #fff; }

.step-body { flex: 1; padding: 22px 24px 8px; overflow-y: auto; }
.step-title { font-size: 22px; font-weight: 700; margin: 0 0 4px; letter-spacing: -.01em; }
.step-sub { margin: 0 0 18px; color: var(--ink-2); font-size: 14px; line-height: 1.45; }
.step-nav {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 14px 24px; border-top: 1px solid var(--line); background: var(--surface);
  position: sticky; bottom: 0;
}
.step-nav .btn { min-width: 110px; }

.group-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); margin: 18px 0 10px; }
.group-label:first-of-type { margin-top: 0; }

/* option cards (Ausführung, Armlehnen) */
.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.card {
  border: 1.5px solid var(--line); border-radius: 12px; background: var(--surface);
  padding: 14px 10px 12px; text-align: center; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  transition: border-color .15s, box-shadow .15s;
}
.card img { width: 40px; height: 40px; object-fit: contain; }
.card strong { font-size: 14px; }
.card small { font-size: 12px; color: var(--ink-3); line-height: 1.3; }
.card:hover { border-color: #cfc8bf; }
.card[aria-checked="true"] { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* leather swatches */
.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 10px; }
.swatch {
  border: 0; background: none; padding: 0; cursor: pointer; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.swatch .chip-img {
  width: 52px; height: 52px; border-radius: 50%;
  background-size: cover; background-position: center;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.12);
  transition: transform .15s, box-shadow .15s;
}
.swatch:hover .chip-img { transform: scale(1.06); }
.swatch[aria-checked="true"] .chip-img { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); }
.swatch .lbl { font-size: 11.5px; line-height: 1.2; color: var(--ink-2); }
.swatch .code { display: block; color: var(--ink-3); font-size: 10.5px; }
.swatch[aria-checked="true"] .lbl { color: var(--ink); font-weight: 600; }

.selected-line {
  margin: 18px 0 0; padding: 10px 12px; border-radius: 10px; background: #f7f5f2;
  font-size: 13px; color: var(--ink-2);
}
.selected-line b { color: var(--ink); }

/* quilting patterns */
.patterns { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.pattern {
  border: 1.5px solid var(--line); border-radius: 12px; background: var(--surface); cursor: pointer;
  padding: 10px 6px 8px; display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 12px; font-weight: 600;
}
.pattern .pimg { width: 48px; height: 48px; border-radius: 8px; background: #f2efeb center/cover no-repeat; display: grid; place-items: center; color: var(--ink-3); font-size: 20px; }
.pattern[aria-checked="true"] { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* hints */
.hint {
  display: flex; gap: 10px; align-items: flex-start;
  margin: 0 0 16px; padding: 12px 14px; border-radius: 12px;
  background: #fff7e6; border: 1px solid #f3dfb2; font-size: 13px; line-height: 1.45; color: #6b4d12;
}
.hint .btn { margin-left: auto; flex-shrink: 0; background: #fff; }
.info {
  margin: 14px 0 0; padding: 10px 12px; border-radius: 10px; background: #f1f4f7; color: #3d4c5c; font-size: 13px; line-height: 1.45;
}

/* summary */
.summary { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.summary-row { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-top: 1px solid var(--line); font-size: 14px; }
.summary-row:first-child { border-top: 0; }
.summary-row .k { color: var(--ink-3); width: 120px; flex-shrink: 0; font-size: 13px; }
.summary-row .v { flex: 1; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.summary-row .dot { width: 18px; height: 18px; border-radius: 50%; background-size: cover; box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); flex-shrink: 0; }
.summary-row .edit { border: 0; background: none; color: var(--accent); font-size: 13px; font-weight: 600; cursor: pointer; }

/* form */
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 18px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.field input, .field textarea {
  font: inherit; font-size: 14px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
}
.field input:focus, .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field textarea { min-height: 80px; resize: vertical; }
.check { grid-column: 1 / -1; display: flex; gap: 8px; align-items: flex-start; font-size: 12.5px; color: var(--ink-2); line-height: 1.4; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.form-error { grid-column: 1 / -1; color: #a11; font-size: 13px; min-height: 1em; margin: 0; }

.success { text-align: center; padding: 30px 6px; }
.success .tick { width: 56px; height: 56px; border-radius: 50%; margin: 0 auto 14px; background: #e7f4ea; color: #1d7a37; display: grid; place-items: center; font-size: 28px; }
.success img { width: 100%; border-radius: 12px; background: var(--stage-a); margin-top: 16px; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  .topbar { padding: 0 16px; }
  .brand-text em { display: none; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .stage { position: sticky; top: 60px; height: 42vh; min-height: 260px; z-index: 10; border-bottom: 1px solid var(--line); }
  .stage-inner { padding: 8px 16px 8px; }
  .color-note { display: none; }
  .stage-bar { margin-top: 4px; }
  .stage-tools .btn { padding: 6px 10px; font-size: 12px; }
  .panel { border-left: 0; min-height: 0; }
  .steps { padding: 10px 12px 0; }
  .step-body { padding: 18px 16px 8px; overflow: visible; }
  .step-nav { padding: 12px 16px; }
  .cards { gap: 8px; }
  .card { padding: 12px 6px 10px; }
  .patterns { grid-template-columns: repeat(4, 1fr); gap: 8px; }
  .form { grid-template-columns: 1fr; }
  .summary-row .k { width: 96px; }
}
@media (max-width: 420px) {
  .stage-tools #btn-share { display: none; }
}
