:root {
  --ink: #1d1b26;
  --ink-2: #4a4658;
  --muted: #777287;
  --paper: #faf7f2;
  --card: #ffffff;
  --line: #e5e0d8;
  --accent: #7a1f3d;
  --accent-2: #9c2a50;
  --accent-soft: #f6e7ec;
  --gold: #d9a441;
  --stage: #2a2433;
  --focus: #3b5bdb;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 8px 24px rgba(30,20,40,.08);
  --ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --tap: 44px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--ui);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- Screens ---------- */
.screen { display: none; min-height: 100%; }
.screen.active { display: flex; flex-direction: column; }
#screen-editor.active { height: 100dvh; min-height: 0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 16px; border-radius: 10px;
  border: 1px solid transparent; background: transparent; cursor: pointer;
  font-weight: 600; font-size: 15px; text-decoration: none; color: var(--ink);
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-2); }
.btn-secondary { background: var(--card); border-color: var(--line); }
.btn-secondary:hover { border-color: var(--ink-2); }
.btn-ghost:hover { background: rgba(0,0,0,.05); }
.btn-icon { width: var(--tap); padding: 0; border-color: var(--line); background: var(--card); }
.btn-icon[aria-pressed="false"] { color: var(--muted); }
.btn-danger { color: #c92a2a; }
.btn-danger:hover { background: #fff0f0; }

/* ---------- Start ---------- */
.hero {
  background:
    radial-gradient(ellipse 60% 90% at 50% -10%, rgba(255,214,140,.35), transparent 60%),
    linear-gradient(180deg, #2b1b3d, #1c1328);
  color: #fff; text-align: center;
  padding: 48px 20px 56px;
}
.eyebrow { margin: 0 0 8px; letter-spacing: .14em; text-transform: uppercase; font-size: 12px; color: #e8cfa0; font-weight: 700; }
.hero h1 { font-family: "Playfair Display", Georgia, serif; font-weight: 900; font-size: clamp(32px, 6vw, 52px); margin: 0; line-height: 1.05; }
.hero-show { font-size: 18px; margin: 10px 0 0; color: #f3e6d2; }
.hero-show em { font-family: "Playfair Display", Georgia, serif; font-style: italic; color: #fff; }
.hero-sub { max-width: 560px; margin: 16px auto 0; color: #d9cfe4; line-height: 1.5; }

.start-body { width: 100%; max-width: 980px; margin: 28px auto 40px; padding: 0 16px; }
.resume {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--gold);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); margin-bottom: 20px;
}
.resume-actions { display: flex; gap: 8px; }
.step-title { display: flex; align-items: center; gap: 10px; font-size: 20px; margin: 28px 0 14px; }
.start-body > .step-title:first-of-type { margin-top: 0; }
.resume:not([hidden]) + .step-title { margin-top: 8px; }
.step-num {
  display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 14px; font-weight: 700;
}
.size-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.size-card {
  display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center;
  background: var(--card); border: 2px solid var(--line); border-radius: var(--radius);
  padding: 20px 16px 18px; cursor: pointer; box-shadow: var(--shadow);
  transition: border-color .15s, transform .15s;
}
.size-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.size-shape-box { height: 120px; display: grid; place-items: center; }
.size-shape {
  background: repeating-linear-gradient(45deg, var(--accent-soft) 0 8px, #fbf3f6 8px 16px);
  border: 2px solid var(--accent); border-radius: 4px;
}
.size-name { font-weight: 700; font-size: 18px; }
.size-dims { color: var(--muted); font-size: 14px; }
.size-price { font-weight: 800; font-size: 22px; color: var(--accent); }
.start-secondary { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-top: 28px; }
.due { color: var(--muted); font-size: 14px; margin: 0; text-align: center; }

/* ---------- Templates ---------- */
.subbar {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 12px;
  background: var(--paper); border-bottom: 1px solid var(--line); padding: 10px 16px;
}
.subbar h2 { display: flex; align-items: center; gap: 10px; font-size: 18px; margin: 0; flex: 1; }
.subbar-size { color: var(--muted); font-size: 14px; }
.btn-back { padding-left: 8px; }
.tpl-body { width: 100%; max-width: 1080px; margin: 0 auto; padding: 8px 16px 40px; }
.tpl-group { font-size: 13px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin: 24px 0 12px; }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.tpl-card {
  display: flex; flex-direction: column; gap: 10px; padding: 10px; cursor: pointer; text-align: left;
  background: var(--card); border: 2px solid var(--line); border-radius: var(--radius);
  transition: border-color .15s, transform .15s;
}
.tpl-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.tpl-thumb { display: grid; place-items: center; background: #f1ede6; border-radius: 8px; padding: 10px; aspect-ratio: 4 / 3; }
.tpl-thumb img { max-width: 100%; max-height: 100%; box-shadow: 0 2px 8px rgba(0,0,0,.18); }
.tpl-name { font-weight: 600; padding: 0 4px 2px; }
.tpl-hint { color: var(--muted); text-align: center; margin-top: 28px; }

/* ---------- Editor ---------- */
.topbar {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  background: var(--card); border-bottom: 1px solid var(--line); z-index: 3;
}
.topbar-title { flex: 1; display: flex; gap: 8px; align-items: baseline; min-width: 0; font-weight: 700; white-space: nowrap; overflow: hidden; }
.topbar-title .muted { font-weight: 400; font-size: 14px; }
.topbar-actions { display: flex; gap: 6px; align-items: center; }
.btn-icon-text { padding: 0 10px 0 6px; }

.editor {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: 88px 1fr 320px;
}
.tools {
  display: flex; flex-direction: column; gap: 4px; padding: 10px 8px;
  background: var(--card); border-right: 1px solid var(--line); overflow-y: auto;
}
.tool {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 4px; border: 0; border-radius: 10px; background: transparent; cursor: pointer;
  font-size: 12px; font-weight: 600; color: var(--ink-2);
}
.tool svg { width: 24px; height: 24px; }
.tool:hover { background: var(--accent-soft); color: var(--accent); }

.stage {
  position: relative; min-width: 0; min-height: 0; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background:
    radial-gradient(circle at 1px 1px, rgba(255,255,255,.07) 1px, transparent 0) 0 0 / 18px 18px,
    var(--stage);
  padding: 16px;
}
.canvas-wrap { position: relative; box-shadow: 0 10px 40px rgba(0,0,0,.45); background: #fff; }
.guides { position: absolute; inset: 0; pointer-events: none; }
.guides .safe { position: absolute; border: 1.5px dashed rgba(59, 91, 219, .7); }
.guides .snap-v, .guides .snap-h { position: absolute; background: #f06595; display: none; }
.guides .snap-v { top: 0; bottom: 0; width: 1px; left: 50%; }
.guides .snap-h { left: 0; right: 0; height: 1px; top: 50%; }
.guides.off .safe { display: none; }
.guides.show-v .snap-v, .guides.show-h .snap-h { display: block; }
.stage-hint { position: absolute; bottom: 8px; left: 0; right: 0; margin: 0; text-align: center; color: #c9c2d6; font-size: 13px; pointer-events: none; padding: 0 12px; }

.panel {
  background: var(--card); border-left: 1px solid var(--line);
  overflow-y: auto; padding: 16px;
}
.panel h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 10px; }
.panel-section { padding: 14px 0; border-bottom: 1px solid var(--line); }
.panel-section:first-child { padding-top: 0; }
.panel-section:last-child { border-bottom: 0; }
.panel label.lbl { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin: 10px 0 6px; }
.panel textarea, .panel select, .panel input[type="text"] {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 10px; background: #fff; font-size: 16px;
}
.panel textarea { min-height: 72px; resize: vertical; }
.panel-empty p { color: var(--ink-2); line-height: 1.5; margin: 0 0 8px; }
.row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.chip {
  min-height: 40px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-weight: 600; font-size: 14px;
}
.chip:hover { border-color: var(--ink-2); }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chip-danger { color: #c92a2a; }
.swatches { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.swatch {
  aspect-ratio: 1; border-radius: 50%; border: 1px solid rgba(0,0,0,.15); cursor: pointer; padding: 0;
  min-width: 26px;
}
.swatch.on { outline: 3px solid var(--accent); outline-offset: 2px; }
.swatch-picker { position: relative; overflow: hidden; background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red); }
.swatch-picker input { position: absolute; inset: -8px; opacity: 0; cursor: pointer; width: 200%; height: 200%; }
input[type="range"] { width: 100%; accent-color: var(--accent); height: 28px; }
.range-row { display: grid; grid-template-columns: 1fr 52px; gap: 8px; align-items: center; }
.range-row output { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--muted); text-align: right; }
.warn { background: #fff4e6; border: 1px solid #ffd8a8; color: #8a4b00; border-radius: 8px; padding: 10px; font-size: 13px; line-height: 1.4; margin-top: 10px; }
.font-select option { font-size: 18px; }

/* ---------- Modals ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px;
  background: rgba(20, 14, 28, .6);
}
.modal-card {
  width: 100%; max-width: 520px; max-height: calc(100dvh - 32px); overflow-y: auto;
  background: var(--card); border-radius: 16px; padding: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.modal-wide { max-width: 860px; }
.modal-narrow { max-width: 420px; }
.modal-card h2 { margin: 0 0 8px; font-size: 22px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.crop-area { height: min(60vh, 520px); background: #222; border-radius: 10px; overflow: hidden; margin: 12px 0; }
.crop-area img { display: block; max-width: 100%; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg-btn { min-height: 40px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-weight: 600; font-size: 14px; }
.seg-btn.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

.field { display: block; margin: 14px 0 0; border: 0; padding: 0; }
.field > span, .field legend { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.field input[type="text"], .field input[type="tel"], .field input[type="email"] {
  width: 100%; min-height: var(--tap); border: 1px solid var(--line); border-radius: 8px; padding: 0 12px; font-size: 16px;
}
.field small { display: block; color: var(--muted); margin-top: 6px; }
.field.invalid input { border-color: #e03131; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.yn label { display: inline-flex; align-items: center; gap: 6px; margin-right: 14px; min-height: var(--tap); }
.check { display: flex; gap: 10px; align-items: flex-start; margin-top: 16px; cursor: pointer; line-height: 1.4; }
.check input { width: 20px; height: 20px; margin-top: 1px; accent-color: var(--accent); }
.order-fields { border-left: 3px solid var(--accent-soft); padding-left: 12px; margin-top: 6px; }

.done-preview { background: #f1ede6; border-radius: 10px; padding: 12px; display: grid; place-items: center; margin: 12px 0 6px; }
.done-preview img { max-width: 100%; max-height: 240px; box-shadow: 0 2px 10px rgba(0,0,0,.2); }
.next-steps { padding-left: 20px; line-height: 1.55; }
.next-steps li { margin-bottom: 6px; }
.done-buttons { display: flex; flex-wrap: wrap; gap: 8px; }

.busy { color: #fff; text-align: center; }
.spinner { width: 42px; height: 42px; margin: 0 auto 12px; border-radius: 50%; border: 4px solid rgba(255,255,255,.25); border-top-color: #fff; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); z-index: 60;
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

#print-area { display: none; }

/* ---------- Phones and small tablets ---------- */
@media (max-width: 860px) {
  .editor { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto auto; }
  .stage { grid-row: 1; padding: 12px; }
  .panel {
    grid-row: 2; border-left: 0; border-top: 1px solid var(--line);
    max-height: 38dvh; padding: 12px 14px;
  }
  .panel-section { padding: 10px 0; }
  .tools {
    grid-row: 3; flex-direction: row; justify-content: space-around; border-right: 0; border-top: 1px solid var(--line);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); overflow-x: auto; overflow-y: hidden;
  }
  .tool { flex: 1; min-width: 60px; padding: 8px 2px; font-size: 11px; }
  .tool svg { width: 22px; height: 22px; }
  .hide-sm { display: none; }
  .topbar { padding: 6px 8px; gap: 6px; }
  .topbar-title { flex-direction: column; gap: 0; font-size: 14px; }
  .topbar-title .muted { font-size: 12px; }
  .stage-hint { display: none; }
  .toast { bottom: calc(96px + env(safe-area-inset-bottom)); }
  .field-row { grid-template-columns: 1fr; }
  .modal { padding: 10px; }
  .modal-card { padding: 18px; }
}
@media (max-width: 420px) {
  #btn-download span { display: none; }
  #btn-download { width: var(--tap); padding: 0; }
  .swatches { grid-template-columns: repeat(7, 1fr); }
}

/* ---------- Printable order form ---------- */
@media print {
  body > *:not(#print-area) { display: none !important; }
  html, body { background: #fff !important; }
  #print-area { display: block !important; color: #000; font-family: Arial, sans-serif; }
  @page { margin: 0.6in; }
}
.slip h1 { font-size: 22px; margin: 0 0 4px; }
.slip h2 { font-size: 16px; margin: 0 0 16px; font-weight: 400; }
.slip table { width: 100%; border-collapse: collapse; margin: 10px 0 18px; }
.slip td { border: 1px solid #999; padding: 8px 10px; font-size: 14px; vertical-align: top; }
.slip td:first-child { width: 34%; font-weight: 700; background: #f3f3f3; }
.slip .thumb { max-width: 3.5in; max-height: 2.5in; border: 1px solid #ccc; }
.slip .cols { display: flex; gap: 24px; }
.slip .cols > div { flex: 1; font-size: 14px; line-height: 1.5; }
.slip .cut { border-top: 2px dashed #888; margin: 18px 0 6px; padding-top: 4px; font-size: 11px; color: #555; }
