/* ============================================================
   PADEL PAL — appearance tokens and the System / Light / Dark switch.
   Shared by every page (marketing, legal, all four spectator pages) and
   loaded AFTER each page's own styles so these tokens win.

   The values are PadelPalTheme.swift's, appearance for appearance:

                      dark        light
     background       #000000     #F2F2F7
     surface          #1C1C1E     #FFFFFF
     border           #3A3A3C     #E5E5EA
     text             #FFFFFF     #000000
     muted            #8E8E93     #6C6C70
     green (fill)     #C9FD69     #7BC818   carries black content
     greenText        #C9FD69     #3F7A0C   green used AS text or a thin line
     deuce            #FFD60A     #B8860B
     team1 / team2    #F05AA5 / #5AF0F0     never change: the panels are the brand
     serving ball     #CCFF00 on a #1A1A1A disc

   theme.js sets <html data-theme="light|dark"> before first paint.
   ============================================================ */

:root {
  color-scheme: dark;
  --bg: #000000;
  --surface: #1C1C1E;
  --surface-2: #0F0F10;
  --border: #3A3A3C;
  --text: #FFFFFF;
  --muted: #8E8E93;
  --green: #C9FD69;
  --green-text: #C9FD69;
  --team1: #F05AA5;
  --team2: #5AF0F0;
  /* Team colours used as TEXT on the page background. Bright cyan on white is
     1.4:1, so light mode swaps in a darker ink of the same hue for text only.
     Panels, bars and chips keep the true team colours in both appearances. */
  --team1-text: #F05AA5;
  --team2-text: #5AF0F0;
  --orange: #FF9F0A;
  --orange-text: #FF9F0A;
  --serve: #CCFF00;
  --serving: #CCFF00;
  --serve-disc: #1A1A1A;
  --deuce: #FFD60A;
  --on-panel-secondary: rgba(0,0,0,0.75);   /* PadelPalTheme.onPanelSecondary */

  /* derived */
  --green-tint: rgba(201,253,105,0.14);
  --green-line: rgba(201,253,105,0.32);
  --hairline: rgba(255,255,255,0.08);
  --wash: rgba(255,255,255,0.05);
  --nav-bg: rgba(0,0,0,0.78);
  --card-shadow: 0 16px 50px rgba(201,253,105,0.06);
  --device-shadow: 0 40px 80px rgba(0,0,0,0.55), 0 4px 18px rgba(0,0,0,0.4);
  --glow-1: rgba(240,90,165,0.14);
  --glow-2: rgba(90,240,240,0.12);
  --glow-3: rgba(201,253,105,0.10);
  /* the landscape scoreboard: the gap between panels is the app background */
  --board-gap: #000000;
  --board-pill: rgba(60,40,60,0.55);
  --board-pill-label: rgba(255,255,255,0.6);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #F2F2F7;
  --surface: #FFFFFF;
  --surface-2: #F2F2F7;
  --border: #E5E5EA;
  --text: #000000;
  --muted: #6C6C70;
  --green: #7BC818;
  --green-text: #3F7A0C;
  --team1-text: #C2185B;
  --team2-text: #007A80;
  --orange-text: #955200;
  --deuce: #B8860B;

  --green-tint: rgba(123,200,24,0.16);
  --green-line: rgba(63,122,12,0.35);
  --hairline: rgba(0,0,0,0.08);
  --wash: rgba(0,0,0,0.04);
  --nav-bg: rgba(242,242,247,0.82);
  --card-shadow: 0 16px 44px rgba(0,0,0,0.09);
  --device-shadow: 0 34px 70px rgba(20,20,40,0.22), 0 4px 16px rgba(20,20,40,0.12);
  --glow-1: rgba(240,90,165,0.20);
  --glow-2: rgba(90,240,240,0.26);
  --glow-3: rgba(123,200,24,0.18);
  --board-gap: #FFFFFF;
  --board-pill: rgba(255,255,255,0.55);
  --board-pill-label: rgba(0,0,0,0.5);
}

/* ---------- per-appearance content (screenshots, etc.) ----------
   Two <img> per screenshot, one per appearance; only the matching one is
   displayed. Both are loading="lazy", and a display:none lazy image is never
   fetched, so a visitor downloads one set. */
.t-light { display: none !important; }
:root[data-theme="light"] .t-dark { display: none !important; }
:root[data-theme="light"] .t-light { display: block !important; }

/* ---------- appearance change ---------- */
.theme-fade, .theme-fade *, .theme-fade *::before, .theme-fade *::after {
  transition: background-color .4s ease, color .4s ease, border-color .4s ease,
              fill .4s ease, stroke .4s ease, box-shadow .4s ease !important;
}
.theme-wipe::view-transition-old(root),
.theme-wipe::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
.theme-wipe::view-transition-new(root) { z-index: 2; }
.theme-wipe::view-transition-old(root) { z-index: 1; }

