/* ============================================================
   ui.css — crdt-svg chrome theme
   TTRPG dark palette · emboss borders · backdrop blur surfaces
   No JS. No app logic. Import this in index.html.
   ============================================================ */

:root {
  /* Canvas */
  --bg:  #0d0b13;
  --dot: rgba(200,168,80,0.07);

  /* Surfaces — semi-transparent dark, blur to taste */
  --surface:       rgba(22, 17, 34, 0.82);
  --surface-2:     rgba(36, 29, 52, 0.70);
  --surface-solid: #1a1228;

  /* Text — warm parchment palette */
  --text:   #ddd0b4;
  --text-2: #8a7d68;
  --text-3: #4e4438;

  /* Emboss borders — warm gold-tinted lights */
  --border:   rgba(210,185,130,0.13);
  --border-2: rgba(210,185,130,0.26);

  /* Accent */
  --primary:      #c8941e;
  --primary-soft: rgba(200,148,30,0.20);
  --info:         #5a7ea8;
  --info-soft:    rgba(90,126,168,0.20);
  --warn:         #b87820;
  --warn-soft:    rgba(184,120,32,0.22);
  --danger:       #8b2a2a;

  /* Emboss shadow stacks:
       inset top  = warm light catch (the "raised" illusion)
       inset bot  = underside shadow
       ring       = dark outer outline
       depth      = ambient drop shadow                          */
  --emboss:
    inset 0 2px 0 rgba(210,185,130,0.40),
    inset 0 -1px 0 rgba(0,0,0,0.55),
    0 0 0 1px rgba(0,0,0,0.70),
    0 4px 18px rgba(0,0,0,0.55);

  --emboss-lg:
    inset 0 2px 0 rgba(210,185,130,0.40),
    inset 0 -1px 0 rgba(0,0,0,0.55),
    0 0 0 1px rgba(0,0,0,0.80),
    0 12px 40px rgba(0,0,0,0.70);

  --emboss-active:
    inset 0 2px 0 rgba(200,148,30,0.35),
    inset 0 -1px 0 rgba(0,0,0,0.55),
    0 0 0 1px rgba(200,148,30,0.45),
    0 0 14px rgba(200,148,30,0.22),
    0 4px 16px rgba(0,0,0,0.55);

  --emboss-inset:
    inset 0 2px 5px rgba(0,0,0,0.60),
    inset 0 1px 2px rgba(0,0,0,0.40),
    inset 0 -1px 0 rgba(210,185,130,0.06),
    0 0 0 1px rgba(0,0,0,0.70);

  /* Layout */
  --radius:    14px;
  --radius-sm: 10px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --panel-w:  0px;   /* set by ui.js when desktop panel is open */
  --idbar-h:  54px;  /* mobile idbar content height excl. safe-t */

  /* Typography */
  --font-body:    -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-display: "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;

  /* Aliases consumed by <color-picker> (component/color-picker.js) */
  --color-border-tertiary:  var(--border);
  --color-border-secondary: var(--border-2);
  --color-text-primary:     var(--text);

  /* Aliases consumed by <range-ticked> (component/range_ticked.js) */
  --color-accent:        var(--primary);
  --color-text-tertiary: var(--text-3);
}

/* ── Reset & base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%; overflow: hidden;
  font-family: var(--font-body); color: var(--text); background: var(--bg);
  overscroll-behavior: none; touch-action: none;
  user-select: none; -webkit-user-select: none;
}

/* ── Stage / canvas host ──────────────────────────────────── */
#stage {
  position: fixed; inset: 0;
  right: var(--panel-w);
  transition: right .3s cubic-bezier(.2,.9,.3,1);
}
/* Subtle dark tint over the hex image so dot grid and vignette read */
#stage::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image:
    radial-gradient(circle, var(--dot) 1.5px, transparent 1.5px),
    radial-gradient(circle, var(--dot) 1.5px, transparent 1.5px);
  background-size: 26px 45px, 26px 45px;
  background-position:
    var(--bgx, 0px) var(--bgy, 0px),
    calc(var(--bgx, 0px) + 13px) calc(var(--bgy, 0px) + 22px);
  background-color: rgba(5, 3, 12, 0.55);  /* tint layer */
}
/* Vignette — focuses attention on centre */
#stage::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(5,3,10,0.55) 100%);
}
#stage > svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; z-index: 1; }

/* SVG class helpers (applied by canvas.js) */
.shape     { cursor: pointer; }
.selRing   { pointer-events: none; }
.peer-ring { pointer-events: none; }
.requestedRing { pointer-events: none; }
.remote-sel     { pointer-events: none; }
.handle    { pointer-events: auto; }
.handle[data-corner="nw"] { cursor: nw-resize; }
.handle[data-corner="ne"] { cursor: ne-resize; }
.handle[data-corner="sw"] { cursor: sw-resize; }
.handle[data-corner="se"] { cursor: se-resize; }
.handle[data-corner="r"]  { cursor: ew-resize; }

