/* ============================================================
   Tiny Canvas — main stylesheet
   ============================================================
   Onioncore tokens lifted directly from ../DESIGN.md. The coloring
   surface itself ("paper") is a deviation from canon dark: the
   canvas reads light so colors land on a familiar coloring-book
   substrate. UI chrome stays dark.
   ============================================================ */

/* ----- 0. Fonts (SELF-HOSTED — do not put these back on a CDN) -----
   Vendored locally rather than loaded from fonts.googleapis.com. Two
   reasons, both load-bearing for this particular product:

     1. Offline. The app's whole promise is that it works with no
        network. A CDN font means the logo and every label silently
        fall back to system fonts the moment the kid is off-grid —
        and with Bungee and Press Start 2P that isn't graceful
        degradation, it's a different-looking app.

     2. Data Safety. Tiny Canvas declares "no data collected" and
        deliberately ships no analytics (see the GoatCounter note in
        index.html). A Google Fonts request hands Google the client IP
        on every single launch, contradicting exactly that claim — and
        it is the sort of thing a Designed for Families review looks
        for.

   All three are SIL Open Font License, free to self-host.
   74.7KB total: bungee 14.3K, vt323 31.2K, press-start-2p 29.2K. */

@font-face {
    font-family: "Bungee";
    src: url("assets/fonts/bungee-latin.woff2") format("woff2");
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: "VT323";
    src: url("assets/fonts/vt323.woff2") format("woff2");
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: "Press Start 2P";
    src: url("assets/fonts/press-start-2p.woff2") format("woff2");
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

/* ----- 1. Tokens (canon — see ../DESIGN.md §2) ----- */

:root {
    /* Onioncore base */
    --bg-deep:      #06141a;
    --bg-stage:     #0c1f25;
    --bg-panel:     #0f2a32;
    --bg-frame:     #143842;

    --teal:         #00ffcc;
    --teal-dim:     #4dd9b8;
    --teal-low:     #0a665a;

    --pink:         #ff2e88;
    --pink-bright:  #ff5cab;
    --pink-deep:    #b81866;

    --ink:          #eaf6f4;
    --ink-dim:      #9fb8b6;
    --ink-low:      #5a7773;

    /* Tiny Canvas deviation: the drawing surface is bright like
       a real coloring book. See tiny-canvas/CLAUDE.md for why. */
    --paper:        #fbfaf6;
    --paper-shade:  #e9e6dc;
    --line-ink:     #1c2226;

    --font-title:   "Bungee", "Impact", "Haettenschweiler",
                    "Arial Narrow Bold", system-ui, sans-serif;
    --font-lcd:     "VT323", "Courier New", monospace;
    --font-mono:    "Press Start 2P", "VT323", "Courier New", monospace;
    --font-ui:      system-ui, -apple-system, "Segoe UI", Roboto,
                    "Helvetica Neue", Arial, sans-serif;

    --content-max:  920px;
    --radius-sm:    4px;
    --radius-md:    8px;
    --radius-lg:    14px;
}

/* ----- 2. Reset / base ----- */

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg-deep);
    color: var(--ink);
    font-family: var(--font-ui);
    min-height: 100vh;
    min-height: 100dvh;
}

body {
    background:
        radial-gradient(ellipse at 50% 0%,
            rgba(0, 255, 204, 0.06) 0%, transparent 55%),
        linear-gradient(180deg,
            #07181e 0%, var(--bg-deep) 60%, #04101a 100%);
    background-attachment: fixed;
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
    -webkit-text-size-adjust: 100%;
}

body::before {
    content: "";
    position: fixed; inset: 0;
    pointer-events: none;
    background-image: repeating-linear-gradient(0deg,
        rgba(255,255,255,0.025) 0px, rgba(255,255,255,0.025) 1px,
        transparent 1px, transparent 3px);
    z-index: 9000;
    mix-blend-mode: overlay;
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
    color: inherit;
}

a {
    color: var(--teal);
    text-decoration: none;
}

a:hover,
a:focus-visible {
    color: var(--pink-bright);
    text-decoration: underline;
}

:focus-visible {
    outline: 2px solid var(--pink);
    outline-offset: 3px;
    border-radius: 2px;
}

/* ----- 3. Screens ----- */

.screen {
    max-width: var(--content-max);
    margin: 0 auto;
    padding: 24px 16px 72px;
    min-height: calc(100vh - 110px);
    display: flex;
    flex-direction: column;
}

.screen[hidden] { display: none; }

/* ----- 4. Title screen ----- */

.title-stack {
    margin: 24px auto 0;
    width: 100%;
    max-width: 720px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 28px;
    position: relative;
}

.big-title {
    font-family: var(--font-title);
    margin: 0;
    text-align: center;
    line-height: 0.95;
    text-transform: uppercase;
    display: flex;
    flex-direction: column;
    gap: 8px;
    text-shadow:
        4px 4px 0 var(--pink-deep),
        -1px -1px 0 #fff,
        0 0 28px rgba(255, 46, 136, 0.45);
    animation: title-wobble 5.5s ease-in-out infinite;
    transform-origin: 50% 60%;
}

.big-title .line-1,
.big-title .line-2 { white-space: nowrap; }

.big-title .line-1 {
    font-size: clamp(36px, 10vw, 88px);
    color: var(--ink);
    letter-spacing: 0.5px;
}

.big-title .line-2 {
    font-size: clamp(54px, 14vw, 132px);
    color: var(--teal);
    letter-spacing: 1px;
    text-shadow:
        4px 4px 0 var(--pink-deep),
        -2px -2px 0 #fff,
        0 0 36px rgba(0, 255, 204, 0.5);
}

@keyframes title-wobble {
    0%, 100% { transform: rotate(-0.6deg) translateY(0); }
    25%      { transform: rotate(0.5deg)  translateY(-2px); }
    50%      { transform: rotate(-0.4deg) translateY(1px); }
    75%      { transform: rotate(0.7deg)  translateY(-1px); }
}

/* Warm subtitle — kid-voice variant. Replaces the CRT/LCD chrome
   that the rest of madderverse uses. The pill reads as paper-on-dark:
   cream fill, soft pink border, no glow text shadows. Construction
   paper, not Win95. */
.warm-sub {
    margin: 0;
    font-family: var(--font-ui);
    font-size: clamp(18px, 3.4vw, 24px);
    letter-spacing: 0.4px;
    color: var(--bg-deep);
    text-align: center;
}

.warm-frame {
    display: inline-block;
    padding: 10px 20px;
    background: var(--paper);
    border: 2px solid var(--pink-bright);
    border-radius: 22px;
    box-shadow:
        0 2px 0 #02141a,
        0 6px 18px rgba(0, 0, 0, 0.5);
    font-weight: 500;
}

/* ----- 5. Menu buttons (.big-btn) ----- */

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 14px;
    width: min(360px, 88vw);
    margin-top: 12px;
}

