:root {
  --header-grad-start: #4a3d8f;
  --header-grad-mid: #6d5eb5;
  --header-grad-end: #8070c8;
  --tile-grad-start: #2e2468;
  --tile-grad-mid: #362879;
  --tile-grad-end: #4a3d8f;
  --tile-hover-start: #3a2e80;
  --tile-hover-mid: #4a3a9a;
  --tile-hover-end: #5a4da8;

  --bg: #000000;
  --bg-glow: rgba(109, 94, 181, 0.16);
  --panel: #2e2468;
  --panel-head-top: #3a2e80;
  --panel-head-bottom: #2e2468;
  --ink: #e8edf2;
  --muted: #c9c3ee;
  --line: #5a4da8;

  --control-bg: #24303a;
  --control-border: #3c4b57;
  --control-hover: #2b3944;
  --button-top: #3a3f47;
  --button-bottom: #22262c;
  --button-border: #98a5b9;
  --button-hover-top: #444a53;
  --button-hover-bottom: #2a2f36;
  --button-shadow: rgba(0, 0, 0, 0.48);

  --paper-top: #fff6df;
  --paper-bottom: #d6c7a8;
  --paper-fibre: rgba(102, 84, 54, 0.12);
  --paper-ink: #1b2128;
  --paper-line: #7a652c;

  --accent: #ff8f6b;
  --ok: #39ff7a;
  --warn: #ff6d6d;
  --focus: #fff3a6;
  --rail: #ffd86b;
  --rail-alt: #19b5ff;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, var(--bg-glow), transparent 32%),
    radial-gradient(circle at top right, rgba(255, 216, 107, 0.08), transparent 26%),
    var(--bg);
  color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  -webkit-user-select: none;
  user-select: none;
}

body {
  min-height: 100dvh;
}

button,
select,
input,
textarea {
  font: inherit;
}

button,
select,
input {
  min-height: 42px;
}

button,
select,
input,
textarea {
  border-radius: 10px;
  border: 1px solid var(--control-border);
  background: var(--control-bg);
  color: var(--ink);
}

button {
  padding: 0 14px;
  cursor: pointer;
  background: linear-gradient(180deg, var(--button-top), var(--button-bottom));
  border-color: var(--button-border);
  box-shadow: 0 6px 14px var(--button-shadow);
}

button:hover:not(:disabled):not([aria-disabled="true"]):not(.hamburger-btn):not(.btn-clear-states):not(.menu-close-btn):not(.menu-concertina-trigger):not(.menu-item-btn):not(.menu-preset-btn):not(.rule-del-btn),
input:hover,
textarea:hover {
  border-color: var(--focus);
}

button:hover:not(:disabled):not([aria-disabled="true"]):not(.hamburger-btn):not(.btn-clear-states):not(.menu-close-btn):not(.menu-concertina-trigger):not(.menu-item-btn):not(.menu-preset-btn):not(.rule-del-btn) {
  background: linear-gradient(180deg, var(--button-hover-top), var(--button-hover-bottom));
}

button:focus-visible:not([aria-disabled="true"]):not(.hamburger-btn):not(.btn-clear-states):not(.menu-close-btn):not(.menu-concertina-trigger):not(.menu-item-btn):not(.menu-preset-btn):not(.rule-del-btn),
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23a0a0c0' stroke-width='1.8' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding: 10px 28px 10px 12px;
}

input,
textarea {
  padding: 10px 12px;
  font-size: 16px;
}

textarea {
  width: 100%;
  min-height: 0;
  flex: 1;
  resize: vertical;
  line-height: 1.45;
  -webkit-user-select: text;
  user-select: text;
}

.app-shell {
  height: 100dvh;
  min-height: 100svh;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.top-bar,
.card {
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.36);
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: linear-gradient(135deg, var(--header-grad-start), var(--header-grad-mid), var(--header-grad-end));
}

