/* lectes.dev: an arcade cabinet for the lectes scanner */

@font-face {
  font-family: "Press Start 2P";
  src: url("fonts/PressStart2P.5c7e04d0202b.woff2") format("woff2");
  font-display: swap;
}

@font-face {
  font-family: VT323;
  src: url("fonts/VT323.9cb03ff10174.woff2") format("woff2");
  font-display: swap;
}

:root {
  color-scheme: dark;
  --screen: #0d0b1e;
  --panel: #17142e;
  --panel-2: #211c40;
  --rail: #2b2550;
  --text: #edeaff;
  --soft: #c9c5ee;
  --muted: #9c97c9;
  --dim: #6e68a3;
  --coin: #ffd400;
  --shadow: #ff2e88;
  --cyan: #00e5ff;
  --green: #4dff6a;
  --warn: #ff9a3c;
  --error: #ff6b6b;
  --select: #3a3275;

  /* Rule colours: neon fills under dark text */
  --c0: #00e5ff;
  --c1: #ff4fa3;
  --c2: #4dff6a;
  --c3: #b48cff;
  --c4: #ff9a3c;
  --c5: #ffd400;
  --c6: #ff6b6b;
  --c7: #c9c5ee;
  --tok-text: #0d0b1e;

  /* A stepped pixel arrow for the stage picker */
  --pixel-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 7 4' shape-rendering='crispEdges'%3E%3Cpath fill='%23ffd400' d='M0 0h7v1H6v1H5v1H4v1H3V3H2V2H1V1H0z'/%3E%3C/svg%3E");

  --hl-comment: #8a85b8;
  --hl-name: #ffd400;
  --hl-escape: #ff4fa3;
  --hl-class: #4dff6a;
  --hl-operator: #ff4fa3;
  --hl-group: #b48cff;
  --hl-invalid: #ff6b6b;

  --px: "Press Start 2P", ui-monospace, monospace;
  --vt: VT323, ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;
  --frame: 3px solid var(--text);
  --rail-line: 3px solid var(--rail);
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--screen);
  color: var(--text);
  font: 22px/1.25 var(--vt);
}

/* CRT scanlines */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 1000;
  pointer-events: none;
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0 2px,
    rgb(0 0 0 / 0.22) 2px 3px
  );
}

a { color: var(--cyan); }
a:hover { color: var(--coin); }
code, pre { font-family: var(--vt); }

:focus-visible { outline: 3px solid var(--coin); outline-offset: 2px; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.muted { color: var(--muted); }
.px { font-family: var(--px); }

/* Header and footer */

.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 24px;
  max-width: 1440px;
  margin: 0 auto;
  padding: 14px 24px;
  border-bottom: var(--rail-line);
}

.brand {
  margin: 0;
  font: 16px/1 var(--px);
  color: var(--coin);
  text-shadow: 3px 3px 0 var(--shadow);
}
.brand a { color: inherit; text-decoration: none; }
.brand-tld { color: var(--text); }

.header-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

.picker { display: flex; align-items: center; gap: 10px; font: 10px var(--px); color: var(--cyan); }

/* Stage picker: a themed listbox in front of the hidden example <select> (stage-picker.js) */

select {
  font: 22px var(--vt);
  color: var(--text);
  background: var(--panel);
  border: var(--frame);
  border-radius: 0;
  min-height: 44px;
}

.stage-picker { position: relative; }

.stage-button {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  min-height: 44px;
  padding: 2px 12px 2px 10px;
  font: 22px var(--vt);
  color: var(--text);
  text-align: left;
  background: var(--panel);
  border: var(--frame);
  border-radius: 0;
  box-shadow: 5px 5px 0 var(--rail);
  cursor: pointer;
}
.stage-button::after {
  content: "";
  flex: none;
  width: 14px;
  height: 8px;
  background: var(--pixel-arrow) center / contain no-repeat;
}
.stage-button:hover { color: var(--coin); }
.stage-button[aria-expanded="true"] { border-color: var(--coin); }
.stage-button[aria-expanded="true"]::after { rotate: 180deg; }

.stage-list {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 20;
  width: max-content;
  min-width: 100%;
  max-width: calc(100vw - 32px);
  max-height: min(24rem, 70vh);
  overflow: auto;
  margin: 0;
  padding: 6px 0;
  list-style: none;
  background: var(--panel);
  border: var(--frame);
  box-shadow: 6px 6px 0 var(--shadow);
}

.stage-option {
  display: flex;
  gap: 10px;
  padding: 4px 16px 4px 10px;
  font: 22px var(--vt);
  color: var(--soft);
  cursor: pointer;
}
.stage-option::before { content: "▶"; visibility: hidden; color: var(--coin); }
.stage-option[aria-selected="true"] { color: var(--coin); }
.stage-option[aria-selected="true"]::before { visibility: visible; }
.stage-option.is-active { color: var(--screen); background: var(--coin); }
.stage-option.is-active::before { color: var(--screen); }

