/* ============================================================
   DESIGN TOKENS — light theme defaults
   ============================================================ */
:root {
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  --bg: #ffffff;
  --bg-1: #fafafa;
  --bg-2: #f4f4f5;
  --bg-3: #e9e9ec;
  --surface: #ffffff;
  --surface-2: #f7f7f9;
  --overlay: rgba(255,255,255,0.86);
  --border: #e5e5ea;
  --border-strong: #d4d4d8;
  --text: #0a0a0a;
  --text-2: #52525b;
  --text-3: #686873;
  --text-inverse: #ffffff;

  --accent: #5b5bd6;
  --accent-hover: #4f4fc4;
  --accent-soft: #eeeeff;
  --accent-fg: #ffffff;
  --danger: #e5484d;
  --warning: #f5a524;
  --success: #30a46c;
  --info: #3b82f6;

  --grid: rgba(0,0,0,0.06);
  --canvas-bg: #fbfbfd;

  --shadow-xs: 0 1px 2px rgba(15,15,20,0.04);
  --shadow-sm: 0 1px 3px rgba(15,15,20,0.06), 0 1px 2px rgba(15,15,20,0.04);
  --shadow-md: 0 4px 12px rgba(15,15,20,0.08), 0 2px 4px rgba(15,15,20,0.04);
  --shadow-lg: 0 12px 32px rgba(15,15,20,0.12), 0 4px 8px rgba(15,15,20,0.06);
  --shadow-xl: 0 24px 60px rgba(15,15,20,0.18), 0 8px 16px rgba(15,15,20,0.08);

  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  --topbar-h: 48px;
  --statusbar-h: 24px;
  --rail-w: 44px;
  --left-w: 320px;
  --right-w: 280px;
  --drawer-h: 0px;

  --dur: 160ms;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);

  --ui-scale: 1;
}

:root[data-theme="dark"] {
  --bg: #0b0b0e;
  --bg-1: #111114;
  --bg-2: #17171c;
  --bg-3: #20202a;
  --surface: #131318;
  --surface-2: #181820;
  --overlay: rgba(15,15,20,0.78);
  --border: #25252e;
  --border-strong: #34343f;
  --text: #f3f3f5;
  --text-2: #a8a8b3;
  --text-3: #9a9aa6;
  --text-inverse: #0a0a0a;

  --accent: #7c7cff;
  --accent-hover: #8e8eff;
  --accent-soft: #20203a;
  --accent-fg: #0a0a0a;

  --grid: rgba(255,255,255,0.05);
  --canvas-bg: #0d0d12;

  --shadow-xs: 0 1px 2px rgba(0,0,0,0.4);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.45);
  --shadow-md: 0 6px 16px rgba(0,0,0,0.5);
  --shadow-lg: 0 16px 36px rgba(0,0,0,0.55);
  --shadow-xl: 0 28px 64px rgba(0,0,0,0.65);
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

* { box-sizing: border-box; }
html { height: 100%; }
body {
  margin: 0; padding: 0; min-height: 100%;
  background: var(--bg); color: var(--text);
  font-family: var(--font-ui);
  font-size: calc(13px * var(--ui-scale));
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-y: auto;
}
body { transition: background var(--dur) var(--ease), color var(--dur) var(--ease); }

button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
::selection { background: var(--accent); color: var(--accent-fg); }

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

/* Scrollbars */
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--text-3); border: 2px solid transparent; background-clip: padding-box; }

/* Boot screen */
.boot {
  position: fixed; inset: 0; display: grid; place-items: center;
  font-family: var(--font-ui); color: var(--text-2); background: var(--bg);
  z-index: 9999; font-size: 13px;
}

/* ============================================================
   APP SHELL
   ============================================================ */
#app {
  display: grid;
  grid-template-rows: var(--topbar-h) 1fr var(--statusbar-h);
  zoom: var(--ui-scale);
  height: 100vh;
  height: 100dvh;
  width: calc(100vw / var(--ui-scale));
  overflow: hidden;
}

/* ============================================================
   TOP BAR
   ============================================================ */
.topbar {
  display: flex; align-items: center; gap: 4px;
  padding: 0 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: relative; z-index: 50;
  height: var(--topbar-h);
}
.brand {
  display: flex; align-items: center; gap: 8px;
  padding: 0 8px 0 4px; margin-right: 4px;
  font-weight: 600; font-size: 13px; letter-spacing: -0.01em;
}
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px;
  background: linear-gradient(135deg, var(--accent), #8b8bff);
  display: grid; place-items: center; color: white;
}
.brand-name { color: var(--text); }

.menu-btn {
  height: 28px; padding: 0 10px; border-radius: var(--radius-sm);
  font-size: 12.5px; color: var(--text); display: inline-flex; align-items: center; gap: 4px;
  transition: background var(--dur) var(--ease);
}
.menu-btn:hover, .menu-btn.open { background: var(--bg-2); }

.tb-divider { width: 1px; height: 22px; background: var(--border); margin: 0 4px; }
.tb-spacer { flex: 1; }

.dt-select {
  height: 28px; padding: 0 8px; border-radius: var(--radius-sm);
  background: var(--bg-2); color: var(--text); border: 1px solid var(--border);
  font-size: 12px;
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat; background-position: right 6px center;
  padding-right: 22px;
  cursor: pointer;
}