.hamburger-btn {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 30px;
  height: 22px;
  min-height: 0;
  background: none;
  border: none;
  box-shadow: none;
  cursor: pointer;
  padding: 0;
  margin-left: auto;
  position: relative;
  z-index: 31;
  transition: opacity 160ms ease;
}

.hamburger-btn:focus-visible {
  outline: 2px solid #fff3a6;
  outline-offset: 1px;
}

.hamburger-btn span {
  display: block;
  height: 3px;
  border-radius: 2px;
  background: var(--ink);
  transition: transform 200ms ease, opacity 200ms ease;
}

.hamburger-btn.is-open {
  opacity: 0;
  pointer-events: none;
}

.app-menu {
  position: fixed;
  top: 0;
  right: -260px;
  bottom: 0;
  width: 260px;
  background: linear-gradient(180deg, var(--tile-grad-start) 0%, var(--tile-grad-mid) 100%);
  border-left: 1px solid var(--line);
  box-shadow: -6px 0 24px rgba(0, 0, 0, 0.5);
  z-index: 30;
  display: flex;
  flex-direction: column;
  padding: 0 0 16px;
  transition: right 260ms cubic-bezier(0.4, 0, 0.2, 1), visibility 0ms 260ms;
  visibility: hidden;
}

.app-menu.is-open {
  right: 0;
  transition: right 260ms cubic-bezier(0.4, 0, 0.2, 1), visibility 0ms 0ms;
  visibility: visible;
}

.app-shell {
  position: relative;
}

.menu-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  height: 66px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 8px;
}

.menu-title {
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.12em;
  color: var(--ink);
  text-transform: uppercase;
  position: relative;
  top: 1px;
}

.menu-close-btn {
  width: 34px;
  min-width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border: 1px solid #8f1c1c;
  background: linear-gradient(180deg, #f15454, #b32020);
  color: #ffffff;
}

.menu-close-btn svg {
  width: 16px;
  height: 16px;
  display: block;
  stroke: currentColor;
  fill: none;
  stroke-width: 2.4;
  stroke-linecap: round;
}

.menu-close-btn:hover:not(:disabled) {
  background: linear-gradient(180deg, #ff6666, #c32727);
  border-color: #a52323;
  box-shadow: 0 5px 12px rgba(207, 42, 42, 0.45);
  transform: translateY(-1px);
}

.menu-close-btn:focus-visible {
  outline: 2px solid #fff3a6;
  outline-offset: 1px;
}

.menu-inner {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 12px;
}

.menu-concertina-trigger,
.menu-item-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 10px 12px;
  background: none;
  border: none;
  border-radius: 8px;
  color: var(--ink);
  font-size: 1.1rem;
  cursor: pointer;
  text-align: left;
}

.menu-concertina-trigger:hover,
.menu-item-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: transparent;
}

.concertina-arrow {
  font-size: 0.8rem;
  transition: transform 180ms ease;
}

.menu-concertina-list {
  list-style: none;
  margin: 2px 0 6px;
  padding: 0;
}

.menu-concertina-list[hidden] {
  display: none;
}

.menu-preset-btn {
  display: block;
  width: 100%;
  padding: 8px 24px;
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.9rem;
  cursor: pointer;
  text-align: left;
}

.menu-preset-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  border-color: transparent;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
}

.brand-mark img {
  width: auto;
  height: 46px;
  display: block;
}

.brand-text h1 {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  line-height: 1;
  color: #ffffff;
}

.brand-tagline {
  font-size: 0.9rem;
  font-weight: 400;
}

.brand-text p {
  margin: 2px 0 0;
  color: #ffffff;
  font-size: 0.9rem;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr);
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 10px;
  min-height: 0;
  flex: 1;
  align-content: start;
}

.editor-panel,
.diagram-panel {
  min-width: 0;
}

.card {
  background: linear-gradient(180deg, var(--panel-head-top), var(--panel-head-bottom) 72px, var(--panel));
  min-height: 0;
  overflow: hidden;
}

