/* ============================================================================
   Scratchy - design tokens & chrome
   Calm, professional dark chrome; the playfulness lives in the canvas.
   Gradient appears in exactly two places: active tool pill + primary CTAs.
   ========================================================================== */
:root {
  --bg0: #0b0b10;
  --surface: #14141c;
  --surface-2: #1c1c26;
  --surface-3: #262633;
  --line: rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.12);
  --ink: #eceef6;
  --muted: #8d90a8;
  --accent: #7c5cff;
  --accent-2: #38d6ff;
  --accent-grad: linear-gradient(135deg, #7c5cff, #38b6ff);
  --accent-tint: rgba(124, 92, 255, 0.16);
  --good: #35d99a;
  --danger: #ff5470;
  --radius: 14px;
  --radius-lg: 20px;
  --touch: 48px;
  --bar-h: 60px;
  --shadow: 0 10px 34px rgba(0, 0, 0, 0.5);
  --font-display: ui-rounded, "SF Pro Rounded", "Segoe UI Rounded", system-ui, sans-serif;
  --font-ui: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  --ease: cubic-bezier(0.3, 0.9, 0.4, 1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  /* --app-height (set in index.html) pins us to the real visible viewport -
     see the comment there for why 100% alone isn't safe on iOS standalone. */
  margin: 0; height: var(--app-height, 100%); width: 100%;
  overflow: hidden; overscroll-behavior: none;
  background: var(--bg0); color: var(--ink);
  font-family: var(--font-ui); font-size: 15px;
  touch-action: none; user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none; /* iOS long-press callout would cancel spiral holds */
  position: fixed; inset: 0;
}
button { font-family: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
.icn { display: block; flex: none; }

/* ---------------------------------------------------------------- stage */
#backdrop {
  position: absolute; inset: 0;
  /* lighter than the canvas so the black scratch board reads as a distinct
     sheet floating on the surface */
  background: radial-gradient(1200px 820px at 50% 38%, #3a3a48 0%, #262632 74%);
}
#stage { position: absolute; inset: 0; overflow: hidden; }
#board {
  position: absolute; top: 0; left: 0;
  transform-origin: 0 0; will-change: transform;
  box-shadow: 0 16px 70px rgba(0, 0, 0, 0.65);
  border-radius: 2px;
}
#board canvas { position: absolute; top: 0; left: 0; display: block; touch-action: none; }
#reveal { z-index: 1; } #scratch { z-index: 2; } #overlay { z-index: 3; pointer-events: none; }

#stencilLayer { position: absolute; inset: 0; z-index: 20; pointer-events: none; }
#stencilControls {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 22px);
  display: flex; gap: 10px; pointer-events: auto;
}

/* desktop brush cursor ring */
#cursorRing {
  position: absolute; left: 0; top: 0; z-index: 15; pointer-events: none;
  border: 1.5px solid rgba(255, 255, 255, 0.85); border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.55);
  will-change: transform; /* positioned via transform from JS */
}

/* first-scratch shimmer hint */
#magicLoading {
  position: fixed; inset: 0; z-index: 80; display: grid; place-items: center;
  background: rgba(6, 6, 14, 0.45); backdrop-filter: blur(2px);
}

/* ---- Scratchy loading spinner: a rainbow felt-tip line traces a hand-wobbly
   circle, drawing forward and erasing behind - like a pen actually scratching
   it out, not a wedge sliding over a fixed ring. One shared <mask> (defined
   once in index.html) drives every instance in sync; only the size differs. */
.scratchy-spinner {
  width: var(--sp-size); height: var(--sp-size);
  position: relative; margin: 0 auto;
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.4));
}
.scratchy-spinner--lg { --sp-size: 72px; }
.scratchy-spinner--sm { --sp-size: 34px; margin: 4px auto 2px; }

/* The SVG path is visible (not inside a <mask>) so stroke-dashoffset
   animation works in WebKit. A rotating SVG linearGradient (SMIL
   <animateTransform>) gives the rainbow; CSS animates the dash. */
.scratchy-spinner__svg {
  width: 100%; height: 100%; overflow: visible;
}
.scratchy-spinner__stroke {
  stroke-dasharray: 0.34 0.66;
  animation: scratchyDraw 1.8s linear infinite;
}
@keyframes scratchyDraw { to { stroke-dashoffset: -1; } }

#hint {
  position: absolute; z-index: 14; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  display: flex; align-items: center; gap: 12px; white-space: nowrap;
  color: rgba(255, 255, 255, 0.85); font-family: var(--font-display);
  font-size: 20px; font-weight: 700; letter-spacing: 0.2px;
  pointer-events: none;
  animation: hintPulse 2.2s var(--ease) infinite;
}
@keyframes hintPulse {
  0%, 100% { opacity: 0.5; transform: translate(-50%, -50%) scale(1); }
  50% { opacity: 1; transform: translate(-50%, -50%) scale(1.06); }
}

/* transient zoom chip */
#zoomChip {
  position: absolute; z-index: 40; top: calc(var(--bar-h) + env(safe-area-inset-top, 0px) + 10px);
  left: 50%; transform: translateX(-50%);
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  color: var(--ink); font-weight: 600; font-size: 13px; padding: 7px 14px;
  cursor: pointer; font-variant-numeric: tabular-nums;
  transition: opacity 0.2s;
}

/* Magic Picture find-the-creatures progress */

/* ---------------------------------------------------------------- top bar */
#topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 30;
  height: calc(var(--bar-h) + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) max(10px, env(safe-area-inset-right, 0px)) 4px max(10px, env(safe-area-inset-left, 0px));
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: color-mix(in srgb, var(--bg0) 86%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.bar-group { display: flex; align-items: center; gap: 6px; min-width: 0; }
.bar-group.center { flex: 1; justify-content: center; }

#logo {
  font-family: var(--font-display); font-weight: 800; font-size: 17px;
  letter-spacing: 0.3px; color: var(--muted); padding: 0 6px;
}

.bar-btn {
  display: flex; align-items: center; gap: 7px;
  height: 44px; padding: 0 14px; border: 0; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 999px; font-size: 14px; font-weight: 600;
  transition: transform 0.12s var(--ease), background 0.15s;
}
.bar-btn:active { transform: scale(0.96); background: var(--surface-3); }

.icon-btn {
  width: 46px; height: 46px; flex: none;
  display: grid; place-items: center;
  border: 1px solid transparent; border-radius: 12px;
  background: transparent; cursor: pointer;
  transition: transform 0.12s var(--ease), background 0.15s, border-color 0.15s;
}
.icon-btn:active { transform: scale(0.94); background: var(--surface-2); }
.icon-btn:disabled { opacity: 0.35; cursor: default; }
@media (hover: hover) {
  .icon-btn:hover { background: var(--surface-2); border-color: var(--line); }
  .bar-btn:hover { background: var(--surface-3); }
}

/* tool switcher - sliding pill */
#toolSwitcher {
  position: relative; display: flex; gap: 2px;
  background: var(--surface); border: 1px solid var(--line);
  padding: 3px; border-radius: 999px;
}
#toolPill {
  position: absolute; top: 3px; bottom: 3px; left: 3px; width: 48px;
  border-radius: 999px; background: var(--accent-grad);
  box-shadow: 0 2px 12px rgba(124, 92, 255, 0.45);
  transition: transform 0.2s var(--ease), width 0.2s var(--ease);
}
.tool-btn {
  position: relative; z-index: 1;
  display: flex; align-items: center; justify-content: center; gap: 7px;
  height: 46px; min-width: 52px; padding: 0 13px;
  border: 0; border-radius: 999px; background: transparent; cursor: pointer;
  color: var(--muted); font-size: 14px; font-weight: 600;
  transition: color 0.15s;
}
.tool-btn.active { color: #fff; }
.tool-btn .lbl { display: none; }
@media (min-width: 900px) { .tool-btn .lbl { display: inline; } }

/* current pattern dot */
#patternDot {
  width: 26px; height: 26px; border-radius: 50%;
  background-size: cover; background-position: center;
  border: 2px solid var(--line-strong); display: block;
}
#patternBtn[data-open="1"] #patternDot, .icon-btn[data-open="1"] { border-color: var(--accent); }

