/* Drawtomata · "Calm Canvas": quiet chrome, white canvas, slate type, blue for action and selection.
   Layout: top bar + full-height panels. Split panels = input sidebar + result board. Draw FA = full canvas + floating tools + results drawer. */
:root {
  --canvas: #FFFFFF;
  --bg: #F8FAFC;
  --fg: #111827;
  --muted: #64748B;
  --line: #E2E8F0;
  --line-strong: #CBD5E1;
  --accent: #2563EB;
  --accent-hover: #1D4ED8;
  --accent-soft: #DBEAFE;
  --on-accent: #FFFFFF;
  --blue: #DBEAFE;
  --green: #DCFCE7;
  --amber: #FEF3C7;
  --rose: #FFE4E6;
  --violet: #EDE9FE;
  --green-ink: #15803D;
  --amber-ink: #B45309;
  --rose-ink: #BE123C;
  --violet-ink: #6D28D9;
  --node: #FFFFFF;
  --node-stroke: #475569;
  --edge: #64748B;
  --dot: #DCE3EC;
  --float-shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 6px 20px rgba(15, 23, 42, 0.06);
  --ui: "IBM Plex Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --r-sm: 6px;
  --r: 8px;
  --r-lg: 10px;
  --top: 56px;
  --plate-1: #EEF2F7; --plate-2: #E2E8F0; --key-1: #FFFFFF; --key-2: #EEF2F7; --key-side: #C9D3E0; --rim: rgba(255, 255, 255, 0.95); --drop: rgba(15, 23, 42, 0.18);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --canvas: #0B1220; --bg: #0F172A; --fg: #F1F5F9; --muted: #94A3B8; --line: #1E293B; --line-strong: #334155;
    --accent: #3B82F6; --accent-hover: #60A5FA; --accent-soft: #172554; --on-accent: #FFFFFF;
    --blue: #172554; --green: #052E16; --amber: #3A2A07; --rose: #4C0519; --violet: #2E1065;
    --green-ink: #4ADE80; --amber-ink: #FBBF24; --rose-ink: #FB7185; --violet-ink: #A78BFA;
    --node: #111A2E; --node-stroke: #94A3B8; --edge: #94A3B8; --dot: #1C2638; --plate-1: #131C2E; --plate-2: #0B1220; --key-1: #26324A; --key-2: #1A2438; --key-side: #070B14; --rim: rgba(255, 255, 255, 0.22); --drop: rgba(0, 0, 0, 0.55);
    --float-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --canvas: #0B1220; --bg: #0F172A; --fg: #F1F5F9; --muted: #94A3B8; --line: #1E293B; --line-strong: #334155;
  --accent: #3B82F6; --accent-hover: #60A5FA; --accent-soft: #172554; --on-accent: #FFFFFF;
  --blue: #172554; --green: #052E16; --amber: #3A2A07; --rose: #4C0519; --violet: #2E1065;
  --green-ink: #4ADE80; --amber-ink: #FBBF24; --rose-ink: #FB7185; --violet-ink: #A78BFA;
  --node: #111A2E; --node-stroke: #94A3B8; --edge: #94A3B8; --dot: #1C2638; --plate-1: #131C2E; --plate-2: #0B1220; --key-1: #26324A; --key-2: #1A2438; --key-side: #070B14; --rim: rgba(255, 255, 255, 0.22); --drop: rgba(0, 0, 0, 0.55);
  --float-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body { margin: 0; background: var(--bg); color: var(--fg); font: 400 14px/1.55 var(--ui); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 0.93em; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
h1, h2, h3 { margin: 0; line-height: 1.25; text-wrap: balance; font-weight: 600; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button { font: inherit; color: inherit; }
kbd { font: 500 10px var(--ui); color: var(--muted); }
.ic { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: square; stroke-linejoin: miter; stroke-miterlimit: 8; flex: none; }
.ic.sm { width: 15px; height: 15px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* ---------- app shell ---------- */
.app { height: 100%; display: flex; flex-direction: column; padding-top: env(safe-area-inset-top, 0px); }
.topbar {
  height: var(--top); flex: none; display: flex; align-items: center; gap: 16px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: var(--canvas); border-bottom: 1px solid var(--line);
}
.brandH { margin: 0; font-size: inherit; font-weight: inherit; line-height: 1; flex: none; }
.vh { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.brand { display: flex; align-items: center; gap: 9px; color: var(--fg); flex: none; }
.brand:hover { text-decoration: none; }
.logoMark { width: 28px; height: 28px; display: block; }
.wordmark { font: 600 17px var(--ui); letter-spacing: -0.02em; }
.wordmark span { color: var(--accent); }
.modes { display: flex; gap: 2px; padding: 3px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-lg); overflow-x: auto; scrollbar-width: none; min-width: 0; margin: 0 auto; }
.modes::-webkit-scrollbar { display: none; }
.modes button { flex: none; border: 0; background: none; color: var(--muted); font-weight: 500; font-size: 13.5px; padding: 6px 12px; border-radius: var(--r-sm); cursor: pointer; white-space: nowrap; transition: background 0.15s, color 0.15s; }
.modes button:hover { color: var(--fg); }
.modes button[aria-pressed="true"] { background: var(--canvas); color: var(--fg); box-shadow: 0 0 0 1px var(--line); }
.subModes { flex: none; display: flex; gap: 4px; height: 40px; align-items: stretch; overflow-x: auto; scrollbar-width: none; background: var(--canvas); border-bottom: 1px solid var(--line); padding-left: max(12px, env(safe-area-inset-left, 0px)); padding-right: max(12px, env(safe-area-inset-right, 0px)); }
.subModes::-webkit-scrollbar { display: none; }
.subModes button { flex: none; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--muted); font-weight: 500; font-size: 13.5px; padding: 0 10px; cursor: pointer; white-space: nowrap; transition: color 0.15s, border-color 0.15s; }
.subModes button[hidden] { display: none; }
.welcome { flex: none; position: relative; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 8px 48px 8px max(16px, env(safe-area-inset-left, 0px)); background: var(--accent-soft); border-bottom: 1px solid var(--line); font-size: 13.5px; }
.welcome[hidden] { display: none; }
.welcome p { margin: 0; }
.welcomeBtns { display: flex; flex-wrap: wrap; gap: 6px; }
.welcomeBtns button { padding: 4px 10px; font-size: 13px; }
.welcomeX { position: absolute; top: 50%; right: 8px; transform: translateY(-50%); font-size: 18px; }
.subModes button:hover { color: var(--fg); }
.subModes button[aria-selected="true"] { color: var(--fg); border-bottom-color: var(--accent); }
.topRight { display: flex; align-items: center; gap: 8px; flex: none; }
.epsSwitch { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.epsSwitch button { width: 32px; height: 30px; border: 0; background: var(--canvas); color: var(--muted); font: 500 14px var(--mono); cursor: pointer; }
.epsSwitch button + button { border-left: 1px solid var(--line); }
.epsSwitch button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.iconBtn { width: 32px; height: 32px; display: inline-grid; place-items: center; border: 0; background: none; color: var(--fg); border-radius: var(--r-sm); cursor: pointer; flex: none; transition: background 0.12s; }
.iconBtn:hover { background: var(--bg); }
.iconBtn:disabled { color: var(--line-strong); cursor: default; background: none; }
.topRight .iconBtn { border: 1px solid var(--line); background: var(--canvas); }
.main { flex: 1; min-height: 0; position: relative; }
.panel { height: 100%; }

/* ---------- split panels ---------- */
.split { display: grid; grid-template-columns: 360px minmax(0, 1fr); }
.side {
  background: var(--canvas); border-right: 1px solid var(--line); overflow-y: auto;
  padding: 20px 20px 32px; padding-left: max(20px, env(safe-area-inset-left, 0px));
  display: flex; flex-direction: column; gap: 16px; min-width: 0;
}
.sideHead h2 { font-size: 20px; letter-spacing: -0.01em; }
.sideHead p { margin: 4px 0 0; color: var(--muted); font-size: 13.5px; }
.board {
  overflow: auto; min-width: 0;
  background-color: var(--bg);
  background-image: radial-gradient(var(--dot) 1px, transparent 1.2px);
  background-size: 22px 22px;
}
.boardInner { max-width: 1040px; margin: 0 auto; padding: 24px; padding-right: max(24px, env(safe-area-inset-right, 0px)); padding-bottom: max(40px, env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 16px; }
.emptyState { max-width: 520px; margin: 48px auto; text-align: center; color: var(--muted); }
.emptyState h2 { font-size: 18px; color: var(--fg); margin: 0 0 8px; }
.emptyState p { margin: 0 0 16px; line-height: 1.6; }
.boardInner:empty::before { content: "Results appear here."; color: var(--muted); padding: 40px 0; text-align: center; }

/* ---------- form controls ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.fieldRow { display: flex; gap: 10px; align-items: flex-end; min-width: 0; }
.fieldRow.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.lbl { font-size: 12.5px; font-weight: 500; color: var(--muted); }
input, select, textarea {
  font: inherit; color: var(--fg); background: var(--canvas); border: 1px solid var(--line-strong); border-radius: var(--r);
  padding: 8px 10px; min-width: 0; width: 100%; transition: border-color 0.12s, box-shadow 0.12s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; line-height: 1.55; }
input.big { font-size: 18px; padding: 10px 12px; }
input.tiny { width: 76px; }
select.slim { width: auto; padding: 5px 8px; font-size: 13px; border-color: var(--line); }
.primary { background: var(--accent); color: var(--on-accent); border: 0; border-radius: var(--r); padding: 9px 16px; font-weight: 500; cursor: pointer; white-space: nowrap; transition: background 0.12s; }
.primary:hover { background: var(--accent-hover); }
.primary.block { width: 100%; }
.primary.sm { padding: 6px 12px; font-size: 13px; }
.ghost { background: var(--canvas); color: var(--fg); border: 1px solid var(--line-strong); border-radius: var(--r); padding: 7px 12px; cursor: pointer; white-space: nowrap; font-weight: 500; font-size: 13px; }
.ghost:hover { border-color: var(--accent); color: var(--accent); }
.danger { color: var(--rose-ink) !important; }
.keys, .examples { display: flex; flex-wrap: wrap; gap: 6px; }
.keys button { min-width: 36px; height: 32px; border: 1px solid var(--line); background: var(--bg); border-radius: var(--r-sm); font: 500 15px var(--mono); cursor: pointer; }
.examples button { border: 1px solid var(--line); background: var(--canvas); border-radius: 999px; padding: 3px 10px; font: 12.5px var(--mono); cursor: pointer; color: var(--fg); }
.keys button:hover, .examples button:hover { border-color: var(--accent); color: var(--accent); }
.hint { margin: 0; font-size: 12.5px; color: var(--muted); }
.err { background: var(--rose); color: var(--rose-ink); border-radius: var(--r); padding: 9px 12px; font-weight: 500; font-size: 13px; }
.op { border: 1px solid var(--line); background: var(--canvas); color: var(--fg); border-radius: var(--r); padding: 7px 11px; font-weight: 500; font-size: 13px; cursor: pointer; white-space: nowrap; transition: background 0.12s, border-color 0.12s, color 0.12s; }
.op:hover { border-color: var(--accent); color: var(--accent); }
.op[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.opGrid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.divider { height: 1px; background: var(--line); margin: 4px 0; }
.cond { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; padding: 12px; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--bg); }
.cond .lbl { width: 100%; }
.cond select { flex: 1 1 100%; }
.cond .cf { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.cond .cf input, .cond .cf select { width: 84px; flex: none; }
.chk { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; font-size: 13px; }
.chk input { width: auto; }

/* ---------- result stages ---------- */
.summary { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip { display: inline-flex; gap: 6px; align-items: baseline; padding: 3px 10px; border-radius: 999px; background: var(--canvas); border: 1px solid var(--line); font-size: 12.5px; white-space: nowrap; color: var(--muted); }
.chip b { font: 500 12.5px var(--mono); color: var(--fg); }
.stage-h .meta { min-width: 0; }
.stage-h .meta .chip, .summary .chip { white-space: normal; max-width: 100%; }
.chip.ok { background: var(--green); border-color: transparent; color: var(--green-ink); font-weight: 500; }
.chip.bad { background: var(--rose); border-color: transparent; color: var(--rose-ink); font-weight: 500; }
.jump { display: flex; flex-wrap: wrap; gap: 6px; }
.jump a { font-size: 12.5px; padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px; color: var(--fg); background: var(--canvas); }
.jump a:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.stage { background: var(--canvas); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 18px; display: flex; flex-direction: column; gap: 12px; min-width: 0; scroll-margin-top: 16px; }
.stage-h { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stage-h .num { font: 600 12px var(--mono); color: var(--accent); background: var(--accent-soft); width: 24px; height: 24px; border-radius: var(--r-sm); display: grid; place-items: center; }
.stage-h h2 { font-size: 16px; }
.stage-h .meta { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.stage p { margin: 0; }
.formula { font-family: var(--mono); font-size: 12.5px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--r); padding: 8px 12px; overflow-x: auto; white-space: nowrap; }
.cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.cols > * { min-width: 0; }
.sub { font-size: 12px; font-weight: 600; color: var(--muted); margin: 6px 0 6px; text-transform: uppercase; letter-spacing: 0.05em; }
details { border-top: 1px solid var(--line); padding-top: 10px; }
summary { cursor: pointer; font-weight: 500; color: var(--accent); font-size: 13.5px; }
details > *:not(summary) { margin-top: 10px; }
.legend { font-size: 12px; color: var(--muted); margin: 4px 0 0; }
.answer { font: 500 clamp(17px, 2.6vw, 22px)/1.5 var(--mono); padding: 12px 14px; border-radius: var(--r); background: var(--accent-soft); color: var(--fg); overflow-x: auto; overflow-y: hidden; white-space: nowrap; }
/* the drawer is narrow: wrap long answers instead of scrolling them */
.drawer .answer { white-space: normal; overflow-wrap: anywhere; overflow-x: visible; }
.btnRow { display: flex; flex-wrap: wrap; gap: 8px; }
.steps { margin: 0; padding-left: 22px; display: flex; flex-direction: column; gap: 6px; font-family: var(--mono); font-size: 12.5px; }
.steps li { overflow-x: auto; }
.deriv { font-family: var(--mono); font-size: 13.5px; line-height: 2; overflow-x: auto; }
.deriv .arrow { color: var(--accent); padding: 0 6px; }
.prods { font-family: var(--mono); font-size: 14px; line-height: 1.85; background: var(--bg); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 14px; overflow-x: auto; white-space: pre; }
.prods .v { color: var(--accent); font-weight: 600; }

/* tables */
.tbl { overflow-x: auto; max-width: 100%; }
table { border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
table.mono td, table.mono th { font-family: var(--mono); font-size: 12.5px; }
th { text-align: left; font-weight: 500; color: var(--muted); border-bottom: 1px solid var(--line-strong); padding: 6px 14px 6px 0; white-space: nowrap; }
td { border-bottom: 1px solid var(--line); padding: 6px 14px 6px 0; white-space: nowrap; vertical-align: top; }
tr.dim td { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--line-strong); }
.none { color: var(--muted); }
.mk-start { color: var(--accent); font-weight: 700; margin-right: 2px; }
.mk-final { color: var(--green-ink); font-weight: 700; margin-right: 2px; }
table.mark td, table.mark th { text-align: center; padding: 6px 8px; min-width: 40px; border: 1px solid var(--line); }
table.mark td.x { color: var(--rose-ink); font-weight: 600; }
table.mark td.eq { color: var(--green-ink); background: var(--green); font-weight: 600; }
table.mark td.blank { border: 0; }
table.mark sub { font-size: 10px; }
.part { font-family: var(--mono); font-size: 12.5px; display: flex; flex-direction: column; gap: 6px; }
.part .grp { display: inline-block; padding: 1px 8px; border: 1px solid var(--line); border-radius: var(--r-sm); margin: 0 4px 4px 0; background: var(--violet); }
.ids { font-family: var(--mono); font-size: 12.5px; line-height: 1.9; overflow-x: auto; }
.ids span { white-space: nowrap; }

/* ---------- graphviz diagrams ---------- */
.gv { overflow-x: auto; max-width: 100%; padding: 8px 0; min-height: 60px; }
.gv svg { display: block; height: auto; }
.gv-wait { color: var(--muted); font-size: 12.5px; padding: 20px 0; }
.gv .node ellipse, .gv .node circle { fill: none; stroke: var(--node-stroke); stroke-width: 1.3; }
.gv .node ellipse:first-of-type { fill: var(--node); }
.gv .node.final ellipse { stroke: var(--green-ink); }
.gv .node.final ellipse:first-of-type { fill: var(--green); }
.gv .node.start ellipse:first-of-type { fill: var(--blue); }
.gv .node.start.final ellipse:first-of-type { fill: var(--green); }
.gv .node.dead ellipse { stroke-dasharray: 4 3; stroke: var(--muted); }
.gv .node.dead ellipse:first-of-type { fill: var(--amber); }
.gv .node text, .gv .edge text { fill: var(--fg); font-family: var(--mono); }
.gv .edge path { stroke: var(--edge); stroke-width: 1.2; }
.gv .edge polygon { fill: var(--edge); stroke: var(--edge); }
.gv .startarrow path { stroke: var(--accent); stroke-width: 1.6; }
.gv .startarrow polygon { fill: var(--accent); stroke: var(--accent); }
/* dependency graphs: parse-tree nodes as dashed boxes, the tree dotted, dependencies as arrows */
.gv .cluster path, .gv .cluster polygon { fill: none; stroke: var(--line-strong); }
.gv .cluster text { fill: var(--muted); font-family: var(--mono); }
.gv .edge.treeedge path { stroke: var(--muted); stroke-dasharray: 3 3; }
.gv .edge.dep path { stroke: var(--accent); }
.gv .edge.dep polygon { fill: var(--accent); stroke: var(--accent); }
.gv.tree .node.tvar text { fill: var(--accent); font-weight: 600; }
.gv.tree .node.tleaf text { fill: var(--rose-ink); font-weight: 600; }
.gv.tree .edge path { stroke: var(--line-strong); }
.treeText { font-family: var(--mono); font-size: 12.5px; margin: 0; }

.gv .node.itemset path, .gv .node.itemset polygon { fill: var(--node); stroke: var(--node-stroke); stroke-width: 1.2; }
.gv .node.itemset.final path, .gv .node.itemset.final polygon { fill: var(--green); stroke: var(--green-ink); }
.gv .node.itemset.conflict path, .gv .node.itemset.conflict polygon { fill: var(--rose); stroke: var(--rose-ink); }
.gv .node.itemset.start path, .gv .node.itemset.start polygon { fill: var(--blue); }
.gv .node.itemset text { font-size: 11px; font-family: "JetBrains Mono", "Courier New", monospace; }

/* parsing tables */
table.grid { border-collapse: collapse; }
table.grid th, table.grid td { border: 1px solid var(--line); padding: 5px 9px; text-align: center; white-space: nowrap; }
table.grid th { background: var(--bg); color: var(--muted); font-weight: 600; }
table.grid td:first-child, table.grid th:first-child { text-align: left; font-weight: 600; color: var(--fg); }
table.grid .sep { border-left: 2px solid var(--line-strong); }
table.grid td.l { text-align: left; white-space: nowrap; vertical-align: top; }
table.grid td.conflict { background: var(--rose); color: var(--rose-ink); font-weight: 600; }
table.grid td.resolved { background: var(--amber); }
table.grid td.acc { color: var(--green-ink); font-weight: 600; }
table.trace td { white-space: nowrap; }
table.trace td.act { color: var(--accent); }
table.trace tr.done td { background: var(--green); }
table.trace tr.bad td { background: var(--rose); color: var(--rose-ink); }
.code { font-family: var(--mono); font-size: 12.5px; line-height: 1.6; background: var(--bg); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; overflow-x: auto; white-space: pre; margin: 0; }
.calls { font-family: var(--mono); font-size: 12.5px; line-height: 1.7; overflow-x: auto; white-space: pre; margin: 0; }
.calls .ok { color: var(--green-ink); }
.calls .bad { color: var(--rose-ink); font-weight: 600; }
.calls .note { color: var(--muted); }
.sub .raw { text-transform: none; letter-spacing: 0; font-family: var(--mono); color: var(--fg); }
.seg2 { display: flex; flex-direction: column; gap: 6px; }
table.grid td.yes { color: var(--green-ink); }
table.grid td.no { color: var(--rose-ink); font-weight: 600; }
table.grid tr.pumps td { background: var(--amber); }
.wsplit { font-family: var(--mono); font-size: 20px; letter-spacing: .02em; }
.wsplit .x { color: var(--fg); }
.wsplit .y { background: var(--accent-soft); color: var(--accent); border-radius: 4px; padding: 0 2px; font-weight: 600; }
.wsplit .z { color: var(--muted); }
.cmp { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- shared svg drawing (canvas + fallback) ---------- */
.ncircle { fill: var(--node); stroke: var(--node-stroke); stroke-width: 1.6; }
.fnode.final .ncircle { fill: var(--green); stroke: var(--green-ink); }
.ninner { fill: none; stroke: var(--green-ink); stroke-width: 1.5; }
.fnode.start:not(.final) .ncircle { fill: var(--blue); }
.nlabel { fill: var(--fg); font: 500 13px var(--mono); pointer-events: none; }
.eline { fill: none; stroke: var(--edge); stroke-width: 1.6; }
.eline.start { stroke: var(--accent); stroke-width: 1.8; }
.eline.preview { stroke: var(--accent); stroke-dasharray: 5 4; }
.ahead { fill: var(--edge); }
.ahead.start { fill: var(--accent); }
.elabel { fill: var(--fg); font: 500 13px var(--mono); paint-order: stroke; stroke: var(--canvas); stroke-width: 5px; stroke-linejoin: round; }
.hit { fill: none; stroke: transparent; stroke-width: 18; }
.gridDot { fill: var(--dot); }
.fallback { display: block; }
.fedge.sel .eline { stroke: var(--accent); stroke-width: 2.4; }
.fedge.sel .elabel { fill: var(--accent); }
.fedge.draft .eline { stroke: var(--accent); stroke-dasharray: 5 4; }

/* ---------- Draw FA workspace ---------- */
.workspace { position: relative; display: flex; overflow: hidden; }
.stageArea { position: relative; flex: 1; min-width: 0; background: var(--canvas); overflow: hidden; container-type: size; }
svg.canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; user-select: none; -webkit-user-select: none; }
svg.canvas[data-tool="state"] { cursor: crosshair; }
svg.canvas[data-tool="pan"], svg.canvas.panning { cursor: grab; }
svg.canvas.panning:active { cursor: grabbing; }
svg.canvas[data-tool="edge"] .fnode { cursor: crosshair; }
svg.canvas[data-tool="move"] .fnode { cursor: grab; }
svg.canvas[data-tool="move"] .fedge, svg.canvas[data-tool="delete"] .fedge, svg.canvas[data-tool="delete"] .fnode { cursor: pointer; }
svg.canvas .fnode.sel .ncircle { stroke: var(--accent); stroke-width: 2.6; }
svg.canvas .fnode.pending .ncircle { stroke: var(--accent); stroke-width: 2.6; fill: var(--accent-soft); }
svg.canvas[data-tool="delete"] .fnode:hover .ncircle, svg.canvas[data-tool="delete"] .fedge:hover .eline { stroke: var(--rose-ink); }
.emptyHint { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 4px; align-items: center; justify-content: center; text-align: center; color: var(--muted); pointer-events: none; padding: 16px; }
.emptyHint b { color: var(--fg); font-weight: 600; font-size: 15px; }
.emptyHint kbd { border: 1px solid var(--line-strong); border-radius: 4px; padding: 0 5px; font-size: 11px; color: var(--fg); }
.float { position: absolute; background: var(--canvas); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--float-shadow); display: flex; align-items: center; gap: 2px; padding: 4px; z-index: 3; }
.tools { left: max(12px, env(safe-area-inset-left, 0px)); top: 50%; transform: translateY(-50%); flex-direction: column; }
.tools button { width: 40px; height: 40px; border: 0; background: none; border-radius: var(--r); display: grid; place-items: center; cursor: pointer; position: relative; color: var(--fg); transition: background 0.12s; }
.tools button kbd { position: absolute; right: 3px; bottom: 1px; font-size: 9px; }
.tools button:hover { background: var(--bg); }
.tools button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.tools button[aria-pressed="true"] kbd { color: var(--accent); }
.sep { width: 24px; height: 1px; background: var(--line); margin: 3px 0; }
.sep.v { width: 1px; height: 20px; margin: 0 4px; }
.opsBar { top: 12px; left: max(12px, env(safe-area-inset-left, 0px)); max-width: calc(100% - 420px); overflow-x: auto; scrollbar-width: none; gap: 4px; }
.opsBar::-webkit-scrollbar { display: none; }
.opsBar .op { border-color: transparent; padding: 6px 10px; }
.opsBar .op:hover { background: var(--bg); border-color: transparent; }
.opsBar .op[aria-pressed="true"] { border-color: transparent; }
@container (max-width: 1060px) { .opsBar { top: 60px; max-width: calc(100% - 24px); } }
.actions { top: 12px; right: max(12px, env(safe-area-inset-right, 0px)); }
.zoomBar { bottom: max(12px, env(safe-area-inset-bottom, 0px)); left: max(12px, env(safe-area-inset-left, 0px)); }
.zoomPct { border: 0; background: none; font: 500 12.5px var(--ui); min-width: 48px; height: 32px; cursor: pointer; border-radius: var(--r-sm); font-variant-numeric: tabular-nums; }
.zoomPct:hover { background: var(--bg); }
.statusBar { bottom: max(12px, env(safe-area-inset-bottom, 0px)); right: max(12px, env(safe-area-inset-right, 0px)); padding: 6px 12px; font-size: 12.5px; color: var(--muted); gap: 6px; font-variant-numeric: tabular-nums; }
.statusBar .bad { color: var(--rose-ink); }
.menuWrap { position: relative; }
.menu { position: absolute; right: 0; top: 40px; background: var(--canvas); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--float-shadow); padding: 4px; min-width: 170px; display: flex; flex-direction: column; z-index: 5; }
.menu button, .menuFile { text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: var(--r-sm); cursor: pointer; font-size: 13px; font-weight: 500; }
.menu button:hover, .menuFile:hover { background: var(--bg); }
.menuFile input { display: none; }
.ctx { position: absolute; z-index: 4; background: var(--canvas); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--float-shadow); padding: 5px; display: flex; flex-direction: column; gap: 4px; }
.ctxNode, .ctxEdge { display: flex; align-items: center; gap: 4px; }
.ctx input { width: 96px; padding: 5px 8px; font-size: 13px; }
.ctxEdge input { width: 120px; }
.edgeWhat { font-size: 12px; color: var(--muted); padding: 0 6px; white-space: nowrap; }
.chipBtn { display: inline-flex; gap: 5px; align-items: center; border: 1px solid var(--line); background: var(--canvas); border-radius: var(--r-sm); padding: 5px 9px; font-size: 12.5px; font-weight: 500; cursor: pointer; color: var(--fg); }
.chipBtn:hover { border-color: var(--accent); }
.chipBtn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
#selFinal[aria-pressed="true"] { background: var(--green); border-color: var(--green-ink); color: var(--green-ink); }
.ctxErr { margin: 0 4px; color: var(--rose-ink); font-size: 12px; }
.ctxErr:empty { display: none; }
.toast { position: absolute; left: 50%; bottom: 64px; transform: translateX(-50%); background: var(--fg); color: var(--canvas); padding: 9px 14px; border-radius: var(--r); font-size: 13px; font-weight: 500; z-index: 6; max-width: calc(100% - 32px); }
.drawer { width: min(520px, 46vw); flex: none; background: var(--canvas); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.drawerHead { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 12px 18px; border-bottom: 1px solid var(--line); }
.drawerHead h2 { font-size: 15px; }
.drawerBody { overflow-y: auto; padding: 16px; padding-right: max(16px, env(safe-area-inset-right, 0px)); padding-bottom: max(24px, env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 14px; flex: 1; min-height: 0; background: var(--bg); }
.drawer .stage { padding: 14px; }
.drawer .cols { grid-template-columns: minmax(0, 1fr); }
.drawerForm { display: flex; gap: 8px; align-items: flex-end; }
.drawerForm .field { flex: 1; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .app { height: auto; min-height: 100%; }
  .topbar { height: auto; flex-wrap: wrap; padding-block: 10px; row-gap: 10px; }
  .modes { order: 3; width: 100%; margin: 0; }
  .modes button { flex: 1 1 auto; padding: 6px 8px; }
  .topRight { margin-left: auto; }
  .split { display: flex; flex-direction: column; height: auto; }
  .side { border-right: 0; border-bottom: 1px solid var(--line); overflow: visible; padding-right: max(16px, env(safe-area-inset-right, 0px)); padding-left: max(16px, env(safe-area-inset-left, 0px)); }
  .board { overflow: visible; }
  .boardInner { padding: 16px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
  .cols { grid-template-columns: minmax(0, 1fr); }
  .workspace { height: calc(100dvh - 145px); min-height: 480px; }
  .drawer { position: absolute; left: 0; right: 0; bottom: 0; width: auto; height: 62%; border-left: 0; border-top: 1px solid var(--line); border-radius: 14px 14px 0 0; z-index: 7; box-shadow: var(--float-shadow); }
  .tools { top: auto; bottom: 64px; transform: none; }
  .tools button { width: 38px; height: 38px; }
  .tools button kbd { display: none; }
  .opsBar { left: max(12px, env(safe-area-inset-left, 0px)); right: max(12px, env(safe-area-inset-right, 0px)); top: 60px; max-width: none; }
  .statusBar .dotSep, .statusBar #objCount { display: none; }
  .actions { left: max(12px, env(safe-area-inset-left, 0px)); right: max(12px, env(safe-area-inset-right, 0px)); }
  .actions select.slim { flex: 1; min-width: 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }

/* input buffering: two halves of cells, each ending in a sentinel */
.bframe { margin: 0 0 14px; }
.buf { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 4px; }
.bhalf { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 6px; overflow: hidden; }
.bhalf.empty { padding: 4px 10px; color: var(--muted); font-size: 12.5px; }
.bc { display: inline-block; min-width: 24px; padding: 3px 4px; text-align: center; font-family: var(--mono); font-size: 13px; border-right: 1px solid var(--line); }
.bc:last-child { border-right: 0; }
.bc.eof { color: var(--muted); font-size: 11px; }
.bc.lexeme { background: var(--blue); }
.bc.lb { box-shadow: inset 3px 0 0 var(--accent); }
.bc.fw { box-shadow: inset 0 -3px 0 var(--green-ink); }

/* ---------- converter pages: explanation and links below the tool ---------- */
.seo { max-width: 760px; margin: 0 auto; padding: 40px 20px 8px; color: var(--fg); font-size: 15px; line-height: 1.7; }
footer.seo { padding: 24px 20px 48px; border-top: 1px solid var(--line); }
article.seo + footer.seo { margin-top: 24px; }
.seo h1 { font-size: 28px; line-height: 1.25; margin: 6px 0 12px; letter-spacing: -0.01em; }
.seo h2 { font-size: 19px; margin: 32px 0 8px; }
.seo h3 { font-size: 15.5px; margin: 20px 0 4px; }
.seo p, .seo ul, .seo ol { margin: 0 0 12px; }
.seo li { margin: 4px 0; }
.seo a:link, .seo a:visited { color: var(--accent); }
.seoLead { font-size: 16.5px; color: var(--fg); }
.seoCrumb, .seoMeta { font-size: 13px; color: var(--muted); margin: 0; }
.seo table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; font-family: var(--mono); font-size: 13.5px; margin: 8px 0 16px; }
.seo table.ex tr th, .seo table.ex tr td { border: 1px solid var(--line); padding: 6px 12px; text-align: left; }
.seo table.ex tr th { background: var(--bg); color: var(--muted); font-weight: 600; }
.seoNav h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0 0 10px; }
.seoNav ul { list-style: none; padding: 0; margin: 0 0 16px; display: flex; flex-wrap: wrap; gap: 8px; }
.seoNav li { margin: 0; }
.seoNav a:link, .seoNav a:visited, .seoNav span { display: inline-block; padding: 5px 12px; border: 1px solid var(--line); border-radius: 999px; font-size: 13.5px; text-decoration: none; color: var(--fg); background: var(--panel, var(--bg)); }
.seoNav a:hover { border-color: var(--accent); color: var(--accent); }
.seoNav span { border-color: var(--accent); color: var(--accent); }

@media (max-width: 420px) {
  .modes .wide { display: none; }
}

/* learning mode */
.learn { margin: 4px 0 12px; }
.learn.open { border: 1px solid var(--line); border-radius: var(--r-lg); padding: 10px 12px; background: var(--canvas); }
.learnBar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.learnBar .iconBtn { border: 1px solid var(--line); background: var(--canvas); font-size: 12px; }
.learnPos { font-size: 13px; color: var(--muted); min-width: 92px; text-align: center; font-variant-numeric: tabular-nums; }
.learnText { margin: 10px 0; padding: 8px 10px; border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 0 var(--r-sm) var(--r-sm) 0; font-size: 14px; line-height: 1.5; }
.learnTable td.hl { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.learnTable td.wait { background: var(--bg); }
.learnTable tr.cur td { background: var(--accent-soft); }

/* /verified/ */
.docPage { height: auto; }
.docPage .topbar { justify-content: space-between; }
.vOpen { text-decoration: none; }
.verified h2 { margin-top: 36px; }
.vSummary { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.vCase { border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--canvas); padding: 14px 16px; margin: 0 0 12px; }
.vHead { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.vHead h3 { margin: 0; font-size: 15.5px; line-height: 1.4; }
.vSrc { font-size: 13px; color: var(--muted); margin: 2px 0 8px; }
.vIn { margin: 0 0 10px; padding: 8px 10px; background: var(--bg); border-radius: var(--r-sm); font: 13px/1.5 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }
.vCmp { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 14px; margin: 0; font-size: 13.5px; }
.vCmp dt { color: var(--muted); font-weight: 500; }
.vCmp dd { margin: 0; font-family: var(--mono); overflow-wrap: anywhere; }
@media (max-width: 520px) {
  .vCmp { grid-template-columns: minmax(0, 1fr); }
  .vCmp dd { margin-bottom: 6px; }
}

/* site footer */
.siteFoot { border-top: 1px solid var(--line); background: var(--canvas); color: var(--fg); padding: 40px max(20px, env(safe-area-inset-right, 0px)) 24px max(20px, env(safe-area-inset-left, 0px)); font-size: 14px; }
article.seo + .siteFoot { margin-top: 40px; }
.fInner { max-width: 1120px; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1.6fr) repeat(3, minmax(0, 1fr)); gap: 32px; }
.fCol h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); margin: 4px 0 12px; }
.fCol ul { list-style: none; margin: 0; padding: 0; }
.fCol li { margin: 0 0 7px; }
.fCol a:link, .fCol a:visited { color: var(--fg); text-decoration: none; }
.fCol a:hover { color: var(--accent); }
.fCol span[aria-current] { color: var(--accent); font-weight: 500; }
.fGroup { font-size: 12.5px; color: var(--muted); font-weight: 600; margin-top: 12px !important; }
.fGroup:first-child { margin-top: 0 !important; }
.fAbout .brand { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; margin-bottom: 12px; }
.fAbout p { color: var(--muted); margin: 0 0 10px; line-height: 1.6; max-width: 340px; }
.fAbout .fMade { color: var(--fg); }
.fAbout p a:link, .fAbout p a:visited { color: var(--accent); text-decoration: none; font-weight: 500; }
.fAbout p a:hover { text-decoration: underline; }
.fBottom { max-width: 1120px; margin: 32px auto 0; padding-top: 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; text-align: center; }
@media (max-width: 860px) {
  .fInner { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .fAbout { grid-column: 1 / -1; }
}
@media (max-width: 420px) {
  .fInner { grid-template-columns: minmax(0, 1fr); gap: 24px; }
}
.fSocial { display: flex; gap: 8px; }
.fIcon { width: 36px; height: 36px; display: inline-grid; place-items: center; border: 1px solid var(--line); border-radius: var(--r); color: var(--fg) !important; }
.fIcon:hover { border-color: var(--accent); color: var(--accent) !important; }
.fBottom a:link, .fBottom a:visited { color: var(--muted); }

/* tactile controls: a top highlight and a thin base that compresses when pressed */
.primary {
  --depth: 2px;
  margin-top: var(--depth);
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 88%, #fff), var(--accent));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 var(--depth) 0 var(--accent-hover), 0 4px 10px -3px color-mix(in srgb, var(--accent) 60%, transparent);
  transform: translateY(calc(var(--depth) * -1));
  transition: transform 0.1s, box-shadow 0.1s, filter 0.1s;
}
.primary:hover { background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 88%, #fff), var(--accent)); filter: brightness(1.06); }
.primary:active { transform: translateY(0); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 0 0 var(--accent-hover), 0 1px 3px -1px var(--drop); }
.primary:disabled { filter: grayscale(0.6) opacity(0.6); transform: none; box-shadow: none; cursor: default; }
.modes { padding: 5px; background: linear-gradient(160deg, var(--plate-1), var(--plate-2)); border-color: transparent; box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.12), inset 0 -1px 0 var(--rim); }
.modes button { border-radius: var(--r); transition: color 0.12s, transform 0.12s, box-shadow 0.12s; }
.modes button[aria-pressed="true"] {
  background: linear-gradient(180deg, var(--key-1), var(--key-2));
  box-shadow: inset 0 1px 0 var(--rim), 0 2px 0 var(--key-side), 0 4px 8px -3px var(--drop);
  transform: translateY(-1px);
}
.modes button:active { transform: translateY(1px); }
.learnBar .iconBtn, .learnBar .ghost {
  --depth: 2px; border: 0; margin-top: var(--depth);
  background: linear-gradient(180deg, var(--key-1), var(--key-2)); color: var(--fg);
  box-shadow: inset 0 1.5px 0 var(--rim), 0 var(--depth) 0 var(--key-side), 0 calc(var(--depth) + 4px) 8px -3px var(--drop);
  transform: translateY(calc(var(--depth) * -1)); transition: transform 0.1s, box-shadow 0.1s;
}
.learnBar .iconBtn { width: 38px; height: 36px; border-radius: 10px; }
.learnBar .ghost { border-radius: 10px; padding: 8px 14px; font-weight: 600; }
.learnBar [data-lstep="play"] {
  color: var(--on-accent);
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 80%, #fff), var(--accent));
  box-shadow: inset 0 1.5px 0 rgba(255, 255, 255, 0.5), 0 var(--depth) 0 color-mix(in srgb, var(--accent-hover) 70%, #000), 0 calc(var(--depth) + 4px) 10px -3px color-mix(in srgb, var(--accent) 55%, transparent);
}
.learnBar .iconBtn:active, .learnBar .ghost:active { transform: translateY(0); box-shadow: inset 0 1.5px 0 var(--rim), 0 1px 0 var(--key-side), 0 2px 3px -1px var(--drop); }
.learnBar .iconBtn:disabled { opacity: 0.45; transform: none; box-shadow: inset 0 1px 0 var(--rim); background: var(--bg); }
.learnBar .iconBtn:disabled:active { transform: none; }
@media (prefers-reduced-motion: reduce) {
  .primary, .modes button, .learnBar .iconBtn, .learnBar .ghost { transition: none; }
}

/* keyboard users can jump past the header */
.skipLink { position: absolute; left: 12px; top: -48px; z-index: 50; padding: 8px 14px; border-radius: var(--r); background: var(--accent); color: var(--on-accent); font-weight: 600; text-decoration: none; transition: top 0.15s; }
.skipLink:focus { top: 12px; }
.main:focus { outline: none; }