/* A toy nested inside a tray is excluded from native hit-testing, so a
 * click over it lands on whatever's actually painted underneath — the
 * tray's own background — instead of the nested toy itself. Descendant
 * selector + inheritance means this holds at any nesting depth (a tray
 * inside a tray inside a tray) with no extra rule needed. */
.tt_contents .toy { pointer-events: none; }

/* .tt_hit_plate (in every tray_*.svg) is a full-coverage, invisible rect
 * providing an exact hit-testing floor for the whole tray, decoupled from
 * whatever the tray's background art happens to visibly paint
 */
.tt_hit_plate { pointer-events: fill; }
.tt_contents .tt_hit_plate { pointer-events: none; }

/* Draw-preview div (used by canvas.js for rubber-band rect) */
#draw-preview {
  display: none; position: absolute; pointer-events: none; z-index: 2;
  border: 1.5px dashed var(--primary); background: var(--primary-soft);
}

/* ── Identity bar ─────────────────────────────────────────── */
/* Mobile: full-width bar at top, slides down from above */
#idbar {
  position: fixed; z-index: 81; /* above panel */
  top: 0; left: 0; right: 0;
  background: var(--surface);
  backdrop-filter: blur(18px) saturate(1.3);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  box-shadow: var(--emboss);
  padding: calc(var(--safe-t) + 10px) calc(var(--safe-r) + 16px) 10px calc(var(--safe-l) + 16px);
  display: flex; flex-direction: row; align-items: center; gap: 10px;
  transform: translateY(-110%);
  opacity: 0;
  transition: transform .28s cubic-bezier(.2,.9,.3,1), opacity .22s ease;
  pointer-events: none;
}
#idbar.visible { transform: translateY(0); opacity: 1; pointer-events: auto; }
.idbar-project { font-family: var(--font-display); font-size: 14px; color: var(--text); letter-spacing: .02em; white-space: nowrap; text-decoration: none; cursor: pointer; }
.idbar-project:hover { color: var(--primary); }
.idbar-user    { font-size: 11px; color: var(--primary); font-weight: 600; white-space: nowrap; }
.idbar-table   { font-size: 11px; color: var(--text-3); font-family: ui-monospace, Menlo, monospace; white-space: nowrap; margin-left: auto; }
.idbar-sep     { width: 0.5px; height: 16px; background: var(--border-2); flex-shrink: 0; }

/* Desktop: small card, top-left, slides in from left */
@media (min-width: 760px) {
  #idbar {
    top: calc(var(--safe-t) + 12px);
    left: calc(var(--safe-l) + 12px);
    right: auto;
    border-radius: var(--radius-sm);
    padding: 9px 13px;
    flex-direction: column; align-items: flex-start; gap: 3px;
    max-width: 220px;
    transform: translateX(calc(-100% - 20px));
  }
  #idbar.visible { transform: translateX(0); }
  .idbar-sep     { width: 100%; height: 0.5px; margin: 2px 0; }
  .idbar-table   { margin-left: 0; }
}

/* ── Toasts ───────────────────────────────────────────────── */
#toasts {
  position: fixed; left: 50%; transform: translateX(-50%);
  top: calc(var(--safe-t) + 12px);
  width: min(420px, calc(100vw - 24px));
  display: flex; flex-direction: column; gap: 8px; z-index: 60; pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--surface); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  box-shadow: var(--emboss);
  border-radius: var(--radius-sm); padding: 10px 14px;
  font-size: 13px; color: var(--text);
  display: flex; align-items: center; gap: 9px;
  animation: toastIn .22s cubic-bezier(.2,.9,.3,1);
}
.toast.out { animation: toastOut .18s ease forwards; }
.toast .dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; background: var(--primary); }
.toast.info { color: #7fa8d4; } .toast.info .dot { background: var(--info); }
.toast.warn { color: #d4a060; } .toast.warn .dot { background: var(--warn); }
.toast.error { color: #d47070; } .toast.error .dot { background: var(--danger); }
@keyframes toastIn  { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { to   { opacity: 0; transform: translateY(-6px); } }

/* ── Branch Acknowledge dialog — true blocking modal, every viewport
   (unlike #scrim/#panel, which are a mobile-only bottom sheet). Same
   surface/emboss/radius/typography language as #panel throughout, just
   centered instead of docked. ────────────────────────────────────── */
.dialog-scrim {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(4,3,8,0.72);
  opacity: 0; visibility: hidden;
  transition: opacity .2s, visibility .2s;
}
.dialog-scrim.open { opacity: 1; visibility: visible; }
.dialog {
  position: fixed; z-index: 91;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%) scale(0.96);
  width: min(380px, calc(100vw - 32px));
  max-height: calc(100dvh - var(--safe-t) - var(--safe-b) - 32px);
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface-solid);
  border-radius: var(--radius);
  box-shadow: var(--emboss-lg);
  opacity: 0; visibility: hidden;
  transition: opacity .2s, visibility .2s, transform .2s cubic-bezier(.2,.9,.3,1);
}
.dialog.open { opacity: 1; visibility: visible; transform: translate(-50%, -50%) scale(1); }
.dialog-head {
  padding: 16px 18px 12px; border-bottom: 0.5px solid var(--border-2);
  background: rgba(0,0,0,0.15); flex-shrink: 0;
}
.dialog-head h2 {
  font-family: var(--font-display); font-size: 16px; font-weight: normal; letter-spacing: .04em;
  margin: 0; color: var(--text);
}
.dialog-body {
  padding: 16px 18px; overflow-y: auto; flex: 1;
  font-size: 13px; line-height: 1.55; color: var(--text-2);
}
.dialog-body strong { color: var(--text); font-weight: 600; }
.dialog-body p { margin: 0 0 10px; }
.dialog-body p:last-child { margin-bottom: 0; }
.dialog-actions {
  display: flex; flex-direction: column; gap: 8px;
  padding: 14px 18px; border-top: 0.5px solid var(--border-2);
  background: rgba(0,0,0,0.15); flex-shrink: 0;
}
.dialog-btn {
  width: 100%; padding: 11px 14px; border: none; border-radius: var(--radius-sm);
  background: var(--surface-2); box-shadow: var(--emboss);
  color: var(--text); font-family: var(--font-body); font-size: 13px; font-weight: 500;
  cursor: pointer;
}
.dialog-btn:active { box-shadow: var(--emboss-inset); }
.dialog-btn-primary { background: var(--primary-soft); color: var(--primary); }

/* ── Info button (top-right, always visible) ──────────────── */
#infoBtn {
  position: fixed; z-index: 55;
  right: calc(var(--safe-r) + 14px); top: calc(var(--safe-t) + 12px);
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--surface); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  box-shadow: var(--emboss); color: var(--text-2); border: none;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  transition: color .15s, box-shadow .15s;
}
#infoBtn:hover  { color: var(--text); }
#infoBtn:active { box-shadow: var(--emboss-inset); }
#infoBtn svg    { width: 18px; height: 18px; }