/* premium locks */
[data-locked="1"] { position: relative; }
.lock-badge {
  position: absolute; top: -3px; right: -3px; z-index: 2;
  width: 17px; height: 17px; border-radius: 50%;
  background: var(--surface-3); border: 1px solid var(--line-strong);
  display: grid; place-items: center; color: var(--muted);
  pointer-events: none;
}

/* responsive top bar */
.show-sm { display: none; }
@media (max-width: 599px) {
  #logo { display: none; }
  .hide-sm { display: none; }
  .show-sm { display: flex; }
  .bar-btn .lbl { display: none; }
  .bar-btn { padding: 0 12px; }
}

/* ---------------------------------------------------------------- popovers */
.popover {
  position: absolute; z-index: 45;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 12px;
  box-shadow: var(--shadow);
  transform-origin: top right;
  animation: popIn 0.16s var(--ease);
}
@keyframes popIn { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } }
/* Side popovers are pinned with translateY(-50%); the plain popIn above
   animates `transform: scale()`, which both drops that offset mid-animation
   (panel opens low, snaps up) and shifts the edges as it scales. Fade only -
   no transform - so the panel appears exactly where it stays, no movement. */
@keyframes popInSide { from { opacity: 0; } to { opacity: 1; } }

/* "scroll for more" cue: a down chevron pinned to the bottom of a scroll area
   that fades out at the end. Sticky + negative margin = zero layout footprint;
   pointer-events:none so taps reach the content under it. */
.scroll-hint {
  position: sticky; bottom: 0; z-index: 2;
  height: 30px; margin-top: -30px;
  display: flex; align-items: flex-end; justify-content: center;
  pointer-events: none; opacity: 0; transition: opacity 0.2s;
  background: linear-gradient(to bottom, transparent, var(--surface));
  color: var(--accent-2);
}
.scroll-hint.show { opacity: 1; }
.scroll-hint svg { width: 18px; height: 18px; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.55)); animation: scrollHintBob 1.5s ease-in-out infinite; }
@keyframes scrollHintBob { 0%, 100% { transform: translateY(-1px); } 50% { transform: translateY(3px); } }
@media (prefers-reduced-motion: reduce) { .scroll-hint svg { animation: none; } }
.popover h3 {
  margin: 2px 4px 10px; font-size: 13px; font-weight: 600;
  color: var(--muted); letter-spacing: 0.4px; text-transform: uppercase;
}
#patternPopover { top: calc(var(--bar-h) + env(safe-area-inset-top, 0px) + 8px); right: 10px; }
#patternGrid { display: grid; grid-template-columns: repeat(3, 84px); gap: 8px; }
.pattern-cell {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 10px 4px 8px; border: 1px solid transparent; border-radius: var(--radius);
  background: transparent; cursor: pointer; font-size: 12px; color: var(--muted);
  transition: background 0.15s, border-color 0.15s, transform 0.12s var(--ease);
}
.pattern-cell:active { transform: scale(0.95); }
.pattern-cell .dot {
  width: 44px; height: 44px; border-radius: 50%;
  background-size: cover; background-position: center;
  border: 2px solid var(--line-strong);
  display: grid; place-items: center; color: var(--ink);
}
.pattern-cell.active { background: var(--accent-tint); border-color: var(--accent); color: var(--ink); }
.pattern-cell.active .dot { border-color: var(--accent); }

.popover.menu { display: flex; flex-direction: column; gap: 2px; min-width: 200px; }
#morePopover,
#sizePopover { top: calc(var(--bar-h) + env(safe-area-inset-top, 0px) + 8px); right: 10px; }
.menu-row {
  display: flex; align-items: center; gap: 12px;
  min-height: var(--touch); padding: 0 12px;
  border: 0; border-radius: 10px; background: transparent; cursor: pointer;
  font-size: 15px; font-weight: 500; color: var(--ink); text-align: left;
  transition: background 0.12s;
}
.menu-row:active { background: var(--surface-3); }
@media (hover: hover) { .menu-row:hover { background: var(--surface-2); } }
.menu-row.active { background: var(--accent-tint); color: var(--ink); }
.menu-row.active .icn { color: var(--accent-2); }

/* phone: popovers become bottom sheets */
@media (max-width: 599px) {
  #patternPopover, #morePopover {
    top: auto; right: 0; left: 0;
    bottom: 0; border-radius: 22px 22px 0 0;
    padding: 16px 16px calc(env(safe-area-inset-bottom, 0px) + 16px);
    transform-origin: bottom center;
    animation: sheetUp 0.22s var(--ease);
  }
  #patternGrid { grid-template-columns: repeat(3, 1fr); }
}
@keyframes sheetUp { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: none; } }

/* ---------------------------------------------------------------- sidebar */
#sidebar {
  position: absolute; z-index: 30;
  left: calc(env(safe-area-inset-left, 0px) + 10px);
  /* top is owned by Viewport._positionSidebar (viewport.js), which centers
     the sidebar on wherever the canvas actually rests and - the one hard
     rule - never lets it start above the canvas, even when the sidebar's
     content (e.g. Free Draw's extra colour/texture rows) is taller than a
     small board. This 50%/translateY is only the fallback for the brief
     window before the first fitToScreen() runs. */
  top: 50%;
  transform: translateY(-50%);
  max-height: calc(100% - var(--bar-h) - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 20px);
  overflow-y: auto;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--line);
  padding: 12px 7px; border-radius: 24px;
  box-shadow: var(--shadow);
}
/* margin-bottom clears the thumb's own overflow below the track (26px thumb,
   `bottom:0%` + translateY(50%) center-pins it ON the track's bottom edge at
   minimum brush size, so it overhangs ~13px past the track), PLUS the
   opacity slider immediately below it overhangs ~13px above ITS OWN track
   at max opacity (`bottom:100%`, same center-pin trick) - the two thumbs
   face each other, so clearing one thumb's overflow (18px) wasn't enough;
   both can overflow toward each other at once. */
#brushSlider { height: 168px; width: 40px; display: grid; place-items: center; touch-action: none; margin-bottom: 28px; }
#brushTrack { position: relative; width: 10px; height: 100%; background: var(--surface-3); border-radius: 999px; }
#brushFill { position: absolute; bottom: 0; left: 0; right: 0; border-radius: 999px; background: var(--accent); opacity: 0.8; }
#brushThumb {
  position: absolute; left: 50%; transform: translate(-50%, 50%);
  width: 26px; height: 26px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}
/* Brush opacity (Free Draw only) - a checkerboard track makes "transparent
   to solid" legible at a glance, same fill/thumb shape as the size slider.
   margin-bottom matches #brushSlider's fix: the 26px thumb overhangs ~13px
   below the track at minimum opacity, so 4px let it overlap the row below. */
#opacitySlider { height: 100px; width: 40px; display: grid; place-items: center; touch-action: none; margin-bottom: 18px; }
#opacityTrack {
  /* No overflow:hidden here - border-radius already clips the checkerboard
     background to the pill, and #opacityFill rounds itself, so clipping isn't
     needed; it only clipped the thumb (a child of the track), cutting off its
     top at high opacity. */
  position: relative; width: 10px; height: 100%; border-radius: 999px;
  background-color: var(--surface-3);
  background-image: repeating-conic-gradient(rgba(255, 255, 255, 0.18) 0% 25%, transparent 0% 50%);
  background-size: 6px 6px;
}
#opacityFill { position: absolute; bottom: 0; left: 0; right: 0; border-radius: 999px; background: var(--accent); opacity: 0.8; }
#opacityThumb {
  position: absolute; left: 50%; transform: translate(-50%, 50%);
  width: 26px; height: 26px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}
