:root {
  color-scheme: dark;
  font: 14px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --background: #0a0c0d;
  --panel: #111517;
  --hover: #1a2022;
  --border: #2d3538;
  --wire: #485559;
  --wire-dim: #262e30;
  --text: #e0e7e7;
  --muted: #a4afb2;
  --accent: #86ddc7;
  --fault: #f49eb2;
  --waiting: #eacc8f;
  color: var(--text);
  background: var(--background);
}

* { box-sizing: border-box; }
body { margin: 0; }
h1, h2, h3, p { margin: 0; }
button, select { color: inherit; font: inherit; }
button, select, a { touch-action: manipulation; }
button { cursor: pointer; }
button:disabled { opacity: .45; cursor: default; }
a { color: var(--accent); text-underline-offset: .25em; }
a:hover { color: var(--text); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.world {
  --gutter: clamp(16px, 3vw, 44px);
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 1600px;
  margin-inline: auto;
  padding: clamp(14px, 3.5vh, 40px) var(--gutter) 0;
}
.toolbar, .view-controls, .map-actions { display: flex; align-items: center; gap: 10px; }
.toolbar { justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.title-row { display: flex; align-items: baseline; gap: 12px; }
h1 { font-size: 1.25rem; font-weight: 650; }
.source { font-size: .78rem; color: var(--muted); text-decoration: none; }
#replay-label, .map-note, #level-note { color: var(--muted); font-size: .86rem; }
.view-switch { display: flex; gap: 3px; }
.view-switch button, select, .arrow, .level-step {
  min-height: 44px;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--panel);
  font-size: .86rem;
}
.view-switch button { border-color: transparent; background: none; color: var(--muted); }
.view-switch button[aria-current], .level-step[aria-current] {
  color: var(--accent);
  border-color: var(--border);
  background: var(--hover);
}
.run-picker select { max-width: min(46vw, 284px); }
.view-switch button:hover, .arrow:hover:enabled, .level-step:hover { background: var(--hover); color: var(--text); }

.map { padding: 21px 0 34px; }
.map-actions { flex-wrap: wrap; padding-bottom: 16px; }
.map-board { position: relative; }
#map-belts, #belts { position: absolute; inset: 0; pointer-events: none; }
.map-grid {
  position: relative;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr)) minmax(156px, 1.43fr) minmax(176px, 1.6fr);
  gap: clamp(16px, 2vw, 32px);
}
.map-column { min-width: 0; display: grid; grid-template-rows: auto 1fr; gap: 10px; }
.map-label { color: var(--muted); font-size: .74rem; font-weight: 500; padding-bottom: 7px; border-bottom: 1px solid var(--border); }
.map-nodes { display: flex; flex-direction: column; justify-content: center; gap: 9px; }
.map-lane, .lane { display: grid; gap: 10px; }
.map-nodes:has(.map-lane) { gap: 15px; }
.stations:has(.lane) { gap: 22px; }
.map-lane .map-station { min-height: 45px; flex-direction: row; align-items: center; }