/* ── Tool-mode cursor hints (applied to #stage by canvas.js) */
#stage[data-tool="select"]                           { cursor: default; }
#stage[data-tool="select"][data-select-mode="pan"]   { cursor: grab; }
#stage[data-tool="select"][data-select-mode="pan"].dragging { cursor: grabbing; }
#stage[data-tool="select"][data-select-mode="multi"] { cursor: crosshair; }
/* Any non-select tool (drawing, toy, or boundary/position) is "adding" —
   crosshair by default; text is the one deliberate exception below. */
#stage[data-tool]:not([data-tool="select"]):not([data-tool="text"]) { cursor: crosshair; }
#stage[data-tool="text"]    { cursor: text; }

#select-preview {
  display: none; position: absolute; pointer-events: none; z-index: 2;
  border: 1.5px dashed var(--info); background: var(--info-soft);
}

/* ── Pill ─────────────────────────────────────────────────── */
#pill {
  position: fixed; z-index: 50;
  bottom: calc(var(--safe-b) + 16px);
  left: calc(var(--safe-l) + 14px);
  background: var(--surface);
  backdrop-filter: blur(18px) saturate(1.3); -webkit-backdrop-filter: blur(18px) saturate(1.3);
  box-shadow: var(--emboss);
  border-radius: 28px; padding: 5px;
  display: flex; gap: 2px; align-items: center;
}
@media (min-width: 760px) {
  #pill {
    left: 50%; transform: translateX(-50%);
    margin-left: calc(var(--panel-w) / -2);
    transition: margin-left .3s cubic-bezier(.2,.9,.3,1);
  }
}

#pill.toy-menu {
  flex-direction: column; align-items: center; gap: 3px;
  background: none; box-shadow: none; padding: 0; border-radius: 0;
}

.toy-menu-row {
  background: var(--surface);
  backdrop-filter: blur(18px) saturate(1.3); -webkit-backdrop-filter: blur(18px) saturate(1.3);
  box-shadow: var(--emboss);
  border-radius: 22px;
  display: flex; align-items: stretch; overflow: hidden;
}
.toy-menu-row:first-child:not(:last-child)  { border-radius: 22px 22px 8px 8px; }
.toy-menu-row:last-child:not(:first-child)  { border-radius: 8px 8px 22px 22px; }
.toy-menu-row:not(:first-child):not(:last-child) { border-radius: 8px; }

.toy-menu-item {
  display: flex; align-items: center; gap: 7px; flex: 1; justify-content: center;
  padding: 14px 16px; color: var(--text-2); font-size: 12.5px; font-weight: 500;
  border-right: 1px solid var(--border); cursor: pointer; white-space: nowrap;
}
.toy-menu-item:last-child { border-right: none; }
.toy-menu-item:hover { color: var(--text); }
.toy-menu-item.danger:hover { color: var(--danger); }

