/* ==========================================================================
   Akuru — web app UI
   A modern browser-native shell: top bar with document chips, a vertical
   workspace rail, a canvas card with a floating tool palette, and a card-based
   inspector. Deliberately not a desktop-window imitation.
   ========================================================================== */

:root {
  /* Surfaces */
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #eef2f6;
  --line: #e2e7ee;
  --line-strong: #cbd3de;

  /* Ink */
  --ink: #131922;
  --ink-2: #475263;
  --ink-3: #727d8e;
  --ink-4: #9ea7b5;

  /* Accent: deep sea teal */
  --accent: #0d7a6f;
  --accent-strong: #085f56;
  --accent-soft: #e6f4f2;
  --accent-line: #b5dfd9;
  --plum: #6d4d8c;
  --amber: #e2a33c;
  --danger: #cf4b3f;
  --danger-soft: #fdecea;
  --ok: #2f8f5b;
  --ok-soft: #e6f4ec;

  /* Selection on canvas */
  --select: #0d7a6f;
  --node: #ffffff;
  --handle: #d9553f;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 1px rgba(15, 23, 42, 0.03);
  --shadow: 0 6px 18px rgba(15, 23, 42, 0.08), 0 1px 3px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 20px 50px rgba(15, 23, 42, 0.16), 0 4px 12px rgba(15, 23, 42, 0.06);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);

  --font: "Plus Jakarta Sans", "Geist", "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Mono", ui-monospace, "SF Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  font-size: 13px;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #d2d8e0; border-radius: 8px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: #b8c1cd; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

/* --------------------------------------------------------------- shell */

.app-shell {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: 58px minmax(0, 1fr) 26px;
  background: var(--bg);
}

.app-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 10px; flex: none; }
.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: linear-gradient(150deg, #12897b, #0a5f56);
  display: grid;
  place-items: center;
  box-shadow: 0 2px 6px rgba(8, 95, 86, 0.28);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-size: 14px; font-weight: 700; letter-spacing: -0.2px; }
.brand-sub { font-size: 10px; color: var(--ink-3); letter-spacing: 0.2px; }

.doc-chips { display: flex; align-items: center; gap: 6px; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.doc-chips::-webkit-scrollbar { display: none; }
.doc-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 12px;
  border-radius: 9px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--ink-2);
  font-size: 12px;
  white-space: nowrap;
  max-width: 240px;
  transition: background 0.12s, border-color 0.12s;
}
.doc-chip:hover { background: var(--surface-3); }
.doc-chip.is-active { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent-strong); font-weight: 600; }
.doc-chip .chip-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-4); flex: none; }
.doc-chip.is-active .chip-dot { background: var(--accent); }
.doc-chip .chip-name { overflow: hidden; text-overflow: ellipsis; }
.doc-chip .chip-close { opacity: 0; display: grid; place-items: center; width: 16px; height: 16px; border-radius: 4px; color: inherit; }
.doc-chip:hover .chip-close { opacity: 0.7; }
.doc-chip .chip-close:hover { opacity: 1; background: rgba(0, 0, 0, 0.06); }
.doc-chip .chip-dirty { color: var(--amber); font-size: 15px; line-height: 1; }

.chip-add {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  border: 1px dashed var(--line-strong);
  color: var(--ink-2);
  display: grid;
  place-items: center;
  flex: none;
}
.chip-add:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.header-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; flex: none; }

.search-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 10px 0 12px;
  min-width: 210px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink-3);
  font-size: 12px;
}
.search-trigger:hover { border-color: var(--line-strong); background: var(--surface-3); }
.search-trigger kbd {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 5px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink-3);
}

/* ------------------------------------------------------------------ body */

.app-body { display: grid; grid-template-columns: 88px minmax(0, 1fr); min-height: 0; }