.side-btn {
  width: 44px; height: 44px; flex: none;
  display: grid; place-items: center;
  border: 1px solid transparent; border-radius: 12px;
  background: transparent; cursor: pointer; color: var(--ink);
  transition: transform 0.12s var(--ease), background 0.15s, color 0.15s;
}
.side-btn:active { transform: scale(0.94); background: var(--surface-2); }
@media (hover: hover) { .side-btn:hover { background: var(--surface-2); border-color: var(--line); } }
/* highlight a sidebar button while its popover is open (colour / brush) */
.side-btn.on, .side-btn[data-open="1"] { background: var(--accent-tint); color: var(--accent-2); border-color: var(--accent); }
.side-btn:disabled { opacity: 0.32; cursor: default; }

#brushPreview {
  position: absolute; z-index: 31; pointer-events: none;
  left: calc(env(safe-area-inset-left, 0px) + 76px); top: 50%; transform: translateY(-50%);
  display: flex; align-items: center; gap: 12px;
}
#brushPreviewDot { border-radius: 50%; background: radial-gradient(circle, #fff, #cfd3ff); box-shadow: 0 0 22px rgba(124, 92, 255, 0.55); }
#brushPreviewVal {
  font-variant-numeric: tabular-nums; font-weight: 700; font-size: 15px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 5px 11px;
}

#sidePill {
  position: absolute; z-index: 40; pointer-events: none;
  left: calc(env(safe-area-inset-left, 0px) + 76px); top: 50%; transform: translateY(-50%);
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  padding: 8px 14px; font-weight: 600; font-size: 14px;
  box-shadow: var(--shadow); opacity: 0; transition: opacity 0.15s;
}
#sidePill.show { opacity: 1; }
#symmetryTray,
#textureTray { left: calc(env(safe-area-inset-left, 0px) + 74px); top: 50%; transform: translateY(-50%); transform-origin: left center; animation: popInSide 0.16s var(--ease); }
#textureTray { max-height: min(74vh, 560px); width: min(430px, 92vw); max-width: calc(100vw - 90px); }

/* ---------------------------------------------------------------- trays */
.tray {
  position: absolute; z-index: 29;
  left: 50%; transform: translateX(-50%);
  top: calc(var(--bar-h) + env(safe-area-inset-top, 0px) + 8px);
  /* multi-row sideways-scrolling grid: see many shapes at once */
  display: grid; grid-auto-flow: column; grid-template-rows: repeat(4, auto);
  gap: 6px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 8px;
  box-shadow: var(--shadow);
  max-width: calc(100vw - 20px); overflow-x: auto; -webkit-overflow-scrolling: touch;
  touch-action: pan-x; /* global touch-action:none would make the tray unscrollable */
  animation: popInTray 0.16s var(--ease);
}
@keyframes popInTray { from { opacity: 0; transform: translateX(-50%) scale(0.96); } to { opacity: 1; transform: translateX(-50%) scale(1); } }
#spiralTray { grid-template-rows: repeat(3, auto); }
.tray .tray-divider { grid-row: 1 / -1; }
/* right-edge fade hints that more shapes are off-screen */
.tray.overflowing {
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 44px), transparent);
  mask-image: linear-gradient(to right, #000 calc(100% - 44px), transparent);
}
.tray-item {
  width: 62px; min-width: 62px; height: 56px;
  display: grid; place-items: center;
  border: 1px solid transparent; border-radius: 12px;
  background: transparent; cursor: pointer; color: var(--muted);
  transition: background 0.15s, color 0.15s, transform 0.12s var(--ease), border-color 0.15s;
}
.tray-item:active { transform: scale(0.93); }
@media (hover: hover) { .tray-item:hover { background: var(--surface-2); } }
.tray-item.active { background: var(--accent-tint); color: var(--ink); border-color: var(--accent); }
.tray.shapes svg { width: 40px; height: 40px; }
.tray-item.emoji { font-size: 30px; line-height: 1; }
.tray-divider { width: 1px; min-width: 1px; align-self: stretch; margin: 2px 3px; background: var(--line-strong); }
.tray-item.any-emoji {
  border: 1.5px dashed var(--accent); color: var(--accent-2);
  display: flex; flex-direction: column; gap: 2px;
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.2px;
}
#emojiInput {
  width: 100%; box-sizing: border-box; margin: 4px 0 16px;
  font-size: 44px; text-align: center; padding: 10px; min-height: 76px;
  background: var(--surface-2); border: 1px solid var(--line-strong);
  border-radius: 14px; color: var(--ink);
}
#emojiInput::placeholder { font-size: 15px; color: var(--muted); font-family: var(--font-ui); }
#emojiInput:focus { outline: 2px solid var(--accent); }

