/* Gameplay chrome stays at the edges; dialogs own the foreground. */
/* Preferences use native inputs and remain scrollable on short screens. */
.preference-group { margin: 16px 0; padding: 12px; border: 1px solid #c4d77845; border-radius: 10px; min-width: 0; }
.preference-group legend { padding: 0 6px; font-size: 14px; font-weight: 700; color: #d9e994; }
.preference-group > strong { display: block; font-size: 13px; margin-bottom: 10px; }
.preference-check { display: flex; gap: 10px; align-items: center; min-height: 44px; font-size: 14px; line-height: 1.4; }
.preference-check input { flex: none; width: 20px; height: 20px; accent-color: #c1d575; }
.preference-range { display: grid; grid-template-columns: 1fr auto; gap: 8px; font-size: 14px; }
.preference-range input { grid-column: 1 / -1; width: 100%; min-height: 36px; accent-color: #c1d575; }
.preference-group input:focus-visible { outline: 2px solid #e6c17d; outline-offset: 3px; }
.reduced-motion .return-flash { opacity: 0 !important; }
.reduced-motion :is(.intro, .lobby-card, #race-countdown, #reconnect-banner) { animation: none !important; transition: none !important; }
:root {
  --hud-top: max(12px, env(safe-area-inset-top));
  --hud-left: max(12px, env(safe-area-inset-left));
  --hud-right: max(12px, env(safe-area-inset-right));
  --hud-bottom: max(16px, env(safe-area-inset-bottom));
}
#scene canvas { width: 100%; height: 100%; }
.masthead { top: var(--hud-top); left: var(--hud-left); right: var(--hud-right); gap: 8px; z-index: 3; }
.hud-tools { display: flex; align-items: center; gap: 2px; margin-left: auto; pointer-events: auto; }
.hud-tools .icon-btn { width: 36px; height: 36px; background: #2933278c; flex: none; font-size: 17px; }
.hud-tools .icon-btn svg { width: 17px; height: 17px; }
body:is([data-play-mode="home"], [data-play-mode="queue"], [data-play-mode="lobby"], [data-play-mode="browse"]) #menu-toggle { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
body:is([data-play-mode="practice"], [data-play-mode="online"]) .brand { display: none; }
.course-hud { position: relative; top: auto !important; left: auto; width: min(420px, calc(100% - 158px)) !important; padding: 0 9px; border-radius: 8px; overflow: hidden; }
.course-hud .course-heading { display: flex; gap: 7px; align-items: center; letter-spacing: 0; }
#levels { min-width: 0; min-height: 36px; width: auto; flex: 1; gap: 7px; justify-content: flex-start; padding: 0; font-size: 12px; }
#level-round { color: #eef2d3; font-size: 11px; font-variant-numeric: tabular-nums; flex: none; }
#level-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body[data-play-mode="online"] #levels > span:last-child { display: block; }
#course-time { flex: none; font-size: 11px; font-variant-numeric: tabular-nums; color: #e2dec8; }
.course-hud .course-track { height: 2px; margin: 0 -9px; width: calc(100% + 18px); border-radius: 0; }
#menu-toggle { border-radius: 9px; }
#menu-toggle svg { width: 18px; height: 18px; }
.shade { background: linear-gradient(180deg, #12211812, transparent 15%, transparent 90%, #11211625); }

/* The map is opt-in on small/touch screens, and can also be hidden on desktop. */
.route-guide { display: none; top: calc(var(--hud-top) + 60px); right: var(--hud-right); width: 148px; padding: 8px; background: #2d3525c9; }
body.map-visible .route-guide { display: block; }
.route-guide canvas { width: 130px; height: 90px; }
.route-guide > span { justify-content: flex-end; margin-bottom: 3px; }
.route-guide strong { font-size: 10px; }

footer { left: var(--hud-left); right: var(--hud-right); bottom: var(--hud-bottom); justify-content: center; }
footer .speed, footer .control-strip, footer .status-sub { display: none; }
footer .status-block { min-width: 0 !important; padding: 8px 12px; border-radius: 8px; background: #263323d9; }
footer .status-block > div { align-items: center; }
footer #motion-state { font-size: 12px; }
body:not([data-balance-warning="true"]) footer { visibility: hidden; }
.balance-track { width: 86px; height: 3px; }
.intro { top: calc(var(--hud-top) + 75px) !important; left: var(--hud-left); max-width: 310px; transition-duration: .35s; }
.intro .eyebrow, .intro h2 { display: none; }
.intro .course-tip { padding: 9px 12px; border-radius: 8px; background: #2d3525d6; max-width: 290px; font-size: 12px; line-height: 1.5; margin: 0; }

/* Native dialogs prevent the map, touch controls and home action covering buttons. */
#game-menu, #help-panel, #stage-complete {
  position: fixed; inset: 0; margin: auto; width: min(360px, calc(100% - var(--hud-left) - var(--hud-right)));
  max-height: calc(100dvh - var(--hud-top) - var(--hud-bottom)); overflow: auto;
  padding: 20px; color: #f5e9c1; background: #293123f5; border: 1px solid #b1a56580;
  border-radius: 14px; box-shadow: 0 16px 70px #111c1860; backdrop-filter: blur(14px);
}
#game-menu::backdrop, #help-panel::backdrop, #stage-complete::backdrop { background: #111d2440; }
#game-menu { inset: var(--hud-top) var(--hud-right) auto auto; margin: 0; }
#game-menu .panel-heading h2, #help-panel .panel-heading h2 { font-size: 19px; }
.panel-heading button { min-width: 44px; min-height: 44px; opacity: 1; }
.menu-course { display: grid; gap: 5px; margin: 12px 0; padding-bottom: 14px; border-bottom: 1px solid #ffffff20; }
.menu-course strong { font-size: 14px; overflow-wrap: anywhere; }
.menu-course span, .menu-course small { font-size: 12px; color: #c0c5ad; }
.menu-options { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.menu-options button, #game-menu .lobby-back, .quiet-button { min-height: 44px; padding: 10px 12px; border: 1px solid #ffffff27; background: #ffffff07; border-radius: 8px; font-size: 13px; text-align: center; }
.menu-options button:hover, .quiet-button:hover { background: #ffffff14; }
.menu-options #menu-resume { grid-column: 1 / -1; background: #b8ce63; color: #24321b; font-weight: 700; }
#game-menu .lobby-back { position: static; margin-top: 14px; width: 100%; color: #e8c8a4; }
.menu-online-note { display: none; margin: 14px 0 0; font-size: 11px; color: #e8c8a4; }
body[data-play-mode="online"] .menu-online-note { display: block; }
body:is([data-play-mode="home"], [data-play-mode="queue"], [data-play-mode="lobby"], [data-play-mode="browse"]) .menu-course { display: none; }
#help-panel { top: 0 !important; width: min(460px, calc(100vw - 28px)); }
#help-panel > p, #help-panel dl > div, #help-panel .panel-note { font-size: 14px; line-height: 1.5; }
#help-panel dl { margin: 12px 0; }
#help-panel dl > div { padding: 9px 0; }
#help-panel .audio-mix input { width: min(155px, 52%); min-height: 28px; }
.touch-help { display: none; }
#stage-complete { width: min(360px, calc(100% - 32px)); text-align: center; padding: 24px; }
.completion-mark { display: grid; place-items: center; width: 40px; height: 40px; margin: 0 auto 10px; border-radius: 50%; color: #b8ce63; background: #b8ce631c; font-size: 25px; }
#stage-complete h2 { font: 800 25px/1.15 'Manrope', sans-serif; margin: 0 0 8px; }
#stage-complete p { margin: 0; font-size: 13px; line-height: 1.5; color: #d6d6ba; overflow-wrap: anywhere; }
.completion-actions { display: grid; gap: 8px; margin-top: 18px; }
#next-level { margin: 0; min-height: 48px; width: 100%; font-size: 15px; border-radius: 8px; }
.completion-actions .quiet-button { min-height: 44px; border-color: transparent; background: transparent; }
#course-message { top: 30% !important; z-index: 4; padding: 12px 16px; pointer-events: none !important; }
#course-message strong { font-size: 17px; }
#course-message span { font-size: 12px; }
body.stage-cleared :is(.masthead, .route-guide, footer, .touch-controls, .intro, #practice-notice),
body:has(dialog[open]) :is(.touch-controls, footer, .route-guide, .intro, #course-message),
body:is([data-race-phase="results"], [data-race-phase="over"], [data-race-phase="finished"]) :is(.touch-controls, footer, .route-guide, .intro) { visibility: hidden; }
.ui-hidden #menu-toggle { visibility: visible; }

/* The held item is also a button, so keyboard, pointer and touch players share
   one action. Active abilities keep their slot until the effect ends. */
#item-slot { --item-color: #d4bd8a; position: absolute; right: var(--hud-right); bottom: var(--hud-bottom); display: flex; align-items: center; gap: 10px; width: 260px; min-height: 76px; padding: 12px; z-index: 3; border: 1px solid color-mix(in srgb, var(--item-color) 55%, transparent); border-radius: 12px; background: #292337ed; color: var(--item-color); text-align: left; box-shadow: 0 6px 24px #15112030; overflow: hidden; }
#item-slot[hidden] { display: none; }
#item-swap-warning { position: absolute; z-index: 4; top: 22%; left: 50%; transform: translateX(-50%); max-width: calc(100% - 32px); padding: 12px 20px; border: 2px solid #dfa7ff; border-radius: 12px; background: #28153aed; color: #f4deff; font-size: 1rem; font-weight: 800; text-align: center; pointer-events: none; }
#item-swap-warning[hidden] { display: none; }
body.ui-hidden #item-swap-warning, body:has(dialog[open]) #item-swap-warning { visibility: hidden; }
#item-slot:disabled { opacity: 1; cursor: default; }
#item-slot[data-state="empty"] { background: #293123bd; border-color: #c1b69b45; }
#item-slot[data-state="ready"] { cursor: pointer; }
#item-slot[data-state="ready"]:hover { border-color: var(--item-color); background: #392a45f5; }
#item-slot:focus-visible, #touch-item:focus-visible { outline: 3px solid #fff4bb; outline-offset: 4px; }
#item-icon { display: grid; place-items: center; flex: none; width: 43px; height: 43px; border: 1px solid color-mix(in srgb, var(--item-color) 40%, transparent); border-radius: 9px; background: color-mix(in srgb, var(--item-color) 10%, transparent); }
#item-icon svg { width: 32px; height: 32px; stroke: currentColor; fill: currentColor; fill-opacity: .17; stroke-width: 1.7; stroke-linejoin: round; stroke-linecap: round; }
.item-copy { display: grid; gap: 3px; min-width: 0; flex: 1; }
.item-copy small { font-size: 8px; letter-spacing: 1.3px; font-weight: 700; opacity: .72; }
#item-label { font-size: 13px; line-height: 1.25; color: #fff4df; }
#item-hint { font-size: 9px; line-height: 1.35; color: #d6cddd; }
#item-key { position: absolute; top: 8px; right: 9px; font: 700 8px/1 sans-serif; border: 0; padding: 3px 4px; background: #ffffff10; border-radius: 3px; color: var(--item-color); }
#item-duration { position: absolute; height: 3px; bottom: 0; left: 0; right: 0; background: var(--item-color); transform-origin: left; }
#touch-item { position: absolute; right: 84px; bottom: 28px; width: 60px; height: 60px; border: 1px solid #d4b7f1b0; border-radius: 50%; background: #49345ac9; color: #fff0cf; font: 800 11px 'Manrope', sans-serif; letter-spacing: .8px; pointer-events: auto; touch-action: none; }
#touch-item:disabled { opacity: .35; }
/* Camera-forward throws share the screen center on desktop and touch. */
#item-crosshair { position: absolute; left: 50%; top: 50%; width: 32px; height: 32px; transform: translate(-50%, -50%); z-index: 2; pointer-events: none; user-select: none; }
#item-crosshair svg { display: block; width: 100%; height: 100%; overflow: visible; fill: none; stroke: #fff4df; stroke-width: 2; stroke-linecap: round; }
#item-crosshair .crosshair-outline { stroke: #172219; stroke-width: 4; }
#item-crosshair circle { fill: #fff4df; stroke: #172219; stroke-width: 1; }
body:not(:is([data-play-mode="practice"], [data-play-mode="online"])) :is(#item-slot, #item-crosshair),
body.stage-cleared :is(#item-slot, #item-crosshair), body:has(dialog[open]) :is(#item-slot, #item-crosshair),
body:is([data-race-phase="results"], [data-race-phase="over"], [data-race-phase="finished"]) :is(#item-slot, #item-crosshair),
body.ui-hidden :is(#item-slot, #item-crosshair) { visibility: hidden; }
@media (max-width: 900px), (pointer: coarse) {
 #item-slot { bottom: calc(var(--hud-bottom) + 123px); width: 214px; min-height: 67px; padding: 10px; gap: 8px; }
 #item-icon { width: 36px; height: 36px; }
 #item-icon svg { width: 28px; height: 28px; }
 #item-label { font-size: 12px; }
 #item-hint { font-size: 9px; }
 #item-key { display: none; }
 body.left-handed #item-slot { left: var(--hud-left); right: auto; }
 body.left-handed #touch-item { left: 84px; right: auto; }
 body.large-touch #touch-item { right: 104px; width: 68px; height: 68px; }
 body.left-handed.large-touch #touch-item { left: 104px; right: auto; }
 body.large-touch #item-slot { bottom: calc(var(--hud-bottom) + 147px); }
}
@media (max-height: 500px) and (min-width: 600px) {
 #item-slot { right: calc(var(--hud-right) + 162px); bottom: var(--hud-bottom); width: 205px; }
 body.left-handed #item-slot { left: calc(var(--hud-left) + 162px); right: auto; }
}
@media (max-width: 360px) {
 body.large-touch #touch-item { right: 14px; bottom: 110px; }
 body.left-handed.large-touch #touch-item { left: 14px; right: auto; }
 body.large-touch #item-slot { bottom: calc(var(--hud-bottom) + 188px); }
}

/* Race counts share the same top row; the score lives in the menu. */
#online-hud { position: static; padding: 0; flex: none; flex-direction: row; align-items: center; gap: 7px; max-width: none; background: none; border: 0; border-radius: 0; white-space: nowrap; }
#race-position { font-size: 11px; }
#tournament-points { font-size: 11px; letter-spacing: 0; max-width: none; }
#finish-clock { font-size: 12px; }
body[data-play-mode="online"] #course-time, body:not([data-play-mode="online"]) #tournament-points { display: none; }
#finished-notice { top: calc(var(--hud-top) + 54px); width: max-content; max-width: calc(100% - 24px); font-size: 13px; padding: 10px 14px; }
#race-countdown span { display: none !important; }
#start-number { font-size: 90px; }
#race-countdown small { font-size: 12px; background: #283523c9; padding: 7px 11px; border-radius: 7px; }
#practice-notice { top: calc(var(--hud-top) + 65px); bottom: auto; max-width: min(380px, calc(100% - 32px)); padding: 10px 13px; font-size: 12px; }
body:has(#practice-notice:not([hidden])) .intro { visibility: hidden; }

@media (max-width: 900px), (pointer: coarse) {
  .masthead { flex-wrap: nowrap; }
  .course-hud { width: calc(100% - 158px) !important; }
  .brand { flex: 1; }
  body:is([data-play-mode="home"], [data-play-mode="queue"], [data-play-mode="lobby"], [data-play-mode="browse"]) .masthead { flex-wrap: nowrap; }
  body:is([data-play-mode="home"], [data-play-mode="queue"], [data-play-mode="lobby"], [data-play-mode="browse"]) #menu-toggle { display: none; }
  .touch-controls { display: block; position: absolute; left: var(--hud-left); right: var(--hud-right) !important; bottom: var(--hud-bottom); pointer-events: none; z-index: 2; }
  #joystick { position: relative; width: 112px; height: 112px; border: 1px solid #ffffff45; border-radius: 50%; background: #2435232b; backdrop-filter: none; pointer-events: auto; touch-action: none; }
  #stick { position: absolute; width: 46px; height: 46px; left: 32px; top: 32px; border-radius: 50%; background: #f5f5df40; border: 1px solid #ffffff88; }
  #touch-jump { right: 0; bottom: 16px !important; width: 76px; height: 76px; font-size: 12px; letter-spacing: .5px; background: #2435233b; }
  footer { bottom: calc(var(--hud-bottom) + 8px); left: calc(var(--hud-left) + 120px); right: calc(var(--hud-right) + 84px); }
  footer .status-block { padding: 7px; }
  footer #motion-state { font-size: 10px !important; text-align: center; }
  .balance-track { width: 60px; }
  #help-panel .keyboard-help, .level-note { display: none; }
  #help-panel .touch-help { display: flex; }
  .route-guide { width: 116px; padding: 6px; top: calc(var(--hud-top) + 50px); }
  .route-guide canvas { width: 102px; height: 70px; }
  body[data-play-mode="online"] .route-guide { top: calc(var(--hud-top) + 50px); }
  #tournament-points { font-size: 10px; }
  .intro { top: calc(var(--hud-top) + 54px) !important; }
  .intro .course-tip { max-width: min(290px, calc(100vw - 32px)); }
  #practice-notice { top: calc(var(--hud-top) + 54px); }
}
@media (max-width: 380px) {
  #levels { gap: 5px; font-size: 11px; }
  .course-hud .course-heading { gap: 5px; }
  #course-time, #level-round { font-size: 10px; }
  #online-hud { gap: 4px; }
  #race-position, #finish-clock { font-size: 10px; }
  .brand h1 { font-size: 21px; }
  body:is([data-play-mode="home"], [data-play-mode="queue"], [data-play-mode="lobby"], [data-play-mode="browse"]) .brand > svg { display: none; }
  .brand .brand-overline { font-size: 7px !important; letter-spacing: 1px !important; }
}
@media (max-height: 500px) {
  :root { --hud-top: max(8px, env(safe-area-inset-top)); --hud-bottom: max(10px, env(safe-area-inset-bottom)); }
  .masthead { flex-wrap: nowrap; }
  .course-hud { width: min(420px, calc(100% - 158px)) !important; }
  .intro { top: calc(var(--hud-top) + 66px) !important; }
  .route-guide, body[data-play-mode="online"] .route-guide { top: calc(var(--hud-top) + 60px); }
  #multiplayer-menu { padding: 66px var(--hud-right) 16px var(--hud-left); align-items: flex-start; }
  #results-panel { padding: 16px; }
  #results-panel h2 { font-size: 23px; margin: 8px 0; }
  #results-panel .lobby-lead { margin-bottom: 8px; font-size: 12px; }
  #stage-complete { padding: 16px 22px; }
  .completion-mark { display: none; }
  .completion-actions { margin-top: 12px; }
  #game-menu { padding: 12px 18px; }
  .menu-course { margin: 4px 0 10px; padding-bottom: 8px; }
  .intro { max-width: 270px; }
  #start-number { font-size: 70px; line-height: 1.15; }
}

@media (max-width: 900px), (pointer: coarse) {
  body.left-handed #joystick { margin-left: auto; }
  body.left-handed #touch-jump { left: 0; right: auto; }
  body.large-touch #joystick { width: 136px; height: 136px; }
  body.large-touch #stick { left: calc(50% - 23px); top: calc(50% - 23px); }
  body.large-touch #touch-jump { width: 96px; height: 96px; }
  body.large-touch footer { left: calc(var(--hud-left) + 142px); right: calc(var(--hud-right) + 104px); }
  body.left-handed footer { left: calc(var(--hud-left) + 84px); right: calc(var(--hud-right) + 120px); }
  body.left-handed.large-touch footer { left: calc(var(--hud-left) + 104px); right: calc(var(--hud-right) + 142px); }
}