.ico {
  width: 46px; height: 46px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-2); background: transparent; border: none; cursor: pointer;
  transition: color .15s, box-shadow .15s, transform .1s; position: relative;
}
.ico:active { transform: scale(0.91); box-shadow: var(--emboss-inset); }
.ico.active { color: var(--primary); box-shadow: var(--emboss-active); }
.ico.danger { color: var(--danger); }
.ico svg    { width: 22px; height: 22px; }
.ico .active-dot {
  position: absolute; bottom: 5px; left: 50%; transform: translateX(-50%);
  width: 4px; height: 4px; border-radius: 50%; background: var(--primary); display: none;
}
.ico.active .active-dot { display: block; }
.pill-sep { width: 2px; height: 24px; background: var(--border-2); margin: 0 1px; flex-shrink: 0; }

/* ── Tool-options popover (above pill) ────────────────────── */
#toolOpts {
  position: fixed; z-index: 55;
  background: var(--surface);
  backdrop-filter: blur(22px) saturate(1.4); -webkit-backdrop-filter: blur(22px) saturate(1.4);
  box-shadow: var(--emboss-lg);
  border-radius: var(--radius); padding: 14px; min-width: 220px; display: none;
}
#toolOpts h3 {
  margin: 0 0 12px;
  font-family: var(--font-display); font-size: 13px; font-weight: normal; letter-spacing: .04em;
  color: var(--text-2);
}
.opt-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.opt-row:last-child { margin-bottom: 0; }
.opt-label { color: var(--text-3); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.cp-row { display: flex; align-items: flex-start; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.cp-opt-row { display: block; margin-bottom: 14px; }
.cp-opt-row:last-child { margin-bottom: 0; }
.cp-opt-row .opt-label { display: block; margin-bottom: 6px; }
.cp-none {
  height: 28px; padding: 0 10px; border-radius: 6px; border: 0.5px solid var(--border-2);
  background: var(--surface-2); color: var(--text-3); font-size: 12px; cursor: pointer;
  display: flex; align-items: center; gap: 4px; font-family: var(--font-body);
}
.cp-none.active { color: var(--text); border-color: var(--text-2); box-shadow: 0 0 0 1px rgba(0,0,0,0.8); }
.stepper { display: flex; align-items: center; gap: 6px; }
.step-btn {
  width: 30px; height: 30px; border-radius: 50%; border: none;
  background: var(--surface-2); box-shadow: var(--emboss);
  color: var(--text); font-size: 18px; font-family: var(--font-body);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.step-btn:active { box-shadow: var(--emboss-inset); }
.step-val { font-size: 14px; font-weight: 500; min-width: 28px; text-align: center; color: var(--text); }

/* ── Menu button (bottom-right) ───────────────────────────── */
#menuBtn {
  position: fixed; z-index: 50;
  right: calc(var(--safe-r) + 14px); bottom: calc(var(--safe-b) + 16px);
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--surface); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  box-shadow: var(--emboss); color: var(--text-2); border: none;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  transition: box-shadow .2s, color .15s;
}
#menuBtn.open { color: var(--primary); box-shadow: var(--emboss-active); }
#menuBtn svg  { width: 22px; height: 22px; transition: transform .25s; }
#menuBtn.open svg { transform: rotate(90deg); }

#menuItems {
  position: fixed; z-index: 49;
  right: calc(var(--safe-r) + 14px); bottom: calc(var(--safe-b) + 78px);
  display: flex; flex-direction: column-reverse; gap: 10px; align-items: stretch;
  pointer-events: none; opacity: 0; transform: translateY(16px);
  transition: opacity .2s, transform .2s;
}
#menuItems.open { pointer-events: auto; opacity: 1; transform: translateY(0); }
.menu-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; cursor: pointer; }
.menu-label {
  font-size: 12px; font-weight: 500; letter-spacing: .02em;
  background: var(--surface); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  box-shadow: var(--emboss); border-radius: 10px; padding: 4px 11px;
  color: var(--text-2); white-space: nowrap;
}
.menu-circle {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  background: var(--surface); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  box-shadow: var(--emboss); color: var(--text-2); position: relative;
  display: flex; align-items: center; justify-content: center;
}
.menu-circle svg { width: 20px; height: 20px; }
.menu-item:hover .menu-label  { color: var(--text); }
.menu-item:hover .menu-circle { color: var(--primary); box-shadow: var(--emboss-active); }

/* ── Scrim (mobile bottom-sheet backdrop only) ────────────── */
#scrim {
  position: fixed;
  top: calc(var(--safe-t) + var(--idbar-h));
  left: 0; right: 0; bottom: 0;
  background: rgba(4,3,8,0.60);
  opacity: 0; visibility: hidden;
  transition: opacity .25s, visibility .25s; z-index: 70;
}
#scrim.open { opacity: 1; visibility: visible; }
@media (min-width: 760px) { #scrim { display: none !important; } }

/* ── Panel (persistent desktop sidebar / full-height mobile sheet) ── */
#panel {
  position: fixed; z-index: 80;
  background: var(--surface-solid);
  display: flex; flex-direction: column; overflow: hidden;
  /* Mobile: bottom sheet stops below idbar */
  left: 0; right: 0; top: auto; bottom: 0;
  height: calc(100dvh - var(--safe-t) - var(--idbar-h));
  border-radius: 18px 18px 0 0;
  box-shadow: var(--emboss-lg);
  transform: translateY(110%);
  transition: transform .3s cubic-bezier(.2,.9,.3,1);
}
#panel.open { transform: translateY(0); }
@media (min-width: 760px) {
  #panel {
    top: 0; bottom: 0; right: 0; left: auto;
    width: 540px; height: 100%; border-radius: 0; padding-bottom: 0;
    box-shadow: inset 1px 0 0 rgba(210,185,130,0.08), -8px 0 32px rgba(0,0,0,0.60);
    transform: translateX(110%);
  }
  #panel.open { transform: translateX(0); }
}

