/* =============================================================================
   Infinicanvas — application stylesheet
   -----------------------------------------------------------------------------
   Loaded directly by index.html after css/fonts.css. No build step, no imports,
   no remote resources. Every colour comes from a token declared in the theme
   blocks below; nothing else in this file contains a literal colour.

   Contents
     01  Design tokens — metrics, motion, z-index
     02  Design tokens — light theme
     03  Design tokens — dark theme
     04  Reset & document shell
     05  Canvas stack
     06  UI layer & shared primitives (.btn, .field, .segmented, .slider)
     07  Popovers & menus
     08  Top bar
     09  Style panel
     10  Toolbar
     11  Navigator (zoom controls, minimap)
     12  Toasts & tooltips
     13  Modals & dialog content
     14  On-canvas text editor
     15  Boot, noscript, fatal, drop target
     16  Scrollbars, selection, focus
     17  Responsive — narrow layout, coarse pointers, short viewports
     18  Reduced motion & print
   ========================================================================== */

/* -----------------------------------------------------------------------------
   01  Design tokens — metrics, motion, z-index
   -------------------------------------------------------------------------- */

:root {
  /* Type ------------------------------------------------------------------ */
  --font-ui: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --fs-base: 13px;
  --fs-sm: 12px;
  --fs-xs: 11px;
  --fw-regular: 400;
  --fw-medium: 500;
  --fw-semibold: 600;
  --lh-tight: 1.25;
  --lh-body: 1.55;

  /* Spacing --------------------------------------------------------------- */
  --sp-1: 2px;
  --sp-2: 4px;
  --sp-3: 6px;
  --sp-4: 8px;
  --sp-5: 12px;
  --sp-6: 16px;
  --sp-7: 20px;
  --sp-8: 24px;

  /* Radii ----------------------------------------------------------------- */
  --r-xs: 4px;
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 10px;
  --r-xl: 14px;
  --r-pill: 999px;

  /* Control metrics (overridden by the responsive/coarse blocks) ----------- */
  --ctl-h: 32px;
  --mini-h: 26px;
  --seg-h: 28px;
  --row-h: 30px;
  --tool-size: 38px;
  --swatch-size: 22px;
  --swatch-size-compact: 18px;
  --icon-gutter: 20px;

  /* Motion ---------------------------------------------------------------- */
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --t-fast: 120ms;
  --t-med: 180ms;
  --t-slow: 260ms;
  --t-spin: 1100ms;

  /* Stacking -------------------------------------------------------------- */
  --z-canvas: 0;
  --z-chrome: 20;
  --z-toast: 60;
  --z-modal: 800;
  --z-popover: 1000;
  --z-tooltip: 1100;
  --z-boot: 1200;

  /* Viewport height with a vh fallback (upgraded to dvh just below) -------- */
  --vh100: 100vh;

  /* Safe areas ------------------------------------------------------------ */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);

  /* Chrome placement ------------------------------------------------------ */
  --gutter: 10px;
  --topbar-h: 46px;
  --toolbar-gap: 12px;

  /* Layout switches — flipped wholesale by the responsive blocks ----------- */
  --chrome-top: calc(var(--safe-top) + var(--topbar-h) + var(--gutter) + 8px);
  --panel-w: 236px;
  --panel-top: var(--chrome-top);
  --panel-left: calc(var(--safe-left) + var(--gutter));
  --panel-right: auto;
  --panel-bottom: auto;
  --panel-radius: var(--r-xl);
  --panel-maxh: calc(
    var(--vh100) - var(--safe-top) - var(--safe-bottom) - var(--topbar-h) - var(--gutter) -
      var(--toolbar-gap) - 62px
  );
  --toolbar-overflow: visible;
  --toolbar-snap: none;
  --toolbar-maxw: calc(100vw - (var(--gutter) * 2) - var(--safe-left) - var(--safe-right));
  --minimap-display: flex;
  --count-display: inline-flex;
  --title-max: 190px;
  --pagename-max: 120px;
  --export-label: inline;
  --help-btn: inline-flex;
  --zoom-top: auto;
  --zoom-bottom: calc(var(--safe-bottom) + var(--toolbar-gap));
  --toast-bottom: calc(var(--safe-bottom) + var(--toolbar-gap) + var(--tool-size) + 26px);
}

@supports (height: 100dvh) {
  :root {
    --vh100: 100dvh;
  }
}

/* -----------------------------------------------------------------------------
   02  Design tokens — light theme
   Canvas bg matches render/renderer.js CANVAS_BG.light (#fbfbfc) so the page and
   the canvas never show a seam. Accent matches render/overlay.js THEME_COLORS.
   -------------------------------------------------------------------------- */

:root,
:root[data-theme='light'] {
  color-scheme: light;

  --canvas-bg: #fbfbfc;
  --surface: #ffffff;
  --surface-float: #ffffff;
  --surface-sunken: #f1f2f5;
  --surface-raised: #ffffff;
  --surface-hover: rgba(15, 17, 26, 0.05);
  --surface-active: rgba(15, 17, 26, 0.09);

  --text: #16181d;
  --text-2: #5a6069;
  --text-3: #8a8f98;

  --border: rgba(15, 17, 26, 0.08);
  --border-strong: rgba(15, 17, 26, 0.14);
  --hairline: rgba(15, 17, 26, 0.06);

  --accent: #3b6ef6;
  --accent-hover: #2f5fe0;
  --accent-soft: rgba(59, 110, 246, 0.12);
  --accent-soft-hover: rgba(59, 110, 246, 0.18);
  --on-accent: #ffffff;

  --danger: #e5484d;
  --danger-hover: #cf3438;
  --danger-soft: rgba(229, 72, 77, 0.12);
  --on-danger: #ffffff;

  --scrim: rgba(18, 20, 26, 0.32);
  --checker: rgba(15, 17, 26, 0.09);
  --swatch-ring: rgba(15, 17, 26, 0.16);
  --thumb: #ffffff;
  --kbd-bg: #ffffff;
  --toast-bg: #1c1e25;
  --toast-text: #f4f5f7;
  --toast-accent: #8aa9ff;
  --selection: rgba(59, 110, 246, 0.22);
  --scrollbar: rgba(15, 17, 26, 0.18);
  --scrollbar-hover: rgba(15, 17, 26, 0.32);

  --shadow-sm: 0 1px 2px rgba(15, 17, 26, 0.07), 0 1px 1px rgba(15, 17, 26, 0.04);
  --shadow-md: 0 1px 2px rgba(15, 17, 26, 0.06), 0 4px 12px rgba(15, 17, 26, 0.08);
  --shadow-lg: 0 1px 2px rgba(15, 17, 26, 0.06), 0 10px 32px rgba(15, 17, 26, 0.14);
  --shadow-inset: inset 0 0 0 1px rgba(15, 17, 26, 0.05);

  /* Document palette mirror — see the note above the .swatch fallback rules.
     `-ink` is PALETTE[key].light.stroke, `-fill` is PALETTE[key].light.solid. */
  --pal-black-ink: #16161a;
  --pal-black-fill: #16161a;
  --pal-grey-ink: #7b8794;
  --pal-grey-fill: #9aa5b1;
  --pal-white-ink: #c6ccd4;
  --pal-white-fill: #ffffff;
  --pal-red-ink: #e03131;
  --pal-red-fill: #f47b7b;
  --pal-orange-ink: #e8590c;
  --pal-orange-fill: #f89b5e;
  --pal-yellow-ink: #c99a09;
  --pal-yellow-fill: #f2cb52;
  --pal-green-ink: #2f9e44;
  --pal-green-fill: #69c47c;
  --pal-teal-ink: #0c8599;
  --pal-teal-fill: #4bb6c6;
  --pal-blue-ink: #1971c2;
  --pal-blue-fill: #6aa8e8;
  --pal-violet-ink: #6741d9;
  --pal-violet-fill: #9d84ec;
  --pal-pink-ink: #c2255c;
  --pal-pink-fill: #ef86ac;
  --pal-brown-ink: #8a6240;
  --pal-brown-fill: #bf9a76;
}

