/* ==========================================================================
   Diagrama — layout, then the twelve themes.

   A theme is nothing but a set of custom properties plus a few flourish rules
   for the ground and the strokes. Switching theme repaints the whole diagram
   because every colour in the canvas is a var() reference, so there is no
   per-theme drawing code and no flash.
   ========================================================================== */

/* A [hidden] element must never be resurrected by a later display rule. The
   quickbar and the help sheet both stayed on screen after being dismissed
   because a more specific display rule won; this guard ends that whole class
   of bug for every element in the app. */
[hidden] { display: none !important; }

:root {
  --ui-bg: #101722;
  --ui-panel: #16202e;
  --ui-line: #24344a;
  --ui-text: #e8eef7;
  --ui-dim: #93a4bd;
  --ui-accent: #4ea8ff;
  --ui-radius: 10px;
  --topbar-h: 52px;
  --quickbar-h: 60px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%; overflow: hidden;
  background: var(--ui-bg); color: var(--ui-text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

/* ------------------------------------------------------------------ topbar */
#topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--topbar-h); z-index: 40;
  display: flex; align-items: center; gap: 8px; padding: 0 10px;
  background: color-mix(in srgb, var(--ui-panel) 92%, transparent);
  border-bottom: 1px solid var(--ui-line);
  backdrop-filter: blur(8px);
}
.name-input {
  flex: 1; min-width: 0; background: transparent; border: 0; color: var(--ui-text);
  font: 600 16px/1 inherit; padding: 8px 6px; border-radius: 8px;
}
.name-input:focus { background: #0c121b; outline: 2px solid var(--ui-accent); outline-offset: -2px; }
.top-actions { display: flex; gap: 6px; }

.icon-btn, .chip, .float-btn, .quick-btn, .seg-btn, .danger {
  font: inherit; color: var(--ui-text); background: #1d2a3b;
  border: 1px solid var(--ui-line); border-radius: 9px;
  padding: 9px 12px; cursor: pointer; min-height: 40px;
}
.chip[aria-pressed="true"], .chip.active { background: var(--ui-accent); border-color: var(--ui-accent); color: #06111c; }
.chip.wide { width: 100%; }
/* The way back to the front page, wearing a chip's shape so the topbar stays a
   single row on a phone. */
.home-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 12px; border: 1px solid var(--ui-line); border-radius: 999px;
  background: var(--ui-panel); color: var(--ui-text);
  font: inherit; font-size: 13px; text-decoration: none; white-space: nowrap;
}
.home-btn:hover { border-color: var(--ui-accent); }
@media (max-width: 620px) {
  .home-btn .btn-text { display: none; }
  .home-btn { padding: 8px 11px; }
}
.icon-btn { width: 40px; padding: 0; display: grid; place-items: center; }
.burger, .burger::before, .burger::after {
  display: block; width: 18px; height: 2px; background: currentColor; content: "";
}
.burger { position: relative; }
.burger::before { position: absolute; top: -6px; }
.burger::after { position: absolute; top: 6px; }

.menu {
  position: fixed; top: calc(var(--topbar-h) + 6px); right: 8px; z-index: 60;
  background: var(--ui-panel); border: 1px solid var(--ui-line); border-radius: 12px;
  padding: 6px; min-width: 210px; box-shadow: 0 18px 40px #0008;
}
.menu button {
  display: block; width: 100%; text-align: left; background: none; border: 0;
  color: var(--ui-text); font: inherit; padding: 11px 12px; border-radius: 8px; cursor: pointer;
}
.menu button:hover { background: #223146; }
.menu hr { border: 0; border-top: 1px solid var(--ui-line); margin: 5px 8px; }

/* ------------------------------------------------------------------- panel */
#panel {
  position: fixed; z-index: 35; top: var(--topbar-h); bottom: 0; left: 0; width: 342px;
  background: var(--ui-panel); border-right: 1px solid var(--ui-line);
  transform: translateX(-100%); transition: transform .22s ease;
}
#panel.open { transform: none; }
.panel-scroll { height: 100%; overflow-y: auto; padding: 14px; }
.panel-block { margin-bottom: 22px; }
.panel-block h2 {
  font-size: 12px; text-transform: uppercase; letter-spacing: .1em;
  color: var(--ui-dim); margin: 0 0 8px;
}
.hint { color: var(--ui-dim); font-size: 12.5px; margin: 0 0 10px; }

#scrim { position: fixed; inset: 0; z-index: 30; background: #0008; }

.demo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.demo-card {
  text-align: left; background: #1b2736; border: 1px solid var(--ui-line);
  border-radius: 10px; padding: 10px; cursor: pointer; color: var(--ui-text); font: inherit;
}
.demo-card:hover { border-color: var(--ui-accent); }
.demo-card b { display: block; font-size: 13px; }
.demo-card span { display: block; color: var(--ui-dim); font-size: 11.5px; margin-top: 3px; }
.demo-card.on { border-color: var(--ui-accent); box-shadow: inset 0 0 0 1px var(--ui-accent); }

.theme-group { margin-bottom: 12px; }
.theme-group h3 {
  font-size: 11px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--ui-dim); margin: 0 0 6px;
}
.theme-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.theme-btn {
  position: relative; height: 54px; border-radius: 9px; cursor: pointer;
  border: 1px solid var(--ui-line); color: #fff; font: 600 10.5px/1.15 inherit;
  padding: 6px 5px 5px; text-align: left; overflow: hidden;
  display: flex; align-items: flex-end;
}
.theme-btn.on { outline: 2px solid var(--ui-accent); outline-offset: 1px; }
.theme-btn em { position: absolute; inset: auto 5px 5px auto; font-style: normal; opacity: .9; }

.seg { display: flex; gap: 6px; margin-bottom: 8px; }
.seg-btn { flex: 1; font-size: 12.5px; padding: 9px 8px; }
.seg-btn.on { background: var(--ui-accent); border-color: var(--ui-accent); color: #06111c; }

.slider { display: block; font-size: 12.5px; color: var(--ui-dim); margin-bottom: 10px; }
.slider input { width: 100%; margin-top: 4px; accent-color: var(--ui-accent); }
.slider output { float: right; color: var(--ui-text); }

.field { display: block; margin-bottom: 10px; font-size: 12.5px; color: var(--ui-dim); }
.field input, .field select {
  width: 100%; margin-top: 4px; padding: 10px; border-radius: 8px; font: inherit;
  background: #101722; color: var(--ui-text); border: 1px solid var(--ui-line);
}
.field > span { display: block; margin-bottom: 2px; }
.tones { display: flex; gap: 7px; margin-top: 6px; }
.tone-dot {
  width: 34px; height: 34px; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent; background: var(--tone);
}
.tone-dot.on { border-color: #fff; }

.danger { width: 100%; background: #4a1f27; border-color: #7d3542; color: #ffd9df; }

.peek {
  background: #0b1119; border: 1px solid var(--ui-line); border-radius: 8px;
  padding: 9px; font: 11px/1.45 ui-monospace, Menlo, monospace; color: #9dd3ff;
  max-height: 190px; overflow: auto; white-space: pre; margin: 0 0 8px;
}

/* ------------------------------------------------------------------ canvas */
#stage-wrap { position: fixed; inset: var(--topbar-h) 0 0 0; }
#canvas { width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#canvas.dragging { cursor: grabbing; }

#canvas-controls {
  position: absolute; right: 10px; bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: 7px; z-index: 20;
}
.float-btn { width: 44px; height: 44px; padding: 0; font-size: 19px; line-height: 1; }

.status {
  position: absolute; left: 10px; bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  background: #0d1520cc; border: 1px solid var(--ui-line); border-radius: 8px;
  padding: 6px 10px; font-size: 12px; color: var(--ui-dim); max-width: 60vw;
  pointer-events: none;
}
.warnings {
  position: absolute; left: 10px; top: 10px; right: 10px;
  background: #3a2a12; border: 1px solid #7c5a1f; color: #ffe6b8;
  border-radius: 10px; padding: 10px 12px; font-size: 12.5px; z-index: 22;
}
.warnings ul { margin: 6px 0 0; padding-left: 18px; }
.empty-hint {
  position: absolute; inset: auto 0 50% 0; text-align: center; color: var(--ui-dim);
  pointer-events: none; font-size: 14px; line-height: 1.7;
}
.empty-hint strong { color: var(--ui-text); }
.empty-hint span { font-size: 12.5px; }
/* covered by the global [hidden] guard above */

/* ----------------------------------------------------------------- elements */
/* The accent slot. Every stroked part of a node or edge is drawn with --tone,
   which the .tone-N class fills in from the theme's palette. Without these rules
   --tone is undefined, the var() resolves to nothing, and stroke falls back to
   its INITIAL value — none — so every outline and every edge vanishes with no
   error anywhere. Each theme defines --t0..--t5. */
.tone-0 { --tone: var(--t0); }
.tone-1 { --tone: var(--t1); }
.tone-2 { --tone: var(--t2); }
.tone-3 { --tone: var(--t3); }
.tone-4 { --tone: var(--t4); }
.tone-5 { --tone: var(--t5); }

.node { cursor: pointer; }
.node-shape {
  stroke-linejoin: round;
  stroke-width: 1.7;
  vector-effect: non-scaling-stroke;
}
.node.dim { opacity: .28; }
.node.connectable .node-shape { stroke-dasharray: 5 4; }
.node-ring { fill: none; stroke-width: 2.5; vector-effect: non-scaling-stroke; opacity: 0; cursor: crosshair; }
.node.selected .node-ring, .node:hover .node-ring { opacity: 1; }
.node-label { font-weight: 600; pointer-events: none; }
.node-value { pointer-events: none; }
.node-glyph { pointer-events: none; }
.edge-path {
  stroke-width: 1.9;
  /* Screen-space strokes: an outline that shrinks with the zoom disappears exactly
     when the diagram is small enough that you need it most. */
  vector-effect: non-scaling-stroke;
}
.edge-hit { stroke: transparent; stroke-width: 22; fill: none; cursor: pointer; vector-effect: non-scaling-stroke; }
.edge.selected .edge-path { stroke-width: 3.4; }
.edge-label { font-size: 10.5px; pointer-events: none; }
.edge.dim { opacity: .2; }

.legend text { font-size: 11px; }

/* Layer guides are scaffolding. A filled panel per layer competes with the nodes —
   on a dark theme the pale guide box reads as the node and the real node disappears
   inside it. A faint dashed outline marks the layer without claiming to be content. */
.layer-guide rect {
  fill: none;
  stroke: var(--grid-strong);
  stroke-dasharray: 7 7;
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  opacity: .5;
}
.layer-guide text { opacity: .75; }

/* ==========================================================================
   The themes. Each block sets the same variables; the flourish rules after it
   are the ones that need more than a colour.
   ========================================================================== */

/* ---------------------------------------------------------------- sci-fi -- */
.theme-neon {
  --ground: #04070e; --grid: #0e2f45; --grid-strong: #12455f; --grid-opacity: .5;
  --node-fill: #0a1f2e; --node-stroke: #4fd6ff; --node-text: #dcf8ff; --node-value: #79cdea;
  --edge: #3fa9c8; --edge-text: #8fd8f0;
  --label-font: ui-monospace, "SF Mono", Menlo, monospace; --label-spacing: .04em;
  --node-radius: 9; --glow: drop-shadow(0 0 6px #4fd6ff66);
  --t0: #4fd6ff; --t1: #56ffcf; --t2: #b98cff; --t3: #ffd166; --t4: #ff6b9d; --t5: #7f8cff;
}
.theme-neon .node-shape { filter: var(--glow); }
.theme-neon .node-label { letter-spacing: .06em; text-transform: uppercase; font-size: 10.5px; }

.theme-cyberdeck {
  --ground: #0d0b08; --grid: #2b2113; --grid-strong: #43331c; --grid-opacity: .55;
  --node-fill: #1a1610; --node-stroke: #ffb347; --node-text: #ffe3b0; --node-value: #d9a45c;
  --edge: #b47a2a; --edge-text: #e8bd7a;
  --label-font: ui-monospace, "SF Mono", Menlo, monospace; --label-spacing: .05em;
  --node-radius: 3; --glow: drop-shadow(0 0 5px #ffb34755);
  --t0: #ffb347; --t1: #ff7f50; --t2: #d4ff5e; --t3: #6fd3c7; --t4: #e05a5a; --t5: #cfae7a;
}
.theme-cyberdeck .node-shape { filter: var(--glow); }
.theme-cyberdeck #grid { opacity: .35; }
.theme-cyberdeck .node-label { text-transform: uppercase; letter-spacing: .08em; }

.theme-deepspace {
  --ground: #07060f; --grid: #1b1636; --grid-strong: #2a2154; --grid-opacity: .45;
  --node-fill: #150f2c; --node-stroke: #a98cff; --node-text: #ecdcff; --node-value: #b6a2f0;
  --edge: #6f5fd0; --edge-text: #b9aaf5;
  --label-font: system-ui, sans-serif; --node-radius: 14; --glow: drop-shadow(0 0 8px #a98cff4d);
  --t0: #a98cff; --t1: #55e6c1; --t2: #ff93c4; --t3: #ffe08a; --t4: #6ec6ff; --t5: #c3b1ff;
}
.theme-deepspace #grid { opacity: .22; }
.theme-deepspace .node-shape { filter: var(--glow); }

/* ------------------------------------------------------------------- tech -- */
.theme-blueprint {
  --ground: #0b3a6b; --grid: #17518f; --grid-strong: #2a6cad; --grid-opacity: .9;
  --node-fill: #0e4478; --node-stroke: #dbeaff; --node-text: #f2f7ff; --node-value: #bcd8f7;
  --edge: #cfe2f7; --edge-text: #dceafc;
  --label-font: ui-monospace, "SF Mono", Menlo, monospace; --label-spacing: .04em;
  --node-radius: 2;
  --t0: #ffffff; --t1: #ffd166; --t2: #7ee7c7; --t3: #ff9db1; --t4: #c0a6ff; --t5: #9fd0ff;
}
.theme-blueprint .node-shape { fill: none; stroke-width: 1.6; }
.theme-blueprint .node-label { text-transform: uppercase; letter-spacing: .07em; font-size: 10.5px; }

.theme-terminal {
  --ground: #000000; --grid: #07220c; --grid-strong: #0d3a15; --grid-opacity: .8;
  --node-fill: #04160a; --node-stroke: #46d160; --node-text: #b9f5c4; --node-value: #6fdc85;
  --edge: #2f9448; --edge-text: #78e08d;
  --label-font: ui-monospace, "SF Mono", Menlo, monospace; --label-spacing: .03em;
  --node-radius: 0; --glow: drop-shadow(0 0 4px #46d16055);
  --t0: #46d160; --t1: #ffd166; --t2: #ff7b72; --t3: #6ec6ff; --t4: #c792ea; --t5: #8ee6a0;
}
.theme-terminal .node-shape { filter: var(--glow); }
.theme-terminal #grid { opacity: .5; }

.theme-circuit {
  --ground: #05211c; --grid: #0c3a30; --grid-strong: #14584a; --grid-opacity: .8;
  --node-fill: #0a2f27; --node-stroke: #d9a441; --node-text: #f4e6c8; --node-value: #c9a86a;
  --edge: #c98f34; --edge-text: #e5c184;
  --label-font: ui-monospace, "SF Mono", Menlo, monospace; --node-radius: 4;
  --t0: #d9a441; --t1: #6fd3a0; --t2: #7fd4ff; --t3: #ff9f7a; --t4: #e0e28a; --t5: #b9c9d0;
}
.theme-circuit .node-shape, .theme-circuit .edge-path { stroke-width: 1.7; }

/* --------------------------------------------------------------- commercial */
.theme-corporate {
  --ground: #ffffff; --grid: #e8eef6; --grid-strong: #d3dfec; --grid-opacity: 1;
  --node-fill: #ffffff; --node-stroke: #1c4f8f; --node-text: #10233b; --node-value: #516780;
  --edge: #6c86a6; --edge-text: #4c6483;
  --label-font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; --node-radius: 8;
  --t0: #1c4f8f; --t1: #2f9e7a; --t2: #b8543b; --t3: #7a5ac2; --t4: #c99000; --t5: #4a7fb5;
}
.theme-corporate .node-shape { stroke-width: 1.6; }
.theme-corporate #canvas { cursor: grab; }

.theme-consulting {
  --ground: #f7f5f0; --grid: #e6e2d8; --grid-strong: #d8d3c6; --grid-opacity: 1;
  --node-fill: #ffffff; --node-stroke: #4a5a6a; --node-text: #23303c; --node-value: #6a7784;
  --edge: #8d9aa6; --edge-text: #5d6a76;
  --label-font: "Iowan Old Style", Georgia, "Times New Roman", serif; --node-radius: 6;
  --t0: #4a5a6a; --t1: #35707a; --t2: #8a6a3a; --t3: #6b5a86; --t4: #a35d52; --t5: #5b7f68;
}
.theme-consulting .node-label { letter-spacing: .01em; }

.theme-slate {
  --ground: #1b2027; --grid: #262e38; --grid-strong: #333c48; --grid-opacity: .9;
  --node-fill: #2b323c; --node-stroke: #8fa6bd; --node-text: #f2f6fa; --node-value: #b6c4d2;
  --edge: #7d90a5; --edge-text: #c2d0de;
  --label-font: system-ui, sans-serif; --node-radius: 7;
  --t0: #6fd0ff; --t1: #7ee2a8; --t2: #ffcc66; --t3: #ff8fa3; --t4: #c3a6ff; --t5: #d5dee7;
}
.theme-slate .node-shape { stroke-width: 1.5; }

/* ---------------------------------------------------------------- artistic -- */
.theme-sketch {
  --ground: #fdfcf7; --grid: #efece2; --grid-strong: #e3ded1; --grid-opacity: 1;
  --node-fill: #ffffff; --node-stroke: #3a3a3a; --node-text: #2c2c2c; --node-value: #6d6d6d;
  --edge: #6f6f6f; --edge-text: #5a5a5a;
  --label-font: "Bradley Hand", "Segoe Print", "Comic Sans MS", cursive, sans-serif;
  --node-radius: 12;
  --t0: #3a3a3a; --t1: #7a6a4f; --t2: #5c6b52; --t3: #7b5a5a; --t4: #4f5a70; --t5: #8a8a8a;
}
.theme-sketch .node-shape { stroke-width: 1.9; stroke-dasharray: 62 3 30 2; }
.theme-sketch .edge-path { stroke-dasharray: 40 3 18 2; }
.theme-sketch .node-label { font-size: 13px; }

.theme-watercolour {
  --ground: #fffdf9; --grid: #f2ece2; --grid-strong: #e8e0d2; --grid-opacity: 1;
  --node-fill: #eaf3fb; --node-stroke: #7fa8c9; --node-text: #2e4356; --node-value: #5b7285;
  --edge: #9db8cd; --edge-text: #5f7a90;
  --label-font: "Iowan Old Style", Georgia, serif; --node-radius: 16;
  --t0: #7fa8c9; --t1: #86c39c; --t2: #e2a86a; --t3: #c48fae; --t4: #92a6d6; --t5: #b8ada0;
}
.theme-watercolour .node-shape { fill-opacity: .92; filter: url(#bleed); stroke-width: 1.2; }
.theme-watercolour .edge-path { stroke-opacity: .75; }

.theme-ink {
  --ground: #fbf7ee; --grid: #efe9dc; --grid-strong: #e2dac8; --grid-opacity: 1;
  --node-fill: #fffdf8; --node-stroke: #14110e; --node-text: #14110e; --node-value: #5b544a;
  --edge: #14110e; --edge-text: #3b352d;
  --label-font: "Iowan Old Style", Georgia, serif; --node-radius: 5;
  --t0: #14110e; --t1: #b23a2e; --t2: #2f5d50; --t3: #7a5c2e; --t4: #3c4a6b; --t5: #6b6459;
}
.theme-ink .node-shape { stroke-width: 1.8; }
.theme-ink .node-label { letter-spacing: .01em; }

/* ==========================================================================
   Portrait / phone
   ========================================================================== */
@media (max-width: 860px) {
  #panel { width: min(94vw, 380px); box-shadow: 16px 0 40px #0007; }
  #stage-wrap { bottom: 0; }
  .status { bottom: calc(var(--quickbar-h) + 10px + env(safe-area-inset-bottom, 0px)); }
  #canvas-controls {
    bottom: auto; top: 10px; right: 10px; flex-direction: row;
  }
  body #quickbar { display: flex; }
  .empty-hint { bottom: 42%; }
  .demo-grid { grid-template-columns: 1fr; }
}

#quickbar {
  display: none; position: fixed; inset: auto 0 0 0; z-index: 38;
  gap: 8px; padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px));
  background: color-mix(in srgb, var(--ui-panel) 94%, transparent);
  border-top: 1px solid var(--ui-line); backdrop-filter: blur(8px);
}
.quick-btn { flex: 1; font-size: 14px; }
.quick-btn.primary { background: var(--ui-accent); border-color: var(--ui-accent); color: #06111c; font-weight: 600; }

/* ------------------------------------------------------------------- sheet */
.sheet { position: fixed; inset: 0; z-index: 70; background: #000a; display: grid; place-items: center; padding: 16px; }
.sheet-inner {
  background: var(--ui-panel); border: 1px solid var(--ui-line); border-radius: 14px;
  padding: 18px; max-width: 520px; width: 100%; max-height: 86vh; overflow: auto;
}
.sheet-inner h2 { margin: 0 0 12px; font-size: 17px; }
.sheet dt { font-weight: 600; margin-top: 12px; }
.sheet dd { margin: 4px 0 0; color: var(--ui-dim); font-size: 13.5px; }
.sheet button { margin-top: 16px; }

@media (prefers-reduced-motion: reduce) { #panel { transition: none; } }

/* ------------------------------------------------------- what a tap does --- */
/* A pill of chips over the canvas. Select, Edit and Collapse mean different
 * things to the same gesture, so the choice is visible rather than remembered. */
#tapbar {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 5px; z-index: 6; padding: 5px; border-radius: 999px;
  background: color-mix(in srgb, var(--ground) 76%, transparent);
  border: 1px solid var(--ui-line); backdrop-filter: blur(9px);
}
#tapbar .tap-btn { font-size: 12px; padding: 5px 11px; }
#tapbar .tap-btn[disabled] { opacity: .4; cursor: not-allowed; }
#tapbar .tap-btn.on { background: var(--ui-accent); border-color: var(--ui-accent); color: #06111c; font-weight: 600; }
#canvas.creating { cursor: crosshair; }
.chip-row { display: flex; flex-wrap: wrap; gap: 5px; }
.layout-chip { font-size: 11.5px; padding: 5px 10px; }
.layout-chip.on { background: var(--ui-accent); border-color: var(--ui-accent); color: #06111c; font-weight: 600; }
.sub { font-size: 11.5px; text-transform: uppercase; letter-spacing: .1em; opacity: .72; margin: 14px 0 6px; }
.row-btns { display: flex; gap: 6px; flex-wrap: wrap; }
#multi-fields .sub { color: var(--ui-accent); opacity: 1; font-size: 13px; letter-spacing: .02em; }

/* ------------------------------------------------------------ node parts --- */
/* Text, count chips and group frames are decoration: the interaction layer
 * hit-tests in model coordinates, so nothing here needs to catch a pointer. */
.node-text, .node-count, .group-box, .band-stripe { pointer-events: none; }
/* A node with a non-default accent wears it in its fill as well as its outline,
 * so a diagram that colour-codes its nodes (permanent, contractor, vacant) reads
 * as one at a glance instead of hiding the code in a stroke. Tone 0 is the theme's
 * own accent, so leaving it alone keeps every existing diagram looking as it did. */
.node:not(.tone-0) .node-shape { fill: color-mix(in srgb, var(--node-fill) 78%, var(--tone)); }
.node:not(.tone-0) .node-glyph { stroke: color-mix(in srgb, var(--tone) 70%, var(--node-text)); }
.node.highlighted .node-shape { stroke: var(--t0); stroke-width: 2.1; }
.node.collapsed .node-shape { stroke-dasharray: 6 4; }
.node-count rect { fill: color-mix(in srgb, var(--ground) 82%, transparent); opacity: .92; }
.node-count text { opacity: .88; }
.node-count.folded rect { fill: var(--t0); }
.node-count.folded text { fill: #06111c; opacity: 1; font-weight: 600; }
.edge.dim { opacity: .2; }
.edge.selected .edge-path { stroke-width: 3; }
.group-frame { opacity: .34; }
.group-label { opacity: .5; }
.band-stripe rect { pointer-events: none; }

/* ------------------------------------------------------------ type faces --- */
:root {
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-serif: "Iowan Old Style", Georgia, "Times New Roman", serif;
  --font-slab: Rockwell, "Roboto Slab", "Courier New", Georgia, serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --font-rounded: ui-rounded, "Avenir Next Rounded", Nunito, "Segoe UI", system-ui, sans-serif;
  --font-condensed: "Arial Narrow", "Roboto Condensed", "Helvetica Neue", system-ui, sans-serif;
  --font-hand: "Bradley Hand", "Segoe Print", "Comic Sans MS", cursive;
  --font-display: Futura, "Trebuchet MS", "Avenir Next", system-ui, sans-serif;
}
.font-sans text { font-family: var(--font-sans); }
.font-serif text { font-family: var(--font-serif); }
.font-slab text { font-family: var(--font-slab); }
.font-mono text { font-family: var(--font-mono); }
.font-rounded text { font-family: var(--font-rounded); }
.font-condensed text { font-family: var(--font-condensed); }
.font-hand text { font-family: var(--font-hand); }
.font-display text { font-family: var(--font-display); }
.font-smallcaps text { font-variant: small-caps; letter-spacing: .05em; }
.font-wide text { letter-spacing: .16em; }

/* On a phone the pill would cover the diagram, so it tucks under the top edge
 * and scrolls sideways rather than wrapping into two rows over the canvas. */
@media (max-width: 760px) {
  #tapbar {
    top: auto; bottom: calc(58px + env(safe-area-inset-bottom, 0px));
    left: 8px; right: 8px; transform: none; border-radius: 12px;
    overflow-x: auto; scrollbar-width: none;
  }
  #tapbar::-webkit-scrollbar { display: none; }
  #tapbar .tap-btn { flex: 0 0 auto; }
  .group-label { font-size: 10.5px; }
}


/* ── find a node, versions, the ring menu and the pop-up forms ─────────────── */

.search-row { display: flex; gap: 6px; align-items: center; }
.search-row input { flex: 1; min-width: 0; }
.icon-btn.small { width: 32px; height: 32px; font-size: 14px; flex: none; }

.versions { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.version {
  border: 1px solid var(--ui-line); border-radius: 10px; padding: 8px 10px;
  background: var(--ui-panel-2, #ffffff08);
}
.version-name { font-weight: 600; font-size: 13.5px; }
.version-when { color: var(--ui-dim); font-size: 11.5px; margin-top: 1px; }
.version-actions { display: flex; gap: 6px; margin-top: 8px; }
.version-actions button {
  flex: 1; font: inherit; font-size: 12px; padding: 5px 6px; border-radius: 8px;
  border: 1px solid var(--ui-line); background: transparent; color: var(--ui-text); cursor: pointer;
}
.version-actions button:hover { border-color: var(--accent); color: var(--accent); }

/* A node matched by the search stands out without stealing the selection styling. */
.node.match .node-shape { stroke: var(--accent); stroke-width: 2.6; }

/* The menu sits on a ring around the node, in screen pixels, so zoom does not
   change the size of the targets. */
.ring-menu { position: absolute; inset: 0; pointer-events: none; z-index: 40; }
.ring-menu .ring-btn {
  position: absolute; transform: translate(-50%, -50%); pointer-events: auto;
  display: grid; place-items: center; gap: 2px;
  width: 54px; height: 54px; padding: 4px; border-radius: 50%; cursor: pointer;
  border: 1px solid var(--ui-line); background: var(--ui-panel, #1119); color: var(--ui-text);
  box-shadow: 0 6px 18px #0008; backdrop-filter: blur(6px);
}
.ring-menu .ring-btn:hover { border-color: var(--accent); color: var(--accent); }
.ring-menu .ring-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.ring-menu .ring-btn span { font-size: 9px; letter-spacing: 0.01em; opacity: 0.85; }
.ring-menu .ring-dot {
  position: absolute; transform: translate(-50%, -50%); width: 9px; height: 9px;
  border-radius: 50%; background: var(--accent); opacity: 0.7;
}

#modal .sheet-inner { max-height: 86vh; overflow: auto; position: relative; width: min(520px, 100%); }
.sheet-close {
  position: absolute; top: 10px; right: 12px; width: 30px; height: 30px; padding: 0;
  border-radius: 50%; border: 1px solid var(--ui-line); background: transparent;
  color: var(--ui-text); font-size: 17px; line-height: 1; cursor: pointer;
}
#modal .field, #modal .row { margin-top: 10px; }
/* Each choice on its own line: three radios in a row read as one long sentence. */
#modal-body > .row.check { display: flex; width: 100%; align-items: flex-start; gap: 9px; }
#modal-body > .row.check input { flex: none; margin-top: 2px; }
#modal-body > .row.check span { flex: 1; }
#modal-confirm.danger { width: auto; }
.reassign { list-style: none; margin: 8px 0 0; padding: 0 0 0 4px; display: flex; flex-direction: column; gap: 6px; }
.reassign li { display: flex; gap: 8px; align-items: center; }
.reassign li span { flex: 1; font-size: 13px; }
.reassign select { max-width: 58%; }
.warn-line { color: #ffb4c0; font-size: 13px; margin: 12px 0 0; }

/* A row in a form: the label and its control on one line, but the row itself on its
   own line — an inline <label> turns a list of choices into one long sentence. */
label.row { display: flex; align-items: center; gap: 8px; width: 100%; margin-top: 8px; }
label.row > .field-label { flex: none; width: 62px; color: var(--ui-dim); font-size: 12.5px; }
label.row input[type="text"], label.row input[type="search"] { flex: 1; min-width: 0; }
label.row.check span { flex: 1; }

/* ── the hierarchy view toggle ──────────────────────────────────────────────── */

.hierarchy-bar {
  position: absolute; top: 6px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 7px; align-items: center; flex-wrap: wrap; justify-content: center;
  padding: 5px 8px; border-radius: 11px; z-index: 30;
  background: var(--ui-panel, #1119); border: 1px solid var(--ui-line);
  box-shadow: 0 6px 18px #0007; backdrop-filter: blur(6px);
  max-width: calc(100% - 20px);
}
.hierarchy-bar .seg { display: flex; gap: 4px; }
.hierarchy-bar .seg-btn {
  font: inherit; font-size: 11.5px; padding: 4px 8px; border-radius: 7px; cursor: pointer;
  border: 1px solid var(--ui-line); background: transparent; color: var(--ui-text);
}
.hierarchy-bar .seg-btn.on { border-color: var(--accent); color: var(--accent); background: #ffffff10; }
.hierarchy-bar .chip-row { display: flex; gap: 4px; align-items: center; }
.hierarchy-bar .bar-note { font-size: 11px; color: var(--ui-dim); margin-right: 2px; }
.hierarchy-bar .align-chip { font-size: 11px; padding: 3px 7px; }
.hierarchy-bar .align-chip.on { border-color: var(--accent); color: var(--accent); background: #ffffff10; }
@media (max-width: 720px) {
  .hierarchy-bar { top: 4px; padding: 5px 7px; gap: 6px; }
  .hierarchy-bar .seg-btn { font-size: 11.5px; padding: 4px 7px; }
  .hierarchy-bar .bar-note { display: none; }
}

/* The tap pill shares the top of the canvas with the hierarchy bar. They used to be
 * two absolutely positioned pills at the same spot, so the hierarchy bar simply
 * covered Select / Edit / Collapse — the options were not gone, they were underneath.
 * Now the tap pill starts below whatever height the hierarchy bar reports. */
#tapbar { top: calc(12px + var(--topbars, 0px)); z-index: 7; }
@media (max-width: 760px) {
  #tapbar { top: auto; }
}

/* Dragging the canvas is not a text gesture. Without this, every drag that starts on
 * the SVG highlights whichever label it crosses and the selection then follows the
 * pointer around like a bad paintbrush. Scoped to the canvas, so text in the panel and
 * the modals stays selectable. */
#canvas, #canvas * { user-select: none; -webkit-user-select: none; -ms-user-select: none; }
#canvas text { -webkit-user-drag: none; }
