:root {
  --radius: 10px;

  --rail-w: 78px;          /* vertical rail, desktop */
  --rail-h: 58px;          /* horizontal rail, phones */
  --panel-w: 312px;

  /* how much of the stage the bottom sheet is currently covering.
     Written by ui.js; consumed by .stage-inner so fitView() stays honest. */
  --sheet-inset: 0px;
  --sheet-y: 100%;
}

/* ── themes ───────────────────────────────────────────────────────────────
   Every colour in this file is a token. Light is the default — it is what
   :root carries, so the app is light even before any script runs — and
   [data-theme="dark"] swaps the same names. Nothing below re-states a
   literal colour, which is the only reason the two themes stay in sync.
   The theme lives on <html> and is written by ui.js (localStorage key
   `mrc_theme`, shared with the rest of myrecorp.com). */
:root,
[data-theme="light"] {
  /* three surfaces, deliberately distinct: stage darkest, chrome tinted,
     panel white — otherwise the slots vanish into the panel behind them */
  --bg: #eceff4;
  --bg2: #f7f9fc;
  --panel: #ffffff;
  --line: #e1e7ef;
  --line2: #cbd4e0;
  --txt: #16202b;
  --mut: #63707f;
  --acc: #2b7fd4;
  --acc2: #1b6ab8;

  --hov: #e9eef5;          /* bare-button hover                     */
  --sel: #dbeafe;          /* selected chip / rail button           */
  --sel-txt: #14538d;
  --btn: #f1f4f9;          /* raised button face                    */
  --btn-hov: #e4eaf2;
  --btn-line-hov: #adbccd;
  --field: #ffffff;        /* inputs, chips, readouts               */
  --track: #d7dee7;        /* range track, scrollbar thumb          */
  --hint: #7a8694;
  --empty-icon: #c2cbd7;
  --export-bg: rgba(43,127,212,.12);
  --dot-glow: rgba(43,127,212,.28);

  --chk1: #ffffff;         /* transparency checkerboard             */
  --chk2: #e7ebf1;

  --stage-top: #ffffff;    /* stage's radial highlight              */
  --float: rgba(255,255,255,.9);
  --pill-bg: rgba(255,255,255,.86);
  --veil: rgba(219,234,254,.8);

  --shadow-canvas: 0 10px 34px rgba(22,32,43,.16), 0 0 0 1px var(--line2);
  --shadow-float: 0 8px 26px rgba(22,32,43,.14);
  --shadow-panel: 18px 0 40px rgba(22,32,43,.14);
  --shadow-sheet: 0 -14px 44px rgba(22,32,43,.18);
}

[data-theme="dark"] {
  --bg: #0d1013;
  --bg2: #14181d;
  --panel: #171c22;
  --line: #262e37;
  --line2: #333d49;
  --txt: #e6ebf1;
  --mut: #8b97a5;
  --acc: #4da3ff;
  --acc2: #2b7fd4;

  --hov: #1e242c;
  --sel: #1d3d5c;
  --sel-txt: #cfe6ff;
  --btn: #222a33;
  --btn-hov: #2b353f;
  --btn-line-hov: #435161;
  --field: #0f1318;
  --track: #2a333d;
  --hint: #6d7885;
  --empty-icon: #3a4551;
  --export-bg: rgba(45,110,180,.22);
  --dot-glow: rgba(77,163,255,.45);

  --chk1: #232830;
  --chk2: #2e343d;

  --stage-top: #1a2029;
  --float: rgba(23,28,34,.88);
  --pill-bg: rgba(20,24,29,.84);
  --veil: rgba(20,40,64,.75);

  --shadow-canvas: 0 10px 40px rgba(0,0,0,.55), 0 0 0 1px var(--line2);
  --shadow-float: 0 8px 26px rgba(0,0,0,.5);
  --shadow-panel: 18px 0 40px rgba(0,0,0,.4);
  --shadow-sheet: 0 -14px 44px rgba(0,0,0,.55);
}