/* ---------------------------------------------------------------- canvas maker */
.maker-body {
  display: flex; gap: 20px; flex-wrap: wrap;
  max-width: 720px; margin: 0 auto; justify-content: center;
}
.maker-preview-wrap { flex: none; display: flex; flex-direction: column; gap: 8px; max-width: min(300px, 46vw); }
#makerPreview {
  width: 100%; border-radius: 12px;
  border: 1px solid var(--line-strong); background: #000;
  touch-action: none; cursor: crosshair; /* paintable in Paint style */
}
#makerHint { margin: 0; text-align: center; }
.maker-controls { flex: 1; min-width: 260px; max-width: 380px; }
.maker-controls h4 { margin: 4px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); }
#makerPalette { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.pal-dot {
  width: 38px; height: 38px; border-radius: 50%; cursor: pointer;
  border: 3px solid transparent; padding: 0;
  transition: transform 0.12s var(--ease), border-color 0.12s;
}
.pal-dot.on { border-color: #fff; transform: scale(1.12); }
.chip-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.style-chip {
  border: 1px solid var(--line-strong); background: var(--surface-2); color: var(--muted);
  border-radius: 999px; padding: 9px 16px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.style-chip.on { background: var(--accent-tint); border-color: var(--accent); color: var(--ink); }
.maker-slider { display: block; font-size: 13.5px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.maker-slider input {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 44px; background: transparent; display: block;
  touch-action: pan-x; /* global touch-action:none would break the drag */
}
.maker-slider input::-webkit-slider-runnable-track {
  height: 8px; border-radius: 999px; background: var(--surface-3);
}
.maker-slider input::-webkit-slider-thumb {
  -webkit-appearance: none; width: 28px; height: 28px; border-radius: 50%;
  background: #fff; border: 3px solid var(--accent); margin-top: -10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}
.maker-slider input::-moz-range-track { height: 8px; border-radius: 999px; background: var(--surface-3); }
.maker-slider input::-moz-range-thumb {
  width: 24px; height: 24px; border-radius: 50%;
  background: #fff; border: 3px solid var(--accent);
}
.maker-controls .row { margin-bottom: 8px; }
.save-strong { border-color: var(--accent) !important; color: var(--accent-2) !important; }
#makerShuffle:active .icn { animation: wiggle 0.3s var(--ease); }
@keyframes wiggle {
  0%, 100% { transform: rotate(0); }
  30% { transform: rotate(-18deg) scale(1.2); }
  65% { transform: rotate(14deg) scale(1.15); }
}
#makerSaved { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.saved-canvas { position: relative; }
.saved-canvas canvas { width: 56px; height: 56px; border-radius: 50%; border: 2px solid var(--line-strong); display: block; }
.saved-canvas .del.arm { background: var(--danger); border-color: var(--danger); color: #fff; }
.saved-canvas .del {
  position: absolute; top: -6px; right: -6px; width: 20px; height: 20px;
  border-radius: 50%; border: 1px solid var(--line-strong); cursor: pointer;
  background: var(--surface-3); color: var(--muted); display: grid; place-items: center;
}
.tray.shapes svg path, .tray.shapes svg circle { fill: none; stroke: currentColor; stroke-width: 6; stroke-linejoin: round; stroke-linecap: round; }
.tray.shapes .tray-item.active svg { color: var(--accent-2); }

.chip-btn {
  display: flex; align-items: center; gap: 8px;
  border: 0; cursor: pointer; font-weight: 700; font-size: 16px;
  padding: 0 20px; height: var(--touch); border-radius: 999px;
  box-shadow: var(--shadow); color: #0b0b10;
  transition: transform 0.12s var(--ease);
}
.chip-btn.done { background: var(--good); }
.chip-btn.fill { background: linear-gradient(135deg, #ffd23a, #ff9d3a); }
.chip-btn:active { transform: scale(0.95); }

/* ------------------------------------------------ Mystery Card recipient */
/* A visitor opening a shared #c= link gets a sealed card and this bar; the
   studio chrome (sidebar tools, new/pattern buttons) is hidden - they're
   here to scratch one card, not to draw. */
/* Flip: a labelled pill at the bottom, where a kid will actually find it. */
#flipBtn {
  position: absolute; z-index: 40; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line-strong);
  color: var(--ink); font-family: var(--font-display);
  font-size: 15px; font-weight: 800; white-space: nowrap;
  padding: 11px 20px 11px 16px; border-radius: 999px; box-shadow: var(--shadow);
  cursor: pointer;
}
#flipBtn:active { transform: translateX(-50%) scale(0.95); }
#flipBtn svg { color: var(--accent-2); }
#flipBtn[hidden] { display: none; }
/* the recipient of a card gets a stripped-back studio - no view controls */
body.cardview #flipBtn { display: none; }

/* Squiggle two-player: whose-turn prompt, and the pass-over screen.
   Lives at the TOP: the bottom is taken by the flip pill, and a full-width
   bar down there also covered the sidebar's last button on a phone. It wraps
   to two rows rather than squeezing the button - the prompt plus "Pass it
   over" is wider than a phone screen, which clipped the button's label. */
#squiggleBar {
  position: absolute; z-index: 41; left: 50%; transform: translateX(-50%);
  top: calc(var(--bar-h) + env(safe-area-inset-top, 0px) + 12px);
  display: flex; align-items: center; justify-content: center;
  flex-wrap: wrap; gap: 8px 12px; text-align: center;
  background: var(--surface); border: 1px solid var(--line-strong);
  color: var(--ink); font-family: var(--font-display);
  font-size: 15px; font-weight: 700; line-height: 1.25;
  padding: 10px 16px; border-radius: 22px; box-shadow: var(--shadow);
  /* max-content, capped: without it the absolutely-positioned box shrink-wraps
     far narrower than the room available and breaks the prompt across lines */
  width: max-content; max-width: min(94vw, 560px);
}
#squiggleBar[hidden] { display: none; }
#squiggleBarText { min-width: 0; }
#squigglePass { white-space: nowrap; flex: 0 0 auto; }
.fullscreen-veil {
  position: fixed; inset: 0; z-index: 90;
  display: grid; place-items: center; padding: 24px;
  background: rgba(8, 8, 16, 0.86); backdrop-filter: blur(6px);
}
.fullscreen-veil[hidden] { display: none; }
.handover-card {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  text-align: center; max-width: 420px;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: 22px; padding: 30px 26px; box-shadow: var(--shadow);
}
.handover-card svg { color: var(--accent-2); }
.handover-card h2 { font-family: var(--font-display); font-size: 26px; margin: 0; }
.handover-card .big-btn { margin-top: 6px; }

#cardBar {
  position: absolute; z-index: 40; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  pointer-events: none;
}
#cardMsg {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line-strong);
  color: var(--ink); font-family: var(--font-display);
  font-size: 16px; font-weight: 700; white-space: nowrap;
  padding: 10px 18px; border-radius: 999px; box-shadow: var(--shadow);
}
#cardMsg svg { color: var(--accent-2); }
#cardNote {
  max-width: min(340px, 84vw); text-align: center;
  background: var(--surface); border: 1px solid var(--line);
  color: var(--muted); font-size: 14px; line-height: 1.4;
  padding: 8px 14px; border-radius: 14px; box-shadow: var(--shadow);
}
#cardActions {
  display: flex; gap: 8px; pointer-events: auto;
  flex-wrap: wrap; justify-content: center; max-width: 94vw;
}
#cardActions .chip-btn { color: #0b0b10; white-space: nowrap; flex: none; padding: 0 16px; }

/* compose sheet fields */
.card-field { display: block; margin: 0 0 12px; text-align: left; }
.card-field > span {
  display: block; font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--muted); margin-bottom: 5px;
}
.card-field input, .card-field textarea {
  width: 100%; box-sizing: border-box; resize: none;
  background: var(--surface-2); border: 1px solid var(--line-strong); color: var(--ink);
  border-radius: 10px; padding: 10px 12px; font: inherit; font-size: 15px;
  user-select: text; -webkit-user-select: text;
}
.card-field input:focus, .card-field textarea:focus { outline: 2px solid var(--accent); }
#cardSendGo { width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 4px; }
#cardActions #cardReplay { background: var(--accent-grad); color: #fff; }
body.cardview #sidebar > :not(#brushSlider),
body.cardview #topbar .bar-group.center,
body.cardview #topbar .bar-group.right { display: none; }

/* ---------------------------------------------------------------- toasts */
.toast {
  position: absolute; z-index: 60; left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 24px);
  transform: translateX(-50%) translateY(6px);
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line);
  color: var(--ink); padding: 10px 18px; border-radius: 999px;
  font-weight: 600; font-size: 14px;
  box-shadow: var(--shadow); opacity: 0;
  transition: opacity 0.18s, transform 0.18s var(--ease);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.sync-status {
  position: absolute; bottom: calc(env(safe-area-inset-bottom, 0px) + 10px);
  right: 12px; z-index: 40;
  font-size: 12px; color: var(--muted);
  background: var(--surface); border: 1px solid var(--line);
  padding: 5px 11px; border-radius: 999px;
}

/* ---------------------------------------------------------------- sheets */
.sheet-backdrop {
  position: absolute; inset: 0; z-index: 70;
  background: rgba(5, 5, 10, 0.62);
  backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px);
  display: grid; place-items: center; padding: 20px;
}
.sheet-backdrop:not([hidden]) { animation: backdropIn 0.18s ease-out; }
@keyframes backdropIn { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  position: relative; width: min(430px, 92vw);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 24px; padding: 26px;
  box-shadow: 0 26px 90px rgba(0, 0, 0, 0.65);
  animation: popIn 0.18s var(--ease);
}
.sheet.small { width: min(350px, 90vw); text-align: center; }
.sheet h2 {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--font-display); margin: 0 0 6px; font-size: 24px;
}
.sheet .sub { color: var(--muted); margin: 0 0 16px; font-size: 14.5px; line-height: 1.45; }
.sheet .sub.warn { color: var(--danger); font-weight: 600; }
.sub2 { color: var(--muted); font-size: 13.5px; line-height: 1.4; }
.sheet-close {
  position: absolute; top: 12px; right: 12px;
  width: 44px; height: 44px; display: grid; place-items: center;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink);
  border-radius: 50%; cursor: pointer;
  transition: transform 0.12s var(--ease), background 0.15s;
}
.sheet-close:active { transform: scale(0.92); background: var(--surface-3); }
#deleteThumb {
  width: 92px; height: 118px; object-fit: cover;
  border-radius: 12px; border: 1px solid var(--line-strong);
  margin: 0 auto 12px; display: block; background: #000;
}
#videoPreview {
  width: 100%; max-height: 240px; object-fit: contain;
  border-radius: 12px; border: 1px solid var(--line-strong);
  margin: 4px 0 12px; display: block; background: #000;
}
#videoSave { display: flex; align-items: center; justify-content: center; gap: 4px; }
.replay-controls.recording #replayProgressFill { background: var(--danger); }
#recLabel {
  color: var(--danger); font-weight: 700; font-size: 13px;
  padding: 0 4px 0 10px; letter-spacing: 0.3px;
}
#photoPreview {
  width: 100%; max-height: 190px; object-fit: cover;
  border-radius: 12px; border: 1px solid var(--line-strong);
  margin: 4px 0 6px; display: block; background: #000;
}
#photoPreview.pop { filter: saturate(1.6) brightness(1.1); }

.coach-row { display: flex; gap: 14px; align-items: center; text-align: left; padding: 10px 2px; }
.coach-ic {
  width: 50px; height: 50px; flex: none; display: grid; place-items: center;
  border-radius: 14px; background: var(--accent-tint); color: var(--accent-2);
}
#coachGo { margin-top: 14px; width: 100%; }