.editor-panel.card,
.diagram-panel.card {
  background: #000000;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 20px rgba(10, 6, 30, 0.4);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.editor-panel .panel-head,
.diagram-panel .panel-head {
  border-bottom: 1px solid var(--line);
  padding: 8px 10px;
  background: linear-gradient(180deg, var(--panel-head-top), var(--panel-head-bottom));
  min-height: 51px;
}

.panel-head h2 {
  margin: 0;
  font-size: 1.1rem;
}

.editor-panel .panel-head h2,
.diagram-panel .panel-head h2 {
  font-size: 1.05rem;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.compact {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.action-stack {
  row-gap: 6px;
}

.btn-clear-states {
  width: 34px;
  min-width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border-color: #8f1c1c;
  background: linear-gradient(180deg, #f15454, #b32020);
  color: #ffffff;
}

.editor-panel #resetGrammarBtn.btn-clear-states {
  width: 42px;
  min-width: 42px;
  height: 42px;
  min-height: 42px;
}

.btn-clear-states svg {
  width: 24px;
  height: 24px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn-clear-states:hover:not(:disabled) {
  border-color: #a52323;
  background: linear-gradient(180deg, #ff6666, #c32727);
  box-shadow: 0 5px 12px rgba(207, 42, 42, 0.45);
  transform: translateY(-1px);
}

.btn-clear-states:focus-visible {
  outline: 2px solid #fff3a6;
  outline-offset: 2px;
}

.editor-panel,
.diagram-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding-bottom: 16px;
}

.field-label,
.inline-label,
.summary-label {
  display: block;
  font-size: 0.88rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
}

.editor-panel .field-label,
.editor-panel .panel-note,
.summary-grid,
.diagram-frame {
  margin-left: 16px;
  margin-right: 16px;
}

.grammar-editor {
  position: relative;
  flex: 1;
  min-height: 0;
  margin-top: 16px;
  margin-left: 16px;
  margin-right: 16px;
  border-radius: 10px;
  border: 1px solid var(--control-border);
  background: #000000;
  overflow: hidden;
}

.grammar-editor:focus-within {
  border-color: var(--focus);
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.grammar-highlight,
.grammar-editor textarea {
  margin: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 10px 12px;
  border: 0;
  border-radius: 0;
  font-family: "Cascadia Code", "Consolas", "Courier New", monospace;
  font-size: 1rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.grammar-highlight {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  color: var(--ink);
}

.grammar-editor textarea {
  position: relative;
  background: transparent;
  color: transparent;
  caret-color: var(--ink);
  resize: none;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 216, 107, 0.78) rgba(255, 255, 255, 0.08);
}

.grammar-editor textarea:focus-visible {
  outline: none;
}

.grammar-editor textarea::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

.grammar-editor textarea::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 10px;
}

.grammar-editor textarea::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, rgba(255, 216, 107, 0.9), rgba(255, 143, 107, 0.9));
  border-radius: 10px;
  border: 2px solid rgba(0, 0, 0, 0.35);
}

.grammar-editor textarea::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, rgba(255, 243, 166, 0.95), rgba(255, 167, 132, 0.95));
}

.grammar-editor textarea::-webkit-scrollbar-corner {
  background: rgba(255, 255, 255, 0.08);
}

.grammar-snippet-menu {
  position: fixed;
  display: grid;
  min-width: 220px;
  padding: 8px;
  gap: 6px;
  border: 1px solid rgba(255, 243, 166, 0.6);
  border-radius: 12px;
  background:
    linear-gradient(180deg, rgba(46, 36, 104, 0.96), rgba(22, 16, 52, 0.98));
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.5);
  z-index: 60;
}

.grammar-snippet-btn {
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.04);
  box-shadow: none;
  text-align: left;
  color: var(--ink);
}

.grammar-snippet-btn:hover,
.grammar-snippet-btn:focus-visible {
  background: rgba(255, 216, 107, 0.14);
  border-color: var(--focus);
}

.hl-comment {
  color: #8ea0b0;
}

.hl-nonterminal {
  color: #4fb584;
  font-weight: 600;
}

