/* Shared by the Astro playground page and the e2e harness.

   Starlight layout overrides apply only on the playground page: they are
   scoped with :has(#split), and #split exists only there. */

/* Constrain page height so the split pane fills without overflowing */
html:has(#split) .page {
  height: 100vh;
  overflow: hidden;
}

/* Full window: the playground covers the site header and sidebar. */
html.nfm-full {
  overflow: hidden;
}
html.nfm-full .header,
html.nfm-full .sidebar-pane,
html.nfm-full starlight-menu-button {
  display: none;
}
html.nfm-full .nfm-playground {
  position: fixed;
  inset: 0;
  z-index: 100;
}
html.nfm-full .CodeMirror-hints {
  z-index: 101;
}

/* Hide the site footer; the playground is a full-height interactive tool */
html:has(#split) .nfm-site-footer {
  display: none;
}

/* Hide the auto-generated page <h1>; the playground has no prose title */
html:has(#split) h1#_top {
  display: none;
}

/* Hide Starlight's in-content footer (pagination / edit link / built-with);
   the playground is a full-height tool, so it would only strand a gap. */
html:has(#split) .content-panel footer {
  display: none;
}

/* Expand .main-frame into a flex column so .nfm-playground can fill it */
html:has(#split) .main-frame {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/*
  Grow exactly the wrapper chain that contains #split into a flex column.
  :has(#split) matches only that branch, so the Starlight-injected <script>
  sibling and the page-title panel (neither contains #split) keep their
  natural size instead of each claiming flex:1 and halving the column. It
  also excludes #split itself, so the editor/preview panes keep their own
  side-by-side row layout.
*/
html:has(#split) .main-frame *:has(#split) {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* The playground supplies no prose title; drop Starlight's empty title panel. */
html:has(#split) main > .content-panel:not(:has(#split)) {
  display: none;
}

/* Starlight spaces each prose block from the one before; the stylesheet link
   precedes the playground, so that gap would push it down. */
html:has(#split) .nfm-playground {
  margin-top: 0;
}

/* Strip content padding/max-width so .nfm-playground spans the full area */
html:has(#split) .content-panel {
  padding: 0 !important;
}
html:has(#split) main:has(#split) {
  padding-bottom: 0;
}
html:has(#split) .sl-container {
  max-width: unset !important;
  padding: 0 !important;
  margin: 0 !important;
}
html:has(#split) .sl-markdown-content {
  overflow: hidden;
}

/*
  #split is a CSS grid whose single implicit row is `auto`, so the tall
  preview render would stretch the row (and the editor pane / CodeMirror)
  to its content height. Pinning the row to minmax(0, 1fr) keeps it bounded
  by the viewport-filled column; each pane scrolls its own overflow instead.
*/
html:has(#split) #split {
  grid-template-rows: minmax(0, 1fr);
}

/*
  CodeMirror is a flex:1 child of the editor pane. Its default min-height:auto
  refuses to shrink below the intrinsic content height, so inside Starlight's
  nested flex/grid chain the wrapper overflows the pane instead of scrolling.
  min-height:0 lets it fill the pane and scroll its own overflow.
*/
.nfm-playground .CodeMirror,
.nfm-playground .CodeMirror-scroll {
  min-height: 0;
}

/* Element selectors (button, select, input) and utility classes (.hidden,
   .muted, .small) are scoped to .nfm-playground so they never restyle
   Starlight's own chrome. */

/* Custom properties and flex fill */
.nfm-playground {
  color-scheme: dark;
  --pg-bg: #0b1320;
  --pg-panel: #111b2a;
  --pg-panel-2: #172437;
  --pg-border: #2a394d;
  --pg-control-border: #66778f;
  --pg-text: #e5ebf2;
  --pg-muted: #8e9bae;
  --pg-accent: #19b7a5;
  --pg-accent-text: #19b7a5;
  --pg-accent-press: #129887;
  --pg-danger: #d95d57;
  --pg-danger-bg: #2a1414;

  /* Expose the short names used throughout app.js-generated HTML */
  --bg: var(--pg-bg);
  --panel: var(--pg-panel);
  --panel-2: var(--pg-panel-2);
  --border: var(--pg-border);
  /* Form-field outlines, kept at 3:1 or more against the panels (WCAG 1.4.11). */
  --control-border: var(--pg-control-border);
  --text: var(--pg-text);
  --muted: var(--pg-muted);
  --accent: var(--pg-accent);
  /* Accent for text, at 4.5:1 or more against the panels (WCAG 1.4.3). */
  --accent-text: var(--pg-accent-text);
  --accent-press: var(--pg-accent-press);
  --danger: var(--pg-danger);
  --danger-bg: var(--pg-danger-bg);

  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font:
    14px/1.45 -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    Helvetica,
    Arial,
    sans-serif;
}

/*
  Follow Starlight's theme toggle, which sets data-theme on <html>. Only the
  --pg-* values change; color-scheme also drives the inlined preview SVG's
  light-dark() chrome, so the rendered map tracks the toggle with no re-render.
*/
:root[data-theme="light"] .nfm-playground {
  color-scheme: light;
  --pg-bg: #f7f9fc;
  --pg-panel: #ffffff;
  --pg-panel-2: #edf2f7;
  --pg-border: #dbe2ea;
  --pg-control-border: #7b8794;
  --pg-text: #172234;
  --pg-muted: #5c6879;
  --pg-accent: #0b8f82;
  --pg-accent-text: #097a6f;
  --pg-accent-press: #0f766e;
  --pg-danger: #b84742;
  --pg-danger-bg: #fdeaea;
}

.nfm-playground * {
  box-sizing: border-box;
}

.pane-toolbar {
  display: flex;
  align-items: center;
  gap: 8px 12px;
  flex-wrap: wrap;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  min-height: 41px;
}
.pane-toolbar label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
.pane-toolbar label.check {
  gap: 5px;
}

.advanced {
  border-bottom: 1px solid var(--border);
}
.advanced > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  padding: 7px 12px;
  font-size: 12px;
  color: var(--muted);
  background: var(--panel);
  display: flex;
  align-items: center;
  gap: 6px;
}
.advanced > summary::-webkit-details-marker {
  display: none;
}
.advanced > summary::before {
  content: "▸";
  font-size: 10px;
  transition: transform 0.12s ease;
}
.advanced[open] > summary::before {
  transform: rotate(90deg);
}
.advanced > summary:hover {
  color: var(--text);
}
.advanced .advanced-controls {
  border-bottom: none;
}

.swatches {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.swatch {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--muted);
}
.swatch input[type="color"] {
  width: 20px;
  height: 20px;
  padding: 0;
  border: 1px solid var(--control-border);
  border-radius: 4px;
  background: none;
  cursor: pointer;
}
.swatch input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 2px;
}
.swatch input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 2px;
}
.theme-hint {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  color: var(--muted);
  font-size: 11px;
}
.theme-hint.hidden {
  display: none;
}
.swatch-item {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}
.group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.swatch-reset {
  padding: 0 4px;
  font-size: 11px;
  line-height: 1.4;
}
.swatches:empty::after {
  content: "none defined";
  color: var(--muted);
  font-size: 11px;
  font-style: italic;
}

.group-label {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}
.sep {
  width: 1px;
  align-self: stretch;
  background: var(--border);
  margin: 2px 4px;
}

/* Scope general element styles to the playground wrapper */
.nfm-playground select,
.nfm-playground input[type="number"] {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--control-border);
  border-radius: 6px;
  padding: 4px 6px;
  font: inherit;
  font-size: 12px;
}
.nfm-playground input[type="number"] {
  width: 68px;
}
.nfm-playground input[type="checkbox"] {
  accent-color: var(--accent);
}
.nfm-playground button {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.nfm-playground button:hover {
  border-color: var(--accent);
}
.nfm-playground button:active {
  background: var(--accent-press);
  border-color: var(--accent-press);
  color: #02120f;
}
.nfm-playground button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

#split {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(280px, 38%) 1fr;
  min-height: 0;
}