/* -----------------------------------------------------------------------------
   03  Design tokens — dark theme
   Panels sit LIGHTER than the #0e0e11 canvas and are separated by low-alpha
   hairlines rather than heavy borders.
   -------------------------------------------------------------------------- */

:root[data-theme='dark'] {
  color-scheme: dark;

  --canvas-bg: #0e0e11;
  --surface: #1a1b21;
  --surface-float: #1d1e25;
  --surface-sunken: #121319;
  --surface-raised: #2c2e37;
  --surface-hover: rgba(255, 255, 255, 0.06);
  --surface-active: rgba(255, 255, 255, 0.11);

  --text: #eceef2;
  --text-2: #a3a8b3;
  --text-3: #767b85;

  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.15);
  --hairline: rgba(255, 255, 255, 0.06);

  --accent: #5b8bff;
  --accent-hover: #7ba1ff;
  --accent-soft: rgba(91, 139, 255, 0.16);
  --accent-soft-hover: rgba(91, 139, 255, 0.26);
  --on-accent: #0b0b0e;

  --danger: #ff6369;
  --danger-hover: #ff8085;
  --danger-soft: rgba(255, 99, 105, 0.16);
  --on-danger: #1a0a0c;

  --scrim: rgba(4, 4, 7, 0.58);
  --checker: rgba(255, 255, 255, 0.08);
  --swatch-ring: rgba(255, 255, 255, 0.22);
  --thumb: #e9ebf0;
  --kbd-bg: #2c2e37;
  --toast-bg: #2c2e37;
  --toast-text: #f2f3f6;
  --toast-accent: #8fb0ff;
  --selection: rgba(91, 139, 255, 0.3);
  --scrollbar: rgba(255, 255, 255, 0.16);
  --scrollbar-hover: rgba(255, 255, 255, 0.3);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 14px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 36px rgba(0, 0, 0, 0.55);
  --shadow-inset: inset 0 0 0 1px rgba(255, 255, 255, 0.05);

  /* Document palette mirror — PALETTE[key].dark.stroke / .dark.solid. */
  --pal-black-ink: #e6e6e9;
  --pal-black-fill: #e6e6e9;
  --pal-grey-ink: #98a2ae;
  --pal-grey-fill: #7b8794;
  --pal-white-ink: #8b93a0;
  --pal-white-fill: #f4f5f7;
  --pal-red-ink: #ff7070;
  --pal-red-fill: #c74141;
  --pal-orange-ink: #ff9354;
  --pal-orange-fill: #c4652c;
  --pal-yellow-ink: #ecc44a;
  --pal-yellow-fill: #b99326;
  --pal-green-ink: #5fce78;
  --pal-green-fill: #3d8a4c;
  --pal-teal-ink: #4cc3d6;
  --pal-teal-fill: #2e7a89;
  --pal-blue-ink: #69adf5;
  --pal-blue-fill: #3a6fa8;
  --pal-violet-ink: #a48bf5;
  --pal-violet-fill: #6b52b8;
  --pal-pink-ink: #f37ba9;
  --pal-pink-fill: #a83c68;
  --pal-brown-ink: #c39c76;
  --pal-brown-fill: #7d5b3d;
}

/* -----------------------------------------------------------------------------
   04  Reset & document shell
   -------------------------------------------------------------------------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  position: relative;
  margin: 0;
  width: 100%;
  height: var(--vh100);
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--canvas-bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: var(--fs-base);
  font-weight: var(--fw-regular);
  line-height: var(--lh-body);
  font-feature-settings: 'cv05' 1, 'ss01' 1;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  touch-action: manipulation;
}

h1,
h2,
h3,
p,
ul,
figure {
  margin: 0;
}

ul {
  padding: 0;
  list-style: none;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
  margin: 0;
}

svg {
  display: block;
  flex: none;
}

/* Default class written by ui/icons.js onto every generated <svg>. */
.icn {
  color: inherit;
}

/* The app root fills the viewport and deliberately keeps `z-index: auto` so
   body-level popovers and in-layer tooltips share one stacking context. */
.app {
  position: absolute;
  inset: 0;
  overflow: hidden;
  isolation: auto;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* -----------------------------------------------------------------------------
   05  Canvas stack
   -------------------------------------------------------------------------- */

.canvas-stack {
  position: absolute;
  inset: 0;
  z-index: var(--z-canvas);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  cursor: default;
  background: var(--canvas-bg);
}

.canvas-layer {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.scene-canvas {
  z-index: 0;
}

.overlay-canvas {
  z-index: 1;
  pointer-events: none;
}

.html-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  overflow: hidden;
  pointer-events: none;
}

/* -----------------------------------------------------------------------------
   06  UI layer & shared primitives
   -------------------------------------------------------------------------- */

.ui-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.topbar,
.style-panel,
.toolbar,
.zoom-controls,
.minimap,
.toasts,
.tooltip,
.modal-backdrop {
  pointer-events: auto;
}

/* Buttons -------------------------------------------------------------------*/

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  flex: none;
  height: var(--ctl-h);
  padding: 0 10px;
  border: 0;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--text-2);
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition:
    background-color var(--t-fast) var(--ease),
    color var(--t-fast) var(--ease),
    box-shadow var(--t-fast) var(--ease),
    opacity var(--t-fast) var(--ease);
}

.btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.btn:active {
  background: var(--surface-active);
}

.btn:disabled {
  opacity: 0.38;
  cursor: default;
  background: transparent;
  color: var(--text-2);
}

.icon-btn {
  width: var(--ctl-h);
  padding: 0;
}

.primary-btn {
  padding: 0 12px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: var(--fw-semibold);
  box-shadow: var(--shadow-sm);
}

.primary-btn:hover {
  background: var(--accent-hover);
  color: var(--on-accent);
}

.primary-btn:active {
  background: var(--accent-hover);
}

.ghost-btn {
  padding: 0 12px;
  background: var(--surface-sunken);
  color: var(--text);
}

.ghost-btn:hover {
  background: var(--surface-active);
  color: var(--text);
}

.danger-btn {
  padding: 0 12px;
  background: var(--danger);
  color: var(--on-danger);
  font-weight: var(--fw-semibold);
  box-shadow: var(--shadow-sm);
}

.danger-btn:hover {
  background: var(--danger-hover);
  color: var(--on-danger);
}

.mini-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: var(--mini-h);
  height: var(--mini-h);
  padding: 0;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition:
    background-color var(--t-fast) var(--ease),
    color var(--t-fast) var(--ease),
    opacity var(--t-fast) var(--ease);
}

.mini-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.mini-btn:active {
  background: var(--surface-active);
}

.mini-btn:disabled {
  opacity: 0.3;
  cursor: default;
  background: transparent;
}

.mini-btn.danger:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

/* Fields --------------------------------------------------------------------*/

.field {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  min-width: 0;
}

.field-label {
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  line-height: 1.2;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-3);
}

.field-value {
  flex: none;
  min-width: 42px;
  text-align: right;
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  font-variant-numeric: tabular-nums;
  color: var(--text-2);
}

/* Segmented control ---------------------------------------------------------*/

.segmented {
  display: flex;
  align-items: stretch;
  gap: var(--sp-1);
  padding: 2px;
  border-radius: var(--r-md);
  background: var(--surface-sunken);
  box-shadow: var(--shadow-inset);
}

.seg {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 1 1 0;
  min-width: 0;
  height: var(--seg-h);
  padding: 0 var(--sp-3);
  border: 0;
  border-radius: calc(var(--r-md) - 3px);
  background: transparent;
  color: var(--text-2);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  line-height: 1;
  cursor: pointer;
  transition:
    background-color var(--t-fast) var(--ease),
    color var(--t-fast) var(--ease),
    box-shadow var(--t-fast) var(--ease);
}

.seg:hover {
  color: var(--text);
}

.seg.is-active {
  background: var(--surface-raised);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.seg:disabled {
  opacity: 0.38;
  cursor: default;
}

/* Slider --------------------------------------------------------------------*/

.slider {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  height: 20px;
  margin: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.slider:focus-visible {
  outline: none;
}

.slider::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: var(--r-pill);
  background: var(--surface-sunken);
  box-shadow: inset 0 0 0 1px var(--border-strong);
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 15px;
  height: 15px;
  margin-top: -5.5px;
  border: 0;
  border-radius: 50%;
  background: var(--thumb);
  box-shadow:
    0 0 0 1px var(--border-strong),
    var(--shadow-sm);
  transition: box-shadow var(--t-fast) var(--ease);
}

.slider:focus-visible::-webkit-slider-thumb {
  box-shadow:
    0 0 0 1px var(--accent),
    0 0 0 4px var(--accent-soft);
}

.slider::-moz-range-track {
  height: 4px;
  border-radius: var(--r-pill);
  background: var(--surface-sunken);
  box-shadow: inset 0 0 0 1px var(--border-strong);
}

.slider::-moz-range-thumb {
  width: 15px;
  height: 15px;
  border: 0;
  border-radius: 50%;
  background: var(--thumb);
  box-shadow:
    0 0 0 1px var(--border-strong),
    var(--shadow-sm);
  transition: box-shadow var(--t-fast) var(--ease);
}

.slider:focus-visible::-moz-range-thumb {
  box-shadow:
    0 0 0 1px var(--accent),
    0 0 0 4px var(--accent-soft);
}

/* Select --------------------------------------------------------------------*/

.select {
  height: var(--ctl-h);
  width: 100%;
  padding: 0 28px 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background-color: var(--surface-sunken);
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-3) 50%),
    linear-gradient(135deg, var(--text-3) 50%, transparent 50%);
  background-position:
    right 14px center,
    right 9px center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  color: var(--text);
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color var(--t-fast) var(--ease);
}

.select:hover {
  border-color: var(--accent);
}

/* -----------------------------------------------------------------------------
   07  Popovers & menus
   `.popover` is appended to document.body (ui/menu.js), so it is styled
   globally and positioned with fixed coordinates written inline by the JS.
   -------------------------------------------------------------------------- */

.popover {
  position: fixed;
  left: 0;
  top: 0;
  z-index: var(--z-popover);
  min-width: 196px;
  max-width: min(340px, calc(100vw - 16px));
  max-height: min(calc(var(--vh100) - 32px), 620px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--sp-2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface-float);
  box-shadow: var(--shadow-lg);
  color: var(--text);
  font-size: var(--fs-base);
}

.popover.is-open {
  animation: popover-in var(--t-fast) var(--ease-out) both;
}

@keyframes popover-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.submenu {
  min-width: 176px;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  width: 100%;
  min-height: var(--row-h);
  padding: 0 var(--sp-4) 0 var(--sp-3);
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text);
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
  line-height: 1.2;
  text-align: left;
  cursor: pointer;
  transition:
    background-color var(--t-fast) var(--ease),
    color var(--t-fast) var(--ease);
}

.menu-item:hover {
  background: var(--surface-hover);
}

.menu-item:active {
  background: var(--surface-active);
}

