/* The installed club app / phone shell (static/pwa.js, templates/pwa_parts.html): bottom tab bar, collapsing
   titles, pull to refresh, live mini-player, my next race, bottom sheets. Every colour is a theme token. */

.app-tabs, .app-title { display: none; }
@media (max-width: 760px), (display-mode: standalone) {
  .has-app-tabs { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .has-app-tabs .site-footer { padding-bottom: calc(var(--s-6) + 8px); }
  .app-tabs {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    padding: 0 max(8px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(8px, env(safe-area-inset-left));
    background: color-mix(in oklab, var(--bg) 86%, transparent); backdrop-filter: saturate(160%) blur(20px); -webkit-backdrop-filter: saturate(160%) blur(20px);
    border-top: 1px solid var(--line);
  }
  .app-tabs a {
    position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    min-height: 56px; color: var(--text-2); font: 600 10.5px/1 var(--font-body); text-decoration: none; -webkit-tap-highlight-color: transparent;
  }
  .app-tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  .app-tabs a[aria-current="page"] { color: var(--brand); }
  .app-tabs a[aria-current="page"]::before { content: ""; position: absolute; top: 0; width: 28px; height: 2px; border-radius: 2px; background: var(--brand); box-shadow: 0 0 10px var(--brand); }
  .app-tabs a:active { transform: scale(.94); }
  /* Large titles: the page's own headline; once it scrolls away its text sits in a 44 px bar. */
  .has-app-tabs .site-header .bar { min-height: 56px; transition: min-height var(--t-med) var(--ease); }
  .app-collapsed .site-header .bar { min-height: 44px; }
  .app-collapsed .site-header .brandmark .sub { display: none; }
  .app-collapsed .app-title { display: block; position: absolute; left: 50%; transform: translateX(-50%); max-width: 46vw; font: 700 15px/44px var(--font-body);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none; animation: app-fade var(--t-med) var(--ease-out); }
  .app-collapsed .site-header .brandmark .name { opacity: 0; }
}
@media (display-mode: standalone) {
  /* Installed: the status bar is see-through (black-translucent), so the header pads below it. */
  .site-header { padding-top: env(safe-area-inset-top); }
  .site-footer .powered { display: none; }
}
@keyframes app-fade { from { opacity: 0; } to { opacity: 1; } }

/* Pull to refresh */
.app-ptr { position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 64px); z-index: 70; transform: translate(-50%, -60px); opacity: 0;
  padding: 8px 14px; border-radius: 999px; background: var(--surface-2); color: var(--text); font: 600 13px/1 var(--font-body);
  box-shadow: var(--shadow-2); transition: opacity var(--t-fast); pointer-events: none; display: flex; align-items: center; gap: 8px; }
.app-ptr i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--brand); border-right-color: transparent; }
.app-ptr.go i { animation: app-spin .8s linear infinite; }
@keyframes app-spin { to { transform: rotate(360deg); } }

/* The dock above the tab bar: my next race, then the live mini-player. */
.app-dock { position: fixed; left: 8px; right: 8px; bottom: calc(8px + env(safe-area-inset-bottom)); z-index: 55; display: grid; gap: 8px; pointer-events: none; }
.has-app-tabs .app-dock { bottom: calc(64px + 8px + env(safe-area-inset-bottom)); }
@media (min-width: 761px) and (not (display-mode: standalone)) { .app-dock, .has-app-tabs .app-dock { left: auto; right: 16px; bottom: 16px; width: 380px; } }
.app-dock > * { pointer-events: auto; }
.app-next { display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 10px 14px; border-radius: var(--r-lg); text-decoration: none; color: var(--text);
  background: color-mix(in oklab, var(--leader) 18%, var(--surface)); border: 1px solid color-mix(in oklab, var(--leader) 60%, transparent);
  box-shadow: var(--shadow-2); animation: app-deck 3s ease-in-out infinite; }