.button {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 14px;
  font: 10px var(--px);
  color: var(--text);
  text-decoration: none;
  background: var(--panel);
  border: var(--frame);
  border-radius: 0;
  box-shadow: 5px 5px 0 var(--rail);
  cursor: pointer;
}
.button:hover { color: var(--coin); }
.button:active { transform: translate(5px, 5px); box-shadow: none; }
.button.primary { color: var(--screen); background: var(--coin); border-color: var(--screen); box-shadow: 5px 5px 0 var(--shadow); }
.button.primary:hover { color: var(--screen); background: #ffe14d; }
.button.ghost { background: transparent; border-color: transparent; box-shadow: none; }
.button.ghost:hover { border-color: var(--rail); }
.button.ghost:active { transform: none; }
.button.small { min-height: 36px; padding: 0 10px; font-size: 9px; }
.button.danger { color: var(--text); background: var(--error); border-color: var(--screen); box-shadow: 5px 5px 0 var(--rail); }
.button.danger:hover { color: var(--screen); }
.button.player { color: var(--green); }

/* Saved grammars: the title in the header, the save dialog and its errors */

.saved-title { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin: 0 8px 0 0; min-width: 0; }
.saved-name { font: 22px var(--vt); color: var(--coin); overflow-wrap: anywhere; }
input.saved-name {
  width: 18ch;
  min-height: 44px;
  padding: 2px 10px;
  background: var(--panel);
  border: var(--frame);
  border-radius: 0;
}
input.saved-name:focus-visible { outline: none; border-color: var(--coin); }
.byline { color: var(--muted); white-space: nowrap; }

.save-errors { max-width: 1440px; margin: 0 auto; padding: 0 24px; }
.save-errors:empty { display: none; }
.save-errors .errorlist { margin: 16px 0 0; padding: 10px 14px; border: 3px solid var(--error); background: var(--panel); }

.save-dialog {
  width: min(34rem, calc(100vw - 32px));
  padding: 28px 28px 32px;
  color: var(--text);
  background: var(--panel);
  border: var(--frame);
  box-shadow: 6px 6px 0 var(--shadow);
}
.save-dialog::backdrop { background: rgb(13 11 30 / 0.8); }
.save-dialog .auth-note { margin: 0 0 16px; }

.site-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 24px;
  max-width: 1440px;
  margin: 0 auto;
  padding: 32px 24px 40px;
  font-size: 20px;
  color: var(--muted);
}
.footer-links { display: flex; flex-wrap: wrap; gap: 8px 20px; }
/* A button that opens something, styled like the links next to it. */
.link-button { font: inherit; color: var(--cyan); background: none; border: 0; padding: 0; text-decoration: underline; cursor: pointer; }
.link-button:hover { color: var(--coin); }

/* The documentation and GitHub menus: popovers (no JavaScript), centred like a dialog. */
.link-menu {
  width: min(30rem, calc(100vw - 32px));
  padding: 28px 28px 24px;
  color: var(--text);
  background: var(--panel);
  border: var(--frame);
  box-shadow: 6px 6px 0 var(--shadow);
}
.link-menu::backdrop { background: rgb(13 11 30 / 0.8); }
.link-options { list-style: none; margin: 0 0 20px; padding: 0; display: grid; gap: 12px; }
.link-option {
  display: grid;
  gap: 6px;
  padding: 12px 14px;
  color: var(--text);
  text-decoration: none;
  background: var(--screen);
  border: var(--rail-line);
}
.link-option:hover, .link-option:focus-visible { border-color: var(--coin); }
.link-option:hover .link-name { color: var(--coin); }
.link-name { font: 12px var(--px); color: var(--cyan); }
.link-about { color: var(--muted); }

.noscript { margin: 16px 24px; padding: 12px; border: 3px solid var(--warn); color: var(--warn); }

/* Title screen */

.title-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  max-width: 1440px;
  margin: 0 auto;
  padding: 56px 24px 48px;
  text-align: center;
}
.title-kicker { margin: 0; font: 11px var(--px); letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.title-logo {
  margin: 0;
  font: clamp(26px, 6.6vw, 96px)/1.1 var(--px);
  color: var(--coin);
  text-shadow: 6px 6px 0 var(--shadow), 12px 12px 0 var(--cyan);
  overflow-wrap: anywhere;
}
.title-logo span { color: var(--text); }
.title-screen h1 {
  margin: 8px 0 0;
  font: clamp(14px, 2.6vw, 30px)/1.6 var(--px);
  letter-spacing: 0.02em;
}
.title-screen h1 span { color: var(--green); }
.title-screen h1 .parse-word { color: var(--cyan); }
.title-blurb { margin: 0; max-width: 34em; font-size: 24px; color: var(--soft); }
.title-help { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 12px 18px; margin: 6px 0 0; }
.title-new { font: 11px var(--px); color: var(--coin); animation: blink 1s steps(1) infinite; }

@keyframes blink { 50% { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .title-new { animation: none; }
}

/* HOW TO PLAY: the guided tour (tour.js). A modal dialog over the whole
   viewport: the spotlight's shadow dims everything but the target, and the
   box sits next to it (pinned to the bottom on narrow screens). */

.tour {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  color: var(--text);
  background: transparent;
  border: 0;
}
.tour::backdrop { background: transparent; }
/* No target on the page: no spotlight, and the box in the middle. */
.tour.no-target { background: rgb(13 11 30 / 0.8); }
.tour-spotlight {
  position: absolute;
  left: var(--x, 0);
  top: var(--y, 0);
  width: var(--w, 0);
  height: var(--h, 0);
  border: 3px solid var(--coin);
  box-shadow: 0 0 0 100vmax rgb(13 11 30 / 0.8);
  pointer-events: none;
}
.tour.no-target .tour-spotlight { display: none; }
.tour-box {
  position: absolute;
  left: var(--box-x, 50%);
  top: var(--box-y, 50%);
  width: min(34rem, calc(100vw - 32px));
  padding: 20px 22px 22px;
  background: var(--panel);
  border: var(--frame);
  box-shadow: 6px 6px 0 var(--coin);
}
.tour.no-target .tour-box { left: 50%; top: 50%; transform: translate(-50%, -50%); }
.tour-title { margin: 0 0 12px; font: 12px/1.6 var(--px); color: var(--coin); }
.tour-count { color: var(--muted); }
.tour-body { margin: 0 0 18px; color: var(--soft); }
.tour-body p { margin: 0 0 10px; }
.tour-body p:last-child { margin-bottom: 0; }
.tour-body code { color: var(--text); white-space: nowrap; }
.tour-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.tour-actions [data-tour-skip] { margin-left: auto; }
.tour-actions .button:disabled, .lr-trace-controls .button:disabled { color: var(--dim); box-shadow: none; cursor: default; }
.tour-actions .button:disabled:active, .lr-trace-controls .button:disabled:active { transform: none; }

main { max-width: 1440px; margin: 0 auto; padding: 0 24px; }

/* Editors */

/* The grammars side by side (lexer, then parser), the text across both
   columns below them. */
.editors {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-areas: "lexer parser" "text text";
  gap: 24px;
}
.lexer-pane { grid-area: lexer; }
.parser-pane { grid-area: parser; }
.text-pane { grid-area: text; }

.pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--panel);
  border: var(--frame);
  box-shadow: 6px 6px 0 var(--shadow);
}
.pane.text-pane { box-shadow: 6px 6px 0 var(--cyan); }

