/* xtt — UI shell styles. Tokens documented in docs/DESIGN.md §8. */

/* ================= Tokens ================= */
:root {
  color-scheme: light;
  --canvas-bg: #ffffff;
  --canvas-grid: #e9ecef;
  --surface: #ffffff;
  --surface-hover: #f1f3f5;
  --surface-sunken: #f8f9fa;
  --border: #dee2e6;
  --border-strong: #adb5bd;
  --text: #1e1e1e;
  --text-muted: #5c636a;
  --accent: #5b4ccc;
  --accent-hover: #4c3fb3;
  --accent-soft: #ece9ff;
  --accent-ink: #ffffff;
  --focus: #1c7ed6;
  --danger: #c92a2a;
  --success: #2b8a3e;
  --warning: #e67700;
  --online: #2f9e44;
  --offline: #e03131;
  --reconnect: #f59f00;
  --idle: #868e96;
  --checker: #dee2e6;
  --backdrop: rgba(20, 22, 26, .35);
  --shadow-island: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.08);
  --shadow-pop: 0 4px 10px rgba(0,0,0,.08), 0 16px 40px rgba(0,0,0,.16);

  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --fs-xs: 12px; --fs-sm: 13px; --fs-md: 14px; --fs-lg: 16px; --fs-xl: 20px;

  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 24px; --space-6: 32px;
  --radius-sm: 6px; --radius-md: 8px; --radius-lg: 12px; --radius-pill: 999px;

  --btn: 36px;          /* control size; 40px on coarse pointers */
  --icon: 20px;
  --edge: var(--space-3);

  --dur-fast: 120ms; --dur: 200ms; --ease: cubic-bezier(.2,.8,.2,1);

  --z-canvas: 0; --z-overlay: 5; --z-ui: 10; --z-menu: 20; --z-toast: 30; --z-fatal: 50;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --canvas-bg: #121417;
  --canvas-grid: #24282e;
  --surface: #1e2126;
  --surface-hover: #2a2e35;
  --surface-sunken: #16181c;
  --border: #343a40;
  --border-strong: #5c636a;
  --text: #e9ecef;
  --text-muted: #a5acb4;
  --accent: #a79bff;
  --accent-hover: #bdb4ff;
  --accent-soft: #2f2a52;
  --accent-ink: #121417;
  --focus: #74c0fc;
  --danger: #ff8787;
  --success: #69db7c;
  --warning: #ffd43b;
  --online: #51cf66;
  --offline: #ff6b6b;
  --reconnect: #fcc419;
  --checker: #343a40;
  --backdrop: rgba(0, 0, 0, .55);
  --shadow-island: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.35);
  --shadow-pop: 0 4px 10px rgba(0,0,0,.4), 0 16px 40px rgba(0,0,0,.5);
}

@media (pointer: coarse) { :root { --btn: 40px; } }

@media (prefers-reduced-motion: reduce) {
  :root { --dur-fast: 0ms; --dur: 0ms; }
  *, *::before, *::after { animation-duration: 0ms !important; animation-iteration-count: 1 !important; transition-duration: 0ms !important; }
}

/* ================= Base ================= */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: var(--canvas-bg);
  color: var(--text);
  font: 400 var(--fs-md)/1.4 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none; user-select: none;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.icon {
  width: var(--icon); height: var(--icon); flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round;
}
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
kbd {
  display: inline-block; min-width: 1.6em; padding: 1px 5px;
  font: 600 var(--fs-xs)/1.5 var(--font-ui); text-align: center;
  color: var(--text); background: var(--surface-sunken);
  border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px;
}

/* ================= Canvas ================= */
#board {
  position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh;
  display: block; z-index: var(--z-canvas);
  background-color: var(--canvas-bg);
  cursor: default;
}
#board:focus-visible { outline: none; } /* canvas focus is shown by selection, not a ring */
body[data-tool="hand"] #board { cursor: grab; }
body[data-panning="true"] #board { cursor: grabbing; }
body[data-tool="rectangle"] #board, body[data-tool="ellipse"] #board, body[data-tool="diamond"] #board,
body[data-tool="line"] #board, body[data-tool="arrow"] #board, body[data-tool="sticky"] #board,
body[data-tool="pen"] #board { cursor: crosshair; }
body[data-tool="text"] #board { cursor: text; }
body[data-tool="eraser"] #board {
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20'%3E%3Ccircle cx='10' cy='10' r='7' fill='white' fill-opacity='.6' stroke='%231e1e1e' stroke-width='1.5'/%3E%3C/svg%3E") 10 10, crosshair;
}

