:root {
  --bg: #12151c;
  --panel: #1a1e27;
  --grid: #2b313d;
  --text: #e6e8ec;
  --muted: #8a92a3;
  --accent: #f5c518;
  --turn: #5b8def;
  --fade: #e5484d;
  color-scheme: dark;
  font: 14px/1.4 system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100vh;
  display: grid;
  grid-template-columns: 280px 1fr;
  /* fill the window exactly; otherwise content like the chart's svg, which
     has a fixed size, can grow the row and scroll the page */
  grid-template-rows: minmax(0, 1fr);
  background: var(--bg);
  color: var(--text);
}

h1 {
  font-size: 18px;
  margin: 0 0 12px;
}

/* focusable only so the drawer can take focus when it opens */
#filters:focus {
  outline: none;
}

#filters {
  background: var(--panel);
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

fieldset {
  border: 1px solid var(--grid);
  border-radius: 6px;
  margin: 0;
  padding: 8px 10px 10px;
}

legend {
  color: var(--muted);
  padding: 0 4px;
}

input[type="search"],
select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--grid);
  border-radius: 4px;
  padding: 5px 7px;
  font: inherit;
  width: 100%;
}

/* two-handle sliders: two range inputs stacked on one track, with only their
   thumbs taking pointer events */

.ranges {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.range-head {
  display: flex;
  justify-content: space-between;
}

.range output {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.range.active output {
  color: var(--accent);
}

.dual {
  --thumb: 14px;
  position: relative;
  height: calc(var(--thumb) + 6px);
}

/* big enough to grab with a finger */
@media (pointer: coarse) {
  .dual {
    --thumb: 24px;
  }

  .check {
    padding: 4px 0;
  }
}

/* inset by half a thumb, since that's where the thumb centers travel */
.dual::before {
  content: "";
  position: absolute;
  left: calc(var(--thumb) / 2);
  right: calc(var(--thumb) / 2);
  top: calc(var(--thumb) / 2 + 1px);
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(
    to right,
    var(--grid) var(--lo, 0%),
    var(--muted) var(--lo, 0%) var(--hi, 100%),
    var(--grid) var(--hi, 100%)
  );
}

.range.active .dual::before {
  background: linear-gradient(
    to right,
    var(--grid) var(--lo),
    var(--accent) var(--lo) var(--hi),
    var(--grid) var(--hi)
  );
}

.dual input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  appearance: none;
  background: none;
  pointer-events: none;
}

.dual input::-webkit-slider-runnable-track {
  height: 100%;
  background: none;
}

.dual input::-moz-range-track {
  background: none;
}

.dual input::-webkit-slider-thumb {
  appearance: none;
  pointer-events: auto;
  width: var(--thumb);
  height: var(--thumb);
  margin-top: 3px;
  border-radius: 50%;
  background: var(--text);
  border: 2px solid var(--panel);
  cursor: grab;
}

.dual input::-moz-range-thumb {
  pointer-events: auto;
  width: var(--thumb);
  height: var(--thumb);
  box-sizing: border-box;
  border-radius: 50%;
  background: var(--text);
  border: 2px solid var(--panel);
  cursor: grab;
}

.dual input:active::-webkit-slider-thumb {
  cursor: grabbing;
}

.dual input:focus-visible {
  outline: none;
}

.dual input:focus-visible::-webkit-slider-thumb {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.dual input:focus-visible::-moz-range-thumb {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.checks {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.check {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

/* display: flex would otherwise beat the hidden attribute, which the brand
   search uses to filter the list */
.check[hidden] {
  display: none;
}

.brands {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#brands {
  max-height: 320px;
  overflow-y: auto;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid;
  flex: none;
}

.n {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
}

button {
  font: inherit;
  color: var(--text);
  background: var(--grid);
  border: none;
  border-radius: 4px;
  padding: 6px 10px;
  cursor: pointer;
}

button.link {
  background: none;
  color: var(--accent);
  padding: 0 2px;
}

main {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

#toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--grid);
}

#toolbar select {
  width: auto;
  margin-left: 4px;
}

/* no taller than a line of text, so showing it doesn't resize the toolbar */
#reset-zoom {
  padding: 0 8px;
  font-size: 12px;
  line-height: 20px;
}

/* the display controls are a group only so a narrow screen can move them into
   the filters drawer; here they sit in the toolbar as if ungrouped, with the
   legend, which is often empty, at the end */
#display {
  display: contents;
}

#legend {
  order: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  font-size: 12px;
}

.key-text {
  color: var(--muted);
  font-size: 12px;
  margin-left: -10px;
}

/* the svg is positioned absolutely so its size, set from the container's,
   never feeds back into the container's. Only the plot's own svg: the single
   disc panel lives in here too, and its flight path must stay in its flow */
#chart {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: auto;
}