.benefits { list-style: none; padding: 0; margin: 0 0 16px; }
.benefits li { padding: 7px 0 7px 26px; position: relative; font-size: 15px; }
.benefits li::before { content: ""; position: absolute; left: 2px; top: 12px; width: 7px; height: 7px; border-radius: 50%; background: var(--accent-grad); }
.price-row { display: flex; gap: 10px; margin-bottom: 16px; }
.price-opt { flex: 1; border: 1.5px solid var(--line-strong); border-radius: 14px; padding: 13px; text-align: center; cursor: pointer; }
.price-opt.active { border-color: var(--accent); background: var(--accent-tint); }
.price-opt b { display: block; font-size: 18px; }
.price-opt small { color: var(--muted); }
.fineprint { color: var(--muted); font-size: 12.5px; text-align: center; margin: 12px 0 0; }
.toggle-row { display: flex; align-items: center; gap: 8px; justify-content: center; font-size: 16px; margin: 8px 0 16px; }
.toggle-row input { width: 20px; height: 20px; accent-color: var(--accent); }

.row { display: flex; gap: 10px; }
.big-btn {
  flex: 1; min-width: 0; border: 0; cursor: pointer; font-weight: 700; font-size: 16px;
  padding: 14px; border-radius: 14px; min-height: var(--touch);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  text-align: center;
  transition: transform 0.12s var(--ease), filter 0.15s;
}
.big-btn:active { transform: scale(0.97); }
.big-btn.primary { background: var(--accent-grad); color: #fff; }
.big-btn.danger { background: var(--danger); color: #fff; }
.big-btn.ghost { background: var(--surface-2); border: 1px solid var(--line); color: var(--ink); }
.big-btn.hold { position: relative; overflow: hidden; }
.big-btn.hold::after {
  content: ""; position: absolute; left: 0; bottom: 0; height: 100%;
  width: var(--hold, 0%); background: rgba(255, 255, 255, 0.28);
  transition: width 0.1s linear;
}

/* ---------------------------------------------------------------- gallery */
.fullscreen {
  position: absolute; inset: 0; z-index: 65; background: var(--bg0);
  padding: calc(env(safe-area-inset-top, 0px) + 10px)
           max(16px, env(safe-area-inset-right, 0px)) 24px
           max(16px, env(safe-area-inset-left, 0px));
  overflow-y: auto;
}
/* [hidden] toggles display, so un-hiding re-triggers the enter animation */
.fullscreen:not([hidden]) { animation: screenIn 0.22s var(--ease); }
@keyframes screenIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.screen-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.screen-head h1 { font-family: var(--font-display); font-size: 26px; margin: 4px 0; }
.screen-head .icon-btn { border-color: var(--line); background: var(--surface); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); gap: 12px; }
.card {
  position: relative;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; overflow: hidden;
  transition: transform 0.12s var(--ease), border-color 0.15s;
}
@media (hover: hover) { .card:hover { border-color: var(--line-strong); transform: translateY(-2px); } }
.card .thumb { width: 100%; aspect-ratio: 3/4; object-fit: cover; background: #000; display: block; cursor: pointer; }
.card .meta { padding: 8px 10px 2px; display: flex; align-items: center; gap: 6px; }
.card .title { font-weight: 600; font-size: 13.5px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .title[contenteditable="true"]:focus { outline: 1px solid var(--accent); border-radius: 4px; white-space: normal; }
.card .rename-btn { border: 0; background: none; color: var(--muted); cursor: pointer; width: 40px; height: 40px; margin: -8px; display: grid; place-items: center; }
.card .date { color: var(--muted); font-size: 11.5px; padding: 0 10px; }
.card .card-actions { display: flex; gap: 4px; padding: 8px; }
.card .card-actions button {
  flex: 1; height: 44px; display: grid; place-items: center;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--muted);
  border-radius: 10px; cursor: pointer; transition: color 0.15s, background 0.15s;
}
.card .card-actions button:active { background: var(--surface-3); color: var(--ink); }
@media (hover: hover) { .card .card-actions button:hover { color: var(--ink); } }
.card.readonly .thumb { opacity: 0.75; }
.card .lock-note {
  display: flex; align-items: center; gap: 5px;
  color: var(--muted); font-size: 11px; padding: 0 10px 6px;
}
.empty {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  color: var(--muted); text-align: center; margin-top: 60px; line-height: 1.5;
}

/* ---- gallery multi-select ---- */
.screen-head .head-actions { display: flex; align-items: center; gap: 10px; }
#gallerySelect, #gallerySelectAll {
  background: var(--surface); color: var(--ink); box-shadow: none;
  border: 1px solid var(--line); font-size: 14px; font-weight: 600;
  height: 38px; padding: 0 16px;
}
.sel-check {
  /* sized for small fingers in multi-select mode */
  position: absolute; top: 6px; left: 6px; width: 38px; height: 38px;
  border-radius: 999px; display: none; place-items: center; z-index: 2;
  background: rgba(6, 6, 16, 0.55); border: 2px solid #fff; color: transparent;
  backdrop-filter: blur(2px); cursor: pointer;
}
.shared-badge {
  position: absolute; top: 6px; right: 6px; width: 26px; height: 26px;
  border-radius: 999px; display: grid; place-items: center; z-index: 2;
  background: rgba(6, 6, 16, 0.55); border: 2px solid #fff; color: #fff;
  backdrop-filter: blur(2px); pointer-events: none;
}
.shared-badge .icn { width: 14px; height: 14px; }
.gallery-filter-empty { grid-column: 1 / -1; color: var(--muted); text-align: center; padding: 40px 20px; }
.grid.selecting .sel-check { display: grid; }
.grid.selecting .thumb { cursor: pointer; }
/* keep the last row clear of the fixed Delete bar */
.grid.selecting { padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 84px); }
.card.selected { outline: 3px solid var(--accent); outline-offset: -3px; }
.card.selected .sel-check { background: var(--accent); border-color: var(--accent); color: #fff; }
#galleryBulkBar {
  /* fixed to the viewport so it sticks to the bottom while the grid scrolls */
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border: 1px solid var(--line);
  padding: 8px 8px 8px 18px; border-radius: 999px; box-shadow: var(--shadow); z-index: 70;
}
#gallerySelCount { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
#galleryDeleteSel { height: 44px; padding: 0 22px; }
#galleryDeleteSel:disabled { opacity: 0.45; }

/* ---------------------------------------------------------------- home hub */
#hub { display: flex; flex-direction: column; min-height: 100%; }
.hub-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px; max-width: 920px; margin: 10px auto 0;
  /* #hub is a flex column; without a definite width the grid's auto-fit
     resolves against max-content and overflows sideways. Pin it to the row. */
  width: 100%; box-sizing: border-box;
}
.hub-tile {
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px;
  padding: 22px 20px; text-align: left; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); border-radius: 20px;
  color: var(--ink); transition: transform 0.12s var(--ease), border-color 0.15s;
}
.hub-tile:active { transform: scale(0.98); }
@media (hover: hover) { .hub-tile:hover { border-color: var(--accent); transform: translateY(-2px); } }
.hub-ic { color: var(--accent); display: inline-flex; line-height: 0; }
.hub-ic .icn { width: 34px; height: 34px; stroke-width: 1.75; }
/* each doorway gets its own colour - faster to recognise for pre-readers */
#hubMagic .hub-ic { color: var(--accent-2); }
#hubMazes .hub-ic { color: var(--good); }
#hubGallery .hub-ic { color: #ffb14a; }
@media (hover: hover) {
  #hubBlank:hover { border-color: var(--accent); }
  #hubMagic:hover { border-color: var(--accent-2); }
  #hubMazes:hover { border-color: var(--good); }
  #hubGallery:hover { border-color: #ffb14a; }
}
.hub-label { font-family: var(--font-display); font-size: 19px; font-weight: 700; }
.hub-sub { font-size: 13px; color: var(--muted); }
.hub-links { margin-top: auto; text-align: center; padding-top: 16px; display: flex; gap: 8px; justify-content: center; align-items: center; color: var(--muted); font-size: 13px; }
.hub-links a { color: var(--muted); text-decoration: none; font-weight: 600; padding: 4px 2px; }
.hub-links a:active { color: var(--ink); }
@media (hover: hover) { .hub-links a:hover { color: var(--ink); } }
.hub-version { display: block; text-align: center; font-size: 11px; color: var(--muted); opacity: 0.5; padding: 8px 0 4px; }
@media (max-height: 730px), (max-width: 479px) {
  .hub-grid { gap: 10px; margin-top: 4px; }
  .hub-tile {
    flex-direction: row; align-items: center; gap: 14px;
    padding: 14px 18px; border-radius: 16px;
  }
  .hub-ic .icn { width: 28px; height: 28px; }
  .hub-sub { display: none; }
  .hub-label { font-size: 17px; }
}