#editor-pane,
#preview-pane {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
#editor-pane {
  border-right: 1px solid var(--border);
}

/* CodeMirror theme */
.nfm-playground .CodeMirror {
  flex: 1;
  height: auto;
  font-family: "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
}
.nfm-playground .CodeMirror-gutters {
  background: var(--panel);
  border-right: 1px solid var(--border);
}
.nfm-playground .CodeMirror-linenumber {
  color: var(--muted);
}
.nfm-playground .CodeMirror-cursor {
  border-left: 2px solid var(--text);
}
.nfm-playground .CodeMirror-focused .CodeMirror-cursor {
  border-left: 2px solid var(--accent);
}
.nfm-playground .CodeMirror-selected {
  background: #2a3344 !important;
}
.nfm-playground .CodeMirror-focused .CodeMirror-selected {
  background: #31507a !important;
}
:root[data-theme="light"] .nfm-playground .CodeMirror-selected {
  background: #d5dbe6 !important;
}
:root[data-theme="light"]
  .nfm-playground
  .CodeMirror-focused
  .CodeMirror-selected {
  background: #b9cdf0 !important;
}
.nfm-playground .CodeMirror-line::selection,
.nfm-playground .CodeMirror-line > span::selection {
  background: #31507a;
}
/* Read-only: the edits line a save writes, after the blank line it leaves. */
.nfm-playground .nfm-edits-line {
  padding: 0 4px;
  margin-top: 1lh;
  white-space: pre;
  color: var(--muted);
  font-style: italic;
  cursor: default;
}
/* Token colours match the docs' code blocks (Night Owl / Starlight light). */
.nfm-playground .cm-s-default .cm-comment {
  color: light-dark(#5f636f, #919f9f);
}
.nfm-playground .cm-metro-directive,
.nfm-playground .cm-metro-keyword {
  color: light-dark(#8844ae, #c792ea);
}
.nfm-playground .cm-metro-property {
  color: light-dark(#096e72, #80cbc4);
}
.nfm-playground .cm-metro-constant {
  color: light-dark(#3b61b0, #82aaff);
}
.nfm-playground .cm-metro-hex {
  color: light-dark(#aa0982, #ffeb95);
}
.nfm-playground .cm-metro-number {
  color: light-dark(#aa0982, #f78c6c);
}
.nfm-playground .cm-metro-arrow {
  color: light-dark(#096e72, #7fdbca);
}
.nfm-playground .cm-metro-edgelabel {
  color: light-dark(#3b61b0, #ecc48d);
}
.nfm-playground .cm-metro-nodelabel {
  color: light-dark(#984e4d, #ecc48d);
}

#error {
  background: var(--danger-bg);
  color: var(--danger);
  border-top: 1px solid var(--danger);
  padding: 8px 12px;
  font-family: "SF Mono", Menlo, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  max-height: 30%;
  overflow: auto;
}

#preview-pane {
  background: var(--bg);
}
#preview {
  flex: 1;
  overflow: auto;
  padding: 18px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}
/* When zoomed past the viewport, left-align so the start stays scrollable. */
#preview.zoomed {
  justify-content: flex-start;
}
/* flex-shrink:0 so an explicit zoom width isn't shrunk back to the container. */
#preview svg {
  max-width: 100%;
  height: auto;
  flex-shrink: 0;
}
/* Dim the preview while the Python renderer is running. */
#preview.rendering {
  opacity: 0.45;
  cursor: wait;
}

/* Bottom left, clear of the selection panel, which docks bottom right. */
#zoom-controls {
  position: absolute;
  left: 16px;
  bottom: 16px;
  display: flex;
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  z-index: 5;
}
#zoom-controls button {
  border: none;
  border-radius: 0;
  background: var(--panel-2);
  color: var(--text);
  min-width: 34px;
  height: 30px;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}
#zoom-controls button#zoom-fit {
  font-size: 12px;
}
#zoom-controls button:hover {
  background: var(--accent-press);
  color: #02120f;
}