* { box-sizing: border-box; }

html { height: 100%; }

/* fixed body + dvh shell: the document never scrolls, so iOS can't rubber-band
   the whole app, and dvh tracks the real visible area as the URL bar collapses */
body {
  position: fixed;
  inset: 0;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--txt);
  font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  transition: background .2s, color .2s;
}

/* progressive: vh → svh → dvh, last supported one wins */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100svh;
  height: 100dvh;
  overflow: hidden;
}

/* double-tap-to-zoom is the reason people reach for user-scalable=no.
   Killing it per-control keeps pinch-zoom working everywhere else. */
button, input, select, label, .chip { touch-action: manipulation; }

/* ── topbar ── */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
  padding-left: calc(16px + env(safe-area-inset-left));
  padding-right: calc(16px + env(safe-area-inset-right));
  background: var(--bg2);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .dot {
  width: 16px; height: 16px; border-radius: 5px;
  background: linear-gradient(135deg, var(--acc), #a06bff);
  box-shadow: 0 0 14px var(--dot-glow);
}
.brand h1 { font-size: 15px; font-weight: 650; margin: 0; letter-spacing: .2px; }
.brand h1 em { color: var(--mut); font-style: normal; font-weight: 400; }

.topbar-gap { flex: 1 1 auto; }

/* only present on the hosted copy, where this app is the whole page and the
   visitor needs a way back to the site */
.topbar-link {
  display: flex; align-items: center; gap: 6px;
  flex: 0 0 auto;
  padding: 7px 11px;
  font-size: 12px;
  color: var(--mut);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--btn);
  transition: background .14s, color .14s, border-color .14s;
}
.topbar-link:hover { background: var(--btn-hov); color: var(--txt); border-color: var(--btn-line-hov); }
.topbar-link svg { width: 14px; height: 14px; }
@media (max-width: 480px) {
  .topbar-link span { display: none; }
  .topbar-link { padding: 8px; }
}

/* theme toggle — one button, two icons; CSS picks which one is showing so the
   script only ever has to move the data-theme attribute */
.themebtn {
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  flex: 0 0 auto;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--btn);
  color: var(--mut);
  cursor: pointer;
  transition: background .14s, color .14s, border-color .14s;
}
.themebtn:hover { background: var(--btn-hov); color: var(--txt); border-color: var(--btn-line-hov); }
.themebtn:active { transform: translateY(1px); }
.themebtn:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; }
.themebtn svg { width: 17px; height: 17px; }

.themebtn .ico-sun { display: none; }
[data-theme="dark"] .themebtn .ico-sun { display: block; }
[data-theme="dark"] .themebtn .ico-moon { display: none; }

/* ── shell ── */
.shell {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
  position: relative;
}

/* ── tool rail ───────────────────────────────────────────────────────────
   Navigation-rail on wide screens, bottom bar on phones. Same markup. */
.rail {
  flex: 0 0 auto;
  width: var(--rail-w);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  padding: 8px 8px;
  padding-left: calc(8px + env(safe-area-inset-left));
  background: var(--bg2);
  border-right: 1px solid var(--line);
  z-index: 40;
}
.rail-gap { flex: 1 1 auto; }

.rail-btn {
  position: relative;
  font: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 9px 2px 7px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--mut);
  cursor: pointer;
  transition: background .14s, color .14s;
}
.rail-btn svg { width: 22px; height: 22px; flex: 0 0 auto; }
.rail-lbl { font-size: 10.5px; letter-spacing: .2px; line-height: 1; }

.rail-btn:hover:not(:disabled) { background: var(--hov); color: var(--txt); }
.rail-btn.on { background: var(--sel); color: var(--sel-txt); }
.rail-btn:disabled { opacity: .35; cursor: not-allowed; }
.rail-btn:focus-visible { outline: 2px solid var(--acc); outline-offset: -2px; }

