:root {
  --bg: #efedea;
  --wall-1: #dcd8d1;
  --wall-2: #c7c2ba;
  --surface: #ffffff;
  --surface-2: #faf9f7;
  --line: #e2ded8;
  --line-strong: #cfc9c1;
  --text: #1f1c19;
  --muted: #837b72;
  --accent: #7a5c33;
  --accent-soft: #f2ece3;
  --danger: #9c3f38;
  --radius: 12px;
  --radius-sm: 9px;
  /* The phone bottom sheet's top corners. A token like the others so a
     square-cornered host can square these too. */
  --radius-sheet: 18px;
  --panel-w: 372px;
  --shadow-sm: 0 1px 2px rgba(31, 28, 25, 0.06);
  --shadow-md: 0 4px 16px rgba(31, 28, 25, 0.10);

  /* Typography is a token too, so a host can dress the builder in its
     own face. See themes/ — the builder is embedded in the Vantage
     Point site and in FrameFlow, and in each it should look like it
     belongs there rather than like a tool someone bolted on. */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-head: var(--font);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font: 15px/1.5 var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font-family: inherit; touch-action: manipulation; }

.app {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
  grid-template-columns: 1fr var(--panel-w);
  grid-template-areas: "top top" "stage panel";
}

/* --- top bar --- */
.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  z-index: 30;
}
.brand {
  font-family: var(--font-head);
  font-weight: 650;
  letter-spacing: -0.015em;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.top-actions { display: flex; gap: 8px; align-items: center; flex: 0 0 auto; }

/* --- stage --- */
.stage-wrap {
  grid-area: stage;
  position: relative;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: radial-gradient(120% 100% at 50% 0%, var(--wall-1) 0%, var(--wall-2) 100%);
}
#stage {
  flex: 1;
  width: 100%;
  min-height: 0;
  display: block;
  touch-action: none;
}
.stage-hint {
  margin: 0;
  padding: 9px 16px;
  padding-bottom: max(9px, env(safe-area-inset-bottom));
  font-size: 11.5px;
  letter-spacing: 0.01em;
  color: #6d665e;
  text-align: center;
  background: rgba(255, 255, 255, 0.42);
  border-top: 1px solid rgba(255, 255, 255, 0.5);
}
.fit-btn {
  position: absolute;
  right: 14px;
  bottom: 52px;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-md);
  padding: 0 18px;
  min-height: 40px;
  font-weight: 550;
  font-size: 13px;
  z-index: 5;
}

/* The selected opening's photo lock, floating on the stage (placeStageLock
   in app.js). Filled with the accent while locked, so the state reads at a
   glance from across the room. */
.stage-lock {
  position: absolute;
  z-index: 6;
  gap: 7px;
  min-height: 36px;
  padding: 0 13px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-md);
}
.stage-lock[hidden] { display: none; }
.stage-lock svg { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.stage-lock[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.stage-lock.pulse { animation: fmb-lock-pulse 0.55s ease-in-out 3; }
@keyframes fmb-lock-pulse { 50% { transform: scale(1.12); box-shadow: 0 0 0 7px var(--accent-soft), var(--shadow-md); } }
@media (prefers-reduced-motion: reduce) { .stage-lock.pulse { animation: none; outline: 2px solid var(--accent); } }

/* How to move and zoom a photo, over the photo itself (showPhotoTip in
   app.js). Never takes a tap: it would otherwise block the drag it is
   describing. */
.photo-tip {
  position: absolute;
  z-index: 7;
  padding: 8px 13px;
  font-size: 13px;
  line-height: 1.3;
  white-space: nowrap;
  color: #fff;
  background: rgba(20, 18, 16, 0.8);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.photo-tip.show { opacity: 1; }
.photo-tip[hidden] { display: none; }
.photo-tip b { font-weight: 700; }
.photo-tip.stacked { text-align: center; }
.photo-tip.stacked span { display: block; }
.photo-tip.stacked .sep { display: none; }
@media (prefers-reduced-motion: reduce) { .photo-tip { transition: none; } }

/* --- panel --- */
.panel {
  grid-area: panel;
  background: var(--surface);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  z-index: 25;
}
.panel-head {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 4px 16px 12px;
  font-weight: 650;
  font-size: 15px;
}
.sheet-handle {
  display: none;
  width: 100%;
  min-height: 0;
  height: 22px;
  border: none;
  border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
  background: transparent;
  padding: 0;
  flex: 0 0 auto;
  position: relative;
}
.sheet-handle::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 9px;
  transform: translateX(-50%);
  width: 38px;
  height: 4px;
  border-radius: 99px;
  background: var(--line-strong);
}
.sheet-handle:hover { background: transparent; }
.panel-body {
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 14px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* --- cards --- */
.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
#sel-card {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 3px rgba(122, 92, 51, 0.09);
}
.card h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
  margin: 0 0 12px;
  font-weight: 650;
}
/* --- tabs --- */
.tabs {
  display: flex;
  gap: 2px;
  padding: 0 10px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
  background: var(--surface);
}
.tabs button {
  flex: 1;
  min-width: 0;
  min-height: 46px;
  padding: 0 4px;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tabs button:hover { background: transparent; color: var(--text); border-color: transparent; border-bottom-color: var(--line-strong); }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); background: transparent; }