.hl-terminal {
  color: #d967be;
}

.hl-operator,
.hl-alternative {
  color: #d4985c;
  font-weight: 600;
}

.hl-epsilon {
  color: #b8a0e8;
}

.panel-note {
  margin-top: 10px;
  margin-bottom: 0;
  color: var(--muted);
}

.code-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: rgba(255, 216, 107, 0.18);
  color: #fff3bf;
}

.summary-grid {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.summary-card {
  min-height: 86px;
  padding: 12px;
  border-radius: 12px;
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.18), rgba(0, 0, 0, 0.28)),
    linear-gradient(135deg, var(--tile-grad-start), var(--tile-grad-end));
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.summary-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.summary-card > .summary-label {
  min-height: 30px;
  display: flex;
  align-items: center;
}

.summary-action-btn {
  min-height: 30px;
  padding: 0 10px;
  font-size: 0.82rem;
}

.summary-action-btn:disabled {
  opacity: 0.35;
}

#btnFooterHelp {
  appearance: none;
  -webkit-appearance: none;
  touch-action: manipulation;
  min-height: 0;
  height: auto;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: #f7f7ff;
  background: linear-gradient(180deg, var(--button-top), var(--button-bottom));
  border: 1px solid var(--button-border);
  box-shadow: 0 4px 10px var(--button-shadow);
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease, box-shadow 120ms ease;
  background-clip: padding-box;
  -webkit-background-clip: padding-box;
  font-size: 0.82rem;
}

#btnFooterHelp:hover:not(:disabled) {
  border-color: #bcc7db;
  background: linear-gradient(180deg, var(--button-hover-top), var(--button-hover-bottom));
  box-shadow: 0 6px 14px var(--button-shadow);
  transform: translateY(-1px);
}

#btnFooterHelp:focus-visible {
  outline: 2px solid #d7e0f2;
  outline-offset: 2px;
}

.summary-card strong {
  display: block;
  margin-top: 8px;
  font-size: 1.2rem;
}

.summary-select {
  width: 100%;
  margin-top: 8px;
}

.summary-input {
  width: 100%;
  margin-top: 8px;
}

#testInput {
  background: #000000;
}

#testInput:focus-visible {
  outline: none;
}

#testInput.test-pass,
#testInput.test-pass:hover,
#testInput.test-pass:focus-visible {
  border-color: #00ff00;
  box-shadow: 0 0 0 2px rgba(0, 255, 0, 0.5);
}

#testInput.test-fail,
#testInput.test-fail:hover,
#testInput.test-fail:focus-visible {
  border-color: #ff0000;
  box-shadow: 0 0 0 2px rgba(255, 0, 0, 0.5);
}

.summary-card-wide {
  grid-column: 1 / -1;
}

.token-list,
.message-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.token-chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.token-chip.terminal {
  color: #fff3bf;
}

.message-pill {
  display: block;
  width: 100%;
  padding: 6px 10px;
  border-radius: 10px;
  background: #1a1a1a;
  border: 1px solid #ff0000;
  color: #ffd9d9;
}

.message-pill-ok {
  border-color: #ffffff;
  color: #ffffff;
}

.muted-copy {
  color: var(--muted);
}

.diagram-frame {
  position: relative;
  min-height: 0;
  flex: 1;
  margin-top: 16px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: #000000;
  overflow: hidden;
}

.diagram-frame svg {
  width: 100%;
  height: 100%;
  min-height: 0;
  max-width: 100%;
  max-height: 100%;
  display: block;
  -webkit-user-select: none;
  user-select: none;
}

.diagram-frame svg * {
  -webkit-user-select: none;
  user-select: none;
}

.diagram-rule-title {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  font-size: 1.8rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.015em;
  color: #39ff7a;
  pointer-events: none;
}

.diagram-empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  color: var(--muted);
}

.rail-title {
  fill: #f8f3d8;
  font-size: 18px;
  font-weight: 700;
}

.rail-backdrop {
  fill: #000000;
  stroke: none;
}