.menu-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: var(--icon-gutter);
  height: var(--icon-gutter);
  color: var(--text-2);
}

.menu-text {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu-hint {
  flex: none;
  margin-left: auto;
  padding-left: var(--sp-5);
  color: var(--text-3);
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.menu-chevron {
  display: inline-flex;
  align-items: center;
  flex: none;
  margin-left: auto;
  color: var(--text-3);
}

.menu-hint + .menu-chevron {
  margin-left: var(--sp-2);
}

.menu-sep {
  height: 1px;
  margin: var(--sp-2) var(--sp-3);
  background: var(--hairline);
}

.menu-label {
  padding: var(--sp-3) var(--sp-3) var(--sp-2);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-3);
}

.menu-item.is-disabled,
.menu-item:disabled {
  opacity: 0.38;
  cursor: default;
  background: transparent;
}

.menu-item.is-danger {
  color: var(--danger);
}

.menu-item.is-danger .menu-icon {
  color: var(--danger);
}

.menu-item.is-danger:hover {
  background: var(--danger-soft);
}

.menu-item.is-checked {
  color: var(--text);
}

.menu-item.is-checked .menu-icon {
  color: var(--accent);
}

.context-menu {
  min-width: 216px;
}

/* -----------------------------------------------------------------------------
   08  Top bar
   The strip itself never intercepts pointer events — only its two floating
   pill groups do — so the canvas stays clickable in the gap between them.
   -------------------------------------------------------------------------- */

.topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: var(--z-chrome);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-5);
  padding:
    calc(var(--safe-top) + var(--gutter))
    calc(var(--safe-right) + var(--gutter))
    0
    calc(var(--safe-left) + var(--gutter));
  pointer-events: none;
}

.topbar-group {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  min-width: 0;
  padding: var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  background: var(--surface-float);
  box-shadow: var(--shadow-md);
  pointer-events: auto;
}

/* The left group absorbs the remaining width and lets its children shrink; the
   right group is the fixed-size anchor, so the two can never collide. */
.topbar-group.left {
  flex: 1 1 auto;
}

.topbar-group.right {
  flex: 0 0 auto;
  gap: var(--sp-1);
}

.topbar-group.right .icon-btn[aria-label='Keyboard shortcuts'] {
  display: var(--help-btn);
}

.topbar .primary-btn span {
  display: var(--export-label);
}

.topbar-divider {
  flex: none;
  width: 1px;
  height: 20px;
  margin: 0 var(--sp-2);
  background: var(--border);
}

.menu-btn {
  width: var(--ctl-h);
  padding: 0;
  color: var(--text);
}

.doc-title {
  flex: 1 1 auto;
  min-width: 0;
  width: var(--title-max);
  max-width: var(--title-max);
  height: var(--ctl-h);
  padding: 0 var(--sp-4);
  border: 1px solid transparent;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--text);
  font-size: var(--fs-base);
  font-weight: var(--fw-semibold);
  text-overflow: ellipsis;
  transition:
    background-color var(--t-fast) var(--ease),
    border-color var(--t-fast) var(--ease);
}

.doc-title:hover {
  background: var(--surface-hover);
}

.doc-title:focus {
  outline: none;
  background: var(--surface-sunken);
  border-color: var(--accent);
}

.page-btn {
  flex: 0 1 auto;
  gap: var(--sp-3);
  min-width: 0;
  padding: 0 var(--sp-3) 0 var(--sp-4);
  color: var(--text-2);
}

.page-btn-name {
  min-width: 0;
  overflow: hidden;
  max-width: var(--pagename-max);
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: var(--fw-medium);
}

.page-btn-count {
  display: var(--count-display);
  align-items: center;
  justify-content: center;
  flex: none;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--r-pill);
  background: var(--surface-sunken);
  color: var(--text-3);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  font-variant-numeric: tabular-nums;
}

.page-btn-count:empty {
  display: none;
}

.chev {
  display: inline-flex;
  align-items: center;
  flex: none;
  color: var(--text-3);
}

/* Menus anchored to the top bar --------------------------------------------*/

.main-menu {
  min-width: 254px;
}

.page-menu {
  min-width: 268px;
}

.export-menu {
  min-width: 250px;
}

.page-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: var(--row-h);
  padding: 0 var(--sp-2) 0 0;
  border-radius: var(--r-sm);
  transition: background-color var(--t-fast) var(--ease);
}

.page-row:hover {
  background: var(--surface-hover);
}

.page-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: var(--icon-gutter);
  height: var(--icon-gutter);
  margin-left: var(--sp-3);
  color: var(--accent);
}

.page-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  height: var(--row-h);
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text-2);
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.page-name.is-active {
  color: var(--text);
  font-weight: var(--fw-semibold);
}

.page-actions {
  display: flex;
  align-items: center;
  gap: 1px;
  flex: none;
  opacity: 0;
  transition: opacity var(--t-fast) var(--ease);
}

.page-row:hover .page-actions,
.page-row:focus-within .page-actions {
  opacity: 1;
}

.page-rename {
  flex: 1 1 auto;
  min-width: 0;
  height: calc(var(--row-h) - 4px);
  padding: 0 var(--sp-3);
  border: 1px solid var(--accent);
  border-radius: var(--r-sm);
  background: var(--surface-sunken);
  color: var(--text);
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
}

.page-rename:focus {
  outline: none;
}

/* -----------------------------------------------------------------------------
   09  Style panel
   -------------------------------------------------------------------------- */

.style-panel {
  position: absolute;
  z-index: var(--z-chrome);
  top: var(--panel-top);
  left: var(--panel-left);
  right: var(--panel-right);
  bottom: var(--panel-bottom);
  width: var(--panel-w);
  max-height: var(--panel-maxh);
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--border);
  border-radius: var(--panel-radius);
  background: var(--surface-float);
  box-shadow: var(--shadow-lg);
}

.style-panel.is-hidden {
  display: none;
}

.style-body {
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
  padding: var(--sp-5);
}

.style-section {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  min-width: 0;
}

.style-section + .style-section {
  padding-top: var(--sp-5);
  border-top: 1px solid var(--hairline);
}

.style-title {
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  line-height: 1.2;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-3);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  min-width: 0;
}

.row {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  min-width: 0;
}

/* Swatches ------------------------------------------------------------------*/

.swatch-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: var(--sp-3);
}

.swatch-grid.compact {
  gap: var(--sp-2);
}