.pane-head, .pane-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px 12px;
  padding: 8px 14px;
  font-size: 20px;
}

.pane-head { background: var(--panel-2); border-bottom: var(--frame); }
.pane-head label { font: 12px var(--px); color: var(--coin); }
.pane.text-pane .pane-head label { color: var(--cyan); }
.pane-foot { border-top: var(--rail-line); color: var(--muted); }

/* P2, the parser grammar: optional, beside the lexer grammar */
.pane.parser-pane { box-shadow: 6px 6px 0 var(--green); }
.pane.parser-pane .pane-head label { color: var(--green); }
.hint { color: var(--muted); }

/* A saved grammar's description: a pane across both editor columns */
.about { margin-bottom: 24px; }
.about-label { margin: 0; font: 12px/25px var(--px); color: var(--coin); }  /* as tall as a hint line */
.about-text { margin: 0; padding: 10px 14px; color: var(--soft); white-space: pre-line; overflow-wrap: anywhere; }
.hint code { color: var(--text); white-space: nowrap; }

.pane textarea {
  display: block;
  width: 100%;
  min-height: 20rem;
  border: 0;
  padding: 10px 12px;
  resize: vertical;
  font: 22px/1.3 var(--vt);
  color: var(--text);
  background: var(--panel);
  tab-size: 4;
}
.about textarea { min-height: 0; color: var(--soft); resize: none; field-sizing: content; }  /* as tall as its text */
.about textarea::placeholder { color: var(--dim); }
.about textarea:focus-visible { outline: 3px solid var(--coin); outline-offset: -3px; }

.counter { color: var(--muted); }
.counter.near { color: var(--warn); }
.counter.over { color: var(--error); }

/* Heights in lines: 1.3em is the scroller's line height, 8px CodeMirror's content padding. */
.pane .cm-editor { height: calc(var(--lines) * 1.3em + 8px); font-size: 22px; background: var(--panel); color: var(--text); }
.pane.lexer-pane .cm-editor, .pane.parser-pane .cm-editor { --lines: 15; }
.pane.text-pane .cm-editor { --lines: 10; }
/* Grow into the row, so P1 lines up with P2 when P2's hint wraps onto its own line. */
.pane .cm-editor { flex-grow: 1; }
.pane .cm-editor.cm-focused { outline: none; }
.pane:focus-within { border-color: var(--coin); }
.pane .cm-scroller { font-family: var(--vt); line-height: 1.3; }
.pane .cm-gutters { background: var(--panel); color: var(--dim); border-right: var(--rail-line); }
.pane .cm-activeLine { background: color-mix(in srgb, var(--panel-2) 70%, transparent); }
.pane .cm-activeLineGutter { background: var(--panel-2); color: var(--text); }
.pane .cm-content { caret-color: var(--coin); }
/* Beats CodeMirror's own theme, which loads after this file. */
.pane .cm-content .cm-placeholder { color: var(--dim); }
.pane .cm-cursor { border-left: 3px solid var(--coin); }
.pane .cm-selectionBackground, .pane .cm-focused .cm-selectionBackground { background: var(--select) !important; }
.pane .cm-lintRange-error { background-image: none; text-decoration: underline wavy var(--error); text-underline-offset: 4px; }
.pane .cm-lintRange-warning { background-image: none; text-decoration: underline wavy var(--warn); text-underline-offset: 4px; }

/* Highlighted tokens in the text editor */