/* Static preview of the grid before the renderer is up (purely cosmetic) */
body[data-boot="loading"] #board, body:not([data-boot]) #board {
  background-image: radial-gradient(var(--canvas-grid) 1px, transparent 1.2px);
  background-size: 24px 24px;
}

/* ================= Overlay layout ================= */
#ui {
  position: fixed; inset: 0; z-index: var(--z-ui);
  pointer-events: none;
  padding: max(var(--edge), env(safe-area-inset-top)) max(var(--edge), env(safe-area-inset-right))
           max(var(--edge), env(safe-area-inset-bottom)) max(var(--edge), env(safe-area-inset-left));
}
#ui > * { pointer-events: auto; }
#ui > .toolbar-wrap { pointer-events: none; }
#ui > .toolbar-wrap > * { pointer-events: auto; }

.island {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-island);
}
.island--flat { background: transparent; border-color: transparent; box-shadow: none; }
.island--pill { border-radius: var(--radius-pill); }
.island--row { display: flex; align-items: center; padding: 2px; gap: 2px; }

/* Brand */
.brand {
  position: absolute; top: var(--edge); left: var(--edge);
  display: flex; align-items: center; gap: 6px; height: var(--btn); padding: 0 var(--space-2);
  font-weight: 700; font-size: var(--fs-lg); letter-spacing: -.02em; color: var(--accent);
  pointer-events: none !important;
}
.brand .icon { width: 22px; height: 22px; }

/* ================= Toolbar ================= */
.toolbar-wrap {
  position: absolute; top: var(--edge); left: 0; right: 0;
  display: flex; justify-content: center;
  padding: 0 calc(var(--edge) + 0px);
}
#toolbar {
  display: flex; align-items: center; gap: 2px; padding: 4px;
  max-width: 100%;
  overflow-x: auto; scrollbar-width: none; scroll-snap-type: x proximity;
}
#toolbar::-webkit-scrollbar { display: none; }
#toolbar .sep { flex: none; width: 1px; height: 22px; margin: 0 4px; background: var(--border); }

.tool, .icon-btn {
  position: relative; flex: none;
  display: inline-grid; place-items: center;
  width: var(--btn); height: var(--btn); padding: 0;
  border: 0; border-radius: var(--radius-md);
  background: transparent; color: var(--text);
  scroll-snap-align: center;
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.tool:hover, .icon-btn:hover:not(:disabled) { background: var(--surface-hover); }
.tool:active, .icon-btn:active:not(:disabled) { transform: translateY(.5px); }
.tool[aria-pressed="true"], .icon-btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.tool[aria-pressed="true"] .icon { stroke-width: 2; }
.icon-btn:disabled, .tool:disabled { opacity: .4; cursor: default; }
.tool-key {
  position: absolute; right: 3px; bottom: 1px;
  font-size: 9px; font-weight: 600; line-height: 1; color: var(--text-muted);
  pointer-events: none;
}
.tool[aria-pressed="true"] .tool-key { color: var(--accent); }
.tool--lock .icon-on, .tool--lock[aria-pressed="true"] .icon-off { display: none; }
.tool--lock[aria-pressed="true"] .icon-on { display: block; }

/* ================= Top-right ================= */
.topright {
  position: absolute; top: var(--edge); right: var(--edge);
  display: flex; align-items: center; gap: var(--space-2);
}
.conn {
  display: flex; align-items: center; gap: 6px;
  height: var(--btn); padding: 0 var(--space-3);
  font-size: var(--fs-sm); font-weight: 500; color: var(--text-muted);
  white-space: nowrap;
}
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--idle); flex: none; }
.conn-label { display: none; }
.conn[data-state="connecting"] [data-when="connecting"],
.conn[data-state="online"] [data-when="online"],
.conn[data-state="reconnecting"] [data-when="reconnecting"],
.conn[data-state="offline"] [data-when="offline"] { display: inline; }
.conn[data-state="online"] .conn-dot { background: var(--online); box-shadow: 0 0 0 3px color-mix(in srgb, var(--online) 22%, transparent); }
.conn[data-state="connecting"] .conn-dot { background: var(--idle); animation: pulse 1.2s ease-in-out infinite; }
.conn[data-state="reconnecting"] .conn-dot { background: var(--reconnect); animation: pulse 1.2s ease-in-out infinite; }
.conn[data-state="offline"] { color: var(--text); border-color: color-mix(in srgb, var(--offline) 45%, var(--border)); }
.conn[data-state="offline"] .conn-dot { background: var(--offline); }
/* online: collapse to a quiet dot after a moment */
.conn[data-state="online"] [data-when="online"] {
  display: inline-block; max-width: 6em; overflow: hidden; vertical-align: bottom;
  animation: label-out var(--dur) var(--ease) 3s forwards;
}
.conn[data-state="online"] { animation: conn-quiet var(--dur) var(--ease) 3s forwards; }
.conn[data-state="online"]:hover [data-when="online"] { animation: none; }
.conn[data-state="online"]:hover { animation: none; }
@keyframes label-out { to { max-width: 0; opacity: 0; } }
@keyframes conn-quiet { to { gap: 0; padding: 0 13px; } }
@keyframes pulse { 50% { opacity: .35; } }
.badge {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: var(--radius-pill);
  background: var(--offline); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
}