.swatch {
  width: 100%;
  height: var(--swatch-size);
  padding: 0;
  border: 0;
  border-radius: var(--r-sm);
  background: var(--swatch, var(--surface-sunken));
  box-shadow: inset 0 0 0 1px var(--swatch-ring);
  cursor: pointer;
  transition:
    transform var(--t-fast) var(--ease),
    box-shadow var(--t-fast) var(--ease);
}

.swatch:hover {
  transform: translateY(-1px);
}

.swatch.is-active {
  box-shadow:
    inset 0 0 0 1px var(--swatch-ring),
    0 0 0 2px var(--surface-float),
    0 0 0 4px var(--accent);
}

.swatch-grid.compact .swatch {
  height: var(--swatch-size-compact);
  border-radius: var(--r-xs);
}

/* Palette fallback.
   ui/stylepanel.js asks for `style: { '--swatch': … }`, but ui/dom.js applies
   style objects with `Object.assign(el.style, …)`, which silently drops custom
   properties — so `--swatch` never reaches the element and every swatch would
   render empty. These rules seed `--swatch` from the accessible name the JS
   does emit ('blue' for stroke swatches, 'fill blue' for fill swatches), using
   a mirror of core/style.js PALETTE held in the theme token blocks. An inline
   `--swatch` still wins, so this becomes inert the moment the JS is fixed.
   Note-colour swatches share the plain aria-labels and therefore show the
   stroke shade of the same key. */
.swatch[aria-label='black'] {
  --swatch: var(--pal-black-ink);
}
.swatch[aria-label='grey'] {
  --swatch: var(--pal-grey-ink);
}
.swatch[aria-label='white'] {
  --swatch: var(--pal-white-fill);
}
.swatch[aria-label='red'] {
  --swatch: var(--pal-red-ink);
}
.swatch[aria-label='orange'] {
  --swatch: var(--pal-orange-ink);
}
.swatch[aria-label='yellow'] {
  --swatch: var(--pal-yellow-ink);
}
.swatch[aria-label='green'] {
  --swatch: var(--pal-green-ink);
}
.swatch[aria-label='teal'] {
  --swatch: var(--pal-teal-ink);
}
.swatch[aria-label='blue'] {
  --swatch: var(--pal-blue-ink);
}
.swatch[aria-label='violet'] {
  --swatch: var(--pal-violet-ink);
}
.swatch[aria-label='pink'] {
  --swatch: var(--pal-pink-ink);
}
.swatch[aria-label='brown'] {
  --swatch: var(--pal-brown-ink);
}
.swatch[aria-label='fill black'] {
  --swatch: var(--pal-black-fill);
}
.swatch[aria-label='fill grey'] {
  --swatch: var(--pal-grey-fill);
}
.swatch[aria-label='fill white'] {
  --swatch: var(--pal-white-fill);
}
.swatch[aria-label='fill red'] {
  --swatch: var(--pal-red-fill);
}
.swatch[aria-label='fill orange'] {
  --swatch: var(--pal-orange-fill);
}
.swatch[aria-label='fill yellow'] {
  --swatch: var(--pal-yellow-fill);
}
.swatch[aria-label='fill green'] {
  --swatch: var(--pal-green-fill);
}
.swatch[aria-label='fill teal'] {
  --swatch: var(--pal-teal-fill);
}
.swatch[aria-label='fill blue'] {
  --swatch: var(--pal-blue-fill);
}
.swatch[aria-label='fill violet'] {
  --swatch: var(--pal-violet-fill);
}
.swatch[aria-label='fill pink'] {
  --swatch: var(--pal-pink-fill);
}
.swatch[aria-label='fill brown'] {
  --swatch: var(--pal-brown-fill);
}

/* Fill / font / stroke segmented variants ----------------------------------*/

.fill-styles .seg,
.font-seg .seg {
  padding: 0 var(--sp-2);
}

.font-seg .seg {
  font-size: var(--fs-base);
  font-weight: var(--fw-regular);
}

/* Arrowheads ----------------------------------------------------------------*/

.heads {
  gap: var(--sp-3);
}

.head-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  flex: 1 1 0;
  min-width: 0;
  height: var(--seg-h);
  padding: 0 var(--sp-2);
  border: 0;
  border-radius: var(--r-md);
  background: var(--surface-sunken);
  box-shadow: var(--shadow-inset);
  color: var(--text-2);
  cursor: pointer;
  transition:
    background-color var(--t-fast) var(--ease),
    color var(--t-fast) var(--ease);
}

.head-btn:hover {
  color: var(--text);
  background: var(--surface-active);
}

.head-menu {
  min-width: 0;
  padding: var(--sp-3);
}

.head-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--sp-2);
}

.head-opt {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition:
    background-color var(--t-fast) var(--ease),
    color var(--t-fast) var(--ease);
}

.head-opt:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.head-opt.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

/* Arrange actions -----------------------------------------------------------*/

.style-section.actions {
  gap: var(--sp-4);
}

.btn-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--sp-2);
}

.btn-row .mini-btn {
  width: 100%;
  background: var(--surface-sunken);
}

.btn-row .mini-btn:hover {
  background: var(--surface-active);
}

.btn-row .mini-btn:disabled {
  background: var(--surface-sunken);
}

/* -----------------------------------------------------------------------------
   10  Toolbar
   -------------------------------------------------------------------------- */

.toolbar {
  position: absolute;
  z-index: var(--z-chrome);
  left: 50%;
  bottom: calc(var(--safe-bottom) + var(--toolbar-gap));
  transform: translateX(-50%);
  max-width: var(--toolbar-maxw);
  padding: var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  background: var(--surface-float);
  box-shadow: var(--shadow-lg);
}

.toolbar-inner {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  overflow-x: var(--toolbar-overflow);
  scroll-snap-type: var(--toolbar-snap);
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.toolbar-inner::-webkit-scrollbar {
  display: none;
}

.toolbar-divider {
  flex: none;
  width: 1px;
  height: 22px;
  margin: 0 var(--sp-2);
  background: var(--border);
}

.tool-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: var(--tool-size);
  height: var(--tool-size);
  padding: 0;
  border: 0;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  scroll-snap-align: center;
  transition:
    background-color var(--t-fast) var(--ease),
    color var(--t-fast) var(--ease),
    transform var(--t-fast) var(--ease);
}

.tool-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
  transform: translateY(-1px);
}

.tool-btn:active {
  transform: translateY(0);
  background: var(--surface-active);
}

