/* ══════════════════════════════════════════════════════════
   editor.css — Pixel Studio chrome. Reuses the house warm-ink
   pixel tokens so theme.js's [data-theme] switch drives it too.
   The SPRITE pixels the user paints are their own data (arbitrary
   colours); these tokens are only the app chrome.
   ══════════════════════════════════════════════════════════ */
:root{
  --bg:#0b0a0d; --bg-2:#16131a;
  --panel:rgba(29,25,34,.82); --panel-solid:#1d1922;
  --line:rgba(184,175,164,.20); --line-hot:rgba(245,158,11,.45);
  --ink:#f5f1ea; --ink-dim:#b8afa4; --ink-faint:#6b635a;
  --brand:#f59e0b; --brand-2:#a78bfa;
  --p1:#48c8dd; --p2:#e05b7a; --p3:#9ec95a; --p4:#e39a48;
  --ok:#4ee8a5; --warn:#fbbf24;
  --surf:rgba(43,37,51,.72);
  --shadow:4px 4px 0 rgba(0,0,0,.45);
  /* Logo palette. Wordmark strokes are currentColor; only the bulb reads
     these, so one asset serves both grounds. */
  --logo-glow:1; --logo-glow-color:#f59e0b; --logo-bulb:#d9a441;
  --logo-glass-hi:#fffdf6; --logo-glass-lo:#f8e3b6; --logo-face:#8a6a3b;
  --font:"Inter Variable","Inter",ui-sans-serif,system-ui,-apple-system,"Segoe UI",sans-serif;
  --display:"Silkscreen","VT323",ui-monospace,monospace;
  /* checkerboard for transparency, tuned per theme */
  --checker-a:#2b2533; --checker-b:#1d1922;
}
:root[data-theme="light"]{
  --bg:#ece5d8; --bg-2:#ded5c4;
  --panel:rgba(246,241,232,.90); --panel-solid:#f6f1e8;
  --line:rgba(90,74,54,.24); --line-hot:rgba(180,83,9,.45);
  --ink:#2b2536; --ink-dim:#5b5266; --ink-faint:#7b7188;
  /* Paper turns the bloom to haze — drop the glow, deepen the bulb. */
  --logo-glow:0; --logo-bulb:#a86f18;
  --logo-glass-hi:#fffaec; --logo-glass-lo:#f2d79c; --logo-face:#6b4d22;
  --brand:#b45309; --brand-2:#7c3aed;
  --p1:#0f6f7a; --p2:#b03050; --p3:#4a6b1e; --p4:#8c5210;
  --ok:#047857; --warn:#8c6510;
  --surf:rgba(222,213,196,.75);
  --shadow:4px 4px 0 rgba(90,74,54,.30);
  --checker-a:#cfc6b3; --checker-b:#ded5c4;
}

*{box-sizing:border-box}
/* native range/checkbox chrome follows the brand instead of browser blue */
input[type=range],input[type=checkbox]{accent-color:var(--brand)}
[hidden]{display:none !important}
html,body{height:100%}
body{
  margin:0;background:var(--bg);color:var(--ink);
  font-family:var(--font);-webkit-font-smoothing:antialiased;
  -webkit-tap-highlight-color:transparent;
  display:flex;flex-direction:column;min-height:100dvh;
}
button{font-family:inherit;color:inherit;cursor:pointer}
h3{font-family:var(--display);font-size:.82rem;letter-spacing:.04em;
   text-transform:uppercase;color:var(--ink-dim);margin:0 0 .6rem}

/* ── wordmark (borrowed idiom) ── */
/* inline-flex, not inline: the lockup is taller than its line box (the bulb
   needs headroom above the caps), so a line box would let it escape and the
   sticky bar would clip the bulb. As a flex item it makes the bar grow. */
/* Mark over title, matching portal, the arcade and search. Still inline-flex
   (see above) — only the direction changes, so the clipping fix survives. */
.wordmark{font-weight:700;letter-spacing:-.03em;line-height:1;
  display:inline-flex;flex-direction:column;align-items:center;gap:.3rem}
.wordmark.small{font-size:1.2rem}
/* One SVG: bulb + HAPPY LiGHT, the bulb being the tittle of the "i". The
   viewBox reserves headroom above the caps, so the element runs ~2.8x the cap
   height it draws — hence 2em. */
.wordmark .hl-lockup{height:2em;width:auto;display:inline-block;
  color:var(--ink);flex:none}
.wm-b{background:none;-webkit-background-clip:border-box;background-clip:border-box;
  color:var(--ink-dim);font-size:max(.62rem,.16em);font-weight:700;letter-spacing:.26em;
  text-indent:.26em;text-transform:uppercase;line-height:1}
.wm-dot{color:var(--p2)}

/* ── top bar ── */
.ed-bar{display:flex;align-items:center;gap:.9rem;flex-wrap:wrap;
  padding:.6rem .9rem;background:var(--panel);
  border-bottom:1px solid var(--line);position:sticky;top:0;z-index:20}
.ed-home{text-decoration:none}
.ed-title{font-family:var(--display);font-size:.8rem;letter-spacing:.08em;
  text-transform:uppercase;color:var(--ink-faint)}
.ed-bar-actions{margin-left:auto;display:flex;align-items:center;gap:.5rem;flex-wrap:wrap}

/* ── bar menu ──
   `<details>`/`<summary>` rather than a custom widget: it is keyboard-operable
   with no script (Enter/Space toggles, Escape is wired in editor.js), which is
   the same pattern portal and the arcade use. ── */
