/* traffic-sim. The colour tokens match the tiling explorer and site.css,
   so the cards read as part of the site. The road and cars take their
   colours from app.js. */
:root {
  color-scheme: light dark;
  --bg: light-dark(#f6f3ec, #16161a);
  --panel: light-dark(rgba(255, 253, 248, 0.92), rgba(30, 30, 35, 0.9));
  --text: light-dark(#46443d, #c8c4b9);
  --h1: light-dark(#1a1a1a, #f5f3ec);
  --link: light-dark(#1552a1, #7aa6e0);
  --rule: light-dark(#ddd8cc, #3a3a3a);
  --muted: light-dark(#7c786d, #918c80);
  --button: light-dark(#fffdf8, #26262c);
  --pressed: light-dark(#1a1a1a, #f5f3ec);
  --pressed-text: light-dark(#fffdf8, #16161a);
  --accent: light-dark(#d96c00, #ffd04d);
  --shadow: light-dark(0 2px 10px rgba(40, 30, 10, 0.14), 0 2px 12px rgba(0, 0, 0, 0.5));
  --ui: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); }
body {
  color: var(--text);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 15px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--link); }

#view {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  display: block;
  touch-action: none;
  cursor: grab;
  outline: none;
}
#view.dragging { cursor: grabbing; }

/* The two cards share a top bar, controls on the left and the live numbers
   on the right. The bar lets drags through to the road. */
.top {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  pointer-events: none;
}
.card {
  pointer-events: auto;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 10px;
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.controls {
  width: 292px;
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  overflow: auto;
  padding: 0.6rem 0.8rem 0.7rem;
}
.controls header { display: flex; align-items: baseline; gap: 0.5rem; }
.controls h1 { flex: 1; margin: 0; font-size: 1.25rem; font-weight: normal; color: var(--h1); white-space: nowrap; }
.controls .back { order: -1; font-size: 0.8rem; text-decoration: none; }
.controls .back:hover { text-decoration: underline; }
.controls.folded { width: auto; }
.controls.folded .steps, .controls.folded .hint { display: none; }

/* Numbered steps, in the order a visitor uses them. The next one is lit. */
.steps { list-style: none; margin: 0.4rem 0 0; padding: 0; counter-reset: step; }
.steps li { counter-increment: step; position: relative; padding: 0.45rem 0 0.35rem 1.9rem; border-top: 1px solid var(--rule); }
.steps li::before {
  content: counter(step);
  position: absolute; left: 0; top: 0.5rem;
  width: 1.35rem; height: 1.35rem; border-radius: 50%;
  display: grid; place-items: center;
  font: 600 0.75rem/1 var(--ui);
  color: var(--muted); border: 1px solid var(--rule);
}
.steps li.next::before {
  color: var(--pressed-text); background: var(--accent); border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent);
}
.steps h2 { margin: 0 0 0.3rem; font-size: 0.95rem; font-weight: normal; color: var(--h1); }

button {
  font: 0.82rem/1.2 var(--ui);
  color: var(--text);
  background: var(--button);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 0.32rem 0.55rem;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: 0.45; cursor: default; }
button[aria-pressed="true"] { background: var(--pressed); color: var(--pressed-text); border-color: var(--pressed); }
button.small { padding: 0.15rem 0.45rem; font-size: 0.75rem; }
#fullscreen { font-size: 0.9rem; line-height: 1; }

.seg { display: flex; flex-wrap: wrap; margin: 0.3rem 0 0.15rem; }
.seg button { border-radius: 0; margin-left: -1px; flex: 1 1 auto; }
.seg button:first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.seg button:last-child { border-radius: 0 6px 6px 0; }
.row { display: flex; flex-wrap: wrap; gap: 0.35rem; margin: 0.3rem 0 0.15rem; }

.slider { display: block; margin: 0.15rem 0 0.35rem; font: 0.82rem/1.3 var(--ui); }
.slider span { display: flex; justify-content: space-between; }
.slider output { font-variant-numeric: tabular-nums; color: var(--h1); }
.slider input { width: 100%; margin: 0.15rem 0 0; accent-color: var(--accent); }
.check { display: flex; gap: 0.4rem; align-items: center; font: 0.82rem/1.3 var(--ui); }
.check input { accent-color: var(--accent); }
.hint { margin: 0.35rem 0 0; font-size: 0.8rem; color: var(--muted); }

.numbers { width: 214px; padding: 0.55rem 0.8rem 0.6rem; font-family: var(--ui); }
.numbers dl { margin: 0; display: grid; gap: 0.12rem; }
.numbers dl div { display: flex; justify-content: space-between; align-items: baseline; gap: 0.6rem; }
.numbers dt { font-size: 0.78rem; color: var(--muted); }
.numbers dd { margin: 0; font-size: 0.95rem; color: var(--h1); font-variant-numeric: tabular-nums; }
.numbers small { font-size: 0.7rem; color: var(--muted); }
.legend { list-style: none; margin: 0.45rem 0 0; padding: 0.4rem 0 0; border-top: 1px solid var(--rule); display: flex; flex-wrap: wrap; gap: 0.2rem 0.7rem; font-size: 0.75rem; }
.legend li { display: flex; align-items: center; gap: 0.3rem; }
.swatch { width: 0.75rem; height: 0.75rem; border-radius: 3px; border: 1px solid var(--rule); }
.meta { margin: 0.35rem 0 0; font-size: 0.7rem; color: var(--muted); }

.fail { position: fixed; inset: auto 1rem 1rem; padding: 0.8rem 1rem; background: var(--panel); border: 1px solid var(--rule); border-radius: 8px; }

/* A phone: the steps fold behind the title, and the numbers move to a
   compact strip along the bottom, so the road stays clear. */
@media (max-width: 640px), (max-height: 500px) {
  .top { right: auto; }
  .controls { width: min(292px, calc(100vw - 24px)); }
  .numbers {
    position: fixed;
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
    width: auto;
    padding: 0.35rem 0.6rem;
  }
  .numbers dl { grid-template-columns: repeat(3, 1fr); gap: 0 0.6rem; }
  .numbers dl div { flex-direction: column; align-items: flex-start; gap: 0; }
  .numbers dl div:nth-child(n + 4) { display: none; }
  .numbers .meta { display: none; }
  .legend { margin-top: 0.25rem; padding-top: 0.25rem; }
}
/* A phone held sideways: the folded title takes the top left corner, and
   the numbers a narrow column on the right. */
@media (max-height: 500px) and (min-width: 641px) {
  .numbers { left: auto; top: max(8px, env(safe-area-inset-top)); width: 150px; }
  .numbers dl { grid-template-columns: 1fr; gap: 0.15rem; }
  .legend { flex-direction: column; }
}