.tool-btn.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  transform: none;
}

.tool-btn.is-active:hover {
  background: var(--accent-soft-hover);
  color: var(--accent);
}

.has-flyout {
  overflow: hidden;
}

.flyout-dot {
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 5px;
  height: 5px;
  background: currentColor;
  opacity: 0.42;
  clip-path: polygon(100% 0, 100% 100%, 0 100%);
  pointer-events: none;
}

.lock-btn {
  color: var(--text-3);
}

/* Shape flyout --------------------------------------------------------------*/

.shape-flyout {
  min-width: 0;
  padding: var(--sp-3);
}

.shape-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--sp-2);
}

.shape-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition:
    background-color var(--t-fast) var(--ease),
    color var(--t-fast) var(--ease);
}

.shape-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.shape-btn.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

/* -----------------------------------------------------------------------------
   11  Navigator — zoom controls & minimap
   -------------------------------------------------------------------------- */

.zoom-controls {
  position: absolute;
  z-index: var(--z-chrome);
  left: calc(var(--safe-left) + var(--gutter));
  top: var(--zoom-top);
  bottom: var(--zoom-bottom);
  display: flex;
  align-items: center;
  gap: 1px;
  padding: var(--sp-2);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  background: var(--surface-float);
  box-shadow: var(--shadow-md);
}

.zoom-label {
  min-width: 54px;
  height: var(--ctl-h);
  padding: 0 var(--sp-3);
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-2);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  font-variant-numeric: tabular-nums;
  text-align: center;
  cursor: pointer;
  transition:
    background-color var(--t-fast) var(--ease),
    color var(--t-fast) var(--ease);
}

.zoom-label:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.zoom-menu {
  min-width: 216px;
}

.minimap {
  position: absolute;
  z-index: var(--z-chrome);
  right: calc(var(--safe-right) + var(--gutter));
  bottom: calc(var(--safe-bottom) + var(--toolbar-gap));
  display: var(--minimap-display);
  flex-direction: column;
  padding: var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  background: var(--surface-float);
  box-shadow: var(--shadow-lg);
}

.minimap-canvas {
  display: block;
  border-radius: var(--r-md);
  background: var(--surface-sunken);
  box-shadow: var(--shadow-inset);
  cursor: crosshair;
  touch-action: none;
}

.minimap-toggle {
  position: absolute;
  top: 12px;
  right: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-float);
  color: var(--text-2);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition:
    background-color var(--t-fast) var(--ease),
    color var(--t-fast) var(--ease);
}

.minimap-toggle:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.minimap.is-collapsed {
  padding: var(--sp-2);
  border-radius: var(--r-md);
}

.minimap.is-collapsed .minimap-canvas {
  display: none;
}

.minimap.is-collapsed .minimap-toggle {
  position: static;
  border-color: transparent;
  background: transparent;
  box-shadow: none;
}

/* -----------------------------------------------------------------------------
   12  Toasts & tooltips
   -------------------------------------------------------------------------- */

.toasts {
  position: absolute;
  z-index: var(--z-toast);
  left: 50%;
  bottom: var(--toast-bottom);
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-4);
  width: max-content;
  max-width: calc(100vw - 32px);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  max-width: 440px;
  min-height: 38px;
  padding: var(--sp-3) var(--sp-5);
  border-radius: var(--r-lg);
  background: var(--toast-bg);
  color: var(--toast-text);
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
  line-height: 1.35;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  pointer-events: auto;
  opacity: 0;
  transform: translateY(10px) scale(0.97);
  transition:
    opacity var(--t-med) var(--ease-out),
    transform var(--t-med) var(--ease-out);
}

.toast.is-in {
  opacity: 1;
  transform: none;
}

.toast.is-out {
  opacity: 0;
  transform: translateY(6px) scale(0.97);
}

.toast.is-error {
  background: var(--danger);
  color: var(--on-danger);
}

.toast-icon {
  display: inline-flex;
  align-items: center;
  flex: none;
  opacity: 0.85;
}

.toast-text {
  flex: 1 1 auto;
  min-width: 0;
}

.toast-action {
  flex: none;
  margin-left: var(--sp-2);
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--toast-accent);
  font-size: var(--fs-base);
  font-weight: var(--fw-semibold);
  cursor: pointer;
}

.toast-action:hover {
  text-decoration: underline;
}

.toast.is-error .toast-action {
  color: var(--on-danger);
}

/* Tooltip — ui/feedback.js writes `transform: translate(x, y)` inline, so the
   entrance animates `opacity` + the independent `scale` property instead. */
.tooltip {
  position: fixed;
  left: 0;
  top: 0;
  z-index: var(--z-tooltip);
  max-width: 260px;
  padding: 5px var(--sp-4);
  border-radius: var(--r-sm);
  background: var(--toast-bg);
  color: var(--toast-text);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  line-height: 1.4;
  white-space: nowrap;
  box-shadow: var(--shadow-md);
  pointer-events: none;
  opacity: 0;
  scale: 0.96;
  transform-origin: 50% 50%;
  transition:
    opacity var(--t-fast) var(--ease-out),
    scale var(--t-fast) var(--ease-out);
}

/* The JS flips `display` in the same task as the class, so an animation (rather
   than a transition alone) is what actually plays on first reveal. */
.tooltip.is-in {
  opacity: 1;
  scale: 1;
  animation: tooltip-in var(--t-fast) var(--ease-out) both;
}

@keyframes tooltip-in {
  from {
    opacity: 0;
    scale: 0.96;
  }
  to {
    opacity: 1;
    scale: 1;
  }
}

/* -----------------------------------------------------------------------------
   13  Modals & dialog content
   -------------------------------------------------------------------------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-top) + var(--sp-6)) calc(var(--safe-right) + var(--sp-6))
    calc(var(--safe-bottom) + var(--sp-6)) calc(var(--safe-left) + var(--sp-6));
  background: var(--scrim);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity var(--t-med) var(--ease-out);
}

.modal-backdrop.is-open {
  opacity: 1;
}

.modal {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 480px;
  max-height: calc(var(--vh100) * 0.86);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(8px) scale(0.985);
  transition:
    opacity var(--t-med) var(--ease-out),
    transform var(--t-med) var(--ease-out);
}

.modal.is-wide {
  max-width: 860px;
}

.modal-backdrop.is-open .modal {
  opacity: 1;
  transform: none;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-5);
  flex: none;
  padding: var(--sp-5) var(--sp-5) var(--sp-4) var(--sp-6);
}

.modal-title {
  font-size: 15px;
  font-weight: var(--fw-semibold);
  line-height: 1.3;
  color: var(--text);
}

.modal-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 var(--sp-6) var(--sp-6);
  color: var(--text-2);
}

.modal-foot {
  flex: none;
  padding: var(--sp-5) var(--sp-6);
  border-top: 1px solid var(--hairline);
}

.modal-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--sp-4);
}

.confirm-text {
  font-size: var(--fs-base);
  line-height: var(--lh-body);
  color: var(--text-2);
}

/* Export sheet --------------------------------------------------------------*/