.rail-grid {
  fill: url(#railGrid);
  opacity: 0.5;
}

.rail-line {
  fill: none;
  stroke: #ffd86b;
  stroke-width: 2.4;
  stroke-linecap: butt;
  stroke-linejoin: miter;
}

.rail-line-alt {
  stroke: #ffd86b;
}

.rail-flow {
  fill: none;
  stroke: #000000;
  stroke-width: 2;
  stroke-linecap: butt;
  stroke-linejoin: miter;
  stroke-dasharray: 14 8;
  filter: none;
  mix-blend-mode: normal;
  animation: rail-flow 4s linear infinite;
  pointer-events: none;
}

@keyframes rail-flow {
  from {
    stroke-dashoffset: 0;
  }

  to {
    stroke-dashoffset: -44;
  }
}

.rail-node-terminal {
  fill: #000000;
  stroke: #ff4df3;
  stroke-width: 2;
}

.rail-node-nonterminal {
  fill: #000000;
  stroke: #39ff7a;
  stroke-width: 2;
}

.rail-node-epsilon {
  fill: #000000;
  stroke: #ffd86b;
  stroke-width: 2;
}

.rail-label-terminal,
.rail-label-nonterminal,
.rail-label-epsilon,
.rail-operator {
  dominant-baseline: middle;
  font-size: 15px;
  letter-spacing: 0.01em;
}

.rail-label-terminal,
.rail-label-nonterminal,
.rail-label-epsilon {
  fill: #ffffff;
}

.rail-operator {
  fill: #dff7ff;
}

.rail-dot-start {
  fill: var(--rail);
}

.rail-dot-end {
  fill: var(--rail);
}

.rail-loop-arrow {
  fill: var(--rail);
}

@media (max-width: 1080px) {
  .app-shell {
    height: auto;
    min-height: 100dvh;
  }

  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    flex: none;
  }

  .diagram-frame,
  .diagram-frame svg {
    min-height: 360px;
  }

  .grammar-editor {
    min-height: 420px;
  }
}

@media (max-width: 700px) {
  .app-shell {
    padding: 8px;
  }

  .top-bar {
    align-items: center;
    gap: 10px;
  }

  .brand {
    align-items: center;
    min-width: 0;
    flex: 1;
  }

  .brand-text {
    min-width: 0;
  }

  .panel-head {
    flex-direction: row;
    align-items: center;
  }

  .panel-head h2 {
    min-width: 0;
  }

  .panel-actions.compact {
    flex-wrap: nowrap;
    gap: 6px;
  }

  .summary-grid {
    grid-template-columns: 1fr;
  }

}

.workspace-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  margin-top: 2px;
  color: var(--ink);
  background: linear-gradient(
    135deg,
    var(--header-grad-start) 0%,
    var(--header-grad-mid) 50%,
    var(--header-grad-end) 100%
  );
  box-shadow: 0 6px 18px rgba(25, 14, 66, 0.5);
  font-size: 0.92rem;
  grid-column: 1 / -1;
}

.workspace-footer-copy {
  min-width: 0;
}

.workspace-footer a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.workspace-footer a:hover,
.workspace-footer a:focus-visible {
  color: #ffffff;
}

.modal a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.modal a:hover,
.modal a:focus-visible {
  opacity: 0.8;
}

.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  padding: 16px;
  box-sizing: border-box;
  z-index: 9999;
  color: var(--ink);
  display: flex;
}

.modal {
  width: min(420px, calc(100vw - 24px));
  margin: 0 auto;
  position: relative;
  z-index: 1;
  padding: 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #000000;
  box-shadow: 0 8px 20px rgba(10, 6, 30, 0.4);
  max-height: calc(100dvh - 32px);
  overflow: auto;
}

.modal h3 {
  margin: 0 0 10px;
  padding-right: 42px;
}

.modal > h3 {
  margin: -14px -14px 10px;
  padding: 10px 46px 10px 14px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, var(--panel-head-top), var(--panel-head-bottom));
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
}

