/* figgy studio — light/dark themed, IBM Plex */

:root, body[data-theme="light"] {
  --bg: #f2f0ec;
  --panel: #ffffff;
  --panel-alt: #faf9f6;
  --border: #e5e2da;
  --border-soft: #eeece6;
  --text: #1d1b18;
  --dim: #8b8578;
  --faint: #b9b4a8;
  --accent: oklch(0.52 0.14 330);
  --accent-soft: oklch(0.52 0.14 330 / 0.1);
  --green: oklch(0.52 0.14 150);
  --stripe: rgba(0, 0, 0, 0.045);
  --shadow: 0 1px 2px rgba(28, 24, 20, 0.06), 0 8px 24px rgba(28, 24, 20, 0.07);
  --canvas-bg: #e9e6e0;
}
body[data-theme="dark"] {
  --bg: #141217;
  --panel: #1e1b22;
  --panel-alt: #252129;
  --border: #332e3a;
  --border-soft: #2a2630;
  --text: #edeaf0;
  --dim: #8f8898;
  --faint: #5d5765;
  --accent: oklch(0.72 0.14 330);
  --accent-soft: oklch(0.72 0.14 330 / 0.14);
  --green: oklch(0.72 0.14 150);
  --stripe: rgba(255, 255, 255, 0.05);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 32px rgba(0, 0, 0, 0.45);
  --canvas-bg: #19161d;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "IBM Plex Sans", system-ui, sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; padding: 0; }
input, select { font: inherit; color: var(--text); }
.spacer { flex: 1; }
.mono { font-family: "IBM Plex Mono", ui-monospace, monospace; }

/* ---- app frame -------------------------------------------------- */

#app { display: flex; flex-direction: column; height: 100vh; }
#topbar {
  height: 52px; flex: none;
  background: var(--panel); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 14px; padding: 0 16px;
}
.logo { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); }
.logo-mark { width: 22px; height: 22px; position: relative; }
.logo-mark::after {
  content: ""; position: absolute; inset: 0;
  background: url('data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"%3E%3Cpath d="M12 5.2 C12 7.2, 7.6 8.2, 7.1 12.6 C6.7 16.8, 9 19.8, 12 19.8 C15 19.8, 17.3 16.8, 16.9 12.6 C16.4 8.2, 12 7.2, 12 5.2 Z" fill="oklch(0.52 0.14 330)"/%3E%3Cpath d="M12 5.6 C12.2 4.2, 13 3.2, 14.4 2.9" fill="none" stroke="oklch(0.42 0.12 330)" stroke-width="1.6" stroke-linecap="round"/%3E%3Cpath d="M9 16.2 L11.2 13 L12.8 14.4 L15 10.6" fill="none" stroke="white" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" opacity="0.95"/%3E%3Ccircle cx="15" cy="10.6" r="1.5" fill="%238FE3B0"/%3E%3C/svg%3E') center / 100% 100% no-repeat;
}
body[data-theme="dark"] .logo-mark::after {
  background-image: url('data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"%3E%3Cpath d="M12 5.2 C12 7.2, 7.6 8.2, 7.1 12.6 C6.7 16.8, 9 19.8, 12 19.8 C15 19.8, 17.3 16.8, 16.9 12.6 C16.4 8.2, 12 7.2, 12 5.2 Z" fill="oklch(0.62 0.14 330)"/%3E%3Cpath d="M12 5.6 C12.2 4.2, 13 3.2, 14.4 2.9" fill="none" stroke="oklch(0.5 0.12 330)" stroke-width="1.6" stroke-linecap="round"/%3E%3Cpath d="M9 16.2 L11.2 13 L12.8 14.4 L15 10.6" fill="none" stroke="white" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" opacity="0.95"/%3E%3Ccircle cx="15" cy="10.6" r="1.5" fill="%238FE3B0"/%3E%3C/svg%3E');
}
.logo-word { font-weight: 700; font-size: 17px; letter-spacing: -0.02em; }
.vsep { width: 1px; height: 22px; background: var(--border); flex: none; }
#breadcrumb { font-size: 13px; color: var(--dim); display: flex; gap: 6px; align-items: center; min-width: 0; overflow: hidden; white-space: nowrap; }
.bc-sep { color: var(--faint); }
.bc-leaf { color: var(--text); font-weight: 600; }
#status { font-size: 12px; color: var(--dim); max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#status.error { color: #c0392b; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 8px; font-size: 13px; font-weight: 600;
  background: var(--panel-alt); border: 1px solid var(--border); white-space: nowrap;
}
.btn:hover { border-color: var(--dim); }
.btn.primary { background: var(--accent); color: #fff; border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.5; cursor: default; }
a.btn { text-decoration: none; color: inherit; cursor: pointer; }
#export-scale { padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel); }

#main { flex: 1; display: flex; min-height: 0; }

/* ---- left panel -------------------------------------------------- */

#left-panel {
  width: 264px; flex: none; background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 10px; padding: 12px;
}
#left-panel.dropping { outline: 2px dashed var(--accent); outline-offset: -6px; }
.panel-label { font-size: 10.5px; font-weight: 700; letter-spacing: 0.08em; color: var(--faint); padding: 2px 4px 0; }
#tree { flex: 1; overflow: auto; min-height: 0; }
.tree-empty { color: var(--dim); font-size: 12.5px; padding: 12px 6px; line-height: 1.6; }
.tree-line { position: relative; }
.tree-row {
  display: flex; align-items: center; gap: 7px; padding: 6px 8px; border-radius: 7px;
  cursor: pointer; color: var(--text); min-width: 0;
}
.tree-row:hover { background: var(--panel-alt); }
.tree-row.selected { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tree-row.dim .tree-name { color: var(--faint); }
.tree-caret { width: 12px; font-size: 9px; color: var(--faint); flex: none; text-align: center; }
.tree-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.tree-name.strong { font-weight: 600; }
.tree-meta { font-family: "IBM Plex Mono", monospace; font-size: 10.5px; color: var(--faint); flex: none; }
.tree-del { color: var(--faint); font-size: 10px; padding: 2px 4px; border-radius: 4px; display: none; flex: none; }
.tree-row:hover .tree-del { display: block; }
.tree-del:hover { color: #c0392b; background: var(--stripe); }
.tree-rename { flex: 1; min-width: 0; border: 1px solid var(--accent); border-radius: 4px; padding: 1px 4px; background: var(--panel); font-size: 12.5px; }
.tree-children { margin-left: 17px; border-left: 1px solid var(--border); padding-left: 3px; }
.tree-name.dimmed { color: var(--faint); }

.ic { display: inline-flex; flex: none; }
.ic-file { width: 11px; height: 13px; border: 1.5px solid var(--dim); border-radius: 2px; border-top-right-radius: 5px; }
.ic-sheet { width: 12px; height: 10px; border: 1.5px solid var(--dim); border-radius: 2px; display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.ic-sheet i:nth-child(1) { border-right: 1px solid var(--dim); border-bottom: 1px solid var(--dim); }
.ic-sheet i:nth-child(2) { border-bottom: 1px solid var(--dim); }
.ic-sheet i:nth-child(3) { border-right: 1px solid var(--dim); }
.ic-chart { width: 12px; height: 10px; border-left: 1.5px solid var(--dim); border-bottom: 1.5px solid var(--dim); position: relative; }
.ic-chart i { position: absolute; width: 4px; height: 4px; border-radius: 50%; border: 1.5px solid var(--dim); }
.ic-chart i:nth-child(1) { left: 1px; bottom: 0; }
.ic-chart i:nth-child(2) { right: 0; top: 0; }
.ic-chart.active { border-color: var(--accent); }
.ic-chart.active i { border-color: var(--accent); }

.ad-slot {
  flex: none; height: 84px; border-radius: 8px; border: 1.5px dashed var(--border);
  background: repeating-linear-gradient(45deg, transparent 0 9px, var(--stripe) 9px 10px);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-family: "IBM Plex Mono", monospace; font-size: 10.5px; color: var(--faint);
}

/* ---- center ------------------------------------------------------- */

#center { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; background: var(--canvas-bg); }

#presets-bar {
  min-height: 44px; flex: none; background: var(--panel); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px; row-gap: 6px; padding: 6px 14px;
  flex-wrap: wrap; /* narrow layouts wrap to extra lines — every preset stays reachable */
}
#presets-bar::-webkit-scrollbar { display: none; }
.bar-label { font-size: 10.5px; font-weight: 700; letter-spacing: 0.08em; color: var(--faint); flex: none; }
.bar-sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; flex: none; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; padding: 5px 10px; border-radius: 7px;
  border: 1px solid var(--border); background: var(--panel); font-size: 11.5px; font-weight: 550;
  color: var(--dim); white-space: nowrap; flex: none;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip-ic { width: 16px; height: 12px; display: inline-block; }
.chip-ic.boxedinward, .chip-ic.boxedoutward { border: 1.5px solid currentColor; }
.chip-ic.openoutward, .chip-ic.openinward { border-left: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; }
.chip-ic.minimal { border-bottom: 1.5px solid currentColor; }
.chip-swatches { display: inline-flex; gap: 2px; }
.chip-swatches i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }
.chip-active { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.chip-x {
  display: inline-flex; align-items: center; justify-content: center;
  width: 13px; height: 13px; margin-left: 2px; border-radius: 50%;
  font-size: 11px; line-height: 1; color: var(--faint);
}
.chip-x:hover { background: var(--accent); color: #fff; }
.chip-new { border-style: dashed; color: var(--dim); }
#preset-savebar {
  display: flex; align-items: center; gap: 8px; flex: none;
  padding: 7px 14px; background: var(--accent-soft); border-bottom: 1px solid var(--border);
}
#preset-savebar .psb-label { font-size: 11.5px; color: var(--dim); }
#preset-savebar input {
  width: 180px; padding: 4px 8px; font: inherit; font-size: 12px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
}
select.chip-select {
  appearance: none; -webkit-appearance: none; cursor: pointer;
  max-width: 130px; padding-right: 18px;
  background-image: linear-gradient(45deg, transparent 50%, var(--faint) 50%), linear-gradient(135deg, var(--faint) 50%, transparent 50%);
  background-position: calc(100% - 11px) 55%, calc(100% - 7px) 55%;
  background-size: 4px 4px; background-repeat: no-repeat;
}

#chart-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
#canvas-stage { flex: 1; min-height: 0; display: grid; place-items: center; padding: 18px 18px 10px; position: relative; overflow: hidden; }
#canvas-wrap {
  position: relative;
  background: #fff; border-radius: 10px; box-shadow: var(--shadow); overflow: hidden;
}
#chart-canvas { width: 100%; height: 100%; display: block; touch-action: none; }
/* aspect-ratio drag handles — selection-style grips on the canvas frame */
.a-h {
  position: absolute; z-index: 6; touch-action: none;
  background: var(--panel); border: 1.5px solid var(--accent); border-radius: 4px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.22); opacity: 0.85;
  transition: opacity 0.15s, background 0.15s;
}
.a-h:hover, .a-h.dragging { opacity: 1; background: var(--accent); }
.a-h.corner { right: 3px; bottom: 3px; width: 12px; height: 12px; cursor: nwse-resize; }
.a-h.right { right: 3px; top: 50%; transform: translateY(-50%); width: 7px; height: 34px; cursor: ew-resize; }
.a-h.bottom { bottom: 3px; left: 50%; transform: translateX(-50%); width: 34px; height: 7px; cursor: ns-resize; }
#aspect-badge {
  display: none; position: absolute; right: 14px; bottom: 22px; z-index: 7;
  font-family: "IBM Plex Mono", monospace; font-size: 11px;
  background: var(--panel); color: var(--dim);
  border: 1px solid var(--border); border-radius: 5px; padding: 3px 8px;
  pointer-events: none;
}
#zoom-box {
  display: none; position: absolute; border: 1.5px dashed var(--accent);
  background: var(--accent-soft); border-radius: 3px; pointer-events: none;
}

