/* The demo page.
 *
 * Two columns on a wide screen — what you wrote on the left, what came out on the
 * right — and one column on a narrow one. The colours are declared once as custom
 * properties and redeclared for a dark scheme; the `--rg-*` half of them are the
 * names `roadgen-viewer` draws its SVGs with, so a picture already in the page
 * re-themes without being drawn again.
 */

:root {
  color-scheme: light dark;

  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f1f3f6;
  --ink: #111827;
  --ink-dim: #5b6472;
  --line: #dfe3e9;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --bad: #b91c1c;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  /* What roadgen-viewer's SVGs read. */
  --rg-text: #5b6472;

  /* The frame every viewer gets. One number, so that switching format changes the
     picture and not its place on the page: tall enough for a map to be a map, short
     enough that the switch above it stays on screen. */
  --viewer-height: min(60vh, 600px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --panel: #161b22;
    --panel-2: #1c222b;
    --ink: #e6e9ee;
    --ink-dim: #9aa4b2;
    --line: #2a313b;
    --accent: #4b8bff;
    --accent-ink: #0b1020;
    --bad: #f87171;

    --rg-text: #9aa4b2;
    --rg-boundary: #94a3b8;
    --rg-surface: rgba(148, 163, 184, 0.16);
    --rg-mark-white: #cbd5e1;
    --rg-node: #94a3b8;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

a {
  color: var(--accent);
}

.masthead {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 24px;
  align-items: flex-end;
  justify-content: space-between;
  padding: 22px 16px 16px;
  max-width: 1600px;
  margin: 0 auto;
}

.masthead h1 {
  margin: 0 0 4px;
  font-size: 26px;
  letter-spacing: -0.01em;
}

.masthead p {
  margin: 0;
  max-width: 78ch;
  color: var(--ink-dim);
}

.repo {
  font-family: var(--mono);
  font-size: 12.5px;
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px;
  background: var(--panel);
  white-space: nowrap;
}

main {
  display: grid;
  grid-template-columns: minmax(360px, 30%) 1fr;
  gap: 16px;
  padding: 0 16px 24px;
  max-width: 1600px;
  margin: 0 auto;
  align-items: start;
}

@media (max-width: 900px) {
  main {
    grid-template-columns: 1fr;
  }
}

.pane {
  min-width: 0;
}

.editor-pane {
  position: sticky;
  top: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: calc(100vh - 32px);
}

@media (max-width: 900px) {
  .editor-pane {
    position: static;
    max-height: none;
  }
}

.toolbar {
  display: flex;
  gap: 8px;
}

select,
button {
  font: inherit;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 7px 10px;
}

select {
  flex: 1;
  min-width: 0;
}

button {
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
}

button:disabled {
  opacity: 0.55;
  cursor: progress;
}

#run {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
  font-weight: 600;
  padding-inline: 18px;
}

.editor {
  flex: 1 1 auto;
  min-height: 260px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}

.editor .CodeMirror {
  height: 100%;
  font-family: var(--mono);
  font-size: 13px;
  background: transparent;
  color: var(--ink);
}

.editor .CodeMirror-gutters {
  background: transparent;
  border-right: 1px solid var(--line);
}

.editor .CodeMirror-linenumber {
  color: var(--ink-dim);
}

.editor .CodeMirror-cursor {
  border-left-color: var(--ink);
}

.editor .CodeMirror-selected {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
}

@media (prefers-color-scheme: dark) {
  .cm-s-default .cm-keyword { color: #c792ea; }
  .cm-s-default .cm-string { color: #a5d6a7; }
  .cm-s-default .cm-number { color: #ffcb6b; }
  .cm-s-default .cm-comment { color: #7f8a99; }
  .cm-s-default .cm-def,
  .cm-s-default .cm-variable-2 { color: #82aaff; }
  .cm-s-default .cm-builtin { color: #f78c6c; }
}

.console {
  flex: 0 0 auto;
  max-height: 34vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 12.5px;
  white-space: pre-wrap;
  word-break: break-word;
}

.status {
  color: var(--ink-dim);
}

.console .bad {
  color: var(--bad);
}

/* One viewer, and a switch above it. Every format is written by the same run and
   shown in the same frame, so flipping between them compares like with like: the
   picture changes and nothing around it moves. */
.results {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
}

.tab {
  border: 0;
  border-radius: 999px;
  padding: 7px 16px;
  background: transparent;
  color: var(--ink-dim);
  font-weight: 600;
  font-size: 13.5px;
  white-space: nowrap;
}

.tab:hover {
  color: var(--ink);
  background: var(--panel-2);
}

.tab[aria-selected='true'] {
  background: var(--accent);
  color: var(--accent-ink);
}

.tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  overflow: hidden;
}

.panel:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.panel > header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}

.placeholder {
  color: var(--ink-dim);
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 28px;
  text-align: center;
  margin: 0;
}

.panel h2 {
  margin: 0;
  font-size: 14px;
  font-family: var(--mono);
  font-weight: 500;
}

.panel .note {
  color: var(--ink-dim);
  font-size: 12.5px;
  flex: 1 1 100%;
  margin: 0;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 14px 0;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 4px 3px 10px;
  font-family: var(--mono);
  font-size: 12px;
  background: var(--panel);
  white-space: nowrap;
}

.chip > span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 34ch;
}

.chip .size {
  color: var(--ink-dim);
}

.chip button {
  border: 0;
  background: transparent;
  color: var(--ink-dim);
  padding: 2px 6px;
  border-radius: 999px;
  font-size: 11.5px;
  cursor: pointer;
}

.chip button:hover {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
}

.chip button[aria-pressed='true'] {
  color: var(--accent);
}

.figure {
  /* The same frame a map panel gets — one number, so that flipping between a drawn
     format and a Leaflet one moves the picture and nothing else. */
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--viewer-height);
  padding: 10px 14px 16px;
  overflow: auto;
}

.figure svg {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
}

/* On a phone a picture scaled to the width of the screen is a thumbnail with a
   legend nobody can read. Below this it keeps its size and the panel scrolls. */
@media (max-width: 700px) {
  .figure {
    justify-content: flex-start;
    min-height: 0;
  }

  .figure svg {
    max-width: none;
    margin: 0;
  }
}

.map {
  height: var(--viewer-height);
  min-height: 320px;
}

.leaflet-container {
  background: var(--panel-2);
  font: inherit;
}

.source {
  margin: 0;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  background: var(--panel-2);
  font-family: var(--mono);
  font-size: 12px;
  max-height: 340px;
  overflow: auto;
  white-space: pre;
}

.panel .bad {
  margin: 0;
  padding: 14px;
  color: var(--bad);
  font-family: var(--mono);
  font-size: 12.5px;
}

footer {
  border-top: 1px solid var(--line);
  padding: 18px 16px 40px;
  max-width: 1600px;
  margin: 0 auto;
  color: var(--ink-dim);
  font-size: 13px;
}

footer p {
  max-width: 90ch;
  margin: 0 0 8px;
}

code {
  font-family: var(--mono);
  font-size: 0.92em;
}

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