/* Colours are repeated in src/ui/theme.js for canvas drawing; change them together. */
:root {
  --yellow: #ffd500;
  --yellow-pressed: #e6c000;
  --ink-on-yellow: #0d0d0c;
  --muted-on-yellow: #4a3f00;
  --black: #0d0d0c;
  --panel: #181816;
  --rule: #3a3933;
  --control-border: #8a8674;
  --white: #ffffff;
  --muted: #b9b4a0;
  --positive: #4fb3ff;
  --negative: #ff6a3d;
  --radius: 3px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --font: Frutiger, "Frutiger Next", "Myriad Pro", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { scrollbar-color: var(--control-border) var(--panel); }

body {
  margin: 0;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  font: 14px/1.45 var(--font);
  font-variant-numeric: tabular-nums;
  background: var(--black);
  color: var(--white);
}

::selection { background: var(--yellow); color: var(--ink-on-yellow); }

:focus-visible { outline: 2px solid var(--yellow); outline-offset: 2px; }
.band :focus-visible { outline-color: var(--ink-on-yellow); }

h1, h2, p { margin: 0; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---- The sign band ---- */

.band {
  display: flex;
  align-items: center;
  gap: 16px 28px;
  padding: 12px 20px;
  background: var(--yellow);
  color: var(--ink-on-yellow);
}

.band > * + * { padding-left: 28px; border-left: 1px solid var(--ink-on-yellow); }
.band > .button { margin-left: auto; padding-left: 14px; border: 1.5px solid var(--ink-on-yellow); }

.picto {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  background: var(--ink-on-yellow);
  color: var(--white);
  border-radius: var(--radius);
}
.picto svg { width: 70%; height: 70%; }
.picto-large { width: 64px; height: 64px; }
.pictos { display: flex; gap: 4px; }
.pictos.out svg { opacity: 0.35; }
.picto-pedal { width: 32px; height: 64px; }
.picto-pedal svg { width: 12px; height: 24px; transform: scale(2); }
#signWing { transform-box: fill-box; transform-origin: center; transition: transform 120ms ease; }
@media (prefers-reduced-motion: reduce) { #signWing { transition: none; } }

.brand, .gate, .run-state, .band > .button { flex: none; white-space: nowrap; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { font-size: 18px; font-weight: 700; line-height: 1.2; }
.brand h1 span { display: block; font-size: 13px; font-weight: 400; color: var(--muted-on-yellow); }

.sign { display: flex; align-items: center; gap: 16px; flex: 1 1 auto; min-width: 0; }
.sign-steer { font-size: 34px; font-weight: 700; line-height: 1.1; letter-spacing: -0.01em; perspective: 300px; }
.sign-steer span { display: inline-block; transform-origin: 50% 0; }
.sign > div { min-width: 255px; }
.sign-detail { font-size: 15px; white-space: nowrap; }

.flap { animation: flap 180ms var(--ease-out); }
@keyframes flap {
  from { transform: rotateX(-80deg); opacity: 0.3; }
  to { transform: rotateX(0); opacity: 1; }
}

.gate { display: grid; grid-template-columns: auto auto; align-items: center; column-gap: 14px; }
.gate-word { font-size: 20px; font-weight: 700; line-height: 1.2; }
.gate-number { grid-column: 2; grid-row: 1 / span 2; font-size: 64px; font-weight: 700; line-height: 0.95; letter-spacing: -0.02em; min-width: 3ch; }
.gate-detail { font-size: 14px; line-height: 1.3; color: var(--muted-on-yellow); }

.run-state { font-size: 14px; color: var(--muted-on-yellow); white-space: nowrap; min-width: 264px; }
.run-counts { min-height: 1.45em; }
.run-generation { font-size: 20px; font-weight: 700; color: var(--ink-on-yellow); }

/* ---- Layout ---- */

main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 392px;
  min-height: 0;
}

.stage { display: grid; grid-template-rows: minmax(0, 1fr) auto; min-width: 0; min-height: 0; }
#track { width: 100%; height: 100%; display: block; cursor: pointer; }

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px 20px;
  padding: 12px 20px 14px;
  background: var(--panel);
  border-top: 1px solid var(--rule);
}

.column {
  overflow-y: auto;
  background: var(--panel);
  border-left: 1px solid var(--rule);
}
.column section { padding: 20px 20px 22px; }
.column section + section { border-top: 1px solid var(--rule); }

h2 { font-size: 17px; font-weight: 700; line-height: 1.25; }
.heading-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.note { margin-top: 2px; color: var(--muted); font-size: 13px; text-wrap: pretty; }

canvas.network, canvas.trace, canvas.genome, canvas.chart { display: block; width: 100%; margin-top: 14px; }
canvas.network { height: 460px; }
canvas.trace { height: 150px; }
canvas.genome { height: 44px; }
canvas.chart { height: 130px; }

.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; margin-top: 10px; font-size: 13px; color: var(--muted); }
.swatch { width: 10px; height: 10px; border-radius: 50%; }
.swatch:not(:first-child) { margin-left: 10px; }
.swatch.positive { background: var(--positive); }
.swatch.negative { background: var(--negative); }
.swatch.line-best, .swatch.line-average { width: 16px; height: 2px; border-radius: 0; background: var(--white); }
.swatch.line-average { background: var(--muted); }
.legend-rest { flex-basis: 100%; }

/* ---- Controls ---- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 6px 14px;
  font: inherit;
  font-weight: 600;
  color: var(--white);
  background: transparent;
  border: 1.5px solid var(--control-border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background-color 120ms var(--ease-out), border-color 120ms var(--ease-out);
}
.button:hover { background: #2a2925; border-color: var(--white); }
.button:active { background: var(--rule); }
.button.small { min-height: 28px; padding: 2px 10px; font-size: 13px; }

.button.primary { min-width: 96px; color: var(--ink-on-yellow); background: var(--yellow); border-color: var(--yellow); }
.button.primary:hover { background: #ffe14d; border-color: #ffe14d; }
.button.primary:active { background: var(--yellow-pressed); }

.button.on-yellow { color: var(--ink-on-yellow); }
.button.on-yellow:hover { background: var(--ink-on-yellow); color: var(--yellow); border-color: var(--ink-on-yellow); }

.button.file { position: relative; }
.button.file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.button.file:focus-within { outline: 2px solid var(--yellow); outline-offset: 2px; }

.buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }

.field { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.field output { color: var(--white); font-weight: 600; }
.field.speed { width: 190px; }
.field.circuit { flex: 1 1 200px; max-width: 320px; }

select, input[type="number"] {
  width: 100%;
  min-height: 36px;
  padding: 6px 10px;
  font: inherit;
  font-size: 14px;
  color: var(--white);
  background: var(--black);
  border: 1.5px solid var(--control-border);
  border-radius: var(--radius);
}
select:hover, input[type="number"]:hover { border-color: var(--white); }

input[type="range"] { width: 100%; height: 36px; margin: 0; accent-color: var(--yellow); }
input[type="checkbox"] { width: 18px; height: 18px; margin: 1px 0 0; flex: none; accent-color: var(--yellow); }

.segmented { display: flex; margin: 0; padding: 0; border: 0; }
.segmented legend { padding: 0 0 4px; font-size: 13px; color: var(--muted); }
.segmented label { position: relative; }
.segmented input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.segmented span {
  display: flex;
  align-items: center;
  min-height: 36px;
  padding: 6px 14px;
  font-weight: 600;
  border: 1.5px solid var(--control-border);
}
.segmented label:first-of-type span { border-radius: var(--radius) 0 0 var(--radius); }
.segmented label + label span { margin-left: -1.5px; }
.segmented label:last-of-type span { border-radius: 0 var(--radius) var(--radius) 0; }
.stage-mode, .race-grid { margin-top: 14px; }
.stage-mode + .note, .race-grid + .note { margin-top: 8px; }
.segmented input:hover + span { background: #2a2925; }
.segmented input:checked + span { position: relative; color: var(--ink-on-yellow); background: var(--white); border-color: var(--white); }
.segmented input:focus-visible + span { outline: 2px solid var(--yellow); outline-offset: 2px; }

#message { flex: 1 1 220px; min-height: 36px; display: flex; align-items: center; color: var(--white); }
#message.error { color: var(--negative); }

.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; }
.pair + .note { margin-top: 8px; }
.check { display: flex; gap: 10px; margin-top: 14px; cursor: pointer; }
.check small { display: block; font-size: 13px; color: var(--muted); }
#reset { margin-top: 16px; }

/* ---- Help ---- */

#help {
  width: min(760px, calc(100vw - 32px));
  margin: 0;
  inset: 96px 20px auto auto;
  /* The script that positions the panel also caps its height to the space
     below the band; this is the fallback. It scrolls only if it must. */
  max-height: calc(100dvh - 112px);
  overflow-y: auto;
  padding: 16px 22px 16px;
  color: var(--ink-on-yellow);
  background: var(--white);
  border: 0;
  border-radius: var(--radius);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.55);
  scrollbar-color: #8a8674 var(--white);
}
#help h2 { font-size: 20px; }
#help p { margin: 0; font-size: 14px; }
#help .help-intro { margin-top: 6px; max-width: 78ch; }
.help-list { display: grid; grid-template-columns: 1fr 1fr; gap: 7px 28px; margin: 10px 0 0; }
.help-list dt { font-size: 14px; font-weight: 700; }
.help-list dd { margin: 0; font-size: 14px; line-height: 1.35; color: #33332e; }
.help-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 20px; margin-top: 12px; }
.help-foot a { font-size: 14px; font-weight: 600; color: var(--ink-on-yellow); text-underline-offset: 3px; }
.help-foot .button { margin-left: auto; }
#help .keys { color: #4a4a44; }
#help .button { color: var(--ink-on-yellow); border-color: var(--ink-on-yellow); }
#help .button:hover { background: var(--ink-on-yellow); color: var(--white); }
#help :focus-visible { outline-color: var(--ink-on-yellow); }
kbd {
  display: inline-block;
  min-width: 24px;
  margin-left: 12px;
  padding: 1px 6px;
  font: inherit;
  font-weight: 600;
  text-align: center;
  color: var(--white);
  background: var(--ink-on-yellow);
  border-radius: var(--radius);
}
kbd:first-child { margin-left: 0; }

