:root {
  --bg: #0d1014;
  --panel: #14181f;
  --panel-2: #1b212b;
  --raised: #222a36;
  --line: #232b38;
  --line-soft: #1b222c;
  --text: #e7ebf3;
  --muted: #8792a5;
  --accent: #4c8dff;
  --accent-soft: rgba(76, 141, 255, .14);
  --ok: #35c46b;
  --warn: #e0a32e;
  --bad: #f2545b;

  --r-sm: 6px;
  --r-md: 9px;
  --r-lg: 14px;
  --pad: 14px;

  --shadow: 0 6px 22px rgba(0, 0, 0, .45);
  --ring: 0 0 0 2px rgba(76, 141, 255, .45);
}

* { box-sizing: border-box; }

/* Must beat the display rules below, or [hidden] elements such as the drive bar
   (display: flex) stay on screen. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* Header and content as grid rows, so the main area is whatever is left over —
   no magic pixel offset to keep in step with the header's padding. */
body {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100dvh;
  overflow: hidden;
}

::selection { background: var(--accent-soft); }

/* Slim scrollbars, so a scrolling panel does not lose 16px to chrome. */
* { scrollbar-width: thin; scrollbar-color: var(--raised) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-thumb {
  background: var(--raised); border-radius: 20px;
  border: 2px solid transparent; background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background: #2f3a4a; background-clip: content-box; }
*::-webkit-scrollbar-track { background: transparent; }

:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--r-sm); }

/* ---------- tooltips ----------
   Attribute-driven, never class-driven: app.js overwrites className on the
   health pills, which would strip a class-based hook.

   Two placements, because the panels scroll. The base rule is an absolutely
   positioned box, which a scrolling ancestor clips — so it is kept narrow enough
   to fit inside the panel it lives in. Where anchor positioning exists it is
   replaced by a fixed-position box, which no ancestor's overflow can clip and
   which flips itself away from an edge instead of being cut off. */
[data-tip] { position: relative; }

[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  top: calc(100% + 7px);
  left: 0;
  z-index: 1200;
  width: max-content;
  /* Fits under a control anywhere in the narrowest panel without overflowing it. */
  max-width: 200px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--raised);
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 11.5px;
  font-weight: 400;
  line-height: 1.45;
  letter-spacing: 0;
  text-align: start;
  text-transform: none;
  white-space: normal;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-3px);
  transition: opacity .13s ease, transform .13s ease, visibility .13s;
  pointer-events: none;
}

/* Right-hand controls would push a start-aligned tooltip past the edge. */
[data-tip][data-tip-align="end"]::after { left: auto; right: 0; }

[data-tip]:hover::after,
[data-tip]:focus-visible::after {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  transition-delay: .28s;
}

/* The scroll-clipping fix. A pseudo-element's implicit anchor is the element it
   belongs to, so no anchor has to be named — which matters here, because every
   [data-tip] would otherwise need a unique anchor-name. position: fixed is what
   escapes the panel's overflow, and the fallbacks flip the box above or across
   the control when the viewport edge is nearer than the tooltip is wide. */
@supports (position-area: block-end) {
  [data-tip]::after {
    position: fixed;
    top: auto; left: auto; right: auto;
    margin: 7px 0;
    max-width: 260px;
    position-area: block-end span-inline-end;
    position-try-fallbacks: flip-block, flip-inline, flip-block flip-inline;
    /* Hide with the control when it scrolls out of the panel, rather than
       leaving a tooltip floating over the page. */
    position-visibility: anchors-visible;
  }

  [data-tip][data-tip-align="end"]::after {
    position-area: block-end span-inline-start;
  }
}

@media (prefers-reduced-motion: reduce) {
  [data-tip]::after { transition: none; transform: none; }
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- top bar ---------- */
.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px var(--pad);
  background: linear-gradient(180deg, #171c24, var(--panel));
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.brand strong {
  font-size: 13.5px; font-weight: 600; letter-spacing: .2px;
  white-space: nowrap;
}

.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted); flex: none;
  transition: background .2s, box-shadow .2s;
}
.dot.running { background: var(--ok); box-shadow: 0 0 0 3px rgba(53, 196, 107, .18); }
.dot.stopping { background: var(--warn); box-shadow: 0 0 0 3px rgba(224, 163, 46, .16); }

.badge {
  font-size: 10px; text-transform: uppercase; letter-spacing: .7px; font-weight: 600;
  padding: 2px 8px; border-radius: 20px;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--line);
  white-space: nowrap;
}