.rail-btn.export { color: var(--sel-txt); background: var(--export-bg); }
.rail-btn.export:hover:not(:disabled) {
  background: linear-gradient(180deg, var(--acc), var(--acc2));
  color: #fff;
}
.rail-btn.export:disabled { background: transparent; color: var(--mut); }

/* filled-slot indicator — Layers is hidden most of the time, so surface it */
.rail-dot {
  position: absolute;
  top: 7px; right: 14px;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--acc);
  box-shadow: 0 0 0 2px var(--bg2);
  opacity: 0;
  transition: opacity .15s;
}
.rail-dot.on { opacity: 1; }

/* ── panel ─────────────────────────────────────────────────────────────── */
.panel {
  flex: 0 0 auto;
  width: var(--panel-w);
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow: hidden;
  transition: width .24s cubic-bezier(.4,0,.2,1);
  z-index: 30;
}
body[data-panel="closed"] .panel { width: 0; border-right-width: 0; }

.panel-head,
.panel-scroll { min-width: var(--panel-w); }   /* no reflow while collapsing */

.panel-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--line);
}
.panel-head h2 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .9px;
  color: var(--mut); margin: 0; font-weight: 600;
}
.panel-close {
  display: grid; place-items: center;
  width: 26px; height: 26px; padding: 0;
  border: 0; border-radius: 7px;
  background: transparent; color: var(--mut); cursor: pointer;
}
.panel-close svg { width: 15px; height: 15px; }
.panel-close:hover { background: var(--hov); color: var(--txt); }

.panel-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 24px;
}
.panel-scroll::-webkit-scrollbar { width: 10px; }
.panel-scroll::-webkit-scrollbar-thumb { background: var(--track); border-radius: 8px; border: 3px solid var(--panel); }

.pane { display: none; padding: 14px 16px; }
.pane.on { display: block; }

/* the sheet's drag handle — only ever visible in sheet mode */
.sheet-grab { display: none; }

