/* Mobile race-bracket card feed — shared by the public bracket page's <768px
   block (race-bracket-public.html) and the standalone PWA page
   (race-bracket-public-mobile.html). The markup comes from the shared
   bracket-mobile-feed.html fragment; behaviour from bracket-mobile.js.

   Tokens resolve mp-page vars first (the native PWA shell), then the site
   theme vars (base.html pages), then a light fallback. --lb-pad is the page
   gutter the round carousel bleeds into: .85rem on the site page, 16px on
   the PWA shell (set by that page). */

.lb-mobile {
    --lb-border: var(--mp-border, var(--border, #e4e4e7));
    --lb-surface: var(--mp-bg-card, var(--surface, #ffffff));
    --lb-surface-soft: var(--mp-bg-subtle, var(--surface-muted, #f7f7f8));
    --lb-accent: var(--mp-primary, var(--color-primary, var(--accent, #0070f3)));
    --lb-text: var(--mp-text, var(--text, #18181b));
    --lb-text-soft: var(--mp-text-muted, var(--text-muted, #6b7280));
    --lb-pad: .85rem;
    --lbm-mono: ui-monospace, "JetBrains Mono", "SF Mono", "Menlo", "Consolas", monospace;
    color: var(--lb-text);
}

/* Sticky toolbar, stacked rows: view segments (+ Up next), then the lane
   filter chips at full width, then the round tabs — so Winners/Redemption
   never fight the Cards|Diagram|Standings switch for space */
.lbm-toolbar {
    position: sticky; top: 0; z-index: 6;
    display: flex; flex-direction: column; gap: .5rem;
    padding: .55rem 0 .5rem;
    margin: 0 0 .35rem;
    background: color-mix(in oklab, var(--lb-surface) 90%, transparent);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--lb-border);
}
.lbm-viewrow { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
/* collapse the row entirely when neither the segments nor Up next render
   (e.g. the desktop page's narrow-window feed with no panes) */
.lbm-viewrow:not(:has(:not([hidden]))) { display: none; }
.lbm-chips { display: flex; gap: .4rem; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; flex: 1; min-width: 0; }
.lbm-chips::-webkit-scrollbar { display: none; }
.lbm-chip {
    flex-shrink: 0;
    border: 1px solid var(--lb-border); border-radius: 999px;
    background: var(--lb-surface);
    color: var(--lb-text-soft);
    font-size: .78rem; font-weight: 600;
    padding: .4rem .8rem;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.lbm-chip .n { font-family: var(--lbm-mono); font-size: .66rem; opacity: .7; margin-left: .25rem; }
.lbm-chip.is-active { background: var(--lb-accent); border-color: var(--lb-accent); color: #fff; }
/* display:flex on these would beat the UA's [hidden] rule — restate it */
.lbm-jump[hidden], .lbm-follow-pill[hidden], .lbm-card[hidden], .lbm-round[hidden] { display: none; }
.lbm-jump {
    flex-shrink: 0;
    display: inline-flex; align-items: center; gap: .3rem;
    border: 1px solid color-mix(in oklab, var(--lb-accent) 45%, var(--lb-border));
    color: var(--lb-accent);
    background: color-mix(in oklab, var(--lb-accent) 12%, transparent);
    border-radius: 999px;
    font-size: .78rem; font-weight: 700;
    padding: .4rem .8rem;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

/* Cards | Diagram segmented view switch (shown only when the page renders
   a #lbmSvgPane — the standalone PWA page does) */
.lbm-viewseg {
    flex-shrink: 0;
    display: inline-flex; align-items: center;
    border: 1px solid var(--lb-border); border-radius: 999px;
    background: var(--lb-surface-soft);
    padding: 2px;
}
.lbm-viewseg[hidden] { display: none; }
.lbm-viewseg-btn {
    border: 0; border-radius: 999px;
    background: transparent;
    color: var(--lb-text-soft);
    font-size: .74rem; font-weight: 700;
    padding: .34rem .7rem;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.lbm-viewseg-btn.is-active { background: var(--lb-accent); color: #fff; }
.lbm-viewseg-btn[hidden] { display: none; }

/* Standings pane — the third view segment (shown when the page renders a
   #lbmResultsPane, i.e. standings are available) */
.lbm-respane[hidden] { display: none; }
.lbm-respane { margin-top: .35rem; }

/* Round tabs — the pager for the horizontal round carousel below */
.lbm-roundtabs {
    display: flex; gap: .4rem;
    overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.lbm-roundtabs::-webkit-scrollbar { display: none; }
.lbm-roundtab {
    flex-shrink: 0;
    border: 1px solid var(--lb-border); border-radius: 999px;
    background: var(--lb-surface);
    color: var(--lb-text-soft);
    font-family: var(--lbm-mono);
    font-size: .74rem; font-weight: 700;
    padding: .34rem .8rem;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.lbm-roundtab[hidden] { display: none; }
.lbm-roundtab.is-active { background: var(--lb-text); border-color: var(--lb-text); color: var(--lb-surface); }
/* Accent dot on the tab whose round holds the on-deck heat */
.lbm-roundtab.has-live::after {
    content: ''; display: inline-block; width: 6px; height: 6px;
    border-radius: 50%; background: var(--lb-accent);
    margin-left: .35rem; vertical-align: 1px;
}

/* Round carousel — one round per screen, swipe horizontally between them.
   The wrap's height is JS-managed to the active panel so a short final round
   doesn't inherit round 1's height. */
.lbm-rounds {
    position: relative;
    display: flex; align-items: flex-start;
    overflow-x: auto; overflow-y: hidden;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    margin: 0 calc(-1 * var(--lb-pad));
    transition: height .28s ease;
}
.lbm-rounds::-webkit-scrollbar { display: none; }
.lbm-round {
    min-width: 100%; box-sizing: border-box;
    scroll-snap-align: start; scroll-snap-stop: always;
    padding: 0 var(--lb-pad) 1rem;
}
.lbm-round-head {
    display: flex; align-items: baseline; gap: .6rem;
    font-family: var(--lbm-mono);
    font-size: .7rem; font-weight: 700; letter-spacing: .18em; text-transform: uppercase;
    color: var(--lb-text-soft);
    margin: .9rem 0 .6rem;
}
.lbm-round-head::after { content: ''; flex: 1; height: 1px; background: var(--lb-border); }

/* Race cards */
.lbm-cards { display: flex; flex-direction: column; gap: .65rem; }
.lbm-card {
    position: relative;
    border: 1px solid var(--lb-border);
    border-radius: 14px;
    background: var(--lb-surface);
    padding: .6rem .7rem .55rem .8rem;
    scroll-margin-top: 72px;
    --lane: var(--lb-accent);
    transition: opacity .25s ease;
}
.lbm-card::before { content: ''; position: absolute; left: 0; top: 12px; bottom: 12px; width: 3px; border-radius: 0 3px 3px 0; background: var(--lane); opacity: .85; }
/* Lane colour tokens — shared by the cards AND the flow chips that point at
   a heat in that lane */
.lb-mobile .lane-winners    { --lane: var(--lane-winners, #2a8); }
.lb-mobile .lane-redemption { --lane: var(--lane-redemption, #a33); }
.lb-mobile .lane-gf         { --lane: var(--lane-grandfinal, #a87); }
.lb-mobile .lane-cta        { --lane: var(--lane-cta, #339); }
.lb-mobile .lane-filler     { --lane: #888; }
.lbm-card.lane-filler       { opacity: .82; }
/* Generic-format lanes (points mains "A Main"/"B Main"…, mains-progression
   mains, ladder) — a rotating palette assigned by first appearance */
.lb-mobile .lane-g0 { --lane: #2aa88a; }
.lb-mobile .lane-g1 { --lane: #4e8fd1; }
.lb-mobile .lane-g2 { --lane: #c9822a; }
.lb-mobile .lane-g3 { --lane: #9a6dd7; }
.lb-mobile .lane-g4 { --lane: #d16a9a; }
.lb-mobile .lane-g5 { --lane: #58a84c; }
.lb-mobile .lane-g6 { --lane: #d1584e; }
.lb-mobile .lane-g7 { --lane: #3fadc9; }
/* The SVG's lane hexes are tuned for light surfaces — lift them on dark */
[data-theme="dark"] .lb-mobile .lane-winners    { --lane: var(--lane-winners, #34c99c); }
[data-theme="dark"] .lb-mobile .lane-redemption { --lane: var(--lane-redemption, #e06c6c); }
[data-theme="dark"] .lb-mobile .lane-gf         { --lane: var(--lane-grandfinal, #d0a17c); }
[data-theme="dark"] .lb-mobile .lane-cta        { --lane: var(--lane-cta, #8b9aff); }
.lbm-card.status-waiting  { background: color-mix(in oklab, var(--lb-surface-soft) 55%, var(--lb-surface)); }
.lbm-card.status-next {
    border-color: color-mix(in oklab, var(--lb-accent) 55%, var(--lb-border));
    box-shadow: 0 0 0 1px color-mix(in oklab, var(--lb-accent) 35%, transparent),
                0 6px 18px color-mix(in oklab, var(--lb-accent) 12%, transparent);
}
.lbm-card-head { display: flex; align-items: center; gap: .5rem; margin-bottom: .4rem; }
.lbm-lane-tag { font-family: var(--lbm-mono); font-size: .6rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--lane); }
.lbm-code { font-family: var(--lbm-mono); font-size: .76rem; font-weight: 800; color: var(--lb-text); background: var(--lb-surface-soft); border: 1px solid var(--lb-border); border-radius: 6px; padding: .05rem .4rem; }
.lbm-head-spacer { flex: 1; }
.lbm-pill { flex-shrink: 0; font-family: var(--lbm-mono); font-size: .6rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; border-radius: 999px; padding: .24rem .55rem; display: inline-flex; align-items: center; gap: .3rem; }
.lbm-pill.done  { color: var(--lb-text-soft); background: var(--lb-surface-soft); }
.lbm-pill.next  { color: #fff; background: var(--lb-accent); }
.lbm-pill.ready { color: var(--lb-accent); border: 1px solid color-mix(in oklab, var(--lb-accent) 45%, var(--lb-border)); }
.lbm-pill.wait  { color: var(--lb-text-soft); border: 1px dashed var(--lb-border); }
.lbm-pill .lbm-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: lbm-pulse 1.6s ease-in-out infinite; }
@keyframes lbm-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.45; }
}

/* Pilot rows — 46px touch targets; tap a pilot to follow them */
.lbm-pilots { list-style: none; margin: 0; padding: 0; }
.lbm-pilot {
    display: flex; align-items: center; gap: .6rem;
    min-height: 46px;
    padding: .25rem .3rem;
    border-radius: 10px;
    -webkit-tap-highlight-color: transparent;
}
.lbm-pilot + .lbm-pilot { border-top: 1px solid color-mix(in oklab, var(--lb-border) 55%, transparent); }
.lbm-pilot.adv { background: color-mix(in oklab, var(--lane) 8%, transparent); }
.lbm-ava {
    flex-shrink: 0; width: 34px; height: 34px; border-radius: 50%;
    overflow: hidden; display: inline-flex; align-items: center; justify-content: center;
    background: var(--lb-surface-soft); border: 1px solid var(--lb-border);
    font-weight: 700; font-size: .9rem; color: var(--lb-text-soft);
}
.lbm-ava img { width: 100%; height: 100%; object-fit: cover; display: block; }
.lbm-pilot.ghost .lbm-ava { border-style: dashed; background: transparent; }
.lbm-name { flex: 1; min-width: 0; font-size: .95rem; font-weight: 600; letter-spacing: -.01em; display: flex; align-items: baseline; gap: .4rem; overflow: hidden; }
.lbm-name .lbm-nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lbm-seed { flex-shrink: 0; font-family: var(--lbm-mono); font-size: .7rem; font-weight: 700; color: var(--lb-text-soft); }
.lbm-from { font-family: var(--lbm-mono); font-size: .8rem; font-weight: 600; color: var(--lb-text-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lbm-chan { flex-shrink: 0; font-family: var(--lbm-mono); font-size: .64rem; font-weight: 800; border-radius: 999px; padding: .2rem .5rem; border: 1px solid rgba(0,0,0,.2); }
.lbm-pos { flex-shrink: 0; font-family: var(--lbm-mono); font-size: .68rem; font-weight: 800; letter-spacing: .06em; min-width: 2.6em; text-align: center; border-radius: 7px; padding: .24rem .3rem; color: var(--lb-text-soft); background: var(--lb-surface-soft); }
.lbm-pos.p1 { background: #d4a017; color: #1a1205; }
.lbm-pos.p2 { background: #c0c5cc; color: #1c1f24; }
.lbm-pos.p3 { background: #cd7f32; color: #1c0f04; }
.lbm-adv { flex-shrink: 0; font-weight: 800; color: var(--lane); font-size: .85rem; }

/* Card-to-card flow chips — the tappable relationships between heats.
   Outgoing: "1st–2nd → W2-1" (where finishers go, coloured by the target
   lane); incoming: "← W1-1" (who feeds this heat). Tapping swipes the
   carousel to that card and flashes it. */
.lbm-flow { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .55rem; padding-top: .5rem; border-top: 1px dashed color-mix(in oklab, var(--lb-border) 70%, transparent); }
.lbm-flow-chip {
    display: inline-flex; align-items: center; gap: .3rem;
    font-family: var(--lbm-mono); font-size: .66rem; font-weight: 700;
    border: 1px solid var(--lb-border); border-radius: 999px;
    background: var(--lb-surface-soft);
    color: var(--lb-text-soft);
    padding: .3rem .6rem;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.lbm-flow-chip .code { color: var(--lane, var(--lb-text)); font-weight: 800; }
.lbm-flow-chip .arr { opacity: .6; }
.lbm-flow-chip:active { background: var(--lb-border); }

/* Jump-target flash — the destination card pulses so the relationship the
   user just tapped is unmissable after the carousel lands */
.lbm-card.lbm-flash { animation: lbm-flash 1.6s ease; }
@keyframes lbm-flash {
    0%, 55% { box-shadow: 0 0 0 2.5px var(--lb-accent), 0 8px 22px color-mix(in oklab, var(--lb-accent) 25%, transparent); }
    100% { box-shadow: 0 0 0 0 transparent; }
}
/* Ghost feeder rows are jump targets too — hint with a dotted underline */
.lbm-pilot.ghost[data-goto] .lbm-from { text-decoration: underline dotted; text-underline-offset: 3px; cursor: pointer; }

/* Waiting note + card actions */
.lbm-waiting-on { margin: .3rem 0 0 .3rem; font-size: .74rem; color: var(--lb-text-soft); }
.lbm-card-actions { display: flex; gap: .5rem; margin-top: .5rem; }
.lbm-watch, .lbm-livelink {
    display: inline-flex; align-items: center; gap: .35rem;
    font-size: .78rem; font-weight: 700; text-decoration: none;
    border-radius: 999px; padding: .42rem .85rem;
    -webkit-tap-highlight-color: transparent;
}
.lbm-watch { background: #ff4d4d; color: #fff; }
.lbm-livelink { border: 1px solid var(--lb-border); color: var(--lb-text-soft); }

/* Follow-a-pilot mode — highlight-only, never dim. (Dimming the other cards
   read as "the page is broken/dark" to pilots who tapped a row without
   noticing, so the followed pilot's heats light up instead.) */
.lbm-card.has-me {
    border-color: color-mix(in oklab, var(--lb-accent) 60%, var(--lb-border));
    box-shadow: 0 0 0 1.5px color-mix(in oklab, var(--lb-accent) 40%, transparent),
                0 6px 18px color-mix(in oklab, var(--lb-accent) 14%, transparent);
}
.lbm-pilot.is-me { background: color-mix(in oklab, var(--lb-accent) 14%, transparent); box-shadow: inset 0 0 0 1.5px color-mix(in oklab, var(--lb-accent) 60%, transparent); }
.lbm-follow-pill {
    position: fixed; left: 50%; transform: translateX(-50%);
    bottom: calc(.9rem + env(safe-area-inset-bottom, 0px));
    z-index: 1100; /* above the fixed bottom navs */
    display: flex; align-items: center; gap: .4rem;
    background: var(--lb-text); color: var(--lb-surface);
    border-radius: 999px;
    padding: .4rem .45rem .4rem 1rem;
    box-shadow: 0 8px 24px rgba(0,0,0,.28);
    font-size: .82rem; font-weight: 600;
    max-width: calc(100vw - 2rem);
}
/* Ride above the app bottom tab bars (site pages inject .mobile-bottom-nav on
   phones; the PWA shell renders .mp-nav) so the pilot can always dismiss it */
body:has(.mobile-bottom-nav) .lbm-follow-pill,
body:has(.mp-nav) .lbm-follow-pill {
    bottom: calc(86px + env(safe-area-inset-bottom, 0px));
}
.lbm-follow-pill > span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lbm-follow-pill button {
    flex-shrink: 0;
    border: 0; border-radius: 999px; cursor: pointer;
    font-size: .78rem; font-weight: 700;
    padding: .4rem .75rem;
    background: color-mix(in oklab, var(--lb-surface) 18%, transparent);
    color: inherit;
    -webkit-tap-highlight-color: transparent;
}

/* Diagram (SVG) view — the toolbar's Diagram toggle swaps the card carousel
   for the page's #lbmSvgPane (the same live SVG the desktop page shows).
   Lane chips / round tabs / Up-next only make sense on the cards, so they
   hide while the diagram is up. */
.lbm-svg-view .lbm-chips, .lbm-svg-view .lbm-roundtabs, .lbm-svg-view .lbm-rounds { display: none; }
.lbm-svgpane[hidden] { display: none; }
.lbm-svgpane {
    border: 1px solid var(--lb-border);
    border-radius: 14px;
    background: var(--lb-surface);
    overflow: hidden;
    margin-top: .35rem;
}
.lbm-svgzoom {
    display: flex; align-items: center; justify-content: flex-end; gap: .25rem;
    padding: .4rem .5rem;
    border-bottom: 1px solid var(--lb-border);
    background: var(--lb-surface-soft);
}
.lbm-svgzoom button {
    width: 34px; height: 34px;
    border: 1px solid var(--lb-border); border-radius: 50%;
    background: var(--lb-surface);
    color: var(--lb-text);
    font-size: 1rem; font-weight: 700; line-height: 1;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.lbm-svgzoom .z {
    font-family: var(--lbm-mono);
    font-size: .72rem; font-variant-numeric: tabular-nums;
    color: var(--lb-text-soft);
    min-width: 3.2em; text-align: center;
}
.lbm-svgscroll {
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    max-height: 72vh;
    padding: .75rem;
}
.lbm-svgscroll svg { display: block; }
.lbm-svghint { padding: .45rem .75rem; font-size: .72rem; color: var(--lb-text-soft); border-top: 1px solid var(--lb-border); }

@media (prefers-reduced-motion: reduce) {
    .lbm-pill .lbm-dot { animation: none; }
    .lbm-card { transition: none; }
    .lbm-rounds { transition: none; }
    .lbm-card.lbm-flash { animation: none; box-shadow: 0 0 0 2.5px var(--lb-accent); }
}