.icon-btn {
  width: 32px; height: 28px; border-radius: var(--radius-sm);
  display: inline-grid; place-items: center; color: var(--text-2);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.icon-btn:hover { background: var(--bg-2); color: var(--text); }
.icon-btn.active { background: var(--accent-soft); color: var(--accent); }
.icon-btn svg { width: 16px; height: 16px; }

.btn-primary {
  height: 28px; padding: 0 12px; border-radius: var(--radius-sm);
  background: var(--accent); color: var(--accent-fg);
  font-size: 12.5px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary svg { width: 14px; height: 14px; }

.btn-secondary {
  height: 28px; padding: 0 10px; border-radius: var(--radius-sm);
  background: var(--bg-2); color: var(--text); border: 1px solid var(--border);
  font-size: 12.5px;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.btn-secondary:hover { background: var(--bg-3); }
.btn-secondary svg { width: 14px; height: 14px; }
.tutorial-btn {
  color: var(--accent-hover);
  border-color: color-mix(in srgb, var(--accent) 30%, var(--border));
  background: color-mix(in srgb, var(--accent) 8%, var(--bg-2));
}
.tutorial-btn:hover {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
  background: color-mix(in srgb, var(--accent) 14%, var(--bg-2));
}

/* Dropdown */
.dropdown {
  position: absolute; top: calc(var(--topbar-h) - 4px); left: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-lg);
  padding: 4px; min-width: 220px;
  z-index: 100;
  animation: dd-in 120ms var(--ease);
}
@keyframes dd-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.dd-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 6px 10px; border-radius: var(--radius-xs);
  font-size: 12.5px; color: var(--text); text-align: left;
  cursor: pointer; transition: background var(--dur) var(--ease);
}
.dd-item:hover, .dd-item:focus-visible { background: var(--bg-2); outline: none; }
.dd-item:disabled { opacity: 0.4; cursor: not-allowed; }
.dd-item .kbd { margin-left: auto; color: var(--text-3); font-size: 11px; }
.dd-sep { height: 1px; background: var(--border); margin: 4px 0; }
.dd-label { padding: 6px 10px; font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.04em; }
.dd-sub { padding-left: 6px; font-size: 11px; color: var(--text-3); margin-left: auto; }

.kbd {
  font-family: var(--font-mono); font-size: 11px;
  padding: 1px 5px; border-radius: 4px;
  background: var(--bg-2); border: 1px solid var(--border);
  color: var(--text-2);
}

/* ============================================================
   WORKSPACE
   ============================================================ */
.workspace {
  display: grid;
  grid-template-columns: var(--rail-w) var(--left-w) 1fr var(--right-w);
  grid-template-rows: 1fr var(--drawer-h);
  grid-template-areas:
    "rail left center right"
    "drawer drawer drawer drawer";
  min-height: 0; min-width: 0;
  background: var(--bg-1);
}

/* Icon rail */
.rail {
  grid-area: rail;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center; padding: 6px 0; gap: 2px;
  min-height: 0; overflow-y: auto;
}
.rail-tabs { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.rail-btn {
  width: 32px; height: 32px; border-radius: var(--radius-sm);
  display: grid; place-items: center; color: var(--text-2);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
  position: relative;
}
.rail-btn:hover { background: var(--bg-2); color: var(--text); }
.rail-btn.active { background: var(--accent-soft); color: var(--accent); }
.rail-btn.active::before {
  content: ""; position: absolute; left: -6px; top: 6px; bottom: 6px;
  width: 2px; border-radius: 2px; background: var(--accent);
}
.rail-btn svg { width: 16px; height: 16px; }
.rail-spacer { flex: 1; }

/* Left panel */
.left-panel {
  grid-area: left;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-width: 0; min-height: 0;
  position: relative;
}
.panel-header {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.panel-title { font-size: 12.5px; font-weight: 600; color: var(--text); }
.panel-search {
  position: sticky; top: 0; background: var(--surface); z-index: 5;
  padding: 6px 8px; border-bottom: 1px solid var(--border);
}
.search-input {
  width: 100%; height: 26px; padding: 0 8px 0 26px;
  background: var(--bg-2); border: 1px solid transparent; border-radius: var(--radius-sm);
  font-size: 12px; color: var(--text);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238a8a93' stroke-width='2.5' stroke-linecap='round'><circle cx='11' cy='11' r='7'/><path d='M21 21l-4.35-4.35'/></svg>");
  background-repeat: no-repeat; background-position: 8px center;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.search-input:focus { outline: none; background: var(--bg); border-color: var(--accent); }
.panel-body { flex: 1; overflow-y: auto; min-height: 0; }
.panel-tab { display: none; }
.panel-tab.active { display: block; }

/* Sections inside panels */
.section {
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
}
.section h4 {
  margin: 0 0 8px; font-size: 11px; font-weight: 600; text-transform: uppercase;
  color: var(--text-3); letter-spacing: 0.04em;
  display: flex; align-items: center; gap: 4px; cursor: pointer; user-select: none;
}
.section h4 .chev { transition: transform var(--dur) var(--ease); }
.section.collapsed h4 .chev { transform: rotate(-90deg); }
.section.collapsed .section-body { display: none; }
.row { display: grid; grid-template-columns: 100px 1fr; align-items: center; gap: 8px; margin-bottom: 8px; }
.row label { font-size: 12px; color: var(--text-2); }
.row.full { grid-template-columns: 1fr; }
.row .ctl { min-width: 0; }

.input, .select {
  width: 100%; height: 28px; padding: 0 8px;
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 12px; color: var(--text);
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.input:hover, .select:hover { border-color: var(--text-3); }
.input:focus, .select:focus { outline: none; background: var(--bg); border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 20%, transparent); }
.select {
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat; background-position: right 6px center;
  padding-right: 22px; cursor: pointer;
}

.range { display: grid; grid-template-columns: 1fr 42px; gap: 6px; align-items: center; }
.range input[type=range] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 4px;
  background: var(--bg-3); border-radius: 4px; outline: none;
  background-image: linear-gradient(var(--accent), var(--accent));
  background-repeat: no-repeat;
}
.range input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; }
.range input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); cursor: pointer; border: 2px solid var(--surface);
  box-shadow: 0 1px 3px rgba(0,0,0,.25); margin-top: -5px;
  transition: box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.range input[type=range]::-webkit-slider-thumb:hover { box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 20%, transparent); transform: scale(1.15); }
.range input[type=range]::-moz-range-track { height: 4px; background: var(--bg-3); border-radius: 4px; border: none; }
.range input[type=range]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); cursor: pointer; border: 2px solid var(--surface);
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.range input[type=range]::-moz-range-progress { background: var(--accent); height: 4px; border-radius: 4px; }
.range .num {
  height: 24px; padding: 0 4px; text-align: center;
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius-xs);
  font-size: 11px; color: var(--text-2); font-family: var(--font-mono);
  transition: border-color var(--dur) var(--ease);
}
.range .num:focus { border-color: var(--accent); outline: none; }

.toggle-group { display: inline-flex; background: var(--bg-2); padding: 2px; border-radius: var(--radius-sm); gap: 1px; border: 1px solid var(--border); }
.toggle-group button {
  flex: 1; padding: 4px 10px; border-radius: var(--radius-xs);
  font-size: 11px; font-weight: 500; color: var(--text-3);
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  transition: all var(--dur) var(--ease);
}
.toggle-group button:hover { color: var(--text); background: var(--bg-1); }
.toggle-group button.active { background: var(--accent); color: var(--accent-fg); box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.toggle-group button svg { width: 12px; height: 12px; }

.switch { position: relative; width: 32px; height: 18px; flex-shrink: 0; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch .slider {
  position: absolute; inset: 0; background: var(--bg-3); border-radius: 999px; border: 1px solid var(--border);
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease); cursor: pointer;
}
.switch .slider::before {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 12px; height: 12px; border-radius: 50%; background: white;
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
  box-shadow: 0 1px 2px rgba(0,0,0,.2);
}
.switch:hover .slider { border-color: var(--text-3); }
.switch:hover .slider::before { box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked + .slider { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(14px); }
.switch input:focus-visible + .slider { box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent); }

.color-input {
  width: 28px; height: 24px; padding: 2px; border: 1px solid var(--border);
  border-radius: var(--radius-xs); background: transparent; cursor: pointer;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.color-input:hover { border-color: var(--text-3); }
.color-input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 20%, transparent); outline: none; }
.color-input::-webkit-color-swatch-wrapper { padding: 0; }
.color-input::-webkit-color-swatch { border: none; border-radius: 3px; }
.color-input::-moz-color-swatch { border: none; border-radius: 3px; }

.color-row { display: flex; align-items: center; gap: 6px; }
.color-row .input { font-family: var(--font-mono); }

.swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; margin-top: 4px; }
.swatch {
  aspect-ratio: 1; border-radius: var(--radius-xs); cursor: pointer;
  border: 2px solid transparent; transition: transform var(--dur) var(--ease);
}
.swatch:hover { transform: scale(1.08); }
.swatch.active { border-color: var(--text); }

.preset-card {
  display: flex; align-items: center; gap: 8px;
  padding: 8px; border-radius: var(--radius-sm);
  background: var(--bg-2); margin-bottom: 6px; cursor: pointer;
  transition: background var(--dur) var(--ease);
}
.preset-card:hover { background: var(--bg-3); }
.preset-thumb {
  width: 36px; height: 36px; border-radius: var(--radius-xs);
  display: grid; place-items: center; flex-shrink: 0;
  background: var(--surface); border: 1px solid var(--border);
}
.preset-info { flex: 1; min-width: 0; }
.preset-name { font-size: 12px; font-weight: 500; color: var(--text); }
.preset-meta { font-size: 11px; color: var(--text-3); }

/* Resizer */
.resizer { position: absolute; top: 0; bottom: 0; width: 4px; cursor: col-resize; z-index: 30; }
.resizer.right { right: -2px; }
.resizer.left { left: -2px; }
.resizer:hover { background: var(--accent); opacity: 0.4; }
.resizer.dragging { background: var(--accent); opacity: 0.6; }
.resizer-h { position: absolute; left: 0; right: 0; height: 4px; cursor: row-resize; z-index: 30; }
.resizer-h.top { top: -2px; }
.resizer-h:hover { background: var(--accent); opacity: 0.4; }