#chart > svg {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  cursor: crosshair;
  /* brushing is mouse only, so let a finger pan and pinch zoom the page */
  touch-action: manipulation;
  user-select: none;
}

/* the 3D chart's canvas, which the 2D chart's svg makes way for */
#chart > canvas {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  touch-action: none;
}

body.view-3d #chart > svg,
body:not(.view-3d) #chart > canvas {
  display: none;
}

/* the 3D chart has no brush zoom, ghosts or turn and fade lines, so the
   controls and key for them go */
body.view-3d :is(#zoom-hint, #reset-zoom, .key, .key-text, label:has(#ghosts)) {
  display: none;
}

.brush {
  fill: var(--accent);
  fill-opacity: 0.1;
  stroke: var(--accent);
  stroke-dasharray: 4 3;
  pointer-events: none;
}

#zoom-hint {
  font-size: 12px;
}

#empty {
  position: absolute;
  top: 50%;
  left: 50%;
  translate: -50% -50%;
  color: var(--muted);
  text-align: center;
  background: #0b0d12ee;
  border: 1px solid var(--grid);
  border-radius: 8px;
  padding: 4px 20px 16px;
}

/* chart */

.axis .grid {
  stroke: var(--grid);
}

.axis .zero {
  stroke: var(--accent);
  stroke-dasharray: 4 4;
  opacity: 0.6;
}

.axis text {
  fill: var(--muted);
  font-size: 12px;
}

.axis .stability-icon path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.axis .axis-title {
  fill: var(--text);
  font-size: 13px;
}

.ghost {
  fill: #4a5162;
  opacity: 0.35;
}

.turn,
.key-turn {
  stroke: var(--turn);
  stroke-width: var(--turn-w, 6px);
  stroke-linecap: round;
  stroke-opacity: calc(0.35 * var(--k, 1));
}

.fade,
.key-fade {
  stroke: var(--fade);
  stroke-width: 1.5;
  stroke-opacity: calc(0.85 * var(--k, 1));
}

.key-dot {
  fill: #9b6bff;
  stroke: var(--text);
}

/* the cursor is set on the svg instead, since the hit area is wider than the dot */
.disc {
  stroke-width: 1.5;
}

.lines g.hover line {
  stroke-opacity: 1;
}

.lines g.hover .turn {
  stroke-opacity: 0.6;
}

.disc.hover {
  stroke: var(--text);
  stroke-width: 2.5;
}

.label {
  fill: var(--text);
  font-size: 11px;
  pointer-events: none;
  paint-order: stroke;
  stroke: var(--bg);
  stroke-width: 3px;
  stroke-linejoin: round;
}

#tooltip {
  position: absolute;
  pointer-events: none;
  background: #0b0d12ee;
  border: 1px solid var(--grid);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  max-width: 260px;
  z-index: 1;
}

/* the four flight numbers, each under its name */
.ratings {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  margin: 6px 0;
}

.ratings div {
  background: #ffffff0f;
  border: 1px solid var(--grid);
  border-radius: 5px;
  padding: 3px 0;
  text-align: center;
}

.ratings span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.ratings b {
  font-variant-numeric: tabular-nums;
  font-size: 16px;
}

/* the estimated flight path */
.flight svg {
  display: block;
  width: 100%;
  height: 100%;
}