.modal-close-x {
  position: absolute;
  top: 8px;
  right: 10px;
}

.rule-del-btn {
  min-width: 28px;
  width: 28px;
  min-height: 28px;
  height: 28px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #8f1c1c;
  background: #cf2a2a;
  color: #ffffff;
  font-weight: 700;
  font-size: 0;
  line-height: 1;
  border-radius: 8px;
  box-shadow: none;
}

.rule-del-btn:hover:not(:disabled) {
  background: #e13c3c;
  border-color: #a52323;
  box-shadow: 0 5px 12px rgba(207, 42, 42, 0.45);
  transform: translateY(-1px);
}

.rule-del-btn:focus-visible {
  outline: 2px solid #fff3a6;
  outline-offset: 1px;
}

.rule-del-btn svg {
  width: 16px;
  height: 16px;
  display: block;
  stroke: currentColor;
  fill: none;
  stroke-width: 2.4;
  stroke-linecap: round;
}

.about-modal .about-modal-content {
  line-height: 1.45;
}

.about-modal .about-modal-image {
  float: left;
  width: 110px;
  height: auto;
  margin: 2px 12px 8px 0;
  border-radius: 10px;
}

.about-modal .about-modal-content::after {
  content: "";
  display: block;
  clear: both;
}

.about-startup-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0 10px;
}

.about-startup-toggle input[type="checkbox"] {
  width: 16px;
  height: 16px;
  min-height: 16px;
  min-width: 16px;
  margin: 0;
  padding: 0;
  flex: 0 0 16px;
  appearance: none;
  -webkit-appearance: none;
  display: inline-grid;
  place-content: center;
  border: 2px solid #ffd400;
  background: #000000;
  border-radius: 3px;
}

.about-startup-toggle input[type="checkbox"]::before {
  content: "";
  width: 4px;
  height: 8px;
  border: solid #1b1b1b;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) scale(0);
  transform-origin: center;
  transition: transform 120ms ease-in-out;
}

.about-startup-toggle input[type="checkbox"]:checked {
  background: #ffd400;
  border-color: #ffd400;
}

.about-startup-toggle input[type="checkbox"]:checked::before {
  transform: rotate(45deg) scale(1);
}

.about-startup-toggle input[type="checkbox"]:focus-visible {
  outline: 2px solid #fff3a6;
  outline-offset: 2px;
}

@media (max-width: 420px) {
  .about-modal .about-modal-image {
    width: 92px;
    margin-right: 10px;
  }
}

.tasks-modal {
  width: min(720px, calc(100vw - 24px));
}

.tasks-modal-status {
  margin: 0;
  color: var(--muted);
}

.tasks-modal-list {
  display: grid;
  gap: 12px;
}

.tasks-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  align-items: center;
  margin-top: -4px;
  margin-bottom: 2px;
}

.tasks-modal-actions button {
  min-height: 32px;
  height: 32px;
  padding: 0 12px;
  font-size: 0.9rem;
}

.tasks-modal-position {
  margin-right: auto;
  color: var(--muted);
  font-size: 0.92rem;
}

.tasks-modal-shortcut {
  display: block;
  margin: 8px 0 0;
  text-align: right;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.2;
}

.task-card {
  display: grid;
  gap: 10px;
  padding: 2px 0 0;
}

.task-card-title {
  margin: 0;
  color: #ffe28a;
  font-size: 1.08rem;
}

.task-card-grade {
  margin: -2px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.task-card-description,
.task-card-outcome,
.task-card-tape-label {
  margin: 0;
}

.task-card-tests {
  display: grid;
  gap: 6px;
}

.task-card-tests-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.task-tests-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
}

.task-test-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 9px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
}

.task-test-input {
  font-family: "Cascadia Code", "Consolas", "Courier New", monospace;
  color: #d7e1ea;
  font-size: 0.92rem;
  overflow-wrap: anywhere;
}

.task-test-expected {
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.05em;
}

.task-test-expected.accept {
  color: var(--ok);
}