.big-btn {
    --btn-bg:        #0f2a32;
    --btn-bg-hover:  #14404a;
    --btn-border:    var(--teal-low);
    --btn-fg:        var(--ink);
    --btn-glow:      rgba(0, 255, 204, 0.35);

    position: relative;
    width: 100%;
    padding: 18px 22px;
    font-family: var(--font-title);
    font-size: clamp(18px, 3.4vw, 22px);
    letter-spacing: 2px;
    text-transform: uppercase;
    background: var(--btn-bg);
    color: var(--btn-fg);
    border: 2px solid var(--btn-border);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    transition: transform 0.06s ease,
                background 0.12s ease,
                border-color 0.12s ease,
                box-shadow 0.12s ease;
    box-shadow:
        0 0 0 1px rgba(0, 0, 0, 0.4),
        0 6px 0 #02141a,
        0 8px 16px rgba(0, 0, 0, 0.5);
    text-shadow: 2px 2px 0 #000;
}

.big-btn:hover,
.big-btn:focus-visible {
    background: var(--btn-bg-hover);
    border-color: var(--teal);
    box-shadow:
        0 0 0 1px rgba(0, 0, 0, 0.4),
        0 6px 0 #02141a,
        0 0 18px var(--btn-glow);
    outline: none;
}

.big-btn:active {
    transform: translateY(3px);
    box-shadow:
        0 0 0 1px rgba(0, 0, 0, 0.4),
        0 3px 0 #02141a,
        0 0 12px var(--btn-glow);
}

.big-btn .btn-glyph {
    font-size: 1.3em;
    color: var(--teal);
    line-height: 1;
}

.big-btn.install {
    border-color: var(--teal);
    background: linear-gradient(180deg, #0d2a32 0%, #07181e 100%);
}
.big-btn.install .btn-glyph { color: var(--teal); }

.big-btn.primary {
    --btn-border:    var(--pink);
    --btn-fg:        #fff;
    --btn-glow:      rgba(255, 46, 136, 0.55);

    background: linear-gradient(180deg, #3a1024 0%, #20081a 100%);
    text-shadow:
        2px 2px 0 #000,
        0 0 12px rgba(255, 46, 136, 0.5);
}

.big-btn.primary:hover,
.big-btn.primary:focus-visible {
    background: linear-gradient(180deg, #51163a 0%, #2f0e26 100%);
}

.big-btn.primary .btn-glyph { color: var(--pink-bright); }

/* ----- 6. Screen titlebar ----- */

.screen-titlebar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 6px 4px 12px;
    margin-bottom: 12px;
    border-bottom: 1px dashed var(--teal-low);
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 1.2px;
}

.back-btn {
    color: var(--teal);
    padding: 5px 10px;
    border: 1px solid var(--teal-low);
    border-radius: var(--radius-sm);
    background: rgba(0, 255, 204, 0.04);
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 1px;
    white-space: nowrap;
    flex: 0 0 auto;
}

.back-btn:hover,
.back-btn:focus-visible {
    color: var(--pink-bright);
    border-color: var(--pink);
    background: rgba(255, 46, 136, 0.08);
    outline: none;
}

.screen-title {
    margin: 0;
    font-family: var(--font-title);
    color: var(--pink-bright);
    font-size: clamp(11px, 2.6vw, 20px);
    letter-spacing: 2.5px;
    text-shadow:
        2px 2px 0 #000,
        0 0 10px rgba(255, 46, 136, 0.45);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1 1 auto;
    text-align: center;
}

.screen-status {
    color: var(--teal-dim);
    font-family: var(--font-lcd);
    font-size: 16px;
    letter-spacing: 1.5px;
    text-shadow: 0 0 5px rgba(0, 255, 204, 0.4);
    white-space: nowrap;
    flex: 0 0 auto;
}

/* ----- 7. Picker screen ----- */

.picker-grid {
    width: 100%;
    max-width: 720px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
}

.pick-card {
    background:
        repeating-linear-gradient(0deg,
            rgba(0,0,0,0.18) 0 1px,
            transparent 1px 2px),
        linear-gradient(180deg, #082028 0%, #051218 100%);
    border: 1px solid var(--teal-low);
    border-radius: var(--radius-md);
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    cursor: pointer;
    transition: border-color 0.12s ease,
                box-shadow 0.12s ease,
                transform 0.06s ease;
    text-align: left;
}

.pick-card:hover,
.pick-card:focus-visible {
    border-color: var(--pink-bright);
    box-shadow: 0 0 14px rgba(255, 46, 136, 0.35);
    outline: none;
    transform: translateY(-2px);
}

.pick-thumb {
    aspect-ratio: 1 / 1;
    background: var(--paper);
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--teal-low);
    display: flex;
    align-items: center;
    justify-content: center;
}

.pick-thumb svg {
    width: 86%;
    height: 86%;
    color: var(--line-ink);
}

.pick-name {
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 1.2px;
    color: var(--ink);
    text-shadow: 1px 1px 0 #000;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ----- 8. Draw screen — full-viewport canvas ----- */

/* Body gets a paper background ONLY when the draw screen is showing,
   so the dark onioncore bg returns when the kid is on title / picker
   / gallery / settings. */
body.screen-draw {
    background:
        repeating-linear-gradient(0deg,
            rgba(212, 196, 152, 0.06) 0 1px,
            transparent 1px 12px),
        repeating-linear-gradient(90deg,
            rgba(212, 196, 152, 0.05) 0 1px,
            transparent 1px 12px),
        linear-gradient(180deg, #fbfaf6 0%, #f3eedf 100%);
}

body.screen-draw::before { display: none; }   /* hide scanlines on paper */

/* The draw screen is its own world — fixed inset 0, fills viewport. */
#screen-draw {
    position: fixed;
    inset: 0;
    padding: 0;
    margin: 0;
    max-width: none;
    overflow: hidden;
    min-height: 0;
}

/* Titlebar floats at the top with a backdrop-blur frosted pill so the
   paper shows through. Same brand chrome as the other screens, just
   rendered as a floating bar instead of a flow element. */
#screen-draw .screen-titlebar {
    position: fixed;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    width: min(640px, calc(100vw - 24px));
    margin: 0;
    padding: 6px 12px;
    border: 1px solid rgba(10, 102, 90, 0.45);
    border-bottom: 1px solid rgba(10, 102, 90, 0.45);
    border-radius: 16px;
    background: rgba(251, 250, 246, 0.78);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 50;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.12);
}

#screen-draw .back-btn {
    color: var(--teal-low);
    background: rgba(0, 255, 204, 0.05);
}
#screen-draw .back-btn:hover,
#screen-draw .back-btn:focus-visible {
    color: var(--pink-deep);
    border-color: var(--pink);
    background: rgba(255, 46, 136, 0.06);
}
#screen-draw .screen-title  { color: var(--pink-deep);  }
#screen-draw .screen-status { color: var(--teal-low);   }

/* The "stack" becomes a frameless container for the fixed-position
   canvas + line-art + onion. No layout duties. */