.flight-centre {
  stroke: var(--grid);
  stroke-width: 2;
  stroke-dasharray: 10 10;
}

.flight-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 7;
  stroke-linecap: round;
}

.flight-land {
  fill: var(--accent);
}

.flight-tee {
  fill: var(--muted);
}

.flight figcaption {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
}

.hand-toggle button {
  background: none;
  color: var(--muted);
  border: 1px solid var(--grid);
  border-radius: 4px;
  padding: 1px 6px;
  font: inherit;
  cursor: pointer;
}

.hand-toggle button[aria-pressed="true"] {
  background: var(--grid);
  color: var(--text);
}

.muted {
  color: var(--muted);
}

/* the about link sits at the foot of the sidebar, or after the brands when
   they're long enough to scroll */
#about-link {
  margin-top: auto;
  align-self: flex-start;
}

/* detail and about dialogs */

#detail,
#about {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--grid);
  border-radius: 8px;
  width: min(560px, 90vw);
  padding: 20px;
}

#detail::backdrop,
#about::backdrop {
  background: #0008;
}

#detail .close,
#about .close {
  float: right;
  font-size: 20px;
  line-height: 1;
  background: none;
}

/* shared by the dialog and the panel the chart shows for a single disc */
.card h2 {
  margin: 0 0 4px;
}

.card .flight {
  float: right;
  width: 150px;
  margin: 0 0 8px 14px;
}

.card .flight svg {
  height: 230px;
}

/* the tooltip's copy is a glance, not a control: no toggle, and it only earns
   its space on a screen wide enough to have it */
#tooltip .flight figcaption,
#tooltip .flight-tee {
  display: none;
}

#tooltip .flight svg {
  height: 150px;
}

@media (max-width: 900px) {
  #tooltip .flight {
    display: none;
  }
}

.card dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 12px;
  font-size: 13px;
}

.card dt {
  color: var(--muted);
}

.card dd {
  margin: 0;
}

.card a {
  color: var(--accent);
}

/* one disc leaves the chart with almost nothing to draw, so its details take
   the space instead. Anchored inside #chart, which is the plot area below the
   toolbar, and scrolls rather than growing past it. */
#inline-detail {
  display: flex;
  flex-direction: column;
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  width: min(300px, 45%);
  max-height: calc(100% - 24px);
  overflow-y: auto;
  padding: 12px 14px;
  background: #0b0d12f2;
  border: 1px solid var(--grid);
  border-radius: 8px;
  font-size: 13px;
}

/* display: flex would otherwise beat the hidden attribute */
#inline-detail[hidden] {
  display: none;
}

/* too narrow to float the flight path beside the specs, so it gets its own
   full width row, moved up under the four numbers it's drawn from */
#inline-detail > * {
  order: 1;
}

#inline-detail > :is(h2, .muted, .ratings) {
  order: 0;
}

#inline-detail .flight {
  float: none;
  width: auto;
  margin: 4px 0 8px;
}

#inline-detail img {
  width: 88px;
  margin: 0 0 6px 10px;
}

#inline-detail h2 {
  font-size: 18px;
}

/* only a phone collapses the single disc panel */
#inline-detail .expand {
  display: none;
}

/* the card a tap on a disc opens, docked at the foot of the chart: the
   tooltip's summary, its flight beside it, and a way to the full card */
#peek {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  z-index: 3;
  max-width: 480px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  padding: 10px 12px;
  /* opaque, or the labels of the discs under it read through */
  background: #0b0d12;
  border: 1px solid var(--grid);
  border-radius: 8px;
  font-size: 13px;
}

#peek[hidden] {
  display: none;
}

#peek .flight {
  grid-column: 2;
  grid-row: 1 / 3;
  align-self: end;
  width: 64px;
}

#peek .flight svg {
  height: 120px;
}

#peek .flight figcaption,
#peek .flight-tee {
  display: none;
}

.peek-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.peek-details {
  padding: 8px 16px;
}

.peek-close {
  position: absolute;
  top: 2px;
  right: 2px;
  background: none;
  font-size: 22px;
  line-height: 1;
  padding: 4px 10px;
}