.rail {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 8px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  scrollbar-width: none;
}
.rail::-webkit-scrollbar { display: none; }
.rail-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--ink-4);
  text-align: center;
  margin: 2px 0 6px;
}
.rail-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 9px 2px 8px;
  border-radius: 10px;
  color: var(--ink-2);
  font-size: 10px;
  line-height: 1.15;
  text-align: center;
  transition: background 0.12s, color 0.12s;
}
.rail-btn:hover { background: var(--surface-3); color: var(--ink); }
.rail-btn.is-active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.rail-btn .rail-key { font-size: 8.5px; color: var(--ink-4); font-family: var(--mono); }
.rail-btn.is-active .rail-key { color: var(--accent); }

.workspace {
  display: grid;
  grid-template-rows: 52px minmax(0, 1fr) auto;
  min-height: 0;
  min-width: 0;
}

/* ---------------------------------------------------------- context bar */

.context-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  overflow: hidden;
}
.context-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 650;
  letter-spacing: -0.1px;
  flex: none;
  padding-right: 10px;
  border-right: 1px solid var(--line);
  height: 24px;
}
.context-title .icon { color: var(--accent); }
.context-tools { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; overflow-x: auto; scrollbar-width: none; }
.context-tools::-webkit-scrollbar { display: none; }
.drawer-toggle { display: none; flex: none; }
.drawer-backdrop { display: none; }

/* ----------------------------------------------------------- work area */

.workspace-area {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr) 304px;
  min-height: 0;
  background: var(--bg);
}
.workspace-area.no-glyphs { grid-template-columns: minmax(0, 1fr) 304px; }
.workspace-area.no-inspector { grid-template-columns: 200px minmax(0, 1fr); }
.workspace-area.canvas-only { grid-template-columns: minmax(0, 1fr); }

/* Glyph sidebar */
.glyph-side {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--line);
}
.side-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px 8px;
  font-size: 11px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--ink-3);
  font-weight: 650;
}
.side-head .spacer { flex: 1; }
.side-head .count { font-size: 11px; color: var(--ink-3); font-family: var(--mono); letter-spacing: 0; text-transform: none; }