.overlay {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
  padding: 24px;
}
.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: nfm-playground-spin 0.8s linear infinite;
}
@keyframes nfm-playground-spin {
  to {
    transform: rotate(360deg);
  }
}

/* Utility classes scoped to playground so they don't leak into Starlight */
.nfm-playground .muted {
  color: var(--muted);
}
.nfm-playground .small {
  font-size: 12px;
}
.nfm-playground .hidden {
  display: none !important;
}

#toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  z-index: 20;
  transition: opacity 0.15s ease;
}
/* Hidden visually only: the live region stays in the accessibility tree so
   the next message is announced. */
#toast.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.toolbar-right {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px 12px;
}
.report-btn {
  color: var(--muted) !important;
}
.report-btn:hover {
  color: var(--text) !important;
  border-color: var(--muted) !important;
  background: var(--panel) !important;
}

.build-hint {
  font-family: "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  text-decoration: none;
  opacity: 0.5;
}
.build-hint:hover {
  opacity: 1;
  text-decoration: underline;
}

/* Native modal dialogs: the inner .modal draws the box, so a click on the
   dialog element itself is a click on the backdrop. */
.modal-dialog {
  margin: auto;
  width: min(560px, calc(100% - 48px));
  max-width: none;
  max-height: calc(100% - 48px);
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  overflow: visible;
}
.modal-dialog::backdrop {
  background: rgba(4, 6, 10, 0.66);
}
#welcome-modal {
  width: min(720px, calc(100% - 48px));
}
#command-modal {
  width: min(520px, calc(100% - 48px));
}
.nfm-playground .modal {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 22px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}
.nfm-playground .modal h2 {
  margin: 0 0 8px;
  font-size: 17px;
}
.nfm-playground .modal p {
  margin: 0 0 14px;
}
.nfm-playground .modal label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--text);
}
.nfm-playground .modal label .req {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--danger);
}
.nfm-playground .modal textarea {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--control-border);
  border-radius: 8px;
  padding: 10px;
  font: inherit;
  font-size: 13px;
  resize: vertical;
}
.nfm-playground .modal textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}
.modal-actions button.ghost {
  color: var(--muted);
}
.nfm-playground .modal a {
  color: var(--accent-text);
}
.nfm-playground .modal code {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 12px;
}
.modal-error {
  margin-top: 12px;
  color: var(--danger);
  background: var(--danger-bg);
  border: 1px solid var(--danger);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  white-space: pre-wrap;
}