.draw-stack {
    position: static;
    display: block;
    width: 100%;
    height: 100%;
}

/* Canvas IS the viewport. */
#drawCanvas {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    background: transparent;
    border-radius: 0;
    touch-action: none;
    cursor: crosshair;
    user-select: none;
    -webkit-user-select: none;
    z-index: 5;
    aspect-ratio: auto;        /* override the 1:1 from base styles */
    display: block;
}

/* Line-art SVG renders centered on top of the canvas at a fixed
   visible size. Kid sees the printed page in the middle and paper
   extending out to all edges of the screen. */
.line-art {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width:  min(82vmin, 720px);
    height: min(82vmin, 720px);
    pointer-events: none;
    z-index: 10;
}

/* Idle scribble — kinetic centerpiece. Three brand-color paths
   each draw themselves over 12 seconds, offset by 4s so at any
   moment one shape is "writing" and the others rest at zero
   opacity. Reduced-motion users get a static heart instead. */
.idle-scribble {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width:  min(56vmin, 460px);
    height: auto;
    pointer-events: none;
    z-index: 8;          /* between canvas (5) and line-art (10) */
    transition: opacity 0.4s ease-out;
}

.idle-scribble.is-hidden {
    opacity: 0;
}

.idle-scribble .scribble {
    fill: none;
    stroke-width: 14;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-dasharray: 1300;
    stroke-dashoffset: 1300;
    opacity: 0;
    filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.08));
}

#scribbleHeart {
    stroke: #ff2e88;
    animation: idle-scribble-cycle 12s ease-in-out infinite 0s;
}
#scribbleStar {
    stroke: #ffd23f;
    animation: idle-scribble-cycle 12s ease-in-out infinite 4s;
}
#scribbleSquiggle {
    stroke: #00ffcc;
    animation: idle-scribble-cycle 12s ease-in-out infinite 8s;
}

@keyframes idle-scribble-cycle {
    0%   { stroke-dashoffset: 1300; opacity: 0; }
    5%   { opacity: 1; }
    25%  { stroke-dashoffset: 0;    opacity: 1; }   /* fully drawn */
    33%  { opacity: 1; }                            /* hold */
    40%  { opacity: 0; }                            /* fade out */
    100% { stroke-dashoffset: 0;    opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
    /* Show only the heart, statically drawn at full opacity. No
       cycling motion. Still functions as a "draw here" hint. */
    .idle-scribble .scribble {
        animation: none !important;
        stroke-dashoffset: 0;
    }
    #scribbleHeart    { opacity: 0.7; }
    #scribbleStar     { display: none; }
    #scribbleSquiggle { display: none; }
}

.line-art svg {
    width: 100%;
    height: 100%;
    color: var(--line-ink);
    filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.06));
}

/* Floating undo button — top-right of the viewport, clear of the
   floating titlebar. */
/* ⚠ These two float BELOW the titlebar, not level with it.
   Both used to sit at top:16px — which is exactly where the titlebar's
   back button and status label already are. The PAGES pill landed on
   top of "← HOME", covering the arrow, and UNDO landed under "READY"
   at the very edge of the screen, clipped and (being disabled by
   default) faded to 35% opacity. The single most important safety
   control in a kids' drawing app was a pale grey sliver hiding behind
   a status label.
   --overlay-top clears the titlebar and respects the notch, since the
   page is viewport-fit=cover. */
:root {
    --overlay-top: calc(env(safe-area-inset-top, 0px) + 76px);
}

/* Tray UNDO sits with CLEAR/SAVE — there is no floating twin any more.
   Two undo buttons was one too many; the tray is where people look. */
#drawUndo .btn-glyph { font-size: 17px; }

/* Floating PAGES button — top-left mirror of UNDO. Optional template
   picker so kids who want a guided coloring page can grab one without
   the app forcing the picker grid on every launch. Pill-shaped with
   a tiny grid glyph + a short label so it reads at a glance. */
#screen-draw .pages-btn {
    position: fixed;
    top: var(--overlay-top);
    left: 14px;
    z-index: 60;
    width: auto;
    height: 40px;
    padding: 0 14px;
    border-radius: 20px;
    background: rgba(12, 31, 37, 0.85);
    border: 1px solid var(--pink-bright);
    color: var(--pink-bright);
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 1.4px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    line-height: 1;
    text-shadow: 1px 1px 0 #000;
}

#screen-draw .pages-btn:hover,
#screen-draw .pages-btn:focus-visible {
    background: rgba(20, 64, 74, 0.92);
    border-color: var(--pink);
    color: #fff;
    outline: none;
    box-shadow: 0 0 14px rgba(255, 46, 136, 0.45);
}

.pages-glyph {
    font-size: 14px;
    line-height: 1;
}

@media (max-width: 480px) {
    /* Compact on narrow phones — drop the label so the pill stays
       out of the kid's drawing area. The aria-label keeps it
       accessible. */
    #screen-draw .pages-btn .pages-label { display: none; }
    #screen-draw .pages-btn {
        padding: 0;
        width: 40px;
        justify-content: center;
    }
}

/* ----- Onion mascot ----- */

.onion {
    position: fixed;
    left: 16px;
    bottom: 40px;
    width: 96px;
    height: 112px;
    z-index: 55;
    pointer-events: none;
    transform-origin: 50% 100%;
    /* Slow gentle sway when idle. */
    animation: onion-sway 5s ease-in-out infinite;
}

.onion svg {
    width: 100%;
    height: 100%;
    display: block;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.15));
}

@keyframes onion-sway {
    0%, 100% { transform: rotate(-2deg); }
    50%      { transform: rotate(2deg); }
}

/* Blink via brief vertical scale on the pupils + highlights.
   Sneaky timing makes it feel naturalistic. */
.onion .pupil,
.onion .highlight {
    transform-box: fill-box;
    transform-origin: 50% 50%;
    animation: onion-blink 4.6s ease-in-out infinite;
}

@keyframes onion-blink {
    0%, 94%, 100% { transform: scaleY(1); }
    96%, 98%      { transform: scaleY(0.08); }
}

/* Pupil tracking: JS sets transform="translate(...)" on the eye groups
   directly so we don't fight CSS animations. The blink animation
   targets pupils + highlights individually; tracking moves the
   parent <g>. */

/* Sparkles only show during .is-saved */
.onion .onion-sparkles { opacity: 0; transition: opacity 0.2s; }
.onion.is-saved .onion-sparkles {
    opacity: 1;
    animation: onion-sparkle 0.9s ease-out;
}

@keyframes onion-sparkle {
    0%   { opacity: 0; transform: scale(0.3); }
    40%  { opacity: 1; transform: scale(1.15); }
    100% { opacity: 0; transform: scale(1.4); }
}

/* Mouth state machine: all mouths exist in DOM; CSS picks which is
   visible. idle is the default. */
.onion .mouth         { opacity: 0; transition: opacity 0.15s; }
.onion .mouth-idle    { opacity: 1; }