#gpu-banner {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 10px; text-align: center; padding: 40px;
  background: var(--panel); z-index: 5;
}
#gpu-banner .why { color: var(--dim); max-width: 480px; line-height: 1.6; }
#gpu-banner .head { font-size: 17px; font-weight: 650; }

#view-toolbar {
  align-self: center; flex: none; margin: 0 0 12px;
  display: flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 6px 10px; box-shadow: var(--shadow);
}
.tool {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 5px 8px; border-radius: 8px; border: 1px solid transparent; color: var(--dim);
}
.tool:hover { background: var(--panel-alt); }
.tool.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.tool.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.tool.disabled { opacity: 0.4; }

.legend-hint { font-size: 10.5px; color: var(--faint); line-height: 1.5; }
.w-subhead { font-size: 10px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--dim); }
.rt-edit.multi { min-height: 38px; }
.rt-hint { margin-left: auto; font-size: 9.5px; color: var(--faint); align-self: center; font-family: "IBM Plex Mono", monospace; }

@keyframes focusPulse {
  0% { box-shadow: 0 0 0 1.5px var(--accent); background: var(--accent-soft); }
  65% { box-shadow: 0 0 0 1.5px var(--accent); background: transparent; }
  100% { box-shadow: 0 0 0 0 transparent; background: transparent; }
}
.focus-ring { border-radius: 7px; animation: focusPulse 1.3s ease-out forwards; }