.hl-menu{position:relative}
.hl-menu-summary{display:flex;align-items:center;gap:.45rem;cursor:pointer;list-style:none;
  padding:.3rem .6rem;border:1px solid var(--line);background:var(--surf);
  color:var(--ink-dim);font-family:var(--display);font-size:.78rem;user-select:none}
.hl-menu-summary::-webkit-details-marker{display:none}
.hl-menu-summary:hover{border-color:var(--line-hot);color:var(--ink)}
.hl-menu-summary:focus-visible{outline:2px solid var(--brand);outline-offset:2px}
.hl-menu-bars{width:.85rem;height:.7rem;flex:none;
  border-top:2px solid currentColor;border-bottom:2px solid currentColor;position:relative}
.hl-menu-bars::after{content:"";position:absolute;left:0;right:0;top:calc(50% - 1px);
  border-top:2px solid currentColor}
.hl-menu-panel{position:absolute;right:0;top:calc(100% + .35rem);z-index:60;
  min-width:14rem;display:flex;flex-direction:column;padding:.3rem;
  border:1px solid var(--line);background:var(--panel-solid);box-shadow:var(--shadow)}
.hl-menu-head{margin:.45rem .55rem .2rem;font-family:var(--display);font-size:.62rem;
  letter-spacing:.08em;text-transform:uppercase;color:var(--ink-faint)}
.hl-menu-head:first-child{margin-top:.2rem}
.hl-menu-item{appearance:none;background:none;border:0;cursor:pointer;font:inherit;
  font-size:.85rem;color:var(--ink);text-align:left;text-decoration:none;padding:.45rem .55rem}
.hl-menu-item:hover{background:var(--line)}
.hl-menu-item:focus-visible{outline:2px solid var(--brand);outline-offset:-2px}
.hl-menu-seg{margin:.15rem .55rem .3rem;align-self:flex-start}

.ed-btn{background:var(--surf);border:1px solid var(--line);color:var(--ink);
  padding:.42rem .7rem;font-size:.82rem;font-weight:600;border-radius:0;
  transition:border-color .15s,transform .06s}