/* Center / Canvas */
.center {
  grid-area: center; position: relative; overflow: hidden;
  background: var(--canvas-bg);
}
.canvas-bg-grid::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image:
    radial-gradient(circle, var(--grid) 1px, transparent 1px);
  background-size: 18px 18px;
  background-position: 0 0;
}
.canvas-bg-lines::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
}
.canvas-bg-solid { background: var(--surface) !important; }
.canvas-bg-blueprint { background: #0f3a6b !important; }
.canvas-bg-blueprint::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image:
    linear-gradient(rgba(255,255,255,0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.06) 1px, transparent 1px);
  background-size: 22px 22px;
}

.canvas {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
}
.canvas svg { display: block; max-width: 100%; max-height: 100%; }

.stale-badge {
  position: absolute; top: 12px; left: 12px;
  padding: 4px 10px; border-radius: 999px;
  background: var(--warning); color: #1a1a1a; font-size: 11px; font-weight: 600;
  display: none; box-shadow: var(--shadow-md); z-index: 5;
}
.stale-badge.show { display: block; }
.stale-fix { margin-left:8px;border:0;border-radius:999px;padding:2px 9px;background:#1a1a1a;color:#fff;font:inherit;font-size:11px;font-weight:650;cursor:pointer; }
.fixer-changes { margin:10px 0 0;padding-left:20px;font-size:14px;color:var(--text-2); }
.fixer-preview { max-height:220px;overflow:auto;margin:12px 0 0;padding:12px;border-radius:8px;background:var(--bg-2);font-family:ui-monospace,monospace;font-size:12px;line-height:1.6;white-space:pre-wrap; }

.hybrid-badge {
  position: absolute; top: 42px; left: 12px;
  display: none; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  font-size: 11px; font-weight: 600;
  box-shadow: var(--shadow-md); z-index: 6;
}
.hybrid-badge.show { display: inline-flex; }
.hybrid-badge.warn { background: color-mix(in srgb, var(--warning) 20%, var(--surface)); color: var(--warning); border-color: color-mix(in srgb, var(--warning) 35%, transparent); }

.canvas-toolbar {
  position: absolute; top: 12px; right: 12px;
  display: flex; align-items: center; gap: 2px;
  background: var(--overlay); backdrop-filter: blur(12px);
  border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 3px; box-shadow: var(--shadow-md); z-index: 5;
}
.canvas-toolbar .icon-btn { width: 28px; height: 24px; }
.canvas-toolbar .visual-tool { display: none; }
body.visual-edit-mode .canvas-toolbar .visual-tool { display: inline-grid; }
.zoom-readout {
  font-size: 11px; font-family: var(--font-mono); color: var(--text-2);
  min-width: 38px; text-align: center; padding: 0 4px;
}
.canvas-toolbar .div { width: 1px; height: 16px; background: var(--border); margin: 0 2px; }

#canvas svg g.node { cursor: pointer; }
body.visual-edit-mode #canvas svg { cursor: default; }
body.visual-edit-mode #canvas svg g.node { cursor: text; }
body.connect-mode #canvas svg g.node { cursor: crosshair; }
#canvas svg g.node.selected rect,
#canvas svg g.node.selected polygon,
#canvas svg g.node.selected circle,
#canvas svg g.node.selected ellipse,
#canvas svg g.node.connect-source rect,
#canvas svg g.node.connect-source polygon,
#canvas svg g.node.connect-source circle,
#canvas svg g.node.connect-source ellipse {
  stroke: var(--accent) !important;
  stroke-width: 3px !important;
  filter: drop-shadow(0 0 6px color-mix(in srgb, var(--accent) 35%, transparent));
}
#canvas svg .flowchart-link.selected,
#canvas svg .edgePath.selected path {
  stroke: var(--accent) !important;
  stroke-width: 3px !important;
}
#canvas svg .edgeLabel.selected {
  filter: drop-shadow(0 0 4px var(--accent));
}

.inline-editor {
  position: fixed;
  min-width: 120px;
  min-height: 32px;
  z-index: 1500;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
}
.inline-editor input,
.inline-editor textarea {
  width: 100%;
  border: 0;
  outline: none;
  padding: 0 6px;
  box-sizing: border-box;
  background: transparent;
  color: var(--text);
  font: 600 13px/1.25 var(--font-ui);
  text-align: center;
}
.inline-editor input {
  height: 100%;
  line-height: 1;
}
.inline-editor textarea {
  min-height: 20px;
  max-height: 100%;
  resize: none;
  overflow: hidden;
}

.floating-popover {
  position: fixed;
  z-index: 1800;
  width: 230px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
}
.floating-popover .input { height: 30px; }
.floating-popover .actions {
  display: flex; justify-content: flex-end; gap: 6px; margin-top: 8px;
}

@keyframes pulse-shadow {
  0% { opacity: 0.4; }
  50% { opacity: 1.0; }
  100% { opacity: 0.4; }
}
.pulsing-drag-shadow {
  animation: pulse-shadow 1s infinite ease-in-out;
}

.shape-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
}
.shape-btn {
  min-height: 34px;
  padding: 5px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-2);
  color: var(--text-2);
  font-size: 11px;
  display: grid;
  place-items: center;
}
.shape-btn:hover { background: var(--bg-3); color: var(--text); }
.shape-btn.active { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.connection-list {
  display: grid;
  gap: 4px;
}
.connection-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%;
  padding: 5px 7px;
  border-radius: var(--radius-xs);
  color: var(--text-2);
  font-size: 12px;
}
.connection-item:hover { background: var(--bg-2); color: var(--text); }
.connection-item .mono { font-size: 11px; color: var(--text-3); }

.org-list {
  display: grid;
  gap: 6px;
}
.org-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px 52px;
  gap: 6px;
  align-items: center;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-1);
}
.org-row .input,
.org-row .select { height: 26px; }
.org-actions {
  display: flex;
  justify-content: flex-end;
  gap: 2px;
}

.code-preview {
  margin: 0;
  padding: 12px;
  overflow: auto;
  min-height: 320px;
  max-height: 520px;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font: 12px/1.55 var(--font-mono);
  white-space: pre;
}



.right-panel {
  grid-area: right;
  background: var(--surface); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; min-width: 0; min-height: 0;
  position: relative;
}
.inspector-empty {
  padding: 32px 16px; text-align: center; color: var(--text-3); font-size: 12px;
}
.inspector-empty svg { width: 36px; height: 36px; margin: 0 auto 12px; display: block; opacity: 0.6; }

/* Status bar */
.statusbar {
  display: flex; align-items: center; gap: 12px;
  padding: 0 12px;
  background: var(--surface); border-top: 1px solid var(--border);
  font-size: 11px; color: var(--text-2); font-family: var(--font-mono);
  height: var(--statusbar-h);
}
.sb-item { display: inline-flex; align-items: center; gap: 4px; }
.sb-item .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--success); }
.sb-item.warn .dot { background: var(--warning); }
.sb-item.err .dot { background: var(--danger); }
.sb-spacer { flex: 1; }

/* Drawer */
.drawer {
  grid-area: drawer;
  background: var(--surface); border-top: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
  position: relative;
}
.drawer-tabs {
  display: flex; align-items: center; gap: 2px;
  padding: 4px 6px; border-bottom: 1px solid var(--border);
}
.drawer-tab {
  padding: 4px 10px; border-radius: var(--radius-xs); font-size: 12px;
  color: var(--text-2); transition: all var(--dur) var(--ease);
  display: inline-flex; align-items: center; gap: 6px;
}
.drawer-tab:hover { background: var(--bg-2); color: var(--text); }
.drawer-tab.active { background: var(--bg-2); color: var(--text); font-weight: 500; }
.drawer-tab .badge {
  background: var(--bg-3); color: var(--text-2);
  padding: 0 6px; border-radius: 999px; font-size: 10px; min-width: 16px; text-align: center;
}
.drawer-tab.active .badge { background: var(--accent); color: var(--accent-fg); }
.drawer-body { flex: 1; overflow: auto; padding: 8px 12px; min-height: 0; }
.drawer-tab-content { display: none; }
.drawer-tab-content.active { display: block; }
.drawer-close {
  margin-left: auto; width: 24px; height: 24px; display: grid; place-items: center;
  border-radius: var(--radius-xs); color: var(--text-3);
}
.drawer-close:hover { background: var(--bg-2); color: var(--text); }