/* ---------------------------------------------------------------- maze picker */
.maze-mods { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0 0 16px; }
.mods-label { font-size: 14px; color: var(--muted); }
.mod-chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px;
  padding: 8px 16px; border-radius: 999px; font-size: 14px; font-weight: 600;
  background: var(--surface); border: 1px solid var(--line); color: var(--muted); cursor: pointer;
  transition: transform 0.12s var(--ease), background 0.15s;
}
.mod-chip:active { transform: scale(0.95); }
.mod-chip .icn { width: 16px; height: 16px; }
.mod-chip.on { border-color: var(--accent); color: var(--ink); background: rgba(124, 92, 255, 0.16); }
.mod-chip.on .icn { color: var(--accent); }
.win-star { display: inline-flex; vertical-align: -3px; color: #ffb14a; }
.win-star .icn { fill: #ffce5a; stroke: #e0921f; }
.maze-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 14px; max-width: 1080px; margin: 0 auto;
}

/* Squiggle picker: tiles ARE the squiggle, rendered live from the seed.
   Laid out like the gallery (same auto-fill/148px track) so all 30 can be
   scanned at a glance - wider tracks gave one enormous tile per row on a
   phone and turned choosing into scrolling. */
.squiggle-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 12px; max-width: 1080px; margin: 0 auto; padding-bottom: 24px;
}
.squiggle-card {
  padding: 0; border: 1px solid var(--line); border-radius: 16px;
  overflow: hidden; background: #000; cursor: pointer; line-height: 0;
  transition: transform 0.12s var(--ease), border-color 0.15s;
}
@media (hover: hover) {
  .squiggle-card:hover { border-color: var(--line-strong); transform: translateY(-2px); }
}
.squiggle-card:active { transform: scale(0.97); }
.squiggle-thumb { width: 100%; aspect-ratio: 1/1; display: block; }
.maze-tile {
  display: flex; flex-direction: column; gap: 4px; padding: 0 0 12px; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  color: var(--ink); cursor: pointer; transition: transform 0.12s var(--ease), border-color 0.15s;
}
.maze-tile:active { transform: scale(0.98); }
@media (hover: hover) { .maze-tile:hover { border-color: var(--accent); transform: translateY(-2px); } }
.maze-thumb { width: 100%; height: auto; display: block; background: #0a0a14; }
.maze-label { font-family: var(--font-display); font-size: 17px; font-weight: 700; padding: 8px 12px 0; }
.maze-tag { font-size: 12.5px; color: var(--muted); padding: 0 12px; }

/* Maze mode: the game locks the toys that could cheat through walls. */
body.maze-mode .tool-btn:not([data-tool="scratch"]),
body.maze-mode #symmetryBtn { opacity: 0.35; pointer-events: none; }

/* ---------------------------------------------------------- dots mode */
/* Scratch only: the other toys are parked while a puzzle is on the board. */
body.dots-mode .tool-btn:not([data-tool="scratch"]),
body.dots-mode #symmetryBtn { opacity: 0.35; pointer-events: none; }

/* ------------------------------------------------------- squiggle mode */
/* Squiggle: the squiggle is pre-scratched and the kid carries on from it,
   so the same scratch-only lock applies (setTool also guards this in JS). */
body.squiggle-mode .tool-btn:not([data-tool="scratch"]),
body.squiggle-mode #symmetryBtn { opacity: 0.35; pointer-events: none; }

#dotsChip, #mazeTimerChip {
  position: absolute; z-index: 40; top: calc(var(--bar-h) + env(safe-area-inset-top, 0px) + 10px);
  left: 50%; transform: translateX(-50%);
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  color: var(--ink); font-weight: 600; font-size: 13px; padding: 7px 14px;
  font-variant-numeric: tabular-nums; pointer-events: none;
}
#dotsConnectChip {
  position: absolute; z-index: 40; top: calc(var(--bar-h) + env(safe-area-inset-top, 0px) + 48px);
  left: 50%; transform: translateX(-50%);
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  color: var(--muted); font-weight: 600; font-size: 12.5px; padding: 6px 12px; cursor: pointer;
}
#dotsConnectChip.on { color: var(--ink); border-color: var(--accent); }
#dotsConnectChip.on .icn { color: var(--accent); }
@media (hover: hover) { #dotsConnectChip:hover { border-color: var(--accent); } }
/* quiet post-win bar: no popup - a view toggle and a next-puzzle button */
#dotsDoneBar {
  position: absolute; z-index: 40; bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px;
  /* same floating panel as the sidebar: the buttons need contrast against
     whatever picture ends up behind them */
  background: var(--surface); border: 1px solid var(--line);
  padding: 7px; border-radius: 999px;
  box-shadow: var(--shadow);
}
#dotsViewChip, #dotsNextBtn {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: 999px;
  color: var(--ink); font-weight: 600; font-size: 13.5px; padding: 9px 16px; cursor: pointer;
  white-space: nowrap;
}
#dotsViewChip .icn { color: var(--accent); }
#dotsNextBtn {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
#dotsNextBtn .icn { color: #fff; }
@media (hover: hover) {
  #dotsViewChip:hover { border-color: var(--accent); }
  #dotsNextBtn:hover { filter: brightness(1.1); }
}

.tier-preview {
  display: block; width: 100%; max-height: 200px; object-fit: contain;
  border-radius: 12px; background: #050508; margin: 2px 0 4px;
}
.tier-hint { color: var(--muted); font-size: 12px; text-align: center; margin: 0 0 6px; }
.tier-list { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.tier-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  color: var(--ink); padding: 12px 14px; cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.tier-row .tier-name { font-weight: 700; font-size: 15px; }
.tier-row .tier-dots { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.tier-row.on { border-color: var(--accent); background: rgba(124, 92, 255, 0.14); }
@media (hover: hover) { .tier-row:hover { border-color: var(--accent); } }

/* ---------------------------------------------------------- magic picker */
.magic-lede { color: var(--muted); margin: -6px 0 16px; font-size: 14px; }
.shelf { margin-bottom: 22px; }
.shelf-head {
  font-family: var(--font-display); font-size: 19px; margin: 0 0 10px;
  display: flex; align-items: center; gap: 8px;
}
.shelf-emoji { font-size: 22px; }
.shelf-row {
  display: flex; gap: 12px; overflow-x: auto; padding: 2px 2px 10px;
  /* proximity, not mandatory: a mandatory-snap row wins slightly-diagonal
     drags on iOS, hijacking vertical scrolls that start on a card */
  scroll-snap-type: x proximity; -webkit-overflow-scrolling: touch;
  /* pan-y too: a vertical drag that starts on a card must scroll the picker,
     not get swallowed by the row (the browser axis-locks from the first move) */
  touch-action: pan-x pan-y;
  overscroll-behavior-x: contain;
}
.shelf-row::-webkit-scrollbar { height: 6px; }
.shelf-row::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 3px; }
.magic-card {
  position: relative; flex: 0 0 auto; width: 210px;
  scroll-snap-align: start; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; overflow: hidden; padding: 0;
  transition: transform 0.12s var(--ease), border-color 0.15s;
}
.magic-card:active { transform: scale(0.98); }
@media (hover: hover) { .magic-card:hover { border-color: var(--accent); transform: translateY(-2px); } }
.magic-card .mc-thumb {
  width: 100%; aspect-ratio: 32/21; object-fit: cover; display: block; background: #05050e;
}
.magic-card .mc-title {
  display: block; padding: 8px 10px 10px; font-weight: 600; font-size: 13.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: left;
}
.magic-card.make-own {
  display: grid; place-items: center; aspect-ratio: 32/21;
  border: 1.5px dashed var(--line-strong); background: transparent; color: var(--muted);
}
.magic-card.make-own .mo-inner { display: flex; flex-direction: column; align-items: center; gap: 8px; font-weight: 600; }
.magic-card.make-own .mo-inner .icn { color: var(--accent); }
@media (hover: hover) { .magic-card.make-own:hover { border-color: var(--accent); color: var(--ink); } }
.magic-card.locked .mc-thumb { opacity: 0.82; }
#sizePopover h3 { margin: 2px 6px 8px; font-size: 13px; color: var(--muted); }
.size-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.size-row small { color: var(--muted); font-variant-numeric: tabular-nums; }
.size-row.active { color: var(--accent); }
.magic-card .mc-lock {
  position: absolute; top: 8px; left: 8px;
  width: 26px; height: 26px; display: grid; place-items: center;
  background: rgba(6,6,16,0.72); color: #fff; border-radius: 999px;
  backdrop-filter: blur(2px);
}

/* ---------------------------------------------------------------- replay */
#replayOverlay { position: absolute; inset: 0; z-index: 55; }
.replay-controls {
  /* below the top bar so it never covers the header nav */
  position: absolute; top: calc(var(--bar-h) + env(safe-area-inset-top, 0px) + 10px);
  left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--line);
  padding: 7px; border-radius: 999px;
  box-shadow: var(--shadow);
}
#replayProgress {
  width: min(34vw, 220px); height: 4px; border-radius: 999px;
  background: var(--surface-3); overflow: hidden; margin: 0 6px;
}
#replayProgressFill { height: 100%; width: 0%; background: var(--accent-grad); border-radius: 999px; }
#replaySpeed { font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums; }
#replayTimer { font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums; color: var(--muted); padding: 0 2px; }