.tab-panel { display: none; flex-direction: column; gap: 12px; }
.tab-panel.active { display: flex; }

.empty-state {
  margin: 0;
  padding: 26px 18px;
  text-align: center;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.5;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  height: 28px;
}

/* --- cut list --- */
.spec-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.spec-table th {
  text-align: left;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  font-weight: 650;
  padding: 0 8px 6px 0;
  border-bottom: 1px solid var(--line);
}
.spec-table td {
  padding: 7px 8px 7px 0;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.spec-table tr:last-child td { border-bottom: none; }
.spec-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13.5px;
}
.spec-head:last-of-type { border-bottom: none; }
.spec-head span:first-child { color: var(--muted); }
.spec-head span:last-child { font-weight: 600; font-variant-numeric: tabular-nums; }
.spec-group { margin-top: 16px; }

/* --- fields --- */
.row { display: flex; gap: 10px; }
.row + .row { margin-top: 10px; }
label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
  font-size: 11.5px;
  font-weight: 550;
  letter-spacing: 0.02em;
  color: var(--muted);
  min-width: 0;
}
.unit-label { font-weight: 450; }

input[type="number"], input[type="text"], select {
  width: 100%;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 16px; /* keeps iOS from zooming the page on focus */
  font-weight: 500;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input[type="number"]:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(122, 92, 51, 0.14);
}
input[type="color"] {
  width: 100%;
  min-height: 44px;
  padding: 3px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
}
input:disabled { background: var(--surface-2); color: var(--muted); border-style: dashed; }

button, .btn, .file-label {
  font: inherit;
  font-size: 14px;
  font-weight: 550;
  min-height: 44px;
  padding: 9px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
  transition: background 0.15s ease, border-color 0.15s ease;
}
button:hover, .btn:hover, .file-label:hover { background: var(--surface-2); border-color: var(--muted); }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover, .btn.primary:hover { background: #684d2a; border-color: #684d2a; }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); padding: 9px 10px; }
button.ghost:hover { background: var(--surface-2); border-color: var(--line); color: var(--text); }
button.danger, .btn.danger { color: var(--danger); border-color: #e6d2cf; background: transparent; }
button.danger:hover, .btn.danger:hover { background: #fbf3f2; border-color: var(--danger); }

.btn-row { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.btn-row > * { flex: 1; min-width: 116px; }
.icon-btn { border: none; background: transparent; font-size: 26px; line-height: 1; min-height: 0; padding: 2px 6px; color: var(--muted); }
.icon-btn:hover { background: transparent; border: none; color: var(--text); }

.note { font-size: 12px; line-height: 1.45; color: var(--muted); margin: 10px 0 0; }
.note code { background: var(--surface-2); border: 1px solid var(--line); padding: 1px 5px; border-radius: 5px; font-size: 11px; }

/* --- chips --- */
.chip-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); gap: 9px; }
.chip {
  aspect-ratio: 1;
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  background-size: cover;
  background-position: center;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  padding: 0;
  min-height: 0;
  box-shadow: var(--shadow-sm);
  transition: transform 0.12s ease, border-color 0.15s ease;
}
/* The current moulding, when the host lists mouldings in a box of its own
   (see showCurrentMoulding in app.js). */
.moulding-current {
  width: 100%;
  justify-content: flex-start;
  gap: 12px;
  padding: 8px 12px;
  text-align: left;
  font-weight: 400;
}
.moulding-current:hover { background: var(--surface); border-color: var(--accent); }
.moulding-current-thumb {
  width: 40px; height: 40px; flex: none;
  border: 1px solid var(--line);
  background: var(--surface-2) center / cover no-repeat;
}
.moulding-current-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.moulding-current-text b { font-size: 13.5px; font-weight: 650; }
.moulding-current-text span { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.moulding-current-go { font-size: 22px; line-height: 1; color: var(--muted); }
/* Their own display rules would otherwise beat the hidden attribute. */
.moulding-current[hidden], .chip-grid[hidden], .note[hidden] { display: none; }

.chip:hover { transform: translateY(-1px); border-color: var(--line-strong); background-color: transparent; }
.chip.selected { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(122, 92, 51, 0.2); }
.chip span {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: rgba(20, 18, 16, 0.62);
  color: #fff;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  padding: 3px 3px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- sub-blocks (mount layers) --- */
.sub {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 10px;
  background: var(--surface-2);
}
.sub:last-of-type { margin-bottom: 0; }
.sub-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.sub-head strong {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text);
  font-weight: 650;
}
.sub-head .btn { min-height: 34px; padding: 4px 12px; font-size: 12.5px; }
.sub .chip-grid { margin-top: 10px; }

/* --- steppers + segmented --- */
.stepper-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0;
}
.stepper-row + .stepper-row { border-top: 1px solid var(--line); }
.stepper-row > span { font-size: 14px; font-weight: 500; }
.stepper {
  display: flex;
  align-items: center;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface);
}
.stepper button {
  width: 46px;
  min-height: 44px;
  padding: 0;
  font-size: 19px;
  line-height: 1;
  border: none;
  border-radius: 0;
  color: var(--accent);
}
.stepper output {
  min-width: 44px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-size: 16px;
  font-weight: 650;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  align-self: stretch;
  display: flex;
  align-items: center;
  justify-content: center;
}

.field-label {
  display: block;
  font-size: 11.5px;
  font-weight: 550;
  letter-spacing: 0.02em;
  color: var(--muted);
  margin: 14px 0 6px;
}
.seg { display: flex; }
.seg button {
  flex: 1;
  border-radius: 0;
  border-left-width: 0;
  min-height: 44px;
  font-size: 13.5px;
}
.seg button:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); border-left-width: 1px; }
.seg button:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.seg button.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.check-row {
  flex-direction: row;
  align-items: center;
  gap: 11px;
  margin-top: 14px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 13.5px;
  font-weight: 500;
  letter-spacing: 0;
  color: var(--text);
  cursor: pointer;
}
.check-row input { width: 20px; height: 20px; flex: 0 0 auto; accent-color: var(--accent); cursor: pointer; }