.console-line {
  display: flex; gap: 8px; padding: 3px 0; font-family: var(--font-mono); font-size: 11.5px;
  border-bottom: 1px dashed var(--border);
}
.console-line .ts { color: var(--text-3); flex-shrink: 0; width: 60px; }
.console-line .lvl { width: 50px; flex-shrink: 0; text-transform: uppercase; font-size: 10px; font-weight: 600; padding-top: 1px; }
.console-line.info .lvl { color: var(--info); }
.console-line.warn .lvl { color: var(--warning); }
.console-line.err .lvl { color: var(--danger); }
.console-line.ok .lvl { color: var(--success); }
.console-line .msg { flex: 1; word-break: break-word; }

.outline-tree { font-family: var(--font-mono); font-size: 12px; }
.outline-node { padding: 3px 6px; border-radius: var(--radius-xs); cursor: pointer; display: flex; align-items: center; gap: 6px; }
.outline-node:hover { background: var(--bg-2); }
.outline-node.active { background: var(--accent-soft); color: var(--accent); }
.outline-node .pill { font-size: 10px; padding: 0 5px; border-radius: 4px; background: var(--bg-2); color: var(--text-3); }

.history-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm); margin-bottom: 4px;
  background: var(--bg-1); cursor: pointer;
  transition: background var(--dur) var(--ease);
}
.history-item:hover { background: var(--bg-2); }
.history-item .when { font-family: var(--font-mono); font-size: 11px; color: var(--text-3); width: 90px; }
.history-item .name { flex: 1; font-size: 12.5px; }
.history-item .actions { display: flex; gap: 4px; opacity: 0; transition: opacity var(--dur) var(--ease); }
.history-item:hover .actions { opacity: 1; }

.diff-panel { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; height: 100%; }
.diff-side { background: var(--bg-1); border-radius: var(--radius-sm); overflow: auto; padding: 8px; font-family: var(--font-mono); font-size: 11.5px; white-space: pre-wrap; }
.diff-add { background: rgba(48,164,108,0.15); }
.diff-del { background: rgba(229,72,77,0.15); text-decoration: line-through; opacity: 0.7; }

/* ============================================================
   EDITOR
   ============================================================ */
.editor-wrap {
  position: relative; height: 100%; display: flex; flex-direction: column;
  background: var(--surface); min-height: 0;
}
.editor-toolbar {
  display: flex; align-items: center; gap: 4px; padding: 4px 6px;
  border-bottom: 1px solid var(--border); flex-shrink: 0;
  position: sticky; top: 0; z-index: 20; background: var(--surface);
}
.editor-area {
  position: relative; flex: 1; overflow: hidden; min-height: 0;
  display: flex;
}
.line-gutter {
  flex-shrink: 0; width: 38px; padding: 8px 6px 8px 0;
  font-family: var(--font-mono); font-size: 12px; line-height: 1.55;
  color: var(--text-3); text-align: right;
  background: var(--bg-1); border-right: 1px solid var(--border);
  overflow: hidden; user-select: none;
}
.editor-scroll {
  position: relative; flex: 1; overflow: hidden; min-width: 0;
}
.editor-pre, .editor-textarea {
  margin: 0; padding: 8px 12px;
  font-family: var(--font-mono); font-size: 12px; line-height: 1.55;
  white-space: pre; word-wrap: normal;
  tab-size: 2;
}
.editor-pre {
  position: absolute; inset: 0; pointer-events: none;
  color: var(--text); overflow: visible;
}
.editor-textarea {
  position: relative; width: 100%; min-height: 100%;
  background: transparent; color: transparent; caret-color: var(--text);
  border: 0; outline: 0; resize: none;
  display: block;
}
.editor-textarea::selection { background: rgba(91,91,214,0.25); color: transparent; }
:root[data-theme="dark"] .editor-textarea::selection { background: rgba(124,124,255,0.30); }
.editor-wrap.wrap .editor-pre,
.editor-wrap.wrap .editor-textarea { white-space: pre-wrap; word-wrap: break-word; }