.export-layout {
  display: grid;
  grid-template-columns: minmax(0, 292px) minmax(0, 1fr);
  gap: var(--sp-7);
  align-items: start;
}

.export-left {
  min-width: 0;
}

.export-body {
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
  min-width: 0;
}

.export-field {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  min-width: 0;
}

.export-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 240px;
  padding: var(--sp-5);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background-color: var(--surface-sunken);
  background-image: conic-gradient(
    var(--checker) 0 25%,
    transparent 0 50%,
    var(--checker) 0 75%,
    transparent 0
  );
  background-size: 16px 16px;
  overflow: hidden;
}

.preview-canvas {
  display: block;
  max-width: 100%;
  max-height: 420px;
  height: auto;
  object-fit: contain;
  border-radius: var(--r-xs);
  box-shadow: var(--shadow-md);
}

.export-info {
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
  color: var(--text-3);
}

.export-json {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 96px;
  height: 96px;
  border-radius: var(--r-lg);
  background: var(--surface);
  color: var(--text-3);
  box-shadow: var(--shadow-sm);
}

/* Keyboard reference --------------------------------------------------------*/

.shortcut-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(248px, 1fr));
  gap: var(--sp-7);
  align-items: start;
}

.shortcut-group {
  min-width: 0;
}

.shortcut-group h3 {
  margin-bottom: var(--sp-3);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-3);
}

.shortcut-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-5);
  min-height: 28px;
  padding: var(--sp-1) 0;
  border-bottom: 1px solid var(--hairline);
}

.shortcut-row:last-child {
  border-bottom: 0;
}

.shortcut-label {
  min-width: 0;
  overflow: hidden;
  font-size: var(--fs-base);
  color: var(--text-2);
  text-overflow: ellipsis;
}

.shortcut-keys {
  display: flex;
  align-items: center;
  gap: 3px;
  flex: none;
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-xs);
  background: var(--kbd-bg);
  color: var(--text-2);
  font-family: var(--font-ui);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  line-height: 1;
  box-shadow: 0 1px 0 var(--border-strong);
}

/* About ---------------------------------------------------------------------*/

.about {
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
  font-size: var(--fs-base);
  line-height: var(--lh-body);
  color: var(--text-2);
}

.about-list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.about-list li {
  position: relative;
  padding-left: var(--sp-6);
}

.about-list li::before {
  content: '';
  position: absolute;
  left: 3px;
  top: 0.65em;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
}

.about-credit {
  color: var(--text-3);
  font-size: var(--fs-sm);
}

/* -----------------------------------------------------------------------------
   14  On-canvas text editor
   ui/texteditor.js owns width, height, padding, font, line-height, colour,
   text-align, white-space and the transforms — this block must not fight them.
   -------------------------------------------------------------------------- */

.text-edit-wrap {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  pointer-events: auto;
}

.text-edit {
  display: block;
  margin: 0;
  border: 0;
  outline: none;
  background: transparent;
  resize: none;
  overflow: hidden;
  box-sizing: border-box;
  caret-color: currentColor;
  -webkit-appearance: none;
  appearance: none;
  -webkit-tap-highlight-color: transparent;
}

.text-edit:focus,
.text-edit:focus-visible {
  outline: none;
}

.text-edit::selection {
  background: var(--selection);
}

/* -----------------------------------------------------------------------------
   15  Boot, noscript, fatal, drop target, capture
   -------------------------------------------------------------------------- */

.boot {
  position: fixed;
  inset: 0;
  z-index: var(--z-boot);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-6);
  background: var(--canvas-bg);
  color: var(--text-3);
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
  opacity: 1;
  transition:
    opacity var(--t-slow) var(--ease-out),
    visibility var(--t-slow) var(--ease-out);
}

body:not(.is-loading) .boot {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.boot-mark {
  width: 26px;
  height: 26px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: var(--r-md);
  animation: boot-spin var(--t-spin) linear infinite;
}

@keyframes boot-spin {
  to {
    transform: rotate(360deg);
  }
}

.noscript,
.fatal {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-5);
  padding: var(--sp-8);
  text-align: center;
  background: var(--canvas-bg);
  color: var(--text-2);
}

.noscript h1,
.fatal h1 {
  font-size: 19px;
  font-weight: var(--fw-semibold);
  color: var(--text);
}

.noscript p {
  max-width: 46ch;
  font-size: var(--fs-base);
  line-height: var(--lh-body);
}

.fatal pre {
  max-width: min(760px, 100%);
  max-height: 40vh;
  margin: 0;
  overflow: auto;
  padding: var(--sp-5);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface-sunken);
  color: var(--text-3);
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: var(--fs-sm);
  line-height: 1.6;
  text-align: left;
  white-space: pre-wrap;
}

/* Drag-and-drop target ------------------------------------------------------*/

.app.is-dropping::after {
  content: '';
  position: absolute;
  inset: var(--sp-4);
  z-index: var(--z-chrome);
  border: 2px dashed var(--accent);
  border-radius: var(--r-xl);
  background: var(--accent-soft);
  pointer-events: none;
}

/* Pointer capture — keep one cursor for the whole drag ----------------------*/

.app.is-capturing {
  user-select: none;
  -webkit-user-select: none;
}

.app.is-capturing * {
  cursor: inherit;
}

/* -----------------------------------------------------------------------------
   16  Scrollbars, selection, focus
   -------------------------------------------------------------------------- */

::selection {
  background: var(--selection);
  color: var(--text);
}

.style-panel,
.popover,
.modal-body,
.export-left {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar) transparent;
}

.style-panel::-webkit-scrollbar,
.popover::-webkit-scrollbar,
.modal-body::-webkit-scrollbar,
.export-left::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.style-panel::-webkit-scrollbar-track,
.popover::-webkit-scrollbar-track,
.modal-body::-webkit-scrollbar-track,
.export-left::-webkit-scrollbar-track {
  background: transparent;
}