/* Tokens in the text are coloured by their rule: the letters, not a fill. */
.tok.c0 { color: var(--c0); }
.tok.c1 { color: var(--c1); }
.tok.c2 { color: var(--c2); }
.tok.c3 { color: var(--c3); }
.tok.c4 { color: var(--c4); }
.tok.c5 { color: var(--c5); }
.tok.c6 { color: var(--c6); }
.tok.c7 { color: var(--c7); }
.tok-unmatched {
  color: var(--error);
  background: color-mix(in srgb, var(--error) 18%, transparent);
  text-decoration: wavy underline var(--error);
  text-underline-offset: 4px;
}
.tok-active { outline: 3px solid var(--text); outline-offset: 0; }
.node-active { outline: 3px solid var(--green); outline-offset: 0; }
.tok-parse-error { text-decoration: underline wavy var(--error) 2px; text-underline-offset: 5px; }
.parse-error-eof { margin-left: 4px; padding: 0 4px; font: 9px var(--px); color: var(--screen); background: var(--error); }
.line-active { background: var(--rail) !important; }

/* Grammar syntax */

.hl-comment { color: var(--hl-comment); }
.hl-name { color: var(--hl-name); }
.hl-escape { color: var(--hl-escape); }
.hl-class { color: var(--hl-class); }
.hl-operator { color: var(--hl-operator); }
.hl-group { color: var(--hl-group); }
.hl-invalid { color: var(--hl-invalid); text-decoration: underline wavy; }

/* Tooltips: a game dialogue box */

.cm-editor .cm-tooltip {
  border: var(--frame);
  border-radius: 0;
  background: var(--screen);
  color: var(--text);
}
.cm-editor .cm-tooltip-hover { box-shadow: 6px 6px 0 var(--coin); }
.cm-tooltip-lint { font: 20px var(--vt); }
.cm-diagnostic { border-left: 0; padding: 6px 10px; }
.cm-diagnostic-error { color: var(--error); }
.cm-diagnostic-warning { color: var(--warn); }

/* Controls */

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px 28px;
  margin: 26px 0 18px;
}

.segmented {
  display: inline-flex;
  gap: 22px;
  margin: 0;
  padding: 6px 16px;
  border: var(--rail-line);
  background: var(--panel);
}
.segmented.view-toggle { margin: 0 0 16px; }
.segmented label {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  font: 11px var(--px);
  color: var(--muted);
  cursor: pointer;
}
.segmented label::before { content: "▶"; visibility: hidden; }
.segmented label:has(input:checked) { color: var(--coin); }
.segmented label:has(input:checked)::before { visibility: visible; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label:has(input:focus-visible) { outline: 3px solid var(--coin); outline-offset: 4px; }


.indicator { font: 10px var(--px); color: var(--green); visibility: hidden; }
.htmx-request .indicator, .htmx-request.indicator { visibility: visible; }

/* Results */

#results { min-height: 8rem; }

.hud { display: flex; flex-wrap: wrap; gap: 16px; margin-bottom: 16px; }
.hud-stat {
  flex: 1 1 150px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 16px;
  background: var(--panel);
  border: var(--rail-line);
}
.hud-label { font: 10px var(--px); color: var(--cyan); }
.hud-value { font: 22px var(--px); color: var(--coin); }
.hud-stat.good .hud-value { color: var(--green); }
.hud-stat.bad .hud-value { color: var(--error); }
.hud-time .hud-value { color: var(--text); }
.hud-notes { flex: 2 1 260px; display: flex; flex-direction: column; justify-content: center; gap: 4px; color: var(--warn); }

.state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
  padding: 28px 24px;
  text-align: center;
  background: var(--panel);
  border: 3px solid var(--error);
  box-shadow: 6px 6px 0 var(--shadow);
}
.state.warn { border-color: var(--warn); box-shadow: 6px 6px 0 var(--coin); }
.state-title { margin: 0; font: 22px/1.4 var(--px); color: var(--error); }
.state.warn .state-title { color: var(--warn); }
.state.ready { border-color: var(--cyan); }
.state.ready .state-title { color: var(--cyan); }
.state-hint { font: 10px var(--px); }

.problems { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 8px; }
.state .problems { margin: 0; justify-items: center; }
.problem {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px;
  padding: 8px 14px;
  border: 3px solid currentColor;
  background: var(--panel);
}
.state .problem { border: 0; padding: 0; background: none; }
.problem.error { color: var(--error); }
.problem.warning { color: var(--warn); }
.severity { font: 9px var(--px); text-transform: uppercase; }
.problem .message { color: var(--text); overflow-wrap: anywhere; }
.line-link {
  font: inherit;
  color: var(--coin);
  background: none;
  border: 0;
  padding: 0;
  text-decoration: underline;
  cursor: pointer;
}

/* The parse: outcome, problems, error and tree, above the scan results */

.parse { margin-bottom: 20px; background: var(--panel); border: var(--frame); box-shadow: 6px 6px 0 var(--green); }

/* PARSING TREE, PARSING TABLE, TOKENS and SAVE GAME collapse from their head
   bars, with a ▾/▸ marker. Hovering a bar lights up its title. */
.parse-head, .lr-head, .scan-head, .export-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 16px;
  padding: 12px 16px;
  background: var(--panel-2);
  cursor: pointer;
  list-style: none;
}
.parse-head::-webkit-details-marker,
.lr-head::-webkit-details-marker,
.scan-head::-webkit-details-marker,
.export-head::-webkit-details-marker { display: none; }
.parse-head::before, .lr-head::before, .scan-head::before, .export-head::before {
  content: "▸";
  align-self: center;
  font: 22px/1 var(--vt);
  color: var(--coin);
}
details[open] > .parse-head::before,
details[open] > .lr-head::before,
details[open] > .scan-head::before,
details[open] > .export-head::before { content: "▾"; }
.parse-head:hover .parse-title,
.lr-head:hover .lr-title,
.scan-head:hover .scan-title,
.export-head:hover .export-title { color: var(--coin); }