/* Mermaid syntax tokens */
.tk-key { color: #c46aff; font-weight: 500; }
.tk-dir { color: #00a8c8; }
.tk-str { color: #30a46c; }
.tk-num { color: #f5a524; }
.tk-cmt { color: var(--text-3); font-style: italic; }
.tk-arr { color: var(--accent); font-weight: 500; }
.tk-id  { color: var(--text); }
.tk-op  { color: var(--text-2); }
.tk-bra { color: #e5484d; }
:root[data-theme="dark"] .tk-key { color: #d39bff; }
:root[data-theme="dark"] .tk-dir { color: #5cdfff; }
:root[data-theme="dark"] .tk-str { color: #4cc38a; }

.editor-error-line {
  position: absolute; left: 0; right: 0; height: 18.6px;
  background: rgba(229,72,77,0.10);
  border-left: 2px solid var(--danger);
  pointer-events: none; z-index: 1;
}

.find-bar {
  display: flex; align-items: center; gap: 6px; padding: 6px 8px;
  background: var(--bg-1); border-bottom: 1px solid var(--border);
  position: sticky; top: 37px; z-index: 19;
}
.find-bar .input { height: 24px; font-size: 12px; }
.find-bar .icon-btn { width: 24px; height: 24px; }
.find-bar .count { font-size: 11px; color: var(--text-3); font-family: var(--font-mono); min-width: 50px; text-align: center; }

.autocomplete {
  position: absolute; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-lg);
  padding: 4px; min-width: 180px; max-height: 220px; overflow-y: auto;
  z-index: 200;
}
.ac-item {
  padding: 5px 8px; border-radius: var(--radius-xs);
  font-size: 12px; font-family: var(--font-mono); cursor: pointer;
  display: flex; align-items: center; gap: 8px;
}
.ac-item:hover, .ac-item.active { background: var(--bg-2); }
.ac-item .kind { font-size: 10px; color: var(--text-3); margin-left: auto; }

/* ============================================================
   MODAL
   ============================================================ */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: grid; place-items: center; z-index: 1000;
  animation: fade-in 120ms var(--ease);
  backdrop-filter: blur(2px);
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--surface); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl); border: 1px solid var(--border);
  width: 560px; max-width: calc(100vw - 32px); max-height: calc(100vh - 64px);
  display: flex; flex-direction: column; overflow: hidden;
  animation: modal-in 160ms var(--ease);
}
.modal.lg { width: 760px; }
.modal.xl { width: 920px; height: 640px; max-height: calc(100vh - 64px); }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }
.modal-header {
  display: flex; align-items: center; padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-title { margin: 0; font-size: 14px; font-weight: 600; flex: 1; }
.modal-body { flex: 1; overflow: auto; padding: 16px; min-height: 0; }
.modal-footer {
  display: flex; align-items: center; gap: 8px; justify-content: flex-end;
  padding: 12px 16px; border-top: 1px solid var(--border); background: var(--bg-1);
}

.modal-tabs { display: flex; gap: 2px; padding: 0 16px; border-bottom: 1px solid var(--border); }
.modal-tab {
  padding: 10px 12px; font-size: 12.5px; color: var(--text-2);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.modal-tab:hover { color: var(--text); }
.modal-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.template-card {
  background: var(--bg-1); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 10px; cursor: pointer; transition: all var(--dur) var(--ease);
  display: flex; flex-direction: column; gap: 8px;
}
.template-card:hover { border-color: var(--accent); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.template-thumb {
  height: 90px; background: var(--surface); border-radius: var(--radius-sm);
  display: grid; place-items: center; color: var(--text-3); font-size: 11px;
  overflow: hidden;
}
.template-thumb svg { max-width: 100%; max-height: 100%; }
.template-name { font-size: 12.5px; font-weight: 500; }
.template-cat { font-size: 11px; color: var(--text-3); }

/* Tutorial */
.tutorial { display: flex; flex-direction: column; padding: 0; }
.tutorial-hero {
  padding: 20px 20px 18px;
  border-bottom: 1px solid var(--border);
  background:
    radial-gradient(120% 140% at 0% 0%, color-mix(in srgb, var(--accent) 13%, transparent), transparent 55%),
    linear-gradient(160deg, var(--surface), var(--bg-1));
}
.tutorial-hero h3 { margin: 0 0 6px; font-size: 21px; line-height: 1.2; letter-spacing: -0.01em; }
.tutorial-hero p { margin: 0; max-width: 76ch; color: var(--text-2); font-size: 13px; line-height: 1.6; }
.tutorial-hero-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }

.tutorial-nav {
  position: sticky; top: 0; z-index: 2;
  display: flex; gap: 2px; flex-wrap: wrap;
  padding: 10px 20px 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.tutorial-nav button {
  appearance: none; cursor: pointer;
  padding: 8px 12px 10px;
  border: 0; border-bottom: 2px solid transparent;
  background: transparent; color: var(--text-2);
  font-size: 13px; font-weight: 550;
}
.tutorial-nav button:hover { color: var(--text); }
.tutorial-nav button.active { color: var(--accent); border-bottom-color: var(--accent); }

.tutorial-panel { padding: 18px 20px 20px; }
.tutorial-panel[hidden] { display: none; }
.tutorial-lede { margin: 0 0 16px; max-width: 80ch; color: var(--text-2); font-size: 13px; line-height: 1.6; }

/* Numbered steps */
.tutorial-steps { display: grid; gap: 12px; counter-reset: tstep; }
.tutorial-step {
  display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 14px;
  padding: 14px;
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  background: var(--bg-1);
}
.tutorial-step::before {
  counter-increment: tstep; content: counter(tstep);
  display: grid; place-items: center;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent); color: var(--accent-fg);
  font-size: 13px; font-weight: 700;
}
.tutorial-step h5 { margin: 4px 0 6px; font-size: 14px; }
.tutorial-step p { margin: 0; color: var(--text-2); font-size: 13px; line-height: 1.6; }
.tutorial-step ul { margin: 8px 0 0; padding-left: 18px; color: var(--text-2); font-size: 12.5px; line-height: 1.65; }
.tutorial-step li + li { margin-top: 3px; }
.tutorial-snippet {
  margin: 10px 0 0;
  padding: 11px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--bg-2); color: var(--text);
  font: 12px/1.65 var(--font-mono);
  white-space: pre; overflow-x: auto;
}
.tutorial-step-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

/* Diagram type chips */
.tutorial-types { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.tutorial-type {
  appearance: none; cursor: pointer; text-align: left;
  display: grid; gap: 2px;
  padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--bg-1); color: var(--text);
  font-size: 13px; font-weight: 550;
}
.tutorial-type:hover { border-color: var(--accent); background: var(--accent-soft); }
.tutorial-type code { color: var(--text-3); font: 11px/1.4 var(--font-mono); font-weight: 400; }

/* Reference rows */
.tutorial-ref { display: grid; gap: 18px; }
.tutorial-ref h5 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); }
.tutorial-keys { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 6px; }
.tutorial-key {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg-1);
  color: var(--text-2); font-size: 12.5px;
}
.tutorial-key .kbd { margin-left: auto; }
.tutorial-facts { margin: 0; padding-left: 18px; color: var(--text-2); font-size: 12.5px; line-height: 1.7; }
.tutorial-facts li + li { margin-top: 4px; }

@media (max-width: 720px) {
  .tutorial-hero, .tutorial-panel { padding-left: 14px; padding-right: 14px; }
  .tutorial-nav { padding-left: 14px; padding-right: 14px; }
  .tutorial-step { grid-template-columns: 24px minmax(0, 1fr); gap: 10px; padding: 12px; }
  .tutorial-step::before { width: 24px; height: 24px; font-size: 12px; }
}

/* ============================================================
   COMMAND PALETTE
   ============================================================ */
.cmd-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.32);
  display: flex; justify-content: center; padding-top: 14vh;
  z-index: 2000; backdrop-filter: blur(2px);
  animation: fade-in 100ms var(--ease);
}
.cmd-palette {
  width: 560px; max-width: calc(100vw - 32px);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-xl);
  overflow: hidden; max-height: 60vh; display: flex; flex-direction: column;
  animation: modal-in 140ms var(--ease);
}
.cmd-input {
  width: 100%; padding: 14px 18px; font-size: 14px;
  background: transparent; border: 0; border-bottom: 1px solid var(--border);
  color: var(--text); outline: none;
}
.cmd-list { overflow-y: auto; padding: 4px; }
.cmd-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: var(--radius-sm); cursor: pointer;
  font-size: 13px;
}
.cmd-item:hover, .cmd-item.active { background: var(--bg-2); }
.cmd-item .ic { color: var(--text-3); width: 16px; height: 16px; }
.cmd-item .group { color: var(--text-3); font-size: 11px; margin-left: auto; }
.cmd-item .kbd { margin-left: 8px; }
.cmd-empty { padding: 24px; text-align: center; color: var(--text-3); font-size: 12px; }

/* ============================================================
   TOAST
   ============================================================ */
.toast-container {
  position: fixed; bottom: 40px; right: 16px; z-index: 3000;
  display: flex; flex-direction: column-reverse; gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-lg);
  padding: 10px 12px; min-width: 240px; max-width: 360px;
  display: flex; align-items: flex-start; gap: 10px;
  pointer-events: auto;
  animation: toast-in 200ms var(--ease);
}
@keyframes toast-in { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }
.toast.out { animation: toast-out 200ms var(--ease) forwards; }
@keyframes toast-out { to { opacity: 0; transform: translateX(20px); } }
.toast .ic { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
.toast.success .ic { color: var(--success); }
.toast.warn .ic { color: var(--warning); }
.toast.error .ic { color: var(--danger); }
.toast.info .ic { color: var(--info); }
.toast .body { flex: 1; font-size: 12.5px; min-width: 0; }
.toast .body .t { font-weight: 600; margin-bottom: 2px; }
.toast .body .m { color: var(--text-2); word-break: break-word; }
.toast .actions { display: flex; gap: 4px; margin-top: 6px; }
.toast .actions button {
  font-size: 11.5px; padding: 3px 8px; border-radius: var(--radius-xs);
  background: var(--bg-2); color: var(--text);
}
.toast .actions button:hover { background: var(--bg-3); }
.toast .close { color: var(--text-3); padding: 2px; }
.toast .close:hover { color: var(--text); }

/* ============================================================
   CONTEXT MENU
   ============================================================ */
.ctx-menu {
  position: fixed; min-width: 200px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-lg);
  padding: 4px; z-index: 1500;
  animation: dd-in 100ms var(--ease);
}
.ctx-item {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px; border-radius: var(--radius-xs);
  font-size: 12.5px; cursor: pointer;
}
.ctx-item:hover { background: var(--bg-2); }
.ctx-item.danger { color: var(--danger); }
.ctx-sep { height: 1px; background: var(--border); margin: 4px 0; }

/* ============================================================
   COACH MARKS / ONBOARDING
   ============================================================ */
.coach-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55);
  z-index: 4000; display: grid; place-items: center;
  animation: fade-in 200ms var(--ease);
}
.coach-card {
  background: var(--surface); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl); border: 1px solid var(--border);
  padding: 24px; max-width: 440px;
}
.coach-card h3 { margin: 0 0 8px; font-size: 16px; }
.coach-card p { margin: 0 0 16px; color: var(--text-2); font-size: 13px; line-height: 1.55; }
.coach-card .footer { display: flex; align-items: center; gap: 8px; }
.coach-card .step { color: var(--text-3); font-size: 11px; flex: 1; }