/* ------------------------------------------------------- maze leaderboard */
#mazeWinTime { margin: -8px 0 16px; font-weight: 700; color: var(--ink); }
#mazeNameEntry { margin: 0 0 16px; text-align: left; }
#mazeNameInput {
  width: 100%; box-sizing: border-box; margin: 0 0 16px;
  font-size: 16px; font-family: var(--font-ui); padding: 11px 14px;
  background: var(--surface-2); border: 1px solid var(--line-strong);
  border-radius: 12px; color: var(--ink);
}
#mazeNameInput::placeholder { color: var(--muted); }
#mazeNameInput:focus { outline: 2px solid var(--accent); }
#mazeRecentNames:empty { margin: 0; }
#mazeRecentNames:not(:empty) { margin: 0 0 16px; }
.recent-name {
  background: var(--surface-2); border: 1px solid var(--line-strong); color: var(--muted);
  height: 34px; padding: 0 14px; font-size: 13.5px; box-shadow: none;
}
.recent-name:hover, .recent-name:active { border-color: var(--accent); color: var(--ink); }
#mazeSaveScore { width: 100%; }

/* one scrolling row, not a wrap - 7 difficulty labels of very different
   lengths wrapped into ragged, unevenly-centered rows otherwise */
#mazeBoardTabs {
  display: flex; flex-wrap: nowrap; flex-direction: row; justify-content: flex-start;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  gap: 8px; margin: 0 0 16px; padding: 2px 2px 8px;
}
#mazeBoardTabs::-webkit-scrollbar { height: 6px; }
#mazeBoardTabs::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 3px; }
#mazeBoardTabs .mod-chip { flex: 0 0 auto; white-space: nowrap; }
#mazeBoardList { display: flex; flex-direction: column; gap: 8px; max-height: 50vh; overflow-y: auto; }
.board-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 14px;
}
.board-row:nth-child(1) { border-color: #ffce5a; }
.board-rank {
  font-family: var(--font-display); font-weight: 800; font-size: 15px;
  color: var(--muted); min-width: 20px;
}
.board-row:nth-child(1) .board-rank { color: #ffb14a; }
.board-name { flex: 1; font-weight: 600; font-size: 14.5px; display: flex; align-items: center; gap: 4px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-badges { display: inline-flex; color: var(--muted); flex: none; }
.board-badges .icn { width: 13px; height: 13px; }
.board-time { font-weight: 700; font-size: 14.5px; font-variant-numeric: tabular-nums; color: var(--accent-2); }

/* ---------------------------------------------------------------- install / update */
.install-hint, .update-toast {
  position: absolute; z-index: 62; border: 1px solid var(--line); cursor: pointer;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 16px); right: 16px;
  background: var(--surface); color: var(--ink); font-weight: 600; font-size: 14px;
  padding: 11px 17px; border-radius: 999px; box-shadow: var(--shadow);
}
.update-toast {
  /* above every surface (fullscreen 65, replay 55, sheets 80) so "Update
     ready" is reachable no matter which screen is open, not just the canvas */
  z-index: 90;
  background: var(--accent-grad); color: #fff; border: 0;
  left: 50%; right: auto; transform: translateX(-50%);
}

/* ---------------------------------------------------------------- motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
  #hint { animation: none; opacity: 0.85; }
  /* the spinner is feedback, not decoration - freezing it solid reads as a hang */
  .scratchy-spinner__stroke { animation-duration: 3.4s !important; }
}

/* ---------------------------------------------------------------- free draw */
/* Free Draw hides the chrome that doesn't apply: there's no swappable
   reveal pattern (colour lives on the stroke, not the canvas), and
   stencils/spirals aren't surfaced in this mode (still work if triggered). */
body.freedraw-mode #patternBtn,
body.freedraw-mode .tool-btn[data-tool="stencils"],
body.freedraw-mode .tool-btn[data-tool="spirals"] { display: none; }

#colorDot {
  width: 24px; height: 24px; border-radius: 50%; flex: none;
  /* the ring shows the Secondary colour, set inline alongside the Primary
     fill (see syncFreeDrawChrome in ui.js) - this is just the fallback
     before Free Draw's first sync. */
  border: 4px solid rgba(255, 255, 255, 0.6);
}

/* Two-panel brush library (sidebar tray): left = brush sets,
   right = brushes in the selected set with name + live stroke preview. */
