/* ===== circuit select ===== */


  .masthead.stacked { flex-direction: column; align-items: flex-start; gap: 3px; }
  .masthead.stacked .row { display: flex; align-items: center; gap: 10px; }
  .masthead.stacked .sub { font-size: 13px; }

  .hub-about {
    display: block; width: 100%; border: 0; border-top: 1px solid var(--panel-edge);
    background: transparent; color: var(--dim); cursor: pointer;
    padding: 18px 16px calc(env(safe-area-inset-bottom) + 22px);
    font-family: var(--mono); font-size: 13px; letter-spacing: 1.5px;
    text-transform: uppercase;
  }
  .hub-about:active { color: var(--text); }

  .tier-bar { display: flex; border-bottom: 1px solid var(--panel-edge); }
  .tier-tab {
    flex: 1; padding: 10px 4px; text-align: center; cursor: pointer;
    border-right: 1px solid var(--panel-edge);
  }
  .tier-tab:last-child { border-right: 0; }
  .tier-tab .n {
    font-family: var(--display); font-size: 18px; font-weight: 600;
    letter-spacing: 2px; color: var(--dim);
  }
  .tier-tab.on { background: var(--panel); }
  .tier-tab.on .n { color: var(--text); }
  .tier-tab.locked .n { opacity: .35; }
  .tier-tab .p { font-size: 12px; color: var(--dim); font-variant-numeric: tabular-nums; }

  .tier-note {
    padding: 10px 16px; font-size: 14px; color: var(--dim);
    border-bottom: 1px solid var(--panel-edge);
  }
  .tier-note b { color: var(--orange); font-weight: 500; }

  .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--panel-edge); }

  .card { background: var(--bg); padding: 12px; cursor: pointer; position: relative; }
  .card.locked { opacity: .3; pointer-events: none; }
  .card canvas { display: block; width: 100%; height: auto; }
  .card .rnd {
    position: absolute; top: 10px; right: 12px;
    font-size: 12px; color: var(--dim); font-variant-numeric: tabular-nums;
  }
  .card .nm {
    font-family: var(--display); font-size: 21px; font-weight: 600;
    letter-spacing: 1.5px; text-transform: uppercase; margin-top: 6px;
  }
  .card .meta { display: flex; justify-content: space-between; align-items: baseline; margin-top: 3px; }
  .card .meta .c { font-size: 13px; color: var(--dim); }
  .card .meta .r { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
  .card .pips { display: flex; gap: 2px; margin-top: 7px; }
  .card .pips i { width: 100%; height: 3px; background: var(--panel-edge); }

  .season {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 16px; border-top: 1px solid var(--panel-edge); margin-top: 1px;
  }
  .season .k { font-size: 12px; letter-spacing: 2px; color: var(--dim); text-transform: uppercase; }
  .season .v {
    font-family: var(--display); font-size: 30px; font-weight: 600;
    font-variant-numeric: tabular-nums;
  }

/* ===== race ===== */

  html, body {
    width: 100%; height: 100%; overflow: hidden;
    background: #06060c;          /* covers the safe-area insets */
    overscroll-behavior: none;
  }

  /* Each view owns its own scrolling: the race must not move, the circuit
     list is taller than a phone and has to. */
  #hub {
    height: 100%;
    overflow-y: auto;
    padding-bottom: calc(env(safe-area-inset-bottom) + 12px);
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
  }
  /* The masthead and the tier tabs stay put while the calendar scrolls under
     them: the list is four screens long, and which tier you are looking at is
     the one thing you need on screen the whole way down. */
  #hub .masthead,
  #hub .tier-bar {
    position: sticky;
    z-index: 5;
    background: var(--bg);
  }
  #hub .masthead { top: 0; }
  #hub .tier-bar { top: var(--masthead-h, 92px); }
  #race { height: 100%; position: relative; }
  /* Only the track swallows gestures. The briefing above it has to scroll. */
  canvas { display: block; width: 100%; height: 100%; }
  /* ONLY the race canvases swallow gestures. This used to be on every canvas
     on the page, which included the little circuit map on each card — so a
     drag that began on a map, and most of a card is map, did not scroll the
     calendar. It scrolled only if you happened to start on the text. */
  #game, #game3d { touch-action: none; }
  /* The two renderers share the frame: WebGL draws the world underneath, and
     the 2D canvas stays on top for the things that live in screen space, like
     the start lights. A canvas can only ever hand out one kind of context, so
     they have to be two elements. */
  #game3d, #race > #game { position: absolute; inset: 0; }
  #game3d { z-index: 0; }
  #race > #game { z-index: 1; }
  #overlay { touch-action: pan-y; }

  #hud { position: fixed; top: 0; left: 0; right: 0; z-index: 10; pointer-events: none; }
  #hud .strip, #hud .deltaline { pointer-events: none; }

  /* The tier you have just opened, and the quieter rerun under the primary
     action once that slot is taken by the next circuit. */
  .unlocked {
    margin-top: 10px; text-align: center;
    font-family: var(--display); letter-spacing: .08em; text-transform: uppercase;
    color: var(--purple); font-size: 15px;
  }
  .again { text-align: center; margin-top: 10px; }
  .again .link {
    background: none; border: 0; color: var(--dim);
    font-family: var(--display); letter-spacing: .06em; text-transform: uppercase;
    font-size: 14px; padding: 6px 10px; cursor: pointer;
  }

  #overlay, #results {
    position: fixed; inset: 0; z-index: 30;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    background: var(--bg); padding: 24px;
  }
  #overlay.hidden, #results.hidden { display: none; }

  /* ---- circuit briefing ---- */
  #overlay {
    justify-content: flex-start; padding: 0; overflow-y: auto;
  }
  .brief {
    width: 100%; max-width: 440px; margin: 0 auto;
    padding: calc(env(safe-area-inset-top) + 10px) 18px calc(env(safe-area-inset-bottom) + 14px);
  }
  .brief-top {
    display: flex; justify-content: space-between; align-items: center;
    font-size: 12px; letter-spacing: 2px; text-transform: uppercase; color: var(--dim);
  }
  .brief-back, .brief-sound {
    background: none; border: 0; color: var(--dim); cursor: pointer;
    font-family: var(--mono); font-size: 12px; letter-spacing: 2px;
    text-transform: uppercase; padding: 4px 0;
  }
  .brief-sound { border: 1px solid var(--panel-edge); padding: 6px 10px; }
  .brief-sound.on { color: var(--text); }
  .brief-round {
    font-size: 12px; letter-spacing: 3px; text-transform: uppercase;
    color: var(--dim); margin-bottom: 5px;
  }
  .brief-round b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

  .brief-name {
    font-family: var(--display); font-size: 44px; font-weight: 700;
    letter-spacing: 2px; text-transform: uppercase; line-height: 1; margin-top: 10px;
  }
  .brief-full { font-size: 14px; color: var(--dim); margin-top: 6px; }
  .brief-country {
    display: flex; align-items: center; gap: 9px; margin-top: 12px;
    font-size: 13px; letter-spacing: 2px; text-transform: uppercase;
  }

  .brief-maphead {
    display: flex; justify-content: space-between; align-items: baseline;
    margin: 16px 0 4px; padding-top: 12px; border-top: 1px solid var(--panel-edge);
    font-size: 12px; letter-spacing: 2px; text-transform: uppercase; color: var(--dim);
  }
  .brief-map { display: block; width: 100%; }
  .brief-key {
    display: flex; gap: 20px; margin-top: 6px;
    font-size: 11px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--dim);
  }
  .brief-key span { display: flex; align-items: center; gap: 7px; }
  .k-zone { width: 10px; height: 10px; border-radius: 50%; background: var(--yellow); }
  .k-sf { width: 4px; height: 12px; background: var(--green); }

  .brief-stats {
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px;
    margin: 12px 0; padding: 12px 0;
    border-top: 1px solid var(--panel-edge); border-bottom: 1px solid var(--panel-edge);
  }
  .brief-stats > div { display: flex; flex-direction: column; gap: 5px; }
  .brief-stats .k { font-size: 10px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--dim); }
  .brief-stats .v {
    font-family: var(--display); font-size: 28px; font-weight: 600;
    font-variant-numeric: tabular-nums; line-height: 1;
  }
  .brief-stats .v small { font-size: 12px; color: var(--dim); margin-left: 2px; }
  .brief-stats .v.best { color: var(--purple); }

  .brief-nick {
    display: inline-block; font-size: 12px; letter-spacing: 2.5px;
    text-transform: uppercase; color: var(--yellow);
    border-left: 3px solid var(--yellow); padding-left: 10px;
  }
  .brief-trivia {
    font-size: 15px; line-height: 1.5; color: #b8bcc4; margin: 9px 0 16px;
  }

  .brief-go {
    display: flex; align-items: center; justify-content: center; gap: 12px;
    width: 100%; padding: 17px; cursor: pointer;
    background: var(--orange); border: 0; color: #0b0b0f;
    font-family: var(--display); font-size: 27px; font-weight: 700;
    letter-spacing: 3px; text-transform: uppercase;
  }

  /* ---- results: the screenshot people share ---- */
  #results { justify-content: flex-start; padding-top: calc(env(safe-area-inset-top) + 28px); }
  #results h2 {
    font-family: var(--display); font-size: 32px; font-weight: 700;
    letter-spacing: 4px; text-transform: uppercase; margin-bottom: 4px;
  }
  #results .subhead { font-size: 13px; letter-spacing: 2.5px; color: var(--dim); text-transform: uppercase; margin-bottom: 20px; }
  #results .dnf { color: var(--orange); }
  #results .rows { width: 100%; max-width: 360px; }
  #results .row {
    display: grid; grid-template-columns: 26px 1fr 84px 42px;
    align-items: center; gap: 10px;
    padding: 7px 0; border-bottom: 1px solid var(--panel-edge);
    font-size: 15px;
  }
  #results .row .idx { color: var(--dim); font-size: 12px; }
  #results .row .nm { font-family: var(--display); font-size: 20px; letter-spacing: 1.5px; text-transform: uppercase; }
  #results .row .sc { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
  /* brake trace: where you braked against the optimal point */
  #results .trace { position: relative; height: 10px; background: #101016; border: 1px solid var(--panel-edge); }
  #results .trace .opt { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--text); opacity: .55; }
  #results .trace .you { position: absolute; top: 1px; bottom: 1px; width: 3px; }
  /* ---- the classification: who beat you, and by how much ---- */
  #results .cl-h {
    width: 100%; max-width: 360px; margin: 20px 0 6px;
    font-size: 11px; letter-spacing: 2.5px; text-transform: uppercase; color: var(--dim);
    display: flex; justify-content: space-between;
  }
  /* Two panes, one swipe. The scroller IS the gesture — snap points mean it
     can never rest between the two, and the browser does the physics. */
  #results .cl-swipe {
    width: 100%; max-width: 360px;
    display: flex; overflow-x: auto; scroll-snap-type: x mandatory;
    scrollbar-width: none; -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }
  #results .cl-swipe::-webkit-scrollbar { display: none; }
  #results .cl-pane { flex: 0 0 100%; scroll-snap-align: start; }
  #results .cl-tab {
    cursor: pointer; color: var(--dim); padding: 2px 0;
    border-bottom: 1px solid transparent;
  }
  #results .cl-tab.on { color: var(--text); border-bottom-color: var(--purple); }
  #results .class-table { width: 100%; max-width: 360px; }
  #results .cl-row {
    display: grid; grid-template-columns: 30px 38px 1fr 34px 26px;
    align-items: center; gap: 8px;
    padding: 5px 0; border-bottom: 1px solid var(--panel-edge);
    font-size: 14px; color: #b8bcc4;
  }
  #results .cl-row .pos { color: var(--dim); font-size: 12px; font-variant-numeric: tabular-nums; }
  /* The three-letter code is the timing-tower convention, and it is the only
     way twenty-two drivers fit a phone. Monospaced so the column is a column. */
  #results .cl-row .code {
    font-family: var(--mono); font-size: 12px; letter-spacing: 1px; color: var(--dim);
  }
  #results .cl-row .dn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #results .cl-row .sc { text-align: right; font-variant-numeric: tabular-nums; }
  #results .cl-row .pts { text-align: right; font-variant-numeric: tabular-nums; color: var(--dim); font-size: 12px; }
  #results .cl-row.you { color: var(--text); }
  #results .cl-row.you .code, #results .cl-row.you .pos { color: var(--purple); }
  #results .cl-row.you .dn { font-weight: 600; }
  #results .cl-row.podium .dn { color: var(--text); }
  /* An elision, when the player finished outside the ten shown. Without it the
     jump from P10 to P16 looks like the table losing rows. */
  #results .cl-gap {
    max-width: 360px; width: 100%; text-align: center; color: var(--dim);
    font-size: 11px; letter-spacing: 3px; padding: 5px 0;
  }
  #results .totals { width: 100%; max-width: 360px; margin-top: 18px; }
  #results .totals .line {
    display: flex; justify-content: space-between;
    font-size: 15px; color: var(--dim); padding: 5px 0;
  }
  #results .totals .line b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
  #results .hero {
    font-family: var(--display); font-size: 82px; font-weight: 700;
    line-height: 1; margin: 14px 0 2px; font-variant-numeric: tabular-nums;
  }
  #results .hero-label { font-size: 13px; letter-spacing: 3px; color: var(--dim); text-transform: uppercase; }
  #results .finish {
    font-family: var(--display); font-size: 27px; letter-spacing: 2px;
    margin-top: 14px; text-transform: uppercase;
  }
  #results .restart {
    font-family: var(--display); font-size: 19px; color: var(--orange);
    margin-top: 24px; letter-spacing: 3px; text-transform: uppercase;
    animation: pulse 1.5s ease-in-out infinite;
  }

  @keyframes pulse { 0%,100% { opacity: .5; } 50% { opacity: 1; } }

  .corner-flash {
    position: fixed; top: 46%; left: 50%; transform: translate(-50%,-50%);
    font-family: var(--display); font-weight: 700; font-size: 70px;
    pointer-events: none; z-index: 15; opacity: 0; font-variant-numeric: tabular-nums;
  }
  .penalty-flash {
    position: fixed; top: 34%; left: 50%; transform: translate(-50%,-50%);
    font-family: var(--mono); font-size: 19px; font-weight: 600;
    color: var(--orange); pointer-events: none; z-index: 15; opacity: 0;
  }