/* ---------- the switch: an iOS segmented control, three icons ---------- */
.theme-switch {
  position: relative; display: inline-grid; grid-template-columns: repeat(3, 30px);
  align-items: center; flex: none;
  padding: 3px; border-radius: 100px;
  background: var(--wash); border: 1px solid var(--border);
}
.theme-switch:empty { display: none; }   /* no JS: nothing to switch with */
.theme-switch button {
  position: relative; z-index: 1;
  width: 30px; height: 28px; border: 0; padding: 0; background: none;
  display: grid; place-items: center; cursor: pointer;
  color: var(--muted); border-radius: 100px;
  transition: color .2s;
  -webkit-tap-highlight-color: transparent;
}
.theme-switch button svg { width: 15px; height: 15px; display: block; }
.theme-switch button:hover { color: var(--text); }
.theme-switch button[aria-checked="true"] { color: var(--green-text); }
.theme-switch button:focus-visible { outline: 2px solid var(--green-text); outline-offset: 2px; }
.theme-thumb {
  position: absolute; top: 3px; left: 3px; width: 30px; height: 28px;
  border-radius: 100px; background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 1px 4px rgba(0,0,0,0.18);
  transition: transform .32s cubic-bezier(.3,1.3,.5,1);
}
:root[data-theme-pref="light"] .theme-thumb { transform: translateX(30px); }
:root[data-theme-pref="dark"]  .theme-thumb { transform: translateX(60px); }
/* Larger hit area on touch screens (44pt tall with the padding) */
@media (pointer: coarse) {
  .theme-switch { grid-template-columns: repeat(3, 36px); }
  .theme-switch button { width: 36px; height: 34px; }
  .theme-thumb { width: 36px; height: 34px; }
  :root[data-theme-pref="light"] .theme-thumb { transform: translateX(36px); }
  :root[data-theme-pref="dark"]  .theme-thumb { transform: translateX(72px); }
}
@media (prefers-reduced-motion: reduce) { .theme-thumb { transition: none; } }

/* ---------- the serving ball: lime on its dark disc, as in the app ----------
   PadelPalTheme.ServingBall: the disc carries the contrast against the pink
   and cyan panels (bare lime on cyan is 1.18:1), the ball keeps its colour. */
.pp-serve-ball { display: block; }

/* ============================================================
   SPECTATOR PAGES (spectator, -king, -americano, -league)
   Each page keeps its own inline styles; these rules make them follow
   the appearance and bring them in line with 1.0.3. Written un-gated
   wherever a token already carries both appearances (--green-text is
   --green in dark), so most rules below need no [data-theme] at all.
   ============================================================ */

/* shared chrome that named a colour directly */
nav[aria-label="Main"] { background: var(--nav-bg); }
.logo-text { color: var(--text); }
.nav-right { display: flex; align-items: center; gap: 16px; }
@media (max-width: 900px) {
  :root[data-theme="light"] .nav-links { background: var(--surface); }
}