.health { display: flex; align-items: center; gap: 7px; min-width: 0; }

.pill {
  font-size: 11px; padding: 3px 9px; border-radius: 20px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted);
  white-space: nowrap;
}
.pill.ok { color: #7fe6a6; border-color: #1f4a2d; background: rgba(53, 196, 107, .09); }
.pill.bad { color: #ffb1b5; border-color: #5e2529; background: rgba(242, 84, 91, .09); }

/* Icon-only button: the label it lost lives in its tooltip. */
button.icon {
  display: inline-grid; place-items: center;
  width: 30px; height: 30px; padding: 0;
  color: var(--muted);
}
button.icon svg {
  width: 16px; height: 16px;
  fill: none; stroke: currentColor; stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round;
}
button.icon:hover:not(:disabled) { color: var(--text); }

/* ---------- tabs ---------- */
.tabs {
  display: flex; gap: 3px; flex: none;
  padding: 3px;
  background: var(--bg);
  border: 1px solid var(--line); border-radius: 20px;
}

.tab-btn {
  padding: 4px 16px;
  border: 0; border-radius: 20px;
  background: transparent; color: var(--muted);
  font-size: 11.5px; font-weight: 600;
  letter-spacing: .3px;
}
.tab-btn:hover:not(.on) { background: var(--panel-2); color: var(--text); }
.tab-btn.on { background: var(--accent); color: #fff; }

/* ---------- layout ---------- */
main { display: grid; min-height: 0; }

/* Both tabs occupy the same cell; [hidden] carries !important, so it beats the
   display each one sets for itself. */
.tab { grid-area: 1 / 1; min-height: 0; min-width: 0; }

/* The options, as one flat page. auto-fit means a wide window lays the cards out
   side by side and everything is visible at once — which is the point of moving
   the map out — while a narrow one drops to a single column. */
.setup {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  align-content: start;
  /* Cards hug their content, so a short one is not padded out to match the
     tallest in its row. Overridden where there is height to fill — see below. */
  align-items: start;
  gap: 14px;
  padding: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.card {
  display: flex; flex-direction: column;
  min-height: 0;
  padding: 13px var(--pad) 15px;
  background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--r-lg);
}

/* Where there is height to spare, the cards take it and their lists grow into
   it, rather than a row of short cards over a band of dead space. Only above the
   single-column breakpoint: below it the page scrolls, and equal-height rows
   would squash every card to a fraction of the viewport. */
@media (min-width: 901px) {
  .setup {
    align-content: stretch; align-items: stretch;
    grid-auto-rows: minmax(0, 1fr);
  }
  .card .list.tall { flex: 1; min-height: 140px; max-height: none; }
}

/* Map beside its live fleet. */
.map {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
}

.rail {
  display: flex; flex-direction: column;
  min-height: 0; overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--panel);
  border-left: 1px solid var(--line);
}
.rail section {
  display: flex; flex-direction: column;
  min-height: 0; flex: 1;
  padding: 12px var(--pad) 14px;
}

/* Header row: title on the start side, one compact control on the end. */
.head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-bottom: 9px;
}
.head h2 { margin: 0; }

h2 {
  margin: 0 0 9px;
  font-size: 10.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .8px;
  color: var(--muted);
}

.muted { color: var(--muted); font-weight: 400; }
.hint { margin: 9px 0 0; font-size: 11.5px; color: var(--muted); }
.error {
  margin: 9px 0 0; padding: 7px 9px;
  font-size: 11.5px; color: #ffb1b5;
  background: rgba(242, 84, 91, .09);
  border: 1px solid #5e2529; border-radius: var(--r-md);
}

/* One short line of guidance with the rest behind a "?". */
.legend {
  display: flex; align-items: center; gap: 6px;
  margin: 9px 0 0;
  font-size: 11.5px; color: var(--muted);
}

.count {
  flex: none;
  font-size: 10.5px; color: var(--muted);
  padding: 2px 8px; border-radius: 20px;
  background: var(--panel-2); border: 1px solid var(--line);
  white-space: nowrap;
}

code {
  background: var(--panel-2); padding: 1px 5px; border-radius: 4px;
  border: 1px solid var(--line-soft);
  font-size: 11px;
}

/* ---------- controls ---------- */
.row { display: flex; gap: 7px; align-items: center; }
.row.wrap { flex-wrap: wrap; margin-top: 9px; }
.row.end { justify-content: flex-end; margin-top: 16px; }
.grow { flex: 1; }

.grid2 {
  display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 10px;
}

label {
  display: block;
  font-size: 10.5px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .5px; font-weight: 600;
}

.unit { text-transform: none; letter-spacing: 0; opacity: .65; font-weight: 400; }

/* Checkbox + text as one clickable pill, replacing four stacked lines. */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chip, .switch {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px 5px 8px;
  border: 1px solid var(--line); border-radius: 20px;
  background: var(--panel-2);
  font-size: 11.5px; font-weight: 500; color: var(--muted);
  text-transform: none; letter-spacing: 0;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.chip:hover, .switch:hover { border-color: #38445a; color: var(--text); }
.chip:has(:checked), .switch:has(:checked) {
  background: var(--accent-soft); border-color: rgba(76, 141, 255, .45); color: #cfe0ff;
}
.chip:has(:disabled), .switch:has(:disabled) { opacity: .5; cursor: not-allowed; }

.switch { padding: 4px 10px 4px 8px; }

/* Native control, tinted. Drawing our own box means hand-rolling the tick, which
   renders differently in every engine; accent-color is the one-line version that
   cannot be wrong. */
input[type="checkbox"] {
  width: 13px; height: 13px; margin: 0; flex: none;
  accent-color: var(--accent);
  cursor: inherit;
}

input[type="number"], input[type="text"], input[type="search"],
input[type="password"], input:not([type]) {
  width: 100%; margin-top: 5px;
  padding: 6px 9px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r-sm);
  font: inherit;
  transition: border-color .15s, box-shadow .15s;
}
input[type="search"] { margin-top: 0; }
input:hover:not(:disabled) { border-color: #303b4c; }
input:focus-visible { border-color: var(--accent); box-shadow: var(--ring); }
input:disabled { opacity: .5; cursor: not-allowed; }

button {
  padding: 7px 12px;
  border-radius: var(--r-sm); border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text);
  font: inherit; font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
button:hover:not(:disabled) { background: var(--raised); border-color: #38445a; }
button:disabled { opacity: .45; cursor: not-allowed; }

button.primary {
  background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600;
}
button.primary:hover:not(:disabled) { background: #669eff; border-color: #669eff; }

button.danger { background: rgba(242, 84, 91, .13); border-color: #5e2529; color: #ffb1b5; }
button.danger:hover:not(:disabled) { background: rgba(242, 84, 91, .22); border-color: #7a2f35; }

button.ghost { background: transparent; }
button.ghost:hover:not(:disabled) { background: var(--panel-2); }

/* The "?" that replaced a paragraph. */
button.info {
  display: inline-grid; place-items: center; flex: none;
  width: 16px; height: 16px; padding: 0;
  border-radius: 50%; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--muted);
  font-size: 10px; font-weight: 700; line-height: 1;
}
button.info:hover { color: var(--text); border-color: #38445a; background: var(--raised); }

/* ---------- lists ---------- */
.list {
  margin-top: 10px;
  max-height: 300px; overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--bg);
}
/* Fills the rail instead of capping at 300px (fleet list). */
.list.grow { flex: 1; min-height: 120px; max-height: none; }
/* A card has the height a squeezed sidebar did not, so the lists inside it show
   more rows before they start scrolling. */
.list.tall { max-height: min(46dvh, 420px); }

.item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 9px;
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
  transition: background .12s;
}
.item:last-child { border-bottom: 0; }
.item:hover { background: var(--panel-2); }
.item.selected { background: var(--accent-soft); box-shadow: inset 2px 0 0 var(--accent); }

.item .who { min-width: 0; flex: 1; }
.item .name {
  display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-size: 12px;
}
.item .sub {
  display: block; font-size: 10.5px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.item .tag {
  flex: none;
  font-size: 10px; padding: 1px 6px; border-radius: 4px;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--line);
  white-space: nowrap;
}
.item .tag.gf { color: #ffd9a0; border-color: #5c4426; background: rgba(224, 163, 46, .1); }
.item .tag.area { color: #a9d3ff; border-color: #26405c; background: rgba(76, 141, 255, .1); }
.item .tag.manual { color: #ffc9c9; border-color: #6d2f36; background: rgba(242, 84, 91, .1); }
.item .tag.turns { color: #a9d3ff; border-color: #2b4d70; background: rgba(76, 141, 255, .1); }
.item .tag.off { color: #b9a0a0; }
.item .tag.speed { color: #9fe8d8; border-color: #1f4a44; background: rgba(53, 196, 168, .1); }

.swatch {
  width: 9px; height: 9px; border-radius: 3px;
  flex: none; border: 1px solid rgba(255, 255, 255, .2);
}

/* Row-level action, small enough not to compete with the row itself. */
.item .mini {
  flex: none;
  padding: 2px 7px;
  font-size: 10px; letter-spacing: .3px;
  color: var(--muted);
  background: transparent;
}
.item .mini:hover { color: var(--text); border-color: #38445a; }
.item .mini.on {
  color: #ffd166; border-color: #5c4426; background: rgba(255, 209, 102, .12);
}

.empty { padding: 16px; text-align: center; color: var(--muted); font-size: 11.5px; }

/* ---------- map ---------- */
.mapwrap { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: #0a0d11; }

.overlay {
  position: absolute; z-index: 500;
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px;
  background: rgba(20, 24, 31, .93);
  border: 1px solid var(--line); border-radius: var(--r-md);
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
}
/* Both map bars share one centred column, so drawing a path for the device that
   is also selected stacks the two bars instead of overlapping them. The column
   itself must not swallow map clicks — only the bars inside it take pointers. */
.overlay-stack {
  position: absolute; z-index: 500;
  top: 12px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  max-width: calc(100% - 24px);
  pointer-events: none;
}
.overlay-stack > .overlay { position: static; pointer-events: auto; flex-wrap: wrap; justify-content: center; }

#driveBar span, #drawBar span { font-size: 12px; }
#driveBar strong, #drawBar strong { font-size: 12px; }
#driveHint { color: var(--muted); }
#drawBar strong { color: #ffd166; }

/* Map bars stack at the top, so their tooltips open upward rather than covering
   the bar below them. */
.overlay [data-tip]::after { top: auto; bottom: calc(100% + 7px); }
.overlay [data-tip]:hover::after { transform: translateY(0); }

@supports (position-area: block-end) {
  .overlay [data-tip]::after {
    bottom: auto;
    position-area: block-start span-inline-end;
    position-try-fallbacks: flip-block, flip-inline, flip-block flip-inline;
  }
  .overlay [data-tip][data-tip-align="end"]::after {
    position-area: block-start span-inline-start;
  }
}

/* Says why a click did nothing, where the clicking happened. Read-only, so it
   must not intercept the next click — it sits over the middle of the map. */
.toast {
  bottom: 12px; left: 50%; transform: translateX(-50%);
  max-width: min(560px, 78%);
  font-size: 11.5px; line-height: 1.45;
  border-color: #5c4426; background: rgba(36, 30, 18, .94);
  pointer-events: none;
}

/* View toggles, on the view. Top-right so they clear Leaflet's zoom control. */
.layers {
  top: 12px; right: 12px;
  flex-wrap: wrap; gap: 6px;
  max-width: 240px;
  justify-content: flex-end;
}

/* Two numbers on a bar, not a stacked form field: the base input rule is full
   width, which would push the rest of the draw bar off the map. */
.seg.speeds input[type="number"] {
  width: 56px;
  margin-top: 0;
  padding: 3px 6px;
  text-align: center;
  font-size: 11.5px;
}
/* The spinners are 20px of chrome on a 56px field, and the step arrows are not
   how anyone sets a speed here. */
.seg.speeds input[type="number"] { appearance: textfield; }
.seg.speeds input::-webkit-outer-spin-button,
.seg.speeds input::-webkit-inner-spin-button { appearance: none; margin: 0; }
.seg.speeds .unit { font-size: 10.5px; }

/* Grouped buttons, so the mode switch reads as one control. */
.seg {
  display: inline-flex; gap: 4px; align-items: center;
  padding: 3px; border-radius: var(--r-sm);
  background: rgba(255, 255, 255, .04);
}
.seg > .muted { padding-left: 5px; }

/* Also read-only: a click over the counters is a click on the map. */
.stats {
  bottom: 12px; left: 12px;
  gap: 14px; font-size: 11px; color: var(--muted);
  max-width: calc(100% - 24px); flex-wrap: wrap;
  pointer-events: none;
}

/* Leaflet dark tweaks */
.leaflet-container { background: #0a0d11; font: inherit; }
.leaflet-control-attribution {
  background: rgba(13, 16, 20, .82) !important; color: var(--muted) !important;
}
.leaflet-control-attribution a { color: var(--muted) !important; }
.leaflet-bar { border: 0 !important; box-shadow: var(--shadow) !important; }
.leaflet-bar a {
  background: var(--panel) !important; color: var(--text) !important;
  border-color: var(--line) !important;
}
.leaflet-bar a:hover { background: var(--raised) !important; }

.marker-arrow {
  width: 0; height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 13px solid var(--accent);
  filter: drop-shadow(0 0 2px rgba(0, 0, 0, .7));
  transform-origin: 50% 70%;
}
.marker-arrow.manual { border-bottom-color: #f0a852; }
.marker-arrow.offline { border-bottom-color: #6b7280; }
.marker-arrow.picked { border-bottom-color: #ff5f8f; }

.node-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: #9aa6bd; border: 2px solid #0d1014;
}
.node-dot.picked { background: #ffd166; }

/* Labels and direction glyphs sit over the waypoint dots, so they must let the
   click through to the dot underneath. */
.map-glyph { pointer-events: none; }

/* Direction of travel, on the line itself. */
.leg-arrow {
  width: 0; height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-bottom: 9px solid #9aa6bd;
  transform-origin: 50% 60%;
  filter: drop-shadow(0 0 1px rgba(0, 0, 0, .85));
}

.end-dot {
  display: flex; align-items: center; justify-content: center;
  width: 17px; height: 17px; border-radius: 50%;
  font-size: 9px; font-weight: 700; line-height: 1;
  color: #0d1014; border: 2px solid #0d1014;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .6);
}
.end-dot.start { background: var(--ok); }
/* What happens at the end: parks there, turns round, or is simply the last of
   the stops it calls at in random order. */
.end-dot.parks { background: var(--bad); color: #2a0c0c; }
.end-dot.turns { background: var(--accent); color: #05142e; }
.end-dot.plain { background: #9aa6bd; }
.end-dot.loop { background: #ffd166; font-size: 11px; }

/* ---------- dialog ---------- */
dialog {
  width: min(560px, 94vw);
  max-height: 90dvh;
  overflow-y: auto;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: 18px;
}
dialog::backdrop { background: rgba(0, 0, 0, .6); backdrop-filter: blur(2px); }
dialog .head { margin-bottom: 4px; justify-content: flex-start; gap: 7px; }
dialog h2 { font-size: 12px; }
dialog label { margin-top: 10px; }
dialog .switch { margin-top: 12px; }

fieldset {
  margin: 14px 0 0; padding: 4px 12px 12px;
  border: 1px solid var(--line-soft); border-radius: var(--r-md);
  background: rgba(255, 255, 255, .015);
}
legend {
  padding: 0 6px;
  font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .8px;
  color: var(--muted);
}
fieldset .grid2 { margin-top: 4px; }

/* ---------- responsive ----------
   Leaflet tracks window resize itself, so a breakpoint change re-measures the
   map without help. The one resize it cannot see is the tab switch, which
   showTab() handles by calling invalidateSize. */
@media (max-width: 1280px) {
  :root { --pad: 12px; }
  .map { grid-template-columns: minmax(0, 1fr) 272px; }
}

@media (max-width: 900px) {
  /* Fleet under the map rather than beside it — a 270px rail beside a map this
     narrow leaves neither enough room. */
  .map {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
  }
  .rail {
    border-left: 0; border-top: 1px solid var(--line);
    max-height: 34dvh;
  }
  .rail section { flex: none; }
  .list.grow { max-height: 200px; }
  .layers { max-width: calc(100% - 24px); }
}

@media (max-width: 760px) {
  .setup { padding: 12px; gap: 12px; }
  .bar {
    position: sticky; top: 0; z-index: 900;
    flex-wrap: wrap; justify-content: center;
  }
  .tabs { order: 3; width: 100%; justify-content: center; }
  .brand { flex: 1; }
  .health { flex-wrap: wrap; justify-content: flex-end; }
  /* Wider tooltips read better once a card is full width. */
  [data-tip]::after { max-width: min(300px, 78vw); }
}

@media (max-width: 420px) {
  .grid2 { grid-template-columns: 1fr; }
  .brand strong { font-size: 12.5px; }
  .stats { gap: 8px; }
  .health .pill { font-size: 10px; padding: 2px 7px; }
}

/* Touch and keyboard: a tooltip that needs hover is no use, so tapping the "?"
   focuses it and shows the same text. */
@media (hover: none) {
  [data-tip]:active::after { opacity: 1; visibility: visible; transition-delay: 0s; }
}
