/* Vasecreator v2: the step frame (steps, parts, the phone bar), section
   controls, swatches and the Print step. Uses only the shared tokens from
   app.css :root (ARCHITECTURE.md). Desktop is compact (the panel is 320 px);
   coarse pointers get 44 px targets. */

/* ---------- Shared ---------- */

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.steps :focus-visible {
  outline: 2px solid var(--c-primary-dark);
  outline-offset: 2px;
}


.panel-note {
  margin: 0;
  font-size: 12px;
  color: var(--c-text-2);
}

.icon-btn, .link-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: var(--radius-ctl);
  background: none;
  color: var(--c-text);
  cursor: pointer;
}
.icon-btn {
  width: 32px;
  height: 32px;
  flex: none;
  font-size: 16px;
  line-height: 1;
}
.icon-btn:hover:not(:disabled) { background: var(--c-input-bg); border-color: var(--c-input-border); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.link-btn {
  padding: var(--space-1) var(--space-1);
  min-height: 28px;
  font-size: 13px;
  font-weight: 500;
  color: var(--c-primary-dark);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-color: var(--c-input-border);
}
.link-btn:hover:not(:disabled) { text-decoration-color: currentColor; }
.link-btn:disabled { color: var(--c-text-2); text-decoration: none; cursor: default; }

/* ---------- The step frame (issue #1, ui/steps.js) ---------- */

/* Desktop: one card, the step row on top and the parts under it (they
   scroll); the row stays in sight (C27). There is no Next: the emblems move
   between steps (pattern studio D49). */
.steps {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-2);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  overflow: hidden;
  font-size: 13px;
  color: var(--c-text);
}

/* The five steps. The bar is white so the light-grey steps keep their
   contrast: labels at .66 (4.8:1), emblems at .5 (3:1) on white (§4). */
.step-tabs {
  flex: none;
  display: flex;
  gap: 2px;
  padding: var(--space-2) var(--space-2) 6px;
  background: #fff;
  border-bottom: 1px solid var(--c-border);
}
.step-tab {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 2px 0;
  border: 0;
  border-radius: var(--radius-ctl);
  background: none;
  font-size: 11px;
  font-weight: 500;
  color: rgba(18,47,45,.66);
  cursor: pointer;
}
.step-tab:hover .step-emblem { background: rgba(18,47,45,.07); }
.step-tab:focus-visible { outline-offset: 0; }
.step-emblem {
  display: grid;
  place-items: center;
  width: 44px;
  height: 28px;
  border-radius: 14px;
  color: rgba(18,47,45,.5);
  transition: background-color .15s ease, color .15s ease;
}
.step-emblem svg { width: 20px; height: 20px; }
.step-label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.step-tab[aria-selected="true"] { color: var(--c-text); font-weight: 700; }
.step-tab[aria-selected="true"] .step-emblem { background: var(--c-primary-dark); color: #fff; }

/* The phone header and part row; desktop shows parts under headings instead. */
.step-head, .part-tabs { display: none; }

.step-scroll {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  padding: var(--space-3) var(--space-4) var(--space-4);
}
.step-page { display: flex; flex-direction: column; gap: var(--space-3); }
.step-page:focus-visible { outline-offset: 2px; border-radius: 4px; }

.section-body { display: flex; flex-direction: column; gap: var(--space-3); }

/* A part's small heading (desktop). */
.part-heading {
  margin: var(--space-2) 0 calc(var(--space-1) * -1);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--c-text-2);
}
.step-page > .section-body:first-child > .part-heading:first-child,
.step-page > .part-heading:first-child { margin-top: 0; }

/* A part that doesn't apply, or on a phone isn't the current one. */
.is-part-off { display: none !important; }

/* "More shape options": Curve, Points and Morph on desktop. */
.more-shape { display: flex; flex-direction: column; gap: var(--space-3); margin-top: var(--space-1); border-top: 1px solid var(--c-border); }
.more-toggle {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: var(--space-2);
  width: 100%;
  min-height: 44px;
  padding: var(--space-2) 0;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
}
.more-chevron { display: inline-flex; align-self: center; color: var(--c-text-2); transition: transform .15s ease; }
.more-shape.is-open .more-chevron { transform: rotate(90deg); }
.more-title { font-size: 13px; font-weight: 600; }
.more-sub { font-size: 12px; color: var(--c-text-2); }
.more-toggle:hover .more-title { text-decoration: underline; text-underline-offset: 2px; }
.more-body { display: flex; flex-direction: column; gap: var(--space-3); }
.steps:not(.steps--phone) .more-shape:not(.is-open) .more-body { display: none; }

/* ---------- Number field ---------- */

.nf {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-2);
}
.nf-label {
  flex: 1;
  min-width: 0;
  font-weight: 500;
  color: var(--c-text);
  cursor: ew-resize;
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-y;
}
.nf.is-disabled .nf-label { cursor: default; }
.nf.is-scrubbing .nf-label { color: var(--c-primary-dark); }
.nf-box { display: flex; align-items: center; gap: var(--space-1); flex: none; }
.nf-field {
  position: relative;
  display: flex;
  align-items: center;
  width: 92px;
  height: 30px;
  border: 1px solid var(--c-input-border);
  border-radius: var(--radius-ctl);
  background: var(--c-input-bg);
}
.nf-field:focus-within { border-color: var(--c-primary-dark); box-shadow: 0 0 0 3px var(--c-primary); }
/* The value scrubs too (controls.js): only sideways, so a vertical swipe
   still scrolls the panel. Once the field has focus it's a text field again. */