/* ============================================================
   COLLAPSED STATES
   ============================================================ */
body.left-collapsed .workspace { grid-template-columns: var(--rail-w) 0px 1fr var(--right-w); }
body.left-collapsed .left-panel { display: none; }
body.right-collapsed .workspace { grid-template-columns: var(--rail-w) var(--left-w) 1fr 0px; }
body.right-collapsed .right-panel { display: none; }
body.left-collapsed.right-collapsed .workspace { grid-template-columns: var(--rail-w) 0 1fr 0; }

body.fullscreen-canvas .topbar,
body.fullscreen-canvas .left-panel,
body.fullscreen-canvas .right-panel,
body.fullscreen-canvas .rail,
body.fullscreen-canvas .statusbar,
body.fullscreen-canvas .drawer { display: none; }
body.fullscreen-canvas #app { grid-template-rows: 0 1fr 0; }
body.fullscreen-canvas .workspace { grid-template-columns: 0 0 1fr 0; }

body.focus-mode .stale-badge { display: none !important; }
body.focus-mode .canvas-toolbar { opacity: 0.4; transition: opacity var(--dur) var(--ease); }
body.focus-mode .canvas-toolbar:hover { opacity: 1; }

/* Print */
@media print {
  body { overflow: visible; height: auto; }
  .topbar, .left-panel, .right-panel, .rail, .statusbar, .drawer, .canvas-toolbar, .stale-badge { display: none !important; }
  #app { display: block; height: auto; }
  .workspace { display: block; }
  .center { position: static; background: white !important; }
  .canvas { position: static; padding: 24px; }
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 900px) {
  :root { --left-w: 280px; --right-w: 240px; }
  .right-panel { display: none; }
  .workspace { grid-template-columns: var(--rail-w) var(--left-w) 1fr 0; }
  .tutorial-hero { grid-template-columns: 1fr; }
  .tutorial-grid { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .left-panel { display: none; }
  .workspace { grid-template-columns: var(--rail-w) 0 1fr 0; }
  .menu-btn span:not(.label) { display: none; }
  .brand-name { display: none; }
  .tutorial-btn { width: 32px; padding: 0; justify-content: center; }
  .tutorial-btn .tutorial-label { display: none; }
  .tutorial-card { grid-template-columns: 1fr; }
}

/* Helpers */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
.hidden { display: none !important; }
.muted { color: var(--text-3); }
.mono { font-family: var(--font-mono); }
.flex { display: flex; }
.gap-4 { gap: 4px; } .gap-6 { gap: 6px; } .gap-8 { gap: 8px; }
.mt-8 { margin-top: 8px; } .mt-12 { margin-top: 12px; }

/* Discoverable help and focused small-screen editing. */
.skip-link { position:fixed;top:8px;left:8px;z-index:5000;transform:translateY(-160%);padding:12px;background:var(--bg);color:var(--text); }
.skip-link:focus { transform:none; }
:focus-visible { outline:2px solid var(--accent);outline-offset:3px; }
#landing { display:block;min-height:100vh;padding:48px 24px;background:radial-gradient(circle at 12% 4%,color-mix(in srgb,var(--accent) 10%,transparent),transparent 32%),var(--bg-2);border-top:1px solid var(--border);scroll-margin-top:0; }
.learn-content { max-width:1100px;margin:0 auto;font-size:16px;line-height:1.7; }
.landing-back { display:inline-flex;align-items:center;padding:8px 12px;border:1px solid var(--border);border-radius:999px;background:var(--surface);font-size:14px;font-weight:650;text-decoration:none;box-shadow:var(--shadow-sm); }
.learn-nav { margin:18px 0 36px;padding:18px 20px;border:1px solid var(--border);border-radius:14px;background:color-mix(in srgb,var(--surface) 88%,transparent);box-shadow:var(--shadow-sm); }
.learn-nav nav+nav { margin-top:8px; }
.learn-hero { max-width:860px;margin:0 0 34px; }
.learn-hero h1 { margin:0 0 18px;font-size:clamp(34px,5vw,60px);line-height:1.08;letter-spacing:-.04em; }
.learn-hero p { max-width:76ch;color:var(--text-2);font-size:18px; }
.learn-grid { display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:18px; }
.learn-card { padding:28px;border:1px solid var(--border);border-radius:18px;background:var(--surface);box-shadow:var(--shadow-sm); }
.learn-card-wide { grid-column:1/-1; }
.learn-card>h2:first-child { margin-top:0; }
.faq-grid { display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px 32px; }
.faq-grid section { border-top:1px solid var(--border); }
.faq-grid h3 { margin-bottom:6px;font-size:17px; }
.faq-grid p { margin-top:0;color:var(--text-2); }
.learn-privacy { display:grid;grid-template-columns:minmax(180px,.35fr) 1fr;gap:24px;align-items:start; }
.learn-privacy h2,.learn-privacy p { margin:0; }
.learn-content a { color:var(--accent); }
/* Links inside prose must not rely on colour alone (WCAG 1.4.1). */
.learn-content p a, .learn-content li a, .learn-content td a, .learn-content figcaption a { text-decoration:underline;text-underline-offset:3px; }
.learn-content .table-wrap { overflow-x:auto;margin:18px 0; }
.learn-content table { width:100%;border-collapse:collapse;font-size:15px; }
.learn-content th, .learn-content td { text-align:left;padding:8px 10px;border-bottom:1px solid var(--border);vertical-align:top; }
.learn-content code { background:var(--bg-2);padding:2px 5px;border-radius:4px;font-family:ui-monospace,monospace;font-size:.92em;overflow-wrap:anywhere; }
.learn-content figure { margin:20px 0;padding:16px;border:1px solid var(--border);border-radius:12px;background:var(--bg-1); }
.learn-content figure img { display:block;max-width:100%;height:auto;margin:auto; }
.learn-content figcaption { margin-top:10px;font-size:14px;color:var(--text-2); }
.learn-content .cta { display:inline-block;border:0;background:var(--accent);color:#fff;padding:10px 18px;border-radius:8px;font:inherit;font-weight:650;cursor:pointer;text-decoration:none; }
.learn-content .cta:hover { background:var(--accent-hover,var(--accent)); }
@media (max-width:760px) {
  #landing { padding:28px 16px; }
  .learn-nav { margin-bottom:28px; }
  .learn-grid,.faq-grid { grid-template-columns:1fr; }
  .learn-card-wide { grid-column:auto; }
  .learn-card { padding:22px; }
  .learn-privacy { display:block; }
  .learn-privacy h2 { margin-bottom:10px; }
}
.org-import-input { width:100%;min-height:190px;resize:vertical;padding:12px;border:1px solid var(--border);border-radius:8px;background:var(--bg-1);color:var(--text);font-family:ui-monospace,monospace;font-size:13px;line-height:1.6; }
.org-import-status { margin:12px 0 0;color:var(--text-2);font-size:14px; }
.org-import-status.error { color:var(--danger,#c0392b); }
.site-footer { max-width:850px;margin:48px auto 0;padding:24px 0;border-top:1px solid var(--border);font-size:14px;color:var(--text-2); }
.site-footer nav { display:flex;flex-wrap:wrap;gap:10px 18px; }
.site-footer p { margin:16px 0 0; }
.starter-search { width:100%;margin-bottom:16px;font-size:16px; }
.starter-grid { display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:12px; }
.starter-card { border:1px solid var(--border);border-radius:10px;padding:16px;background:var(--bg-1); }
.starter-card h3 { margin:6px 0;font-size:16px; }
.starter-card p { font-size:14px;color:var(--text-2);min-height:42px; }
.starter-card small { color:var(--accent);font-size:12px; }
.starter-card pre { max-height:130px;overflow:auto;white-space:pre-wrap;font-size:12px; }
.mobile-view { display:none; }
@media(max-width:768px) {
  .topbar { gap:5px;overflow-x:auto; }
  .topbar .menu-btn,.topbar #tutorialBtn,.topbar #settingsBtn,.topbar #cmdkBtn,.topbar .tb-divider { display:none; }
  .topbar .dt-select { width:100px;min-width:80px; }
  .mobile-view { display:inline-flex;min-height:36px; }
  .topbar button { flex-shrink:0; }
  #app { height:100dvh; }
  body.mobile-code .workspace,body.mobile-code.left-collapsed .workspace { grid-template-columns:var(--rail-w) minmax(0,1fr) 0 0; }
  body.mobile-code .left-panel { display:flex !important;width:auto;min-width:0; }
  body.mobile-code .center { display:none; }
  .editor-textarea, .editor-pre { font-size:16px; }
  .statusbar { overflow:hidden; }
  .modal { max-width:calc(100vw - 16px); }
  .modal-footer { flex-wrap:wrap; }
}
@media(prefers-reduced-motion:reduce) { *,*::before,*::after { animation-duration:0.01ms !important;transition-duration:0.01ms !important;scroll-behavior:auto !important; } }

/* Safe-area aware application shell and accessible touch controls. */
#app { min-height:0; }
.workspace,.left-panel,.center,.panel-body { min-width:0;min-height:0; }
@media(max-width:900px) {
  body .workspace { grid-template-columns:var(--rail-w) var(--left-w) minmax(0,1fr) 0; }
  body.left-collapsed .workspace { grid-template-columns:var(--rail-w) 0 minmax(0,1fr) 0; }
}
@media(max-width:768px) {
  html,body { overscroll-behavior:none; }
  #app { zoom:1;width:100%;height:var(--app-height,100dvh);padding-top:env(safe-area-inset-top);padding-bottom:env(safe-area-inset-bottom);padding-left:env(safe-area-inset-left);padding-right:env(safe-area-inset-right);grid-template-rows:92px minmax(0,1fr) 26px; }
  .topbar { height:92px;display:flex;flex-wrap:wrap;align-content:center;gap:6px;padding:6px 10px;overflow:visible; }
  .topbar .brand,.topbar .dt-select,.topbar #themeBtn { order:0; }
  .topbar .tb-spacer { display:none; }
  .topbar #startersBtn,.topbar #installAppBtn,.topbar #exportBtn,.topbar #mobileViewBtn { order:1;flex:1;justify-content:center;font-size:13px;min-height:38px;padding:6px 8px; }
  .topbar #themeBtn { margin-left:auto; }
  .topbar #shareBtn { display:none; }
  body .workspace,body.left-collapsed .workspace,body.right-collapsed .workspace,body.left-collapsed.right-collapsed .workspace { grid-template-columns:44px 0 minmax(0,1fr) 0; }
  body.mobile-code .workspace,body.mobile-code.left-collapsed.right-collapsed .workspace,body.mobile-code.right-collapsed .workspace { grid-template-columns:44px minmax(0,1fr) 0 0; }
  .rail { width:44px;overflow-y:auto;overflow-x:hidden; }
  .rail-btn { min-height:40px;flex-shrink:0; }
  .resizer,.resizer-h { display:none; }
  .canvas-toolbar { max-width:calc(100% - 16px);overflow-x:auto;bottom:12px; }
  .canvas-toolbar .icon-btn { min-width:38px;height:38px; }
  .canvas-toolbar .div { flex-shrink:0; }
  .modal-backdrop { padding:8px; }
  .modal { max-height:calc(var(--app-height,100dvh) - 24px);width:100%; }
  .export-layout { grid-template-columns:1fr !important;gap:12px !important; }
  .export-layout>div:last-child { display:none !important; }
  .modal-footer .input { max-width:100%; }
  .modal-tabs { overflow-x:auto;flex-shrink:0; }
  input,select,textarea { font-size:16px; }
  .statusbar .sb-item { display:none; }
  .statusbar #sbStatus,.statusbar #sbSaved { display:inline-flex; }
  body.fullscreen-canvas #app { grid-template-rows:0 minmax(0,1fr) 0; }
  body.fullscreen-canvas .workspace { grid-template-columns:0 0 minmax(0,1fr) 0; }
}

/* Phone workspace: one task per screen, navigation within thumb reach. */
.mobile-nav,.mobile-tool-heading,.mobile-canvas-heading { display:none; }
@media(max-width:768px) {
  body #app { display:grid;grid-template-rows:60px minmax(0,1fr) 68px;grid-template-columns:minmax(0,1fr);background:var(--bg);height:var(--app-height,100dvh); }
  body #app[hidden] { display:none; }
  body .topbar { height:60px;min-width:0;flex-wrap:nowrap;padding:8px 16px;gap:12px;background:var(--bg);border-bottom:1px solid var(--border); }
  body .topbar > * { display:none !important; }
  body .topbar > .brand { display:flex !important;flex:1;min-width:0;gap:9px;order:0; }
  body .topbar .brand-name { display:inline;font-size:16px;letter-spacing:-.04em; }
  body .topbar .brand-mark { width:28px;height:28px;border-radius:9px; }
  body .topbar > #exportBtn { display:flex !important;flex:0 0 auto;order:0;min-height:42px;padding:0 16px;font-size:14px;border-radius:12px; }
  body #app > .workspace { display:block !important;position:relative;overflow:hidden;min-height:0; }
  body #app .rail,body #app .right-panel,body #app .drawer,body #app .statusbar { display:none !important; }
  body #app .center { display:block;position:absolute;inset:0; }
  body #app .left-panel { display:none !important;position:absolute;inset:0;border:0;width:100%; }
  body[data-mobile-view="code"] #app .left-panel,body[data-mobile-view="tools"] #app .left-panel { display:flex !important; }
  body[data-mobile-view="code"] #app .center,body[data-mobile-view="tools"] #app .center { display:none; }
  body #app .mobile-nav { display:grid;grid-template-columns:repeat(4,1fr);gap:4px;background:var(--bg);border-top:1px solid var(--border);padding:5px 10px;z-index:50; }
  .mobile-nav button { display:flex;flex-direction:column;justify-content:center;align-items:center;gap:4px;border-radius:12px;color:var(--text-2);font-size:12px;min-height:54px;font-weight:500; }
  .mobile-nav button svg { width:22px;height:22px; }
  .mobile-nav button[aria-pressed="true"] { background:var(--accent-soft);color:var(--accent);font-weight:650; }
  body .panel-search { display:none; }
  body[data-mobile-view="tools"] .mobile-tool-heading { display:flex;align-items:center;justify-content:space-between;padding:16px 20px;border-bottom:1px solid var(--border);font-size:20px;font-weight:650; }
  .mobile-tool-heading button { font-size:14px;color:var(--accent);padding:10px 12px;border-radius:10px;background:var(--accent-soft); }
  body[data-mobile-view="tools"] .panel-body { padding:0 4px 24px; }
  body[data-mobile-view="tools"] .section { padding:20px 16px; }
  body[data-mobile-view="tools"] .section h4 { font-size:13px;margin-bottom:18px; }
  body[data-mobile-view="tools"] .row { min-height:52px;gap:12px; }
  body[data-mobile-view="tools"] .row label { font-size:15px; }
  body[data-mobile-view="tools"] .ctl { min-width:0; }
  body[data-mobile-view="tools"] input,body[data-mobile-view="tools"] select { min-height:40px; }
  body[data-mobile-view="code"] .panel-body { display:flex;overflow:hidden;padding:0; }
  body[data-mobile-view="code"] .panel-tab.active { display:flex;flex-direction:column;width:100%;height:100%;min-height:0; }
  body[data-mobile-view="code"] .editor-wrap { flex:1;min-height:0;overflow:auto;overscroll-behavior:contain; }
  body .editor-toolbar { padding:8px 12px;min-height:54px;gap:6px;flex-shrink:0; }
  body .editor-toolbar .icon-btn { width:40px;height:40px; }
  body .editor-toolbar .btn-secondary { font-size:12px;padding:8px; }
  body #edStat { display:none; }
  body .editor-pre,body .editor-textarea { font-size:16px;line-height:1.7;padding-top:16px;padding-bottom:80px; }
  body .line-gutter { font-size:16px;line-height:1.7;padding-top:16px;width:42px; }
  body .editor-textarea { height:100%;min-height:100%;overflow:auto;overscroll-behavior:contain; }
  body #canvas svg { touch-action:none; }
  body .toast-container { bottom:calc(78px + env(safe-area-inset-bottom));max-width:calc(100% - 24px); }
  .mobile-canvas-heading { display:flex;position:absolute;top:20px;left:20px;right:20px;align-items:center;gap:7px;z-index:2;pointer-events:none;font-size:12px;color:var(--text-2); }
  .mobile-canvas-heading>span:last-child { margin-left:auto;color:var(--text-3);font-size:11px; }
  .mobile-live-dot { width:6px;height:6px;border-radius:50%;background:var(--success); }
  body #canvas { top:48px;bottom:80px; }
  body .canvas-toolbar { top:auto;right:auto;left:50%;transform:translateX(-50%);bottom:18px;height:58px;width:max-content;flex-wrap:nowrap;max-width:calc(100% - 32px);padding:6px;border:1px solid var(--border);border-radius:16px;box-shadow:0 6px 22px #0000000d;overflow:visible;gap:4px; }
  body .canvas-toolbar > * { display:none !important; }
  body .canvas-toolbar #zoomIn,body .canvas-toolbar #zoomOut,body .canvas-toolbar #zoomFit,body .canvas-toolbar #zoomReadout { display:grid !important;place-items:center; }
  body .canvas-toolbar .icon-btn { width:44px;height:44px;border-radius:10px; }
  body .canvas-toolbar #zoomReadout { font-size:13px;min-width:52px; }
  body .canvas-toolbar #zoomFit { margin-left:8px;background:var(--accent-soft);color:var(--accent); }
  body .stale-badge { top:52px;max-width:calc(100% - 24px);font-size:12px; }
  body .modal-backdrop { padding:0;align-items:flex-end; }
  body .modal { width:100%;max-width:100%;max-height:calc(var(--app-height,100dvh) - 24px);border-radius:24px 24px 0 0;border-bottom:0;box-shadow:0 -12px 60px #0003;padding-bottom:env(safe-area-inset-bottom); }
  body .modal-header { padding:20px;min-height:68px; }
  body .modal-title { font-size:20px;letter-spacing:-.03em; }
  body .modal-header .icon-btn { width:44px;height:44px; }
  body .modal-body { padding:16px 20px 24px; }
  body .modal-footer { padding:16px 20px;gap:12px; }
  body .modal-footer button { min-height:46px;border-radius:12px; }
  body .modal-tabs { padding:0 12px; }
  body .modal-tab { min-height:46px;min-width:62px;font-size:14px; }
  .mobile-action-list { display:grid;gap:4px; }
  .mobile-action { display:flex;flex-direction:column;align-items:flex-start;text-align:left;padding:14px 12px;gap:3px;border-radius:12px;min-height:66px; }
  .mobile-action:active,.mobile-action:focus-visible { background:var(--accent-soft); }
  .mobile-action span { font-size:16px;font-weight:600; }
  .mobile-action small { font-size:13px;color:var(--text-2); }
  .starter-grid { grid-template-columns:1fr; }
  .starter-card { padding:20px;border-radius:16px; }
  .starter-card .btn-primary { width:100%;min-height:46px;justify-content:center;border-radius:12px; }
}

/* Bound every sheet to the viewport, including the desktop lg/xl variants. */
@media(max-width:768px) {
  body .modal-backdrop { display:flex;align-items:flex-end;justify-content:center;width:100%;height:var(--app-height,100dvh);bottom:auto;overflow:hidden; }
  body .modal,body .modal.lg,body .modal.xl { flex:0 1 auto;width:100%;min-width:0;max-width:100%;height:auto;min-height:0;max-height:calc(var(--app-height,100dvh) - env(safe-area-inset-top) - 12px);margin:0; }
  body .modal > * { min-width:0; }
  body .modal-header,body .modal-footer { flex-shrink:0; }
  body .modal-title { min-width:0;overflow-wrap:anywhere; }
  body .modal-header .icon-btn { flex-shrink:0; }
  body .export-content { flex:1 1 auto;min-height:0; }
  body .export-content .modal-body { overflow-y:auto;overflow-x:hidden; }
  body .export-layout { grid-template-columns:minmax(0,1fr) !important;width:100%;min-width:0; }
  body .export-layout > * { min-width:0; }
  body .export-layout .row { grid-template-columns:94px minmax(0,1fr);gap:12px;min-height:48px; }
  body .export-layout .ctl,body .export-layout .ctl > * { min-width:0;max-width:100%; }
  body .export-layout input,body .export-layout select { max-width:100%; }
  body .modal-tabs { display:grid;grid-template-columns:repeat(6,minmax(0,1fr));min-width:0;max-width:100%;overflow:hidden;padding:0 8px;gap:0; }
  body .modal-tab { min-width:0;padding:10px 2px;font-size:12px; }
  body .export-footer { display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:10px 12px; }
  body .export-footer .export-filename-label { grid-column:1/-1;font-size:13px;color:var(--text-2); }
  body .export-footer #exportFilename { grid-column:1/-1;width:100% !important;min-width:0;height:44px;font-size:16px; }
  body .export-footer > div { display:none; }
  body .export-footer button { width:100%;min-width:0;justify-content:center; }
}

.mobile-back,.sheet-back { display:none; }
.help-back { position:sticky;top:48px;z-index:2;display:block;padding:12px 16px;margin:12px 0;background:var(--accent-soft);color:var(--accent);border-radius:10px;font-size:15px; }
@media(max-width:768px) {
  body .topbar > .mobile-back:not([hidden]) { display:flex !important;align-items:center;min-height:44px;padding:0 10px;flex:0 0 auto;font-size:14px;color:var(--accent); }
  body[data-mobile-view="code"] .topbar .brand-name,body[data-mobile-view="tools"] .topbar .brand-name { display:none; }
  body .sheet-back { display:flex;align-items:center;justify-content:center;flex-shrink:0;min-height:44px;padding:0 10px;margin-right:10px;border-radius:10px;background:var(--accent-soft);color:var(--accent);font-size:14px; }
  body .modal-header { padding:12px;gap:4px; }
  body .modal-title { font-size:18px; }
}

.language-dialog { width:min(420px,calc(100vw - 24px));max-height:calc(100dvh - 32px);overflow:auto;padding:24px;border:1px solid var(--border);border-radius:20px;background:var(--bg);color:var(--text);font-family:var(--font-ui); }
.language-dialog::backdrop { background:#0008; }
.language-dialog h2 { font-size:20px;margin:0 0 16px; }
.language-dialog nav { display:grid;gap:8px; }
.language-dialog a { display:block;padding:14px 16px;border:1px solid var(--border);border-radius:10px;color:var(--text);font-size:16px;text-decoration:none; }
.language-dialog a[aria-current] { border-color:var(--accent);background:var(--accent-soft); }
.language-dialog button { min-height:44px;margin-top:16px;font-size:16px;color:var(--accent); }
html[lang^="zh"] { line-break:strict; }
html[lang^="zh"] .btn-primary,html[lang^="zh"] .btn-secondary { word-break:keep-all; }
/* The interface may use RTL; Mermaid syntax and coordinates remain LTR. */
html[dir="rtl"] #editorWrap,html[dir="rtl"] #canvas,html[dir="rtl"] pre { direction:ltr;text-align:left; }