.app-next .k { font: 700 12px/1.2 var(--font-body); color: var(--leader); }
.app-next .t { font: 700 15px/1.25 var(--font-body); }
.app-next .s { font-size: 12.5px; color: var(--text-2); }
.app-next .chip { margin-left: auto; flex: none; font: 600 11px/1 var(--font-mono); padding: 4px 7px; border-radius: 999px; background: var(--c, var(--brand)); color: #111114; white-space: nowrap; }
@keyframes app-deck { 50% { box-shadow: 0 0 0 1px color-mix(in oklab, var(--leader) 80%, transparent), 0 0 22px color-mix(in oklab, var(--leader) 18%, transparent), var(--shadow-2); } }
.app-mini { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid color-mix(in oklab, var(--live) 45%, transparent); box-shadow: var(--shadow-2); }
.app-mini .thumb { position: relative; flex: none; width: 96px; height: 54px; border-radius: 10px; overflow: hidden; background: #000; border: 0; padding: 0; cursor: pointer; }
.app-mini .thumb img { width: 100%; height: 100%; object-fit: cover; }
.app-mini .thumb-live { background: radial-gradient(circle at 50% 50%, color-mix(in oklab, var(--live) 55%, transparent), color-mix(in oklab, var(--live) 12%, var(--surface-2)) 70%); }
.app-mini .thumb-live::after { content: "LIVE"; font: 800 11px/1 var(--font-body); letter-spacing: .1em; }
.app-mini .thumb::after { content: "▶"; position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-size: 18px; text-shadow: 0 1px 6px #000; }
.app-mini .meta { flex: 1; min-width: 0; display: grid; gap: 2px; background: none; border: 0; padding: 0; text-align: left; color: var(--text); font: inherit; cursor: pointer; }
.app-mini .meta b { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-mini .meta span:not(.app-badge-live) { font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-badge-live { display: inline-flex; align-items: center; gap: 5px; justify-self: start; padding: 2px 7px; border-radius: 999px; background: var(--live); color: #111114; font: 800 10px/1.4 var(--font-body); letter-spacing: .08em; }
.app-badge-live::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #111114; animation: app-blink 1.2s ease-in-out infinite; }
@keyframes app-blink { 50% { opacity: .3; } }
.app-x { flex: none; width: 44px; height: 44px; border-radius: 50%; border: 0; background: none; color: var(--text-2); font-size: 20px; cursor: pointer; }
.app-player { position: fixed; inset: 0; z-index: 90; background: color-mix(in oklab, #000 82%, transparent); display: grid; place-items: center; padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
.app-player .frame { width: min(100vw, 960px); aspect-ratio: 16 / 9; background: #000; }
.app-player iframe { width: 100%; height: 100%; border: 0; }
.app-player .app-x { position: absolute; top: calc(8px + env(safe-area-inset-top)); right: 8px; color: #fff; background: rgb(0 0 0 / 40%); }

/* Bottom sheets (Me, notifications, install, iOS add-to-home-screen). */
.app-sheet-back { position: fixed; inset: 0; z-index: 95; background: rgb(0 0 0 / 45%); animation: app-fade var(--t-fast) var(--ease-out); }
.app-sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 96; max-height: 86vh; overflow: auto; display: grid; gap: 14px;
  padding: 10px 20px calc(20px + env(safe-area-inset-bottom)); border-radius: 22px 22px 0 0; background: var(--surface); color: var(--text);
  box-shadow: 0 -20px 60px -20px rgb(0 0 0 / 60%); animation: app-up var(--t-med) var(--ease-out); }
@media (min-width: 761px) { .app-sheet { left: 50%; right: auto; width: 440px; transform: translateX(-50%); bottom: 24px; border-radius: 22px; animation: none; } }
@keyframes app-up { from { transform: translateY(40px); opacity: 0; } }
.app-sheet .grab { justify-self: center; width: 40px; height: 5px; border-radius: 3px; background: var(--line-strong); }
.app-sheet h2 { margin: 0; font: 800 20px/1.2 var(--font-display); }
.app-sheet p { margin: 0; color: var(--text-2); font-size: 14px; line-height: 1.5; }
.app-sheet .actions { display: grid; gap: 8px; }
.app-sheet .btn { min-height: 48px; }
.app-sheet input[type="search"] { width: 100%; min-height: 48px; }
.app-pick { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.app-pick button { width: 100%; min-height: 48px; display: flex; align-items: center; gap: 10px; padding: 0 12px; border-radius: var(--r-md); border: 1px solid var(--line-strong);
  background: var(--surface-2); color: var(--text); font: 600 15px/1 var(--font-body); text-align: left; cursor: pointer; }
.app-pick .h { color: var(--text-2); font-weight: 500; font-size: 13px; }
.app-pinned { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: var(--r-md); background: color-mix(in oklab, var(--leader) 14%, var(--surface-2)); }
.app-toggles { display: grid; gap: 4px; }
.app-toggles label { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; font-size: 15px; }
.app-toggles input { width: 22px; height: 22px; accent-color: var(--brand); }
.app-ios-share { display: inline-block; width: 18px; height: 18px; vertical-align: -3px; }
.sk { border-radius: var(--r-md); min-height: 48px; background-color: var(--surface-2);
  background-image: linear-gradient(90deg, transparent, color-mix(in oklab, var(--text) 7%, transparent), transparent);
  background-size: 200px 100%; background-repeat: no-repeat; animation: app-shimmer 1.4s ease-in-out infinite; }
@keyframes app-shimmer { from { background-position: -200px 0; } to { background-position: calc(100% + 200px) 0; } }

/* Offline page */
.offline-list { list-style: none; margin: 0; padding: 0; }
.offline-list a { display: flex; align-items: center; min-height: 52px; padding: 0 var(--s-4); border-top: 1px solid var(--line); color: var(--text); text-decoration: none; }

@media (prefers-reduced-motion: reduce) { .app-next, .app-badge-live::before, .sk, .app-ptr.go i, .app-sheet { animation: none !important; } }

/* The installed app's home (MobileHome): phones and the installed app only. */
.app-home { display: none; }
@media (max-width: 760px), (display-mode: standalone) {
  .app-home { display: block; position: relative; margin-top: -1px; }
  .app-home ~ .club-hero { display: none; }
  .has-app-home .site-header { display: none; }
  .ah-hero { position: absolute; left: 0; right: 0; top: 0; height: 300px; overflow: hidden; background: radial-gradient(120% 80% at 85% 0%, color-mix(in oklab, var(--accent) 22%, transparent), transparent 60%), var(--bg); }
  .ah-hero img { width: 100%; height: 100%; object-fit: cover; }
  .ah-scrim { position: absolute; inset: 0; background: linear-gradient(180deg, color-mix(in oklab, var(--bg) 35%, transparent), color-mix(in oklab, var(--bg) 45%, transparent) 40%, color-mix(in oklab, var(--bg) 85%, transparent) 70%, var(--bg)); }
  :root[data-mode="light"] .ah-eyebrow { color: var(--brand-on-light, var(--brand)); }
  .ah-top { position: relative; display: flex; align-items: center; justify-content: space-between; padding: calc(env(safe-area-inset-top) + 16px) 16px 0; }
  .ah-club { display: flex; align-items: center; gap: 10px; min-width: 0; color: var(--text); text-decoration: none; font: 800 italic 20px/1.1 var(--font-display); font-stretch: var(--display-stretch); font-style: var(--display-style); }
  .ah-club img, .ah-club svg { width: 40px; height: 40px; border-radius: 10px; object-fit: contain; flex: none; }
  .ah-club span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .ah-me { flex: none; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; color: var(--text); font: 700 13px/1 var(--font-body);
    background: radial-gradient(circle at 32% 28%, color-mix(in oklab, var(--brand) 40%, transparent), var(--surface-2) 72%); box-shadow: inset 0 0 0 2px var(--brand); text-decoration: none; }
  .ah-me svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; }
  .ah-title { position: relative; display: grid; gap: 6px; padding: 52px 16px 0; min-height: 150px; align-content: end; }
  .ah-eyebrow { font: 600 13px/1.3 var(--font-body); color: var(--brand); }
  .ah-title h1 { margin: 0; font: var(--display-weight) 34px/1.05 var(--font-display); font-style: var(--display-style); letter-spacing: -0.02em; text-wrap: balance; }
  .ah-body { position: relative; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; padding: 18px 16px 8px; }
  .ah-body > * { min-width: 0; }
  .has-app-home .live-strip { display: none; }
  .ah-live, .ah-card { display: grid; gap: 10px; padding: 14px; border-radius: var(--r-lg); color: var(--text); text-decoration: none; background: var(--glass); border: 1px solid var(--line); }
  .ah-live { border-color: color-mix(in oklab, var(--live) 45%, transparent); }
  .ah-live.is-running { animation: ah-ring 1.8s cubic-bezier(.22,1,.36,1) infinite; }
  @keyframes ah-ring { 0%, 100% { box-shadow: 0 0 0 1.5px color-mix(in oklab, var(--live) 95%, transparent), 0 20px 50px rgb(0 0 0 / 35%); } 60% { box-shadow: 0 0 0 1.5px var(--live), 0 0 0 10px transparent, 0 0 40px color-mix(in oklab, var(--live) 40%, transparent), 0 20px 50px rgb(0 0 0 / 35%); } }
  .ah-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
  .ah-status { color: color-mix(in oklab, var(--live) 70%, var(--text)); }
  .ah-h { font: var(--display-weight) 21px/1.15 var(--font-display); font-style: var(--display-style); }
  .ah-more { font: 600 13px/1 var(--font-body); color: var(--brand); white-space: nowrap; }
  .ah-chips { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
  .ah-chip { flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font: 700 11px/1 var(--font-body); color: var(--text);
    background: radial-gradient(circle at 32% 28%, color-mix(in oklab, var(--c, var(--brand)) 40%, transparent), var(--surface-2) 72%); box-shadow: 0 0 0 2px var(--c, var(--brand)); }
  .ah-chip-sm { width: 26px; height: 26px; font-size: 10px; }
  .ah-lead { margin-left: 6px; font-size: 13px; color: var(--text-2); }
  .ah-watch { display: flex; align-items: center; justify-content: center; gap: 8px; height: 44px; border-radius: 999px; background: var(--live); color: #111114; font: 700 15px/1 var(--font-body); }
  .ah-card .btn { justify-self: start; }
  .ah-bracket { display: flex; gap: 12px; min-height: 60px; align-items: center; overflow: hidden; }
  .ah-col { display: grid; gap: 5px; align-content: center; }
  .ah-col i { display: block; width: 40px; height: 16px; border-radius: 4px; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line-strong); }
  .ah-col i.ah-done { background: color-mix(in oklab, var(--brand) 25%, transparent); box-shadow: inset 0 0 0 1px var(--brand); }
  .ah-col i.ah-live { background: color-mix(in oklab, var(--live) 30%, transparent); box-shadow: inset 0 0 0 1px var(--live); }
  .ah-results { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .ah-live, .ah-card { grid-template-columns: minmax(0, 1fr); }
  .ah-results h2 { margin: 4px 0 0; font: var(--display-weight) 19px/1.2 var(--font-display); font-style: var(--display-style); }
  .ah-res { display: flex; align-items: center; gap: 8px; min-height: 52px; padding: 0 8px 0 12px; border-radius: 14px; background: color-mix(in oklab, var(--text) 4%, transparent); }
  .ah-res-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; min-height: 52px; color: var(--text); text-decoration: none; }
  .ah-res-t { font: var(--display-weight) 15px/1.2 var(--font-display); font-style: var(--display-style); max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .ah-res-w { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .ah-play { flex: none; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; color: var(--text); background: color-mix(in oklab, var(--text) 7%, transparent); }
}
@media (prefers-reduced-motion: reduce) { .ah-live.is-running { animation: none; } }

/* On light grounds the live red is deep: white words read better on it. */
:root[data-mode="light"] .ah-watch, :root[data-mode="light"] .app-badge-live { color: #fff; }
:root[data-mode="light"] .app-badge-live::before { background: #fff; }
.site-header .brandmark img { object-fit: contain; }

/* App home (MobileHome): the bracket card's mini-map — every race of the bracket labelled, the one on track lit — and
   "my next heat" inline for the pinned pilot. */
.ah-mini { display: block; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none; }
.ah-mini::-webkit-scrollbar { display: none; }
.ah-mini .lbmini { display: flex; flex-direction: column; gap: 10px; width: max-content; padding: 0; background: none; }
.ah-mini .lbmini .lane { display: flex; gap: 10px; align-items: center; }
.ah-mini .lbmini .col { display: flex; flex-direction: column; gap: 4px; }
.ah-mini .lbmini .m { display: grid; place-items: center; width: 40px; height: 17px; border-radius: 4px; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line-strong); }
.ah-mini .lbmini .m i { font: 700 9.5px/1 var(--font-mono); font-style: normal; color: var(--text-3); }
.ah-mini .lbmini .m.done { background: color-mix(in oklab, var(--brand) 25%, transparent); box-shadow: inset 0 0 0 1px var(--brand); }
.ah-mini .lbmini .m.done i { color: var(--text); }
.ah-mini .lbmini .m.ondeck { background: color-mix(in oklab, var(--leader) 22%, transparent); box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--leader) 60%, transparent); }
.ah-mini .lbmini .m.racing, .ah-mini .lbmini .m.here { background: color-mix(in oklab, var(--live) 32%, transparent); box-shadow: inset 0 0 0 1px var(--live), 0 0 10px color-mix(in oklab, var(--live) 45%, transparent); }
.ah-mini .lbmini .m.racing i { color: var(--text); }
.ah-next-slot { display: grid; }
.ah-next { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: var(--r-lg); color: var(--text); text-decoration: none;
  background: color-mix(in oklab, var(--leader) 14%, var(--surface)); border: 1px solid color-mix(in oklab, var(--leader) 55%, transparent); }
.ah-next .av { flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font: 700 15px/1 var(--font-body); color: var(--text);
  background: radial-gradient(circle at 32% 28%, color-mix(in oklab, var(--c, var(--brand)) 40%, transparent), var(--surface-2) 72%); box-shadow: 0 0 0 2px var(--c, var(--brand)); }
.ah-next .b { flex: 1; min-width: 0; display: grid; gap: 2px; }
.ah-next .k { font: 700 12px/1.2 var(--font-body); color: var(--leader); }
:root[data-mode="light"] .ah-next .k { color: color-mix(in oklab, var(--leader) 60%, black); }
.ah-next .t { font: 700 16px/1.25 var(--font-body); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ah-next .s { font-size: 12.5px; color: var(--text-2); }
.ah-next .chip { flex: none; font: 600 11px/1 var(--font-mono); padding: 4px 7px; border-radius: 999px; background: var(--c, var(--brand)); color: #111114; white-space: nowrap; }