.nf-field { cursor: ew-resize; touch-action: pan-y; }
.nf-field .nf-input:not(:focus) { cursor: ew-resize; }
.nf-field:focus-within { cursor: text; touch-action: auto; }
.nf.is-disabled .nf-field, .nf.is-disabled .nf-input:not(:focus) { cursor: default; }
.nf.is-scrubbing .nf-field { border-color: var(--c-primary-dark); }
.nf.is-scrubbing, .nf.is-scrubbing * { cursor: ew-resize; user-select: none; -webkit-user-select: none; }
.nf-input {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0 var(--space-1) 0 var(--space-2);
  border: 0;
  background: none;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.nf-input:focus, .nf-input:focus-visible { outline: none; }
.nf-unit { flex: none; padding-right: var(--space-2); font-size: 12px; color: var(--c-text-2); pointer-events: none; }
.nf.is-disabled .nf-field { background: var(--c-border); border-style: dashed; }
.nf.is-disabled .nf-input { color: var(--c-text-2); }
.nf-step { display: none; }
.nf-info { flex-basis: 100%; font-size: 12px; color: var(--c-text-2); }
.nf--compact .nf-field { width: 84px; }

/* ---------- Slider ---------- */

.sl {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-1);
}
.sl-label { font-weight: 500; }
.sl-row { display: flex; align-items: center; gap: var(--space-2); }
.sl-row .nf { flex: none; }
.sl-row .nf-field { width: 84px; }
.sl-range {
  flex: 1;
  min-width: 0;
  height: 24px;
  margin: 0;
  background: none;
  accent-color: var(--c-primary-dark);
  cursor: pointer;
}

/* ---------- Segmented ---------- */

.seg { display: flex; flex-direction: column; gap: var(--space-1); }
.seg-label { font-weight: 500; }
.seg-group {
  display: flex;
  gap: 2px;
  padding: 2px;
  border-radius: var(--radius-ctl);
  background: var(--c-border);
}
.seg-btn {
  flex: 1 1 0;
  min-width: 0;
  min-height: 28px;
  padding: 0 var(--space-2);
  border: 0;
  border-radius: calc(var(--radius-ctl) - 2px);
  background: none;
  font-size: 13px;
  font-weight: 500;
  color: var(--c-text);
  cursor: pointer;
  white-space: nowrap;
}
.seg-btn:hover:not([aria-checked="true"]):not(:disabled) { background: var(--c-card); }
.seg-btn[aria-checked="true"] { background: var(--c-input-bg); box-shadow: var(--shadow-1), 0 0 0 1px var(--c-input-border); font-weight: 600; }
.seg-btn:disabled { color: var(--c-text-2); cursor: default; }
.seg-group:has(.seg-btn:only-child) { align-self: flex-start; }
.seg-btn:only-child { flex: none; padding: 0 var(--space-4); }
.seg--many .seg-group { flex-wrap: wrap; }
.seg--many .seg-btn { flex: 1 1 calc(33.3% - 2px); }

/* ---------- Toggle and select ---------- */

.tg { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.tg-btn {
  position: relative;
  width: 40px;
  height: 24px;
  border: 0;
  border-radius: 12px;
  background: var(--c-input-border);
  cursor: pointer;
}
.tg-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--c-input-bg);
  box-shadow: var(--shadow-1);
  transition: transform .15s ease;
}
.tg-btn[aria-checked="true"] { background: var(--c-accent); }
.tg-btn[aria-checked="true"] .tg-knob { transform: translateX(16px); }

.sel { display: flex; align-items: center; gap: var(--space-2); }
.sel-label { flex: 1; font-weight: 500; }
.sel-input {
  width: 150px;
  height: 30px;
  padding: 0 var(--space-2);
  border: 1px solid var(--c-input-border);
  border-radius: var(--radius-ctl);
  background: var(--c-input-bg);
  font-size: 13px;
}

/* ---------- Shape ---------- */

.lock-btn { color: var(--c-text-2); }
.lock-btn[aria-pressed="true"] { color: var(--c-primary-dark); }

/* ---------- Surface: slots and swatches ---------- */

.slot-row { display: flex; align-items: center; gap: var(--space-1); }
.slot-card {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 6px 6px 6px;
  border: 1px solid var(--c-input-border);
  border-radius: var(--radius-ctl);
  background: var(--c-input-bg);
  text-align: left;
  cursor: pointer;
}
.slot-card:hover { border-color: var(--c-primary-light); }
.slot-card[aria-pressed="true"] { border-color: var(--c-accent); box-shadow: 0 0 0 1px var(--c-accent); }
.slot-thumb { position: relative; flex: none; display: block; width: 34px; height: 34px; border-radius: 4px; background: var(--c-border); }
.slot-letter {
  position: absolute;
  left: -4px;
  top: -4px;
  display: grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--c-primary-dark);
  color: var(--c-surface);
  font-size: 10px;
  font-weight: 700;
}
.slot-card.is-none .slot-thumb {
  background:
    linear-gradient(to top right, transparent calc(50% - 1px), var(--c-input-border) calc(50% - 1px), var(--c-input-border) calc(50% + 1px), transparent calc(50% + 1px)),
    var(--c-input-bg);
  box-shadow: 0 0 0 1px var(--c-border);
}
.slot-swatch { display: block; border-radius: 4px; box-shadow: 0 0 0 1px var(--c-border); }
.slot-text { display: flex; flex-direction: column; min-width: 0; }
.slot-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot-sub { font-size: 11px; color: var(--c-text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Narrow on desktop so "main pattern" fits the slot card; 44 px on touch below. */
.swap-btn { width: 26px; }
.swap-btn svg { width: 18px; height: 18px; }

.grid-label { margin-bottom: calc(var(--space-2) * -1); font-size: 12px; color: var(--c-text-2); }
.swatch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
  gap: var(--space-2) var(--space-1);
}
.swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 0;
  padding: 3px 0 2px;
  border: 0;
  border-radius: var(--radius-ctl);
  background: none;
  cursor: pointer;
}
.swatch-canvas, .swatch-none {
  display: block;
  width: 52px;
  height: 52px;
  border-radius: 6px;
  box-shadow: 0 0 0 1px var(--c-border);
}
.swatch-none {
  background:
    linear-gradient(to top right, transparent calc(50% - 1px), var(--c-input-border) calc(50% - 1px), var(--c-input-border) calc(50% + 1px), transparent calc(50% + 1px)),
    var(--c-input-bg);
}
.swatch:hover .swatch-canvas, .swatch:hover .swatch-none { box-shadow: 0 0 0 1px var(--c-primary-light); }
.swatch[aria-pressed="true"] .swatch-canvas, .swatch[aria-pressed="true"] .swatch-none { box-shadow: 0 0 0 2px var(--c-input-bg), 0 0 0 4px var(--c-accent); }
.swatch-name {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
  color: var(--c-text);
}
.swatch[aria-pressed="true"] .swatch-name { font-weight: 600; }

.slot-settings, .blend-settings, .two-walls { display: flex; flex-direction: column; gap: var(--space-3); }
.blend-settings { padding-top: var(--space-3); border-top: 1px solid var(--c-border); }
.range-row .nf-label { cursor: default; }
.range-fields { display: flex; align-items: center; gap: var(--space-1); }
.range-fields .nf-field { width: 76px; }
.range-dash { color: var(--c-text-2); }

/* ---------- Profile points ---------- */

.points-table { width: 100%; table-layout: fixed; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.points-table th:last-child { width: 36px; }
.points-table th {
  padding: 0 var(--space-1) var(--space-1);
  font-size: 11px;
  font-weight: 600;
  color: var(--c-text-2);
  text-align: left;
}
.points-table td { padding: 2px var(--space-1); }
.points-table th:first-child, .points-table td:first-child { width: 24px; text-align: center; }
.point-row { cursor: pointer; }
.point-row:hover td { background: var(--c-input-bg); }
.point-row.is-selected td { background: var(--c-primary); }
.point-row td:first-child { border-radius: var(--radius-ctl) 0 0 var(--radius-ctl); }
.point-row td:last-child { border-radius: 0 var(--radius-ctl) var(--radius-ctl) 0; }
.point-num { font-weight: 600; color: var(--c-text-2); }
.point-row.is-selected .point-num { color: var(--c-text); }
.points-table .nf, .points-table .nf-box { display: flex; width: 100%; }
.points-table .nf-field { width: 100%; min-width: 0; }
.del-btn { width: 28px; height: 28px; font-size: 18px; color: var(--c-text-2); }
/* Corner (Angular) or Sharp (Smooth, Gentle), issue #6. */
.points-table th.point-extra { width: 70px; white-space: nowrap; }
/* The unit sits in the column heading, so the numbers get the room. */
.points-table .nf-unit { display: none; }
.points-table .nf-input { padding-right: var(--space-2); }
.th-unit { font-weight: 400; }
.points-table td.point-extra { text-align: center; }
.sharp-btn { color: var(--c-text-2); }
.sharp-btn[aria-pressed="true"] { color: var(--c-text); border-color: var(--c-input-border); background: var(--c-input-bg); }
.point-end { color: var(--c-text-2); }
.add-point { align-self: flex-start; }

/* ---------- Print (step 5) ---------- */

/* One part of the Print step: Walls, Printer, Check or Export. */
.print-part { display: flex; flex-direction: column; gap: var(--space-3); }
.printer-line { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.printer-name { font-weight: 600; }
.badge {
  display: inline-block;
  padding: 1px var(--space-2);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
}
.badge--draft { background: var(--c-border); color: var(--c-text); box-shadow: inset 0 0 0 1px var(--c-warn); }
.printer-summary { margin: calc(var(--space-2) * -1) 0 0; font-size: 12px; color: var(--c-text-2); }
.print-part > .link-btn { align-self: flex-start; }
.printer-editor { display: flex; flex-direction: column; gap: var(--space-3); }
.printer-editor > .link-btn { align-self: flex-start; }
.printer-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin: 0;
  padding: var(--space-2) 0 0;
  border: 0;
  border-top: 1px solid var(--c-border);
}
.printer-group legend {
  padding: 0 var(--space-1) 0 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--c-text-2);
}
.template-field { display: flex; flex-direction: column; gap: var(--space-1); }
.template-label { font-weight: 500; }
.template-input {
  width: 100%;
  min-height: 72px;
  padding: var(--space-2);
  border: 1px solid var(--c-input-border);
  border-radius: var(--radius-ctl);
  background: var(--c-input-bg);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.4;
  resize: vertical;
}
.template-input:focus-visible { outline: 2px solid var(--c-primary-dark); outline-offset: 0; }

.check-status { display: flex; align-items: center; gap: var(--space-2); font-size: 12px; color: var(--c-text-2); }
.check-status:empty { display: none; }
.check-list { display: flex; flex-direction: column; gap: var(--space-2); margin: 0; padding: 0; list-style: none; transition: opacity .15s ease; }
.check-list.is-stale { opacity: .5; }
.check { display: flex; align-items: flex-start; gap: var(--space-2); line-height: 1.4; }
.check-icon {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  color: var(--c-surface);
}
/* The accent green darkened, so the mark keeps 3:1 against the card (WCAG 1.4.11). */
.check--ok .check-icon { background: color-mix(in srgb, var(--c-accent) 72%, #000); }
.check--warning .check-icon { background: var(--c-warn); color: var(--c-text); }
.check--error .check-icon { background: var(--c-error); }
.check--info .check-icon { background: var(--c-primary-light); }
.check--error .check-text { font-weight: 600; }

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--c-border);
  border-top-color: var(--c-primary-dark);
  border-radius: 50%;
  animation: panel-spin .8s linear infinite;
}
@keyframes panel-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

.export-buttons { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.export-buttons .btn { flex: 1 1 auto; }
.export-progress {
  width: 100%;
  height: 6px;
  border: 0;
  border-radius: 3px;
  background: var(--c-border);
  accent-color: var(--c-accent);
  overflow: hidden;
}
.export-progress::-webkit-progress-bar { background: var(--c-border); }
.export-progress::-webkit-progress-value { background: var(--c-accent); }
.export-progress::-moz-progress-bar { background: var(--c-accent); }
.export-note:empty { display: none; }
.export-note { font-size: 12px; color: var(--c-text-2); }
.size-line { font-size: 13px; font-weight: 500; font-variant-numeric: tabular-nums; }
/* CAD files (issue #7), under the G-code. */
.cad-export { display: grid; gap: var(--space-2); margin-top: var(--space-2); padding-top: var(--space-3); border-top: 1px solid var(--c-border); }
.cad-title { margin: 0; font-weight: 600; }
.cad-hint { margin: 0; font-size: 12px; color: var(--c-text-2); line-height: 1.4; }

/* ---------- Touch screens: 44 px targets, steppers ---------- */

@media (pointer: coarse) {
  .steps { font-size: 14px; }
  .nf-step {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: 1px solid var(--c-input-border);
    border-radius: var(--radius-ctl);
    background: var(--c-input-bg);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    touch-action: manipulation;
  }
  .nf-step:disabled { opacity: .4; }
  .nf-field { height: 44px; width: 96px; }
  .nf-input { font-size: 16px; } /* 16 px stops iOS zooming into the field */
  .sl-row .nf-field, .nf--compact .nf-field, .range-fields .nf-field { height: 44px; }
  .sl-range { height: 44px; }
  .seg-btn { min-height: 44px; font-size: 14px; }
  .icon-btn, .del-btn { width: 44px; height: 44px; }
  .link-btn { min-height: 44px; }
  .sel-input { height: 44px; font-size: 16px; }
  .tg-btn { width: 52px; height: 32px; border-radius: 16px; }
  .tg-knob { width: 26px; height: 26px; }
  .tg-btn[aria-checked="true"] .tg-knob { transform: translateX(20px); }
  .slot-card { min-height: 52px; }
  .swatch-grid { grid-template-columns: repeat(auto-fill, minmax(60px, 1fr)); }
  .template-input { font-size: 16px; }
}

/* ---------- Phone: bottom bar, controls area, part row (D31, §7.5) ---------- */

/* steps.js sets .steps--phone from the same 760 px query app.css uses. The
   DOM order stays the desktop one (nothing moves between layouts); the bar
   goes to the bottom with `order`, the dock just above it. On a phone the
   frame shows either the dock (.steps--dock, the default) or the settings
   sheet (.steps--sheet), mobile stage M3 and M5. */
.steps--phone {
  height: auto;
  border: 0;
  border-radius: var(--radius-card) var(--radius-card) 0 0;
  background: rgb(250,250,250);
  box-shadow: 0 -4px 16px rgba(0,0,0,.08);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}
.steps--phone .step-tabs {
  order: 2;
  height: calc(var(--bar-h, 64px) + env(safe-area-inset-bottom));
  padding: 6px var(--space-1) calc(6px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--c-border);
  border-bottom: 0;
}
/* #panel is the frame itself; its phone rule (app.css) sizes it to the dock. */
#panel.steps--sheet { height: var(--panel-h); }
.steps--dock .step-head,
.steps--dock .part-tabs,
.steps--dock .step-scroll { display: none !important; }
.steps--phone .step-tab { justify-content: center; font-size: 12px; }
.steps--phone .step-emblem { width: 56px; height: 30px; border-radius: 15px; }
.steps--phone .step-emblem svg { width: 24px; height: 24px; }

.steps--phone .step-head {
  position: relative;
  display: flex;
  flex: none;
  align-items: center;
  gap: var(--space-2);
  min-height: 46px;
  padding: 2px var(--space-2) 0 var(--space-4);
}
/* The sheet's ⌄ closes it, back to the pot; a swipe down on its header does too. */
.sheet-collapse { display: none; }
.steps--sheet:not(.steps--print) .step-head { padding: 12px var(--space-2) 0 var(--space-1); touch-action: none; }
.steps--sheet:not(.steps--print) .step-head::before {
  content: '';
  position: absolute;
  top: 6px;
  left: 50%;
  width: 40px;
  height: 4px;
  margin-left: -20px;
  border-radius: 2px;
  background: rgba(18,47,45,.28);
}
.steps--sheet .sheet-collapse:not([hidden]) { display: inline-flex; width: 44px; height: 44px; color: var(--c-text); }
.step-title { flex: 1; min-width: 0; margin: 0; font-size: 15px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.steps--phone .part-tabs {
  display: flex;
  flex: none;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  padding: 0 var(--space-3) 2px;
}
.steps--phone .part-tabs::-webkit-scrollbar { display: none; }
.part-group { display: flex; gap: var(--space-1); }
.part-tab {
  flex: none;
  min-height: 44px;
  padding: 0 var(--space-3);
  border: 1px solid transparent;
  border-radius: var(--radius-ctl);
  background: none;
  font-size: 14px;
  font-weight: 500;
  color: var(--c-text-2);
  white-space: nowrap;
  cursor: pointer;
}
.part-tab[aria-selected="true"] { border-color: var(--c-primary-dark); background: rgba(139,197,193,.2); color: var(--c-text); font-weight: 700; }
.part-tab:focus-visible { outline-offset: -2px; }
.part-divider { flex: none; width: 1px; margin: 10px var(--space-1); background: rgba(18,47,45,.25); }

/* The current part's controls; a long part scrolls here, never the page. */
.steps--phone .step-scroll { flex: 1 1 0; padding: var(--space-1) var(--space-4) var(--space-3); }
.steps--phone .part-heading,
.steps--phone .more-toggle { display: none; }
.steps--phone .more-shape { margin: 0; border: 0; }

/* A compact phone (§7.5): a slider's label, range and value on one row, so
   two controls fit the controls area; the targets stay 44 px. */
.steps--phone .sl { grid-template-columns: auto minmax(0, 1fr); align-items: center; column-gap: var(--space-3); }
.steps--phone .sl > .nf-info { grid-column: 1 / -1; }

/* Swatches on a phone: one row that scrolls sideways, the library, then My
   patterns, then + Image (C35), under slot cards of 44 px, so the slot cards
   and the swatches show together. Room on top for the delete dots. */
.swatch-strip { display: flex; flex-direction: column; gap: var(--space-3); }
.steps--phone .slot-card { min-height: 44px; padding: 3px 6px; }
.steps--phone .slot-thumb, .steps--phone .slot-swatch { width: 32px; height: 32px; }
.steps--phone .swatch-strip {
  flex-direction: row;
  gap: var(--space-2);
  margin: -8px calc(var(--space-4) * -1) 0;
  padding: 8px var(--space-4) 2px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}
.steps--phone .swatch-strip::-webkit-scrollbar { display: none; }
.steps--phone .swatch-strip .swatch-grid { display: flex; flex: none; gap: var(--space-1); }
.steps--phone .swatch-strip .swatch,
.steps--phone .swatch-strip .swatch-item { flex: none; width: 58px; padding-top: 2px; }
.steps--phone .swatch-strip .swatch-canvas,
.steps--phone .swatch-strip .swatch-none,
.steps--phone .swatch-strip .swatch-add { width: 52px; height: 52px; }
.steps--phone .swatch-strip .swatch-del { top: -12px; right: calc(50% - 46px); }
.steps--phone .mine-grid { padding-left: var(--space-2); border-left: 1px solid var(--c-border); }
/* The strip's labels stay for screen readers. */
.steps--phone .swatch-strip > .grid-label {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* A disabled export reads as unavailable, but stays legible. */
.print-panel .btn-primary:disabled {
  background: var(--c-border);
  border-color: var(--c-border);
  color: var(--c-text-2);
  opacity: 1;
}

/* ---------- Phase 2: pattern editor and images ---------- */

/* "+ Image" sits in the My patterns grid like a swatch. */
.swatch-add {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border: 1.5px dashed var(--c-input-border);
  border-radius: 6px;
  background: var(--c-input-bg);
  font-size: 24px;
  font-weight: 300;
  color: var(--c-text-2);
}
.swatch-add svg { width: 24px; height: 24px; }
.swatch-action:hover .swatch-add { border-color: var(--c-primary-light); color: var(--c-text); }
.swatch-action:disabled { opacity: .5; cursor: progress; }
/* One of My patterns: the swatch plus a small delete button on its corner. */
.swatch-item { position: relative; display: flex; flex-direction: column; min-width: 0; }
.swatch-del {
  position: absolute;
  top: -4px;
  right: calc(50% - 34px);
  z-index: 1;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}
.swatch-del-dot {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--c-input-bg);
  box-shadow: 0 0 0 1px var(--c-input-border), var(--shadow-1);
  font-size: 13px;
  line-height: 1;
  color: var(--c-text-2);
}
.swatch-del:hover .swatch-del-dot { color: var(--c-text); box-shadow: 0 0 0 1px var(--c-primary-light), var(--shadow-1); }
.swatch-del:focus-visible { outline: none; }
.swatch-del:focus-visible .swatch-del-dot { box-shadow: var(--focus-ring); }
.mine-confirm {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-ctl);
  background: var(--c-input-bg);
}
.mine-confirm[hidden] { display: none; }
.mine-confirm-text { font-size: 13px; color: var(--c-text); }
.mine-confirm-actions { display: flex; justify-content: flex-end; gap: var(--space-2); }
.image-msg { color: var(--c-text); }
.res-note { margin-top: calc(var(--space-1) * -1); }

/* Save to My patterns (pattern studio D48): the name form opens in place,
   under the swatches (here), in the dock's adjuster or under the 2D
   editor's head, never over the pot. */
.save-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-ctl);
  background: var(--c-input-bg);
}
.save-form[hidden] { display: none; }
.save-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.save-label { flex: 1 0 100%; font-size: 12px; font-weight: 600; color: var(--c-text-2); }
.save-name {
  flex: 1 1 8em;
  min-width: 0;
  height: var(--ctl-h);
  padding: 0 var(--space-3);
  border: 1px solid var(--c-input-border);
  border-radius: var(--radius-ctl);
  background: #fff;
  font: inherit;
  font-size: 14px;
  color: var(--c-text);
}
.save-name:focus-visible { border-color: var(--c-primary-dark); outline: none; box-shadow: var(--focus-ring); }
.save-row .btn { flex: none; padding: 0 var(--space-3); }
/* In the step's panel and sheet the field takes the width, the buttons sit under it on the right. */
.step-page .save-name { flex-basis: 100%; }
.step-page .save-cancel { margin-left: auto; }
.save-note { font-size: 12px; line-height: 1.35; color: var(--c-text-2); }
/* The phone sheet's area is short (about 120 px to scroll in): one row there too. */
.steps--phone .step-page .save-form { gap: 4px; padding: var(--space-2); }
.steps--phone .step-page .save-label {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.steps--phone .step-page .save-row { flex-wrap: nowrap; gap: 6px; }
.steps--phone .step-page .save-name { flex-basis: 8em; }
.steps--phone .step-page .save-cancel { margin-left: 0; }
/* The dock's: one row in the 76 px adjuster, the note under it. */
.save-form--compact { width: 100%; gap: 4px; padding: 0; border: 0; background: none; }
.save-form--compact .save-row { flex-wrap: nowrap; gap: 6px; }
.save-form--compact .save-note { height: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 16px; text-align: center; }
@media (pointer: coarse) {
  .save-name { height: 44px; font-size: 16px; } /* 16 px stops iOS zooming into the field */
  .save-row .btn { min-height: 44px; }
}

@media (pointer: coarse) {
  .swatch-add { width: 60px; height: 60px; }
  /* A 44 px target whose dot stays on the swatch's corner. */
  .swatch-del { top: -14px; right: calc(50% - 48px); width: 44px; height: 44px; }
  .swatch-del-dot { width: 24px; height: 24px; font-size: 15px; }
  .mine-confirm-actions .btn { min-height: 44px; }
}

/* ---------- The phone dock (mobile stage M3, M4, M9; ui/dock.js, ui/dial.js) ---------- */

.dock-host { display: none; }
.steps--dock .dock-host {
  order: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 14px 0 6px;
}
.dock-tip { padding: 4px var(--space-3) var(--space-2); }
.dock-tip:empty, .dock-tip:has(> .step-tip:empty) { display: none; }
.dock-tip .designs-tip { margin: 0; }

/* The grabber: tap or swipe up for all settings. Its target reaches up into
   the stage edge, which the pot never uses. */
.dock-grabber {
  position: absolute;
  top: 0;
  left: 30%;
  right: 30%;
  z-index: 1;
  display: block;
  height: 16px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: none;
}
.dock-grabber::before { content: ''; position: absolute; left: 0; right: 0; top: -16px; bottom: 0; }
.grabber-pill { display: block; width: 40px; height: 4px; margin: 6px auto 0; border-radius: 2px; background: rgba(18,47,45,.3); transition: background-color .15s ease, width .15s ease; }
.dock-grabber:hover .grabber-pill, .dock-grabber:focus-visible .grabber-pill { width: 52px; background: rgba(18,47,45,.55); }
.dock-grabber:focus-visible { outline-offset: -2px; }

/* The adjuster: one control for the chosen tool, always this tall, so the
   pot never jumps when the tool changes. */
.dock-adjust {
  height: 76px;
  display: flex;
  align-items: center;
  padding: 0 var(--space-2);
}

/* The tool row runs the whole width and fades out at the screen's edge; the
   step emblems below move between steps, so it keeps no Next (D49). */
.dock-row { display: flex; align-items: center; gap: var(--space-2); }
.dock-tools {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  gap: 6px;
  padding: 2px var(--space-2) 2px var(--space-3);
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 18px), transparent);
  mask-image: linear-gradient(to right, #000 calc(100% - 18px), transparent);
}
.dock-tools::-webkit-scrollbar { display: none; }
.dock-chip {
  flex: none;
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 46px;
  padding: 3px 12px;
  border: 1px solid var(--c-border);
  border-radius: 12px;
  background: #fff;
  text-align: left;
  cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease;
}
.dock-chip:focus-visible { outline-offset: -2px; }
.dock-chip-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.dock-chip-name { font-size: 11px; font-weight: 500; color: rgba(18,47,45,.7); white-space: nowrap; }
.dock-chip-value { max-width: 104px; overflow: hidden; text-overflow: ellipsis; font-size: 14px; font-weight: 650; color: var(--c-text); white-space: nowrap; font-variant-numeric: tabular-nums; }
.dock-chip-more { display: inline-flex; color: rgba(18,47,45,.6); }
.dock-chip[aria-selected="true"] { background: var(--c-primary-dark); border-color: var(--c-primary-dark); }
.dock-chip[aria-selected="true"] .dock-chip-name { color: rgba(255,255,255,.78); }
.dock-chip[aria-selected="true"] .dock-chip-value,
.dock-chip[aria-selected="true"] .dock-chip-more { color: #fff; }
.dock-chip-swatch { flex: none; display: block; width: 26px; height: 26px; border-radius: 6px; background: var(--c-border); box-shadow: 0 0 0 1px rgba(0,0,0,.12); }
.dock-chip-swatch.is-none,
.dock-swatch-none {
  background:
    linear-gradient(to top right, transparent calc(50% - 1px), var(--c-input-border) calc(50% - 1px), var(--c-input-border) calc(50% + 1px), transparent calc(50% + 1px)),
    #fff;
}
.dock-chip[aria-selected="true"] .dock-chip-swatch { box-shadow: 0 0 0 1.5px #fff; }

/* A short message over the stage edge ("Reading the image…"). */
.dock-msg {
  position: absolute;
  left: var(--space-3);
  right: var(--space-3);
  bottom: calc(100% + var(--space-2));
  padding: var(--space-2) var(--space-3);
  border-radius: 10px;
  background: var(--c-primary-dark);
  color: #fff;
  font-size: 13px;
  box-shadow: var(--shadow-3);
}

/* ---- The ruler dial ---- */
.dial {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: center;
  gap: var(--space-1);
  width: 100%;
}
.dial-step {
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--c-input-border);
  border-radius: 50%;
  background: #fff;
  font-size: 22px;
  line-height: 1;
  color: var(--c-text);
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: var(--shadow-1);
}
.dial-step:disabled { opacity: .35; cursor: default; box-shadow: none; }
.dial-mid { display: flex; flex-direction: column; min-width: 0; }
.dial-value-row { position: relative; display: flex; align-items: center; justify-content: center; height: 28px; }
.dial-extra { position: absolute; left: 0; top: 50%; transform: translateY(-50%); display: flex; }
.dial-extra .dock-lock { width: 36px; height: 36px; }
.dial-value {
  min-height: 28px;
  padding: 0 var(--space-2);
  border: 0;
  border-radius: 8px;
  background: none;
  font-size: 19px;
  font-weight: 700;
  color: var(--c-text);
  font-variant-numeric: tabular-nums;
  cursor: text;
}
.dial-value:hover { background: rgba(18,47,45,.06); }
.dial-unit { font-size: 13px; font-weight: 500; color: var(--c-text-2); }
.dial-input {
  width: 116px;
  height: 30px;
  border: 1px solid var(--c-primary-dark);
  border-radius: 8px;
  background: #fff;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.dial-input:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.dial-ruler { position: relative; height: 34px; cursor: ew-resize; touch-action: none; border-radius: 6px; }
.dial-ruler:focus-visible { outline-offset: 1px; }
.dial-canvas {
  display: block;
  -webkit-mask-image: linear-gradient(to right, transparent, #000 18%, #000 82%, transparent);
  mask-image: linear-gradient(to right, transparent, #000 18%, #000 82%, transparent);
}
.dial-mark {
  position: absolute;
  left: 50%;
  top: -2px;
  width: 3px;
  height: 24px;
  margin-left: -1.5px;
  border-radius: 2px;
  background: var(--c-primary-dark);
  pointer-events: none;
}
.dial-mark::before {
  content: '';
  position: absolute;
  left: 50%;
  top: -3px;
  margin-left: -5px;
  border: 5px solid transparent;
  border-top-color: var(--c-primary-dark);
}
.dial.is-dragging .dial-mark { background: color-mix(in srgb, var(--c-accent) 72%, #000); }
.dial.is-dragging .dial-mark::before { border-top-color: color-mix(in srgb, var(--c-accent) 72%, #000); }
.dial-note { height: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11.5px; line-height: 14px; color: var(--c-text-2); text-align: center; }
.dial.is-disabled .dial-value { color: var(--c-text-2); cursor: default; }
.dial.is-disabled .dial-ruler { cursor: default; }
.dial.is-disabled .dial-mark { background: rgba(18,47,45,.3); }
.dial.is-disabled .dial-mark::before { border-top-color: rgba(18,47,45,.3); }

/* ---- Options and hints ---- */
.dock-optbox { display: flex; flex-direction: column; gap: 6px; width: 100%; padding: 0 var(--space-1); }
.dock-options { display: flex; gap: 6px; }
.dock-opt {
  flex: 1 1 0;
  min-width: 0;
  min-height: 48px;
  padding: 0 var(--space-2);
  border: 1px solid var(--c-input-border);
  border-radius: 12px;
  background: #fff;
  font-size: 14px;
  font-weight: 600;
  color: var(--c-text);
  white-space: nowrap;
  cursor: pointer;
}
.dock-opt[aria-pressed="true"] { border-color: var(--c-primary-dark); background: rgba(139,197,193,.28); box-shadow: inset 0 0 0 1px var(--c-primary-dark); }
.dock-note { height: 16px; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; line-height: 16px; color: var(--c-text-2); text-align: center; }
.dock-hint { display: flex; align-items: center; gap: var(--space-3); width: 100%; padding: 0 var(--space-2); }
.dock-hint-text { flex: 1; min-width: 0; margin: 0; font-size: 13px; line-height: 1.35; color: var(--c-text); }
.dock-hint-btn { flex: none; min-height: 44px; padding: 0 var(--space-3); gap: 4px; }

/* ---- The swatch carousel (M9): the patterns first and large ---- */
.dock-carousel {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  width: calc(100% + var(--space-2) * 2);
  margin: 0 calc(var(--space-2) * -1);
  padding: 6px var(--space-3) 0;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
}
.dock-carousel::-webkit-scrollbar { display: none; }
.dock-swatch {
  position: relative;
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 60px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  scroll-snap-align: center;
}
.dock-swatch-canvas, .dock-swatch-none, .dock-swatch-add {
  display: block;
  width: 52px;
  height: 52px;
  border-radius: 10px;
  box-shadow: 0 0 0 1px rgba(0,0,0,.12);
  transition: box-shadow .12s ease, transform .12s ease;
}
.dock-swatch:active .dock-swatch-canvas { transform: scale(.96); }
.dock-swatch[aria-pressed="true"] .dock-swatch-canvas,
.dock-swatch[aria-pressed="true"] .dock-swatch-none { box-shadow: 0 0 0 2px #fff, 0 0 0 4.5px var(--c-accent); }
.dock-swatch:focus-visible { outline: none; }
.dock-swatch:focus-visible .dock-swatch-canvas,
.dock-swatch:focus-visible .dock-swatch-none,
.dock-swatch:focus-visible .dock-swatch-add { box-shadow: 0 0 0 2px #fff, 0 0 0 4.5px var(--c-primary-dark); }
.dock-swatch-name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; color: var(--c-text); }
.dock-swatch[aria-pressed="true"] .dock-swatch-name { font-weight: 700; }
.dock-swatch.is-first-mine { margin-left: var(--space-2); }
.dock-swatch.is-first-mine::before { content: ''; position: absolute; left: calc(var(--space-2) * -1 - 4px); top: 6px; height: 40px; width: 1px; background: var(--c-border); }
.dock-swatch-add {
  display: grid;
  place-items: center;
  border: 1.5px dashed var(--c-input-border);
  box-shadow: none;
  background: #fff;
  font-size: 22px;
  font-weight: 300;
  color: var(--c-text-2);
}
.dock-swatch-add svg { width: 26px; height: 26px; }
.dock-swatch--action:hover .dock-swatch-add { border-color: var(--c-primary-light); color: var(--c-text); }
.dock-swatch--action:disabled { opacity: .5; cursor: progress; }

/* ---- An open group in the tool row ---- */
.dock-lead { flex: none; display: flex; align-items: center; gap: 6px; }
.dock-tablist { flex: none; display: flex; gap: 6px; }
.dock-back {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 44px;
  min-height: 46px;
  margin-left: var(--space-2);
  padding: 0;
  border: 1px solid var(--c-border);
  border-radius: 12px;
  background: #fff;
  color: var(--c-text);
  cursor: pointer;
}
.dock-back:not([hidden]) + .dock-tools { padding-left: 0; }
.dock-back:focus-visible { outline-offset: -2px; }
.dock-modes { flex: none; display: flex; padding: 3px; border-radius: 12px; background: rgba(18,47,45,.07); }
.dock-mode {
  min-height: 40px;
  padding: 0 12px;
  border: 0;
  border-radius: 9px;
  background: none;
  font-size: 13px;
  font-weight: 600;
  color: var(--c-text-2);
  cursor: pointer;
}
.dock-mode[aria-pressed="true"] { background: #fff; color: var(--c-text); box-shadow: var(--shadow-1); }
.dock-mode:focus-visible { outline-offset: -2px; }
.dock-chip-more--group svg { transform: rotate(90deg); }

/* Five options (the blend and fade words) at a phone's width. */
.dock-options--many { gap: 4px; }
.dock-options--many .dock-opt { padding: 0 4px; font-size: 12px; white-space: normal; line-height: 1.15; }

/* The density's two faces, left of the dial's value (D40). */
.dock-face { display: flex; padding: 2px; border-radius: 8px; background: rgba(18,47,45,.07); }
.dock-face-btn {
  min-width: 34px;
  height: 26px;
  padding: 0 6px;
  border: 0;
  border-radius: 6px;
  background: none;
  font-size: 12px;
  font-weight: 600;
  color: var(--c-text-2);
  cursor: pointer;
}
.dock-face-btn[aria-pressed="true"] { background: #fff; color: var(--c-text); box-shadow: var(--shadow-1); }
@media (pointer: coarse) {
  /* A taller target that keeps the row's height. */
  .dock-face-btn { position: relative; }
  .dock-face-btn::after { content: ''; position: absolute; inset: -9px 0; }
}

/* ---- The Pattern step (ui/sections/pattern.js) ---- */
.pattern-about { margin-top: var(--space-1); }
.pattern-density { display: flex; flex-direction: column; gap: var(--space-2); }
.density-readout { margin: 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.density-pot { margin-top: calc(-1 * var(--space-1)); }