.scan { margin-bottom: 20px; }
.scan-head { border: var(--frame); box-shadow: 6px 6px 0 var(--cyan); }
.scan-title { margin: 0; font: 12px var(--px); color: var(--cyan); }
.scan-stats { color: var(--muted); }
.scan-body { padding-top: 20px; }
.parse-title { margin: 0; font: 12px var(--px); color: var(--green); }
.parse-outcome { font: 12px var(--px); }
.parse-outcome.accepted { color: var(--green); }
.parse-outcome.rejected, .parse-outcome.grammar { color: var(--error); }
.parse-stats { color: var(--muted); }
.parse-conflicts { color: var(--warn); }
.parse .problems { margin: 0; padding: 12px 16px; border-top: var(--rail-line); }
.parse-error { margin: 0; padding: 12px 16px; border-top: var(--rail-line); color: var(--text); overflow-wrap: anywhere; }
.parse-error .severity { margin-right: 8px; color: var(--error); }
.parse-note { margin: 0; padding: 8px 16px; border-top: var(--rail-line); color: var(--warn); }

/* Each row is indented by its --depth (set by main.js), up to 40 levels, with
   a rail line per level. */
.tree { list-style: none; margin: 0; padding: 8px 0; max-height: 32rem; overflow: auto; border-top: var(--frame); }
.tree-node {
  --indent: 22px;
  --levels: min(var(--depth, 0), 40);
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 0 16px 0 calc(16px + var(--levels) * var(--indent));
  white-space: nowrap;
  background: repeating-linear-gradient(
      to right,
      transparent 0 calc(var(--indent) / 2 - 1px),
      var(--rail) calc(var(--indent) / 2 - 1px) calc(var(--indent) / 2 + 1px),
      transparent calc(var(--indent) / 2 + 1px) var(--indent)
    )
    16px 0 / calc(var(--levels) * var(--indent)) 100% no-repeat;
}
.tree-toggle, .tree-leaf { flex: 0 0 18px; text-align: center; }
.tree-toggle { font: 22px var(--vt); color: var(--coin); background: none; border: 0; padding: 0; cursor: pointer; }
.tree-toggle::before { content: "▾"; }
.tree-toggle[aria-expanded="false"]::before { content: "▸"; }
.tree-leaf { color: var(--dim); }
.tree-leaf::before { content: "─"; }
.tree-symbol { font: 22px var(--vt); color: var(--text); background: none; border: 0; padding: 0; text-align: left; cursor: pointer; }
.tree-symbol:hover { text-decoration: underline; }
/* A rule's name has the colour its tokens get in the text. */
.tree-symbol.c0 { color: var(--c0); } .tree-symbol.c1 { color: var(--c1); }
.tree-symbol.c2 { color: var(--c2); } .tree-symbol.c3 { color: var(--c3); }
.tree-symbol.c4 { color: var(--c4); } .tree-symbol.c5 { color: var(--c5); }
.tree-symbol.c6 { color: var(--c6); } .tree-symbol.c7 { color: var(--c7); }
.tree-node.tree-token .tree-symbol { color: var(--cyan); }
.tree-literal { color: var(--text); }
.tree-node.tree-empty .tree-symbol { color: var(--dim); cursor: default; text-decoration: none; }
.tree-node:hover { background-color: var(--panel-2); }

/* PARSING TABLE: the rules legend beside the table. The header rows and the
   STATE column stay put while the table scrolls; a state's items open in a row
   under it (main.js). */