.grab {
  width: 38px; height: 4px; border-radius: 2px;
  background: var(--border-2); margin: 10px auto 4px; flex-shrink: 0;
}
@media (min-width: 760px) { .grab { display: none; } }

.panel-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 18px; border-bottom: 0.5px solid var(--border-2); flex-shrink: 0;
  background: rgba(0,0,0,0.15);
}
.panel-head h2 {
  font-family: var(--font-display); font-size: 15px; font-weight: normal; letter-spacing: .04em;
  margin: 0; flex: 1; color: var(--text);
}
.panel-close {
  width: 32px; height: 32px; border-radius: 50%; border: none;
  background: var(--surface-2); box-shadow: var(--emboss);
  color: var(--text-2); display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.panel-close:active { box-shadow: var(--emboss-inset); }
.panel-close svg { width: 16px; height: 16px; }
.panel-body { padding: 16px 18px; overflow-y: auto; flex: 1; }

/* ── Panel tabs — equal-width tabular targets ─────────────── */
#panelTabs { flex-shrink: 0; }
.panel-tabs {
  display: grid;
  /* Auto columns rather than a fixed count — PANEL_TABS in ui.js is the
     single source of truth for how many tabs there are. */
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  border-bottom: 0.5px solid var(--border-2);
  background: rgba(0,0,0,0.15);
}
.panel-tab {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 9px 2px 8px; border: none; background: none; cursor: pointer;
  color: var(--text-3); font-family: var(--font-body); font-size: 10px;
  letter-spacing: .02em; position: relative;
  transition: color .15s;
}
.panel-tab svg { width: 18px; height: 18px; }
.panel-tab:hover  { color: var(--text-2); }
.panel-tab.active { color: var(--primary); }
.panel-tab.active::after {
  content: ""; position: absolute; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 60%; height: 2px; border-radius: 2px 2px 0 0; background: var(--primary);
}

/* ── Panel internals ──────────────────────────────────────── */
.field { margin-bottom: 20px; }
.field > label {
  display: block; font-size: 10px; font-weight: 700; color: var(--text-3);
  text-transform: uppercase; letter-spacing: .08em; margin-bottom: 10px;
}
.tool-grid { display: flex; gap: 8px; flex-wrap: wrap; }
.tool {
  flex: 1; min-width: 66px; padding: 10px 6px; border-radius: var(--radius-sm); border: none;
  background: var(--surface-2); box-shadow: var(--emboss);
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  font-size: 11px; color: var(--text-2); cursor: pointer; font-family: var(--font-body);
}
.tool:active { box-shadow: var(--emboss-inset); }
.tool.active  { color: var(--primary); box-shadow: var(--emboss-active); }
.tool svg { width: 22px; height: 22px; }

input[type=range] { width: 100%; accent-color: var(--primary); height: 28px; }

.shape-list { display: flex; flex-direction: column; gap: 1px; }
.drawing-item {
  display: flex; align-items: center; gap: 9px; padding: 8px;
  border-radius: 8px; font-size: 13px; cursor: pointer; color: var(--text);
}
.drawing-item:hover { background: var(--surface-2); }
.drawing-item.sel   { background: var(--info-soft); color: #7fa8d4; }
.sw-chip { width: 16px; height: 13px; border-radius: 3px; border: 0.5px solid var(--border-2); flex-shrink: 0; }
.sw-chip.kind-circle { border-radius: 50%; width: 14px; height: 14px; }
.meta { color: var(--text-3); font-size: 11px; margin-left: auto; }

/* Peers */
.peer-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 0.5px solid var(--border); }
.avatar { width: 32px; height: 32px; flex-shrink: 0; }
.pulse {
  width: 8px; height: 8px; border-radius: 50%; background: var(--primary); margin-left: auto; flex-shrink: 0;
  box-shadow: 0 0 6px var(--primary); animation: pulseGlow 2s ease-in-out infinite;
}
@keyframes pulseGlow { 0%,100%{opacity:1;box-shadow:0 0 4px var(--primary);}50%{opacity:.6;box-shadow:0 0 10px var(--primary);} }

.peer-invite a {
  display: block; width: 100%;
  font-size: 15px; font-weight: 700; color: var(--primary);
  font-family: ui-monospace, Menlo, monospace;
  word-break: break-all; text-decoration: none;
  background: var(--surface-2); box-shadow: var(--emboss-inset);
  padding: 10px 12px; border-radius: 8px;
}
.invite-block { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
.invite-url {
  display: block; width: 100%;
  font-size: 15px; font-weight: 700; color: var(--primary);
  font-family: ui-monospace, Menlo, monospace;
  word-break: break-all; text-decoration: none;
  background: var(--surface-2); box-shadow: var(--emboss-inset);
  padding: 10px 12px; border-radius: 8px;
}
.invite-url:hover { text-decoration: underline; }
.qr-gen-link {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 500; color: var(--text-2); text-decoration: none;
}
.qr-gen-link svg { border-radius: 2px; flex-shrink: 0; }
.qr-gen-link:hover { color: var(--primary); }
.row-btn { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 0; }
.toggle {
  width: 44px; height: 26px; border-radius: 13px;
  background: var(--surface-2); box-shadow: var(--emboss-inset);
  position: relative; cursor: pointer; transition: background .2s; flex-shrink: 0;
}
.toggle.on { background: var(--primary); box-shadow: var(--emboss-inset), 0 0 10px rgba(200,148,30,0.3); }
.toggle::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 20px; height: 20px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.5); transition: transform .2s;
}
.toggle.on::after { transform: translateX(18px); }

