/* ============================================================
   app.css — the whole design system.
   ------------------------------------------------------------
   One stylesheet rather than PaddleClub's twelve. That project split CSS
   per page and ended up with three definitions of a card and two of a
   table, because nothing forced them together. At this size a single file
   with clear sections is easier to keep consistent, which is the actual
   goal — "more consistent PWA" was the whole brief.

   Sections:
     1. Tokens          — colours, spacing, type scale
     2. Reset & base
     3. Layout          — page, main, header, tab bar
     4. Components      — buttons, cards, forms, tables, badges
     5. Feature blocks  — leaderboard, schedule, teams, achievements
     6. Utilities
   ============================================================ */

/* ── 1. Tokens ────────────────────────────────────────────────────────── */

:root {
  /* Overwritten at runtime by shell.js applyClubColour(). The defaults are
     basketball orange, which is also what a club gets if it never picks. */
  --primary: #f97316;
  --primary-soft: #fb9a4d;
  --on-primary: #ffffff;
  --tint: rgba(249, 115, 22, 0.14);
  --tint-strong: rgba(249, 115, 22, 0.28);

  --success: #3fb950;
  --danger: #f85149;
  --warning: #d29922;

  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 18px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, monospace;

  /* The tab bar's height plus the iOS home indicator inset. Every scrollable
     page pads its bottom by this, or the last row sits under the bar — the
     single most common "the app is broken" report on an installed PWA. */
  --tabbar-h: 62px;
}

[data-theme='dark'] {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1c2129;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

[data-theme='light'] {
  --bg: #f6f8fa;
  --surface: #ffffff;
  --surface-2: #f0f3f6;
  --border: #d0d7de;
  --text: #1f2328;
  --text-muted: #636c76;
  --shadow: 0 4px 16px rgba(31, 35, 40, 0.08);
}

/* ── 2. Reset & base ──────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Stops the pull-to-refresh rubber-band revealing the page background behind
   an installed PWA, which looks like the app has come loose from the screen. */
body { overscroll-behavior-y: none; }

h1, h2, h3 { margin: 0 0 var(--space-3); line-height: 1.25; font-weight: 650; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 var(--space-3); }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Visible focus for keyboard users only. :focus-visible rather than :focus so
   a mouse click on a button doesn't leave a ring behind it. */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ── 3. Layout ────────────────────────────────────────────────────────── */

/* Pages start hidden and fade in once shell.js confirms the session, so a
   signed-out visitor never sees a flash of the app before being redirected. */
body.app { opacity: 0; }
body.app.ready { opacity: 1; transition: opacity 0.12s ease-out; }

main {
  max-width: 720px;
  margin: 0 auto;
  padding: var(--space-4) var(--space-4) calc(var(--tabbar-h) + var(--space-6));
}

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.page-header .sub { color: var(--text-muted); font-size: 0.875rem; }

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: var(--tabbar-h);
  /* The safe-area inset keeps the bar above the iOS home indicator. Without
     it the rightmost tab is partly under the gesture area and taps get eaten
     by the system swipe. */
  padding-bottom: env(safe-area-inset-bottom, 0);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}

.tabbar a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--space-2) 0;
  color: var(--text-muted);
  font-size: 0.6875rem;
  text-decoration: none;
  /* 44px is Apple's minimum touch target and the reason the bar is 62px
     rather than the 48 it would need for the icon and label alone. */
  min-height: 44px;
}
.tabbar a svg { width: 22px; height: 22px; }
.tabbar a[aria-current='page'] { color: var(--primary); }
.tabbar a:hover { text-decoration: none; }

.tabbar .record { position: relative; }
.tabbar .fab {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  margin-top: -18px;
  border-radius: 50%;
  background: linear-gradient(180deg, var(--primary-soft), var(--primary));
  color: var(--on-primary);
  box-shadow: var(--shadow);
}
.tabbar .fab svg { width: 26px; height: 26px; }

/* ── 4. Components ────────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  margin-bottom: var(--space-3);
}
.card.tinted { background: linear-gradient(180deg, var(--tint), transparent), var(--surface); }
.card-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
  font-weight: 650;
}

button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: 0 var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 550;
  cursor: pointer;
  text-decoration: none;
}
button:hover, .btn:hover { border-color: var(--text-muted); text-decoration: none; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(180deg, var(--primary-soft), var(--primary));
  border-color: transparent;
  color: var(--on-primary);
}
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-sm { min-height: 34px; padding: 0 var(--space-3); font-size: 0.8125rem; }
.btn-block { width: 100%; }

label { display: block; margin-bottom: var(--space-1); font-size: 0.8125rem; color: var(--text-muted); }

input, select, textarea {
  width: 100%;
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  /* 16px minimum, always. Anything smaller makes iOS Safari zoom the whole
     page on focus and never zoom back out — which reads as the app breaking
     the moment you tap a field. */
  font-size: 16px;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); outline: none; }

.field { margin-bottom: var(--space-3); }

/* Two fields side by side. The min-width:0 on children is load-bearing and
   was a real bug in the old app: without it, a native date or number input
   refuses to shrink below its intrinsic width and the row overflows the
   phone screen, wider than everything around it. */
.field-row { display: flex; gap: var(--space-3); }
.field-row > * { flex: 1; min-width: 0; }

/* For genuinely awkward pairs (a date next to a location), stack instead of
   forcing a row. Preferred over fighting .field-row with media queries. */
.field-col { display: flex; flex-direction: column; gap: var(--space-3); }

.check {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 44px;
  padding: var(--space-2) 0;
  cursor: pointer;
}
.check input { width: 20px; height: 20px; min-height: 0; flex: none; }
.check span { color: var(--text); font-size: 1rem; }

table { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
th, td { padding: var(--space-2) var(--space-2); text-align: left; }
th { color: var(--text-muted); font-size: 0.75rem; font-weight: 550; text-transform: uppercase; letter-spacing: 0.03em; }
tbody tr { border-top: 1px solid var(--border); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge {
  display: inline-block;
  padding: 2px var(--space-2);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 550;
}
.badge.primary { background: var(--tint); color: var(--primary); }
.badge.success { background: rgba(63, 185, 80, 0.15); color: var(--success); }
.badge.danger { background: rgba(248, 81, 73, 0.15); color: var(--danger); }
.badge.warning { background: rgba(210, 153, 34, 0.15); color: var(--warning); }

.avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 50%;
  background: var(--tint-strong);
  color: var(--text);
  font-size: 0.8125rem;
  font-weight: 650;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--space-4));
  transform: translate(-50%, 16px);
  z-index: 100;
  max-width: calc(100% - 32px);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: var(--danger); color: var(--danger); }

.update-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  padding-top: calc(var(--space-2) + env(safe-area-inset-top, 0));
  background: var(--primary);
  color: var(--on-primary);
  font-size: 0.875rem;
}
.update-banner button {
  min-height: 32px;
  padding: 0 var(--space-3);
  background: rgba(255, 255, 255, 0.2);
  border-color: transparent;
  color: inherit;
}

.empty {
  padding: var(--space-6) var(--space-4);
  text-align: center;
  color: var(--text-muted);
}
.empty .icon { font-size: 2rem; margin-bottom: var(--space-2); }

/* Skeleton rows while data loads. Better than a spinner because the page
   doesn't jump when content arrives — the layout is already the right shape. */
.skeleton {
  height: 44px;
  margin-bottom: var(--space-2);
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ── 5. Feature blocks ────────────────────────────────────────────────── */

/* Next-step banner. Carried over from the old app, where it replaced a
   blocking alert() after marking a session active — the alert stopped the
   flow to tell you what to do next, which is exactly backwards. */
.next-step {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-3);
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  background: var(--tint);
}
.next-step .actions { display: flex; gap: var(--space-2); }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: var(--space-2);
}
.stat {
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  text-align: center;
}
.stat .value { font-size: 1.375rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .label { font-size: 0.75rem; color: var(--text-muted); }

.rank-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  border-top: 1px solid var(--border);
}
.rank-row:first-child { border-top: none; }
.rank-row .rank { width: 24px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.rank-row .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-row .rating { font-variant-numeric: tabular-nums; font-weight: 650; }
.rank-row.me { background: var(--tint); border-radius: var(--radius-sm); padding-left: var(--space-2); padding-right: var(--space-2); }

.session-row {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  border-top: 1px solid var(--border);
}
.session-row:first-child { border-top: none; }
.session-row .when { flex: none; width: 62px; text-align: center; }
.session-row .when .day { font-size: 1.25rem; font-weight: 700; }
.session-row .when .mon { font-size: 0.6875rem; color: var(--text-muted); text-transform: uppercase; }
.session-row .body { flex: 1; min-width: 0; }
.session-row .actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-2); }

.teams-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
/* Below 420px two roster columns squeeze names to two characters. Stacking
   is the honest answer at that width. */
@media (max-width: 420px) { .teams-grid { grid-template-columns: 1fr; } }

.team-panel { padding: var(--space-3); border: 1px solid var(--border); border-radius: var(--radius); }
.team-panel.a { border-top: 3px solid var(--primary); }
.team-panel.b { border-top: 3px solid var(--text-muted); }
.team-panel h3 { display: flex; justify-content: space-between; }
.team-panel ul { margin: 0; padding: 0; list-style: none; }
.team-panel li { display: flex; justify-content: space-between; gap: var(--space-2); padding: var(--space-1) 0; font-size: 0.9375rem; }

.achv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: var(--space-2); }
.achv {
  padding: var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  text-align: center;
}
.achv .icon { font-size: 1.5rem; }
.achv .name { font-size: 0.6875rem; font-weight: 550; }
/* Unearned badges are dimmed, not hidden, and still show their criteria on
   the profile. That only works if every one is actually achievable — see the
   audit note at the top of src/logic/achievements.js. */
.achv.locked { opacity: 0.35; filter: grayscale(1); }

.auth-shell {
  max-width: 380px;
  margin: 0 auto;
  padding: var(--space-7) var(--space-4) var(--space-6);
}
.auth-shell .logo { text-align: center; font-size: 3rem; margin-bottom: var(--space-2); }
.auth-shell h1 { text-align: center; }
.auth-shell .tagline { text-align: center; color: var(--text-muted); margin-bottom: var(--space-5); }
.auth-switch { text-align: center; margin-top: var(--space-4); font-size: 0.875rem; color: var(--text-muted); }

.error-text { color: var(--danger); font-size: 0.875rem; margin-top: var(--space-2); }

.content { max-width: 640px; margin: 0 auto; padding: var(--space-5) var(--space-4) var(--space-7); }
.content h2 { margin-top: var(--space-5); }
.content ul { padding-left: var(--space-5); }
.content li { margin-bottom: var(--space-2); }

.footer-version {
  margin-top: var(--space-6);
  text-align: center;
  color: var(--text-muted);
  font-size: 0.75rem;
}

/* ── 6. Utilities ─────────────────────────────────────────────────────── */

.muted { color: var(--text-muted); }
.small { font-size: 0.8125rem; }
.mono { font-family: var(--mono); }
.row { display: flex; align-items: center; gap: var(--space-2); }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mb-0 { margin-bottom: 0; }
.hidden { display: none !important; }
.pos { color: var(--success); }
.neg { color: var(--danger); }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Respect a reduced-motion preference. The shimmer and fade are decoration;
   for someone with vestibular sensitivity they are not. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