/* ── slots ── */
.slot {
  display: flex; align-items: center; gap: 10px;
  padding: 8px; margin-bottom: 8px;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: border-color .15s, background .15s;
}
.slot.filled { border-color: var(--line2); }
.slot-thumb {
  width: 44px; height: 44px; flex: 0 0 44px;
  border-radius: 7px; overflow: hidden;
  display: grid; place-items: center;
  background-color: var(--chk1);
  background-image:
    linear-gradient(45deg, var(--chk2) 25%, transparent 25%, transparent 75%, var(--chk2) 75%),
    linear-gradient(45deg, var(--chk2) 25%, transparent 25%, transparent 75%, var(--chk2) 75%);
  background-size: 12px 12px;
  background-position: 0 0, 6px 6px;
  border: 1px solid var(--line);
}
.slot-thumb span { font-size: 9px; color: var(--mut); letter-spacing: .5px; }
.slot-thumb img,
.slot-thumb canvas { width: 100%; height: 100%; object-fit: contain; display: block; }
.slot-body { flex: 1 1 auto; min-width: 0; }
.slot-title { font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.tag {
  font-size: 9px; font-weight: 500; color: var(--mut);
  border: 1px solid var(--line2); border-radius: 20px; padding: 1px 6px;
}
.slot-meta {
  font-size: 11px; color: var(--mut);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.slot-btns { display: flex; gap: 4px; flex: 0 0 auto; }
.slot-btns.col { flex-direction: column; gap: 2px; }

/* a selectable layer row — the whole card is the hit target */
.slot.layer { cursor: pointer; }
.slot.layer:hover { background: var(--hov); }
/* NB: not `.sel` — that name is already taken by the <select> rule below,
   which carries a width and would squash any slot wearing it */
.slot.is-sel {
  border-color: var(--acc);
  box-shadow: 0 0 0 1px var(--acc);
  background: var(--sel);
}
.slot.is-sel .slot-title { color: var(--sel-txt); }
.slot:focus-visible { outline: 2px solid var(--acc); outline-offset: 1px; }

.btn.mini {
  padding: 0; width: 24px; height: 24px;
  font-size: 13px; line-height: 1;
  display: grid; place-items: center;
  border-color: transparent;
  flex: 0 0 auto;
}
.btn.mini:disabled { opacity: .25; }

/* ── restack grip ── */
.grip {
  flex: 0 0 auto;
  width: 18px; height: 30px;
  padding: 0; margin-left: -2px;
  border: 0; background: transparent;
  color: var(--line2);
  cursor: grab;
  display: grid; place-items: center;
  touch-action: none;              /* the sheet must not scroll under a drag */
}
.grip svg { width: 15px; height: 15px; fill: currentColor; }
.grip:hover { color: var(--mut); }
.grip:focus-visible { outline: 2px solid var(--acc); outline-offset: -2px; border-radius: 5px; }
.grip-spacer { flex: 0 0 auto; width: 18px; margin-left: -2px; }
body.row-dragging { cursor: grabbing; user-select: none; }
body.row-dragging .grip { cursor: grabbing; }

.slot.dragging {
  position: relative;
  z-index: 5;
  opacity: .9;
  box-shadow: 0 8px 22px rgba(0,0,0,.28);
  pointer-events: none;
}

.drop-line {
  height: 2px;
  margin: -5px 0 3px;
  border-radius: 2px;
  background: var(--acc);
  box-shadow: 0 0 0 2px var(--dot-glow);
}

/* an unfilled image slot: still a drop target, just quieter */
.slot.empty { border-style: dashed; background: transparent; }
.slot.empty .slot-title,
.slot.empty .slot-meta { color: var(--hint); font-weight: 500; }
.slot.empty .slot-thumb { opacity: .55; }

/* section heading inside the Layers pane */
.layer-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin: 16px 0 8px;
  font-size: 11px; text-transform: uppercase; letter-spacing: .9px;
  color: var(--mut); font-weight: 600;
}
.layer-head b { color: var(--acc); font-weight: 700; }
.layer-head i {
  font-style: normal; font-weight: 500; text-transform: none;
  letter-spacing: 0; font-size: 10.5px; color: var(--hint);
}

/* Adjust pane header + its disabled state */
.editing {
  font-size: 12px; color: var(--mut);
  margin-bottom: 10px;
}
.editing b { color: var(--txt); font-weight: 600; }
#adjustBody.is-off { opacity: .38; pointer-events: none; }

.hint.tight { margin-top: 6px; }

/* ── buttons ── */
.btn {
  font: inherit; color: var(--txt);
  background: var(--btn); border: 1px solid var(--line2);
  border-radius: 8px; padding: 7px 12px; cursor: pointer;
  transition: background .13s, border-color .13s, transform .05s;
}
.btn:hover:not(:disabled) { background: var(--btn-hov); border-color: var(--btn-line-hov); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.tiny { padding: 5px 9px; font-size: 12px; }
.btn.ghost { background: transparent; }
.btn-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 10px; }
.btn-grid .btn { padding: 8px 2px; font-size: 11.5px; }
.btn.on { background: var(--sel); border-color: var(--acc2); color: var(--sel-txt); }

/* ── rows / inputs ── */
.row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.lbl { font-size: 12px; color: var(--mut); flex: 1 1 auto; }
.unit { font-size: 11px; color: var(--mut); }
input[type=number], .sel, input[type=text] {
  font: inherit; color: var(--txt);
  background: var(--field); border: 1px solid var(--line2);
  border-radius: 7px; padding: 5px 8px; width: 88px;
}
.sel { width: 130px; }
input[type=number]:focus, .sel:focus { outline: 2px solid var(--acc2); outline-offset: -1px; }
.custom-ratio { justify-content: flex-start; }
.custom-ratio input { width: 68px; }
.colon { color: var(--mut); }
.color { width: 40px; height: 26px; padding: 0; border: 1px solid var(--line2); border-radius: 6px; background: var(--field); }

.outsize {
  margin-top: 8px; font-size: 11px; color: var(--mut);
  background: var(--field); border: 1px solid var(--line);
  border-radius: 7px; padding: 5px 8px; text-align: center;
}

/* ── ratio chips ── */
.ratios { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.chip {
  font: inherit; font-size: 11.5px; color: var(--mut);
  background: var(--field); border: 1px solid var(--line2);
  border-radius: 7px; padding: 8px 2px; cursor: pointer; text-align: center;
  transition: .13s;
}
.chip:hover { color: var(--txt); border-color: var(--btn-line-hov); }
.chip.on { background: var(--sel); border-color: var(--acc2); color: var(--sel-txt); font-weight: 600; }

/* ── sliders ── */
.slider-row { display: block; margin-bottom: 10px; }
.slider-row .lbl { display: flex; justify-content: space-between; margin-bottom: 4px; }
.slider-row .lbl b { color: var(--txt); font-weight: 600; }
input[type=range] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 4px; border-radius: 3px;
  background: var(--track); outline: none; margin: 6px 0;
  touch-action: pan-y;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 15px; height: 15px; border-radius: 50%;
  background: var(--acc); border: 2px solid var(--panel); cursor: pointer;
  box-shadow: 0 0 0 1px var(--acc2);
}
input[type=range]::-moz-range-thumb {
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--acc); border: 2px solid var(--panel); cursor: pointer;
}