.w-divide { margin-top: 14px; padding-top: 11px; border-top: 1px solid var(--border); }

/* ---- system font picker ------------------------------------------------ */

.font-picker {
  position: fixed; top: 60px; right: 16px; z-index: 120;
  width: 280px; max-height: 60vh; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--border); border-radius: 11px;
  box-shadow: var(--shadow); overflow: hidden;
}
.font-picker-head { display: flex; align-items: center; gap: 6px; padding: 8px; border-bottom: 1px solid var(--border-soft); }
.font-search {
  flex: 1; min-width: 0; border: 1px solid var(--border); border-radius: 7px;
  background: var(--panel-alt); color: var(--text); font-size: 12.5px; padding: 6px 9px;
}
.font-search:focus { outline: 1px solid var(--accent); }
.font-list { overflow-y: auto; padding: 4px; display: flex; flex-direction: column; }
.font-list .menu-item { flex: none; }
/* pointer says what the drag will do: box zoom draws, unlocked pan grabs */
body.mode-boxzoom #chart-canvas { cursor: crosshair; }
body.mode-interactive:not(.mode-boxzoom) #chart-canvas { cursor: grab; }
body.mode-interactive:not(.mode-boxzoom) #chart-canvas:active { cursor: grabbing; }

.tool .glyph { font-size: 14px; line-height: 1; }
.tool .cap { font-size: 9px; font-family: "IBM Plex Mono", monospace; }
.tool-sep { width: 1px; align-self: stretch; background: var(--border); margin: 0 2px; }