.task-test-expected.reject {
  color: var(--warn);
}

.task-test-expected.other {
  color: #ffd86b;
}

.task-card-description,
.task-card-outcome {
  line-height: 1.45;
}

.task-card-outcome {
  font-weight: 800;
  letter-spacing: 0.05em;
}

.task-card-outcome.accept {
  color: var(--ok);
}

.task-card-outcome.reject {
  color: var(--warn);
}

.task-card-outcome.halt {
  color: #f59e0b;
}

.task-card-tape-block {
  display: grid;
  gap: 6px;
}

.task-card-tape-label {
  color: var(--muted);
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.task-tape-preview {
  display: grid;
  justify-content: start;
  gap: 4px;
  --task-head-stroke: 2px;
}

.task-tape-row {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 24px;
  gap: 3px;
  width: max-content;
  padding: 3px 4px;
  background:
    repeating-linear-gradient(
      0deg,
      transparent 0px,
      transparent 5px,
      var(--paper-fibre) 6px,
      transparent 7px
    ),
    linear-gradient(180deg, var(--paper-top), var(--paper-bottom));
  border-radius: 6px;
}

.task-tape-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: 1px solid var(--control-border);
  border-radius: 5px;
  color: var(--paper-ink);
  font-weight: 700;
  font-size: 0.92rem;
  line-height: 1;
  position: relative;
  background: #fffdf8;
}

.task-tape-cell.is-head {
  outline: var(--task-head-stroke) solid #ff3b3b;
  outline-offset: calc(-1 * var(--task-head-stroke));
}

.task-tape-cell.is-head::before {
  content: "";
  position: absolute;
  inset: 0;
  border: var(--task-head-stroke) solid #ff3b3b;
  border-radius: 5px;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.55),
    0 0 0 1px rgba(8, 18, 28, 0.35),
    0 0 10px rgba(13, 79, 134, 0.35);
  transition: border-color 80ms linear, box-shadow 80ms linear;
  pointer-events: none;
  box-sizing: border-box;
}

@media (max-width: 520px) {
  .tasks-modal {
    width: min(100%, calc(100vw - 24px));
  }

  .task-tape-row {
    grid-auto-columns: 22px;
  }

  .task-tape-cell {
    width: 22px;
    height: 22px;
    font-size: 0.84rem;
  }
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 30px;
  background: rgba(0, 0, 0, 0.78);
  backdrop-filter: blur(4px);
}

.modal-dialog {
  width: calc(100vw - 60px);
  max-width: calc(100vw - 60px);
  height: calc(100dvh - 60px);
  max-height: calc(100dvh - 60px);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #000000;
  box-shadow: 0 8px 20px rgba(10, 6, 30, 0.4);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  min-height: 51px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, var(--panel-head-top), var(--panel-head-bottom));
}

.modal-head h2 {
  margin: 0;
  font-size: 1.05rem;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  flex: 1;
  padding: 10px;
  background: #000000;
}

.info-modal {
  width: min(620px, 96vw);
}

#helpModal.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  padding: 16px;
  box-sizing: border-box;
  z-index: 9999;
  color: var(--ink);
}

.help-modal {
  width: min(640px, calc(100vw - 24px));
  margin: 0 auto;
  position: relative;
  z-index: 1;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid #5a4da8;
  background: #000000;
  box-shadow: 0 8px 20px rgba(10, 6, 30, 0.4);
  max-height: calc(100dvh - 32px);
  overflow: auto;
}

.help-modal h3 {
  margin: 0 0 10px;
  padding-right: 42px;
}