.presence-island { display: flex; align-items: center; height: var(--btn); padding: 0 4px; gap: 4px; }
.avatar-item { display: contents; }
.avatars { display: flex; align-items: center; margin: 0; padding: 0 0 0 6px; list-style: none; }
.avatars:empty { display: none; }
.avatar {
  position: relative; display: inline-grid; place-items: center;
  width: 28px; height: 28px; margin-left: -6px; padding: 0;
  border-radius: 50%; border: 2px solid var(--surface);
  background: var(--peer, #868e96); color: var(--peer-ink, #ffffff);
  font-size: 11px; font-weight: 700; letter-spacing: .02em; line-height: 1;
  cursor: pointer; user-select: none;
  transition: transform var(--dur-fast) var(--ease);
}
.avatar:hover { transform: translateY(-2px); z-index: 1; }
[data-overflow] > .avatar { background: var(--surface-hover); color: var(--text); }
.avatar--self {
  margin-left: 0; width: 30px; height: 30px;
  border: 2px solid var(--surface); box-shadow: 0 0 0 2px var(--peer);
  background: var(--peer); color: var(--peer-ink);
}
.avatar--self { --peer: var(--accent); --peer-ink: var(--accent-ink); }
.avatar--self:hover { transform: none; filter: brightness(1.06); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: var(--btn); padding: 0 var(--space-4);
  border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--surface); color: var(--text);
  font-weight: 600; font-size: var(--fs-md); white-space: nowrap;
  transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.btn:hover { background: var(--surface-hover); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.share-btn { box-shadow: var(--shadow-island); border-radius: var(--radius-pill); padding: 0 var(--space-4) 0 var(--space-3); }
.link-btn { padding: 0; border: 0; background: none; color: var(--accent); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }

/* ================= Style panel ================= */
#style-panel {
  position: absolute; left: var(--edge); top: calc(var(--edge) + var(--btn) + 8px + var(--space-4));
  width: 196px; max-height: calc(100% - 2 * var(--edge) - var(--btn) * 2 - 48px);
  overflow-y: auto; overscroll-behavior: contain;
  padding: var(--space-3);
}
.style-panel-toggle { display: none; }
.style-body { display: flex; flex-direction: column; gap: var(--space-3); }
.style-group { display: flex; flex-direction: column; gap: 6px; }
.ctx-text, .ctx-sticky { display: none; }
#style-panel[data-context="text"] .ctx-text, #style-panel[data-context="sticky"] .ctx-sticky { display: inline; }
#style-panel[data-context="text"] [data-group="stroke"] .ctx-default,
#style-panel[data-context="sticky"] [data-group="fill"] .ctx-default { display: none; }
.style-label { margin: 0; font-size: var(--fs-xs); font-weight: 600; color: var(--text-muted); letter-spacing: .01em; }
.swatches { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.swatch {
  --c: transparent;
  width: 100%; height: 28px; padding: 0;
  border: 0; border-radius: var(--radius-sm);
  background: var(--c);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--text) 18%, transparent);
  transition: box-shadow var(--dur-fast) var(--ease);
}
.swatch:hover { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--text) 35%, transparent), 0 0 0 2px var(--surface-hover); }
.swatch[aria-pressed="true"] { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--text) 18%, transparent), 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); }
/* default ink adapts to theme like the renderer does */
:root[data-theme="dark"] .swatch[data-value="#1e1e1eff"] { --c: #e9ecef !important; }
.swatch--none {
  background:
    linear-gradient(to top right, transparent calc(50% - 1px), var(--danger) calc(50% - 1px), var(--danger) calc(50% + 1px), transparent calc(50% + 1px)),
    repeating-conic-gradient(var(--checker) 0 25%, var(--surface) 0 50%) 0 0 / 8px 8px;
}
.segmented { display: flex; gap: 2px; padding: 2px; border-radius: var(--radius-md); background: var(--surface-sunken); }
.seg {
  flex: 1; display: inline-grid; place-items: center;
  height: 30px; min-width: 30px; padding: 0;
  border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text);
}
.seg:hover { background: var(--surface-hover); }
.seg[aria-pressed="true"] { background: var(--surface); color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.seg--text { font-weight: 600; font-size: var(--fs-sm); }
.seg--danger:hover { color: var(--danger); }
.seg .icon { width: 18px; height: 18px; }

input[type="range"] {
  width: 100%; height: 24px; margin: 0; background: transparent;
  -webkit-appearance: none; appearance: none; accent-color: var(--accent);
}
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: var(--border); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; margin-top: -6px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--accent);
}
input[type="range"]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--border); }
#style-opacity[data-mixed]::-webkit-slider-thumb { opacity: .45; }
#style-opacity[data-mixed]::-moz-range-thumb { opacity: .45; }
input[type="range"]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 2px solid var(--accent); }