.lr { margin-bottom: 20px; background: var(--panel); border: var(--frame); box-shadow: 6px 6px 0 var(--green); }
.lr-title { margin: 0; font: 12px var(--px); color: var(--green); }
.lr-stats { color: var(--muted); }
.lr-conflicts { color: var(--warn); }
.lr-outcome { font: 12px var(--px); color: var(--error); }
.lr-key { margin: 0; padding: 10px 16px; border-top: var(--rail-line); color: var(--muted); }
.lr-key b { font-weight: normal; color: var(--coin); }
.lr-loading { margin: 0; padding: 12px 16px; border-top: var(--rail-line); font: 12px var(--px); color: var(--dim); }
.lr-grid {
  display: grid;
  grid-template-columns: minmax(12rem, 20rem) minmax(0, 1fr);
  border-top: var(--frame);
}
.lr-rules {
  list-style: none;
  margin: 0;
  padding: 8px 0;
  max-height: 32rem;
  overflow: auto;
  border-right: var(--frame);
}
.lr-rules li { display: flex; gap: 10px; padding: 0 14px; white-space: nowrap; }
.lr-number { flex: 0 0 2ch; text-align: right; color: var(--dim); }
.lr-rule { font: 22px var(--vt); color: var(--soft); background: none; border: 0; padding: 0; text-align: left; }
button.lr-rule { cursor: pointer; }
button.lr-rule:hover { color: var(--coin); }
.lr-wrap { max-height: 32rem; overflow: auto; }
.lr-table { border-collapse: separate; border-spacing: 0; font: 22px var(--vt); }
.lr-table thead { position: sticky; top: 0; z-index: 2; }
.lr-table thead th {
  padding: 4px 12px;
  font: 10px var(--px);
  color: var(--cyan);
  background: var(--panel-2);
  white-space: nowrap;
}
.lr-table thead tr:last-child th { font: 22px var(--vt); border-bottom: var(--frame); }
.lr-table thead th[scope="colgroup"] { color: var(--muted); border-bottom: 2px solid var(--rail); }
.lr-table thead th[scope="colgroup"] + th { border-left: 2px solid var(--rail); }
.lr-table thead .c0 { color: var(--c0); } .lr-table thead .c1 { color: var(--c1); }
.lr-table thead .c2 { color: var(--c2); } .lr-table thead .c3 { color: var(--c3); }
.lr-table thead .c4 { color: var(--c4); } .lr-table thead .c5 { color: var(--c5); }
.lr-table thead .c6 { color: var(--c6); } .lr-table thead .c7 { color: var(--c7); }
.lr-table .lr-corner, .lr-table tbody th {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--panel-2);
  border-right: var(--frame);
}
.lr-table .lr-corner { border-bottom: var(--frame); }
.lr-table td { padding: 0 12px; text-align: center; white-space: nowrap; border-bottom: 2px solid var(--rail); }
.lr-table tbody th { padding: 0 10px; border-bottom: 2px solid var(--rail); }
/* Room for the sticky header rows when main.js scrolls to a state. */
.lr-table tr[data-state] { scroll-margin-top: 4.5rem; }
.lr-table tr[data-state]:hover td, .lr-table tr[data-state]:hover th { background-color: var(--panel-2); }
.lr-state { font: 22px var(--vt); color: var(--text); background: none; border: 0; padding: 0; cursor: pointer; }
.lr-state::before { content: "▸ "; color: var(--coin); }
.lr-state[aria-expanded="true"]::before { content: "▾ "; }
.lr-state:hover { color: var(--coin); }
.lr-state.lr-conflict { color: var(--warn); }
.lr-action { font: 22px var(--vt); color: var(--text); background: none; border: 0; padding: 0; }
button.lr-action { cursor: pointer; }
button.lr-action:hover { color: var(--coin); text-decoration: underline; }
td.lr-conflict { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }
/* The parser takes the first action; the others are struck out. */
td.lr-conflict .lr-action { color: var(--warn); text-decoration: line-through; }
td.lr-conflict .lr-action.lr-win { color: var(--coin); text-decoration: none; }
.lr-items td { padding: 6px 16px 8px; text-align: left; background: var(--screen); }
.lr-items ul { list-style: none; margin: 0; padding: 0; }
.lr-items li { white-space: nowrap; color: var(--text); }
.lr-items li.lr-closure { color: var(--soft); }
/* The closure items follow the kernel items, under a divider. */
.lr-items li:not(.lr-closure) + .lr-closure { margin-top: 4px; padding-top: 4px; border-top: 2px dashed var(--rail); }
.lr-lookaheads { color: var(--dim); }
/* Stepping through the text (main.js): the cell the parser looks up now, the
   GOTO a reduce follows, and the stack and input before the action. */
.lr-trace { padding: 10px 16px 12px; border-top: var(--rail-line); }
.lr-trace-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.lr-trace-controls .button.primary:disabled { background: var(--panel); border-color: var(--rail); }
.lr-trace-count { min-width: 9ch; padding: 0 6px; font: 10px var(--px); color: var(--coin); text-align: center; }
.lr-trace-action { margin: 10px 0 6px; color: var(--text); }
.lr-trace-action b { font-weight: normal; color: var(--coin); }
.lr-trace-action.lr-trace-accept b { color: var(--green); }
.lr-trace-action.lr-trace-error b { color: var(--error); }
.lr-trace-config { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px 14px; margin: 0; }
.lr-trace-config dt { font: 10px/25px var(--px); color: var(--muted); }
.lr-trace-config dd { margin: 0; overflow-wrap: anywhere; color: var(--soft); }
.lr-trace-config .lr-stack-state { color: var(--coin); }
.lr-trace-config .lr-input-next { color: var(--text); text-decoration: underline; }
/* Room for the sticky header rows and STATE column when a step scrolls to its cell. */
.lr-table td { scroll-margin: 4.5rem 0 0 6rem; }
.lr-table td.lr-now, .lr-table th.lr-now { outline: 3px solid var(--coin); outline-offset: -3px; }
.lr-table td.lr-goto { outline: 3px dashed var(--green); outline-offset: -3px; }
.lr-table td.lr-blank::after { content: "·"; color: var(--error); }
.trace-active { outline: 3px solid var(--coin); outline-offset: 0; }
.lr-table tr.lr-flash th, .lr-table tr.lr-flash td { animation: lr-flash 1.2s steps(6); }
@keyframes lr-flash { 0%, 66% { background-color: var(--select); } }
@media (prefers-reduced-motion: reduce) {
  .lr-table tr.lr-flash th, .lr-table tr.lr-flash td { animation: none; background-color: var(--select); }
}

.results-grid { display: grid; grid-template-columns: 15rem minmax(0, 1fr); gap: 20px; align-items: start; }

.rules, .tokens, .export { background: var(--panel); border: var(--frame); }