/* the narrow screen layout's parts, which a wide screen doesn't use */
.bar-title,
#open-filters,
#display-fieldset,
#show-discs,
#drawer-backdrop {
  display: none;
}

/* a phone: the chart gets the whole screen, and the filters become a drawer
   from the left, opened from a compact top bar. A phone on its side is wide
   enough for the sidebar but too short for it, so a short screen counts too.
   Keep in step with narrow in app.js. See
   docs/plans/2026-10-05-mobile-design.md */
@media (max-width: 700px), (max-height: 500px) {
  /* dvh, since on iOS vh includes the area behind the address bar, and would
     push the chart's bottom edge off screen */
  body {
    grid-template-columns: 1fr;
    height: 100dvh;
  }

  #filters {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    width: min(320px, 85vw);
    padding-bottom: 0;
    translate: -100%;
    visibility: hidden;
    transition:
      translate 0.2s ease,
      visibility 0s 0.2s;
  }

  body.drawer-open #filters {
    translate: 0;
    visibility: visible;
    transition: translate 0.2s ease;
  }

  body.drawer-open #drawer-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 19;
    background: #0008;
  }

  #display-fieldset {
    display: block;
  }

  /* in the drawer the display controls stack, one per line */
  #display {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  .key-text {
    margin-left: 0;
  }

  /* pinned to the drawer's foot, however far the brands have scrolled it */
  #show-discs {
    display: block;
    position: sticky;
    bottom: 0;
    margin: 0 -16px;
    padding: 12px;
    border-radius: 0;
    background: var(--accent);
    color: var(--bg);
    font-weight: 600;
  }

  #toolbar {
    flex-wrap: nowrap;
    gap: 10px;
    padding: 8px 12px;
  }

  .bar-title {
    display: inline;
    white-space: nowrap;
  }

  /* the count gives way first when a zoomed bar runs short of room */
  #count {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: normal;
    color: var(--muted);
    font-size: 13px;
    white-space: nowrap;
  }

  #relaxed,
  #zoom-hint,
  .esc-hint {
    display: none;
  }

  #reset-zoom {
    margin-left: auto;
    white-space: nowrap;
  }

  #open-filters {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
  }

  #reset-zoom:not([hidden]) + #open-filters {
    margin-left: 0;
  }

  #filter-badge {
    min-width: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--accent);
    color: var(--bg);
    font-size: 12px;
    font-weight: 600;
    line-height: 18px;
    text-align: center;
  }

  #filter-badge[hidden] {
    display: none;
  }

  /* the full card is a sheet covering the screen, with its close button kept
     in reach however far it's scrolled */
  #detail {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border: none;
    border-radius: 0;
    padding: 0 16px 24px;
  }

  #detail > form {
    position: sticky;
    top: 0;
    z-index: 1;
    display: flex;
    justify-content: flex-end;
    margin: 0 -16px;
    padding: 6px 8px;
    background: var(--panel);
  }

  #detail .close {
    float: none;
    padding: 6px 12px;
  }

  /* as in the single disc panel: the flight path gets its own row, under the
     four numbers it's drawn from */
  #detail-body {
    display: flex;
    flex-direction: column;
  }

  #detail-body > * {
    order: 1;
  }

  #detail-body > :is(h2, .muted, .ratings) {
    order: 0;
  }

  #detail-body .flight {
    float: none;
    width: auto;
    margin: 4px 0 8px;
  }

  #detail-body .flight svg {
    height: 200px;
  }

  /* the single disc panel docks at the chart's foot like the peek card, showing
     just the disc's name and numbers until it's expanded */
  #inline-detail {
    top: auto;
    left: 8px;
    right: 8px;
    bottom: 8px;
    width: auto;
    max-height: 45%;
    background: #0b0d12;
  }

  #inline-detail.expanded {
    max-height: calc(100% - 16px);
  }

  #inline-detail:not(.expanded) > :not(h2, .muted, .ratings, .expand) {
    display: none;
  }

  #inline-detail .expand {
    display: block;
    align-self: flex-start;
    order: 0;
    margin-top: 4px;
  }
}
