/* Mochi Paint — soft playful UI (premium responsive pass, July 2026)
   Poppins, lavender-pink gradient page, white rounded cards, illustrated
   SVG icons, 0.2s ease transitions, no bounce.

   Layout tiers (each designed, not scaled):
   A  desktop / large tablet ....... top bar + labeled 280px right rail
   B  tablet landscape ≤1180px ..... top bar + labeled 220px right rail
   C  tablet portrait ≤1023px ...... top bar + compact 96px icon rail
   D  phone portrait ≤640px ........ slim top bar + fixed two-row bottom dock
   E  phone landscape (h ≤520px) ... "focus" layout: icon columns both sides,
                                     the artwork gets nearly the full height */

:root{
  --r-card:20px;          /* cards, rail, dock */
  --r-btn:14px;           /* buttons */
  --shadow-card:0 4px 16px rgba(200,160,220,.12);
  --shadow-btn:0 4px 12px rgba(200,160,220,.2);
  --shadow-btn-hover:0 8px 18px rgba(200,160,220,.32);
  --ink:#555555;          /* 7.0:1 on white */
  --ink-soft:#6a6a6a;     /* section headers, 5.7:1 */
  --pink:#d4548d;
  --pink-soft:#f4a4d4;
}

*{box-sizing:border-box}
[hidden]{display:none!important}
html,body{height:100%;overscroll-behavior:none}
body{margin:0;font-family:'Poppins',system-ui,sans-serif;color:var(--ink);
  background:linear-gradient(135deg,#f5e6f0,#e8d5f2);background-attachment:fixed}
/* touch-action:manipulation kills the mobile double-tap-to-zoom gesture on
   every control (a stray fast tap was zooming the whole page and leaving it
   stuck); the canvas keeps touch-action:none for its own pinch handling. */
button,a,input,.logo{touch-action:manipulation}

#app{position:relative;z-index:1;height:100dvh;display:flex;flex-direction:column;
  margin:0 auto;overflow:hidden;
  padding:calc(10px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left))}
/* Only ultra-wide screens get a cap so the rail never drifts far from the art */
@media(min-width:1700px){#app{max-width:1680px}}

/* ---------- splash / launch experience ----------
   The character layers are exact pixels extracted from hero-pals.png.
   Their resting positions reconstruct the canonical hero exactly; only the
   paint trail and heart are SVG. Reduced-motion and repeat visits show the
   finished frame without character movement. */
#splash{position:fixed;inset:0;z-index:100;display:flex;align-items:center;justify-content:center;
  background:linear-gradient(135deg,#f5e6f0,#e8d5f2);
  padding:calc(12px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
  transition:opacity .5s ease,visibility .5s}
#splash.done{opacity:0;visibility:hidden;pointer-events:none}
.splash-inner{display:flex;flex-direction:column;align-items:center;gap:4px;text-align:center;
  width:min(560px,100%)}
.splash-scene{position:relative;width:100%;aspect-ratio:2020/778;max-height:62dvh;
  overflow:hidden;border-radius:26px;box-shadow:0 18px 44px rgba(150,110,170,.28)}
.splash-layer,.splash-paint{position:absolute;inset:0;display:block;width:100%;height:100%}
.splash-layer{object-fit:contain;pointer-events:none;user-select:none}
.splash-paint{overflow:visible;pointer-events:none}
.splash-chick{transform-origin:13.47% 64.27%}
.splash-bear{transform-origin:35.35% 62.34%}
.splash-fox{transform-origin:70.54% 75.84%}
.splash-polar{transform-origin:80.20% 61.70%}
.splash-brush{transform-origin:53.05% 70.69%}
.splash-heart-fill{opacity:.82}
.splash-trail{opacity:0;stroke-dasharray:100;stroke-dashoffset:0}
.splash-heart-line{stroke-dasharray:100;stroke-dashoffset:0}
.splash-sparkles{opacity:1;transform-box:fill-box;transform-origin:center}
.splash-logo{font-size:34px;font-weight:700;color:var(--pink);margin-top:14px}
.splash-tag{font-size:13px;font-weight:600;color:#767676;letter-spacing:.04em}
/* phone landscape: the scene is width-bound, keep the text visible */
@media(orientation:landscape) and (max-height:520px){
  .splash-inner{width:min(760px,100%)}
  .splash-scene{width:auto;height:min(66dvh,330px);max-width:100%}
  .splash-logo{font-size:22px;margin-top:8px}
  .splash-tag{font-size:11px}
}
@media(prefers-reduced-motion:no-preference){
  #splash:not(.quick) .splash-inner{animation:spPop .5s cubic-bezier(.34,1.2,.64,1) both}
  #splash:not(.quick) .splash-trail{animation:spTrail .72s ease-out .28s both}
  #splash:not(.quick) .splash-heart-line{animation:spDraw .82s ease-in-out .75s both}
  #splash:not(.quick) .splash-heart-fill{animation:spHeartFill .34s ease 1.36s both}
  #splash:not(.quick) .splash-sparkles{animation:spSparkle .38s ease 1.45s both}
  #splash:not(.quick) .splash-brush{animation:spBrush 1.28s ease-in-out .25s both}
  #splash:not(.quick) .splash-chick{animation:spChickWave .82s ease-in-out .42s 2}
  #splash:not(.quick) .splash-bear{animation:spBearWave .82s ease-in-out .50s 2}
  #splash:not(.quick) .splash-fox{animation:spFoxWag .86s ease-in-out .58s 2}
  #splash:not(.quick) .splash-polar{animation:spPolarHello .88s ease-in-out .66s 2}
}
@keyframes spPop{from{opacity:0;transform:translateY(12px) scale(.97)}to{opacity:1;transform:none}}
@keyframes spDraw{from{stroke-dashoffset:100}to{stroke-dashoffset:0}}
@keyframes spTrail{
  0%{opacity:1;stroke-dashoffset:100}
  72%{opacity:1;stroke-dashoffset:0}
  100%{opacity:0;stroke-dashoffset:0}
}
@keyframes spHeartFill{from{opacity:0}to{opacity:.82}}
@keyframes spSparkle{
  0%{opacity:0;transform:scale(.7)}
  70%{opacity:1;transform:scale(1.14)}
  100%{opacity:1;transform:scale(1)}
}
@keyframes spBrush{0%,100%{transform:none}35%{transform:translateY(-2px) rotate(-1.4deg)}70%{transform:translateY(-1px) rotate(.8deg)}}
@keyframes spChickWave{0%,100%{transform:none}35%{transform:rotate(-3deg)}70%{transform:rotate(1.4deg)}}
@keyframes spBearWave{0%,100%{transform:none}35%{transform:rotate(-4deg)}70%{transform:rotate(1.8deg)}}
@keyframes spFoxWag{0%,100%{transform:none}35%{transform:rotate(3deg)}70%{transform:rotate(-1.4deg)}}
@keyframes spPolarHello{0%,100%{transform:none}35%{transform:rotate(-2.4deg)}70%{transform:rotate(1deg)}}

/* ---------- top bar: logo + action cards ---------- */
.appbar{display:flex;align-items:flex-start;justify-content:space-between;gap:10px;
  padding:0 0 10px;position:relative;z-index:5}
.logo{font-size:20px;font-weight:700;color:var(--pink);
  display:flex;align-items:center;gap:6px;white-space:nowrap;align-self:center}
.logo .bead{display:inline-block;font-size:22px}
.actions{display:flex;gap:10px}
.abtn{width:72px;padding:10px 0;border-radius:16px;border:none;background:#fff;
  box-shadow:var(--shadow-btn);
  display:flex;flex-direction:column;align-items:center;gap:4px;cursor:pointer;
  font-family:inherit;text-decoration:none;
  transition:transform .2s ease,box-shadow .2s ease,opacity .2s ease}
.abtn span{font-size:11px;font-weight:600;color:var(--ink);line-height:1}
.abtn svg{width:28px;height:28px;display:block;pointer-events:none}
.abtn:hover{transform:translateY(-2px);box-shadow:var(--shadow-btn-hover)}
.abtn:active{transform:translateY(0);box-shadow:var(--shadow-btn)}
.abtn:disabled{opacity:.5;cursor:not-allowed;transform:none;box-shadow:var(--shadow-btn)}

/* ---------- stage: workspace (fitted page + zoom) + tool rail ---------- */
.stage{flex:1;display:flex;min-height:0}
/* The workspace is the visible drawing area. The white page card inside it is
   JS-sized to the coloring page's contain-fit (no tall blank canvas), centered,
   and zoom/pan happen via a transform on the card — pointer math stays correct
   because getBoundingClientRect() reflects transforms. */
.workspace{position:relative;flex:1;min-width:0;min-height:0;
  display:flex;align-items:center;justify-content:center;
  overflow:hidden;touch-action:none}
.canvas-wrap{position:relative;width:100%;height:100%;flex:0 0 auto;
  border-radius:24px;overflow:hidden;background:#fff;
  box-shadow:var(--shadow-card);will-change:transform}

/* zoom controls: bottom-right of the workspace */
.zoomctl{position:absolute;right:10px;bottom:10px;display:flex;flex-direction:column;gap:8px;z-index:6}
.zbtn{width:44px;height:44px;border-radius:var(--r-btn);border:none;background:#fff;
  box-shadow:var(--shadow-btn);cursor:pointer;padding:0;
  display:flex;align-items:center;justify-content:center;
  transition:transform .2s ease,box-shadow .2s ease,opacity .2s ease}
.zbtn svg{width:22px;height:22px;display:block;pointer-events:none}
.zbtn:hover{transform:translateY(-2px);box-shadow:var(--shadow-btn-hover)}
.zbtn:active{transform:translateY(0)}
.zbtn:disabled{opacity:.5;cursor:not-allowed;transform:none}

.rail{flex:0 0 auto;width:280px;margin-left:14px;
  display:flex;flex-direction:column;gap:2px;padding:16px;
  background:#fff;border-radius:var(--r-card);box-shadow:var(--shadow-card);
  overflow-y:auto;overflow-x:hidden;overscroll-behavior:contain;-webkit-overflow-scrolling:touch;
  scrollbar-width:none}
.rail::-webkit-scrollbar{display:none}

/* section headers */
.sec{margin:14px 0 8px;font-size:13px;font-weight:600;color:var(--ink-soft);
  text-transform:uppercase;letter-spacing:.5px;
  display:flex;align-items:center;justify-content:space-between}
.sec:first-child{margin-top:0}

/* ---------- tool rows ---------- */
.rail-tools{display:flex;flex-direction:column;gap:8px}
.tbtn{display:flex;align-items:center;gap:12px;width:100%;min-height:44px;
  padding:12px 14px;border-radius:var(--r-btn);border:2px solid #e8e8e8;background:#fff;
  cursor:pointer;font-family:inherit;font-size:14px;font-weight:500;color:var(--ink);text-align:left;
  transition:background .2s ease,border-color .2s ease,color .2s ease,transform .2s ease}
.tbtn svg{width:28px;height:28px;flex:0 0 auto;display:block;pointer-events:none}
.tbtn span{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.tbtn:hover{border-color:rgba(244,164,212,.5);background:#fef7fb}
.tbtn.on,.tbtn[aria-pressed="true"]{background:linear-gradient(135deg,#fce4f3,#f9d9ed);
  border-color:var(--pink-soft);color:var(--pink)}

/* ---------- colors ---------- */
/* One big color button; tapping it pops the full palette over the canvas
   with a springy expand, so the rail never crams 24 swatches. */
.cc-big{width:56px;height:56px;border-radius:50%;border:3px solid #e8e8e8;background:#fff;margin:2px auto 4px;
  display:flex;align-items:center;justify-content:center;padding:0;cursor:pointer;flex:0 0 auto;
  transition:border-color .2s ease,transform .15s ease}
.cc-big:hover{border-color:var(--pink-soft);transform:scale(1.06)}
.cc-dot{width:40px;height:40px;border-radius:50%;background:#ec4899;pointer-events:none}
/* Dimmed layer under the open palette: catches the outside tap (so it closes
   the palette instead of painting the canvas) and signals "pick a color". */
.pop-backdrop{position:fixed;inset:0;z-index:59;background:rgba(80,60,110,.18)}
.color-pop{display:none;position:fixed;z-index:60;left:50%;top:44%;transform:translate(-50%,-50%);
  max-width:calc(100vw - 24px);max-height:calc(100dvh - 24px);overflow-y:auto;
  background:#fff;border:2px solid #dbe4f6;border-radius:22px;padding:16px;
  box-shadow:0 18px 50px rgba(120,100,160,.32)}
.color-pop.open{display:block;animation:popIn .22s cubic-bezier(.34,1.56,.64,1)}
@keyframes popIn{from{opacity:0;transform:translate(-50%,-46%) scale(.7)}to{opacity:1;transform:translate(-50%,-50%) scale(1)}}
.rail-colors{display:grid;grid-template-columns:repeat(6,46px);gap:10px;justify-items:center}
.qsw{width:40px;aspect-ratio:1;border-radius:50%;background:var(--c);padding:0;cursor:pointer;
  border:2px solid rgba(45,45,45,.25);
  border-color:color-mix(in srgb,var(--c) 72%,#2d2d2d);
  transition:border-color .2s ease,box-shadow .2s ease,transform .2s ease}
.qsw:hover{transform:translateY(-2px)}
.qsw:active{transform:translateY(0)}
.qsw[aria-pressed="true"]{border:3px solid #2d2d2d;box-shadow:0 0 12px var(--c)}

/* ---------- size slider ---------- */
.rail-size{display:flex;align-items:center;gap:12px;padding:2px 2px 4px}
/* The input is 28px tall (comfortable touch target) but paints its 6px track
   as a centered background stripe, so it still looks like a slim slider.
   min-width:0 lets it flex-shrink below its ~129px native minimum. */
#size{flex:1;min-width:0;height:28px;border-radius:8px;
  background:linear-gradient(to right,#f4a4d4,#d4c4f0) no-repeat center/100% 6px;
  -webkit-appearance:none;appearance:none;outline-offset:4px;cursor:pointer;margin:0;
  font-size:16px} /* ≥16px so focusing it never triggers iOS auto-zoom */
#size::-webkit-slider-thumb{-webkit-appearance:none;appearance:none;width:22px;height:22px;
  border-radius:50%;background:#fff;border:3px solid var(--pink-soft);
  box-shadow:0 2px 8px rgba(244,164,212,.3);cursor:pointer}
#size::-moz-range-thumb{width:22px;height:22px;border-radius:50%;background:#fff;
  border:3px solid var(--pink-soft);box-shadow:0 2px 8px rgba(244,164,212,.3);cursor:pointer}
#preview{width:34px;height:34px;flex:0 0 auto;border-radius:50%;border:2px solid #e8e8e8;
  display:flex;align-items:center;justify-content:center;background:#fff}
#previewDot{border-radius:50%;background:#ec4899}

/* ---------- page utilities (clear / left-handed) ---------- */
.rail-page{display:flex;flex-direction:column;gap:8px}
.ubtn{display:flex;align-items:center;gap:12px;width:100%;min-height:44px;
  padding:12px 14px;border-radius:var(--r-btn);border:2px solid #e8e8e8;background:#fff;
  cursor:pointer;font-family:inherit;font-size:14px;font-weight:500;color:var(--ink);text-align:left;
  transition:background .2s ease,border-color .2s ease,color .2s ease}
.ubtn svg{width:28px;height:28px;flex:0 0 auto;display:block;pointer-events:none}
.ubtn .em{font-size:22px;line-height:1;width:28px;text-align:center;flex:0 0 auto}
.ubtn:hover{border-color:rgba(244,164,212,.5);background:#fef7fb}
.ubtn.armed,.ubtn[aria-checked="true"]{background:linear-gradient(135deg,#fce4f3,#f9d9ed);
  border-color:var(--pink-soft);color:var(--pink)}

/* visible keyboard focus across every control */
.tbtn:focus-visible,.abtn:focus-visible,.cc-big:focus-visible,
.qsw:focus-visible,.ubtn:focus-visible,.zbtn:focus-visible,.help-btn:focus-visible,
#size:focus-visible{outline:3px solid #a8d5ff;outline-offset:2px}
@media(prefers-reduced-motion:reduce){
  .abtn,.tbtn,.qsw,.cc-big,.zbtn,.ubtn,.help-btn{transition:none}
}

/* ---------- canvas ---------- */
/* the app handles two-finger pinch zoom/pan itself (workspace is
   touch-action:none); single-finger input goes to drawing */
#board{display:block;width:100%;height:100%;touch-action:none;cursor:crosshair}
#lines{position:absolute;inset:0;width:100%;height:100%;pointer-events:none}
#cursorRing{position:absolute;border:1.5px solid rgba(45,45,45,.5);border-radius:50%;pointer-events:none;display:none;transform:translate(-50%,-50%)}
.hint{position:absolute;top:12px;left:50%;transform:translateX(-50%);margin:0;max-width:92%;
  font-size:12px;font-weight:600;color:var(--ink);background:#fff;
  padding:8px 16px;border-radius:999px;box-shadow:var(--shadow-btn);
  pointer-events:none;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
/* hints announce, then fade away so they never sit over the artwork */
.hint.idle{opacity:0}

/* ---------- rotate gate: the studio is a landscape experience ----------
   Shown only on touch devices held in portrait (desktop windows and the
   home/theme pages are never gated). Sits above the tutorial (70) and
   below the splash (100) so launch still feels seamless. */
#rotateGate{display:none}
@media (orientation:portrait) and (pointer:coarse){
  #rotateGate:not(.dismissed){display:flex;position:fixed;inset:0;z-index:95;
    align-items:center;justify-content:center;text-align:center;
    background:linear-gradient(135deg,#f5e6f0,#e8d5f2);
    padding:calc(24px + env(safe-area-inset-top)) 24px calc(24px + env(safe-area-inset-bottom))}
}
.rg-inner{display:flex;flex-direction:column;align-items:center;gap:14px}
.rg-phone{font-size:64px;line-height:1;filter:drop-shadow(0 8px 14px rgba(212,84,141,.22));
  animation:rgTurn 2s ease-in-out infinite}
@keyframes rgTurn{0%,15%{transform:rotate(0)}50%,88%{transform:rotate(90deg)}100%{transform:rotate(90deg)}}
.rg-inner p{margin:0;font-size:18px;font-weight:700;color:var(--pink);line-height:1.5}
@media (prefers-reduced-motion:reduce){.rg-phone{animation:none;transform:rotate(90deg)}}

/* pointer-events:none — the toast is informational and floats over the
   bottom-center zoom row on phones; it must never swallow their taps */
#toast{position:fixed;left:50%;bottom:calc(24px + env(safe-area-inset-bottom));transform:translateX(-50%);
  background:#fff;color:var(--pink);font-size:13px;font-weight:600;padding:12px 20px;border-radius:16px;
  box-shadow:0 4px 16px rgba(200,160,220,.35);z-index:50;max-width:90vw;text-align:center;
  pointer-events:none}

/* ---------- left-handed mode: mirror the stage ---------- */
#app.left-handed .stage{flex-direction:row-reverse}
#app.left-handed .rail{margin-left:0;margin-right:14px}

/* paint-bucket processing feedback */
.canvas-wrap.busy,.canvas-wrap.busy #board{cursor:progress}

/* ---------- quiet chrome: fade the UI while actively coloring ----------
   Opacity only — never display/size changes, which would resize the
   workspace and rescale the canvas mid-stroke via the ResizeObserver. */
.appbar,.rail,.zoomctl,.hint{transition:opacity .25s ease}
#app.ui-quiet .appbar,#app.ui-quiet .rail,
#app.ui-quiet .zoomctl,#app.ui-quiet .hint{opacity:.15;pointer-events:none}
/* Focus mode (fullscreen fallback + "hide the buttons" on any device):
   like ui-quiet but persistent; the zoom cluster stays usable as the exit. */
#app.focus-mode .appbar,#app.focus-mode .rail,#app.focus-mode .hint{opacity:0;pointer-events:none}
#app.focus-mode .zoomctl{opacity:1;pointer-events:auto}
@media(prefers-reduced-motion:reduce){.appbar,.rail,.zoomctl,.hint{transition:none}}

/* ---------- help dialog ---------- */
.help-pop{position:fixed;z-index:60;left:50%;top:50%;transform:translate(-50%,-50%);
  width:min(440px,calc(100vw - 24px));max-height:calc(100dvh - 24px);overflow-y:auto;
  background:#fff;border:2px solid #dbe4f6;border-radius:22px;padding:20px 22px;
  box-shadow:0 18px 50px rgba(120,100,160,.32);overscroll-behavior:contain}
.help-pop.open{animation:popInC .22s cubic-bezier(.34,1.56,.64,1)}
@keyframes popInC{from{opacity:0;transform:translate(-50%,-48%) scale(.85)}to{opacity:1;transform:translate(-50%,-50%) scale(1)}}
.help-pop h2{margin:0 0 4px;font-size:22px;color:var(--pink)}
.help-sec{margin:16px 0 6px;font-size:12px;font-weight:600;color:var(--ink-soft);
  text-transform:uppercase;letter-spacing:.5px}
.help-list{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:9px}
.help-list li{display:flex;gap:10px;align-items:flex-start;font-size:13.5px;line-height:1.45}
.help-list strong{color:#3d3d3d}
.help-em{font-size:19px;line-height:1.3;flex:0 0 24px;text-align:center}
.help-em svg{width:24px;height:24px;display:block;margin:0 auto}
.help-actions{display:flex;gap:10px;justify-content:flex-end;margin-top:18px;flex-wrap:wrap}
.help-btn{min-height:44px;padding:10px 22px;border-radius:999px;border:none;cursor:pointer;
  font-family:inherit;font-size:14px;font-weight:600;color:#fff;
  background:linear-gradient(180deg,#f79ab2,#ee7d9d);box-shadow:0 3px 0 #d96687;
  transition:transform .15s ease,box-shadow .15s ease}
.help-btn:hover{transform:translateY(-2px);box-shadow:0 5px 0 #d96687}
.help-btn:active{transform:translateY(0);box-shadow:0 2px 0 #d96687}
.help-btn.ghost{background:#fff;color:var(--pink);box-shadow:inset 0 0 0 2px #f4a4d4}
.help-btn.ghost:hover{background:#fef7fb}

/* ---------- first-visit tutorial ---------- */
#tutorial{position:fixed;inset:0;z-index:70;display:grid;place-items:center;
  background:rgba(80,60,110,.3);padding:20px}
.tut-card{width:min(360px,100%);background:#fff;border-radius:26px;padding:26px 24px 20px;
  text-align:center;box-shadow:0 18px 50px rgba(120,100,160,.35);
  animation:popTut .25s cubic-bezier(.34,1.56,.64,1)}
@keyframes popTut{from{opacity:0;transform:scale(.85)}to{opacity:1;transform:scale(1)}}
.tut-art{font-size:52px;line-height:1;filter:drop-shadow(0 6px 12px rgba(212,84,141,.2))}
.tut-art svg{width:58px;height:58px;display:block;margin:0 auto}
.tut-card h2{margin:12px 0 6px;font-size:21px;color:var(--pink)}
.tut-card p{margin:0;font-size:14.5px;line-height:1.5;color:var(--ink)}
.tut-dots{display:flex;gap:7px;justify-content:center;margin:16px 0 4px}
.tut-dots i{width:9px;height:9px;border-radius:50%;background:#eddcf0;transition:background .2s ease}
.tut-dots i.on{background:var(--pink-soft)}
.tut-actions{display:flex;gap:10px;justify-content:center;margin-top:12px}
/* the opt-out lives in the card so nobody has to guess how to stop the tour */
.tut-remember{display:flex;align-items:center;justify-content:center;gap:8px;margin-top:14px;
  font-size:13.5px;font-weight:600;color:var(--ink-soft);cursor:pointer;min-height:24px;user-select:none}
.tut-remember input{width:18px;height:18px;margin:0;accent-color:var(--pink);cursor:pointer}
.tut-remember input:focus-visible{outline:3px solid #a8d5ff;outline-offset:2px}
@media(prefers-reduced-motion:reduce){.color-pop.open,.help-pop.open,.tut-card{animation:none}}

/* ============================================================
   TIER B — tablet landscape / small desktop
   ============================================================ */
@media(max-width:1180px) and (min-height:521px){
  .rail{width:220px;margin-left:12px;padding:12px}
  #app.left-handed .rail{margin-right:12px}
  .abtn{width:64px}
  /* tighter rows so the whole rail fits tablet heights without scrolling */
  .sec{margin:10px 0 6px}
  .rail-tools,.rail-page{gap:6px}
  .tbtn,.ubtn{padding:9px 12px}
}

/* ============================================================
   TIER C — tablet portrait: compact icon rail, labels under icons
   ============================================================ */
@media(min-width:641px) and (max-width:1023px) and (orientation:portrait){
  #app{padding-left:calc(8px + env(safe-area-inset-left));padding-right:calc(8px + env(safe-area-inset-right))}
  .rail{width:96px;margin-left:10px;padding:10px 6px;gap:4px}
  #app.left-handed .rail{margin-right:10px}
  .sec{justify-content:center;font-size:10px;margin:10px 0 6px}
  .tbtn{flex-direction:column;gap:3px;padding:8px 2px;min-height:56px}
  .tbtn span{flex:0 0 auto;font-size:10px;width:100%;text-align:center}
  .ubtn{flex-direction:column;gap:3px;padding:8px 2px;min-height:56px}
  .ubtn span:not(.em){font-size:10px;width:100%;text-align:center;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
  .cc-big{width:52px;height:52px}
  .rail-size{flex-direction:column;gap:6px;padding:0}
  #size{width:100%}
}

/* ============================================================
   TIER D — phone portrait: slim top bar + fixed two-row dock
   (nothing scrolls, nothing hides)
   ============================================================ */
@media(max-width:640px) and (orientation:portrait){
  #app{padding:calc(6px + env(safe-area-inset-top)) 6px calc(6px + env(safe-area-inset-bottom))}
  .appbar{gap:6px;padding-bottom:6px;align-items:center}
  .logo{font-size:15px;gap:3px}
  .logo .bead{font-size:18px}
  .actions{gap:6px;flex:1;justify-content:flex-end}
  .abtn{flex:0 1 60px;width:auto;min-width:44px;padding:7px 0;border-radius:var(--r-btn)}
  .abtn svg{width:22px;height:22px}
  .abtn span{font-size:9px}
  .stage,#app.left-handed .stage{flex-direction:column}
  .canvas-wrap{border-radius:14px}
  /* the dock: row 1 = all six tools, row 2 = color · size · trash · lefty */
  .rail,#app.left-handed .rail{width:100%;height:auto;flex:0 0 auto;margin:6px 0 0;
    padding:8px;display:grid;gap:8px;align-items:center;
    grid-template-columns:auto 1fr auto auto;
    grid-template-areas:"tools tools tools tools" "color size clear lefty";
    overflow:visible}
  .sec{display:none}
  .rail-tools{grid-area:tools;display:grid;grid-template-columns:repeat(6,1fr);gap:6px}
  .tbtn{width:auto;min-height:48px;justify-content:center;gap:0;padding:6px 0}
  .tbtn span{display:none}
  .cc-big{grid-area:color;width:48px;height:48px;margin:0}
  .cc-big .cc-dot{width:34px;height:34px}
  .rail-size{grid-area:size;min-width:0;gap:8px;padding:0 2px}
  .rail-page{display:contents}   /* its two buttons place into the grid */
  .ubtn{width:auto;min-width:48px;min-height:48px;justify-content:center;gap:0;padding:6px}
  .ubtn span:not(.em){display:none}
  #clearBtn{grid-area:clear}
  #leftHandBtn{grid-area:lefty;flex-direction:column;gap:1px;padding:3px 6px}
  #leftHandBtn .em{font-size:17px}
  #leftHandBtn .ubtn-label{display:block;font-size:8px;line-height:1;white-space:nowrap}
  .color-pop{top:44%;padding:14px}
  /* finger-sized swatches on phones */
  .rail-colors{grid-template-columns:repeat(4,48px);gap:8px}
  .qsw{width:44px}
  /* zoom cluster: one horizontal row hugging the bottom edge, out of the
     middle of the artwork; it also fades while actively coloring */
  .zoomctl{flex-direction:row;right:auto;left:50%;transform:translateX(-50%);bottom:6px;gap:6px}
  .hint{font-size:11px;padding:7px 13px}
}

/* very narrow phones: drop the logo text so all six action cards fit */
@media(max-width:520px){
  .logo-text{display:none}
  .logo .bead{font-size:22px}
}
/* narrowest phones (320px): the six cards need every pixel — drop the logo */
@media(max-width:374px) and (orientation:portrait){
  .logo{display:none}
  .actions{justify-content:space-between}
}

/* ============================================================
   TIER E — phone landscape: the artwork gets the whole height.
   App bar becomes a left icon column, tools a right icon column.
   ============================================================ */
@media(orientation:landscape) and (max-height:520px){
  #app{flex-direction:row;
    padding:calc(4px + env(safe-area-inset-top)) calc(6px + env(safe-area-inset-right)) calc(4px + env(safe-area-inset-bottom)) calc(6px + env(safe-area-inset-left))}
  #app.left-handed{flex-direction:row-reverse}
  /* app bar → left icon column */
  .appbar{flex-direction:column;align-items:center;justify-content:flex-start;gap:6px;
    width:56px;flex:0 0 auto;padding:0 6px 0 0;overflow-y:auto;scrollbar-width:none}
  #app.left-handed .appbar{padding:0 0 0 6px}
  .appbar::-webkit-scrollbar{display:none}
  .logo{font-size:0;gap:0;align-self:center;padding:2px 0}
  .logo .bead{font-size:20px}
  .logo-text{display:none}
  .actions{flex-direction:column;gap:4px;flex:0 0 auto;justify-content:flex-start}
  .abtn{width:48px;min-width:0;min-height:44px;padding:5px 0;border-radius:12px;gap:2px;justify-content:center}
  .abtn svg{width:22px;height:22px}
  .abtn span{display:none}
  /* stage fills the rest; tools → right two-column icon panel.
     Width is free in landscape (the tall artwork is height-bound), so the
     panel goes two columns wide to fit every control without scrolling. */
  .stage{flex-direction:row}
  .canvas-wrap{border-radius:12px}
  .rail,#app.left-handed .rail{width:106px;height:auto;margin:0 0 0 6px;padding:6px;
    display:grid;grid-template-columns:1fr 1fr;gap:4px;align-content:start;
    overflow-y:auto;overflow-x:hidden}
  #app.left-handed .rail{margin:0 6px 0 0}
  .sec{display:none}
  .rail-tools,.rail-page{display:contents}
  .tbtn,.ubtn{width:100%;min-height:44px;justify-content:center;gap:0;padding:4px 2px}
  .tbtn span,.ubtn span:not(.em){display:none}
  .tbtn svg,.ubtn svg{width:24px;height:24px}
  .ubtn .em{font-size:19px;width:auto}
  .cc-big{grid-column:1 / -1;width:44px;height:44px;margin:2px auto}
  .cc-big .cc-dot{width:30px;height:30px}
  .rail-size{grid-column:1 / -1;flex-direction:row;align-items:center;gap:4px;width:auto;padding:0}
  #size{flex:1;min-width:0;height:26px}
  #preview{width:26px;height:26px}
  /* zoom cluster: horizontal row so it never collides with the tool column */
  .zoomctl{flex-direction:row;right:auto;left:50%;transform:translateX(-50%);bottom:6px;gap:6px}
  .hint{font-size:11px;padding:6px 12px;top:6px}
  #toast{bottom:calc(10px + env(safe-area-inset-bottom))}
}
/* shortest landscape screens (old SE): the six actions need the whole column */
@media(orientation:landscape) and (max-height:340px){
  .logo{display:none}
}