/* the appearance switch where a page has no nav bar */
.theme-float { position: fixed !important; top: 14px; right: 14px; z-index: 40; }
body:has(#scoreboard.visible) .theme-float { display: none; }
.topbar > .live-pill, .header-bar > .live-pill { margin-right: auto; }

/* green used as text or as a hairline */
.entry-title .accent, .loading-code, .loading-code-inline, .entry-badge-text,
.score-table .win-check, .score-table .g.live-col, .score-table th.live-col,
.set-line .cur-tag, .info-row .v.accent,
.live-pill, .live-pill .label, .live-pill-text,
.audio-toggle.on, .audio-toggle.on .audio-label,
.sb-footer a, .footer a,
.stand-row .name.champion, .stand-row .pts.champion, .stand-row .sw.champion, .stand-row .crown,
table.standings td.team.champion, table.standings td.pts.champion,
.h2h-num.lead, .status-tag.ad, .court-block .card-header span:last-child {
  color: var(--green-text);
}
.loading-code-inline { font-weight: 800; }
.live-pill { background: var(--green-tint); border-color: var(--green-line); }
.live-dot, .live-pill .dot { background: var(--green-text); }
.audio-toggle.on { border-color: var(--green-line); }
.set-line .cur-tag, .status-tag.ad { background: var(--green-tint); }
.entry-code-input:focus, .code-entry input:focus, .code-input:focus { border-color: var(--green-text); }
.spinner, .spin { border-top-color: var(--green-text); }

/* team colours used as text on the page (the panels keep the true colours) */
.set-line .games .g1.won, .info-row .v.t1, .status-tag.advantage-t1,
.side-panel.a .side-names { color: var(--team1-text); }
.set-line .games .g2.won, .info-row .v.t2, .status-tag.advantage-t2,
.side-panel.b .side-names { color: var(--team2-text); }
.status-tag.tiebreak, .status-tag.tb, .set-line .tb-tag, .set-row .tb-tag, .tied-banner .title { color: var(--orange-text); }

/* washes that assumed a black page */
.status-tag.deuce, .status-tag.set, .status-tag.rest { background: var(--wash); }
#scoreboard.finished .live-pill { background: var(--wash); border-color: var(--border); }
#scoreboard.finished .live-pill .dot { background: var(--muted); }
#scoreboard.finished .live-pill .label { color: var(--muted); }
.code-entry input::placeholder { color: var(--muted); opacity: .45; }
.footer-entry { color: var(--muted); }
.entry-card:hover { box-shadow: var(--card-shadow); }
.row, table.standings td, .fix-row { border-top-color: var(--border); }
:root[data-theme="light"] .side-panel.a { background: rgba(240,90,165,0.10); }
:root[data-theme="light"] .side-panel.b { background: rgba(90,240,240,0.16); border-color: rgba(0,150,160,0.5); }
:root[data-theme="light"] .entry-badge:not(:has(.entry-badge-dot)) { color: var(--text); }
/* the floating set strip in the full-bleed board sits on its own dark glass */
.ls-status { color: #fff; }
.ls-status .ls-set .lbl, .ls-status .ls-set .vsep { color: #A1A1A6; }

/* serving ball: the 1.0.3 lime-on-dark-disc mark needs no tint of its own */
.panel .serve-ball { color: inherit; }

/* 1.0.3 copy: links open in the app */
.app-hint {
  margin: 22px auto 0; max-width: 320px; padding-top: 18px; border-top: 1px solid var(--border);
  font-size: 12.5px; line-height: 1.6; color: var(--muted);
}
.app-hint strong { color: var(--text); font-weight: 700; }
.sb-footer .get-app {
  display: block; width: fit-content; margin: 0 auto 14px; padding: 9px 16px; border-radius: 100px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); font-weight: 700; letter-spacing: .4px;
  transition: border-color .2s, transform .2s;
}
.sb-footer .get-app:hover { border-color: var(--muted); transform: translateY(-1px); }

/* RECONNECTING: the connection dropped but the last score stays up, exactly
   as the in-app viewer does. spectator-common.js puts .reconnecting on <body>.
   Done in CSS so the four pages' different pill markup needs no changes. */
body.reconnecting .live-pill {
  font-size: 0 !important; gap: 6px;
  background: rgba(255,159,10,0.15) !important; border-color: rgba(255,159,10,0.4) !important;
}
body.reconnecting .live-pill > * { display: none; }
body.reconnecting .live-pill::before {
  content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--orange);
  animation: pulse 1s ease-in-out infinite;
}
body.reconnecting .live-pill::after {
  content: 'RECONNECTING'; font-family: var(--font-mono); font-size: 10px; font-weight: 700;
  letter-spacing: 2px; color: var(--orange-text);
}

/* a point lands: the number that changed gives a small bounce */
@keyframes point-pop { 0% { transform: scale(1); } 35% { transform: scale(1.12); } 100% { transform: scale(1); } }
.point-pop { animation: point-pop .45s ease; }
/* screens and cards ease in rather than snapping */
@keyframes screen-in { from { opacity: 0; translate: 0 14px; } to { opacity: 1; translate: 0 0; } }
.entry-card, #scoreboard.visible .board-main, #scoreboard.visible .card,
#scoreboard.visible .matchup, #scoreboard.visible .banner, .winner-overlay.visible, .champ-banner {
  animation: screen-in .5s cubic-bezier(.2,.7,.2,1) both;
}
#scoreboard.visible .card:nth-of-type(2) { animation-delay: .07s; }
#scoreboard.visible .card:nth-of-type(3) { animation-delay: .14s; }
#scoreboard.visible .card:nth-of-type(4) { animation-delay: .21s; }
#scoreboard.board-full .board-main, #scoreboard.landscape-board .matchup { animation: none; }
@media (prefers-reduced-motion: reduce) {
  .point-pop, .entry-card, #scoreboard .board-main, #scoreboard .card, #scoreboard .matchup,
  #scoreboard .banner, .winner-overlay, .champ-banner { animation: none !important; }
}

/* links in the small print follow the text, not the browser's default blue */
.footer-entry a, .sb-footer .report-link, .footer .report-link { color: inherit; }

/* A screenshot that failed to load hands over to its other-appearance twin
   (home.js marks the frame), so a phone is never shown empty. */
.no-light .t-light, .no-dark .t-dark { display: none !important; }
:root[data-theme="light"] .no-light .t-dark { display: block !important; }
:root[data-theme="dark"] .no-dark .t-light, :root:not([data-theme]) .no-dark .t-light { display: block !important; }