/* ================= Bottom bars ================= */
.bottomleft {
  position: absolute; left: var(--edge); bottom: var(--edge);
  display: flex; align-items: center; gap: var(--space-2);
}
.bottomright { position: absolute; right: var(--edge); bottom: var(--edge); display: flex; gap: var(--space-2); }
.zoom-level {
  min-width: 56px; height: var(--btn); padding: 0 6px;
  border: 0; border-radius: var(--radius-md); background: transparent;
  font-size: var(--fs-sm); font-weight: 600; font-variant-numeric: tabular-nums;
}
.zoom-level:hover { background: var(--surface-hover); }
.show-dark { display: none; }
:root[data-theme="dark"] .show-dark { display: block; }
:root[data-theme="dark"] .show-light { display: none; }

/* ================= Empty state ================= */
#empty-state {
  position: fixed; inset: 0; z-index: var(--z-overlay);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-2);
  padding: var(--space-6);
  pointer-events: none; text-align: center; color: var(--text-muted);
}
.empty-logo { width: 56px; height: 56px; fill: none; stroke: var(--border-strong); stroke-linecap: round; stroke-linejoin: round; opacity: .7; }
.empty-title { margin: 0; font-size: var(--fs-xl); font-weight: 600; color: var(--text-muted); }
.empty-keys { margin: 0; font-size: var(--fs-md); }
.empty-keys .dot { margin: 0 4px; opacity: .6; }
.empty-keys > span.k { white-space: nowrap; }
.empty-sub { margin: 0; font-size: var(--fs-sm); }
.when-ready { display: none; }
body:not([data-boot="loading"]) .when-loading { display: none; }
body:not([data-boot="loading"]) .when-ready { display: inline; }
body[data-boot="loading"] .empty-keys, body[data-boot="loading"] .empty-sub { opacity: .5; }

/* ================= Text editor ================= */
#text-editor {
  position: fixed; z-index: var(--z-overlay);
  left: 0; top: 0; min-width: 4px; min-height: 1em;
  margin: 0; padding: 0;
  border: 0; outline: none; resize: none; overflow: hidden;
  background: transparent; color: var(--text);
  font-family: var(--font-ui); font-size: 20px; line-height: 1.25;
  white-space: pre-wrap; overflow-wrap: break-word;
  transform-origin: center center;
  caret-color: var(--accent);
  -webkit-user-select: text; user-select: text;
}
#text-editor[data-kind="sticky"] { padding: 16px; color: #1e1e1e; }

