@font-face {
  font-family: "Plex Sans";
  src: url("fonts/plex-sans-var.woff2") format("woff2");
  font-weight: 100 700;
  font-display: swap;
}
@font-face {
  font-family: "Plex Mono";
  src: url("fonts/plex-mono-400.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}

:root {
  color-scheme: light dark;
  --paper: #f2ede3;
  --paper-2: #e9e2d4;
  --ink: #1c2230;
  --ink-soft: #5a6070;
  --rule: #cfc6b4;
  --dot: rgba(28, 34, 48, 0.13);
  --shadow: 0 1px 0 rgba(28, 34, 48, 0.06), 0 12px 32px -12px rgba(28, 34, 48, 0.28);
  --grid: 32px;
  --grid-x: 0px;
  --grid-y: 0px;
  --panel: #1c2230;
  --panel-2: #283041;
  --panel-fg: #e9e4d8;
  --panel-soft: #9aa3b1;
  --accent: #35b6c6;
  --live: #3fae6a;
  --glass: color-mix(in srgb, var(--paper) 84%, transparent);
  --sans: "Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #101b26;
    --paper-2: #16232f;
    --ink: #e9e4d8;
    --ink-soft: #95a0ad;
    --rule: #2b3a48;
    --dot: rgba(233, 228, 216, 0.09);
    --shadow: 0 1px 0 rgba(0, 0, 0, 0.3), 0 16px 40px -12px rgba(0, 0, 0, 0.7);
    --panel: #0b131b;
    --panel-2: #1d2a36;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background-color: var(--paper);
  background-image: radial-gradient(circle, var(--dot) 1.1px, transparent 1.4px);
  background-size: var(--grid) var(--grid);
  background-position: var(--grid-x) var(--grid-y);
  color: var(--ink);
  font: 400 16px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
a { color: inherit; text-underline-offset: 3px; text-decoration-thickness: 1px; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; border-radius: 3px; }

#map {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}
#map.hit { cursor: pointer; }
#map.grabbing { cursor: grabbing; }
body.map { background-image: none; }

/* Title cartouche, styled like the legend box of a printed transit map */
.cartouche {
  position: fixed;
  top: clamp(16px, 5vh, 56px);
  left: clamp(16px, 5vw, 64px);
  width: min(400px, calc(100vw - 32px));
  padding: 26px 28px 22px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 4px;
  box-shadow: var(--shadow);
}
.cartouche h1 {
  margin: 0;
  font-size: 2.35rem;
  line-height: 1.05;
  font-weight: 600;
  letter-spacing: -0.025em;
}
.cartouche .role {
  margin: 10px 0 0;
  color: var(--ink-soft);
  font-size: 0.98rem;
}
.legend-head {
  margin: 18px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--rule);
  font: 400 11.5px/1.5 var(--mono);
  color: var(--ink-soft);
}
.legend {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 14px;
}
.legend button {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 3px 0;
  text-align: left;
  font-size: 0.84rem;
  white-space: nowrap;
  transition: opacity 0.2s;
}
.legend .swatch {
  flex: none;
  width: 18px;
  height: 5px;
  border-radius: 3px;
  background: var(--c, currentColor);
}
.legend.dim button:not(.on) { opacity: 0.35; }

/* Instrument readout: a strip along the bottom edge, like a map's margin */
.strip {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px clamp(16px, 5vw, 64px) calc(10px + env(safe-area-inset-bottom));
  background: var(--paper);
  border-top: 1px solid var(--rule);
  font: 400 12px/1.4 var(--mono);
  color: var(--ink-soft);
}
.hud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 18px;
  font-variant-numeric: tabular-nums;
}
.hud b { font-weight: 400; color: var(--ink); }
.hud .seed { text-decoration: underline dotted; text-underline-offset: 3px; }
.strip a { margin-left: auto; }





/* Imprint */
body.page { overflow: auto; }
.sheet {
  max-width: 560px;
  margin: clamp(16px, 8vh, 96px) auto;
  padding: 32px 32px 28px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 4px;
  box-shadow: var(--shadow);
}
@media (max-width: 600px) {
  .sheet { margin: 16px; padding: 24px 20px; }
}
.sheet h1 { margin: 0 0 18px; font-size: 1.6rem; font-weight: 600; letter-spacing: -0.02em; }
.sheet h2 {
  margin: 28px 0 8px;
  padding-top: 20px;
  border-top: 1px solid var(--rule);
  font: 400 12px/1.4 var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
}
.sheet p { margin: 0 0 10px; }
.sheet .small { font-size: 0.9rem; color: var(--ink-soft); }
.sheet .back { display: inline-block; margin-bottom: 20px; font: 400 12px/1.4 var(--mono); color: var(--ink-soft); }
.hud[hidden] { display: none; }

.hud .presence { display: inline-flex; align-items: center; gap: 7px; }
.hud .presence i { width: 7px; height: 7px; border-radius: 50%; background: var(--rule); }
.hud.live .presence i { background: var(--live); box-shadow: 0 0 0 0 var(--live); animation: beat 2.4s infinite; }
@keyframes beat {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--live) 60%, transparent); }
  70%, 100% { box-shadow: 0 0 0 7px transparent; }
}

/* Tooltip */
.tip {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 5;
  display: grid;
  gap: 3px;
  min-width: 140px;
  pointer-events: none;
  padding: 9px 12px 10px;
  background: var(--panel);
  color: var(--panel-fg);
  border-radius: 6px;
  box-shadow: var(--shadow);
  font: 400 12px/1.35 var(--mono);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.18s;
}
.tip.show { opacity: 1; }
.tip b { font: 600 14px/1.3 var(--sans); }
.tip .tip-line { display: flex; align-items: center; gap: 8px; }
.tip .tip-line::before { content: ""; width: 14px; height: 4px; border-radius: 2px; background: var(--c); }
.tip .tip-meta { color: var(--panel-soft); margin-top: 2px; }

/* Controls, in the spirit of lil-gui */
.gui {
  position: fixed;
  top: clamp(16px, 5vh, 56px);
  right: clamp(16px, 3vw, 40px);
  width: 272px;
  max-height: calc(100vh - 120px);
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  color: var(--panel-fg);
  border-radius: 6px;
  box-shadow: var(--shadow);
  font: 400 11.5px/1.3 var(--mono);
  overflow: hidden;
}
.gui-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 9px 12px;
  font: 500 11.5px/1.3 var(--mono);
  letter-spacing: 0.04em;
  background: var(--panel-2);
}
.gui-title::after { content: "▾"; transition: transform 0.2s; }
.gui.closed .gui-title::after { transform: rotate(-90deg); }
.gui.closed .gui-body { display: none; }
.gui-body { overflow-y: auto; padding: 4px 0 8px; scrollbar-width: thin; }
.gui-folder {
  padding: 8px 12px 3px;
  color: var(--panel-soft);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.gui .row {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 25px;
  padding: 1px 12px;
}
.gui .row > span { color: var(--panel-soft); }
.gui .row output { min-width: 44px; text-align: right; font-variant-numeric: tabular-nums; }
.gui .row:has(output:only-of-type) output, .gui .row > output:last-child { justify-self: end; }
.gui .row.col { grid-template-columns: 1fr; gap: 6px; padding-top: 6px; }
.gui .row.col output { text-align: left; }
.gui .row.spark { grid-template-columns: 1fr auto; }
.gui input[type="text"] {
  width: 100%;
  padding: 4px 6px;
  border: 1px solid transparent;
  border-radius: 3px;
  background: var(--panel-2);
  color: var(--panel-fg);
  font: inherit;
}
.gui input[type="text"]:focus { outline: none; border-color: var(--accent); }
.gui .btn, .gui .icon {
  padding: 4px 8px;
  border-radius: 3px;
  background: var(--panel-2);
  text-align: center;
}
.gui .btn { grid-column: 2 / 4; }
.gui .btn:hover, .gui .icon:hover { background: color-mix(in srgb, var(--panel-2) 70%, var(--accent)); }
.gui input[type="checkbox"] { justify-self: start; width: 15px; height: 15px; margin: 0; accent-color: var(--accent); }
.gui input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 18px;
  margin: 0;
  background: transparent;
  cursor: ew-resize;
}
.gui input[type="range"]::-webkit-slider-runnable-track {
  height: 18px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--accent) 0 calc(var(--p, 0) * 100%), var(--panel-2) 0);
}
.gui input[type="range"]::-moz-range-track {
  height: 18px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--accent) 0 calc(var(--p, 0) * 100%), var(--panel-2) 0);
}
.gui input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 0; height: 18px; }
.gui input[type="range"]::-moz-range-thumb { width: 0; height: 18px; border: 0; }
.gui #spark { width: 100%; height: 30px; display: block; }
.bars { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: var(--panel-2); }
.bars i { flex: var(--w, 0) 1 0; background: var(--c); min-width: 2px; }

/* Event log, like tailing a topic */
.log {
  position: fixed;
  left: clamp(16px, 5vw, 64px);
  bottom: 56px;
  width: 360px;
  margin: 0;
  padding: 8px 12px;
  list-style: none;
  background: var(--glass);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: 1px solid var(--rule);
  border-radius: 6px;
  font: 400 11.5px/1.6 var(--mono);
  color: var(--ink);
  pointer-events: none;
}
.log:empty { display: none; }
.log li {
  display: grid;
  grid-template-columns: auto 8px 1fr auto;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  animation: in 0.35s ease-out;
}
.log li:nth-child(n + 4) { opacity: 0.6; }
.log li:nth-child(n + 6) { opacity: 0.35; }
.log time { color: var(--ink-soft); }
.log i { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.log span { overflow: hidden; text-overflow: ellipsis; }
.log em { font-style: normal; color: var(--ink-soft); }
@keyframes in { from { opacity: 0; transform: translateY(-4px); } }

@media (max-width: 640px) {
  .cartouche { padding: 14px 16px 12px; }
  .cartouche h1 { font-size: 1.6rem; }
  .cartouche .role { font-size: 0.85rem; margin-top: 6px; }
  .legend-head { margin-top: 12px; padding-top: 10px; font-size: 10.5px; }
  .legend { gap: 0 10px; }
  .legend button { font-size: 0.76rem; gap: 7px; padding: 2px 0; }
  .legend .swatch { width: 14px; height: 4px; }
  .hud .hint, .hud .fps { display: none; }
  .log { display: none; }
  .gui { top: auto; bottom: 52px; left: 16px; right: 16px; width: auto; max-height: 55vh; }
}
@media (max-height: 640px) and (min-width: 641px) {
  .log { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .hud.live .presence i, .log li { animation: none; }
}