#empty-view {
  flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px;
}
#empty-card {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 46px 64px; border: 2px dashed var(--border); border-radius: 16px;
  background: var(--panel-alt); text-align: center;
  transition: border-color 0.15s, background 0.15s;
}
#empty-view.dropping #empty-card { border-color: var(--accent); background: var(--accent-soft); }
.empty-mark { width: 54px; height: 54px; }
#empty-card h2 { margin: 4px 0 0; font-size: 20px; letter-spacing: -0.01em; color: var(--text); }
#empty-card p { margin: 0; font-size: 13px; line-height: 1.6; color: var(--dim); }
.empty-cta { display: flex; gap: 10px; margin-top: 10px; }
.empty-cta .btn { padding: 10px 18px; font-size: 14px; }
.empty-hint { font-size: 11px; color: var(--faint); font-family: "IBM Plex Mono", monospace; margin-top: 2px; }

/* ---- sheet view ----------------------------------------------------- */

#sheet-view { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 16px; gap: 10px; }
.sheet-toolbar { display: flex; align-items: center; gap: 10px; flex: none; flex-wrap: wrap; row-gap: 6px; }
.sheet-title { font-size: 14.5px; font-weight: 650; white-space: nowrap; }
.sheet-meta { font-family: "IBM Plex Mono", monospace; font-size: 11px; color: var(--faint); white-space: nowrap; }
.sheet-head {
  display: grid; flex: none; background: var(--panel-alt);
  border: 1px solid var(--border); border-top: none; border-bottom: none; overflow: hidden;
}
.sheet-letters {
  display: grid; flex: none; background: var(--panel-alt);
  border: 1px solid var(--border); border-bottom: 1px solid var(--border); border-radius: 8px 8px 0 0; overflow: hidden;
}
.sheet-cell.letter {
  height: 22px; justify-content: center; padding: 0;
  font-size: 10.5px; color: var(--dim); background: var(--panel-alt);
  cursor: pointer; user-select: none;
}
.sheet-cell.letter:hover { background: var(--accent-soft); color: var(--accent); }
.sheet-cell.letter.colsel { background: var(--accent); color: #fff; }
.sheet-cell.letter.corner { cursor: pointer; }
.sheet-scroll { flex: 1; overflow: auto; border: 1px solid var(--border); border-radius: 0 0 8px 8px; background: var(--panel); position: relative; }
.sheet-spacer { position: relative; }
.sheet-grid { display: grid; position: absolute; left: 0; right: 0; top: 0; }
.sheet-cell {
  padding: 0 10px; height: 28px; display: flex; align-items: center;
  border-bottom: 1px solid var(--border-soft); border-right: 1px solid var(--border-soft);
  font-family: "IBM Plex Mono", monospace; font-size: 12px; justify-content: flex-end;
  overflow: hidden; white-space: nowrap; background: var(--panel);
}
.sheet-cell.data { cursor: cell; user-select: none; }
.sheet-cell.sel { background: var(--accent-soft); }
.sheet-cell.active { outline: 2px solid var(--accent); outline-offset: -2px; }
.sheet-cell.colsel { background: var(--accent-soft); }
.sheet-scroll:focus { outline: none; }
.sheet-cell.nonnum { color: #b06030; justify-content: flex-start; }
.sheet-cell.head, .sheet-cell.corner, .sheet-cell.rowno { background: var(--panel-alt); cursor: default; }
.sheet-cell.head {
  flex-direction: column; align-items: stretch; justify-content: center; gap: 3px;
  height: 58px; padding: 7px 8px; cursor: pointer;
}
.head-line { display: flex; align-items: center; gap: 6px; min-width: 0; }
.sheet-cell.rowno { justify-content: center; color: var(--faint); font-size: 10.5px; }
.sheet-colletter { color: var(--faint); font-size: 10.5px; flex: none; }
.sheet-colname {
  flex: 1; min-width: 0; border: none; background: transparent; font-family: "IBM Plex Sans", sans-serif;
  font-weight: 600; font-size: 12px; padding: 2px 0;
}
.sheet-colname:focus { outline: 1px solid var(--accent); border-radius: 3px; }
.unit-wrap {
  flex: 1; min-width: 0; display: inline-flex; align-items: center; gap: 0;
  border: 1px solid var(--border); border-radius: 5px; background: var(--panel); overflow: hidden;
}
.unit-wrap:focus-within { border-color: var(--accent); }
.unit-tag {
  flex: none; font-family: "IBM Plex Mono", monospace; font-size: 9px; letter-spacing: 0.04em;
  color: var(--faint); background: var(--panel-alt); padding: 3px 5px; border-right: 1px solid var(--border-soft);
}
.sheet-colunit {
  flex: 1; min-width: 0; max-width: none; border: none; background: transparent;
  font-family: "IBM Plex Mono", monospace; font-size: 11px; color: var(--text);
  padding: 2px 5px; border-radius: 0;
}
.sheet-colunit::placeholder { color: var(--faint); }
.sheet-colunit:hover, .sheet-colunit:focus { border-color: transparent; outline: none; background: transparent; }
.role-select {
  margin-left: auto; flex: none; max-width: 96px;
  font-family: "IBM Plex Mono", monospace; font-size: 10.5px;
  border: 1px solid var(--border); border-radius: 5px; background: var(--panel); color: var(--dim);
  padding: 1px 2px; cursor: pointer;
}
.role-select.x { background: var(--green); color: #fff; border-color: transparent; }
.role-select.y { background: var(--accent); color: #fff; border-color: transparent; }
.role-select.xe, .role-select.ye { color: oklch(0.55 0.13 60); border-color: oklch(0.55 0.13 60 / 0.6); font-weight: 600; }
.role-select option { background: var(--panel); color: var(--text); }
.role-badge {
  flex: none; font-family: "IBM Plex Mono", monospace; font-size: 10px; border-radius: 4px;
  padding: 1px 6px; color: #fff; background: var(--faint);
}
.role-badge.x { background: var(--green); }
.role-badge.y { background: var(--accent); }
.role-badge.none { background: transparent; color: var(--faint); border: 1px dashed var(--border); }
.sheet-cell.editing { padding: 0; }
.sheet-editor { width: 100%; height: 100%; border: 2px solid var(--accent); background: var(--panel); padding: 0 8px; font-family: "IBM Plex Mono", monospace; font-size: 12px; text-align: right; }
.sheet-editor:focus { outline: none; }

/* ---- context menu ---------------------------------------------------- */

.ctx-menu {
  position: fixed; z-index: 100; min-width: 170px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 9px;
  box-shadow: var(--shadow); padding: 4px; display: flex; flex-direction: column;
}
.menu-item { text-align: left; padding: 7px 10px; border-radius: 6px; font-size: 12.5px; }
.menu-item:hover { background: var(--accent-soft); color: var(--accent); }
.menu-item.current { color: var(--accent); font-weight: 650; }
.menu-sep { height: 1px; background: var(--border-soft); margin: 3px 6px; }

/* ---- rich text editor -------------------------------------------------- */

.rt-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.rt-edit {
  border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px; background: var(--panel);
  font-size: 13px; min-height: 18px; line-height: 1.45; cursor: text; white-space: pre-wrap; word-break: break-word;
}
.rt-edit:focus { outline: 1px solid var(--accent); }
.rt-edit:empty::before { content: attr(data-placeholder); color: var(--faint); }
.rt-ch.b { font-weight: 700; }
.rt-ch.i { font-style: italic; }
.rt-ch.u { text-decoration: underline; }
.rt-ch.sup { vertical-align: super; font-size: 0.72em; }
.rt-ch.sub { vertical-align: sub; font-size: 0.72em; }
.rt-ch.tab { color: var(--faint); padding: 0 1px; user-select: text; }
/* fixed-width symbol fields (field_em) — ink centered in a fixed advance */
.rt-ch.field { display: inline-block; text-align: center; vertical-align: baseline; }
.rt-ch.rule { letter-spacing: 0; overflow: hidden; }
.rt-bar { display: flex; gap: 2px; }
.rt-btn {
  border: 1px solid var(--border); background: var(--panel-alt); border-radius: 5px;
  font-size: 10.5px; padding: 2px 7px; color: var(--dim); font-family: "IBM Plex Sans", sans-serif;
}
.rt-btn:hover { color: var(--accent); border-color: var(--accent); }
.rt-bold { font-weight: 700; }
.rt-italic { font-style: italic; }
.rt-underline { text-decoration: underline; }

/* ---- inspector -------------------------------------------------------- */

#right-panel {
  width: 312px; flex: none; background: var(--panel); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
body.insp-collapsed #right-panel { display: none; }
body.sheet-mode #right-panel, body.sheet-mode #insp-rail { display: none !important; }
#insp-rail {
  display: none; width: 40px; flex: none; background: var(--panel); border-left: 1px solid var(--border);
  flex-direction: column; align-items: center; padding: 12px 0; gap: 10px; cursor: pointer;
}
body.insp-collapsed #insp-rail { display: flex; }
#insp-rail .rail-text { writing-mode: vertical-rl; font-family: "IBM Plex Mono", monospace; font-size: 10px; letter-spacing: 0.12em; color: var(--faint); }
.insp-top { display: flex; align-items: center; gap: 8px; padding: 12px 14px 8px; flex: none; }
#inspector-content { flex: 1; overflow-y: auto; overflow-x: hidden; min-height: 0; scrollbar-gutter: stable; }
.collapse-btn { font-size: 12px; color: var(--dim); border: 1px solid var(--border); border-radius: 6px; padding: 2px 8px; }
.collapse-btn:hover { color: var(--accent); border-color: var(--accent); }

.insp-section { border-bottom: 1px solid var(--border-soft); }
.insp-section.flash { animation: flash 0.9s ease-out; }
@keyframes flash { 0% { background: var(--accent-soft); } 100% { background: transparent; } }
.insp-head {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px; width: 100%;
  font-size: 12.5px; font-weight: 650; text-align: left; white-space: nowrap;
}
.insp-title { overflow: hidden; text-overflow: ellipsis; }
.insp-caret { font-size: 9px; color: var(--faint); width: 10px; }
.insp-badge { font-size: 10px; font-family: "IBM Plex Mono", monospace; color: var(--accent); background: var(--accent-soft); border-radius: 4px; padding: 1px 6px; margin-left: auto; }
.insp-body { padding: 2px 14px 14px; display: flex; flex-direction: column; gap: 9px; }
.insp-empty { color: var(--dim); padding: 18px 16px; line-height: 1.6; }
.insp-actions { display: flex; gap: 8px; margin-top: 4px; }
.axis-controls { display: flex; flex-direction: column; gap: 9px; }

.chart-link { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 6px; width: 100%; text-align: left; color: var(--text); }
.chart-link:hover { background: var(--accent-soft); color: var(--accent); }
.ycol-list { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.ycol-item { display: flex; align-items: center; gap: 7px; font-size: 12.5px; cursor: pointer; white-space: nowrap; }

.series-card { border: 1px solid var(--border-soft); border-radius: 8px; padding: 10px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.series-head { display: flex; align-items: center; gap: 8px; }
.series-dot { width: 11px; height: 11px; border-radius: 50%; flex: none; }
.series-meta { font-family: "IBM Plex Mono", monospace; font-size: 10.5px; color: var(--faint); }

/* ---- widgets ------------------------------------------------------------ */

.w-row { display: flex; align-items: center; gap: 8px; min-height: 24px; min-width: 0; }
.w-label { font-size: 12px; color: var(--dim); width: 76px; flex: 0 1 76px; min-width: 48px; }
.w-controls { flex: 1; display: flex; align-items: center; gap: 6px; justify-content: flex-end; flex-wrap: wrap; min-width: 0; }
.w-seg { display: flex; background: var(--panel-alt); border: 1px solid var(--border); border-radius: 7px; padding: 2px; gap: 2px; }
.w-seg-btn { padding: 3px 9px; border-radius: 5px; font-size: 11.5px; font-weight: 550; color: var(--dim); white-space: nowrap; }
.w-seg-btn.active { background: var(--panel); color: var(--accent); box-shadow: 0 1px 2px rgba(0,0,0,0.12); }
.w-toggle { width: 30px; height: 17px; border-radius: 9px; background: var(--border); position: relative; flex: none; transition: background 0.15s; }
.w-toggle.on { background: var(--accent); }
.w-knob { position: absolute; top: 2px; left: 2px; width: 13px; height: 13px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,0.25); transition: left 0.15s; }
.w-toggle.on .w-knob { left: 15px; }
.w-num, .w-text, .w-select {
  border: 1px solid var(--border); border-radius: 6px; padding: 4px 7px; background: var(--panel);
  font-size: 12px;
}
.w-num {
  font-family: "IBM Plex Mono", monospace; text-align: right;
  -moz-appearance: textfield; appearance: textfield;
}
.w-num::-webkit-outer-spin-button, .w-num::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.w-text.grow { flex: 1; min-width: 60px; }
.w-text:not(.grow) { width: 110px; }
.w-num:focus, .w-text:focus, .w-select:focus { outline: 1px solid var(--accent); }
.w-slider-wrap { display: flex; align-items: center; gap: 7px; flex: 1 1 120px; min-width: 0; }
.w-slider { flex: 1; accent-color: var(--accent); height: 4px; min-width: 46px; }
.w-slider-num {
  width: 46px; flex: none; padding: 3px 5px; font-size: 11px; text-align: right;
  -moz-appearance: textfield; appearance: textfield;
}
.w-slider-num::-webkit-outer-spin-button, .w-slider-num::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.w-slider-val { font-family: "IBM Plex Mono", monospace; font-size: 11px; color: var(--dim); width: 32px; text-align: right; flex: none; }
.w-color { width: 30px; height: 24px; padding: 1px; border: 1px solid var(--border); border-radius: 6px; background: var(--panel); cursor: pointer; }
.w-color-wrap { display: flex; align-items: center; gap: 5px; }
.w-std {
  width: 24px; height: 24px; flex: none; position: relative;
  border: 1px solid var(--border); border-radius: 6px; padding: 0;
  /* color-wheel icon — reads as "pick a color" at a glance */
  background:
    radial-gradient(circle at 50% 50%, var(--panel) 0 27%, transparent 29%),
    conic-gradient(#e6194b, #f58231, #ffe119, #3cb44b, #17a2a2, #4363d8, #911eb4, #f032e6, #e6194b);
}
.w-std:hover { border-color: var(--accent); box-shadow: 0 0 0 1.5px var(--accent-soft); }
.w-std-pop {
  position: fixed; z-index: 99; display: grid; grid-template-columns: repeat(5, 18px); gap: 5px;
  padding: 9px; background: var(--panel); border: 1px solid var(--border); border-radius: 9px;
  box-shadow: var(--shadow);
}
.w-std-swatch { width: 18px; height: 18px; border-radius: 4px; border: 1px solid rgba(127, 127, 127, 0.35); cursor: pointer; }
.w-std-swatch:hover { outline: 2px solid var(--accent); }
.w-sync {
  flex: none; font-size: 12px; line-height: 1; padding: 4px 6px;
  border: 1px solid var(--border); border-radius: 6px; color: var(--dim); background: var(--panel);
}
.w-sync:hover { color: var(--accent); border-color: var(--accent); }
/* editing a syncable row pulses its ⇉ — a standing "you can bulk-apply this"
   invitation (kept forever by design; regulars tune it out) */
.w-sync.pulse { animation: sync-pulse 0.65s ease-out 2; }
@keyframes sync-pulse {
  0%   { box-shadow: 0 0 0 0 var(--accent-soft); color: var(--accent); border-color: var(--accent); }
  60%  { box-shadow: 0 0 0 8px transparent; color: var(--accent); border-color: var(--accent); }
  100% { box-shadow: 0 0 0 0 transparent; }
}
.w-sync.applied { color: var(--green); border-color: var(--green); }
@media (prefers-reduced-motion: reduce) {
  .w-sync.pulse { animation: none; color: var(--accent); border-color: var(--accent); }
}
.w-btn { border: 1px solid var(--border); background: var(--panel-alt); border-radius: 7px; padding: 5px 11px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.w-btn:hover { border-color: var(--dim); }
.w-btn.primary { background: var(--accent); border-color: transparent; color: #fff; }

/* ---- popover --------------------------------------------------------------- */

#popover {
  display: none; position: absolute; width: 332px; max-width: calc(100% - 16px); z-index: 30;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); overflow: hidden;
}
.pop-head { display: flex; align-items: center; gap: 8px; padding: 9px 12px; border-bottom: 1px solid var(--border-soft); }
.pop-title { font-size: 12.5px; font-weight: 650; white-space: nowrap; }
.pop-open-insp { font-size: 10.5px; color: var(--dim); border: 1px solid var(--border); border-radius: 5px; padding: 2px 7px; white-space: nowrap; }
.pop-open-insp:hover { color: var(--accent); border-color: var(--accent); }
.pop-close { color: var(--faint); font-size: 11px; padding: 2px 4px; }
.pop-body { padding: 12px; display: flex; flex-direction: column; gap: 9px; max-height: 380px; overflow-y: auto; overflow-x: hidden; scrollbar-gutter: stable; }
.pop-body .w-row, .pop-body .series-card { min-width: 0; }
/* popover is width-constrained — tighter label column + card padding */
.pop-body .w-label { width: 64px; }
.pop-body .series-card { padding: 8px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }
