:root {
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --bg: #ffffff;
  --label: #1d1d1f;
  --label-2: rgba(60, 60, 67, 0.62);
  --label-3: rgba(60, 60, 67, 0.36);
  --fill: rgba(120, 120, 128, 0.12);
  --fill-hover: rgba(120, 120, 128, 0.18);
  --glass: rgba(255, 255, 255, 0.72);
  --glass-strong: rgba(255, 255, 255, 0.9);
  --hairline: rgba(0, 0, 0, 0.08);
  --shadow: 0 0.5px 1px rgba(0, 0, 0, 0.06), 0 8px 28px rgba(0, 0, 0, 0.09), 0 24px 60px rgba(0, 0, 0, 0.06);
  --accent: #007aff;
  --accent-press: #0062cc;
  --knob: #fff;
  --seg-thumb: #fff;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --spring: cubic-bezier(0.34, 1.36, 0.64, 1);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--label);
  background: var(--bg);
  transition: background-color 0.6s var(--ease-out), color 0.4s;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}
body[data-bg="tahoe"] { background-color: #dfe6ef; }
/* Wallpaper layer: blurs and settles in when shown, blurs away when hidden */
.wallpaper {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background: center / cover no-repeat;
  opacity: 0; filter: blur(40px) saturate(1.3); transform: scale(1.12);
  transition: opacity 0.6s var(--ease-out), filter 1.1s var(--ease-out), transform 1.4s var(--ease-out);
  will-change: opacity, filter, transform;
}
.wallpaper.on { opacity: 1; filter: blur(0) saturate(1); transform: scale(1); }
body[data-bg="clear"] {
  background-color: #f4f4f6;
  background-image:
    conic-gradient(#e6e6ea 25%, transparent 0 50%, #e6e6ea 0 75%, transparent 0);
  background-size: 22px 22px;
}
button { font: inherit; color: inherit; }
svg { display: block; }
[hidden] { display: none !important; }

/* ---------- Stage ---------- */
.stage { position: fixed; inset: 0; z-index: 1; }
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.input {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  opacity: 0; resize: none; border: 0; padding: 0; margin: 0;
  font-size: 16px; color: transparent; background: transparent;
  caret-color: transparent; outline: none; cursor: text;
}
.hint {
  position: absolute; left: 0; right: 0;
  top: calc(50% + var(--hint-offset, 120px));
  margin: 0; text-align: center;
  font-size: 15px; letter-spacing: -0.01em;
  color: var(--label-3);
  pointer-events: none;
  transition: opacity 0.6s var(--ease-out), transform 0.6s var(--ease-out);
}
body[data-bg="tahoe"] .hint { color: rgba(255, 255, 255, 0.82); }
.hint.gone { opacity: 0; transform: translateY(6px); }

/* ---------- Top bar ---------- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0;
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: max(18px, env(safe-area-inset-top)) 22px 0;
  pointer-events: none;
  z-index: 5;
}
.topbar > * { pointer-events: auto; }
.brand { display: flex; align-items: baseline; gap: 7px; font-family: var(--font-display); }
.brand-name { font-weight: 600; font-size: 15px; letter-spacing: -0.015em; }
.brand-sub { font-size: 15px; color: var(--label-2); letter-spacing: -0.015em; }
.brand-block { display: flex; flex-direction: column; align-items: flex-start; gap: 7px; }
.credit { margin: 0; font-size: 12.5px; color: var(--label-3); letter-spacing: -0.005em; }
.credit a {
  color: var(--label-2); font-weight: 500; text-decoration: none;
  background: linear-gradient(currentColor, currentColor) 0 100% / 0 1px no-repeat;
  transition: background-size 0.3s var(--ease-out);
}
.credit a:hover, .credit a:focus-visible { background-size: 100% 1px; }

.pill-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 14px 0 11px;
  border: 0; border-radius: 999px;
  background: var(--fill);
  font-size: 13px; font-weight: 500; letter-spacing: -0.005em;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s var(--spring);
}
.pill-btn:hover { background: var(--fill-hover); }
.pill-btn:active { transform: scale(0.96); }
.pill-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.popover-anchor { position: relative; }
.popover {
  position: absolute; right: 0; top: calc(100% + 8px);
  width: 300px; padding: 6px;
  background: var(--glass-strong);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  backdrop-filter: saturate(180%) blur(24px);
  border: 0.5px solid var(--hairline);
  border-radius: 14px;
  box-shadow: var(--shadow);
  transform-origin: top right;
  animation: pop-in 0.28s var(--spring);
}
.popover a {
  display: flex; flex-direction: column; gap: 2px;
  padding: 9px 11px; border-radius: 9px;
  color: inherit; text-decoration: none;
}
.popover a:hover, .popover a:focus-visible { background: var(--fill); outline: none; }
.pop-title { font-size: 13px; font-weight: 600; letter-spacing: -0.01em; }
.pop-sub { font-size: 12px; color: var(--label-2); }
@keyframes pop-in { from { opacity: 0; transform: scale(0.94) translateY(-4px); } }

/* ---------- Dock ---------- */
.dock {
  position: fixed; left: 50%; bottom: max(28px, calc(env(safe-area-inset-bottom) + 12px));
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 4px;
  height: 60px; padding: 0 10px;
  background: rgba(255, 255, 255, 0.46);
  -webkit-backdrop-filter: saturate(190%) blur(36px);
  backdrop-filter: saturate(190%) blur(36px);
  border-radius: 22px; /* 12px controls + 10px inset */
  box-shadow:
    0 0 0 0.5px rgba(0, 0, 0, 0.07),
    0 1px 1px rgba(0, 0, 0, 0.03),
    0 6px 16px -4px rgba(0, 0, 0, 0.08),
    0 20px 44px -12px rgba(0, 0, 0, 0.12);
  z-index: 6;
  max-width: calc(100vw - 24px);
  transition: opacity 0.5s var(--ease-out), transform 0.5s var(--ease-out), box-shadow 0.45s var(--ease-out), background-color 0.45s var(--ease-out);
}
/* While typing the dock sinks back: no drop shadow, just its hairline */
body.typing .dock:not(:hover) {
  opacity: 0.5;
  box-shadow: 0 0 0 0.5px rgba(0, 0, 0, 0.06);
  background-color: rgba(255, 255, 255, 0.32);
}
body.loading .dock { opacity: 0; transform: translate(-50%, 16px); }
.dock-group { display: flex; align-items: center; gap: 2px; }
.dock-sep { width: 1px; height: 28px; background: rgba(0, 0, 0, 0.07); margin: 0 8px; flex: none; border-radius: 1px; }

.icon-btn {
  position: relative;
  display: grid; place-items: center;
  width: 40px; height: 40px; flex: none;
  border: 0; border-radius: 12px; padding: 0;
  background: transparent; color: #3a3a3c; cursor: pointer;
  transition: background 0.2s, transform 0.25s var(--spring), color 0.2s;
}
.icon-btn svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.65; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:hover { background: rgba(0, 0, 0, 0.045); color: var(--label); }
.icon-btn:active { transform: scale(0.9); background: rgba(0, 0, 0, 0.07); }
.icon-btn.small { width: 30px; height: 30px; border-radius: 999px; background: var(--fill); }
.icon-btn.small svg { width: 14px; height: 14px; stroke-width: 2.2; color: var(--label-2); }
.icon-btn.toggle { width: 34px; height: 34px; border-radius: 50%; margin-left: 6px; }
.icon-btn.toggle svg { width: 18px; height: 18px; }
.icon-btn.toggle[aria-pressed="true"] {
  color: #fff;
  background: conic-gradient(from 210deg, #49cbae, #aacf3b, #f3a13e, #f3637c, #d454c4, #9364ec, #6fa0e8, #49cbae);
  box-shadow: 0 2px 8px -1px rgba(211, 84, 196, 0.45), inset 0 0 0 0.5px rgba(255, 255, 255, 0.4);
}
.icon-btn.toggle[aria-pressed="true"] svg { fill: #fff; stroke: #fff; stroke-width: 1; animation: twinkle 0.5s var(--spring); }
@keyframes twinkle { 40% { transform: scale(1.25) rotate(12deg); } }
#replayBtn.spin svg { animation: nudge 0.45s var(--spring); }
@keyframes nudge { 35% { transform: translateX(2.5px) scale(0.9); } }
#helloBtn.spin svg { animation: wobble 0.7s var(--spring); }
@keyframes wobble { 30% { transform: rotate(-18deg) scale(1.08); } 60% { transform: rotate(10deg); } }

/* Ink swatches: selected = white gap + ring in the swatch's own colours */
.ink-group { gap: 0; }
.swatches { position: relative; display: flex; align-items: center; gap: 10px; padding: 0 6px; }
/* One ring for the selected ink. It floats between swatches (see moveRing),
   stretching like a drop as it goes, and cross-fades into the new colours. */
.swatch-ring {
  position: absolute; left: 0; top: 0; width: 34px; height: 34px; z-index: 1;
  pointer-events: none; will-change: transform;
  filter: drop-shadow(0 0 0.5px rgba(0, 0, 0, 0.28));
}
.swatch-ring i {
  position: absolute; inset: 0; border-radius: 50%;
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 2px), #000 calc(100% - 1.5px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 2px), #000 calc(100% - 1.5px));
  transition: opacity 0.35s var(--ease-out);
}
.swatch {
  position: relative; flex: none;
  width: 24px; height: 24px; padding: 0;
  border: 0; border-radius: 50%;
  background: var(--sw);
  cursor: pointer;
  box-shadow: inset 0 0 0 0.5px rgba(0, 0, 0, 0.12), inset 0 1px 1px rgba(255, 255, 255, 0.35);
  transition: transform 0.35s var(--spring);
}
.swatch:hover { transform: scale(1.12); }
.swatch[aria-checked="true"]:hover { transform: none; }
.swatch:active { transform: scale(0.9); }
.swatch.custom { background: conic-gradient(from 200deg, #f3637c, #f3a13e, #aacf3b, #49cbae, #64d2ff, #9364ec, #d454c4, #f3637c); }
.swatch.custom input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; border: 0; padding: 0; }
.swatch.custom .dot { position: absolute; inset: 6px; border-radius: 50%; background: var(--custom, #fff); box-shadow: 0 0 0 1.5px #fff; pointer-events: none; }
.swatch.custom { --ring: var(--custom); }


/* Weight: name · tick ruler · number, in one row. The name and number sit in
   fixed-width slots so morphing (Torph) and the name's own weight never shift
   the layout. A transparent range input over the ruler does the dragging. */
.weight {
  position: relative; display: flex; align-items: center; gap: 10px;
  height: 44px; padding: 0 8px; border-radius: 14px; cursor: ew-resize; /* 22 − 8 */
  touch-action: none;
}
.weight-name-slot { flex: none; width: 52px; display: flex; overflow: visible; }
.weight-name {
  font-size: 13px; letter-spacing: -0.01em; color: var(--label); white-space: nowrap;
  font-weight: var(--w, 500); font-variation-settings: "wght" var(--w, 500);
}
.weight-num {
  flex: none; width: 24px; text-align: right;
  font-size: 12px; font-weight: 500; color: var(--label-3); font-variant-numeric: tabular-nums; white-space: nowrap;
}
.weight-track { position: relative; flex: none; width: 112px; height: 44px; display: flex; align-items: center; }
.weight-ruler { position: relative; display: block; width: 100%; height: 16px; }
.weight-ruler .tick {
  position: absolute; top: 50%; width: 1.5px; height: 10px; margin: -5px 0 0 -0.75px; border-radius: 1px;
  background: var(--label-3); transform: scaleY(var(--k, 0.4)); transform-origin: 50% 50%;
  transition: background-color 0.2s;
}
.weight-ruler .tick.on { background: var(--label); }
.weight-mark {
  position: absolute; top: 50%; left: var(--p, 50%); width: 3px; height: 16px; margin: -8px 0 0 -1.5px;
  border-radius: 2px; background: var(--accent);
  transition: transform 0.25s var(--spring);
}
.weight:hover .weight-mark { transform: scaleY(1.12); }
.weight:active .weight-mark { transform: scaleY(1.3) scaleX(1.2); }
.weight-ruler.homing .weight-mark { transition: left 0.4s var(--spring), transform 0.25s var(--spring); }
.weight-ruler.homing .tick { transition: transform 0.4s var(--spring), background-color 0.2s; }
.weight input {
  position: absolute; inset: 0 -1px; width: calc(100% + 2px); height: 100%; margin: 0;
  opacity: 0; cursor: ew-resize; -webkit-appearance: none; appearance: none;
}
.weight input::-webkit-slider-thumb { -webkit-appearance: none; width: 2px; height: 44px; }
.weight input::-moz-range-thumb { width: 2px; height: 44px; border: 0; }
.weight:has(input:focus-visible) { box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.35); }

.chip-btn {
  display: inline-flex; align-items: center; justify-content: center;
  height: 36px; padding: 0 8px; flex: none;
  border: 0; border-radius: 10px; background: transparent; /* concentric: 22 − 12 */
  cursor: pointer;
  transition: background 0.2s, transform 0.25s var(--spring);
}
.chip-val { font-size: 13px; font-weight: 600; color: var(--label); letter-spacing: -0.01em; white-space: nowrap; font-variant-numeric: tabular-nums; }
#speedBtn { width: 48px; }
#bgBtn { width: 60px; }
.chip-btn:hover { background: rgba(0, 0, 0, 0.045); }
.chip-btn:active { transform: scale(0.94); background: rgba(0, 0, 0, 0.07); }

/* Phone-only ink button: a dot of the current ink that opens the colour tray */
.ink-btn { display: none; }
.ink-dot {
  width: 22px; height: 22px; border-radius: 50%; background: var(--ink, #9ab2d8);
  box-shadow: inset 0 0 0 0.5px rgba(0, 0, 0, 0.14), inset 0 1px 1px rgba(255, 255, 255, 0.35);
  transition: transform 0.35s var(--spring);
}
.dock.ink-open .ink-dot { transform: scale(0.82); box-shadow: 0 0 0 2px #fff, 0 0 0 3.5px var(--label-3); }

/* Export: a quiet tinted button, not a call to action */
.export-btn {
  white-space: nowrap;
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  height: 36px; padding: 0 13px 0 10px; flex: none; margin-left: 2px;
  border: 0; border-radius: 10px; /* concentric: 22px dock − 12px inset */
  background: var(--fill); color: var(--label);
  font-size: 13px; font-weight: 600; letter-spacing: -0.01em;
  cursor: pointer;
  transition: background 0.2s, transform 0.25s var(--spring);
}
.export-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; margin-top: -2px; }
.export-btn:hover { background: var(--fill-hover); }
.export-btn:active { transform: scale(0.94); }
.export-btn:disabled { opacity: 0.4; pointer-events: none; }
.export-btn.wide { height: 40px; padding: 0 18px 0 14px; gap: 6px; font-size: 14px; border-radius: 12px; }
.export-btn.wide svg { width: 17px; height: 17px; }

button:focus-visible, .swatch:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Tooltip ---------- */
.tip {
  position: fixed; z-index: 20; pointer-events: none;
  padding: 5px 9px; border-radius: 7px;
  background: var(--glass-strong);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  border: 0.5px solid var(--hairline);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.1);
  font-size: 12px; font-weight: 500; white-space: pre;
  opacity: 0; transform: translate(-50%, 4px);
  transition: opacity 0.15s, transform 0.2s var(--ease-out);
}
.tip.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Sheet ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 10;
  display: grid; place-items: center; padding: 16px;
  background: rgba(255, 255, 255, 0.28);
  -webkit-backdrop-filter: blur(14px) saturate(140%); backdrop-filter: blur(14px) saturate(140%);
  animation: fade-in 0.25s var(--ease-out);
}
.sheet-backdrop.closing { animation: fade-out 0.2s var(--ease-out) forwards; }
.sheet-backdrop.closing .sheet { animation: sheet-out 0.2s var(--ease-out) forwards; }
@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }
.sheet {
  width: min(460px, 100%);
  max-height: calc(100vh - 32px); overflow: auto;
  padding: 16px 18px 18px;
  background: rgba(255, 255, 255, 0.86);
  -webkit-backdrop-filter: saturate(180%) blur(28px); backdrop-filter: saturate(180%) blur(28px);
  border-radius: 26px; /* 14px preview + 12px inset, like the dock */
  box-shadow:
    0 0 0 0.5px rgba(0, 0, 0, 0.07),
    0 1px 1px rgba(0, 0, 0, 0.03),
    0 10px 24px -6px rgba(0, 0, 0, 0.1),
    0 32px 70px -16px rgba(0, 0, 0, 0.18);
  animation: sheet-in 0.42s var(--spring);
}
@keyframes sheet-in { from { opacity: 0; transform: scale(0.94) translateY(10px); } }
@keyframes sheet-out { to { opacity: 0; transform: scale(0.97) translateY(6px); } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet-head h2 { margin: 0; font-family: var(--font-display); font-size: 17px; font-weight: 600; letter-spacing: -0.015em; }

.segmented {
  position: relative;
  display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  padding: 2px; border-radius: 9px;
  background: var(--fill);
}
.segmented button {
  position: relative; z-index: 1;
  height: 28px; padding: 0 10px;
  border: 0; border-radius: 7px; background: transparent;
  font-size: 13px; font-weight: 500; letter-spacing: -0.01em; white-space: nowrap;
  cursor: pointer;
  transition: color 0.2s, opacity 0.2s;
}
.segmented button[aria-checked="true"] { font-weight: 600; }
.segmented button:disabled { opacity: 0.35; cursor: default; }
.segmented .thumb {
  position: absolute; z-index: 0; top: 2px; bottom: 2px; left: 0;
  border-radius: 7px; background: var(--seg-thumb);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12), 0 3px 1px rgba(0, 0, 0, 0.04), 0 0 0 0.5px rgba(0, 0, 0, 0.04);
  transition: transform 0.36s var(--spring), width 0.36s var(--spring);
}
.segmented.big { display: grid; width: 100%; }
.segmented.big button { height: 32px; font-size: 13.5px; }

.preview {
  margin: 14px 0 6px;
  height: 190px;
  display: grid; place-items: center;
  border-radius: 14px;
  background: #f4f4f6;
  overflow: hidden;
}
.preview-frame {
  position: relative;
  border-radius: 6px; overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 0 0 0.5px rgba(0, 0, 0, 0.08);
  transition: width 0.4s var(--spring), height 0.4s var(--spring);
}
.preview-frame.clear {
  background-image: conic-gradient(#e2e2e6 25%, #fff 0 50%, #e2e2e6 0 75%, #fff 0);
  background-size: 12px 12px;
}
.preview-frame canvas { position: absolute; inset: 0; width: 100%; height: 100%; }

.rows { display: flex; flex-direction: column; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 46px;
  border-bottom: 0.5px solid var(--hairline);
}
.row:last-child { border-bottom: 0; }
.row-label { font-size: 13px; font-weight: 500; color: var(--label-2); letter-spacing: -0.01em; }

.switch {
  position: relative; width: 46px; height: 28px; flex: none;
  border: 0; border-radius: 999px; padding: 0;
  background: var(--fill-hover); cursor: pointer;
  transition: background 0.25s;
}
.switch span {
  position: absolute; top: 2px; left: 2px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15), 0 1px 1px rgba(0, 0, 0, 0.12);
  transition: transform 0.3s var(--spring);
}
.switch[aria-checked="true"] { background: #34c759; }
.switch[aria-checked="true"] span { transform: translateX(18px); }

.sheet-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px; }
.meta { display: flex; flex-direction: column; gap: 1px; min-width: 0; font-size: 12.5px; line-height: 1.4; font-variant-numeric: tabular-nums; }
.meta-size { font-size: 17px; font-weight: 600; letter-spacing: -0.015em; line-height: 1.3; color: var(--label); transition: opacity 0.25s; }
.meta-size.pending { opacity: 0.35; }
.meta-size.none { display: none !important; }
.meta-spec { color: var(--label-2); }
.meta-note { color: var(--label-3); }
.meta-note:empty { display: none; }
.progress { margin-top: 16px; }
.progress-track { height: 6px; border-radius: 3px; background: var(--fill); overflow: hidden; }
.progress-bar {
  height: 100%; width: 0; border-radius: 3px;
  background: linear-gradient(90deg, #49cbae, #aacf3b, #f3a13e, #f3637c, #d454c4, #9364ec);
  background-size: 460px 100%;
  transition: width 0.15s linear;
}
.progress-row { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; font-size: 13px; color: var(--label-2); font-variant-numeric: tabular-nums; }
.link-btn { border: 0; background: none; color: var(--accent); font-size: 13px; font-weight: 500; cursor: pointer; padding: 4px; }
.sheet.busy .sheet-foot, .sheet.busy .rows, .sheet.busy .segmented.big { opacity: 0.45; pointer-events: none; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; top: max(18px, env(safe-area-inset-top));
  z-index: 30;
  padding: 9px 16px; border-radius: 999px;
  background: var(--glass-strong);
  -webkit-backdrop-filter: saturate(180%) blur(24px); backdrop-filter: saturate(180%) blur(24px);
  border: 0.5px solid var(--hairline);
  box-shadow: var(--shadow);
  font-size: 13px; font-weight: 500;
  opacity: 0; transform: translate(-50%, -12px) scale(0.96);
  pointer-events: none;
  transition: opacity 0.3s, transform 0.4s var(--spring);
}
.toast.show { opacity: 1; transform: translate(-50%, 0) scale(1); }

/* ---------- Loader ---------- */
.loader {
  position: fixed; inset: 0; z-index: 40;
  display: grid; place-items: center;
  background: #ffffff;
  transition: opacity 0.6s var(--ease-out), visibility 0.6s;
}
.loader.done { opacity: 0; visibility: hidden; }
.loader-inner { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.loader-track { width: 160px; height: 4px; border-radius: 2px; background: rgba(120, 120, 128, 0.16); overflow: hidden; }
.loader-bar {
  height: 100%; width: 0; border-radius: 2px;
  background: linear-gradient(90deg, #9ab2d8, #49cbae, #aacf3b, #f3a13e, #f3637c, #d454c4, #9364ec);
  background-size: 160px 100%;
  transition: width 0.2s linear;
}
.loader p { margin: 0; font-size: 13px; color: var(--label-2); font-variant-numeric: tabular-nums; }
/* just the bar: the progress text stays for screen readers, errors show */
.loader:not(.failed) p { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---------- Small screens ---------- */
.sheet:focus { outline: none; }
@media (max-width: 760px) {
  .topbar { padding-left: 18px; padding-right: 14px; }
  .brand-sub { display: none; }
  .brand-block { gap: 4px; }
  .pill-btn { height: 34px; padding: 0 12px; font-size: 13px; }
  /* One row of controls; the colours wait in a tray above it */
  .dock {
    flex-wrap: wrap; justify-content: space-between;
    width: calc(100vw - 20px); height: auto; padding: 6px; row-gap: 0; column-gap: 0;
    border-radius: 22px;
    bottom: max(10px, env(safe-area-inset-bottom));
  }
  .dock-sep { display: none; }
  .ink-btn { display: grid; } /* keeps .icon-btn's place-items: center */
  .ink-group {
    order: -1; width: 100%; height: 0; padding: 0 6px; overflow: hidden;
    justify-content: space-between; opacity: 0; transform: translateY(8px);
    transition: height 0.42s var(--spring), opacity 0.2s var(--ease-out), transform 0.42s var(--spring);
  }
  .dock.ink-open .ink-group { height: 48px; opacity: 1; transform: none; transition: height 0.42s var(--spring), opacity 0.3s 0.06s var(--ease-out), transform 0.42s var(--spring); }
  .swatches { gap: 0; padding: 0 2px; flex: 1; justify-content: space-between; margin-right: 10px; }
  .dock > .dock-group:first-child { gap: 0; }
  /* every control 40px tall, 6px in from the 22px dock edge -> 16px radius */
  .icon-btn { width: 40px; height: 40px; border-radius: 16px; }
  .icon-btn.toggle { width: 34px; height: 34px; margin-left: 0; }
  .weight { flex: 1; min-width: 0; height: 40px; padding: 0 8px; gap: 0; border-radius: 16px; }
  .weight-name-slot, .weight-num { display: none !important; } /* Torph sets an inline display */
  .weight-track { flex: 1; min-width: 0; width: auto; height: 40px; }
  .chip-btn { height: 40px; border-radius: 16px; }
  #speedBtn { width: 38px; }
  #bgBtn { width: 50px; }
  #exportBtn { width: 40px; height: 40px; padding: 0; margin-left: 2px; border-radius: 16px; }
  .export-label { display: none; }
  .sheet-foot { flex-direction: column; align-items: stretch; gap: 10px; }
  .sheet-foot .export-btn { width: 100%; margin: 0; }
}
/* touch: no hover tint left behind after a tap */
@media (hover: none) {
  .icon-btn:hover, .chip-btn:hover { background: transparent; }
  .export-btn:hover { background: var(--fill); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
