:root {
  color-scheme: dark;
  --page: #282828;
  --ink: #ebdbb2;
  --muted: #a89984;
  --line: #504945;
  --accent: #fabd2f;
  --green: #b8bb26;
  --chord: #fe8019;
  font-family: ui-monospace, "DejaVu Sans Mono", monospace;
  font-size: 13px;
  line-height: 1.6;
}

* { box-sizing: border-box; scrollbar-color: #665c54 var(--page); scrollbar-width: thin; }
body { margin: 0; background: var(--page); color: var(--ink); }
.shell { width: min(1120px, calc(100% - 48px)); margin-inline: auto; }
a { color: var(--muted); text-underline-offset: 4px; }
a:hover { color: var(--accent); }
::selection { background: #665c54; color: var(--ink); }
h1, h2, h3, h4, p { margin: 0; }
h1 { font-size: 20px; font-weight: 600; }
h2 { font-size: 15px; font-weight: 600; }
h3 { font-size: 13px; font-weight: 600; }
h4 { font-size: 12px; color: var(--muted); font-weight: 400; margin-top: 16px; }
button, textarea { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line);
  border-radius: 2px;
  background: transparent;
  padding: 5px 10px;
  cursor: pointer;
}
button:hover { border-color: var(--muted); background: #32302f; }
button.primary { border-color: #928374; }
button:disabled { opacity: .5; cursor: wait; }
button:focus-visible, a:focus-visible, summary:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
.subtext, .muted { color: var(--muted); font-size: 12px; }
.hidden { display: none !important; }

.topbar { display: flex; align-items: center; gap: 32px; padding-block: 22px; border-bottom: 1px solid var(--line); }
.topbar nav { display: flex; flex-wrap: wrap; gap: 18px; }
.report-action { margin-left: auto; text-align: right; max-width: 360px; }
.report-action .actions { justify-content: flex-end; }
#pdfStatus:not(:empty) { display: block; margin-top: 4px; font-size: 11px; color: var(--muted); }
.workspace { display: grid; grid-template-columns: minmax(260px, 1fr) minmax(0, 1.7fr); gap: 32px; padding-block: 26px; }
.input-panel .subtext { margin-top: 6px; }
textarea {
  display: block;
  width: 100%;
  height: 254px;
  min-height: 160px;
  margin-block: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: #1d2021;
  resize: vertical;
  line-height: 1.7;
}
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.shortcut { font-size: 11px; }
.section-heading, .detail-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.graph-panel { min-width: 0; }
.graph-panel > .subtext { margin-top: 6px; }
.graph-modes { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.mode { font-size: 11px; padding: 3px 7px; }
.mode.active { color: var(--accent); border-color: #928374; }
.graph-surface { height: 275px; }
.graph-surface svg { display: block; width: 100%; height: 100%; touch-action: none; user-select: none; }
.graph-bottom { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; font-size: 10px; color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.stroke { display: inline-block; width: 15px; border-top: 2px solid var(--muted); }
.stroke.chord { border-color: var(--chord); border-top-style: dashed; }
.stroke.selected { border-color: var(--green); }

.stats { display: flex; flex-wrap: wrap; gap: 14px 36px; margin: 0; padding-block: 14px; border-block: 1px solid var(--line); }
.stats > div { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.stats dt { color: var(--muted); font-size: 12px; }
.stats dd { margin: 0; overflow-wrap: anywhere; }
.result-section { padding-block: 24px; border-bottom: 1px solid var(--line); }
.section-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; margin-top: 14px; }
.edge-list { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 8px; }
.edge-pill { font-size: 12px; }
.edge-pill.chord { color: var(--chord); }
.code-formula { color: var(--muted); font-size: 12px; margin-top: 10px; }

.cycle-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 32px; margin-top: 14px; }
.cycle-list { max-height: 340px; overflow: auto; }
.cycle-card {
  display: flex;
  width: 100%;
  align-items: baseline;
  text-align: left;
  gap: 12px;
  padding: 8px;
  border: 0;
  border-left: 2px solid transparent;
  border-radius: 0;
}
.cycle-card.active { border-left-color: var(--green); background: #32302f; }
.cycle-index { flex: 0 0 36px; color: var(--muted); }
.cycle-card.active .cycle-index { color: var(--green); }
.cycle-main { min-width: 0; }
.cycle-main strong { display: block; font-weight: 400; overflow-wrap: anywhere; }
.cycle-main small { display: block; color: var(--muted); font-size: 10px; }
.selection-panel { min-width: 0; }
.selection-equation { margin-block: 8px; overflow-wrap: anywhere; }
.state-line { color: var(--green); font-size: 12px; }
.state-line.other { color: var(--accent); }
.selection-panel .subtext { margin-top: 8px; }
.route { margin-top: 4px; overflow-wrap: anywhere; }
.limit-message { color: var(--accent); margin-top: 12px; font-size: 12px; }

#matrixCaption { margin-block: 10px; }
.matrix-scroll { max-height: 440px; overflow: auto; border: 1px solid var(--line); }
.matrix { width: 100%; border-collapse: separate; border-spacing: 0; text-align: center; font-size: 12px; }
.matrix th, .matrix td { min-width: 48px; padding: 6px 10px; border-right: 1px solid #3c3836; border-bottom: 1px solid #3c3836; white-space: nowrap; }
.matrix th { font-weight: 400; }
.matrix thead th { position: sticky; top: 0; z-index: 2; background: #32302f; }
.matrix th:first-child { position: sticky; left: 0; z-index: 1; background: var(--page); }
.matrix thead th:first-child { z-index: 3; background: #32302f; }
.matrix tr > :last-child { border-right: 0; }
.matrix tbody tr:last-child > * { border-bottom: 0; }
.matrix tbody tr { cursor: pointer; }
.matrix tbody tr:hover > *, .matrix tbody tr.active > * { background: #3c3836; }
.matrix .zero { color: #928374; }
.matrix .chord-head, .matrix .chordcell { color: var(--chord); }
.matrix tbody tr.active .one { color: var(--green); }
.matrix tbody tr:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.matrix-footer { display: flex; justify-content: space-between; gap: 12px; margin-top: 8px; font-size: 11px; color: var(--muted); }
.math-note { padding-block: 18px 28px; color: var(--muted); font-size: 12px; }
.math-note summary { width: fit-content; cursor: pointer; }
.math-note p { max-width: 86ch; margin-top: 10px; }
.error { display: none; margin-top: 12px; color: #fb4934; overflow-wrap: anywhere; }
.error.show { display: block; }
.toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); max-width: calc(100% - 32px); border: 1px solid var(--line); background: var(--page); padding: 8px 12px; font-size: 12px; opacity: 0; pointer-events: none; }
.toast.show { opacity: 1; }

@media (max-width: 760px) {
  .shell { width: calc(100% - 32px); }
  .topbar { gap: 12px 24px; flex-wrap: wrap; padding-block: 16px; }
  .topbar nav { order: 3; width: 100%; gap: 20px; }
  .workspace, .section-grid, .cycle-grid { grid-template-columns: 1fr; gap: 24px; }
  .workspace { padding-block: 20px; }
  textarea { height: 200px; }
  .graph-surface { height: 270px; }
  .stats { gap: 8px 24px; }
  .result-section > .section-heading { flex-wrap: wrap; }
  .matrix-footer { flex-wrap: wrap; }
}

.excluded .cycle-index,.matrix tr.excluded th,.matrix tr.excluded td {text-decoration:line-through;text-decoration-thickness:2px;text-decoration-color:#fb4934}
.excluded {opacity:.8}
#forestChoices {margin-bottom:12px}
#forestChoices label {cursor:pointer;gap:6px}
#contourSvg {width:100%;max-height:230px}
.matrix tbody th {min-width:210px;white-space:normal}