/* History */
.hist-item { display: flex; align-items: center; gap: 10px; padding: 9px 8px; border-radius: 8px; font-size: 13px; color: var(--text); min-height: 40px; }
.hist-item:first-child { background: var(--primary-soft); color: var(--primary); }
.hist-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
/* Same recipe as .layer-obj-list: 4 items visible, scroll for the rest. */
.hist-list {
  max-height: calc(4 * 40px);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: rgba(0,0,0,0.22);
  border: 0.5px solid var(--border);
  border-radius: 9px;
}

.action-btn {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 11px 12px; background: var(--surface-2); box-shadow: var(--emboss);
  border-radius: var(--radius-sm); color: var(--text); font-size: 13px;
  cursor: pointer; margin-bottom: 8px; font-family: var(--font-body); border: none;
}
.action-btn:active { box-shadow: var(--emboss-inset); }
.action-btn svg { width: 18px; height: 18px; color: var(--text-2); }

/* Layers */
.layer-block { margin-bottom: 6px; }

.layer {
  display: flex; align-items: center; gap: 10px; padding: 10px;
  border-radius: 9px; font-size: 13px; margin-bottom: 0;
  background: var(--surface-2); box-shadow: var(--emboss);
  cursor: pointer; color: var(--text); border: none; font-family: var(--font-body);
}
.layer-block .layer:has(+ .layer-obj-list) { border-radius: 9px 9px 0 0; }
.layer:active { box-shadow: var(--emboss-inset); }
.layer.active  { color: var(--primary); box-shadow: var(--emboss-active); }
.layer svg { width: 18px; height: 18px; flex-shrink: 0; }
.layer .lmeta { font-size: 11px; color: var(--text-3); margin-left: auto; }

/* Object list beneath the active layer row */
.layer-obj-list {
  max-height: calc(4 * 40px);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: rgba(0,0,0,0.22);
  border: 0.5px solid var(--border);
  border-top: none;
  border-radius: 0 0 9px 9px;
}
.layer-obj-item {
  display: flex; align-items: center; gap: 8px;
  padding: 11px 12px; font-size: 13px; color: var(--text-2);
  cursor: pointer; border-bottom: 0.5px solid var(--border);
  transition: background .1s;
  min-height: 40px;
}
.layer-obj-item:last-child { border-bottom: none; }
.layer-obj-item:hover { background: rgba(255,255,255,0.05); color: var(--text); }
.layer-obj-item.sel  { background: var(--primary-soft); color: var(--primary); }
.layer-obj-label { flex: 1; text-transform: capitalize; }
.layer-obj-empty {
  padding: 10px 12px; font-size: 12px; color: var(--text-3); min-height: 40px;
  display: flex; align-items: center;
}

.bg-preset-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.bg-preset {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  cursor: pointer; padding: 6px; border-radius: 8px;
  background: var(--surface-2); box-shadow: var(--emboss);
  font-size: 11px; color: var(--text-3);
  transition: box-shadow .15s, color .15s;
}
.bg-preset:hover { box-shadow: var(--emboss-active); color: var(--text); }
.bg-preset img {
  width: 100%; aspect-ratio: 4/3; object-fit: cover;
  border-radius: 5px; display: block;
}

/* ── Tool icon loading state ─────────────────────────────────────────────── */
@keyframes tt-icon-pulse {
  0%, 100% { opacity: 0.9; }
  50%       { opacity: 0.25; }
}
svg.tt-icon-letter {
  animation: tt-icon-pulse 1.2s ease-in-out infinite;
}

/* ── Bowstring handle (delight.js / #delight-layer) ───────────────────────── */

/* The resting affordance in #overlay-layer. The live handle is built in
 * #delight-layer on pointerdown and is a separate DOM tree entirely. */
.bowstring { pointer-events: auto; cursor: grab; }
#delight-layer { pointer-events: none; }