/* ---- Narrow screens ---- */

@media (max-width: 1499px) {
  .band { flex-wrap: wrap; gap: 12px 32px; }
  .band > * + * { padding-left: 0; border-left: 0; }
  .brand { flex: 1 1 calc(100% - 240px); }
  .band > .button { order: 1; }
  .sign, .gate, .run-state { order: 2; }
  .sign { flex: 0 1 auto; }
  .brand h1 span { display: none; }
  .gate-number { font-size: 48px; }
  .sign-steer { font-size: 28px; }
}

@media (max-width: 860px) {
  body { height: auto; min-height: 100dvh; }
  .band { gap: 12px 20px; padding: 12px 16px; }
  .band > * + * { padding-left: 0; border-left: 0; }
  .band { position: sticky; z-index: 2; }
  .sign { order: 3; flex: 1 1 100%; }
  .picto-large { width: 52px; height: 52px; }
  .picto-pedal { width: 28px; height: 52px; }
  .run-state { white-space: normal; }
  .sign-detail { white-space: normal; }
  .sign > div, .run-state { min-width: 0; }
  .button, select, input[type="number"], .segmented span { min-height: 44px; }
  input[type="range"] { height: 44px; }
  main { grid-template-columns: minmax(0, 1fr); }
  .stage { grid-template-rows: 62vh auto; }
  .controls { padding: 12px 16px 14px; }
  .column { overflow: visible; border-left: 0; border-top: 1px solid var(--rule); }
  .column section { padding: 20px 16px 22px; }
  .field.speed, .field.circuit { flex: 1 1 100%; width: auto; max-width: none; }
  #help { inset: 16px 16px auto 16px; max-height: calc(100dvh - 32px); }
  .help-list { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .flap { animation: none; }
  .button { transition: none; }
}