.ed-btn:hover{border-color:var(--line-hot)}
.ed-btn:active{transform:translateY(1px)}
.ed-btn.wide{width:100%}
.ed-btn.primary{background:linear-gradient(96deg,var(--brand),var(--brand-2));
  color:#14121f;border-color:transparent;font-weight:700}
.ed-btn:disabled{opacity:.4;cursor:not-allowed}

.ed-seg{display:inline-flex;border:1px solid var(--line);border-radius:0;overflow:hidden}
.ed-seg button{background:var(--surf);border:0;padding:.42rem .6rem;font-size:.76rem;font-weight:600}
.ed-seg button + button{border-left:1px solid var(--line)}
.ed-seg button.on{background:linear-gradient(96deg,var(--brand),var(--brand-2));color:#14121f}

/* ── layout ── */
.ed-main{flex:1;display:grid;gap:.9rem;padding:.9rem;
  grid-template-columns:minmax(0,var(--col-l,230px)) minmax(0,1fr) minmax(0,var(--col-r,260px));
  align-items:start}
body.rail-left-out{--col-l:34px}
body.rail-right-out{--col-r:34px}
.ed-panel{background:var(--panel);border:1px solid var(--line);padding:.85rem;margin-bottom:.9rem}
.ed-tools,.ed-preview{display:flex;flex-direction:column;min-width:0}

/* ── tools ── */
.tool-grid{display:grid;grid-template-columns:1fr 1fr;gap:.5rem;margin-bottom:.6rem}
.tool{position:relative;display:flex;flex-direction:column;align-items:center;gap:.15rem;
  background:var(--surf);border:1px solid var(--line);padding:.55rem .3rem;border-radius:0}
.tool .tico{font-size:1.15rem;line-height:1}
.tool b{font-size:.72rem;font-weight:600}
.tool.on{border-color:var(--brand);background:color-mix(in srgb,var(--brand) 18%,var(--surf))}
.tool .thk{position:absolute;top:2px;right:2px;font-family:var(--display);font-size:.56rem;
  line-height:1;padding:.12rem .2rem;color:var(--ink-faint);background:var(--panel-solid);
  border:1px solid var(--line)}
.tool.on .thk{color:var(--brand);border-color:var(--line-hot)}
/* the marquee-select tile spans the 2-col grid so it reads as its own row */
.tool[data-tool="select"]{grid-column:1 / -1;flex-direction:row;gap:.4rem;justify-content:center;padding:.5rem}
.tool[data-tool="select"] .tico{font-size:1rem}
.paint.sel{cursor:crosshair}

/* ── brush size ── */
.brush-row{display:flex;align-items:center;gap:.5rem;margin-bottom:.6rem;font-size:.8rem;color:var(--ink-dim)}
.brush-row label{white-space:nowrap}
.brush-row input[type=range]{flex:1;min-width:60px}
.brush-swatch{width:22px;height:22px;flex:0 0 auto;border:1px solid var(--line);
  background:var(--surf);position:relative}
.brush-swatch::after{content:"";position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);
  width:var(--bp,4px);height:var(--bp,4px);background:var(--brand);image-rendering:pixelated}

/* ── keyboard shortcuts legend ── */
.ed-btn.ghost{background:none;color:var(--ink-faint);font-size:.76rem}
.ed-btn.ghost:hover{color:var(--ink-dim)}
.shortcuts-wrap{margin-top:.4rem}
.shortcuts{margin:.5rem 0 0;display:grid;gap:.28rem}
.shortcuts div{display:flex;justify-content:space-between;align-items:center;gap:.6rem}
.shortcuts dt{font-size:.74rem;color:var(--ink-dim)}
.shortcuts dd{margin:0;display:flex;gap:.2rem;align-items:center;color:var(--ink-faint);font-size:.72rem}
.shortcuts kbd,.tool .thk{border-radius:0}
.shortcuts kbd{font-family:var(--display);font-size:.62rem;line-height:1;padding:.15rem .3rem;
  color:var(--ink-dim);background:var(--surf);border:1px solid var(--line)}

/* ── canvas row + large all-frames filmstrip ──
   The strip renders every frame of the current direction at the editor's
   own scale (matching the paint canvas height), scrolling horizontally.
   Below the canvas on narrow screens; beside it on wide ones. ── */
.canvas-row{display:flex;flex-direction:column;align-items:center;gap:.7rem;min-width:0;width:100%}
.film-band{width:100%;min-width:0;border-top:1px solid var(--line);padding-top:.6rem}
.film-strip{display:flex;gap:.5rem;overflow-x:auto;overflow-y:hidden;padding-bottom:.4rem;
  scroll-behavior:smooth}
.film-cell{position:relative;flex:0 0 auto;height:clamp(150px,40vh,340px);padding:0;border-radius:0;
  border:1px solid var(--line);background-color:var(--checker-b);
  background-image:
    linear-gradient(45deg,var(--checker-a) 25%,transparent 25%),
    linear-gradient(-45deg,var(--checker-a) 25%,transparent 25%),
    linear-gradient(45deg,transparent 75%,var(--checker-a) 75%),
    linear-gradient(-45deg,transparent 75%,var(--checker-a) 75%);
  background-size:16px 16px;background-position:0 0,0 8px,8px -8px,-8px 0}
/* only the preview thumbnails (direct-child canvases) are height-fit; the live
   editor canvas nests inside .canvas-wrap and keeps its own natural size + zoom */
.film-cell > canvas{height:100%;width:auto;display:block;image-rendering:pixelated;image-rendering:crisp-edges}
.film-cell.on{outline:3px solid var(--brand);outline-offset:1px;z-index:1}
.film-cell .fnum{position:absolute;bottom:0;right:0;background:var(--panel-solid);
  color:var(--ink-dim);font-size:.64rem;padding:.05rem .3rem;font-family:var(--display)}
.tool-row{display:flex;gap:.5rem;margin-bottom:.6rem}
.tool-row .ed-btn{flex:1}
.ed-check{display:flex;align-items:center;gap:.45rem;font-size:.82rem;color:var(--ink-dim);margin-top:.35rem}

/* ── colour ── */
.swatch-current{display:flex;gap:.6rem;align-items:center;margin-bottom:.6rem}
.swatch-big{width:46px;height:46px;border:1px solid var(--line);
  background-image:
    linear-gradient(45deg,var(--checker-a) 25%,transparent 25%),
    linear-gradient(-45deg,var(--checker-a) 25%,transparent 25%),
    linear-gradient(45deg,transparent 75%,var(--checker-a) 75%),
    linear-gradient(-45deg,transparent 75%,var(--checker-a) 75%);
  background-size:12px 12px;background-position:0 0,0 6px,6px -6px,-6px 0;
  background-color:var(--checker-b);position:relative}
.swatch-big::after{content:"";position:absolute;inset:0;background:var(--cur,#000)}
.swatch-meta{flex:1;min-width:0}
.swatch-hex{font-family:var(--display);font-size:.78rem;color:var(--ink-dim)}
.alpha-row{display:flex;align-items:center;gap:.4rem;font-size:.72rem;color:var(--ink-faint);margin-top:.3rem}
.alpha-row input{flex:1}

.palette{display:grid;grid-template-columns:repeat(8,1fr);gap:3px;margin-bottom:.6rem}
.pal-swatch{aspect-ratio:1/1;border:1px solid var(--line);border-radius:0;padding:0;position:relative;
  background-image:
    linear-gradient(45deg,var(--checker-a) 25%,transparent 25%),
    linear-gradient(-45deg,var(--checker-a) 25%,transparent 25%),
    linear-gradient(45deg,transparent 75%,var(--checker-a) 75%),
    linear-gradient(-45deg,transparent 75%,var(--checker-a) 75%);
  background-size:8px 8px;background-position:0 0,0 4px,4px -4px,-4px 0;
  background-color:var(--checker-b)}
.pal-swatch::after{content:"";position:absolute;inset:0;background:var(--c)}
.pal-swatch.on{outline:2px solid var(--brand);outline-offset:1px;z-index:1}
.pal-swatch.transparent::before{content:"∅";position:absolute;inset:0;display:grid;
  place-items:center;color:var(--ink-faint);font-size:.9rem;z-index:1}
.palette-actions{display:flex;gap:.4rem;align-items:center}
.palette-actions input[type=color]{width:34px;height:30px;padding:0;border:1px solid var(--line);background:none}
.palette-actions .ed-btn{flex:1}

/* ── stage ── */
.ed-stage{background:var(--panel);border:1px solid var(--line);padding:.9rem;
  display:flex;flex-direction:column;gap:.8rem;min-height:0}
.stage-top{display:flex;flex-direction:column;gap:.8rem;align-items:center}
.dir-compass{display:grid;grid-template-columns:repeat(3,34px);grid-template-rows:repeat(3,34px);gap:4px}
.dir{background:var(--surf);border:1px solid var(--line);font-size:1rem;padding:0;border-radius:0;
  display:grid;place-items:center}
.dir:hover{border-color:var(--line-hot)}
.dir.on{border-color:var(--brand);background:color-mix(in srgb,var(--brand) 22%,var(--surf));color:var(--ink)}
.dir-mid{display:grid;place-items:center;color:var(--ink-faint);font-size:.7rem;
  border:1px dashed var(--line)}

.canvas-wrap{overflow:auto;max-width:100%;max-height:62vh;display:grid;place-items:center;
  border:1px solid var(--line);
  background-image:
    linear-gradient(45deg,var(--checker-a) 25%,transparent 25%),
    linear-gradient(-45deg,var(--checker-a) 25%,transparent 25%),
    linear-gradient(45deg,transparent 75%,var(--checker-a) 75%),
    linear-gradient(-45deg,transparent 75%,var(--checker-a) 75%);
  background-size:20px 20px;background-position:0 0,0 10px,10px -10px,-10px 0;
  background-color:var(--checker-b)}
.paint{image-rendering:pixelated;image-rendering:crisp-edges;touch-action:none;display:block}

.zoom-row{display:flex;align-items:center;gap:.5rem;justify-content:center;margin-top:.2rem}
.zoom-label{font-family:var(--display);font-size:.76rem;color:var(--ink-dim);min-width:3.4em;text-align:center}
.dir-name{margin-left:.8rem;font-family:var(--display);font-size:.78rem;color:var(--brand)}

/* ── frames ── */
.frames-bar{display:flex;gap:.7rem;align-items:center;flex-wrap:wrap;
  border-top:1px solid var(--line);padding-top:.7rem}
.frames-strip{display:flex;gap:.4rem;overflow-x:auto;flex:1;min-width:0;padding-bottom:.2rem}
.frame-thumb{position:relative;flex:0 0 auto;width:54px;height:54px;border:1px solid var(--line);
  background-color:var(--checker-b);padding:0;border-radius:0}
.frame-thumb canvas{width:100%;height:100%;image-rendering:pixelated;display:block}
.frame-thumb.on{outline:2px solid var(--brand);outline-offset:1px}
.frame-thumb .fnum{position:absolute;bottom:0;right:0;background:var(--panel-solid);
  color:var(--ink-dim);font-size:.6rem;padding:0 .2rem;font-family:var(--display)}
.frames-actions{display:flex;gap:.35rem;flex-wrap:wrap}
.frames-actions .ed-btn{font-size:.76rem;padding:.38rem .5rem}
/* flip + move/copy-to-direction row */
.frame-ops{display:flex;gap:.5rem .8rem;align-items:center;flex-wrap:wrap;
  width:100%;border-top:1px dashed var(--line);padding-top:.55rem;margin-top:.1rem}
.frame-ops .fop-group{display:flex;gap:.35rem;align-items:center;flex-wrap:wrap}
.frame-ops .ed-btn{font-size:.76rem;padding:.38rem .55rem}
.frame-ops .ed-check.inline{margin-top:0}
.fop-lbl{font-size:.76rem;color:var(--ink-dim);font-family:var(--display)}
.ed-select{background:var(--surf);border:1px solid var(--line);color:var(--ink);
  border-radius:0;font-family:inherit;font-size:.78rem;padding:.34rem .4rem;cursor:pointer}
.ed-select:hover{border-color:var(--line-hot)}
.ed-select:focus{outline:2px solid var(--brand);outline-offset:1px}

/* ── preview ── */
.preview-hero{display:grid;place-items:center;border:1px solid var(--line);padding:.6rem;
  background-color:var(--checker-b);
  background-image:
    linear-gradient(45deg,var(--checker-a) 25%,transparent 25%),
    linear-gradient(-45deg,var(--checker-a) 25%,transparent 25%),
    linear-gradient(45deg,transparent 75%,var(--checker-a) 75%),
    linear-gradient(-45deg,transparent 75%,var(--checker-a) 75%);
  background-size:16px 16px;background-position:0 0,0 8px,8px -8px,-8px 0}
.preview-canvas{image-rendering:pixelated;display:block;width:160px;height:160px}
.speed-row{display:flex;align-items:center;gap:.5rem;flex-wrap:wrap;margin-top:.6rem}
.speed-row label{font-size:.8rem;color:var(--ink-dim)}
.speed-row input[type=range]{flex:1;min-width:80px}

/* The pose vocabulary is nine deep and each entry can carry a derived
   mirror row, so this list outgrows the viewport. It scrolls inside
   itself rather than pushing the rest of the editor off-screen;
   `overscroll-behavior` stops a flick here from scrolling the page. */
.dir-overview{display:grid;grid-template-columns:repeat(3,1fr);gap:4px;
  max-height:46vh;overflow-y:auto;overscroll-behavior:contain;scrollbar-gutter:stable}
.ov-cell{aspect-ratio:1/1;border:1px solid var(--line);background-color:var(--checker-b);position:relative}
.ov-cell.mid{border:1px dashed var(--line)}
.ov-cell canvas{width:100%;height:100%;image-rendering:pixelated;display:block}
.ov-cell .ovl{position:absolute;top:0;left:0;font-size:.55rem;color:var(--ink-faint);
  font-family:var(--display);padding:0 .15rem;background:var(--panel-solid)}

/* ── size ── */
.size-presets{display:grid;grid-template-columns:repeat(4,1fr);gap:.4rem;margin-bottom:.5rem}
.size-presets .ed-btn.on{border-color:var(--brand);color:var(--brand)}
.size-custom{display:flex;align-items:center;gap:.4rem;font-size:.85rem;color:var(--ink-dim)}
.size-custom input{width:52px;background:var(--surf);border:1px solid var(--line);color:var(--ink);
  padding:.3rem;font-family:var(--font)}
.size-note{font-size:.72rem;color:var(--ink-faint);margin:.5rem 0 0;line-height:1.4}

/* ── modal ── */
.modal{position:fixed;inset:0;z-index:40;display:grid;place-items:center;
  background:rgba(10,9,16,.6)}
.modal-card{background:var(--panel-solid);border:1px solid var(--line-hot);padding:1.3rem;max-width:340px;width:90%}
.modal-card h3{color:var(--ink)}
.modal-card p{color:var(--ink-dim);font-size:.9rem;line-height:1.5;margin:.4rem 0 1rem}
.modal-actions{display:flex;gap:.5rem;flex-wrap:wrap}
.modal-actions .ed-btn{flex:1}

/* ── toast ── */
.ed-toast{position:fixed;bottom:1.2rem;left:50%;transform:translateX(-50%);
  background:var(--panel-solid);border:1px solid var(--line-hot);color:var(--ink);
  padding:.6rem 1rem;font-size:.85rem;z-index:50;box-shadow:var(--shadow)}

/* ── reference-image panels ──
   Floating, movable, closable panels holding a pasted reference picture.
   Transient overlay chrome; the picture itself is the user's own data. ── */
#ref-layer{position:fixed;inset:0;z-index:38;pointer-events:none}
.ref-panel{position:fixed;pointer-events:auto;min-width:80px;
  background:var(--panel-solid);border:1px solid var(--line-hot);
  box-shadow:var(--shadow);display:flex;flex-direction:column}
.ref-head{display:flex;align-items:center;gap:.4rem;cursor:move;
  padding:.3rem .4rem;background:var(--surf);border-bottom:1px solid var(--line);
  touch-action:none;user-select:none}
.ref-title{font-family:var(--display);font-size:.6rem;letter-spacing:.03em;
  color:var(--ink-dim);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;flex:0 1 auto}
.ref-op{flex:1;display:flex;align-items:center;min-width:36px}
.ref-op input[type=range]{width:100%;min-width:36px;cursor:pointer}
.ref-close{flex:0 0 auto;width:20px;height:20px;line-height:1;padding:0;
  background:var(--surf);border:1px solid var(--line);color:var(--ink-dim);
  font-size:1rem;display:grid;place-items:center}
.ref-close:hover{border-color:var(--line-hot);color:var(--ink)}
.ref-body{position:relative;overflow:hidden;background-color:var(--checker-b);
  background-image:
    linear-gradient(45deg,var(--checker-a) 25%,transparent 25%),
    linear-gradient(-45deg,var(--checker-a) 25%,transparent 25%),
    linear-gradient(45deg,transparent 75%,var(--checker-a) 75%),
    linear-gradient(-45deg,transparent 75%,var(--checker-a) 75%);
  background-size:16px 16px;background-position:0 0,0 8px,8px -8px,-8px 0}
.ref-body img{display:block;width:100%;height:auto;image-rendering:auto;user-select:none;-webkit-user-drag:none}
.ref-resize{position:absolute;right:0;bottom:0;width:16px;height:16px;cursor:nwse-resize;
  touch-action:none;background:
    linear-gradient(135deg,transparent 45%,var(--line-hot) 45%,var(--line-hot) 55%,transparent 55%,transparent 70%,var(--line-hot) 70%,var(--line-hot) 80%,transparent 80%)}

/* ── free sheet ──
   One large surface instead of a single frame. The sheet is usually far bigger
   than a sprite cell, so the wrap is allowed to grow and the page scrolls,
   rather than trapping the art in a small scrolling box. ── */
body.mode-free .canvas-wrap{max-height:72vh}
body.mode-free #opt-onion,
body.mode-free #opt-adjacent{pointer-events:none;opacity:.45}
.cap-sel{font-family:var(--display);font-size:.7rem;color:var(--brand);
  margin:0 0 .6rem;min-height:1.1em}
.cap-target{display:flex;align-items:center;gap:.4rem;margin-bottom:.6rem}
.cap-target .ed-select{flex:1;min-width:0}
.cap-grid{display:flex;gap:.9rem;flex-wrap:wrap;margin:.2rem 0 .6rem}
.cap-grid .ed-check{margin-top:0}
.free-only .size-custom{margin-top:.5rem}
.fps-ms{display:block;font-family:var(--display);font-size:.62rem;color:var(--ink-faint);margin-top:.1rem}

/* ── floating panels ──
   The rails lift out of the grid and sit over the canvas. `position:fixed` with
   a clamped x/y, so a panel can never be dragged fully off-screen; the JS
   re-clamps on load and on resize too. ── */
body.panels-float{--col-l:0px;--col-r:0px}
/* The stage keeps gutters the width of a panel, so the slot picker and the
   canvas are never *hidden* under a panel sitting in its default corner. The
   panels are still free to be dragged over the canvas — this only stops the
   default layout from burying the controls. */
body.panels-float .ed-main{grid-template-columns:minmax(0,1fr);
  padding-left:272px;padding-right:272px}
body.panels-float .ed-tools,
body.panels-float .ed-preview{
  position:fixed;z-index:36;width:248px;max-height:78vh;overflow:auto;
  background:var(--panel-solid);border:1px solid var(--line-hot);
  box-shadow:var(--shadow);padding:0}
body.panels-float .ed-tools .rail-btn,
body.panels-float .ed-preview .rail-btn{cursor:move;touch-action:none;
  position:sticky;top:0;z-index:1;background:var(--surf);
  border-bottom:1px solid var(--line)}
body.panels-float .ed-tools .rail-body,
body.panels-float .ed-preview .rail-body{padding:.6rem}
body.panels-float .ed-panel:last-child{margin-bottom:0}
/* the drag handle earns a grip so it reads as movable, not just clickable */
body.panels-float .rail-btn .rail-name::after{content:" ⠿";color:var(--ink-faint)}

@media (max-width:1179px){
  /* Floating cards cover more than they free on a phone, so the toggle is
     disabled and the rails stay docked no matter what was saved. */
  .float-only{display:none}
}

/* ── responsive: stack the rails under the stage on narrow screens ── */
@media (max-width:900px){
  /* minmax(0,…): a bare `1fr` floors at min-content, so one wide control can
     push the single column past the viewport. Let it shrink instead. */
  .ed-main{grid-template-columns:minmax(0,1fr)}
  .canvas-wrap{max-height:52vh}
}
/* on wide screens the filmstrip sits beside the canvas and matches its height */
@media (min-width:1180px){
  .canvas-row{flex-direction:row;align-items:flex-start;justify-content:center}
  .film-band{width:auto;flex:1 1 0;align-self:stretch;display:flex;
    border-top:0;border-left:1px solid var(--line);padding-top:0;padding-left:.7rem}
  .film-strip{height:100%;flex:1;min-width:0}
  .film-cell{height:100%}
}

/* ── unified "edit in frame strip" mode ──
   The strip becomes the primary surface: one horizontal row of same-height
   cells, the active one hosting the live paint canvas (the editor) and the
   rest click-to-edit previews. Overrides the beside-canvas rules above. ── */
body.film-mode .canvas-row{display:block;width:100%}
body.film-mode .film-band{width:100%;border:0;padding:0;display:block}
/* flex-start, not stretch: once the editor cell grows with the zoom the
   previews must keep their own clamped height instead of stretching to match. */
body.film-mode .film-strip{height:auto;align-items:flex-start}
body.film-mode .film-cell{height:clamp(180px,48vh,420px)}
body.film-mode .film-cell:not(.editing){cursor:pointer}
body.film-mode .film-cell:not(.editing):hover{outline:2px solid var(--line-hot);outline-offset:1px}
/* the editor cell — clearly highlighted as "the editor" among the previews */
.film-cell.editing{background:none;cursor:default;
  outline:3px solid var(--brand);outline-offset:1px;
  box-shadow:0 0 0 3px color-mix(in srgb,var(--brand) 26%,transparent)}
.film-cell.editing .canvas-wrap{height:100%;max-height:100%;max-width:none;width:auto;border:0}
/* ── zoom past the cell must extend, not scroll ──
   The editor cell was `height:clamp(180px,48vh,420px)` with the wrap pinned to
   `height:100%`, so once `D.h * zoom` outgrew the cell the wrap's own
   `overflow:auto` raised a vertical scrollbar (~zoom 13 on a 16px sprite).
   In film mode the cell height goes auto — it grows with the canvas, the
   strip's `height:auto` follows it, and the page takes the overflow. The clamp
   survives as `min-height`, so the fitted zoom still matches the previews. */
body.film-mode .film-cell.editing{height:auto;min-height:clamp(180px,48vh,420px)}
body.film-mode .film-cell.editing .canvas-wrap{height:auto;max-height:none;overflow:visible}
.film-editing-badge{position:absolute;top:0;left:0;z-index:2;
  background:var(--brand);color:#14121f;font-family:var(--display);
  font-size:.58rem;letter-spacing:.02em;padding:.12rem .34rem;line-height:1.3}


/* ══ poses / directions selector ══════════════════════════
   `mode` picks which slot set is live. Both sets stay in the document, so
   switching is non-destructive and the picker just re-renders. ══ */
.slot-bar{display:flex;align-items:center;gap:.7rem;flex-wrap:wrap;justify-content:center;width:100%}
.mode-seg button{font-size:.72rem;padding:.36rem .55rem}
.slot-picker.as-compass{display:grid;grid-template-columns:repeat(3,34px);grid-template-rows:repeat(3,34px);gap:4px}
.slot-picker.as-poses{display:flex;gap:.4rem;flex-wrap:wrap}
/* Poses are a flat list, so a native select beats nine wrapping chips:
   it keeps the bar one row tall and is keyboard-operable for free.
   Compass keeps its 3x3 grid — there the layout IS the information. */
.pose-select{min-width:13rem;max-width:100%}
.mirror-row{margin-top:0;white-space:nowrap}

/* derived rows in the overview read as "not yours to edit" */
.dir-overview.as-poses{grid-template-columns:repeat(2,1fr)}
.ov-cell.derived{opacity:.72;border-style:dashed;cursor:not-allowed}
.dir-overview.as-poses .ov-cell{padding:0;border-radius:0}
.dir-overview.as-poses button.ov-cell:hover{border-color:var(--line-hot)}

/* ══ collapsible rails ═══════════════════════════════════
   Collapsed, an aside folds to a 34px spine that still carries a labelled
   button — a rail you cannot obviously reopen is worse than no rail. ══ */
.rail-btn{display:flex;align-items:center;gap:.35rem;width:100%;
  background:var(--surf);border:1px solid var(--line);color:var(--ink-dim);
  border-radius:0;padding:.34rem .5rem;margin-bottom:.5rem;
  font-family:var(--display);font-size:.62rem;letter-spacing:.03em}
.rail-btn:hover{border-color:var(--line-hot);color:var(--ink)}
.rail-btn:focus-visible{outline:2px solid var(--brand);outline-offset:1px}
.ed-preview .rail-btn{justify-content:flex-end}
.rail-chev{font-size:.9rem;line-height:1}
.ed-tools.collapsed,.ed-preview.collapsed{min-width:0}
.collapsed .rail-btn{flex-direction:column;gap:.5rem;padding:.5rem .2rem;margin-bottom:0;
  height:auto;justify-content:flex-start}
.collapsed .rail-chev{transform:scaleX(-1)}
.ed-preview.collapsed .rail-chev{transform:scaleX(-1)}
.collapsed .rail-name{writing-mode:vertical-rl;text-orientation:mixed;letter-spacing:.08em}

/* ══ canvas context menu ═════════════════════════════════
   Tools, palette and brush under the cursor, so collapsing the rails costs
   nothing mid-stroke. Scoped to the canvas; the browser menu is untouched
   everywhere else. ══ */
.ctx-menu{position:fixed;z-index:45;min-width:212px;max-width:250px;
  background:var(--panel-solid);border:1px solid var(--line-hot);
  box-shadow:var(--shadow);padding:.5rem}
.ctx-menu[hidden]{display:none}
.ctx-h{margin:.1rem 0 .3rem;font-family:var(--display);font-size:.58rem;
  letter-spacing:.04em;color:var(--ink-faint);text-transform:uppercase}
.ctx-h + .ctx-h{margin-top:.5rem}
.ctx-tools{display:grid;grid-template-columns:1fr 1fr;gap:.3rem;margin-bottom:.5rem}
.ctx-tool{position:relative;display:flex;align-items:center;gap:.32rem;
  background:var(--surf);border:1px solid var(--line);border-radius:0;
  padding:.34rem .4rem;color:var(--ink-dim)}
.ctx-tool b{font-size:.72rem;font-weight:600}
.ctx-tool .tico{font-size:.9rem;line-height:1}
.ctx-tool kbd{margin-left:auto;font-family:var(--display);font-size:.56rem;
  color:var(--ink-faint);background:var(--panel-solid);border:1px solid var(--line);
  padding:.08rem .2rem;line-height:1}
.ctx-tool:hover{border-color:var(--line-hot);color:var(--ink)}
.ctx-tool.on{border-color:var(--brand);background:color-mix(in srgb,var(--brand) 18%,var(--surf));color:var(--ink)}
.ctx-tool.on kbd{color:var(--brand);border-color:var(--line-hot)}
.ctx-tool:focus-visible,.ctx-pal .pal-swatch:focus-visible,.ctx-bsize:focus-visible{
  outline:2px solid var(--brand);outline-offset:1px}
.ctx-pal{display:grid;grid-template-columns:repeat(8,1fr);gap:3px;margin-bottom:.5rem}
.ctx-brush{display:grid;grid-template-columns:repeat(8,1fr);gap:3px}
.ctx-bsize{background:var(--surf);border:1px solid var(--line);border-radius:0;
  color:var(--ink-dim);font-family:var(--display);font-size:.66rem;padding:.26rem 0}
.ctx-bsize:hover{border-color:var(--line-hot);color:var(--ink)}
.ctx-bsize.on{border-color:var(--brand);color:var(--brand);
  background:color-mix(in srgb,var(--brand) 16%,var(--surf))}

/* focus ring for the now-focusable canvas (Menu key opens the context menu) */
.paint:focus-visible{outline:2px solid var(--brand);outline-offset:2px}

@media (max-width:900px){
  /* single column: a collapsed rail is a full-width strip, not a spine */
  body.rail-left-out{--col-l:auto}
  body.rail-right-out{--col-r:auto}
  .collapsed .rail-btn{flex-direction:row;padding:.34rem .5rem}
  .collapsed .rail-name{writing-mode:horizontal-tb}
  .slot-picker.as-poses{justify-content:center}
}

/* ── migration notice ── */
.mig-note{display:flex;align-items:center;gap:.6rem;flex-wrap:wrap;
  border:1px solid var(--line-hot);background:color-mix(in srgb,var(--brand) 12%,var(--panel-solid));
  padding:.5rem .7rem;margin-bottom:.2rem}
.mig-note[hidden]{display:none}
.mig-txt{flex:1;min-width:0;font-size:.8rem;color:var(--ink)}
.mig-note .ed-btn{font-size:.76rem;padding:.34rem .6rem}
.mig-x{background:none;border:0;color:var(--ink-dim);font-size:1.1rem;line-height:1;padding:0 .2rem}
.mig-x:hover{color:var(--ink)}
.mig-x:focus-visible,.mig-note .ed-btn:focus-visible{outline:2px solid var(--brand);outline-offset:1px}

/* ── narrow screens: the canvas comes first ──
   Stacked, the tools rail preceded the stage in source order, so drawing on a
   phone meant scrolling past every panel. Collapsing the rail worked but
   shouldn't be the price of admission. ── */
@media (max-width:900px){
  .ed-stage{order:-1}
  .ed-tools{order:1}
  .ed-preview{order:2}
}

/* ── signed-in chip ── same markup and rules in every Happy Light app.
   hl-account.js unhides it from the portal's hl_signed_in hint and fills in
   the hl_name hint as text; with no name it keeps saying "Signed in". The
   avatar is the 8×8 pixel ghost from happylight.io. Below 560px only the
   avatar shows; the link's aria-label carries the words. ── */
.hl-me{display:inline-flex;align-items:center;gap:.4rem;flex:none;max-width:13rem;
  padding:.15rem .7rem .15rem .15rem;border-radius:999px;
  border:1px solid color-mix(in srgb,var(--ok) 40%,var(--line));
  background:color-mix(in srgb,var(--ok) 9%,var(--surf,transparent));
  color:var(--ink);font-size:.78rem;font-weight:600;line-height:1.2;
  text-decoration:none;white-space:nowrap}
.hl-me:hover{border-color:color-mix(in srgb,var(--ok) 65%,transparent);
  background:color-mix(in srgb,var(--ok) 16%,var(--surf,transparent))}
.hl-me-avatar{position:relative;display:grid;place-items:center;flex:none;
  width:1.45rem;height:1.45rem;border-radius:50%;
  background:color-mix(in srgb,var(--ink) 10%,transparent)}
.hl-me-ghost{width:.8rem;height:.8rem;fill:currentColor;animation:hl-me-bob 2.4s steps(4) infinite}
.hl-me-dot{position:absolute;right:-1px;bottom:-1px;width:.5rem;height:.5rem;
  border-radius:50%;background:var(--ok);box-shadow:0 0 0 2px var(--bg)}
.hl-me-dot::after{content:"";position:absolute;inset:0;border-radius:inherit;
  background:var(--ok);animation:hl-me-ping 2.4s cubic-bezier(.22,.61,.36,1) infinite}
.hl-me-name{min-width:0;overflow:hidden;text-overflow:ellipsis}
@keyframes hl-me-bob{0%,100%{transform:translateY(0)}50%{transform:translateY(-1px)}}
@keyframes hl-me-ping{0%{transform:scale(1);opacity:.6}70%,100%{transform:scale(2.4);opacity:0}}
@media (max-width:560px){.hl-me{padding:.15rem}.hl-me-name{display:none}}
@media (prefers-reduced-motion:reduce){.hl-me-ghost,.hl-me-dot::after{animation:none}}

/* ── free sheet: whole-stage canvas + floating action bar ──
   The stage becomes one big canvas and the controls that normally surround it
   (mode / animation picker, zoom, frame strip, frame ops) live in #free-bar,
   floating top-centre. Scoped to body.mode-free: the other modes keep the
   stacked layout untouched. ── */
.free-bar{display:none}
body.mode-free .ed-stage{position:relative;padding:0;gap:0;
  min-height:max(480px,calc(100vh - 9rem));min-height:max(480px,calc(100dvh - 9rem))}
body.mode-free .stage-top{display:contents}
body.mode-free .canvas-row{position:absolute;inset:0;width:auto}
body.mode-free .canvas-wrap{width:100%;height:100%;max-width:none;max-height:none;border:0}
body.mode-free .free-bar:not([hidden]){display:flex;flex-direction:column;align-items:stretch;
  position:absolute;z-index:6;top:.6rem;left:50%;transform:translateX(-50%);
  width:max-content;max-width:calc(100% - 1.2rem);max-height:calc(100% - 1.2rem);
  background:var(--panel-solid);border:1px solid var(--line-hot);box-shadow:var(--shadow)}
.free-bar-toggle{display:flex;align-items:center;justify-content:center;gap:.4rem;
  background:var(--surf);border:0;border-bottom:1px solid var(--line);border-radius:0;
  padding:.25rem .6rem;font-family:var(--display);font-size:.62rem;color:var(--ink-dim);cursor:pointer}
.free-bar.collapsed .fb-chev{transform:rotate(-90deg)}
.free-bar-body{display:flex;flex-flow:row wrap;gap:.35rem .8rem;align-items:center;
  justify-content:center;padding:.4rem .6rem;overflow:auto;min-width:0}
.free-bar-body .slot-bar,.free-bar-body .frames-bar,.free-bar-body .frame-ops{gap:.35rem .6rem;width:auto}
.free-bar-body .frames-bar{border-top:0;padding-top:0;justify-content:center}
.free-bar-body .frames-strip{flex:0 1 auto;max-width:100%}
.free-bar-body .zoom-row{margin-top:0}
.free-bar-body .dir-name{display:none}
.free-bar-body .frame-thumb{width:42px;height:42px}
/* collapsed: only the mode / animation picker stays */
.free-bar.collapsed .zoom-row,.free-bar.collapsed .frames-bar{display:none}
@media (max-width:900px){
  body.mode-free .ed-stage{min-height:max(420px,calc(100vh - 8rem));min-height:max(420px,calc(100dvh - 8rem))}
  body.mode-free .free-bar:not([hidden]){max-height:60%}
}

/* ── Google Drive picker (hl-drive.js builds it; classes only) ── */
.hl-drive-dialog{width:min(30rem,calc(100vw - 2rem));max-height:min(32rem,calc(100vh - 4rem));
  padding:1rem;border:1px solid var(--line);border-radius:12px;
  background:var(--panel-solid);color:var(--ink);box-shadow:var(--shadow);font-family:var(--font)}
.hl-drive-dialog::backdrop{background:rgba(0,0,0,.5)}
.hl-drive-title{margin:0 0 .7rem;font-size:1rem}
.hl-drive-empty{color:var(--ink-dim);font-size:.88rem}
.hl-drive-list{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:.3rem;
  overflow:auto;max-height:22rem}
.hl-drive-file{appearance:none;width:100%;display:flex;justify-content:space-between;gap:1rem;
  font:inherit;font-size:.86rem;text-align:left;cursor:pointer;padding:.5rem .6rem;
  border:1px solid var(--line);border-radius:.4rem;background:var(--surf);color:var(--ink)}
.hl-drive-file:hover{border-color:var(--line-hot)}
.hl-drive-file:focus-visible{outline:2px solid var(--brand);outline-offset:1px}
.hl-drive-name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.hl-drive-meta{flex:none;color:var(--ink-faint);font-size:.78rem}
.hl-drive-actions{display:flex;justify-content:flex-end;margin-top:.8rem}
.hl-drive-cancel{appearance:none;font:inherit;font-size:.84rem;font-weight:600;cursor:pointer;
  padding:.4rem .8rem;border-radius:999px;border:1px solid var(--line);background:none;color:var(--ink)}