/* ── checks ── */
.check { display: flex; align-items: center; gap: 8px; margin: 6px 0; cursor: pointer; font-size: 12.5px; }
.check input { accent-color: var(--acc); width: 15px; height: 15px; }

.hint { font-size: 11px; color: var(--hint); margin: 10px 0 0; line-height: 1.5; }

/* ── stage ── */
.stage {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  background:
    radial-gradient(circle at 50% 0%, var(--stage-top) 0%, var(--bg) 60%);
}
.stage-inner {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 18px;
  padding-right: calc(18px + env(safe-area-inset-right));
  /* the sheet eats into the usable stage here, which shrinks .canvas-wrap,
     which trips app.js's existing ResizeObserver → the view re-fits itself */
  padding-bottom: calc(18px + var(--sheet-inset));
  transition: padding-bottom .18s linear;
}
.canvas-wrap {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  overflow: hidden;            /* the viewport the canvas floats inside */
  overscroll-behavior: contain;
}
#view {
  display: block;
  position: absolute;
  left: 50%;
  top: 50%;
  /* size + translate are driven by the view-zoom state in app.js */
  transform-origin: 50% 50%;
  border-radius: 4px;
  box-shadow: var(--shadow-canvas);
  touch-action: none;
  cursor: grab;
  /* transparency checkerboard sits BEHIND the canvas pixels, never baked in */
  background-color: var(--chk1);
  background-image:
    linear-gradient(45deg, var(--chk2) 25%, transparent 25%, transparent 75%, var(--chk2) 75%),
    linear-gradient(45deg, var(--chk2) 25%, transparent 25%, transparent 75%, var(--chk2) 75%);
  background-size: 20px 20px;
  background-position: 0 0, 10px 10px;
}
#view.dragging { cursor: grabbing; }
#view.empty-state { opacity: .35; }
.canvas-wrap.panning #view,
.canvas-wrap.spacing #view { cursor: grab; }
.canvas-wrap.panning #view { cursor: grabbing; }

.empty {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  pointer-events: none;
}
.empty-card { text-align: center; color: var(--mut); }
.empty-icon { font-size: 46px; line-height: 1; color: var(--empty-icon); }
.empty-card p { margin: 8px 0 0; }
.empty-card .sub { font-size: 12px; color: var(--hint); max-width: 300px; }