.glyph-filter { padding: 0 12px 10px; display: flex; flex-direction: column; gap: 8px; }
.search-box { position: relative; display: flex; align-items: center; }
.search-box .icon { position: absolute; left: 10px; color: var(--ink-3); pointer-events: none; }
.search-box input {
  width: 100%;
  height: 32px;
  padding: 0 10px 0 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  font-size: 12px;
  color: var(--ink);
}
.search-box input::placeholder { color: var(--ink-4); }
.search-box input:focus { outline: none; border-color: var(--accent); background: #fff; box-shadow: 0 0 0 3px var(--accent-soft); }

.chip-row { display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--ink-2);
  font-size: 11px;
  line-height: 1.4;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.chip:hover { border-color: var(--line-strong); background: var(--surface-3); }
.chip.is-active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

.glyph-grid {
  flex: 1;
  overflow-y: auto;
  padding: 4px 10px 14px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  align-content: start;
  grid-auto-rows: 54px;
}
.glyph-cell {
  position: relative;
  height: 54px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  overflow: hidden;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.glyph-cell:hover { border-color: var(--accent-line); box-shadow: var(--shadow-sm); }
.glyph-cell.is-active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.glyph-cell canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.glyph-cell .cell-char {
  position: absolute;
  top: 2px;
  left: 4px;
  font-size: 8.5px;
  color: var(--ink-3);
  background: rgba(255, 255, 255, 0.85);
  border-radius: 3px;
  padding: 0 3px;
  line-height: 1.3;
  max-width: calc(100% - 8px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.glyph-cell .cell-label {
  position: absolute;
  bottom: 2px;
  left: 5px;
  font-family: var(--mono);
  font-size: 8.5px;
  color: var(--ink-4);
  letter-spacing: 0.2px;
}
.glyph-cell.is-mark-cell { background: #fbf7fd; border-color: #ece2f3; }

/* Canvas stage */
.stage {
  position: relative;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
  padding: 12px;
  gap: 10px;
}
.canvas-card {
  position: relative;
  flex: 1;
  min-height: 0;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.stage-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 6px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  color: var(--ink-2);
  flex: none;
}
.stage-toolbar .hint { color: var(--ink-3); font-size: 11.5px; }
.stage-toolbar .spacer { flex: 1; }
.canvas-wrap { position: relative; flex: 1; min-height: 0; overflow: hidden; background: #fdfdfe; }
.canvas-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

.canvas-overlay-hud {
  position: absolute;
  left: 12px;
  bottom: 12px;
  display: flex;
  gap: 6px;
  pointer-events: none;
  font-family: var(--mono);
  font-size: 10px;
}
.hud-badge {
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  color: var(--ink-2);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(6px);
}

.canvas-tools {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  z-index: 6;
}
.zoom-hud {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  z-index: 6;
}
.zoom-hud .zoom-val { min-width: 42px; text-align: center; font-family: var(--mono); font-size: 11px; color: var(--ink-2); }

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

.inspector-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-left: 1px solid var(--line);
}
.inspector { flex: 1; overflow-y: auto; min-height: 0; padding: 0 0 16px; }
.inspector-tabs {
  display: flex;
  gap: 4px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 3;
}
.inspector-tab {
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  color: var(--ink-2);
  background: transparent;
}
.inspector-tab:hover { background: var(--surface-3); }
.inspector-tab.is-active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 650; }

.section {
  margin: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  color: var(--ink-3);
}
.section-head .section-title { display: flex; align-items: center; gap: 6px; }
.section-body { padding: 12px; display: flex; flex-direction: column; gap: 10px; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field-label { font-size: 11px; font-weight: 550; color: var(--ink-2); }
.field-hint { font-size: 11px; color: var(--ink-3); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field-row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

.text-input, .number-input, select.text-input {
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-size: 12px;
  width: 100%;
  color: var(--ink);
  transition: border-color 0.12s, box-shadow 0.12s;
}
.text-input:hover, .number-input:hover { border-color: var(--line-strong); }
.text-input:focus, .number-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.number-input { font-family: var(--mono); font-size: 12px; }
textarea.text-input { height: auto; min-height: 80px; padding: 8px 10px; resize: vertical; line-height: 1.5; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 12px;
  font-weight: 550;
  white-space: nowrap;
  transition: background 0.14s var(--ease), border-color 0.14s var(--ease), box-shadow 0.14s var(--ease), transform 0.1s var(--ease);
}
.btn:hover { background: var(--surface-2); border-color: var(--line-strong); }
.btn:active { transform: translateY(0.5px) scale(0.985); }
.btn:disabled { opacity: 0.45; pointer-events: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 1px 2px rgba(8, 95, 86, 0.25); }
.btn.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn.accent { background: var(--amber); border-color: var(--amber); color: #3a2a08; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-3); color: var(--ink); }
.btn.ghost.is-active { background: var(--accent-soft); color: var(--accent-strong); border-color: var(--accent-line); }
.btn.small { height: 26px; padding: 0 9px; font-size: 11.5px; border-radius: 7px; }
.btn.block { width: 100%; }

.icon-btn {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: var(--ink-2);
  transition: background 0.12s, color 0.12s;
}
.icon-btn:hover { background: var(--surface-3); color: var(--ink); }

.tb-btn {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: var(--ink-2);
  transition: background 0.12s, color 0.12s;
}
.tb-btn:hover { background: var(--surface-3); color: var(--ink); }
.tb-btn.is-active { background: var(--accent); color: #fff; box-shadow: 0 1px 3px rgba(8, 95, 86, 0.3); }
.tb-btn:disabled { opacity: 0.35; pointer-events: none; }
.tb-btn.wide { width: auto; padding: 0 10px; display: inline-flex; gap: 6px; font-size: 12px; }

.tool-group { display: flex; align-items: center; gap: 4px; }
.tool-sep { width: 1px; height: 20px; background: var(--line); margin: 0 6px; }
.tool-label { font-size: 11px; font-weight: 650; letter-spacing: 0.5px; text-transform: uppercase; color: var(--ink-3); margin-right: 4px; }
.toolbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.count-chip { font-size: 11.5px; color: var(--ink-3); white-space: nowrap; }
.count-chip b { color: var(--ink); font-weight: 650; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 11.5px;
  color: var(--ink-2);
}
.pill b { font-family: var(--mono); font-size: 11px; }
.pill.is-accent { border-color: #f2ddb4; background: #fdf6e7; color: #8a6414; }
.pill.is-navy { border-color: var(--accent-line); background: var(--accent-soft); color: var(--accent-strong); }

.segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-3); border-radius: 9px; }
.seg { padding: 4px 10px; border-radius: 7px; font-size: 11.5px; color: var(--ink-2); }
.seg:hover { color: var(--ink); }
.seg.is-active { background: var(--surface); color: var(--accent-strong); font-weight: 650; box-shadow: var(--shadow-sm); }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 12px; color: var(--ink-2); }
.switch {
  width: 36px;
  height: 20px;
  border-radius: 999px;
  background: #dfe4ea;
  position: relative;
  flex: none;
  transition: background 0.16s;
}
.switch .switch-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.24);
  transition: transform 0.16s;
}
.switch.is-on { background: var(--accent); }
.switch.is-on .switch-knob { transform: translateX(16px); }

.check { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-2); }
.check input { width: 15px; height: 15px; accent-color: var(--accent); }

.slider-row { display: flex; align-items: center; gap: 8px; }
.slider-row input[type="range"] { flex: 1; accent-color: var(--accent); height: 18px; }
.slider-row .slider-val { width: 36px; text-align: right; font-family: var(--mono); font-size: 11px; color: var(--ink-2); }
input[type="range"] { accent-color: var(--accent); }

/* --------------------------------------------------------------- lists */

.list { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); overflow: hidden; max-height: 240px; overflow-y: auto; }
.list-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  text-align: left;
  transition: background 0.1s;
}
.list-row:last-child { border-bottom: 0; }
.list-row:hover { background: var(--surface-2); }
.list-row.is-active { background: var(--accent-soft); }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .mono { font-family: var(--mono); font-size: 11px; color: var(--ink-2); }
.list-empty { padding: 18px; text-align: center; color: var(--ink-3); font-size: 12px; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 12px; margin: 0; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; font-family: var(--mono); color: var(--ink); text-align: right; font-size: 11.5px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 10px;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  font-weight: 700;
  background: var(--surface-3);
  color: var(--ink-2);
}
.badge.ok { background: var(--ok-soft); color: #23774a; }
.badge.warn { background: #fdf3e2; color: #96650f; }
.badge.bad { background: var(--danger-soft); color: #a83a30; }
.badge.navy { background: var(--accent-soft); color: var(--accent-strong); }
.badge.pink { background: #f3edf8; color: var(--plum); }

/* ------------------------------------------------------------ preview */

.preview-dock {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-top: 1px solid var(--line);
  min-height: 120px;
}
.preview-dock .preview-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: none;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--ink-3);
}
.preview-dock .preview-label small { font-size: 10px; letter-spacing: 0; text-transform: none; color: var(--ink-4); font-weight: 400; }
.preview-canvas { flex: 1; height: 80px; min-width: 0; }
.preview-controls { display: flex; align-items: center; gap: 6px; flex: none; }
.preview-controls .text-input { width: 240px; height: 32px; }

/* ------------------------------------------------------------ status */

.status-strip {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  background: var(--surface);
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: var(--ink-3);
  font-family: var(--mono);
}
.status-strip .spacer { flex: 1; }
.status-item { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.status-item b { font-weight: 600; color: var(--ink-2); }

/* ------------------------------------------------------------- welcome */

.welcome {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  background:
    radial-gradient(900px 500px at 12% -10%, #e7f4f1 0, transparent 60%),
    radial-gradient(700px 500px at 100% 100%, #f6efe2 0, transparent 55%),
    var(--bg);
  display: flex;
  justify-content: center;
  padding: 48px 24px;
}
.welcome-card { width: min(880px, 100%); }
.welcome-brand { display: flex; align-items: center; gap: 16px; margin-bottom: 8px; }
.welcome-brand .logo {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: linear-gradient(150deg, #12897b, #0a5f56);
  display: grid;
  place-items: center;
  box-shadow: 0 10px 26px rgba(8, 95, 86, 0.28);
  flex: none;
}
.welcome-brand h1 { margin: 0; font-size: 28px; letter-spacing: -0.8px; color: var(--ink); }
.welcome-brand p { margin: 4px 0 0; color: var(--ink-2); font-size: 13.5px; max-width: 560px; line-height: 1.55; }

.welcome-cta { display: flex; align-items: center; gap: 14px; margin: 22px 0 30px; flex-wrap: wrap; }
.welcome-cta .btn { height: 40px; padding: 0 18px; font-size: 13.5px; border-radius: 10px; }
.welcome-cta .small { color: var(--ink-3); font-size: 12px; }

.template-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.template-card {
  position: relative;
  text-align: left;
  padding: 16px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: transform 0.14s, box-shadow 0.14s, border-color 0.14s;
}
.template-card:hover { transform: translateY(-2px); border-color: var(--accent-line); box-shadow: var(--shadow); }
.template-card .t-name { font-size: 13.5px; font-weight: 650; display: flex; align-items: center; gap: 8px; }
.template-card .t-blurb { font-size: 12px; color: var(--ink-2); line-height: 1.5; }
.template-card .t-tag {
  align-self: flex-start;
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 700;
}
.welcome-foot { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 26px; }
.welcome-meta { display: flex; align-items: center; gap: 12px; margin-top: 18px; color: var(--ink-3); font-size: 12px; }
.welcome-meta a, .welcome-meta button { color: var(--accent-strong); font-weight: 550; }
.welcome-meta a:hover, .welcome-meta button:hover { text-decoration: underline; }

/* ------------------------------------------------------------- modals */

.modal-layer { position: fixed; inset: 0; pointer-events: none; z-index: 90; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(14, 22, 32, 0.38);
  backdrop-filter: blur(2px);
  display: grid;
  place-items: center;
  pointer-events: auto;
  padding: 24px;
  animation: fade 0.14s ease-out;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-height: calc(100vh - 64px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: pop 0.16s ease-out;
}
@keyframes pop { from { transform: translateY(6px) scale(0.99); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 20px 22px 14px; }
.modal-head h2 { margin: 0; font-size: 17px; letter-spacing: -0.3px; }
.modal-sub { margin: 6px 0 0; font-size: 12.5px; color: var(--ink-2); line-height: 1.55; max-width: 440px; }
.modal-body { padding: 4px 22px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.modal-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 22px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
}
.modal-foot .left { margin-right: auto; display: flex; gap: 8px; align-items: center; }

/* -------------------------------------------------------------- toasts */

.toast-layer { position: fixed; right: 18px; bottom: 40px; display: flex; flex-direction: column; gap: 8px; z-index: 120; pointer-events: none; }
.toast {
  padding: 10px 14px;
  border-radius: 10px;
  background: #1d2731;
  color: #fff;
  font-size: 12px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.18s, transform 0.18s;
  max-width: 420px;
}
.toast.in { opacity: 1; transform: translateY(0); }
.toast-ok { background: #1f6b4a; }
.toast-warn { background: #8a5c14; }
.toast-error { background: #9c2f26; }

/* ------------------------------------------------- menu (app menu) */

.menu-pop {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 60;
  width: 268px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  max-height: 70vh;
  overflow-y: auto;
}
.menu-group { padding: 4px 0; }
.menu-group + .menu-group { border-top: 1px solid var(--line); }
.menu-group-title {
  padding: 6px 10px 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  color: var(--ink-4);
}
.menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 12.5px;
  white-space: nowrap;
  cursor: pointer;
}
.menu-item:hover { background: var(--accent-soft); color: var(--accent-strong); }
.menu-item:hover .menu-key { color: var(--accent); }
.menu-item.is-disabled { color: var(--ink-4); pointer-events: none; }
.menu-key { font-size: 11px; color: var(--ink-4); font-family: var(--mono); }
.menu-sep { display: none; }

.header-menu-wrap { position: relative; }

/* --------------------------------------------------- kerning workspace */

.kerning-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; height: 100%; min-height: 0; }
.kerning-stage { display: flex; flex-direction: column; min-width: 0; }
.pair-strip { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--surface); flex-wrap: wrap; }
.pair-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  font-family: var(--mono);
  font-size: 11px;
}
.pair-values { display: flex; gap: 16px; margin-left: auto; }
.pair-values .pv { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.pair-values .pv span { font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--ink-3); }
.pair-values .pv b { font-family: var(--mono); font-size: 13px; }
.pair-values .pv b.neg { color: var(--danger); }

.pairs-table { display: flex; flex-direction: column; overflow-y: auto; min-height: 0; }
.pairs-table .list-row { padding: 6px 10px; }
.value-cell { width: 62px; text-align: right; font-family: var(--mono); font-size: 11.5px; }
.kern-slider { width: 100%; accent-color: var(--accent); }

/* fili matrix */
.matrix-wrap { overflow: auto; flex: 1; min-height: 0; background: var(--surface); border-radius: var(--radius); border: 1px solid var(--line); }
table.matrix { border-collapse: collapse; font-size: 11px; }
table.matrix th, table.matrix td { border: 1px solid var(--line); padding: 0; }
table.matrix th { position: sticky; top: 0; background: var(--surface-2); z-index: 2; font-weight: 650; color: var(--ink-2); padding: 6px 4px; font-size: 10px; }
table.matrix th.row-head { position: sticky; left: 0; z-index: 1; background: var(--surface-2); }
table.matrix td.cell { width: 34px; height: 30px; text-align: center; }
table.matrix td.cell canvas { width: 32px; height: 28px; display: block; }
table.matrix td.cell.ok { background: #f1faf5; }
table.matrix td.cell.bad { background: #fdf1ef; }
table.matrix td.cell.missing { background: #fdf7ec; }

/* proofing */
.proof-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; padding: 14px; overflow-y: auto; }
.proof-cell { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; box-shadow: var(--shadow-sm); }
.proof-cell .proof-head { padding: 7px 10px; background: var(--surface-2); border-bottom: 1px solid var(--line); font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--ink-3); font-weight: 700; }
.proof-cell canvas { display: block; width: 100%; }
.proof-cell.dark { background: #12181d; }
.proof-cell.dark .proof-head { background: #1b232b; border-color: #2a333c; color: #b9c4cf; }

/* font testing */
.test-layout { display: grid; grid-template-columns: minmax(0, 1fr) 260px; height: 100%; min-height: 0; }
.test-surface {
  position: relative;
  background: var(--surface);
  overflow: auto;
  padding: 22px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  margin: 12px;
}
.test-text { font-size: 34px; line-height: 1.7; color: #111; outline: none; }
.feature-row { display: flex; flex-wrap: wrap; gap: 5px; }

/* assistant */
.assistant-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; height: 100%; min-height: 0; }
.compare-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 12px; }
.compare-pane { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; box-shadow: var(--shadow-sm); }
.compare-pane .pane-head { display: flex; align-items: center; justify-content: space-between; padding: 7px 10px; background: var(--surface-2); border-bottom: 1px solid var(--line); font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--ink-3); font-weight: 700; }
.compare-pane canvas { display: block; width: 100%; }
.chat-log { display: flex; flex-direction: column; gap: 8px; padding: 12px; overflow-y: auto; flex: 1; min-height: 0; }
.chat-msg { padding: 9px 12px; border-radius: 12px; font-size: 12.5px; line-height: 1.5; max-width: 92%; }
.chat-msg.user { background: var(--accent-soft); color: var(--accent-strong); align-self: flex-end; border-bottom-right-radius: 4px; }
.chat-msg.bot { background: var(--surface-2); border: 1px solid var(--line); align-self: flex-start; border-bottom-left-radius: 4px; }
.chat-msg .msg-tag { display: block; font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--ink-3); margin-bottom: 3px; }
.quick-actions { display: flex; flex-wrap: wrap; gap: 5px; padding: 10px 12px; border-top: 1px solid var(--line); }

/* openType */
.fea-editor {
  flex: 1;
  min-height: 0;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.65;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin: 12px;
  padding: 14px 16px;
  background: var(--surface);
  resize: none;
  color: #1f2b36;
  tab-size: 2;
  box-shadow: var(--shadow-sm);
}
.fea-editor:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* variables */
.axis-graph { width: 100%; height: 130px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); }
.master-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  font-size: 12px;
}
.master-row:hover { border-color: var(--line-strong); }
.master-row.is-active { border-color: var(--accent); background: var(--accent-soft); }

/* --------------------------------------------------------- small helpers */

.mono { font-family: var(--mono); }
.muted { color: var(--ink-3); }
.small { font-size: 11.5px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.spacer { flex: 1; }
.hidden { display: none !important; }
.scroll-y { overflow-y: auto; min-height: 0; }
.full-height { height: 100%; min-height: 0; display: flex; flex-direction: column; }
.pad { padding: 12px; }

.card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm); }
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--ink-3);
  font-weight: 700;
}
.card-body { padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.empty-state { display: grid; place-items: center; gap: 10px; padding: 40px; color: var(--ink-3); font-size: 12.5px; text-align: center; }

.icon { flex: none; }

/* Canvas card wrapper used by full-width workspaces */
.workspace-panel { flex: 1; min-height: 0; margin: 12px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow-sm); overflow: hidden; display: flex; flex-direction: column; }

/* ------------------------------------------------ v2 structural additions */

.app-body { position: relative; }
.app-body.is-welcome { display: block; }
.welcome-hero { margin-bottom: 28px; }

.welcome-section-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--ink-3);
  margin: 0 0 12px;
}

.status-sep { width: 1px; height: 12px; background: var(--line); flex: none; }
.preview-dock.is-hidden { display: none; }

/* Workspace content sits directly inside the padded stage. */
.stage > .stage-toolbar {
  flex: none;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  min-height: 38px;
}
.stage > .canvas-wrap {
  flex: 1;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.stage > .matrix-wrap { margin: 0; }
.stage > .proof-grid { padding: 0; }

.canvas-tools-host { position: absolute; left: 12px; top: 12px; z-index: 6; }

.inspector-panel > .pairs-table { padding: 0 12px 12px; }
.inspector-panel > .side-head { padding: 12px 14px 6px; }
.inspector-panel > .list { margin: 0 12px 12px; }

/* Compact tool rows inside the context bar */
.context-tools .tool-label { display: none; }
.context-tools .pill { height: 30px; }
.context-tools .btn.small { height: 30px; padding: 0 12px; }

/* Glyph sidebar count alignment */
.side-head .count { font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------- v2 corrections */

/* Inspector panels are flex columns; sections must not shrink away. */
.inspector-panel > .section,
.inspector-panel > .inspector-tabs,
.inspector-panel > .side-head,
.inspector-panel > .card,
.inspector-panel > .list { flex: none; }
.inspector-panel > .pairs-table { flex: 1 1 auto; min-height: 140px; padding: 0 12px 12px; }

/* The hint strip floats above the canvas card rather than forming a second card. */
.stage > .stage-toolbar {
  border: 0;
  background: transparent;
  box-shadow: none;
  min-height: 30px;
  padding: 0 4px;
}

/* Glyph labels sit in a soft chip so they never collide with the outline. */
.glyph-cell .cell-char {
  position: absolute;
  top: 2px;
  left: 4px;
  font-size: 8.5px;
  color: var(--ink-3);
  background: rgba(255, 255, 255, 0.85);
  border-radius: 3px;
  padding: 0 3px;
  line-height: 1.3;
  max-width: calc(100% - 8px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.glyph-cell .cell-label {
  left: auto;
  right: 4px;
  bottom: 3px;
  background: rgba(255, 255, 255, 0.88);
  border-radius: 3px;
  padding: 0 3px;
  line-height: 1.3;
}

/* Keep the preview dock from being squeezed by workspaces that fill height. */
.workspace { grid-template-rows: 52px minmax(0, 1fr) auto; }
.preview-dock { flex: none; }

/* Keep compact controls compact inside workspace toolbars. */
.stage-toolbar .number-input { width: 92px; flex: none; }
.stage-toolbar .text-input { width: auto; min-width: 150px; }
.stage-toolbar .btn { flex: none; }
.stage-toolbar > .row { flex: 1; min-width: 0; }
.stage-toolbar > .row > .text-input { flex: 1; width: auto; }

/* Notifications sit under the header, clear of the preview dock. */
.toast-layer { top: 70px; bottom: auto; right: 18px; align-items: flex-end; }

/* Notifications clear the header and the preview dock. */
.toast-layer { top: auto; bottom: 86px; right: 18px; align-items: flex-end; }

/* ------------------------------------------- desktop & tablet responsiveness */

.glyph-grid,
.inspector,
.rail,
.modal-body,
.matrix-wrap,
.proof-grid,
.test-surface,
.chat-log {
  overscroll-behavior: contain;
}

.rail-btn:active,
.tb-btn:active,
.icon-btn:active,
.template-card:active {
  transform: scale(0.97);
}

/* Compact desktop / large tablet */
@media (max-width: 1180px) {
  .workspace-area { grid-template-columns: 176px minmax(0, 1fr) 280px; }
  .search-trigger { min-width: 0; padding: 0 10px; }
  .search-trigger span { display: none; }
}

/* Tablet portrait & landscape (<= 1080px): full-bleed canvas + slide-over drawers */
@media (max-width: 1080px) {
  .app-header { gap: 10px; padding: 0 12px; }
  .brand-sub { display: none; }
  .header-actions { gap: 6px; }
  .header-actions .btn .btn-label { display: none; }
  .header-actions .btn { padding: 0 10px; }
  .search-trigger kbd { display: none; }

  .app-body { grid-template-columns: 68px minmax(0, 1fr); }
  .rail { padding: 8px 5px; }
  .rail-btn { padding: 8px 2px; font-size: 9.5px; }
  .rail-btn .rail-key { display: none; }

  .drawer-toggle { display: inline-flex; }
  .workspace-area {
    position: relative;
    grid-template-columns: minmax(0, 1fr);
    overflow: hidden;
  }
  .workspace-area.no-glyphs,
  .workspace-area.no-inspector {
    grid-template-columns: minmax(0, 1fr);
  }

  .glyph-side,
  .inspector-panel {
    position: absolute;
    top: 0;
    bottom: 0;
    z-index: 32;
    width: min(300px, 84vw);
    box-shadow: var(--shadow-lg);
    transition: transform 0.22s var(--ease);
  }
  .glyph-side { left: 0; transform: translateX(-105%); }
  .inspector-panel { right: 0; width: min(320px, 86vw); transform: translateX(105%); }

  .workspace-area.drawer-glyphs-open .glyph-side { transform: translateX(0); }
  .workspace-area.drawer-inspector-open .inspector-panel { transform: translateX(0); }

  .workspace-area.drawer-glyphs-open .drawer-backdrop,
  .workspace-area.drawer-inspector-open .drawer-backdrop {
    display: block;
    position: absolute;
    inset: 0;
    z-index: 28;
    background: rgba(15, 23, 42, 0.24);
    backdrop-filter: blur(2px);
  }

  .preview-dock {
    flex-wrap: wrap;
    min-height: auto;
    padding: 8px 12px;
    gap: 8px;
  }
  .preview-canvas { height: 64px; min-width: 180px; }
  .preview-controls { flex-wrap: wrap; width: 100%; }
  .preview-controls .text-input { flex: 1 1 160px; width: auto; }
}

/* Narrow tablet / small screen (<= 820px) */
@media (max-width: 820px) {
  .template-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .compare-grid { grid-template-columns: 1fr; }
  .welcome { padding: 28px 16px; }
  .status-strip { gap: 10px; padding: 0 10px; overflow-x: auto; scrollbar-width: none; }
  .status-strip::-webkit-scrollbar { display: none; }
}

@media (max-width: 580px) {
  .template-grid { grid-template-columns: 1fr; }
}

/* Touch / tablet pointer comfort targets */
@media (pointer: coarse) {
  .icon-btn,
  .tb-btn { width: 38px; height: 38px; }
  .btn.small { height: 34px; padding: 0 12px; }
  .chip { padding: 6px 11px; }
  .rail-btn { min-height: 44px; justify-content: center; }
  .doc-chip { height: 38px; }
  .doc-chip .chip-close { opacity: 0.75; width: 22px; height: 22px; }
  .menu-item { padding: 11px 12px; }
}

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