.onion.is-drawing .mouth-idle    { opacity: 0; }
.onion.is-drawing .mouth-open    { opacity: 1; }

.onion.is-saved .mouth-idle      { opacity: 0; }
.onion.is-saved .mouth-big       { opacity: 1; }

.onion.is-cleared .mouth-idle    { opacity: 0; }
.onion.is-cleared .mouth-surprise{ opacity: 1; }

/* Drawing: little bouncing on top of the sway. */
@keyframes onion-bob {
    0%, 100% { transform: rotate(-2deg) translateY(0);   }
    50%      { transform: rotate(2deg)  translateY(-4px); }
}
.onion.is-drawing {
    animation: onion-bob 0.8s ease-in-out infinite;
}

/* Saved: little victory jump (overrides the sway). */
@keyframes onion-jump {
    0%   { transform: translateY(0)   rotate(0); }
    25%  { transform: translateY(-24px) rotate(-6deg); }
    50%  { transform: translateY(0)   rotate(4deg); }
    75%  { transform: translateY(-10px) rotate(-3deg); }
    100% { transform: translateY(0)   rotate(0); }
}
.onion.is-saved {
    animation: onion-jump 0.9s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Cleared: brief shudder/freeze. */
@keyframes onion-shudder {
    0%, 100% { transform: rotate(-2deg); }
    20%      { transform: rotate(2deg) translateX(-2px); }
    40%      { transform: rotate(-2deg) translateX(2px); }
    60%      { transform: rotate(2deg) translateX(-1px); }
}
.onion.is-cleared {
    animation: onion-shudder 0.5s ease-in-out 2;
}

/* Reduced-motion users: kill the constant sway + bob.
   Keep state transitions visible via opacity (mouth swaps still work). */
@media (prefers-reduced-motion: reduce) {
    .onion,
    .onion.is-drawing,
    .onion.is-saved,
    .onion.is-cleared {
        animation: none !important;
    }
    .onion .pupil,
    .onion .highlight {
        animation: none !important;
    }
}

/* ----- canvas-wrap and the old border frame are GONE on the draw
         screen since canvas now fills the viewport directly. The
         class still exists in case other screens use it. ----- */

/* .canvas-wrap is no longer used on the draw screen (canvas is now
   fixed inset 0). Kept here for parity with any other screen that
   might wrap a canvas (none do today). */
.canvas-wrap {
    position: relative;
    display: inline-block;
}

/* Shared floating-overlay button base — actual fixed positioning is
   set per-screen (see #screen-draw .canvas-overlay-btn above). */
.canvas-overlay-btn {
    /* 48px, not 40 — this is the undo target for a small child, and 40
       was under the 44px minimum touch target both platforms publish. */
    width: 48px;
    height: 48px;
    padding: 0;
    border-radius: 50%;
    background: rgba(12, 31, 37, 0.85);
    border: 1px solid var(--teal-low);
    color: var(--teal);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    transition: background 0.12s ease,
                border-color 0.12s ease,
                color 0.12s ease,
                box-shadow 0.12s ease,
                transform 0.06s ease;
    text-shadow: 0 0 6px rgba(0, 255, 204, 0.3);
    z-index: 2;
}

.canvas-overlay-btn:hover,
.canvas-overlay-btn:focus-visible {
    background: rgba(20, 64, 74, 0.9);
    border-color: var(--teal);
    color: var(--pink-bright);
    outline: none;
    box-shadow: 0 0 14px rgba(255, 46, 136, 0.35);
}

.canvas-overlay-btn:active { transform: translateY(1px); }

.canvas-overlay-btn[disabled] {
    /* Was 0.35 — near-invisible against the light paper canvas, on the
       one control a kid reaches for after a mistake. Still clearly
       "off", but still clearly THERE, so it can be found before it's
       needed. */
    opacity: 0.6;
    cursor: not-allowed;
    color: var(--ink-low);
    border-color: var(--ink-low);
    text-shadow: none;
    box-shadow: none;
}

/* ----- 9. Tool rail / drawer ----- */

.draw-side-rail {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    width: 100%;
    max-width: 560px;
}

.drawer-handle { display: none; }

.draw-tools {
    width: 100%;
    max-width: 560px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px;
    background:
        repeating-linear-gradient(0deg,
            rgba(0,0,0,0.18) 0 1px,
            transparent 1px 2px),
        linear-gradient(180deg, #082028 0%, #051218 100%);
    border: 1px solid var(--teal-low);
    border-radius: var(--radius-md);
    box-shadow:
        inset 0 0 16px rgba(0, 0, 0, 0.5),
        0 0 0 1px rgba(0, 0, 0, 0.4);
}

.tool-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.row-label {
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 1.4px;
    color: var(--teal-dim);
    min-width: 52px;
    flex: 0 0 auto;
    text-shadow: 0 0 4px rgba(0, 255, 204, 0.3);
}

/* Tool row: 6 brush cards in a 3-column grid; eraser spans the
   full width below as its own visually distinct row. Each button
   is a vertical mini-card with an SVG icon on top and a small
   label underneath — readable at any rail width, never truncates. */
.tool-modes {
    display: grid;
    /* 4 across, not 3. With 3 columns the seven brush tools left FILL
       stranded alone on a third row beside two empty cells, which reads
       as an unfinished grid. Four columns packs them 4+3 and lets the
       full-width ERASE close the block deliberately. */
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
}

.tool-btn {
    padding: 10px 4px 8px;
    font-family: var(--font-mono);
    font-size: 9px;
    letter-spacing: 1.2px;
    background: var(--bg-panel);
    color: var(--ink);
    border: 1px solid var(--teal-low);
    border-radius: var(--radius-md);
    transition: background 0.12s ease,
                color 0.12s ease,
                border-color 0.12s ease,
                box-shadow 0.12s ease,
                transform 0.06s ease;
    text-shadow: 1px 1px 0 #000;
    /* Vertical card layout: icon on top, label below. */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-height: 64px;
}

.tool-icon {
    width: 26px;
    height: 26px;
    color: var(--teal);
    transition: color 0.12s ease;
    /* drop-shadow lifts the icon slightly off the card background */
    filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.4));
}

.tool-label {
    line-height: 1;
}

.tool-btn:hover,
.tool-btn:focus-visible {
    background: #14404a;
    border-color: var(--teal);
    outline: none;
}

.tool-btn:active { transform: translateY(1px); }

.tool-btn.active {
    background: linear-gradient(180deg, #ff3d96 0%, #b81866 100%);
    color: #fff;
    border-color: var(--pink-bright);
    box-shadow:
        inset 0 0 10px rgba(255, 255, 255, 0.18),
        0 0 12px rgba(255, 46, 136, 0.5);
}

.tool-btn.active .tool-icon {
    color: #fff;
    filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.5));
}

/* Eraser is visually distinct from the 6 brushes — spans the full
   width below the brush grid, gets a teal outline so "destructive"
   reads at a glance. Active state still goes pink. */