/* Press-scale lives on its own transform layer, separate from the
 * position+rotation transform on the parent .handleGroup, so the two can
 * animate independently without clobbering each other. */
.handleVisual {
  transform-box: fill-box;
  transform-origin: center;
  transition: transform 90ms cubic-bezier(.34, 1.56, .64, 1);
}

/* Delight echoes: the skew loop is entirely declarative once the element
 * exists. The one live value JS contributes — the pull parallax — is read
 * from --drag-x/--drag-y INSIDE the keyframes, because a CSS animation on
 * `transform` would otherwise silently override any transform attribute JS
 * set on the same element. */
.selRing-delight-0,
.selRing-delight-1,
.toy-delight {
  transform-box: fill-box;
  transform-origin: center;
  pointer-events: none;
}
.selRing-delight-0 { animation: ring-skew-0 3.2s ease-in-out infinite; }
.selRing-delight-1 { animation: ring-skew-1 2.4s ease-in-out infinite; }
.toy-delight {
  opacity: 0.5;
  animation: ring-skew-1 2.4s ease-in-out infinite;
}

@keyframes ring-skew-0 {
  0%, 100% { transform: translate(var(--drag-x, 0px), var(--drag-y, 0px)) skewX(0deg); }
  50%      { transform: translate(var(--drag-x, 0px), var(--drag-y, 0px)) skewX(-6deg); }
}
@keyframes ring-skew-1 {
  0%, 100% { transform: translate(var(--drag-x, 0px), var(--drag-y, 0px)) skewX(0deg); }
  50%      { transform: translate(var(--drag-x, 0px), var(--drag-y, 0px)) skewX(4deg); }
}

.spark {
  pointer-events: none;
  animation: spark-burst var(--spark-duration, 500ms) cubic-bezier(.2,.7,.3,1) forwards;
}
@keyframes spark-burst {
  0%   { transform: translate(0px, 0px); opacity: 1; }
  100% { transform: translate(var(--tx), var(--ty)); opacity: 0; }
}

/* ── Debug panel (debug_panel.js) ──────────────────────────────
   Dense, monospace, information-first. This is the one panel that should
   look like an instrument rather than a control: nothing here is a thing
   you do to the table, it is all a readout of what the table already did. */

.dbg-section { border-bottom: 0.5px solid var(--border); }
.dbg-summary {
  display: flex; align-items: center; gap: 8px; cursor: pointer;
  padding: 10px 2px; list-style: none; user-select: none;
}
.dbg-summary::-webkit-details-marker { display: none; }
.dbg-summary::before {
  content: "▸"; color: var(--text-3); font-size: 14px; width: 10px;
  transition: transform .15s;
}
.dbg-section[open] > .dbg-summary::before { transform: rotate(90deg); }
.dbg-sec-title {
  flex: 1; font-size: 14px; font-weight: 700; color: var(--text-3);
  text-transform: uppercase; letter-spacing: .08em;
}
.dbg-sec-meta { font-size: 15px; color: var(--text-2); font-family: ui-monospace, monospace; }
.dbg-section-body { padding: 2px 0 14px; }