.rules { padding: 12px 0 10px; }
.rules h2 { margin: 0 14px 10px; font: 12px var(--px); text-transform: uppercase; color: var(--coin); }
.rules ul { list-style: none; margin: 0; padding: 0; max-height: 32rem; overflow: auto; }
.rule { display: grid; grid-template-columns: 14px minmax(0, 1fr) auto auto; align-items: center; gap: 10px; padding: 2px 14px; }
.rule.is-hidden .rule-name, .rule.is-hidden .count { opacity: 0.5; }
.swatch { width: 14px; height: 14px; }
.rule-name {
  font: 22px var(--vt);
  color: var(--text);
  background: none;
  border: 0;
  padding: 2px 0;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rule-name:hover { color: var(--coin); }
.count { font: 10px var(--px); color: var(--coin); }
.count::before { content: "x"; }
.hide-toggle { display: inline-flex; gap: 4px; align-items: center; color: var(--muted); font-size: 18px; cursor: pointer; }
.hide-toggle input { accent-color: var(--coin); }

.swatch.c0 { background: var(--c0); } .swatch.c1 { background: var(--c1); }
.swatch.c2 { background: var(--c2); } .swatch.c3 { background: var(--c3); }
.swatch.c4 { background: var(--c4); } .swatch.c5 { background: var(--c5); }
.swatch.c6 { background: var(--c6); } .swatch.c7 { background: var(--c7); }

.tokens { overflow: hidden; }

.table-wrap { max-height: 32rem; overflow: auto; }
.token-table { width: 100%; border-collapse: collapse; }
.token-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 10px 12px;
  text-align: left;
  font: 10px var(--px);
  text-transform: uppercase;
  color: var(--cyan);
  background: var(--panel-2);
  border-bottom: var(--frame);
  white-space: nowrap;
}
.token-table td { padding: 3px 12px; border-bottom: 2px solid var(--rail); vertical-align: top; }
.token-table tr:last-child td { border-bottom: 0; }
.token-table tr.unmatched td { background: color-mix(in srgb, var(--error) 14%, transparent); }
.token-table tr.is-active td { background: var(--rail); }
.token-table .num { color: var(--muted); white-space: nowrap; }
.token-table td.num:first-child { color: var(--dim); }
.token-table .empty { padding: 28px 16px; font: 12px/1.6 var(--px); color: var(--cyan); text-align: center; }

.rule-chip {
  display: inline-block;
  padding: 4px 6px;
  font: 9px var(--px);
  color: var(--tok-text);
  white-space: nowrap;
}
.rule-chip.c0, .chip.c0 { background: var(--c0); } .rule-chip.c1, .chip.c1 { background: var(--c1); }
.rule-chip.c2, .chip.c2 { background: var(--c2); } .rule-chip.c3, .chip.c3 { background: var(--c3); }
.rule-chip.c4, .chip.c4 { background: var(--c4); } .rule-chip.c5, .chip.c5 { background: var(--c5); }
.rule-chip.c6, .chip.c6 { background: var(--c6); } .rule-chip.c7, .chip.c7 { background: var(--c7); }
.rule-chip.unmatched, .chip.unmatched { color: var(--error); background: transparent; box-shadow: inset 0 0 0 2px var(--error); }