.nfm-playground .modal input[type="file"] {
  width: 100%;
  color: var(--text);
  font-size: 12px;
}
.logo-preview {
  display: block;
  margin-top: 12px;
  max-width: 100%;
  max-height: 120px;
  background: repeating-conic-gradient(#80808033 0% 25%, transparent 0% 50%)
    50% / 16px 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.mode-btn[aria-pressed="true"] {
  background: var(--accent) !important;
  border-color: var(--accent) !important;
  color: #02120f !important;
}
.mode-btn[aria-pressed="true"]:hover {
  border-color: var(--accent) !important;
}

/* Hit-target affordance while a build mode is active */
#preview.mode-add-station [data-section-id],
#preview.mode-add-edge [data-station-id] {
  cursor: crosshair;
}
#preview.mode-add-station svg,
#preview.mode-add-edge svg {
  cursor: default;
}

/* Connect-source highlight */
#preview .nfm-edge-src {
  outline: 2px dashed #ffcb6b;
  outline-offset: 3px;
}

.prop-panel {
  position: absolute;
  right: 16px;
  bottom: 16px;
  width: 248px;
  max-height: calc(100% - 110px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.45);
  padding: 12px 14px;
  z-index: 15;
}
.prop-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.prop-kind {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--accent-text);
}
.prop-head button.ghost {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  padding: 0 4px;
}
.prop-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}
.prop-row label {
  font-size: 11px;
  color: var(--muted);
}
.prop-row input[type="text"] {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--control-border);
  border-radius: 6px;
  padding: 5px 7px;
  font: inherit;
  font-size: 12px;
}
.prop-row input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}
.prop-grid {
  display: flex;
  gap: 8px;
}
.prop-grid input[type="number"] {
  width: 100%;
}
.prop-edges {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.prop-edge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
}
.prop-edge .ends {
  flex: 1;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.prop-edge select {
  flex: 0 0 auto;
}
.prop-edge button.add {
  padding: 2px 7px;
}
.prop-edge button.del {
  color: var(--danger);
  border-color: var(--danger);
  padding: 2px 7px;
}
.prop-empty {
  color: var(--muted);
  font-style: italic;
  font-size: 12px;
}
.prop-delete {
  width: 100%;
  margin-top: 4px;
  color: var(--danger);
  border-color: var(--danger);
}
.prop-delete:hover {
  background: var(--danger-bg);
  border-color: var(--danger);
}
.prop-action {
  width: 100%;
  margin-top: 4px;
}

.line-picker {
  position: fixed;
  inset: auto;
  margin: 0;
  color: var(--text);
  min-width: 140px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.5);
  padding: 6px;
}
.line-picker .picker-title {
  font-size: 11px;
  color: var(--muted);
  padding: 2px 6px 6px;
}
.line-picker button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: none;
  background: none;
  text-align: left;
  padding: 5px 6px;
  border-radius: 6px;
}
.line-picker button:hover {
  background: var(--panel-2);
}
.line-picker .dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex: 0 0 auto;
  border: 1px solid var(--border);
}