.style-panel::-webkit-scrollbar-thumb,
.popover::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb,
.export-left::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: var(--r-pill);
  background-clip: content-box;
  background-color: var(--scrollbar);
}

.style-panel::-webkit-scrollbar-thumb:hover,
.popover::-webkit-scrollbar-thumb:hover,
.modal-body::-webkit-scrollbar-thumb:hover,
.export-left::-webkit-scrollbar-thumb:hover {
  background-color: var(--scrollbar-hover);
}

/* Focus rings — never removed without a replacement -------------------------*/

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.swatch:focus-visible {
  outline-offset: 3px;
}

.doc-title:focus-visible,
.page-rename:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* -----------------------------------------------------------------------------
   17  Responsive
   Breakpoints: 760px (compact chrome — mirrors the `.app.is-narrow` class that
   main.js toggles), 720px (export dialog columns), and `pointer: coarse`.
   Compact layout is expressed entirely through the layout-switch tokens from
   section 01, so the two 760px rules only re-declare custom properties.
   -------------------------------------------------------------------------- */

.app.is-narrow {
  --tool-size: 44px;
  --gutter: 8px;
  --title-max: 132px;
  --pagename-max: 56px;
  --count-display: none;
  --minimap-display: none;
  --export-label: none;
  --help-btn: none;
  --panel-w: auto;
  --panel-top: auto;
  --panel-left: 0px;
  --panel-right: 0px;
  --panel-bottom: calc(var(--safe-bottom) + var(--toolbar-gap) + var(--tool-size) + 22px);
  --panel-radius: var(--r-xl) var(--r-xl) 0 0;
  --panel-maxh: calc(var(--vh100) * 0.42);
  --toolbar-overflow: auto;
  --toolbar-snap: x proximity;
  --toolbar-maxw: calc(100vw - 12px - var(--safe-left) - var(--safe-right));
  --zoom-top: var(--chrome-top);
  --zoom-bottom: auto;
}

@media (max-width: 760px) {
  .app {
    --tool-size: 44px;
    --gutter: 8px;
    --title-max: 132px;
    --pagename-max: 56px;
    --count-display: none;
    --minimap-display: none;
    --export-label: none;
    --help-btn: none;
    --panel-w: auto;
    --panel-top: auto;
    --panel-left: 0px;
    --panel-right: 0px;
    --panel-bottom: calc(var(--safe-bottom) + var(--toolbar-gap) + var(--tool-size) + 22px);
    --panel-radius: var(--r-xl) var(--r-xl) 0 0;
    --panel-maxh: calc(var(--vh100) * 0.42);
    --toolbar-overflow: auto;
    --toolbar-snap: x proximity;
    --toolbar-maxw: calc(100vw - 12px - var(--safe-left) - var(--safe-right));
    --zoom-top: var(--chrome-top);
    --zoom-bottom: auto;
  }

  .style-panel {
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
  }

  .topbar-group {
    padding: var(--sp-2);
  }

  .toolbar {
    padding: var(--sp-3) var(--sp-2);
  }
}

.app.is-narrow .style-panel {
  border-left: 0;
  border-right: 0;
  border-bottom: 0;
}

.app.is-narrow .topbar-group {
  padding: var(--sp-2);
}

.app.is-narrow .toolbar {
  padding: var(--sp-3) var(--sp-2);
}

/* Phone widths — the page name collapses to nothing visible but stays in the
   accessibility tree (clipped, not hidden), so the document title keeps room
   while the pages button still announces itself. -----------------------------*/

@media (max-width: 480px) {
  .app,
  .app.is-narrow {
    --title-max: 120px;
    --pagename-max: 0px;
  }

  .page-btn {
    padding: 0 var(--sp-3);
  }
}

/* Short viewports — keep the style panel from swallowing the canvas ---------*/

.app.is-short {
  --gutter: 6px;
  --toolbar-gap: 8px;
}

@media (max-height: 560px) {
  .app {
    --gutter: 6px;
    --toolbar-gap: 8px;
  }
}

/* Export dialog collapses to a single column --------------------------------*/

@media (max-width: 720px) {
  .export-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--sp-5);
  }

  .export-preview {
    min-height: 180px;
  }

  .shortcut-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--sp-5);
  }
}

/* Coarse pointers — every target reaches at least 40px ----------------------*/

@media (pointer: coarse) {
  body {
    --ctl-h: 40px;
    --mini-h: 34px;
    --seg-h: 36px;
    --row-h: 40px;
    --tool-size: 44px;
    --swatch-size: 26px;
    --swatch-size-compact: 22px;
  }

  .head-opt {
    width: 48px;
    height: 40px;
  }

  .shape-btn {
    width: 44px;
    height: 44px;
  }

  .minimap-toggle {
    width: 34px;
    height: 34px;
  }

  .page-actions {
    opacity: 1;
  }

  .tool-btn:hover,
  .swatch:hover {
    transform: none;
  }
}

/* -----------------------------------------------------------------------------
   18  Reduced motion & print
   Every duration in this file resolves from a token, so collapsing the motion
   tokens is enough — no `!important` overrides needed.
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  :root {
    --t-fast: 1ms;
    --t-med: 1ms;
    --t-slow: 1ms;
  }

  .boot-mark {
    animation: none;
  }

  .popover.is-open,
  .tooltip.is-in {
    animation: none;
    opacity: 1;
  }

  .tool-btn:hover,
  .swatch:hover {
    transform: none;
  }

  html {
    scroll-behavior: auto;
  }
}

@media print {
  .ui-layer,
  .canvas-stack,
  .boot,
  .popover,
  .tooltip {
    display: none;
  }

  body {
    background: transparent;
  }
}

/* -----------------------------------------------------------------------------
   17  Prompt dialog
   Single-field dialog used for renaming a frame. Matches .select metrics so the
   modal's controls line up with the export sheet's.
   -------------------------------------------------------------------------- */

.prompt-body {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.text-input {
  height: var(--ctl-h);
  width: 100%;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--surface-sunken);
  color: var(--text);
  font: inherit;
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
  transition:
    border-color var(--t-fast) var(--ease),
    box-shadow var(--t-fast) var(--ease);
}

.text-input::placeholder {
  color: var(--text-3);
}

.text-input:hover {
  border-color: var(--accent);
}

.text-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