/* ── floating view controls (Maps-style stack) ── */
.viewzoom {
  position: absolute;
  top: 14px;
  right: calc(14px + env(safe-area-inset-right));
  z-index: 15;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px;
  background: var(--float);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: 13px;
  box-shadow: var(--shadow-float);
}
.viewzoom .btn.tiny {
  width: 46px; height: 30px;
  padding: 0;
  display: grid; place-items: center;
  background: transparent; border-color: transparent;
  font-size: 12px; line-height: 1;
}
.viewzoom .btn.tiny:hover:not(:disabled) { background: var(--btn-hov); border-color: transparent; }
.viewzoom .vzval { font-size: 10.5px; font-variant-numeric: tabular-nums; font-weight: 600; }
.viewzoom .vzval.on { color: var(--sel-txt); background: var(--sel); }
.viewzoom .sep { height: 1px; width: 100%; background: var(--line2); margin: 3px 0; }

/* ── status pill ── */
.statuspill {
  position: absolute;
  left: calc(16px + env(safe-area-inset-left));
  bottom: calc(14px + var(--sheet-inset));
  z-index: 12;
  max-width: min(52ch, calc(100% - 96px));
  padding: 5px 11px;
  font-size: 11.5px;
  color: var(--mut);
  background: var(--pill-bg);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: 20px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  transition: opacity .35s, bottom .18s linear;
}
.statuspill.faded { opacity: 0; }

.dropveil {
  position: absolute; inset: 10px;
  border: 2px dashed var(--acc);
  border-radius: 14px;
  background: var(--veil);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  display: none; place-items: center;
  font-size: 18px; font-weight: 600; color: var(--sel-txt);
  pointer-events: none;
  z-index: 20;
}
.stage.dragover .dropveil { display: grid; }


/* ══ 721–1099px: rail stays, panel floats over the stage ══════════════════ */
@media (max-width: 1099px) {
  :root { --rail-w: 62px; --panel-w: 300px; }

  .rail-lbl { display: none; }
  .rail-btn { padding: 11px 2px; }
  .rail-dot { right: 12px; top: 5px; }

  .panel {
    position: absolute;
    left: var(--rail-w); top: 0; bottom: 0;   /* beside the rail, not under it */
    width: var(--panel-w);
    border-right: 1px solid var(--line);
    box-shadow: var(--shadow-panel);
    transition: transform .24s cubic-bezier(.4,0,.2,1), visibility .24s;
  }
  body[data-panel="closed"] .panel {
    width: var(--panel-w);
    border-right-width: 1px;
    transform: translateX(-100%);
    visibility: hidden;
  }
}