/* Playground information architecture */
.app-command-bar {
  min-height: 54px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: 7px 12px;
  background: color-mix(in srgb, var(--panel) 92%, var(--accent));
  border-bottom: 1px solid var(--border);
}
.route-strip {
  display: flex;
  align-items: center;
  min-width: 262px;
}
.route-stop {
  position: relative;
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-family: "Degular", "Arial Narrow", sans-serif;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.route-stop:not(:last-child)::after {
  content: "";
  width: 42px;
  height: 3px;
  margin: 0 7px;
  border-radius: 3px;
  background: var(--border);
}
.route-dot {
  width: 11px;
  height: 11px;
  border: 2px solid var(--muted);
  border-radius: 50%;
  background: var(--panel);
}
.route-stop.complete,
.route-stop.active {
  color: var(--text);
}
.route-stop.complete .route-dot {
  border-color: #19b7a5;
  background: #19b7a5;
  box-shadow: 0 0 0 3px color-mix(in srgb, #19b7a5 18%, transparent);
}
.route-stop.active .route-dot {
  border-color: #8b6fcf;
  animation: route-pulse 1.2s ease-in-out infinite;
}
.route-stop.warning .route-dot {
  border-color: #d9a441;
  background: #d9a441;
}
.route-stop.error .route-dot {
  border-color: var(--danger);
  background: var(--danger);
}
@keyframes route-pulse {
  50% {
    box-shadow: 0 0 0 5px color-mix(in srgb, #8b6fcf 20%, transparent);
  }
}
.document-actions,
.history-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.document-actions {
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.document-actions::-webkit-scrollbar {
  display: none;
}
.command-sep {
  width: 1px;
  height: 24px;
  flex: 0 0 auto;
  margin: 0 3px;
  background: var(--border);
}
.nfm-playground button.primary {
  border-color: #19b7a5;
  background: #19b7a5;
  color: #061511;
  font-weight: 650;
}
.app-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font:
    11px/1.2 "SF Mono",
    Menlo,
    monospace;
  white-space: nowrap;
}
.mobile-view-switch {
  display: none;
}
.pane-heading {
  min-height: 51px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.pane-heading > div:first-child {
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.pane-heading strong {
  overflow: hidden;
  color: var(--text);
  font:
    600 15px/1.15 "Degular",
    "Arial Narrow",
    sans-serif;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pane-kicker {
  color: var(--accent-text);
  font:
    700 10px/1.1 "SF Mono",
    Menlo,
    monospace;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.history-actions button {
  padding: 3px 7px;
  color: var(--muted);
}
.source-help {
  margin-left: auto;
  color: var(--muted);
  font-size: 11px;
  text-decoration: none;
  white-space: nowrap;
}
.source-help:hover {
  color: var(--accent-text);
}
.menu {
  position: relative;
}
.menu > summary {
  list-style: none;
  cursor: pointer;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-2);
  font-size: 13px;
  white-space: nowrap;
}
.menu > summary::-webkit-details-marker {
  display: none;
}
.menu > summary::after {
  content: " ▾";
  color: var(--muted);
}
.menu[open] > summary {
  border-color: var(--accent);
}
.menu-items {
  position: fixed;
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 200px;
  margin-top: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.35);
}
.nfm-playground .menu-items button {
  text-align: left;
  border: 0;
  background: transparent;
}
.nfm-playground .menu-items button:hover:not(:disabled) {
  background: var(--panel-2);
}
.nfm-playground .map-settings-toggle[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent-text);
}
.edit-hint {
  padding: 0 12px 6px;
}
.toolbar-end {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.nfm-playground .icon-btn {
  min-width: 28px;
  padding: 4px 6px;
}
.nfm-playground .help-btn {
  width: 28px;
  padding: 4px 0;
  border-radius: 50%;
}
.help-body h3 {
  margin: 12px 0 4px;
  color: var(--accent-text);
  font-size: 13px;
}
.help-body ul {
  margin: 0;
  padding-left: 18px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
}
.map-settings {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.settings-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.settings-group h3,
.settings-group > summary {
  margin: 0;
  color: var(--accent-text);
  font:
    700 10px/1.4 "SF Mono",
    Menlo,
    monospace;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: default;
}
.settings-group > summary {
  cursor: pointer;
}
.settings-group label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}
.settings-group label.check {
  justify-content: flex-start;
}
.settings-group input[type="number"],
.settings-group select {
  max-width: 130px;
}
.prop-panel.map-mode {
  width: 280px;
}
.preview-control-rail {
  display: block;
  flex: 0 0 auto;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.preview-control-rail .control-row {
  flex-wrap: wrap;
  min-height: 44px;
  padding-block: 5px;
}
.control-title {
  color: var(--accent-text);
  font:
    700 10px/1 "SF Mono",
    Menlo,
    monospace;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  white-space: nowrap;
}
.control-row {
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 8px 12px;
  flex-wrap: wrap;
  padding: 7px 12px;
}
.control-row label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
.control-row.edit-toolbar {
  border: 0;
}
.free-edit-bar {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.canvas-shell {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background-color: var(--bg);
  background-image: radial-gradient(
    circle,
    color-mix(in srgb, var(--border) 48%, transparent) 0.7px,
    transparent 0.8px
  );
  background-size: 18px 18px;
}
.canvas-shell #preview {
  width: 100%;
  height: 100%;
}
.stale-preview {
  position: absolute;
  top: 10px;
  left: 50%;
  z-index: 8;
  transform: translateX(-50%);
  padding: 4px 9px;
  border: 1px solid #d9a441;
  border-radius: 999px;
  background: var(--panel);
  color: #d9a441;
  font-size: 11px;
}
.drop-invitation {
  position: absolute;
  inset: 14px;
  z-index: 20;
  display: grid;
  place-items: center;
  border: 2px dashed var(--accent);
  border-radius: 12px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  color: var(--text);
  font:
    600 16px "Degular",
    sans-serif;
  pointer-events: none;
}
.status-bar {
  min-height: 29px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 4px 12px;
  border-top: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  font:
    11px/1 "SF Mono",
    Menlo,
    monospace;
}
#render-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--text);
}
.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
}
#render-status[data-state="loading"] .status-dot {
  background: #8b6fcf;
}
#render-status[data-state="ready"] .status-dot {
  background: #19b7a5;
}
#render-status[data-state="warning"] .status-dot {
  background: #d9a441;
}
#render-status[data-state="error"] .status-dot {
  background: var(--danger);
}
.nfm-playground button.status-action {
  margin-left: auto;
  border: 0;
  padding: 2px 4px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
}
#error {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: start;
  gap: 9px;
  max-height: 34%;
}
#error[data-severity="warning"] {
  border-color: #d9a441;
  background: color-mix(in srgb, #d9a441 12%, var(--panel));
  color: #d9a441;
}
#error strong {
  font-family: system-ui, sans-serif;
  white-space: nowrap;
}
#error span {
  min-width: 0;
}
.nfm-playground button.diagnostic-jump {
  border-color: currentColor;
  background: transparent;
  color: inherit;
  white-space: nowrap;
}
.diagnostic-marker {
  display: grid;
  width: 15px;
  height: 15px;
  place-items: center;
  border-radius: 50%;
  background: var(--danger);
  color: white;
  font: 700 10px/1 system-ui;
}
.diagnostic-marker.warning {
  background: #d9a441;
  color: #1a1200;
}
.welcome-modal {
  width: min(720px, 100%);
}
.command-modal {
  width: min(520px, 100%);
  padding: 14px;
}
.command-search-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}
.nfm-playground .command-search {
  width: 100%;
  margin-top: 7px;
  border: 1px solid var(--control-border);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--bg);
  color: var(--text);
  font:
    13px "SF Mono",
    Menlo,
    monospace;
}
.command-list {
  max-height: 310px;
  margin-top: 8px;
  overflow: auto;
}
.nfm-playground .command-item {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  border: 0;
  padding: 8px 10px;
  background: transparent;
  text-align: left;
}
.nfm-playground .command-item.selected {
  background: var(--panel-2);
}
.command-item span {
  color: var(--muted);
  font-size: 11px;
}
.command-hint {
  margin: 8px 2px 0 !important;
  color: var(--muted);
  font:
    10px "SF Mono",
    Menlo,
    monospace;
}
html:has(#split) .CodeMirror-hints {
  z-index: 40;
  border: 1px solid var(--sl-color-gray-5);
  border-radius: 8px;
  background: var(--sl-color-bg-nav);
  color: var(--sl-color-text);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.32);
  font:
    12px "SF Mono",
    Menlo,
    monospace;
}
html:has(#split) .CodeMirror-hint {
  padding: 5px 8px;
}
html:has(#split) li.CodeMirror-hint-active {
  background: var(--sl-color-accent);
  color: white;
}
.modal-kicker {
  color: var(--accent-text);
  font:
    700 10px/1 "SF Mono",
    Menlo,
    monospace;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.start-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}