/* Cards */
.dbg-card {
  background: rgba(0,0,0,0.22); border-radius: var(--radius-sm);
  padding: 10px 12px; margin-bottom: 8px;
  box-shadow: inset 0 0 0 1px var(--border);
}
.dbg-card.warn { box-shadow: inset 0 0 0 1px rgba(184,120,32,0.45); }
.dbg-card-title {
  font-size: 14px; font-weight: 700; color: var(--text-2);
  text-transform: uppercase; letter-spacing: .08em; margin-bottom: 8px;
}
.dbg-kv {
  display: flex; gap: 10px; align-items: baseline;
  padding: 3px 0; font-size: 15px; line-height: 1.5;
}
.dbg-k { color: var(--text-3); flex: 0 0 40%; }
.dbg-v { color: var(--text); flex: 1; min-width: 0; word-break: break-word; }
.dbg-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 15px;
  background: rgba(0,0,0,0.35); border-radius: 4px; padding: 1px 5px;
  color: var(--text-2);
}
.dbg-id.me { color: var(--primary); box-shadow: inset 0 0 0 1px rgba(200,148,30,0.4); }
.dbg-nil { color: var(--text-3); font-style: italic; }
.dbg-ok  { color: #6a9a6a; }
.dbg-bad { color: var(--warn); }
.dbg-note { font-size: 15px; color: var(--text-3); margin-top: 8px; line-height: 1.5; }
.dbg-alert {
  margin-top: 8px; padding: 8px 10px; border-radius: 8px;
  background: var(--warn-soft); color: var(--text); font-size: 15px; line-height: 1.5;
}
.dbg-empty { font-size: 15px; color: var(--text-3); padding: 10px 2px; }

/* JSON blocks — wire packets and event detail */
.dbg-json {
  margin: 6px 0 0; padding: 8px 10px; max-height: 320px; overflow: auto;
  background: #0b0812; border-radius: 8px; box-shadow: inset 0 0 0 1px var(--border);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px; line-height: 1.5; color: var(--text-2);
  white-space: pre; -webkit-overflow-scrolling: touch;
}

/* Operations */
.dbg-op-list { display: flex; flex-direction: column; gap: 2px; }
.dbg-op { border-radius: 6px; background: rgba(0,0,0,0.18); }
.dbg-op-sum {
  display: flex; align-items: center; gap: 7px; cursor: pointer;
  padding: 6px 8px; list-style: none; font-size: 15px;
}
.dbg-op-sum::-webkit-details-marker { display: none; }
.dbg-op-i {
  font-family: ui-monospace, monospace; font-size: 14px; color: var(--text-3);
  min-width: 22px; text-align: right;
}
.dbg-op-gesture {
  flex: 1; color: var(--text); font-family: ui-monospace, monospace; font-size: 15px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.dbg-op-entries { font-size: 14px; color: var(--text-3); font-family: ui-monospace, monospace; }
.dbg-op-body { padding: 4px 10px 10px; }
.dbg-tag {
  font-size: 12px; text-transform: uppercase; letter-spacing: .06em;
  padding: 1px 5px; border-radius: 4px; color: var(--text-3);
  box-shadow: inset 0 0 0 1px var(--border);
}
.dbg-tag.mine { color: var(--primary); box-shadow: inset 0 0 0 1px rgba(200,148,30,0.4); }
.dbg-tag.head { color: #6a9a6a; box-shadow: inset 0 0 0 1px rgba(106,154,106,0.4); }
.dbg-wire-label {
  display: flex; align-items: center; gap: 8px; margin-top: 10px;
  font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3);
}

/* Channel chips */
.dbg-chips { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 8px; }
.dbg-chip {
  display: inline-flex; align-items: center; gap: 5px; cursor: pointer;
  border: none; border-radius: 999px; padding: 4px 9px;
  background: var(--surface-2); box-shadow: var(--emboss);
  color: var(--text-3); font-family: var(--font-body); font-size: 15px;
}
.dbg-chip.on { color: var(--primary); box-shadow: var(--emboss-active); }
.dbg-chip-n { font-family: ui-monospace, monospace; font-size: 14px; opacity: .8; }

/* Event stream */
.dbg-stream {
  max-height: 42vh; overflow-y: auto; overscroll-behavior: contain;
  background: rgba(0,0,0,0.22); border-radius: var(--radius-sm);
  box-shadow: inset 0 0 0 1px var(--border); padding: 4px;
}
.dbg-ev { border-radius: 5px; }
.dbg-ev + .dbg-ev { border-top: 0.5px solid var(--border); }
.dbg-ev-sum, .dbg-ev.flat {
  display: flex; align-items: baseline; gap: 7px; padding: 4px 6px;
  list-style: none; font-size: 15px; line-height: 1.45;
}
.dbg-ev-sum { cursor: pointer; }
.dbg-ev-sum::-webkit-details-marker { display: none; }
.dbg-ev-seq {
  font-family: ui-monospace, monospace; font-size: 9.5px; color: var(--text-3);
  min-width: 28px; text-align: right; flex-shrink: 0;
}
.dbg-ev-time {
  font-family: ui-monospace, monospace; font-size: 9.5px; color: var(--text-3);
  flex-shrink: 0;
}
.dbg-ev-ch {
  font-size: 9px; text-transform: uppercase; letter-spacing: .05em;
  padding: 1px 5px; border-radius: 4px; flex-shrink: 0;
  background: rgba(255,255,255,0.04); color: var(--text-2);
}
.dbg-ev-ch.ch-boot     { color: #8a7fc0; }
.dbg-ev-ch.ch-net      { color: #5a9ec0; }
.dbg-ev-ch.ch-op       { color: var(--primary); }
.dbg-ev-ch.ch-envelope { color: #6a9a6a; }
.dbg-ev-ch.ch-wire     { color: #a07ba0; }
.dbg-ev-ch.ch-app      { color: var(--text-2); }
.dbg-ev-msg { flex: 1; color: var(--text); min-width: 0; word-break: break-word; }
.dbg-ev.lvl-warn  { background: rgba(184,120,32,0.10); }
.dbg-ev.lvl-error { background: rgba(139,42,42,0.18); }
.dbg-ev.lvl-error .dbg-ev-msg { color: #d8a0a0; }
.dbg-ev .dbg-json { margin: 0 6px 6px 28px; }

/* Buttons */
.dbg-btn-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.dbg-btn {
  flex: 1; min-width: 108px; border: none; border-radius: var(--radius-sm);
  padding: 8px 10px; cursor: pointer;
  background: var(--surface-2); box-shadow: var(--emboss);
  color: var(--text-2); font-family: var(--font-body); font-size: 12px;
}
.dbg-btn:active { box-shadow: var(--emboss-inset); }
.dbg-mini {
  border: none; border-radius: 5px; padding: 2px 7px; cursor: pointer;
  background: var(--surface-2); box-shadow: var(--emboss);
  color: var(--text-2); font-family: var(--font-body); font-size: 10px;
}
.dbg-mini:active { box-shadow: var(--emboss-inset); }