/* ══ ≤720px: rail becomes a bottom bar, panel becomes a bottom sheet ══════ */
@media (max-width: 720px) {
  .topbar { padding: 8px 14px; padding-top: calc(8px + env(safe-area-inset-top)); }
  .brand h1 { font-size: 14px; }

  .shell { flex-direction: column; }

  .stage { order: 1; flex: 1 1 auto; min-height: 0; }
  .stage-inner { padding: 12px; padding-bottom: calc(12px + var(--sheet-inset)); }

  /* rail → bottom bar, in normal flow so it always reserves its own space */
  .rail {
    order: 2;
    flex: 0 0 auto;
    flex-direction: row;
    width: auto;
    height: auto;
    gap: 2px;
    padding: 5px 6px;
    padding-bottom: calc(5px + env(safe-area-inset-bottom));
    padding-left: calc(6px + env(safe-area-inset-left));
    padding-right: calc(6px + env(safe-area-inset-right));
    border-right: 0;
    border-top: 1px solid var(--line);
  }
  .rail-gap { display: none; }
  .rail-btn {
    flex: 1 1 0;
    min-width: 0;
    height: var(--rail-h);
    padding: 6px 2px;
    border-radius: 10px;
  }
  .rail-lbl { display: block; font-size: 9.5px; }
  .rail-btn svg { width: 21px; height: 21px; }
  .rail-dot { top: 6px; right: calc(50% - 18px); box-shadow: 0 0 0 2px var(--bg2); }
  .rail-btn.export { background: var(--export-bg); }

  /* the sheet */
  .panel {
    position: fixed;
    left: 0; right: 0;
    top: auto;
    bottom: calc(var(--rail-h) + 10px + env(safe-area-inset-bottom));
    width: auto;
    height: 76dvh;
    max-height: 76dvh;
    border: 1px solid var(--line);
    border-bottom: 0;
    border-radius: 18px 18px 0 0;
    box-shadow: var(--shadow-sheet);
    transform: translateY(var(--sheet-y));
    transition: transform .3s cubic-bezier(.32,.72,0,1);
    visibility: visible;
    z-index: 35;
  }
  body[data-panel="closed"] .panel {
    width: auto;
    transform: translateY(var(--sheet-y));
    visibility: visible;
  }
  /* parked below the rail — don't let its top shadow glow onto the stage */
  body[data-sheet="closed"] .panel { box-shadow: none; }
  body.sheet-dragging .panel,
  body.sheet-dragging .stage-inner,
  body.sheet-dragging .statuspill { transition: none; }

  .panel-head, .panel-scroll { min-width: 0; }

  .sheet-grab {
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    height: 24px;
    cursor: grab;
    touch-action: none;
  }
  .sheet-grab span {
    width: 40px; height: 4px;
    border-radius: 3px;
    background: var(--line2);
  }
  body.sheet-dragging .sheet-grab { cursor: grabbing; }

  .panel-head { padding: 2px 14px 10px; }
  .pane { padding: 12px 16px; }
  .panel-scroll { padding-bottom: 28px; }

  /* touch targets */
  .btn.tiny { padding: 8px 10px; font-size: 12px; }
  /* thumb-sized targets for the row controls; the meta line truncates to fit */
  .btn.mini { width: 34px; height: 34px; font-size: 16px; }
  .grip { width: 26px; height: 38px; }
  .grip svg { width: 17px; height: 17px; }
  .grip-spacer { width: 26px; }
  .btn-grid { grid-template-columns: repeat(4, 1fr); gap: 7px; }
  .btn-grid .btn { padding: 11px 2px; }
  .chip { padding: 10px 2px; }
  .slot-btns .btn.tiny { padding: 8px 11px; }
  .check { margin: 10px 0; font-size: 13px; }
  .check input { width: 18px; height: 18px; }
  input[type=range] { height: 6px; margin: 10px 0; }
  input[type=range]::-webkit-slider-thumb { width: 20px; height: 20px; }
  input[type=range]::-moz-range-thumb { width: 18px; height: 18px; }
  input[type=number], .sel { padding: 8px; }

  .viewzoom { top: 10px; right: calc(10px + env(safe-area-inset-right)); }
  .viewzoom .btn.tiny { width: 42px; height: 32px; }

  .statuspill {
    left: 10px; right: 62px;
    bottom: calc(10px + var(--sheet-inset));
    max-width: none;
    font-size: 11px;
  }
  .empty-card .sub { max-width: 240px; }
}

/* landscape phones: the sheet has almost no room, so let it use nearly the
   full height and drop the rail labels. Scoped to sheet mode only — above
   720px the panel is a full-height side overlay and must not be clipped. */
@media (max-width: 720px) and (max-height: 480px) {
  .panel { height: 90dvh; max-height: 90dvh; }
  .rail-lbl { display: none; }
  .rail-btn { height: 46px; }
  :root { --rail-h: 46px; }
}

@media (prefers-reduced-motion: reduce) {
  .panel, .stage-inner, .statuspill { transition: none; }
}