.tool-btn.tool-eraser {
    grid-column: 1 / -1;
    flex-direction: row;
    min-height: 44px;
    padding: 8px 14px;
    gap: 10px;
    border-color: var(--teal);
    background: linear-gradient(180deg, #0d2a32 0%, #07181e 100%);
    color: var(--teal);
}
.tool-btn.tool-eraser .tool-icon {
    width: 22px;
    height: 22px;
}
.tool-btn.tool-eraser:hover,
.tool-btn.tool-eraser:focus-visible {
    border-color: var(--pink);
    color: var(--pink-bright);
    background: linear-gradient(180deg, #14404a 0%, #0a2030 100%);
}
.tool-btn.tool-eraser.active {
    background: linear-gradient(180deg, #ff3d96 0%, #b81866 100%);
    color: #fff;
    border-color: var(--pink-bright);
}

/* Dynamic size-row host — JS injects 3 or 5 buttons depending on
   the active tool. Flex so they line up evenly. */
.size-host {
    flex: 1;
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.size-btn {
    width: 40px;
    height: 40px;
    background: var(--bg-panel);
    border: 1px solid var(--teal-low);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    transition: border-color 0.12s ease, box-shadow 0.12s ease, transform 0.06s ease;
}

.size-btn:hover,
.size-btn:focus-visible {
    border-color: var(--teal);
    outline: none;
}

.size-btn:active { transform: translateY(1px); }

.size-btn.active {
    border-color: var(--pink-bright);
    box-shadow:
        inset 0 0 8px rgba(255, 46, 136, 0.3),
        0 0 10px rgba(255, 46, 136, 0.5);
}

/* Size dots are sized inline by JS based on the brush size value so
   the visual scale matches the numeric scale. */
.size-dot {
    display: block;
    background: var(--ink);
    border-radius: 50%;
}

/* Palette tabs — 5 group switchers (RAINBOW / PASTELS / NEONS / EARTH
   / METALLIC). Matches DESIGN.md §6.3 .pack-tab pattern. */
.palette-tabs-row {
    padding-bottom: 0;
    margin-bottom: -2px;
}

.palette-tabs-host {
    flex: 1;
    display: flex;
    gap: 4px;
    padding-bottom: 4px;
    border-bottom: 1px dashed var(--teal-low);
    /* WRAP, don't scroll. Five tabs don't fit 390px, and this used to
       scroll with `scrollbar-width: none` — so METALLIC was simply cut
       off mid-word with no scrollbar, no fade, nothing to suggest it
       could be reached. A hidden-scrollbar overflow reads as a broken
       layout, not as an invitation to swipe. Wrapping shows all five. */
    flex-wrap: wrap;
    row-gap: 5px;
}
.palette-tabs-host::-webkit-scrollbar { display: none; }

.palette-tab {
    flex: 1 0 auto;
    padding: 6px 8px;
    font-family: var(--font-mono);
    font-size: 9px;
    letter-spacing: 1.3px;
    background: var(--bg-deep);
    color: var(--teal-dim);
    border: 1px solid var(--teal-low);
    border-radius: var(--radius-sm);
    transition: background 0.12s ease,
                color 0.12s ease,
                border-color 0.12s ease,
                box-shadow 0.12s ease,
                transform 0.06s ease;
    text-shadow: 1px 1px 0 #000;
    white-space: nowrap;
}

.palette-tab:hover,
.palette-tab:focus-visible {
    color: var(--teal);
    border-color: var(--teal);
    background: rgba(0, 255, 204, 0.06);
    outline: none;
}

.palette-tab:active { transform: translateY(1px); }

.palette-tab.active {
    background: linear-gradient(180deg, #ff3d96 0%, #b81866 100%);
    color: #fff;
    border-color: var(--pink-bright);
    box-shadow:
        inset 0 0 8px rgba(255, 255, 255, 0.20),
        0 0 12px rgba(255, 46, 136, 0.55);
}

.palette-row { align-items: flex-start; }
.palette-row .row-label { padding-top: 8px; }

.palette {
    flex: 1;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    padding: 2px 4px 6px;
}

.swatch {
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 2px solid rgba(0, 0, 0, 0.55);
    padding: 0;
    cursor: pointer;
    box-shadow: 0 0 0 1px var(--teal-low);
    transition: transform 0.1s ease, box-shadow 0.12s ease;
}

.swatch:hover,
.swatch:focus-visible {
    box-shadow: 0 0 0 1px var(--teal);
    outline: none;
}

.swatch.active {
    transform: scale(1.18);
    box-shadow:
        0 0 0 1px #fff,
        0 0 0 3px var(--pink-bright),
        0 0 10px rgba(255, 46, 136, 0.6);
}

.draw-controls {
    display: flex;
    gap: 12px;
    width: 100%;
    max-width: 560px;
}

.btn-control {
    flex: 1;
    /* Flex items default to min-width:auto, so `flex: 1` alone will NOT
       shrink a button below its label + padding — the three-button row
       overflowed and the tray grew a horizontal scrollbar with SAVE cut
       off. Same family as the `1fr` = `minmax(auto, 1fr)` trap. */
    min-width: 0;
    padding: 14px 10px;
    font-family: var(--font-title);
    font-size: clamp(13px, 2.4vw, 16px);
    letter-spacing: 2px;
    text-transform: uppercase;
    background: var(--bg-panel);
    color: var(--ink);
    border: 2px solid var(--teal-low);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: transform 0.06s ease,
                background 0.12s ease,
                border-color 0.12s ease,
                box-shadow 0.12s ease;
    box-shadow:
        0 0 0 1px rgba(0, 0, 0, 0.5),
        0 5px 0 #02141a;
    text-shadow: 1.5px 1.5px 0 #000;
}

.btn-control:hover,
.btn-control:focus-visible {
    background: #14404a;
    border-color: var(--teal);
    box-shadow:
        0 0 0 1px rgba(0, 0, 0, 0.5),
        0 5px 0 #02141a,
        0 0 14px rgba(0, 255, 204, 0.3);
    outline: none;
}

.btn-control:active {
    transform: translateY(3px);
    box-shadow:
        0 0 0 1px rgba(0, 0, 0, 0.5),
        0 2px 0 #02141a;
}

.btn-control.primary {
    background: linear-gradient(180deg, #3a1024 0%, #20081a 100%);
    border-color: var(--pink);
    color: #fff;
    text-shadow:
        1.5px 1.5px 0 #000,
        0 0 10px rgba(255, 46, 136, 0.5);
}

.btn-control.primary:hover,
.btn-control.primary:focus-visible {
    background: linear-gradient(180deg, #51163a 0%, #2f0e26 100%);
    box-shadow:
        0 0 0 1px rgba(0, 0, 0, 0.5),
        0 5px 0 #02141a,
        0 0 14px rgba(255, 46, 136, 0.45);
}

.btn-control .btn-glyph {
    color: var(--pink-bright);
    font-size: 1.2em;
    line-height: 1;
}

.btn-control.is-flash {
    background: #205060;
    border-color: var(--teal);
    box-shadow:
        0 0 0 1px rgba(0, 0, 0, 0.5),
        0 5px 0 #02141a,
        0 0 24px var(--teal);
}

/* ----- 10. Gallery ----- */

#screen-gallery {
    padding-top: 12px;
    padding-bottom: 30px;
}

.gallery-grid {
    width: 100%;
    max-width: 720px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
}

.gallery-grid:empty { display: none; }

.pic-card {
    background:
        repeating-linear-gradient(0deg,
            rgba(0,0,0,0.18) 0 1px,
            transparent 1px 2px),
        linear-gradient(180deg, #082028 0%, #051218 100%);
    border: 1px solid var(--teal-low);
    border-radius: var(--radius-md);
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    cursor: pointer;
    transition: border-color 0.12s ease,
                box-shadow 0.12s ease,
                transform 0.06s ease;
    text-align: left;
}

.pic-card:hover,
.pic-card:focus-visible {
    border-color: var(--pink-bright);
    box-shadow: 0 0 14px rgba(255, 46, 136, 0.35);
    outline: none;
    transform: translateY(-2px);
}

.pic-thumb {
    aspect-ratio: 1 / 1;
    background: var(--paper);
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--teal-low);
}

.pic-thumb img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.pic-name {
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 1px;
    color: var(--ink);
    text-shadow: 1px 1px 0 #000;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pic-date {
    font-family: var(--font-lcd);
    font-size: 12px;
    letter-spacing: 1px;
    color: var(--teal-dim);
}

.gallery-empty {
    width: 100%;
    max-width: 420px;
    margin: 30px auto 0;
    padding: 24px 18px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    background:
        repeating-linear-gradient(0deg,
            rgba(0,0,0,0.18) 0 1px,
            transparent 1px 2px),
        linear-gradient(180deg, #082028 0%, #051218 100%);
    border: 1px dashed var(--teal-low);
    border-radius: var(--radius-lg);
    text-align: center;
}

.gallery-empty[hidden] { display: none; }

.empty-glyph {
    font-size: 64px;
    color: var(--teal-low);
    line-height: 1;
}

.empty-title {
    margin: 0;
    font-family: var(--font-title);
    color: var(--pink-bright);
    font-size: 22px;
    letter-spacing: 3px;
    text-shadow: 2px 2px 0 #000;
}

.empty-sub {
    margin: 0;
    font-family: var(--font-lcd);
    font-size: 18px;
    color: var(--ink-dim);
    letter-spacing: 1px;
}

.gallery-empty .big-btn {
    width: 100%;
    max-width: 280px;
    margin-top: 8px;
}

/* ----- 11. Detail modal ----- */

.pic-detail {
    position: fixed;
    inset: 0;
    z-index: 220;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.pic-detail[hidden] { display: none; }

.pic-detail-card {
    width: min(440px, 96vw);
    max-height: 96vh;
    overflow-y: auto;
    background: #051419;
    border: 2px solid var(--teal);
    border-radius: var(--radius-md);
    box-shadow:
        0 0 0 1px #000,
        0 0 30px rgba(0, 255, 204, 0.35);
}

.detail-titlebar {
    display: flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(180deg, var(--teal) 0%, #00b890 100%);
    color: #002b22;
    padding: 6px 10px;
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 1.2px;
}

.detail-pack {
    background: rgba(0, 0, 0, 0.45);
    color: var(--teal);
    padding: 2px 8px;
    border-radius: 3px;
    letter-spacing: 1.6px;
}

.detail-date {
    flex: 1;
    color: #002b22;
    font-family: var(--font-lcd);
    font-size: 13px;
    text-align: right;
    margin-right: 8px;
}

.specs-close {
    width: 22px;
    height: 22px;
    line-height: 22px;
    padding: 0;
    background: #002b22;
    color: var(--teal);
    border-radius: 3px;
    font-size: 12px;
}

.specs-close:hover {
    background: var(--pink-deep);
    color: #fff;
}

.detail-canvas-wrap {
    background: var(--paper);
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#detailImg {
    display: block;
    width: 100%;
    max-width: 400px;
    aspect-ratio: 1 / 1;
    background: var(--paper);
    border-radius: var(--radius-sm);
    object-fit: contain;
}

.detail-actions {
    display: flex;
    gap: 10px;
    padding: 12px 14px 14px;
}

.detail-actions .btn-control {
    flex: 1;
    padding: 12px 10px;
}

/* ----- 12. Side-rail layout (tablet+) -----
   Mirrors Pootery's pattern: phone gets a bottom-sheet drawer;
   tablet+ flips to canvas-left + side-rail-right. */

@media (max-width: 767.98px) {
    .draw-side-rail {
        position: fixed;
        left: 0; right: 0; bottom: 0;
        z-index: 80;
        max-width: none;
        max-height: 72vh;
        overflow-y: auto;
        gap: 12px;
        padding: 0 14px 18px;
        background: linear-gradient(180deg,
            #082028 0%, #051218 26%, #04101a 100%);
        border-top: 2px solid var(--pink);
        border-top-left-radius: 18px;
        border-top-right-radius: 18px;
        box-shadow:
            0 -8px 24px rgba(0, 0, 0, 0.65),
            0 -1px 0 0 rgba(255, 46, 136, 0.35);
        transform: translateY(calc(100% - 54px));
        transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
    }

    .draw-side-rail.is-open {
        transform: translateY(0);
    }

    .drawer-handle {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        width: 100%;
        height: 54px;
        flex-shrink: 0;
        background: none;
        border: none;
        padding: 0;
        cursor: pointer;
        font-family: var(--font-mono);
        font-size: 12px;
        letter-spacing: 2px;
        color: var(--pink-bright);
        text-shadow:
            1px 1px 0 #000,
            0 0 8px rgba(255, 46, 136, 0.45);
        position: sticky;
        top: 0;
        z-index: 1;
    }

    .drawer-handle::before {
        content: "";
        position: absolute;
        top: 6px;
        left: 50%;
        transform: translateX(-50%);
        width: 44px;
        height: 4px;
        border-radius: 2px;
        background: var(--teal-low);
    }

    .drawer-pull {
        font-size: 14px;
        transition: transform 0.25s ease;
        line-height: 1;
    }

    .is-open .drawer-pull {
        transform: rotate(180deg);
    }

    #screen-draw {
        padding-bottom: 72px;
    }
}

@media (min-width: 768px) {
    /* Draw stack is no longer a flex layout — canvas + line-art +
       rail are all fixed-positioned overlays. Rail becomes a
       floating panel anchored to the right edge of the viewport. */
    .draw-side-rail {
        position: fixed;
        top: 112px;                /* below the titlebar */
        right: 12px;
        bottom: 40px;              /* clear of slim footer */
        width: 320px;
        max-width: 320px;
        align-items: stretch;
        flex-shrink: 0;
        overflow-y: auto;
        z-index: 50;
        padding: 14px;
        background: rgba(8, 32, 40, 0.88);
        border: 1px solid var(--teal-low);
        border-radius: var(--radius-lg);
        backdrop-filter: blur(8px);
        -webkit-backdrop-filter: blur(8px);
        box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
        scrollbar-width: thin;
        scrollbar-color: var(--teal-low) transparent;
    }
    .draw-side-rail::-webkit-scrollbar       { width: 6px; }
    .draw-side-rail::-webkit-scrollbar-track { background: transparent; }
    .draw-side-rail::-webkit-scrollbar-thumb {
        background: var(--teal-low);
        border-radius: 3px;
    }

    .draw-side-rail .draw-tools,
    .draw-side-rail .draw-controls {
        max-width: none;
    }
}

/* ----- 13. Responsive nudges ----- */

/* ----- 14. Settings screen ----- */

.settings-hook {
    position: fixed;
    bottom: 28px;
    right: 16px;
    z-index: 60;
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
    background: rgba(12, 31, 37, 0.85);
    border: 1px solid var(--teal-low);
    color: var(--teal);
    font-family: var(--font-mono);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    transition: background 0.12s ease,
                border-color 0.12s ease,
                color 0.12s ease,
                box-shadow 0.12s ease,
                transform 0.06s ease;
}

.settings-hook:hover,
.settings-hook:focus-visible {
    background: rgba(20, 64, 74, 0.9);
    border-color: var(--teal);
    color: var(--pink-bright);
    outline: none;
    box-shadow: 0 0 14px rgba(255, 46, 136, 0.35);
    transform: scale(1.06);
}

#screen-settings {
    padding-top: 12px;
    padding-bottom: 60px;
}

.settings-stack {
    width: 100%;
    max-width: 560px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.settings-card {
    padding: 18px 20px;
    background:
        repeating-linear-gradient(0deg,
            rgba(0,0,0,0.18) 0 1px,
            transparent 1px 2px),
        linear-gradient(180deg, #082028 0%, #051218 100%);
    border: 1px solid var(--teal-low);
    border-radius: var(--radius-md);
    box-shadow: inset 0 0 16px rgba(0, 0, 0, 0.45);
}

.settings-section {
    margin: 0 0 12px;
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 1.8px;
    color: var(--pink-bright);
    text-shadow: 1px 1px 0 #000, 0 0 6px rgba(255, 46, 136, 0.35);
}

.settings-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 0;
    border-top: 1px dashed var(--teal-low);
    cursor: pointer;
}
.settings-row:first-of-type { border-top: none; padding-top: 4px; }

.settings-row-disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.settings-label {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-family: var(--font-ui);
    font-size: 16px;
    color: var(--ink);
    line-height: 1.2;
}

.settings-sub {
    font-family: var(--font-lcd);
    font-size: 15px;
    color: var(--ink-dim);
    letter-spacing: 0.6px;
}

.settings-toggle {
    width: 22px;
    height: 22px;
    accent-color: var(--pink);
    flex: 0 0 auto;
    cursor: inherit;
}

.settings-select {
    flex: 0 0 auto;
    padding: 8px 10px;
    background: var(--bg-deep);
    color: var(--ink);
    border: 1px solid var(--teal-low);
    border-radius: var(--radius-sm);
    font-family: var(--font-ui);
    font-size: 15px;
    cursor: pointer;
    min-width: 140px;
}

.settings-select:focus {
    outline: none;
    border-color: var(--pink);
    box-shadow: 0 0 8px rgba(255, 46, 136, 0.3);
}

.settings-blurb {
    margin: 6px 0 0;
    font-family: var(--font-ui);
    font-size: 14px;
    line-height: 1.45;
    color: var(--ink-dim);
}

.settings-version {
    color: var(--teal-dim);
    font-family: var(--font-lcd);
    font-size: 16px;
    letter-spacing: 1.2px;
    margin-top: 10px;
}

/* ----- 15. Parent gate modal ----- */

.parent-gate {
    position: fixed;
    inset: 0;
    z-index: 280;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(0, 0, 0, 0.72);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

.parent-gate[hidden] { display: none; }

.parent-gate-card {
    width: min(480px, 96vw);
    background: #051419;
    border: 2px solid var(--pink);
    border-radius: var(--radius-md);
    box-shadow:
        0 0 0 1px #000,
        0 0 36px rgba(255, 46, 136, 0.45);
    overflow: hidden;
}

.parent-gate-card .detail-titlebar {
    background: linear-gradient(180deg, var(--pink) 0%, var(--pink-deep) 100%);
    color: #fff;
    text-shadow: 1px 1px 0 #000;
}

.parent-gate-card .detail-pack {
    background: rgba(0, 0, 0, 0.45);
    color: var(--pink-bright);
    padding: 2px 8px;
    border-radius: 3px;
}

.parent-gate-card .detail-date {
    color: #fff;
}

.parent-gate-card .specs-close {
    background: rgba(0, 0, 0, 0.45);
    color: var(--pink-bright);
}

.parent-gate-body {
    padding: 22px 24px 24px;
}

.parent-gate-title {
    margin: 0 0 8px;
    font-family: var(--font-title);
    color: var(--pink-bright);
    font-size: clamp(20px, 4vw, 26px);
    letter-spacing: 1.5px;
    text-shadow: 2px 2px 0 #000;
}

.parent-gate-blurb {
    margin: 0 0 18px;
    font-family: var(--font-ui);
    font-size: 15px;
    color: var(--ink-dim);
    line-height: 1.4;
}

.parent-gate-problem {
    margin: 0 0 16px;
    text-align: center;
    font-family: var(--font-title);
    color: var(--ink);
    font-size: clamp(28px, 6vw, 40px);
    letter-spacing: 2px;
    text-shadow: 2px 2px 0 #000, 0 0 16px rgba(0, 255, 204, 0.35);
}

.parent-gate-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.parent-gate-option {
    padding: 16px;
    font-family: var(--font-title);
    font-size: 22px;
    letter-spacing: 2px;
    color: var(--ink);
    background: var(--bg-panel);
    border: 2px solid var(--teal-low);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s, transform 0.06s;
    text-shadow: 1.5px 1.5px 0 #000;
}

.parent-gate-option:hover,
.parent-gate-option:focus-visible {
    background: #14404a;
    border-color: var(--teal);
    outline: none;
}

.parent-gate-option:active {
    transform: translateY(1px);
}

.parent-gate-option.is-wrong {
    border-color: #ff8060;
    color: #ff8060;
    animation: shake 0.18s steps(2) 3;
}

@keyframes shake {
    0%   { transform: translateX(0); }
    25%  { transform: translateX(-4px); }
    50%  { transform: translateX(4px); }
    75%  { transform: translateX(-2px); }
    100% { transform: translateX(0); }
}

.parent-gate-foot {
    margin: 14px 0 0;
    text-align: center;
    font-family: var(--font-lcd);
    font-size: 16px;
    color: var(--teal-dim);
    min-height: 20px;
}

.parent-gate-foot.is-error {
    color: #ff8060;
}

/* ----- 16. First-save + Saved toast ----- */

.first-save-toast,
.saved-toast {
    position: fixed;
    bottom: 36px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    z-index: 270;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    color: #fff;
    font-family: var(--font-ui);
    font-size: 15px;
    border-radius: 22px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.22s ease, transform 0.22s ease;
}

.first-save-toast {
    background: linear-gradient(90deg,
        rgba(255, 210, 70, 0.95),
        rgba(255, 46, 136, 0.95));
    box-shadow:
        0 0 0 2px #000,
        0 0 24px rgba(255, 210, 70, 0.55),
        0 0 30px rgba(255, 46, 136, 0.45);
    text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.45);
    font-weight: 600;
}

.saved-toast {
    background: rgba(12, 31, 37, 0.95);
    border: 1.5px solid var(--teal);
    color: var(--teal);
    box-shadow:
        0 0 0 1px #000,
        0 0 18px rgba(0, 255, 204, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.first-save-toast.is-show,
.saved-toast.is-show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.first-save-toast[hidden],
.saved-toast[hidden] { display: none; }

.fst-glyph {
    font-size: 20px;
    color: #fff;
    text-shadow: 0 0 8px rgba(255, 255, 255, 0.8);
}

.st-glyph {
    font-size: 16px;
    color: var(--teal);
}

@media (max-width: 480px) {
    .title-stack { gap: 22px; }
    .screen-titlebar { font-size: 9px; gap: 6px; padding: 4px 0 10px; }
    .back-btn { font-size: 9px; padding: 4px 7px; }
    .screen-status { font-size: 13px; }
    .canvas-wrap { padding: 5px; border-width: 2px; }
    .draw-tools { padding: 10px 8px; gap: 8px; }
    .row-label { font-size: 9px; min-width: 44px; }
    .tool-btn { font-size: 9px; padding: 9px 3px; letter-spacing: 1px; }
    .tool-modes { gap: 4px; }
    .size-btn { width: 36px; height: 36px; }
    .size-host { gap: 6px; }
    .palette-tab { font-size: 8px; padding: 5px 6px; letter-spacing: 1px; }
    .swatch { width: 30px; height: 30px; }
}

@media (prefers-reduced-motion: reduce) {
    .big-title {
        animation: none;
    }
}

/* ============================================================
   16. COACH — first-run onboarding
   ============================================================
   Shown once on the draw screen, then never again unless replayed
   from Settings. A touch dot travels the squiggle while the squiggle
   strokes itself in: a wordless "drag here" that works before the
   caption can be read.

   pointer-events stays none on every part of this — the coach is
   asking for a stroke, so it must not be able to eat one.
   ============================================================ */

.coach {
    position: fixed;
    inset: 0;
    z-index: 88;              /* under the rail (80 is the sheet, but
                                 the sheet is closed while coaching)
                                 and under the parent gate (9000) */
    display: grid;
    place-items: center;
    pointer-events: none;
    animation: coachIn 0.45s ease-out both;
}

.coach[hidden] { display: none; }

.coach.is-leaving {
    animation: coachOut 0.3s ease-in both;
}

.coach-stage {
    width: min(400px, 88vw);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    /* Lift the whole group above centre so it clears the closed
       bottom sheet and the onion in the lower-left. */
    transform: translateY(-8vh);
}

.coach-cap {
    margin: 0;
    font-family: var(--font-mono);
    font-size: 15px;
    letter-spacing: 2px;
    color: var(--paper);
    text-align: center;
    text-shadow:
        2px 2px 0 var(--line-ink),
        0 0 14px rgba(0, 0, 0, 0.85);
}

.coach-art {
    width: 100%;
    height: auto;
    overflow: visible;
}

.coach-path {
    fill: none;
    stroke: var(--paper);
    stroke-width: 6;
    stroke-linecap: round;
    stroke-dasharray: 620;
    stroke-dashoffset: 620;
    filter: drop-shadow(0 0 6px rgba(0, 0, 0, 0.7));
    animation: coachTrace 2.6s linear infinite;
}

.coach-ring {
    fill: rgba(255, 255, 255, 0.22);
    stroke: var(--paper);
    stroke-width: 2.5;
}

.coach-nub {
    fill: var(--pink);
    stroke: var(--paper);
    stroke-width: 2.5;
}

@keyframes coachTrace {
    0%   { stroke-dashoffset: 620; }
    88%  { stroke-dashoffset: 0; }
    100% { stroke-dashoffset: 0; }
}

@keyframes coachIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes coachOut {
    from { opacity: 1; }
    to   { opacity: 0; }
}

/* Breathe the two buttons the coach can't point at directly.
   A caption alone doesn't move a thumb toward controls nobody has
   noticed — Slip Studio learned this the hard way. Three breaths,
   then it stops on its own; retired for good on first tap. */
.pages-btn.is-new,
.drawer-handle.is-new {
    animation: coachBreathe 1.5s ease-in-out 3;
}

@keyframes coachBreathe {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.09); }
}

/* Reduced motion: keep the coach (it teaches something real) but
   hold it still — full squiggle drawn, dot parked at the start. The
   travelling dot is stopped in JS by removing <animateMotion>, since
   SMIL ignores this media query entirely. */
@media (prefers-reduced-motion: reduce) {
    .coach,
    .coach.is-leaving {
        animation: none;
    }
    .coach-path {
        stroke-dashoffset: 0;
        animation: none;
    }
    .pages-btn.is-new,
    .drawer-handle.is-new {
        animation: none;
    }
}

/* ----- 17. Custom colour swatch -----
   Lives beside #colorPalette rather than inside it, because
   buildPalette() rewrites that container on every group switch.
   The native <input type="color"> is stretched over the whole
   swatch and made invisible, so the kid taps a normal-looking
   round swatch and gets the platform picker. */

.swatch-custom {
    position: relative;
    overflow: hidden;
    display: inline-block;
    /* Rainbow until the kid picks something; JS then paints the
       chosen colour onto the background. */
    background:
        conic-gradient(#ff2e88, #ff7a1f, #ffd23f, #9be15d,
                       #00ffcc, #4fc3f7, #a86bff, #ff2e88);
}

.swatch-custom::after {
    /* Little nib so it reads as "choose", not "a colour". */
    content: "+";
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    font-family: var(--font-mono);
    font-size: 13px;
    color: #fff;
    text-shadow: 0 0 3px #000, 1px 1px 0 #000;
    pointer-events: none;
}

.swatch-custom input[type="color"] {
    position: absolute;
    inset: -4px;
    width: calc(100% + 8px);
    height: calc(100% + 8px);
    padding: 0;
    border: none;
    background: none;
    opacity: 0;
    cursor: pointer;
}