/* ================= Remote cursors (DOM fallback) ================= */
#cursor-layer { position: fixed; inset: 0; z-index: var(--z-overlay); pointer-events: none; overflow: hidden; }
.cursor { --peer: #868e96; --peer-ink: #fff; position: absolute; left: 0; top: 0; will-change: transform; transition: transform 100ms linear; }
.cursor-arrow { display: block; fill: var(--peer); stroke: #fff; stroke-width: 1.5; stroke-linejoin: round; filter: drop-shadow(0 1px 1px rgba(0,0,0,.25)); }
.cursor-name {
  position: absolute; left: 12px; top: 16px;
  padding: 2px 6px; border-radius: var(--radius-pill);
  background: var(--peer); color: var(--peer-ink);
  font-size: var(--fs-xs); font-weight: 600; line-height: 1.35; white-space: nowrap;
  transition: opacity var(--dur) var(--ease);
}
.cursor[data-idle] .cursor-name { opacity: 0; }

/* ================= Context menu ================= */
.menu {
  position: fixed; z-index: var(--z-menu);
  min-width: 220px; padding: 4px;
  box-shadow: var(--shadow-pop);
  display: flex; flex-direction: column;
}
.menu [role="menuitem"] {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-4);
  height: 32px; padding: 0 var(--space-2) 0 var(--space-3);
  border: 0; border-radius: var(--radius-sm); background: transparent;
  text-align: left; font-size: var(--fs-md);
}
.menu [role="menuitem"]:hover:not(:disabled), .menu [role="menuitem"]:focus-visible { background: var(--surface-hover); outline-offset: -2px; }
.menu [role="menuitem"]:disabled { opacity: .4; cursor: default; }
.menu kbd { border: 0; background: none; color: var(--text-muted); font-weight: 500; padding: 0; }
.menu-danger { color: var(--danger); }
.menu-sep { height: 1px; margin: 4px 6px; background: var(--border); }

/* ================= Notices & toasts ================= */
.notice {
  position: absolute; left: 50%; bottom: calc(var(--edge) + var(--btn) + var(--space-3)); transform: translateX(-50%);
  display: flex; align-items: center; gap: var(--space-2);
  max-width: min(560px, calc(100% - 2 * var(--edge)));
  padding: 6px 6px 6px var(--space-3);
  font-size: var(--fs-sm);
  border-color: color-mix(in srgb, var(--warning) 50%, var(--border));
}
.notice > .icon { color: var(--warning); }
.toasts {
  position: absolute; left: 50%; bottom: calc(var(--edge) + 4px); transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex; flex-direction: column-reverse; align-items: center; gap: var(--space-2);
  pointer-events: none !important;
}
.toast {
  padding: 8px 14px; border-radius: var(--radius-md);
  background: var(--text); color: var(--surface);
  font-size: var(--fs-sm); font-weight: 500;
  box-shadow: var(--shadow-pop);
  animation: toast-in var(--dur) var(--ease);
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.toast[data-kind="success"]::before { content: "✓ "; color: var(--success); filter: brightness(1.4); }
.toast[data-kind="error"] { background: var(--danger); color: #fff; }
:root[data-theme="dark"] .toast[data-kind="error"] { color: #121417; }
.toast[data-leaving] { opacity: 0; transform: translateY(6px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ================= Dialogs ================= */
.dialog {
  width: min(440px, calc(100vw - 32px)); max-height: calc(100dvh - 32px);
  padding: var(--space-5); margin: auto;
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-pop);
  -webkit-user-select: text; user-select: text;
}
.dialog[open] { animation: dialog-in var(--dur) var(--ease); }
.dialog::backdrop { background: var(--backdrop); }
.dialog--wide { width: min(820px, calc(100vw - 32px)); }
@keyframes dialog-in { from { opacity: 0; transform: translateY(6px) scale(.98); } }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin: 0 0 var(--space-3); }
.dialog-head h2 { margin: 0; font-size: var(--fs-xl); font-weight: 700; letter-spacing: -.01em; }
.dialog-head .icon-btn { margin: -6px -8px -6px 0; }
.dialog-foot { display: flex; justify-content: flex-end; gap: var(--space-2); margin-top: var(--space-4); }
.muted { color: var(--text-muted); margin: 0 0 var(--space-3); }
.small { font-size: var(--fs-sm); margin: var(--space-3) 0 0; }
.input {
  width: 100%; height: var(--btn); padding: 0 var(--space-3);
  border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  background: var(--surface-sunken); color: var(--text);
}
.input:focus-visible { outline: 2px solid var(--focus); outline-offset: 0; border-color: transparent; }
.field-row { display: flex; gap: var(--space-2); }
.field-row .input { flex: 1; min-width: 0; font-family: var(--font-mono); font-size: var(--fs-sm); }

.help-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-5); }
.help-grid h3 { margin: 0 0 var(--space-2); font-size: var(--fs-sm); text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); }
.help-grid h3:not(:first-child) { margin-top: var(--space-4); }
.keys { display: grid; grid-template-columns: 1fr auto; gap: 6px var(--space-3); margin: 0; font-size: var(--fs-sm); }
.keys dt { color: var(--text); }
.keys dd { margin: 0; text-align: right; color: var(--text-muted); white-space: nowrap; }

/* ================= Fatal ================= */
.fatal {
  position: fixed; inset: 0; z-index: var(--z-fatal);
  display: grid; place-items: center; padding: var(--space-5);
  background: var(--canvas-bg);
}
.fatal-card { max-width: 480px; text-align: center; -webkit-user-select: text; user-select: text; }
.fatal-icon { width: 48px; height: 48px; color: var(--warning); }
.fatal h1 { margin: var(--space-3) 0 var(--space-2); font-size: 24px; letter-spacing: -.01em; }
.fatal p { margin: 0 0 var(--space-4); color: var(--text-muted); }
.fatal details { margin: 0 0 var(--space-4); text-align: left; font-size: var(--fs-sm); color: var(--text-muted); }
.fatal pre { max-height: 160px; overflow: auto; padding: var(--space-2); border-radius: var(--radius-sm); background: var(--surface-sunken); font: var(--fs-xs)/1.4 var(--font-mono); white-space: pre-wrap; }
body[data-boot="failed"] #ui, body[data-boot="failed"] #empty-state { display: none; }

/* ================= Responsive ================= */
@media (max-width: 1100px) {
  .brand { display: none; }
}
@media (max-width: 900px) {
  /* toolbar drops below the top-right cluster */
  .toolbar-wrap { top: calc(var(--edge) + var(--btn) + var(--space-2)); }
  #style-panel { top: calc(var(--edge) + 2 * var(--btn) + 8px + var(--space-5)); }
  .tool-key { display: none; }
}
@media (max-width: 560px) {
  #toolbar {
    -webkit-mask-image: linear-gradient(to right, transparent 0, #000 14px, #000 calc(100% - 14px), transparent 100%);
            mask-image: linear-gradient(to right, transparent 0, #000 14px, #000 calc(100% - 14px), transparent 100%);
    padding: 4px 10px;
  }
}
@media (max-width: 720px) {
  .topright { left: var(--edge); justify-content: flex-end; }
  .share-btn { padding: 0; width: var(--btn); }
  .share-btn .btn-label { display: none; }
  .avatars .avatar-item:nth-child(n+3):not([data-overflow]) > .avatar { display: none; }
  .conn[data-state="offline"] [data-when="offline"] { max-width: 42vw; overflow: hidden; text-overflow: ellipsis; }
  .help-grid { grid-template-columns: 1fr; }
  .notice { bottom: calc(var(--edge) + 2 * var(--btn) + var(--space-4)); width: calc(100% - 2 * var(--edge)); }

  /* style panel → bottom sheet */
  #style-panel {
    top: auto; left: var(--edge); right: var(--edge);
    bottom: calc(var(--edge) + var(--btn) + 4px + var(--space-2));
    width: auto; max-height: 46vh; padding: 0;
  }
  .style-panel-toggle {
    display: flex; align-items: center; gap: var(--space-2); width: 100%;
    height: var(--btn); padding: 0 var(--space-3);
    border: 0; background: transparent; font-weight: 600; font-size: var(--fs-sm);
  }
  .style-panel-toggle .chev { margin-left: auto; transition: transform var(--dur) var(--ease); }
  .style-panel-toggle[aria-expanded="false"] .chev { transform: rotate(180deg); }
  .style-body { padding: 0 var(--space-3) var(--space-3); display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
  .style-group[data-group="stroke"], .style-group[data-group="fill"] { grid-column: 1 / -1; }
  #style-panel[data-collapsed] { right: auto; }
  #style-panel[data-collapsed] .style-body { display: none; }
  #style-panel[data-collapsed] .style-panel-toggle { width: auto; }
}
@media (max-width: 420px) {
  :root { --edge: 8px; }
  .hide-xs { display: none !important; }
  .zoom-level { min-width: 48px; }
  .style-body { grid-template-columns: 1fr; }
}
