:root {
  --bg: #f6f1e7;
  --surface: #fffcf6;
  --sunk: #efe7d8;
  --ink: #1e1a15;
  --ink-2: #3b342b;
  --muted: #6f665a;
  --line: #e3d9c7;
  --line-strong: #cfc2ab;
  --red: #c9141b;
  --red-ink: #a80f15;
  --red-tint: #fbe9e4;
  --yellow: #f5c518;
  --ok: #1f7a45;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 0 rgba(30, 26, 21, .04), 0 8px 24px -12px rgba(30, 26, 21, .18);
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
img { max-width: 100%; display: block; }
a { color: inherit; }
button, input, textarea, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; letter-spacing: -0.02em; line-height: 1.1; }
p { margin: 0; }
[hidden] { display: none !important; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }

.wrap { width: 100%; max-width: 1080px; margin: 0 auto; padding: 0 20px; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: rgba(246, 241, 231, .9);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner { display: flex; align-items: center; gap: 24px; height: 64px; }
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  font-weight: 800; font-size: 19px; letter-spacing: -0.03em; text-decoration: none;
}
.brand-mark {
  width: 28px; height: 28px; border-radius: 6px; background: var(--red);
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .18);
  flex: none;
}
.brand-mark i {
  border-radius: 50%; background: #dd2a2f;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .35), 0 1px 1px rgba(0, 0, 0, .3);
}
.topbar-link { margin-left: auto; font-size: 14px; color: var(--muted); text-decoration: none; }
.topbar-link:hover { color: var(--ink); }

.steps {
  list-style: none; margin: 0 0 0 auto; padding: 0;
  display: flex; align-items: center; gap: 6px;
  font-size: 14px; color: var(--muted);
}
.steps li { display: flex; align-items: center; gap: 8px; }
.steps li + li::before {
  content: ""; width: 22px; height: 2px; border-radius: 2px; background: var(--line-strong); margin-right: 2px;
}
.steps .dot {
  width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700;
  background: var(--sunk); color: var(--muted);
  box-shadow: inset 0 -1.5px 0 rgba(0, 0, 0, .08);
}
.steps li.is-current { color: var(--ink); font-weight: 650; }
.steps li.is-current .dot { background: var(--red); color: #fff; box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .2); }
.steps li.is-done .dot { background: var(--ink); color: var(--bg); }
.steps li.is-done + li::before, .steps li.is-current::before { background: var(--ink); }

/* ---------- Layout ---------- */
main.wrap { padding-top: 40px; padding-bottom: 80px; }
.view { animation: rise .28s ease-out both; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.view-head { margin-bottom: 24px; display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 8px 24px; }
.view-head h2 { font-size: clamp(26px, 3.4vw, 34px); font-weight: 800; }
.view-head p { color: var(--muted); }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}

.eyebrow {
  font-size: 13px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--red);
}