.brushlib-body { display: flex; gap: 4px; }
.brushlib-groups {
  flex: 0 0 84px; display: flex; flex-direction: column; gap: 2px;
  max-height: min(60vh, 460px); overflow-y: auto;
  border-right: 1px solid var(--line); padding-right: 6px; margin-right: 4px;
}
.brushlib-group {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 9px 4px; border-radius: 12px; border: 1px solid transparent;
  background: transparent; color: var(--muted); cursor: pointer;
  font-size: 10.5px; font-weight: 700; line-height: 1.1;
}
.brushlib-group svg { width: 20px; height: 20px; }
.brushlib-group.on { background: var(--accent-tint); color: var(--ink); border-color: var(--accent); }
@media (hover: hover) { .brushlib-group:hover:not(.on) { background: var(--surface-2); } }
.brushlib-brushes {
  flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px;
  max-height: min(60vh, 460px); overflow-y: auto;
}
.brushlib-brush {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; box-sizing: border-box; padding: 8px 10px; border-radius: 10px;
  border: 1px solid transparent; background: transparent; color: var(--ink);
  cursor: pointer; text-align: left; font: inherit;
}
.brushlib-brush .label { font-size: 14px; font-weight: 600; flex: none; }
.brushlib-brush .tex-preview { border-radius: 6px; background: #000; flex: none; }
.brushlib-brush.on { background: var(--surface-2); border-color: var(--line-strong); }
@media (hover: hover) { .brushlib-brush:hover:not(.on) { background: var(--surface-2); } }

/* ------------------------------------------------------------ colour panel */
/* Colour popover: a side card off the sidebar colour button (same placement
   as the brush library), a self-contained tabbed overlay - fixed swatch
   header + scrolling middle + a bottom tab bar. */
.color-popover {
  left: calc(env(safe-area-inset-left, 0px) + 74px); top: 50%; transform: translateY(-50%);
  transform-origin: left center; animation: popInSide 0.16s var(--ease);
  width: min(400px, 92vw); max-width: calc(100vw - 90px);
  max-height: min(84vh, 640px); overflow: hidden;
  display: flex; flex-direction: column; padding: 16px 16px 0;
}
.color-panel { user-select: none; -webkit-user-select: none; display: flex; flex-direction: column; flex: 1; min-height: 0; }
.cp-scroll { flex: 1; min-height: 0; overflow-y: auto; }
#colorDone { margin: 12px 0; flex: none; }
.cp-head { display: flex; align-items: flex-start; justify-content: center; gap: 14px; margin-bottom: 12px; }
.cp-slot { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.cp-slot-lbl { font-size: 11px; font-weight: 600; color: var(--muted); }
.cp-primary, .cp-secondary {
  width: 56px; height: 34px; border: 2px solid var(--line-strong); padding: 0; border-radius: 10px;
  cursor: pointer; transition: box-shadow 0.15s, border-color 0.15s;
}
/* the active (selected) slot - the one a colour pick will fill - gets a ring */
.cp-primary.active, .cp-secondary.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent);
}
.cp-sync {
  width: 26px; height: 26px; border-radius: 50%; flex: none; padding: 0; margin-top: 4px;
  display: grid; place-items: center; cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--surface-2); color: var(--muted);
}
.cp-sync svg { width: 15px; height: 15px; }
.cp-sync.on { background: var(--accent-tint); border-color: var(--accent); color: var(--accent-2); }
/* bottom tab bar - equal-width segments across the foot of the card */
.cp-tabs {
  display: flex; gap: 2px; flex: none;
  padding-top: 10px; margin-top: 6px; border-top: 1px solid var(--line);
}
.cp-tab {
  flex: 1; border: 0; background: transparent; color: var(--muted);
  border-radius: 10px; padding: 9px 2px; font-size: 12px; font-weight: 600; cursor: pointer;
}
.cp-tab.on { background: var(--accent-tint); color: var(--accent-2); }
.cp-pane[hidden] { display: none; }
.cp-disc, .cp-sv { display: block; width: 100%; touch-action: none; cursor: crosshair; }
.cp-disc { max-width: 260px; aspect-ratio: 1; margin: 0 auto 10px; }
.cp-sv { height: 150px; border-radius: 12px; margin-bottom: 10px; }
.cp-sliders { display: flex; flex-direction: column; gap: 6px; }
.cp-slider { display: flex; align-items: center; gap: 10px; }
.cp-sl-lbl { width: 18px; font-size: 13px; font-weight: 700; color: var(--muted); text-align: center; }
.cp-track {
  flex: 1; height: 26px; border-radius: 999px; background: var(--surface-3);
  overflow: hidden; touch-action: none; cursor: pointer; position: relative;
}
.cp-fill { position: absolute; inset: 0 auto 0 0; background: var(--accent); opacity: 0.75; border-radius: 999px; }
/* colour sliders (HSB / RGB): the track IS the gradient, with a round handle
   marking the value so it's obvious what the slider adjusts. */
.cp-track.grad { overflow: visible; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14); }
.cp-handle {
  position: absolute; top: 50%; transform: translate(-50%, -50%);
  width: 22px; height: 22px; border-radius: 50%; background: #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4), 0 2px 6px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}
.cp-num {
  width: 52px; text-align: center; font-variant-numeric: tabular-nums;
  background: var(--surface-2); border: 1px solid var(--line-strong); color: var(--ink);
  border-radius: 8px; padding: 6px 4px; font-size: 14px; font-weight: 600;
}
.cp-hexrow { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.cp-hexlbl { font-size: 13px; font-weight: 700; color: var(--muted); }
.cp-hex {
  flex: 1; background: var(--surface-2); border: 1px solid var(--line-strong); color: var(--ink);
  border-radius: 10px; padding: 9px 12px; font-size: 15px; font-weight: 600;
  font-family: ui-monospace, monospace; text-transform: lowercase;
}
.cp-sub { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); margin: 10px 0 6px; }
.cp-harmhint { text-align: center; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 8px; }
.cp-harmsw-lbl { text-align: center; font-size: 12px; font-weight: 600; color: var(--muted); margin-top: 10px; }
.cp-harmsw { display: flex; gap: 8px; justify-content: center; margin-top: 8px; }
/* the currently-chosen accent match gets a ring */
.cp-harmsw .cp-sw.on { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); }
.cp-sw {
  width: 34px; height: 34px; border-radius: 50%; cursor: pointer; padding: 0; flex: none;
  border: 2px solid rgba(255, 255, 255, 0.25);
}
.cp-palettes-head { display: flex; justify-content: flex-end; margin-bottom: 8px; }
.cp-newpal {
  border: 1px solid var(--line-strong); background: var(--surface-2); color: var(--ink);
  border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.cp-palettes { display: flex; flex-direction: column; gap: 12px; }
/* read-only default-palette title, and the divider above the defaults */
.cp-pal-name-ro { font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.cp-pal-divider {
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--muted); margin: 6px 0 2px; padding-top: 12px; border-top: 1px solid var(--line);
}
.cp-pal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 6px;
}
.cp-pal-name {
  flex: 1; min-width: 0; border: 0; background: transparent; color: inherit;
  font: inherit; padding: 3px 5px; border-radius: 6px;
}
.cp-pal-name:focus { background: var(--surface-2); outline: 2px solid var(--accent); }
.cp-pal-btns { display: flex; gap: 6px; flex: none; }
.cp-pal-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.cp-add, .cp-pal-del {
  width: 28px; height: 28px; border-radius: 50%; cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--surface-2); color: var(--ink);
  font-size: 16px; font-weight: 700; line-height: 1;
}
.cp-pal-del { color: var(--muted); font-size: 15px; }
.cp-sw-hold { transition: transform 0.55s linear; transform: scale(0.7); }
.cp-hist-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); margin: 12px 0 6px; }
.cp-history { display: flex; gap: 8px; flex-wrap: wrap; min-height: 34px; margin-bottom: 12px; }
.cp-empty { font-size: 13px; color: var(--muted); align-self: center; }

/* ---- Collaboration ---- */
.collab-avatars {
  display: flex; align-items: center; gap: 2px; margin-right: 4px;
}
.collab-avatar {
  width: 26px; height: 26px; border-radius: 50%; color: #fff;
  font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--surface-1); position: relative;
}
.collab-avatar + .collab-avatar { margin-left: -6px; }
.collab-status-dot {
  width: 8px; height: 8px; border-radius: 50%; position: absolute; bottom: -1px; right: -1px;
  border: 1.5px solid var(--surface-1);
}
.collab-status-dot.connected { background: #4ade80; }
.collab-status-dot.reconnecting { background: #fbbf24; }

.collab-link-box {
  display: flex; gap: 8px; align-items: center; margin-top: 8px;
}
.collab-link-box input {
  flex: 1; font-size: 13px; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink);
  font-family: inherit;
}

.collab-join-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(0,0,0,0.85); display: flex; align-items: center; justify-content: center;
}
.collab-join-card {
  background: var(--surface-1); border-radius: 16px; padding: 24px; width: 300px; max-width: 90vw;
  text-align: center;
}
.collab-join-card h2 { margin: 0 0 4px; font-size: 18px; color: var(--ink); }
.collab-join-card label {
  display: block; text-align: left; font-size: 13px; color: var(--muted); margin: 20px 0 0;
}
.collab-join-card input {
  /* the label text and input are both children of the same <label> - the
     label's own margin only spaces the whole block, not text-from-input,
     so the gap between them has to live here or they sit flush/overlap
     on narrow (mobile) viewports */
  display: block; margin-top: 8px;
  width: 100%; box-sizing: border-box; font-size: 16px; padding: 10px 12px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2);
  color: var(--ink); font-family: inherit;
}
.collab-join-card .big-btn { width: 100%; margin-top: 16px; }

[hidden] { display: none !important; }