.nfm-playground .start-option {
  min-height: 142px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 9px;
  padding: 16px;
  text-align: left;
}
.start-option strong {
  font:
    600 17px/1.1 "Degular",
    sans-serif;
}
.start-option span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}
.nfm-playground .start-option.primary-option {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, var(--panel-2));
}
.nfm-playground .welcome-continue {
  display: block;
  margin: 14px auto 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  text-decoration: underline;
}
.nfm-playground button:focus-visible,
.nfm-playground select:focus-visible,
.nfm-playground input:focus-visible,
.nfm-playground textarea:focus-visible,
.nfm-playground summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .route-stop.active .route-dot,
  .spinner {
    animation: none;
  }
}

@media (max-width: 900px) {
  .route-strip {
    min-width: auto;
  }
  .route-stop span:last-child {
    display: none;
  }
  .route-stop:not(:last-child)::after {
    width: 22px;
  }
  .app-meta {
    display: none;
  }
}

@media (max-width: 720px) {
  .app-command-bar {
    min-height: 51px;
    display: flex;
    gap: 10px;
    padding: 6px 8px;
  }
  .route-strip {
    flex: 0 0 auto;
  }
  .route-stop:not(:last-child)::after {
    width: 11px;
    margin-inline: 4px;
  }
  .document-actions {
    flex: 1;
  }
  .document-actions button {
    min-height: 38px;
    white-space: nowrap;
  }
  .document-actions .command-sep {
    display: none;
  }
  .mobile-view-switch {
    min-height: 43px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    padding: 5px;
    border-bottom: 1px solid var(--border);
    background: var(--panel);
  }
  .nfm-playground .mobile-view {
    min-height: 32px;
    border: 0;
    background: transparent;
    color: var(--muted);
  }
  .nfm-playground .mobile-view.active {
    background: var(--panel-2);
    color: var(--accent-text);
  }
  #split {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr);
  }
  #split[data-mobile-view="source"] #preview-pane,
  #split[data-mobile-view="preview"] #editor-pane {
    display: none;
  }
  #editor-pane {
    border-right: 0;
  }
  .pane-heading {
    min-height: 49px;
  }
  .source-toolbar,
  .control-row {
    min-height: 49px;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .source-toolbar::-webkit-scrollbar,
  .control-row::-webkit-scrollbar {
    display: none;
  }
  .start-options {
    grid-template-columns: 1fr;
  }
  .nfm-playground .start-option {
    min-height: 96px;
  }
  .modal-dialog,
  #welcome-modal,
  #command-modal {
    width: calc(100% - 24px);
    max-height: calc(100% - 24px);
  }
  .welcome-modal {
    max-height: calc(100vh - 24px);
    overflow: auto;
  }
  .status-bar {
    padding-inline: 9px;
  }
  #runtime-version {
    display: none;
  }
  #error {
    grid-template-columns: 1fr;
  }
}
/* Free edit and grid-drag overlay, drawn in the map's own SVG units. */
#preview.mode-free-edit [data-route-id] {
  cursor: pointer;
}
#preview .nfm-h {
  fill: var(--accent);
  stroke: #02120f;
  stroke-width: 0.6;
  vector-effect: non-scaling-stroke;
  cursor: grab;
}
#preview .nfm-h-section {
  fill: none;
  stroke: transparent;
  pointer-events: stroke;
  vector-effect: none;
  cursor: move;
}
#preview .nfm-h-section:hover,
#preview .nfm-h-section.nfm-h-selected {
  stroke: var(--accent);
  stroke-opacity: 0.35;
}
#preview .nfm-h-station {
  fill-opacity: 0.25;
  stroke: var(--accent);
  stroke-width: 1.5;
}
#preview .nfm-h-port {
  fill: #ffcb6b;
}
#preview .nfm-h-segment {
  fill: #ffffff;
  stroke: var(--accent);
  stroke-width: 1.5;
}
#preview .nfm-h-vertex {
  fill: var(--accent);
}
#preview .nfm-h-resize {
  fill: #ffffff;
  stroke: var(--accent);
  stroke-width: 1.5;
}
#preview .nfm-h-resize[data-edge="e"],
#preview .nfm-h-resize[data-edge="w"] {
  cursor: ew-resize;
}
#preview .nfm-h-resize[data-edge="n"],
#preview .nfm-h-resize[data-edge="s"] {
  cursor: ns-resize;
}
#preview .nfm-h-resize[data-edge="nw"],
#preview .nfm-h-resize[data-edge="se"] {
  cursor: nwse-resize;
}
#preview .nfm-h-resize[data-edge="ne"],
#preview .nfm-h-resize[data-edge="sw"] {
  cursor: nesw-resize;
}
#preview .nfm-h-selected {
  fill: #ffcb6b;
}
#preview .nfm-h-section.nfm-h-selected {
  fill: none;
  stroke: #ffcb6b;
  stroke-opacity: 0.6;
}
.prop-grid.prop-grid-dense {
  gap: 4px;
}
.prop-grid.prop-grid-dense input[type="number"] {
  min-width: 0;
  padding-left: 4px;
  padding-right: 2px;
  font-size: 0.75rem;
}
#split.source-hidden {
  grid-template-columns: minmax(0, 1fr);
}
#split.source-hidden #editor-pane {
  display: none;
}
#preview .nfm-h-station.nfm-h-selected {
  fill: #ffcb6b;
  fill-opacity: 0.85;
  stroke: #ff9e3b;
  stroke-width: 2.5;
}
#preview .nfm-h-port.nfm-h-selected {
  fill: #ff9e3b;
  stroke-width: 2.5;
}
#preview .nfm-marquee {
  fill: var(--accent);
  fill-opacity: 0.08;
  stroke: var(--accent);
  stroke-dasharray: 4 3;
  pointer-events: none;
}
#preview .nfm-guide {
  stroke: #ff4fa3;
  stroke-dasharray: 6 4;
  pointer-events: none;
}
.lane-row {
  cursor: grab;
  padding: 3px 6px;
  border: 1px solid transparent;
  border-radius: 4px;
}
.lane-row.dragging {
  opacity: 0.4;
}
.lane-row.current {
  font-weight: 600;
}
.lane-row.drop-target {
  border-color: var(--accent);
}
.lane-swatch {
  display: inline-block;
  width: 18px;
  height: 4px;
  border-radius: 2px;
  background: currentColor;
}
#preview .nfm-h-junction {
  fill: #b48cff;
  stroke: #2b1a4a;
  stroke-width: 1;
}
#preview .nfm-h-junction.nfm-h-selected {
  fill: #ffcb6b;
  stroke: #ff9e3b;
  stroke-width: 2.5;
}
#preview .nfm-grid {
  pointer-events: none;
}
#preview .nfm-grid-dot {
  fill: var(--muted, #7a8899);
  fill-opacity: 0.55;
}
#preview .nfm-h-edge {
  fill: var(--accent);
  fill-opacity: 0;
  stroke: none;
  pointer-events: all;
}
#preview.engine-view {
  box-shadow: inset 0 0 0 3px #ffcb6b;
}
#preview .nfm-h-mark {
  pointer-events: none;
}
#preview .nfm-h-edge:hover {
  fill-opacity: 0.35;
}
#preview .nfm-h-edge[data-edge="e"],
#preview .nfm-h-edge[data-edge="w"] {
  cursor: ew-resize;
}
#preview .nfm-h-edge[data-edge="n"],
#preview .nfm-h-edge[data-edge="s"] {
  cursor: ns-resize;
}
#preview .nfm-h-edge[data-edge="nw"],
#preview .nfm-h-edge[data-edge="se"] {
  cursor: nwse-resize;
}
#preview .nfm-h-edge[data-edge="ne"],
#preview .nfm-h-edge[data-edge="sw"] {
  cursor: nesw-resize;
}
#preview .nfm-section-outline {
  fill: none;
  stroke: #ffcb6b;
  stroke-dasharray: 6 4;
  pointer-events: none;
}
#preview.mode-free-edit [data-section-id]:not(rect):not([data-station-id]) {
  cursor: move;
}
.lane-row {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--panel-2, rgba(127, 127, 127, 0.08));
  border: 1px solid var(--border, rgba(127, 127, 127, 0.3));
}
.lane-row:hover {
  border-color: var(--accent);
}
.lane-grip {
  cursor: grab;
  opacity: 0.6;
  font-size: 0.9rem;
}
.lane-name {
  flex: 1;
}
.lane-row button {
  padding: 0 6px;
  min-width: 0;
  line-height: 1.4;
}
#preview .nfm-h-legend {
  fill: var(--accent);
  fill-opacity: 0;
  stroke: var(--accent);
  stroke-opacity: 0;
  stroke-dasharray: 5 4;
  pointer-events: all;
  cursor: move;
}
#preview .nfm-h-legend:hover,
#preview .nfm-h-legend.nfm-h-selected {
  fill-opacity: 0.08;
  stroke-opacity: 0.8;
}
#preview .nfm-route-trace {
  fill: none;
  stroke: var(--accent);
  stroke-dasharray: 4 3;
  pointer-events: none;
}
#preview .nfm-ghost {
  fill: none;
  stroke: #ffcb6b;
  stroke-dasharray: 6 4;
  pointer-events: none;
}
#preview .nfm-grid-track {
  fill: none;
  stroke: var(--accent);
  stroke-opacity: 0.35;
  stroke-dasharray: 4 4;
  pointer-events: none;
}
#preview .nfm-grid-target {
  fill: var(--accent);
  fill-opacity: 0.15;
  stroke: var(--accent);
  pointer-events: none;
}
/* Touch gestures pan and zoom the canvas except where a drag starts: on any
   free-edit target, a grid or span handle, or the selected section. */
#preview.mode-free-edit svg,
#preview svg [data-h],
#preview svg .nfm-touch-drag {
  touch-action: none;
}

.free-edit-bar {
  flex-wrap: wrap;
  gap: 6px;
}
.free-edit-bar input[type="text"] {
  flex: 1 1 14rem;
  min-width: 10rem;
}
.free-edit-status {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
  max-width: min(90%, 40rem);
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--panel, #10181c);
  font-size: 0.8rem;
}
.lane-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.lane-row {
  display: flex;
  align-items: center;
  gap: 4px;
}
.lane-row span {
  flex: 1;
  font-family: var(--mono, monospace);
  font-size: 0.8rem;
}
.lane-flips {
  display: flex;
  gap: 4px;
  margin-top: 4px;
}