.select-token {
  font: 22px var(--vt);
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  text-align: left;
  cursor: pointer;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.select-token:hover { color: var(--coin); }
.ws { color: var(--dim); }

.why-label { text-transform: uppercase; white-space: nowrap; }
.why-only { color: var(--muted); }
.why-longest { color: var(--green); }
.why-tie-earlier { color: var(--warn); }
details.why summary { cursor: pointer; }
.candidates { margin: 4px 0 2px; padding-left: 0; list-style: none; color: var(--muted); }
.candidates li { white-space: nowrap; }
.candidates li::before { content: "  "; white-space: pre; }
.candidates li.winner { color: var(--coin); }
.candidates li.winner::before { content: "▶ "; }
.cand-rule { font-family: var(--vt); }

.chips { list-style: none; margin: 0; padding: 14px; display: flex; flex-wrap: wrap; gap: 8px; max-height: 32rem; overflow: auto; }
.chip { color: var(--tok-text); }
.chip.is-active { outline: 3px solid var(--text); outline-offset: 2px; }
.chip .select-token { display: inline-flex; align-items: baseline; gap: 8px; padding: 2px 8px; }
.chip .select-token:hover { color: inherit; text-decoration: underline; }
.chip-name { font: 8px var(--px); }
.chip-literal { font-family: var(--vt); }
.chip .ws { color: inherit; opacity: 0.6; }
.chips .empty { font: 12px/1.6 var(--px); color: var(--cyan); }

.export { margin-top: 20px; box-shadow: 6px 6px 0 var(--shadow); }
.export-title { margin: 0; font: 12px var(--px); color: var(--shadow); }
.export-stats { color: var(--muted); }
.export-body { position: relative; border-top: var(--frame); }
.export-body .button { position: absolute; top: 12px; right: 14px; }
.export pre { margin: 0; padding: 14px; overflow: auto; font-size: 20px; line-height: 1.3; }
.export code { counter-reset: line; }
.export .line::before {
  counter-increment: line;
  content: counter(line);
  display: inline-block;
  min-width: 3ch;
  margin-right: 2ch;
  text-align: right;
  color: var(--muted);
  user-select: none;
}

/* Flash messages */

.messages { list-style: none; max-width: 1440px; margin: 16px auto 0; padding: 0 24px; display: grid; gap: 8px; }
.message { padding: 10px 14px; border: 3px solid var(--cyan); background: var(--panel); color: var(--text); }
.message.success { border-color: var(--green); }
.message.warning { border-color: var(--warn); }
.message.error { border-color: var(--error); }

/* Account pages: a card in the middle of the screen */

.auth { display: flex; justify-content: center; padding: 48px 24px; }
.auth-card {
  width: 100%;
  max-width: 34rem;
  padding: 28px 28px 32px;
  background: var(--panel);
  border: var(--frame);
  box-shadow: 6px 6px 0 var(--shadow);
}
.auth-card > p, .auth-card > ul { color: var(--soft); }
.auth-title { margin: 0 0 18px; font: 18px/1.5 var(--px); color: var(--coin); text-shadow: 3px 3px 0 var(--shadow); overflow-wrap: anywhere; }
.danger-title { color: var(--error); }
.auth-subtitle { margin: 24px 0 12px; font: 12px/1.5 var(--px); color: var(--cyan); }
.auth-rule { margin: 24px 0; border: 0; border-top: var(--rail-line); }
.auth-alert { padding: 10px 14px; border: 3px solid var(--warn); color: var(--warn); }
.auth-note { font-size: 20px; color: var(--muted); }

.auth-form p { margin: 0 0 16px; }
.auth-form label { display: block; margin-bottom: 6px; font: 10px/1.6 var(--px); color: var(--cyan); }
.auth-form input:not([type="checkbox"], [type="radio"]), .auth-form textarea {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 4px 10px;
  font: 22px var(--vt);
  color: var(--text);
  background: var(--screen);
  border: var(--frame);
  border-radius: 0;
}
.auth-form input:focus-visible, .auth-form textarea:focus-visible { outline: none; border-color: var(--coin); }
.auth-form textarea { resize: vertical; }
.auth-form input:disabled { color: var(--muted); border-color: var(--rail); }
.auth-form .helptext { display: block; margin-top: 6px; font-size: 19px; color: var(--muted); }
.auth-form .helptext ul { margin: 0; padding-left: 1.2em; }
.errorlist { margin: 0 0 8px; padding: 0; list-style: none; color: var(--error); }
.auth-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 8px; }

.auth-choice { display: flex; align-items: baseline; gap: 10px; }
.auth-choice label { display: inline; font: 22px var(--vt); color: var(--text); }
.auth-choice input { accent-color: var(--coin); }
.badge { margin-left: 8px; font: 9px var(--px); color: var(--green); }

.providers { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.providers form { margin: 0; }
.button.provider { width: 100%; justify-content: center; }

.account-facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 16px; margin: 0 0 24px; }
.account-facts dt { font: 10px/2.2 var(--px); color: var(--cyan); }
.account-facts dd { margin: 0; overflow-wrap: anywhere; }
.account-menu { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 12px; }
.account-menu form { margin: 0; }

.grammar-list { list-style: none; margin: 0 0 24px; padding: 0; display: grid; gap: 4px; }
.grammar-list li { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 16px; padding: 8px 0; border-bottom: var(--rail-line); }
.grammar-list a:not(.button) { overflow-wrap: anywhere; }
.grammar-title { display: grid; min-width: 0; }
.grammar-description { font-size: 20px; color: var(--muted); overflow-wrap: anywhere; }
.grammar-meta { display: flex; align-items: center; gap: 12px; color: var(--muted); }
.danger-link { color: var(--error); }

/* Text pages */

.prose { max-width: 46rem; padding: 40px 24px; color: var(--soft); }
.prose h1 { margin: 0 0 24px; font: 22px/1.5 var(--px); color: var(--coin); text-shadow: 3px 3px 0 var(--shadow); }
.prose h2 { margin: 32px 0 10px; font: 12px/1.5 var(--px); color: var(--cyan); }

@media (max-width: 800px) {
  .messages { padding: 0 16px; }
  .auth { padding: 32px 16px; }
  .auth-card { padding: 22px 18px 26px; }
  .prose { padding: 32px 16px; }
  .site-header { padding: 12px 16px; }
  .save-errors { padding: 0 16px; }
  .save-dialog { padding: 22px 18px 26px; }
  .title-screen { padding: 40px 16px 36px; }
  .title-logo { text-shadow: 3px 3px 0 var(--shadow), 6px 6px 0 var(--cyan); }
  main { padding: 0 16px; }
  .site-footer { padding: 24px 16px 32px; }
  .editors { grid-template-columns: 1fr; grid-template-areas: "lexer" "parser" "text"; }
  .pane .cm-editor { height: 14rem; }
  .tree-node { --indent: 14px; }
  .pane textarea { min-height: 14rem; }
  .results-grid { grid-template-columns: 1fr; }
  .rules ul { max-height: 12rem; }
  .lr-grid { grid-template-columns: 1fr; }
  .lr-rules { max-height: 12rem; border-right: 0; border-bottom: var(--frame); }
  /* The text scrolls, so the box leaves room for the target above it. */
  .tour .tour-box {
    display: flex;
    flex-direction: column;
    left: 16px;
    right: 16px;
    top: auto;
    bottom: 16px;
    width: auto;
    max-height: 55vh;
    transform: none;
  }
  .tour-body { min-height: 0; overflow-y: auto; }
}
