:root { color-scheme: light; }
.header-actions { display: flex; align-items: center; flex-wrap: wrap; justify-content: flex-end; gap: 6px 14px; }
.theme-button { font-size: 12px; font-weight: 600; background: #f4f8f3; border-color: #a4bba8; white-space: nowrap; }

:root[data-theme="dark"] {
  color-scheme: dark;
  color: #dce5df;
  background: #0e1711;
  --accent: #39744d;
  --accent-hover: #407b53;
  --pastel: #1e3023;
  --panel: #1c2a20;
  --line: #35483b;
  --muted: #acbcb0;
  --dark-surface: #15221a;
  --dark-border: #46614e;
  --dark-hover: #2b4132;
  --dark-link: #a6d7b1;
  --dark-error: #ff9b9b;
  --graph-canvas: #14251b;
}

:root[data-theme="dark"] button { background: #223327; border-color: var(--dark-border); }
:root[data-theme="dark"] button:hover { background: var(--dark-hover); border-color: #7c9a84; }
:root[data-theme="dark"] button:disabled { background: #1e2b21; border-color: var(--line); color: #92a497; }
:root[data-theme="dark"] select,
:root[data-theme="dark"] input:not([type=checkbox]),
:root[data-theme="dark"] textarea:not(#code),
:root[data-theme="dark"] #file-name-input,
:root[data-theme="dark"] #graph-action-search,
:root[data-theme="dark"] #graph-tool-fields input,
:root[data-theme="dark"] #graph-tool-fields textarea { background: #122017; border-color: #59735f; color: #dce5df; }
:root[data-theme="dark"] input::placeholder,
:root[data-theme="dark"] textarea::placeholder { color: #a1b3a6; opacity: 1; }
:root[data-theme="dark"] a { color: var(--dark-link); }
:root[data-theme="dark"] :is(button, select, input, [tabindex], a):focus-visible { outline-color: var(--dark-link); }
:root[data-theme="dark"] .project-header { border-bottom-color: var(--line); }
:root[data-theme="dark"] .project-name { color: #d3ebd9; }
:root[data-theme="dark"] .about-button { color: #c2d7c8; background: transparent; border-color: transparent; }
:root[data-theme="dark"] .about-button:hover { background: var(--dark-hover); border-color: transparent; }
:root[data-theme="dark"] .toolbar { background: var(--dark-surface); }
:root[data-theme="dark"] .file-actions button { background: transparent; border-color: transparent; }
:root[data-theme="dark"] .file-actions button:hover { background: var(--dark-hover); border-color: var(--dark-border); }
:root[data-theme="dark"] .run-actions label { color: #c2d2c6; }
:root[data-theme="dark"] .compile-button,
:root[data-theme="dark"] .graph-history button { color: #fff; background: var(--accent); border-color: var(--accent); }
:root[data-theme="dark"] .compile-button:hover,
:root[data-theme="dark"] .graph-history button:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
:root[data-theme="dark"] .compile-button:disabled,
:root[data-theme="dark"] .graph-history button:disabled { color: #b4c7b9; background: #243e2b; border-color: #43634b; }
:root[data-theme="dark"] #engine-status.error,
:root[data-theme="dark"] #rename-error,
:root[data-theme="dark"] #output-summary.error,
:root[data-theme="dark"] .error-detail { color: var(--dark-error); }

:root[data-theme="dark"] .editor-panel,
:root[data-theme="dark"] .output-panel { background: #111c15; }
:root[data-theme="dark"] .file-bar { background: #1b2e21; }
:root[data-theme="dark"] #modified-indicator { color: #aad4b1; }
:root[data-theme="dark"] #syntax { color: #e0e8e2; }
:root[data-theme="dark"] #code { caret-color: #e0eee3; }
:root[data-theme="dark"] #code::selection { background: #86bc9a60; color: transparent; }
:root[data-theme="dark"] .line-number { color: #98ac9d; }
:root[data-theme="dark"] .active-line { background: #203627; box-shadow: -5px 0 #203627; }
:root[data-theme="dark"] .problem-line { background: #3e2429; }
:root[data-theme="dark"] .token-keyword { color: #d5a4ef; }
:root[data-theme="dark"] .token-tactic { color: #91bdf1; }
:root[data-theme="dark"] .token-comment { color: #9caf96; }
:root[data-theme="dark"] .token-hole { color: #ffaaaa; background: #48272c; }
:root[data-theme="dark"] .token-type { color: #e8c37f; }
:root[data-theme="dark"] .token-string { color: #a5d69e; }
:root[data-theme="dark"] .editor-status,
:root[data-theme="dark"] .graph-statusbar { border-color: var(--line); background: #19281e; }
:root[data-theme="dark"] .output-panel,
:root[data-theme="dark"] .inspector { border-top-color: var(--dark-border); }
:root[data-theme="dark"] .output-entry { background: transparent; }
:root[data-theme="dark"] .output-entry:hover { background: #213628; }
:root[data-theme="dark"] .output-entry.error { border-color: #eb8585; color: var(--dark-error); }
:root[data-theme="dark"] .output-entry.warning { border-color: #c49e5c; color: #edc17b; }
:root[data-theme="dark"] .output-entry.info { border-color: #7198bd; color: #a7cdf2; }
:root[data-theme="dark"] .output-location { color: var(--muted); }
:root[data-theme="dark"] #resize-handle { background: #293d2e; border-color: #46614e; }
:root[data-theme="dark"] #resize-handle:hover { background: #52735b; }

:root[data-theme="dark"] .graph-panel { background: var(--dark-surface); }
:root[data-theme="dark"] .graph-legend { background: #17291d; border-color: var(--line); }
:root[data-theme="dark"] .legend-heading,
:root[data-theme="dark"] #legend-items li { color: #c1d0c5; }
:root[data-theme="dark"] .graph-edit-hint { border-color: var(--line); }
/* Node fills, outlines and text keep their light-mode colors. */
:root[data-theme="dark"] .graph-container { background: var(--graph-canvas); color: #dce5df; color-scheme: dark; }
:root[data-theme="dark"] #graph-stage > svg > g.graph > polygon { fill: var(--graph-canvas); }
:root[data-theme="dark"] .empty-state { color: var(--muted); }
/* Keep connections and labels readable on the dark canvas in both renderers. */
:root[data-theme="dark"] #graph-stage :is(g.edge, marker.drag-arrow) { --edge-color: #afc2b2; }
:root[data-theme="dark"] #graph-stage :is(g.edge, marker.drag-arrow)[data-edge-kind="case_of"] { --edge-color: #e5ab7a; }
:root[data-theme="dark"] #graph-stage :is(g.edge, marker.drag-arrow)[data-edge-kind="introduces"] { --edge-color: #8ab9e6; }
:root[data-theme="dark"] #graph-stage :is(g.edge, marker.drag-arrow)[data-edge-kind="closes"] { --edge-color: #8bc9a0; }
:root[data-theme="dark"] #graph-stage :is(g.edge, marker.drag-arrow)[data-edge-kind="annotates"] { --edge-color: #a3b59e; }
:root[data-theme="dark"] #graph-stage g.edge:is(:hover, :focus-visible) { --edge-color: #c3eacb; }
:root[data-theme="dark"] #graph-stage g.edge path:not(.edge-hit),
:root[data-theme="dark"] #graph-stage g.edge polyline { stroke: var(--edge-color); }
:root[data-theme="dark"] #graph-stage g.edge polygon { fill: var(--edge-color); stroke: var(--edge-color); }
:root[data-theme="dark"] #graph-stage g.edge text { fill: var(--edge-color); }
:root[data-theme="dark"] #graph-stage marker.drag-arrow path { fill: var(--edge-color); stroke: var(--edge-color); }
:root[data-theme="dark"] #graph-stage #basic_arrow path { fill: #afc2b2; }
:root[data-theme="dark"] .zoom-controls button { background: transparent; border-color: transparent; }
:root[data-theme="dark"] .zoom-controls button:hover { background: var(--dark-hover); border-color: var(--dark-border); }
:root[data-theme="dark"] .inspector-bar [role=tab] { color: #b2c5b7; background: transparent; border-color: transparent; }
:root[data-theme="dark"] .inspector-bar [aria-selected=true] { color: #c3eacb; border-bottom-color: #94b99b; }
:root[data-theme="dark"] .state-code { border-left-color: var(--dark-border); }

:root[data-theme="dark"] #about-dialog { color: #dce5df; background: var(--dark-surface); border-color: #6e8c75; }
:root[data-theme="dark"] #about-dialog::backdrop { background: rgb(4 10 6 / 65%); }
:root[data-theme="dark"] .about-header { border-color: var(--line); }
:root[data-theme="dark"] .about-content h2 { color: #bce0c4; }
:root[data-theme="dark"] .about-content code { background: #233529; }
:root[data-theme="dark"] .about-content kbd { background: #233529; border-color: #66836c; }
:root[data-theme="dark"] #notice { background: #223628; border-color: #78977d; }

/* Graph tools use raised dark green surfaces above the graph canvas. */
:root[data-theme="dark"] .graph-tools,
:root[data-theme="dark"] .graph-draft-card,
:root[data-theme="dark"] #graph-mode-bar { color: #dce5df; color-scheme: dark; background: #1a2b20; border-color: #78977d; box-shadow: 0 6px 24px rgb(0 0 0 / 25%); }
:root[data-theme="dark"] .graph-tools-header { background: #263f2e; border-color: var(--dark-border); }
:root[data-theme="dark"] .graph-tools-header button,
:root[data-theme="dark"] .graph-draft-card header button { background: transparent; border-color: transparent; }
:root[data-theme="dark"] .graph-tools-header button:hover,
:root[data-theme="dark"] .graph-draft-card header button:hover { background: var(--dark-hover); }
:root[data-theme="dark"] #graph-tools-goal { background: #15241a; border-color: var(--line); }
:root[data-theme="dark"] .graph-action { color: #dce5df; background: transparent; }
:root[data-theme="dark"] .graph-action:hover,
:root[data-theme="dark"] .graph-action:focus-visible { background: #2b4733; border-color: transparent; }
:root[data-theme="dark"] .graph-action span,
:root[data-theme="dark"] .graph-action-heading,
:root[data-theme="dark"] #graph-tool-preview,
:root[data-theme="dark"] .graph-draft-card p { color: #b3c7b8; }
:root[data-theme="dark"] #graph-tool-code { color: #dce5df; background: #14251a; }
:root[data-theme="dark"] #graph-tools-error { color: var(--dark-error); }
:root[data-theme="dark"] .graph-draft-card header { color: #b8dbbf; }

@media (max-width: 720px) { .header-actions { gap: 6px 12px; } .theme-button { padding: 3px 8px; font-size: 11px; } }
