/* Race HUD, start prompt, countdown, name entry and leaderboard (assets/world/race.js).
   Visible rules are scoped to html.mode-3d; outside the 3D view nothing shows. */

.race-hud,
.race-prompt,
.race-count,
.race-layer { display: none; }
/* status messages for screen readers: present but not visible */
.race-live,
.race-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
.race-live { position: fixed; }

@media screen {
  /* ---------------- lap readout (top left) ---------------- */
  html.mode-3d .race-hud:not([hidden]) {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    position: fixed;
    z-index: 33;
    top: calc(var(--topbar-h, 62px) + 14px);
    left: 18px;
    width: 238px;
    pointer-events: none;
    font: 500 12px/1.25 "IBM Plex Mono", ui-monospace, Consolas, monospace;
    color: #c6d0c8;
  }
  html.mode-3d.card-open .race-hud,
  html.mode-3d.card-open .race-prompt { display: none !important; }
  /* the board map is a modal on top: the race HUD and the prompt step aside */
  html.mode-3d.map-open .race-hud,
  html.mode-3d.map-open .race-prompt,
  html.mode-3d.map-open .race-count { visibility: hidden; }
  html.mode-3d .rh-card {
    box-sizing: border-box;
    width: 100%;
    padding: 10px 12px 11px;
    background: rgba(6, 19, 14, .94);
    border: 1px solid rgba(224, 169, 74, .45);
    border-radius: 12px;
    box-shadow: 0 10px 28px rgba(0, 0, 0, .35);
    font-variant-numeric: tabular-nums;
  }
  html.mode-3d .rh-top {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-size: 10px;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: #93a69b;
  }
  html.mode-3d .rh-time {
    margin-top: 4px;
    font: 600 30px/1.05 "IBM Plex Mono", ui-monospace, Consolas, monospace;
    letter-spacing: .01em;
    color: #f4f2e9;
  }
  html.mode-3d .rh-state {
    min-height: 15px;
    margin-top: 3px;
    font-size: 12px;
    color: #c6d0c8;
  }
  html.mode-3d .rh-time.is-best,
  html.mode-3d .rh-state.is-best { color: #ffd482; }
  html.mode-3d .rh-time.is-bad,
  html.mode-3d .rh-state.is-bad { color: #ff9a76; }
  html.mode-3d .rh-sectors {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 8px;
  }
  html.mode-3d .rh-sectors i {
    flex: none;
    width: 22px;
    height: 6px;
    border-radius: 3px;
    background: rgba(244, 242, 233, .16);
  }
  html.mode-3d .rh-sectors i.is-fast { background: #62e6a4; }
  html.mode-3d .rh-sectors i.is-slow { background: #ff9a76; }
  html.mode-3d .rh-sectors i.is-set { background: #e0a94a; }
  html.mode-3d .rh-sectors i.is-bad { background: rgba(255, 154, 118, .4); }
  html.mode-3d .rh-delta {
    margin-left: 6px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
  }
  html.mode-3d .rh-delta.is-fast { color: #62e6a4; }
  html.mode-3d .rh-delta.is-slow { color: #ff9a76; }
  html.mode-3d .rh-delta.is-set { color: #ffd482; }
  html.mode-3d .rh-stats {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    margin-top: 8px;
    padding-top: 7px;
    border-top: 1px solid rgba(244, 242, 233, .12);
    font-size: 11px;
    color: #93a69b;
  }
  html.mode-3d .rh-stats b { margin-left: 4px; font-weight: 600; color: #f4f2e9; }

  html.mode-3d .rh-board {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 36px;
    padding: 0 8px 0 14px;
    pointer-events: auto;
    font: 500 13px/1 "IBM Plex Mono", ui-monospace, Consolas, monospace;
    letter-spacing: .03em;
    color: #f4f2e9;
    background: #0f271e;
    border: 1px solid rgba(224, 169, 74, .6);
    border-radius: 999px;
    cursor: pointer;
    transition: background-color .18s, border-color .18s;
  }
  html.mode-3d .rh-board:hover { background: #16362a; border-color: #e0a94a; }
  html.mode-3d .rh-board kbd {
    display: inline-grid;
    place-items: center;
    min-width: 20px;
    height: 20px;
    font: 600 11px/1 "IBM Plex Mono", ui-monospace, Consolas, monospace;
    color: #ffd482;
    border: 1px solid rgba(224, 169, 74, .6);
    border-radius: 999px;
  }
  html.mode-3d .race-hud.is-touch .rh-board { padding-right: 14px; }
  html.mode-3d .race-hud.is-touch .rh-board kbd { display: none; }

  /* ---------------- start prompt ---------------- */
  html.mode-3d .race-prompt:not([hidden]) {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    position: fixed;
    z-index: 33;
    left: 50%;
    bottom: 30px;
    min-height: 50px;
    max-width: calc(100vw - 32px);
    padding: 6px 22px 6px 7px;
    transform: translateX(-50%);
    font: 700 16px/1.15 "Archivo", "Arial Narrow", Arial, sans-serif;
    font-stretch: 112%;
    color: #1a1204;
    background: #e0a94a;
    border: 0;
    border-radius: 999px;
    box-shadow: 0 0 0 6px rgba(224, 169, 74, .2), 0 12px 32px rgba(0, 0, 0, .45);
    cursor: pointer;
    animation: race-pop .32s cubic-bezier(.2, .9, .3, 1.3) both;
  }
  html.mode-3d .race-prompt:hover { background: #ffd482; }
  /* the key hints in the bottom left would run under the button */
  html.mode-3d.race-prompting .world-hud .wh-keys { display: none; }
  html.mode-3d .rp-key {
    flex: none;
    padding: 9px 12px;
    font: 600 12px/1 "IBM Plex Mono", ui-monospace, Consolas, monospace;
    letter-spacing: .06em;
    color: #ffd482;
    background: #1a1204;
    border-radius: 999px;
  }

  /* ---------------- 3 2 1 GO ---------------- */
  html.mode-3d .race-count {
    display: block;
    position: fixed;
    z-index: 34;
    left: 50%;
    top: 30%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    opacity: 0;
    font: 800 120px/1 "Archivo", "Arial Black", Arial, sans-serif;
    font-stretch: 118%;
    color: #ff9a76;
    text-shadow: 0 0 28px rgba(255, 154, 118, .55), 0 6px 0 rgba(6, 19, 14, .7);
  }
  html.mode-3d .race-count.is-on { opacity: 1; animation: race-count .5s cubic-bezier(.2, .9, .3, 1.2) both; }
  html.mode-3d .race-count.is-go { color: #62e6a4; text-shadow: 0 0 28px rgba(98, 230, 164, .55), 0 6px 0 rgba(6, 19, 14, .7); }

  /* ---------------- dialogs ---------------- */
  html.mode-3d .race-layer:not([hidden]) {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    position: fixed;
    inset: 0;
    z-index: 60;
    box-sizing: border-box;
    padding: calc(var(--topbar-h, 62px) + 16px) 12px 16px;
    overflow-y: auto;
    background: rgba(3, 10, 7, .62);
    animation: race-fade .2s ease both;
  }
  @media (min-height: 640px) and (min-width: 760px) {
    html.mode-3d .race-layer:not([hidden]) { align-items: center; padding-top: 16px; }
  }
  html.mode-3d .race-dialog:not([hidden]) {
    display: block;
    box-sizing: border-box;
    width: min(440px, 100%);
    padding: 22px 24px 24px;
    color: #c6d0c8;
    background: #0a1c15;
    border: 1px solid rgba(224, 169, 74, .6);
    border-radius: 16px;
    box-shadow: 0 26px 70px rgba(0, 0, 0, .55), inset 0 1px 0 rgba(255, 212, 130, .1);
    font: 400 15px/1.5 "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
    animation: race-in .28s cubic-bezier(.2, .8, .2, 1) both;
  }
  html.mode-3d .race-dialog.race-board:not([hidden]) { width: min(520px, 100%); }
  html.mode-3d .race-dialog h2 {
    margin: 0 0 8px;
    font: 700 22px/1.2 "Archivo", "Arial Narrow", Arial, sans-serif;
    font-stretch: 108%;
    color: #f4f2e9;
  }
  html.mode-3d .rd-lead { margin: 0 0 16px; }
  html.mode-3d .rd-time {
    font: 600 16px/1 "IBM Plex Mono", ui-monospace, Consolas, monospace;
    color: #ffd482;
  }
  html.mode-3d .rd-form label {
    display: block;
    margin-bottom: 6px;
    font: 600 12px/1.2 "IBM Plex Mono", ui-monospace, Consolas, monospace;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: #c6d0c8;
  }
  html.mode-3d .rd-form input {
    display: block;
    box-sizing: border-box;
    width: 100%;
    height: 46px;
    padding: 0 12px;
    font: 500 16px/1 "IBM Plex Sans", system-ui, Arial, sans-serif;
    color: #f4f2e9;
    background: #06130e;
    border: 1px solid rgba(244, 242, 233, .32);
    border-radius: 10px;
  }
  html.mode-3d .rd-form input:focus { outline: 2px solid #ffd482; outline-offset: 1px; border-color: #e0a94a; }
  html.mode-3d .rd-form input[aria-invalid="true"] { border-color: #ff9a76; }
  html.mode-3d .rd-hint { margin: 6px 0 0; font-size: 13px; color: #93a69b; }
  html.mode-3d .rd-error:not([hidden]) { margin: 6px 0 0; font-size: 14px; font-weight: 600; color: #ff9a76; }
  html.mode-3d .rd-privacy {
    margin: 14px 0 0;
    padding: 9px 11px;
    font-size: 13px;
    color: #c6d0c8;
    border: 1px dashed rgba(244, 242, 233, .22);
    border-radius: 8px;
  }
  html.mode-3d .rd-actions,
  html.mode-3d .rb-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 18px;
  }
  html.mode-3d .race-dialog button {
    min-height: 44px;
    padding: 0 18px;
    font: 600 15px/1 "IBM Plex Sans", system-ui, Arial, sans-serif;
    color: #f4f2e9;
    background: #16362a;
    border: 1px solid rgba(244, 242, 233, .3);
    border-radius: 999px;
    cursor: pointer;
    transition: background-color .18s, border-color .18s;
  }
  html.mode-3d .race-dialog button:hover { background: #1d4a38; border-color: #e0a94a; }
  html.mode-3d .race-dialog .rd-save { color: #1a1204; background: #e0a94a; border-color: #e0a94a; }
  html.mode-3d .race-dialog .rd-save:hover { background: #ffd482; }
  html.mode-3d .race-dialog button:focus-visible,
  html.mode-3d .rh-board:focus-visible,
  html.mode-3d .race-prompt:focus-visible { outline: 2px solid #ffd482; outline-offset: 3px; }

  html.mode-3d .rb-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
  html.mode-3d .race-dialog .rb-close {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex: none;
    min-height: 40px;
    padding: 0 14px 0 8px;
    font-size: 14px;
  }
  html.mode-3d .rb-esc {
    padding: 5px 7px;
    font: 500 11px/1 "IBM Plex Mono", ui-monospace, Consolas, monospace;
    letter-spacing: .06em;
    color: #ffd482;
    border: 1px solid rgba(224, 169, 74, .6);
    border-radius: 999px;
  }
  @media (hover: none) and (pointer: coarse) {
    html.mode-3d .race-dialog .rb-close { padding-left: 14px; }
    html.mode-3d .rb-esc { display: none; }
  }
  html.mode-3d .rb-source { margin: 2px 0 12px; font-size: 13px; color: #93a69b; }
  html.mode-3d .rb-wrap {
    max-height: calc(100vh - var(--topbar-h, 62px) - 260px);
    max-height: calc(100dvh - var(--topbar-h, 62px) - 260px);
    min-height: 120px;
    overflow: auto;
    border: 1px solid rgba(244, 242, 233, .12);
    border-radius: 10px;
  }
  html.mode-3d .race-board table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
  html.mode-3d .race-board th {
    position: sticky;
    top: 0;
    padding: 8px 12px;
    text-align: left;
    font: 600 11px/1.2 "IBM Plex Mono", ui-monospace, Consolas, monospace;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: #93a69b;
    background: #0f271e;
  }
  html.mode-3d .race-board td {
    padding: 9px 12px;
    border-top: 1px solid rgba(244, 242, 233, .08);
    color: #f4f2e9;
    overflow-wrap: anywhere;
  }
  html.mode-3d .race-board td:first-child { width: 3ch; font-family: "IBM Plex Mono", ui-monospace, Consolas, monospace; color: #93a69b; }
  html.mode-3d .race-board .rb-t { text-align: right; white-space: nowrap; font-family: "IBM Plex Mono", ui-monospace, Consolas, monospace; }
  html.mode-3d .race-board tr.is-you td { background: rgba(224, 169, 74, .14); color: #ffd482; }
  html.mode-3d .rb-tag {
    display: inline-block;
    margin-left: 4px;
    padding: 2px 7px;
    font: 600 10px/1.3 "IBM Plex Mono", ui-monospace, Consolas, monospace;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: #1a1204;
    background: #e0a94a;
    border-radius: 999px;
    vertical-align: 1px;
  }
  html.mode-3d .rb-empty { color: #c6d0c8 !important; text-align: center; padding: 18px 12px !important; }
  html.mode-3d .rb-you { margin: 12px 0 0; font-size: 14px; color: #c6d0c8; }

  /* phones: smaller readout beside the map, prompt above the joystick */
  @media (max-width: 759px) {
    html.mode-3d .race-hud:not([hidden]) { top: calc(var(--topbar-h, 56px) + 10px); left: 10px; width: min(212px, calc(100vw - 162px)); gap: 6px; }
    html.mode-3d .rh-card { padding: 8px 10px 9px; }
    html.mode-3d .rh-time { font-size: 24px; }
    html.mode-3d .rh-state { font-size: 11px; }
    html.mode-3d .rh-sectors i { width: 16px; }
    html.mode-3d .rh-delta { font-size: 11px; margin-left: 4px; }
    html.mode-3d .rh-stats { font-size: 10px; gap: 6px; }
    html.mode-3d .rh-board { min-height: 34px; font-size: 12px; }
    html.mode-3d .race-prompt:not([hidden]) { bottom: 172px; font-size: 15px; }
    html.mode-3d .race-count { font-size: 88px; top: 34%; }
    html.mode-3d .race-dialog:not([hidden]) { padding: 18px 16px 20px; }
  }
  @media (max-width: 759px) and (hover: hover) {
    html.mode-3d .race-prompt:not([hidden]) { bottom: 24px; }
  }

  @keyframes race-pop { from { opacity: 0; transform: translateX(-50%) translateY(10px) scale(.94); } }
  @keyframes race-count { from { opacity: 0; transform: translate(-50%, -50%) scale(1.5); } }
  @keyframes race-in { from { opacity: 0; transform: translateY(14px) scale(.98); } }
  @keyframes race-fade { from { opacity: 0; } }

  @media (prefers-reduced-motion: reduce) {
    html.mode-3d .race-prompt:not([hidden]),
    html.mode-3d .race-count.is-on,
    html.mode-3d .race-layer:not([hidden]),
    html.mode-3d .race-dialog:not([hidden]) { animation: none; }
  }
}

@media print {
  .race-hud, .race-prompt, .race-count, .race-layer, .race-live { display: none !important; }
}