/* ---------- Buttons ---------- */
.btn {
  appearance: none; border: 1px solid transparent; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px; border-radius: 12px;
  font-weight: 650; font-size: 16px; text-decoration: none; white-space: nowrap;
  transition: background-color .15s, transform .08s, box-shadow .15s;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .drop:focus-within, canvas:focus-visible, .lp-chip:focus-visible, .lp-grid:focus-visible, .size-card:focus-visible {
  outline: 3px solid rgba(201, 20, 27, .35); outline-offset: 2px;
}
.btn.primary { background: var(--red); color: #fff; box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .2); }
.btn.primary:hover { background: var(--red-ink); }
.btn.dark { background: var(--ink); color: var(--bg); }
.btn.dark:hover { background: #000; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line-strong); }
.btn.ghost:hover { background: var(--sunk); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .55; cursor: progress; }
.btn.block { width: 100%; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 22px; }
.actions .btn.primary { flex: 1 1 200px; }

.err {
  margin-top: 14px; padding: 10px 14px; border-radius: var(--radius-sm);
  background: var(--red-tint); color: var(--red-ink); font-size: 14px; font-weight: 550;
  border: 1px solid #f3c9c0;
}

/* ---------- Upload ---------- */
.hero { display: grid; grid-template-columns: 1.05fr 1fr; gap: 40px; align-items: center; }
.hero h1 { font-size: clamp(36px, 5.6vw, 60px); font-weight: 850; letter-spacing: -0.035em; margin: 12px 0 16px; }
.hero h1 em { font-style: normal; color: var(--red); }
.lede { font-size: 18px; color: var(--ink-2); max-width: 34ch; }

.drop {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 320px; padding: 28px; text-align: center; cursor: pointer;
  border: 2px dashed var(--line-strong); border-radius: 20px;
  background:
    radial-gradient(circle, rgba(30, 26, 21, .055) 0 5px, transparent 5.5px) 0 0 / 24px 24px,
    var(--surface);
  transition: border-color .15s, background-color .15s;
}
.drop:hover { border-color: var(--ink-2); }
.drop.is-over { border-color: var(--red); background-color: var(--red-tint); }
.drop strong { font-size: 20px; letter-spacing: -0.01em; }
.drop .sub { color: var(--muted); font-size: 15px; }
.drop .sub u { color: var(--ink); text-decoration-color: var(--red); text-decoration-thickness: 2px; text-underline-offset: 3px; }
.drop-icon {
  width: 64px; height: 64px; border-radius: 12px; background: var(--red); margin-bottom: 10px;
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 9px;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .2), 0 10px 20px -10px rgba(201, 20, 27, .6);
  transform: rotate(-6deg);
}
.drop-icon i { border-radius: 50%; background: #dd2a2f; box-shadow: inset 0 2px 0 rgba(255, 255, 255, .3), 0 2px 2px rgba(0, 0, 0, .3); }
.drop.is-loading .drop-icon { animation: wobble .7s ease-in-out infinite alternate; }
@keyframes wobble { to { transform: rotate(6deg) scale(1.04); } }

.section-title { font-size: 14px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 56px 0 14px; }
.size-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.size-card {
  appearance: none; font: inherit; color: inherit; text-align: left; cursor: pointer; width: 100%;
  display: grid; grid-template-columns: 64px 1fr; gap: 16px; align-items: center; padding: 16px 18px;
  transition: border-color .15s, background-color .15s;
}
.size-card:hover { border-color: var(--ink-2); }
.size-card.is-on { border-color: var(--red); background: var(--red-tint); box-shadow: inset 0 0 0 1px var(--red), var(--shadow); }
.size-card-dia { display: grid; place-items: center; width: 64px; height: 64px; }
.size-card-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.size-card strong { font-size: 19px; font-weight: 800; letter-spacing: -0.02em; }
.size-card .spec { display: block; color: var(--muted); font-size: 14px; margin-top: 3px; line-height: 1.35; }
.size-card .price { font-size: 19px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
/* Baseplates x across, y down; the longer side is 64px. */
.plate-diagram {
  --x: 3; --y: 3; --u: calc(64px / max(var(--x), var(--y)));
  width: calc(var(--u) * var(--x)); height: calc(var(--u) * var(--y));
  display: grid; gap: 2px; padding: 3px;
  grid-template-columns: repeat(var(--x), 1fr); grid-template-rows: repeat(var(--y), 1fr);
  background: var(--ink); border-radius: 5px;
}
.plate-diagram i, .lp-grid i.on {
  border-radius: 2px;
  background: radial-gradient(circle, #4a433a 0 26%, transparent 30%) 0 0 / 25% 25%, #2a251f;
}
.fineprint { margin-top: 18px; color: var(--muted); font-size: 14px; }

/* ---------- Design (framing + live mosaic) ---------- */
body[data-route="design"] main.wrap { max-width: 1240px; }
.design {
  --ar: 1; --arn: 1; --pad: 22px; --maxh: min(58vh, 600px);
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-areas: "photo mosaic" "controls frame" "summary frame";
  gap: 22px 28px; align-items: start;
}
.design.is-wide { grid-template-areas: "photo photo" "mosaic mosaic" "controls frame" "summary frame"; }
.d-photo { grid-area: photo; min-width: 0; }
.d-mosaic { grid-area: mosaic; min-width: 0; }
.d-controls { grid-area: controls; min-width: 0; }
.d-summary { grid-area: summary; min-width: 0; }
.d-frame { grid-area: frame; min-width: 0; }
.pane-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 28px; margin-bottom: 8px; }
.pane-head .field-label { margin: 0; }
.pane-meta { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* The stage shows the photo around the frame (dimmed); the frame box sets the crop's size. */
.stage {
  position: relative; padding: var(--pad); border-radius: var(--radius);
  background: #221e19; box-shadow: var(--shadow); overflow: hidden;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; border-radius: inherit; }
.stage canvas.is-dragging { cursor: grabbing; }
.stage-frame { aspect-ratio: var(--ar); width: min(100%, calc(var(--maxh) * var(--arn))); margin-inline: auto; pointer-events: none; }
.crop-hint {
  position: absolute; left: 50%; bottom: calc(var(--pad) + 12px); transform: translateX(-50%);
  background: rgba(20, 17, 13, .66); color: #fff; font-size: 13px; font-weight: 550;
  padding: 6px 12px; border-radius: 99px; pointer-events: none; white-space: nowrap;
  transition: opacity .4s;
}
.stage.touched .crop-hint { opacity: 0; }
.stage-loading {
  position: absolute; inset: 0; z-index: 2; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  color: #fff; font-weight: 650; font-size: 15px; background: #221e19;
}
.toolbar { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.toolbar input[type=range] { min-width: 60px; }
.zoom-pct { min-width: 4.2em; text-align: right; font-weight: 700; font-size: 15px; }
.btn.sm { min-height: 40px; padding: 0 14px; font-size: 15px; border-radius: 10px; }
.toggles { display: flex; flex-wrap: wrap; gap: 4px 22px; }
.toggles .check { margin-top: 10px; font-size: 14.5px; }

.mosaic-box { position: relative; }
.mosaic-inner {
  position: relative; aspect-ratio: var(--ar); margin-inline: auto;
  width: min(calc(100% - 2 * var(--pad)), calc(var(--maxh) * var(--arn)));
  box-sizing: content-box; border: var(--pad) solid #141210; border-radius: 6px;
  background: #282828;
  box-shadow: 0 1px 0 rgba(0, 0, 0, .05), 0 22px 40px -22px rgba(30, 26, 21, .55);
}
.mosaic-inner canvas, .mosaic-inner img { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.mosaic-inner img { max-width: none; }

.render-status {
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
  font-size: 13px; font-weight: 650; padding: 3px 10px 3px 9px; border-radius: 99px;
  background: var(--sunk); color: var(--ink-2);
}
.render-status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #d49a00; }
.render-status.is-draft::before { animation: blink 1s ease-in-out infinite; }
.render-status.is-final { background: #e3f2e8; color: var(--ok); }
.render-status.is-final::before { background: currentColor; }
.render-status.is-error { background: var(--red-tint); color: var(--red-ink); }
.render-status.is-error::before { background: currentColor; }
@keyframes blink { 50% { opacity: .25; } }

.steppers { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 10px 14px; }
.stepper { display: grid; grid-template-columns: 40px 46px 40px; grid-template-rows: auto 40px; align-items: center; }
.stepper-lbl { grid-column: 1 / -1; font-size: 13px; font-weight: 650; color: var(--muted); margin-bottom: 4px; }
.stepper-val { text-align: center; font-size: 22px; font-weight: 800; letter-spacing: -0.02em; }
.stepper-x { font-size: 20px; color: var(--muted); padding-bottom: 7px; }
.icon-btn:disabled { opacity: .38; cursor: not-allowed; }
.icon-btn:disabled:hover { background: var(--surface); }
.note { margin-top: 14px; font-size: 14px; color: var(--muted); }
.palette-section.is-stale .color-list { opacity: .5; transition: opacity .2s; }

.field-label { display: block; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin-bottom: 10px; }
.zoom-row { display: flex; align-items: center; gap: 10px; }
.icon-btn {
  appearance: none; flex: none; width: 40px; height: 40px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--surface); font-size: 20px; font-weight: 600; line-height: 1;
  display: grid; place-items: center;
}
.icon-btn:hover { background: var(--sunk); }
input[type=range] { flex: 1; accent-color: var(--red); height: 40px; margin: 0; }
fieldset { border: 0; padding: 0; margin: 24px 0 0; min-width: 0; }
legend { padding: 0; }

/* Layout picker: preset chips + max x max baseplate grid (--lp-n set by app.js) */
.lp { margin-top: 18px; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 16px; align-items: start; }
.lp-side { min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.lp-presets { display: flex; flex-wrap: wrap; gap: 6px; }
.lp-chip {
  appearance: none; cursor: pointer; text-align: left; padding: 6px 10px; border-radius: 9px; white-space: nowrap;
  border: 1.5px solid var(--line-strong); background: var(--surface); font-size: 14px; line-height: 1.3;
  transition: border-color .15s, background-color .15s;
}
.lp-chip:hover { border-color: var(--ink-2); }
.lp-chip[aria-checked="true"] { border-color: var(--red); background: var(--red-tint); box-shadow: inset 0 0 0 1px var(--red); }
.lp-chip-name { font-weight: 750; }
.lp-chip-sub { color: var(--muted); font-variant-numeric: tabular-nums; }
.lp-hint { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin-bottom: 6px; }
.lp-grid {
  display: grid; grid-template-columns: repeat(var(--lp-n, 6), 18px); grid-auto-rows: 18px; gap: 2px; padding: 5px;
  background: var(--sunk); border: 1.5px solid var(--line-strong); border-radius: 9px;
  touch-action: none; user-select: none; -webkit-user-select: none; cursor: pointer; width: max-content;
}
.lp-grid i { border-radius: 3px; background: var(--surface); box-shadow: inset 0 0 0 1px var(--line-strong); }
.lp-grid i.on { box-shadow: 0 1px 0 rgba(0, 0, 0, .25); }
.lp-grid.is-pending i.on:not(.cur) { box-shadow: inset 0 0 0 2px var(--red); }
.lp-grid.is-pending i.cur:not(.on) { box-shadow: inset 0 0 0 1.5px var(--ink-2); }
.lp-readout { display: flex; flex-direction: column; gap: 2px; min-width: 0; min-height: 40px; }
.lp-title { font-weight: 800; font-size: 15px; font-variant-numeric: tabular-nums; }
.lp-line { font-size: 13.5px; color: var(--muted); }
.lp-cta { font-size: 12.5px; font-weight: 700; color: var(--red); }

.check { display: flex; align-items: center; gap: 10px; margin-top: 18px; font-size: 15px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--red); margin: 0; }

/* ---------- Spinner ---------- */
.spinner { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; width: 46px; height: 46px; }
.spinner i { border-radius: 50%; animation: pop 1s ease-in-out infinite; box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .2); }
.spinner i:nth-child(1) { background: var(--red); }
.spinner i:nth-child(2) { background: var(--yellow); animation-delay: .15s; }
.spinner i:nth-child(4) { background: #1e5aa8; animation-delay: .3s; }
.spinner i:nth-child(3) { background: #f2f3f2; animation-delay: .45s; }
@keyframes pop { 0%, 100% { transform: scale(.55); opacity: .6; } 45% { transform: scale(1); opacity: 1; } }

/* ---------- Mosaic frame, stats, colors ---------- */
.frame {
  position: relative; border-radius: 6px; overflow: hidden; background: #111;
  width: fit-content; max-width: 100%; margin-inline: auto;
  padding: 14px; box-shadow: 0 1px 0 rgba(0, 0, 0, .05), 0 22px 40px -22px rgba(30, 26, 21, .55);
}
.frame img, .frame canvas { display: block; width: auto; height: auto; max-width: 100%; max-height: 72vh; border-radius: 2px; background: #1b2a34; }
.frame-caption { margin-top: 12px; font-size: 14px; color: var(--muted); text-align: center; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; margin: 0; background: var(--line); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.stats > div { background: var(--surface); padding: 12px 14px; }
.stats dt { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.stats dd { margin: 2px 0 0; font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stats dd small { display: block; font-size: 13px; font-weight: 500; color: var(--muted); }
.price-row { display: flex; justify-content: space-between; align-items: baseline; margin-top: 20px; padding-top: 16px; border-top: 1px dashed var(--line-strong); }
.price-row span { color: var(--muted); font-weight: 600; }
.price-row strong { font-size: 30px; font-weight: 850; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.price-row .ship { font-size: 13px; color: var(--muted); }

.palette-section { margin-top: 44px; }
.palette-section h3 { font-size: 22px; font-weight: 800; }
.palette-section > p { margin-top: 4px; }
.color-list {
  list-style: none; padding: 0; margin: 18px 0 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px;
}
.color-list li {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px 10px 10px;
  position: relative; overflow: hidden;
}
.color-list .bar { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--ink); opacity: .14; }
.color-list .cname { font-weight: 650; font-size: 15px; line-height: 1.25; }
.color-list .cmeta { font-size: 12px; color: var(--muted); font-family: var(--mono); }
.color-list .ccount { font-weight: 750; font-variant-numeric: tabular-nums; }

.stud {
  --c: #999; width: 34px; height: 34px; border-radius: 7px; flex: none; position: relative;
  background: var(--c);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12), inset 0 -2px 0 rgba(0, 0, 0, .12);
}
.stud::after {
  content: ""; position: absolute; inset: 7px; border-radius: 50%;
  background: var(--c);
  box-shadow: 0 1.5px 1.5px rgba(0, 0, 0, .35), inset 0 1.5px 0 rgba(255, 255, 255, .35);
}
.stud.sm { width: 24px; height: 24px; border-radius: 5px; }
.stud.sm::after { inset: 5px; }
.stud.xs { width: 18px; height: 18px; border-radius: 4px; }
.stud.xs::after { inset: 4px; }

/* ---------- Frame picker ---------- */
.fr-head { display: flex; align-items: baseline; justify-content: space-between; gap: 6px 12px; flex-wrap: wrap; }
.fr-head .field-label { margin-bottom: 10px; }
.fr-meta { font-size: 13px; font-weight: 650; color: var(--ok); }
.fr-styles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.fr-style {
  appearance: none; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 5px;
  padding: 7px 4px 6px; border-radius: 10px; border: 1.5px solid var(--line-strong); background: var(--surface);
  font-size: 12.5px; font-weight: 650; line-height: 1.2; text-align: center; min-width: 0;
  transition: border-color .15s, background-color .15s;
}
.fr-style:hover { border-color: var(--ink-2); }
.fr-style[aria-checked="true"] { border-color: var(--red); background: var(--red-tint); box-shadow: inset 0 0 0 1px var(--red); }
.fr-style canvas { width: 100%; max-width: 64px; aspect-ratio: 1; height: auto; border-radius: 3px; background: #282828; display: block; }
.fr-style span { max-width: 100%; text-wrap: balance; }
.fr-sub { font-size: 13px; font-weight: 700; color: var(--muted); margin: 16px 0 6px; }
.fr-sub-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.fr-sub2 { font-size: 13px; font-weight: 650; margin: 12px 0 6px; }
.seg { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1.5px solid var(--line-strong); border-radius: 10px; overflow: hidden; background: var(--surface); }
.seg button {
  appearance: none; cursor: pointer; border: 0; background: transparent; padding: 7px 4px; min-height: 44px;
  font-size: 14px; font-weight: 700; line-height: 1.15; display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button small { font-size: 11.5px; font-weight: 550; color: var(--muted); }
.seg button:hover { background: var(--sunk); }
.seg button[aria-checked="true"] { background: var(--ink); color: var(--bg); }
.seg button[aria-checked="true"] small { color: rgba(246, 241, 231, .75); }
/* Pieces: shape x top. Four across; 2x2 (round row, square row) on phones. */
.pc-row { display: flex; align-items: center; gap: 8px 14px; flex-wrap: wrap; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.pc-row .field-label { margin: 0; }
.pc-seg { flex: 1 1 320px; max-width: 460px; }
.pc-seg button { gap: 5px; min-height: 58px; padding: 7px 4px; }
.pc-txt { display: flex; flex-direction: column; align-items: center; }
.pc-ico {
  --pc: #c9141b; flex: none; width: 18px; height: 18px; position: relative; display: block;
}
.pc-ico::before { content: ""; position: absolute; inset: 0; background: var(--pc); border-radius: 50%; box-shadow: inset 0 -1px 0 rgba(0, 0, 0, .25); }
.pc-ico.is-square::before { inset: 0; border-radius: 2.5px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .28); }
.pc-ico::after { content: ""; position: absolute; inset: 5px; border-radius: 50%; box-shadow: inset 1px 1px 0 rgba(255, 255, 255, .5), 0.5px 0.5px 1px rgba(0, 0, 0, .45); }
/* Smooth tile: no stud ring, just a soft gloss spot. */
.pc-ico.is-smooth::after { inset: 3px 8px 8px 3px; box-shadow: none; background: rgba(255, 255, 255, .38); filter: blur(1px); }
@media (max-width: 560px) {
  .pc-seg { grid-template-columns: repeat(2, minmax(0, 1fr)); flex-basis: 100%; max-width: none; }
  .pc-seg button { flex-direction: row; gap: 8px; min-height: 44px; }
  .pc-seg button:nth-child(odd) { border-left: 0; }
  .pc-seg button:nth-child(n + 3) { border-top: 1px solid var(--line); }
  .pc-txt { flex-direction: row; gap: .3em; }
}
.fr-slots { display: flex; flex-wrap: wrap; gap: 8px; }
.fr-slot {
  appearance: none; cursor: pointer; display: flex; align-items: center; gap: 8px; text-align: left;
  padding: 6px 12px 6px 7px; border-radius: 10px; border: 1.5px solid var(--line-strong); background: var(--surface);
  min-height: 44px; flex: 1 1 130px; min-width: 0;
}
.fr-slot.is-on { border-color: var(--red); box-shadow: inset 0 0 0 1px var(--red); }
.fr-slot-txt { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.fr-slot-name { font-size: 13.5px; font-weight: 750; }
.fr-slot-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; min-height: 36px; align-items: center; }
.fr-chip {
  appearance: none; cursor: pointer; padding: 3px; border-radius: 8px; border: 2px solid transparent; background: transparent;
  display: grid; place-items: center; min-width: 36px; min-height: 36px;
}
.fr-chip:hover { border-color: var(--line-strong); }
.fr-chip[aria-pressed="true"] { border-color: var(--red); }
.fr-wait { font-size: 13px; }
.fr-note { margin-top: 14px; font-size: 14px; color: var(--muted); }
.linkish { appearance: none; border: 0; background: none; padding: 4px 0; cursor: pointer; font-size: 13.5px; font-weight: 700; color: var(--red); text-decoration: underline; text-underline-offset: 3px; }
.fr-style:focus-visible, .seg button:focus-visible, .fr-slot:focus-visible, .fr-chip:focus-visible, .linkish:focus-visible { outline: 3px solid rgba(201, 20, 27, .35); outline-offset: 2px; }
.frame-kv { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.frame-chips { display: inline-flex; gap: 3px; vertical-align: middle; }
.frame-kv + .muted { display: block; }
.summary-lines small { font-size: 13px; }

/* ---------- Checkout ---------- */
.checkout-layout { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(280px, 1fr); gap: 28px; align-items: start; }
.notice {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 14px 16px; border-radius: 12px; margin-bottom: 20px;
  background: #fff6d6; border: 1px solid #f0dc93; color: #5a4600; font-size: 15px;
}
.notice strong { color: #3d2f00; }
.notice-icon { flex: none; width: 22px; height: 22px; border-radius: 50%; background: var(--yellow); display: grid; place-items: center; font-weight: 900; font-size: 13px; color: #3d2f00; margin-top: 1px; }
.field { display: block; margin-bottom: 16px; }
.field span { display: block; font-weight: 650; font-size: 15px; margin-bottom: 6px; }
.field input, .field textarea {
  width: 100%; border: 1.5px solid var(--line-strong); border-radius: 10px; background: #fff;
  padding: 12px 14px; font-size: 16px; transition: border-color .15s, box-shadow .15s;
}
.field textarea { min-height: 112px; resize: vertical; line-height: 1.45; }
.field input:focus, .field textarea:focus { outline: none; border-color: var(--red); box-shadow: 0 0 0 3px rgba(201, 20, 27, .15); }
.field input:user-invalid, .field textarea:user-invalid { border-color: var(--red); }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.summary-item { display: grid; grid-template-columns: 88px 1fr; gap: 14px; align-items: center; }
.summary-item img, .summary-item canvas { width: 88px; height: 88px; border-radius: 6px; background: #111; object-fit: contain; }
.summary-item h3 { font-size: 18px; font-weight: 800; }
.summary-item p { color: var(--muted); font-size: 14px; margin-top: 2px; }
.summary-lines { margin: 18px 0 0; padding: 0; list-style: none; font-size: 15px; }
.summary-lines li { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.summary-lines li span:first-child { color: var(--muted); }

/* ---------- Order ---------- */
.order-hero { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 28px; align-items: start; }
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 99px;
  font-size: 13px; font-weight: 700; background: #e3f2e8; color: var(--ok); text-transform: capitalize;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.order-id { white-space: nowrap; font-family: var(--mono); font-size: 15px; background: var(--sunk); padding: 2px 8px; border-radius: 6px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 18px; margin: 18px 0 0; font-size: 15px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; white-space: pre-line; overflow-wrap: anywhere; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); margin-top: 16px; }
table.pieces { width: 100%; border-collapse: collapse; font-size: 15px; }
.pieces th, .pieces td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.pieces th { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); background: var(--sunk); }
.pieces td.n, .pieces th.n { text-align: right; font-variant-numeric: tabular-nums; }
.pieces td.name { white-space: normal; min-width: 140px; }
.pieces tr.base td { background: #faf6ee; }
.pieces tfoot td { font-weight: 800; border-bottom: 0; }
.pieces .code { font-family: var(--mono); font-size: 13px; color: var(--muted); }
.pieces .cell-sw { display: flex; align-items: center; gap: 10px; }
.list-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 12px; margin-top: 44px; }
.list-head h3 { font-size: 22px; font-weight: 800; }
.list-head p { color: var(--muted); font-size: 14px; margin-top: 4px; }

.loading-block { padding: 80px 0; display: flex; flex-direction: column; align-items: center; gap: 14px; color: var(--muted); }
.loading-block .spinner i:nth-child(3) { background: var(--line-strong); }

/* ---------- Admin ---------- */
.admin-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.admin-table th, .admin-table td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.admin-table th { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); background: var(--sunk); white-space: nowrap; }
.admin-table tbody tr.order-row { cursor: pointer; }
.admin-table tbody tr.order-row:hover td { background: #faf6ee; }
.admin-table tr.order-row.is-open td { background: var(--red-tint); }
.admin-table td.n { text-align: right; font-variant-numeric: tabular-nums; }
.admin-table img, .admin-table canvas { display: block; max-width: none; width: 48px; height: 48px; border-radius: 4px; background: #111; object-fit: contain; }
.admin-table .detail > td { background: #fbf8f2; padding: 18px 20px 24px; }
.admin-table .sub { color: var(--muted); font-size: 13px; }
.chev { display: inline-block; transition: transform .15s; color: var(--muted); }
.is-open .chev { transform: rotate(90deg); }
.empty { padding: 60px 20px; text-align: center; color: var(--muted); }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .hero, .checkout-layout, .order-hero { grid-template-columns: minmax(0, 1fr); }
  .design, .design.is-wide { grid-template-columns: minmax(0, 1fr); grid-template-areas: "photo" "mosaic" "controls" "frame" "summary"; --maxh: min(50vh, 520px); }
  .hero { gap: 24px; }
  .size-cards { grid-template-columns: 1fr; }
  .steps .lbl { display: none; }
  .steps li.is-current .lbl { display: inline; }
}
@media (max-width: 560px) {
  .wrap { padding: 0 16px; }
  main.wrap { padding-top: 22px; padding-bottom: 60px; }
  .topbar-inner { height: 56px; gap: 12px; }
  .brand { font-size: 17px; }
  .brand-name { display: none; }
  .steps li + li::before { width: 12px; }
  .drop { min-height: 220px; }
  .lede { font-size: 17px; }
  .panel { padding: 18px; }
  .size-cards { grid-template-columns: 1fr; gap: 10px; }
  .row-2 { grid-template-columns: 1fr; gap: 0; }
  .pieces th:nth-child(3), .pieces td:nth-child(3) { display: none; }
  .pieces th, .pieces td { padding: 9px 10px; }
  .pieces th { font-size: 11px; letter-spacing: .04em; white-space: normal; }
  .pieces td.name { min-width: 0; }
  .list-head .btn { display: none; }
  .design { --pad: 14px; gap: 18px; }
  .lp { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .pane-meta { display: none; }
  .frame img, .frame canvas { max-height: 64vh; }
  .actions .btn { flex: 1 1 100%; }
  .color-list { grid-template-columns: 1fr; }
  .frame { padding: 8px; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 8px; }
  .section-title { margin-top: 40px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
.admin-table tr.order-row:focus { outline: none; }
.admin-table tr.order-row:focus-visible td { box-shadow: inset 0 2px 0 rgba(201, 20, 27, .35), inset 0 -2px 0 rgba(201, 20, 27, .35); }