.help-modal > h3 {
  margin: -14px -14px 10px;
  padding: 10px 46px 10px 14px;
  border-bottom: 1px solid #5a4da8;
  background: linear-gradient(180deg, #3f3386, #2e2468);
  color: #e8edf2;
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
}

.help-modal .modal-close-x {
  position: absolute;
  top: 8px;
  right: 10px;
}

.help-modal .rule-del-btn {
  min-width: 28px;
  width: 28px;
  min-height: 28px;
  height: 28px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #8f1c1c;
  background: #cf2a2a;
  color: #ffffff;
  font-weight: 700;
  font-size: 0;
  line-height: 1;
  border-radius: 8px;
  box-shadow: none;
}

.help-modal .rule-del-btn:hover:not(:disabled) {
  background: #e13c3c;
  border-color: #a52323;
  box-shadow: 0 5px 12px rgba(207, 42, 42, 0.45);
  transform: translateY(-1px);
}

#aboutModal .rule-del-btn:hover:not(:disabled) {
  background: #e13c3c;
  border-color: #a52323;
  box-shadow: 0 5px 12px rgba(207, 42, 42, 0.45);
  transform: translateY(-1px);
}

.help-modal .rule-del-btn:focus-visible {
  outline: 2px solid #fff3a6;
  outline-offset: 1px;
}

#aboutModal .rule-del-btn:focus-visible {
  outline: 2px solid #fff3a6;
  outline-offset: 1px;
}

.help-modal .rule-del-btn svg {
  width: 16px;
  height: 16px;
  display: block;
  stroke: currentColor;
  fill: none;
  stroke-width: 2.4;
  stroke-linecap: round;
}

.help-modal p {
  margin: 0 0 10px;
  padding: 10px 12px;
  border: 1px solid #5a4da8;
  border-radius: 10px;
  background: #000000;
  line-height: 1.4;
}

.help-modal p:last-child {
  margin-bottom: 0;
}

.help-modal p strong {
  display: block;
  position: relative;
  margin: -10px -12px 8px;
  padding: 8px 12px;
  color: #f2d86b;
}

.help-modal p strong::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 0;
  border-bottom: 1px solid #5a4da8;
}

.help-modal p > br {
  display: none;
}

.help-modal a {
  color: var(--accent);
}

.help-action-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.55em;
  height: 1.35em;
  padding: 0 0.36em;
  border-radius: 7px;
  border: 1px solid var(--button-border);
  background: linear-gradient(180deg, var(--button-top), var(--button-bottom));
  color: #f7f7ff;
  box-shadow: 0 3px 8px var(--button-shadow);
  font-family: "Roboto Mono", "Fira Code", monospace;
  font-size: 0.9em;
  font-weight: 700;
  line-height: 1;
  vertical-align: baseline;
}

.help-action-chip-row {
  border-color: var(--button-border);
  background: linear-gradient(180deg, var(--button-top), var(--button-bottom));
  color: #f7f7ff;
}

.help-modal a:hover,
.help-modal a:focus-visible {
  opacity: 0.8;
}

.modal-status {
  margin: 0;
  color: var(--muted);
  text-align: center;
  font-size: 1.1rem;
  font-weight: 700;
}

.parse-tree-frame {
  flex: 1;
  min-height: 0;
  padding: 0 6px;
  border-radius: 12px;
  background: #000000;
  overflow: auto;
}

.parse-tree-frame svg {
  display: block;
  width: 100%;
  height: 100%;
  min-width: 100%;
  background: #000000;
  -webkit-user-select: none;
  user-select: none;
}

.parse-tree-frame svg * {
  -webkit-user-select: none;
  user-select: none;
}

.parse-tree-edge {
  fill: none;
  stroke: rgba(201, 195, 238, 0.52);
  stroke-width: 2.5;
}

.parse-tree-node rect {
  stroke-width: 1.5;
}

.parse-tree-node text {
  fill: #ffffff;
  font-size: 15px;
  font-weight: 700;
  pointer-events: none;
}

.parse-tree-nonterminal rect {
  fill: #000000;
  stroke: #39ff7a;
}

.parse-tree-terminal rect {
  fill: #000000;
  stroke: #ff4df3;
}

.parse-tree-epsilon rect {
  fill: #000000;
  stroke: #b8a0e8;
}

.parse-tree-root rect {
  stroke: #00ff00;
  stroke-width: 2;
}