[data-station-tone="github"] { --station-accent: #d4dde1; }
[data-station-tone="prefect"] { --station-accent: #86ceef; }
[data-station-tone="agent"] { --station-accent: #c8b5fa; }
[data-station-tone="ship"], [data-station-tone="fix"] { --station-accent: var(--accent); }
[data-station-tone="evidence"] { --station-accent: var(--waiting); }
[data-station-tone="decision"] { --station-accent: #b5baf9; }
[data-station-tone="close"] { --station-accent: #f2ac93; }
[data-station-tone="quiet"] { --station-accent: #aab8ba; }
[data-station-tone="fault"] { --station-accent: var(--fault); }

.map-station, .station, .neighbor {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 5px;
  text-align: left;
}
.map-station {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
  min-height: 74px;
  padding: 8px 7px;
}
.map-station:hover, .neighbor:hover { border-color: var(--station-accent); background: var(--hover); }
.map-station[aria-pressed] {
  min-height: 45px;
  border-left: 2px solid var(--station-accent);
  flex-direction: row;
  align-items: center;
}
.map-station[aria-pressed="true"], .map-board[data-tracing="true"] .map-station[data-route="true"], .station.identity {
  border-color: var(--station-accent);
  background: color-mix(in srgb, var(--station-accent) 8%, var(--panel));
}
.map-station[data-route="false"] { border-color: var(--border); color: var(--muted); background: var(--background); }
.map-station[data-route="false"] .machine-icon { color: var(--muted); }
.map-station[data-route="false"] img { opacity: .65; }
.map-station strong, .map-station small { display: block; overflow-wrap: anywhere; }
.map-station strong { font-size: .85rem; line-height: 1.25; font-weight: 650; }
.map-station small { color: var(--muted); font-size: .72rem; line-height: 1.25; margin-top: 3px; }
.machine-icon {
  width: 22px;
  height: 22px;
  flex: none;
  display: grid;
  place-items: center;
  color: var(--station-accent);
  font-size: 1.2rem;
}
.machine-icon img { display: block; width: 18px; height: 18px; object-fit: contain; }

.action-lanes { margin-top: 25px; max-width: 910px; }
.action-lanes h2 { font-size: 1rem; }
.action-lanes > p { color: var(--muted); font-size: .86rem; margin: 4px 0 12px; }
.action-lane {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(250px, 1.6fr) minmax(155px, 1fr);
  align-items: baseline;
  gap: 0 18px;
  padding: 8px 0;
  border-top: 1px solid var(--border);
  font-size: .84rem;
}
.action-lane > :nth-child(2) { color: var(--muted); }
.action-lane code { font: inherit; color: var(--waiting); }
.action-lane a { text-decoration-color: color-mix(in srgb, var(--accent) 55%, transparent); }

.diagram { flex: 1; padding: clamp(22px, 5vh, 54px) 0 24px; }
.level-heading { text-align: center; margin-bottom: 20px; }
#level-number { color: var(--accent); font-size: .8rem; }
#level-title { font-size: 1.45rem; }
#level-note { max-width: 66ch; margin: 5px auto 0; }
.board {
  display: grid;
  position: relative;
  align-items: center;
  grid-template-columns: minmax(130px, 1fr) minmax(280px, 440px) minmax(130px, 1fr);
  gap: clamp(26px, 5vw, 84px);
  padding-block: 10px;
}
.stations, .neighbors { display: grid; gap: 12px; z-index: 1; }
.stations { grid-column: 2; }
.incoming { grid-column: 1; justify-self: end; }
.outgoing { grid-column: 3; justify-self: start; }
.neighbors { grid-row: 1; width: min(100%, 200px); }
.station { padding: 14px; }
.station[data-tone="fault"] { border-color: var(--fault); }
.station[data-tone="waiting"] { border-color: var(--waiting); }
.station[data-state="unreached"] { border-style: dashed; }
.machine-header { display: flex; gap: 10px; align-items: center; }
.machine-kind, .neighbor span { display: block; color: var(--muted); font-size: .78rem; }
.machine-title { font-size: 1.07rem; }
.machine-detail, .outcome { font-size: .92rem; margin-top: 10px; }
.outcome { border-top: 1px solid var(--border); padding-top: 10px; }
.outcome p + p { margin-top: 6px; }
.outcome a { min-height: 44px; display: inline-flex; align-items: center; }
.neighbor { min-height: 50px; padding: 7px 10px; font-size: .86rem; }
.neighbor[data-route="false"], .level-step[data-route="false"]:not([aria-current]) { border-style: dashed; }
.hand-offs { display: none; }

.transport {
  display: grid;
  grid-template-columns: minmax(44px, 1fr) auto minmax(44px, 1fr);
  align-items: center;
  gap: 8px;
  position: sticky;
  bottom: 0;
  z-index: 2;
  padding: 9px 0 max(9px, env(safe-area-inset-bottom));
  background: var(--background);
  border-top: 1px solid var(--border);
}
#previous { justify-self: start; }
#next { justify-self: end; }
#levels { display: flex; gap: 3px; }
.level-step { min-width: 44px; padding: 0; }

@media (max-width: 1009px) {
  .map-grid { grid-template-columns: 1fr; max-width: 600px; margin-inline: auto; padding-left: 13px; gap: 17px; }
  .map-column { gap: 4px; }
  .map-label { width: fit-content; border: 0; padding: 0 5px 0 0; background: var(--background); }
  .map-nodes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .map-station { flex-direction: row; align-items: center; min-height: 49px; padding: 7px; }
  .map-station:only-child, .map-lane { grid-column: 1 / -1; }
}

@media (max-width: 720px) {
  .board { display: block; }
  .stations, .hand-offs { width: min(100%, 500px); margin-inline: auto; }
  #belts, .neighbors { display: none; }
  .hand-offs { display: grid; margin-top: 6px; }
  .hand-off { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 7px; }
  .hand-off strong { font-size: .78rem; color: var(--muted); }
  .hand-off button { min-height: 44px; padding: 0 4px; background: none; border: 0; color: var(--accent); font-size: .85rem; text-align: left; }
  .action-lane { grid-template-columns: 1fr; padding: 8px 0 0; }
  .action-lane a { min-height: 44px; display: flex; align-items: center; justify-self: start; }
}

@media (max-width: 590px) {
  .view-controls { width: 100%; justify-content: space-between; gap: 5px; }
  .map { padding-top: 12px; }
  .map-actions { gap: 6px; }
  .map-note { flex: 1 0 100%; min-height: 2.6em; }
  .transport { grid-template-columns: repeat(2, 1fr); gap: 5px; }
  #levels { grid-column: 1 / -1; grid-row: 1; width: min(100%, 404px); justify-self: center; display: grid; grid-template-columns: repeat(9, 1fr); }
  .level-step { min-width: 0; }
  #previous, #next { grid-row: 2; }
}