.panel-toggle { display: none; }

/* --- mobile --- */
@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-areas: "top" "stage";
  }
  .topbar { padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top)); }
  :root { --sheet-h: 46dvh; }
  .panel {
    position: fixed;
    inset: auto 0 0 0;
    height: var(--sheet-h);
    border-left: none;
    border-top: 1px solid var(--line);
    border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
    box-shadow: 0 -10px 36px rgba(31, 28, 25, 0.18);
    transform: translateY(101%);
    transition: transform 0.26s cubic-bezier(0.32, 0.72, 0, 1),
                height 0.26s cubic-bezier(0.32, 0.72, 0, 1);
  }
  .panel.open { transform: translateY(0); }
  .panel.expanded { height: 88dvh; }

  /* The stage gives up the sheet's height so the frame stays visible and
     keeps updating while the controls are open. */
  .app.sheet-open .stage-wrap { padding-bottom: var(--sheet-h); }
  .app.sheet-open .fit-btn { bottom: calc(var(--sheet-h) + 50px); }

  .panel-head { display: flex; padding: 0 16px 10px; }
  .sheet-handle { display: block; }
  .panel-toggle { display: inline-flex; }
  .chip-grid { grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); }
  .fit-btn { bottom: 50px; right: 12px; }
  .btn-row > * { min-width: 104px; }
}

@media (max-width: 380px) {
  .brand { font-size: 13px; }
  button.ghost { padding: 9px 8px; font-size: 13px; }
}

/* --- customer mode (?mode=customer, see customer.js) ---------------------
   Four numbered steps with a line of instructions and a Next button each;
   everything only a framer needs is hidden rather than removed, so the
   workshop version is the same page with nothing switched off. */
.customer .workshop-only,
.customer #tabs button[data-tab="specs"],
.customer .tab-panel[data-panel="specs"] { display: none !important; }

.step-intro {
  margin: 0;
  padding: 11px 13px;
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--text);
  background: var(--accent-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.step-next { display: flex; justify-content: flex-end; }
.step-next .primary { min-width: 150px; }
.tabs .step-num { font-weight: 700; margin-right: 6px; color: var(--muted); }
.tabs button.active .step-num { color: var(--accent); }

/* The stalled-for-a-while hint: an outline that breathes on the one
   control that moves things on. */
.nudge {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  animation: fmb-nudge 1.1s ease-in-out infinite alternate;
}
@keyframes fmb-nudge { to { outline-offset: 6px; } }
@media (prefers-reduced-motion: reduce) { .nudge { animation: none; } }
/* Mount colours are named, not coded, for customers — let a two-word
   name wrap instead of cutting it to "Snow W…". */
.customer .chip span { white-space: normal; line-height: 1.15; padding: 3px 2px; }
