/* ================================================================
   Heritage — Design System for Group Golf Manager
   Cream paper, forest ink, gold foil. Country-club refined.
   ================================================================ */

:root {
  /* Each variable is declared twice: a hex fallback that every browser
     understands, then the oklch() value. Browsers that don't understand
     oklch (Chrome <111, Android System WebView <111, iOS Safari <15.4)
     silently ignore the second line and keep the hex — the page renders
     with the same palette in colour, just without the wide-gamut nuance. */
  --paper: #f9f2e4;
  --paper: oklch(0.965 0.02 85);
  --paper-deep: #efe6d5;
  --paper-deep: oklch(0.93 0.025 85);
  --paper-rule: #ddd6c9;
  --paper-rule: oklch(0.88 0.02 85);
  --ink: #101e13;
  --ink: oklch(0.22 0.03 150);
  --ink-soft: #404a42;
  --ink-soft: oklch(0.40 0.02 150);
  --ink-faint: #7b827a;
  --ink-faint: oklch(0.60 0.015 140);
  --green: #093d1b;
  --green: oklch(0.32 0.08 150);
  --green-deep: #002303;
  --green-deep: oklch(0.22 0.08 150);
  --green-light: #d2ecd6;
  --green-light: oklch(0.92 0.04 150);
  --foil: #c38c25;
  --foil: oklch(0.68 0.13 78);
  --foil-deep: #975800;
  --foil-deep: oklch(0.52 0.13 70);
  --claret: #89211c;
  --claret: oklch(0.42 0.14 28);
  --sel-bg: #ffe7b2;
  --sel-bg: oklch(0.95 0.08 75);

  --font-serif: 'Fraunces', Georgia, serif;
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', monospace;
}

/* ---------- Reset / base ---------- */
html, body { margin: 0; padding: 0; }
body {
  min-height: 100vh;
  font-family: var(--font-sans);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
* { box-sizing: border-box; }
button, input, textarea, select { font-family: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 500; }

/* Utility */
.hidden { display: none !important; }

/* ---------- Typography primitives ---------- */
.h-serif { font-family: var(--font-serif); letter-spacing: -0.02em; }
.mono-eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.2em;
  color: var(--ink-faint);
  text-transform: uppercase;
}

/* Links styled with mono-eyebrow (back links, etc.) — larger + higher contrast
   so they're readable and clearly tappable for older users. */
a.mono-eyebrow {
  color: var(--ink-soft);
  font-size: 13px;
  letter-spacing: 0.16em;
  padding: 6px 2px;
  border-bottom: 1px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
a.mono-eyebrow:hover {
  color: var(--foil-deep);
  border-bottom-color: var(--foil-deep);
}
.serif-italic { font-family: var(--font-serif); font-style: italic; }

/* ---------- App shell ---------- */
.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  /* Disable accidental double-tap-to-zoom (especially while picking names
     from the roster on a phone). Pinch-zoom still works for accessibility. */
  touch-action: manipulation;
}
.container {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 0 20px;
}
.container-wide {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ================================================================
   LOGIN
   ================================================================ */
.login-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
}
.login-hero {
  position: relative;
  padding: 40px 32px 52px;
  background: radial-gradient(circle at 85% 0%, var(--green), var(--green-deep) 70%);
  color: var(--paper);
  border-radius: 34px;
  max-width: 520px;
  width: 100%;
  margin: 24px auto 0;
}
.login-hero .eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.24em;
  opacity: 0.7;
}
.login-hero h1 {
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 56px;
  line-height: 0.92;
  letter-spacing: -0.035em;
  margin: 16px 0 12px;
  color: var(--paper);
}
.login-hero h1 em { font-style: italic; color: var(--foil); }
.login-hero .rule {
  height: 1px;
  width: 56px;
  background: var(--foil);
  opacity: 0.8;
  margin: 10px 0 16px;
}
.login-hero p {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 16px;
  opacity: 0.85;
  line-height: 1.4;
  margin: 0;
  max-width: 340px;
}

.login-body {
  flex: 1;
  padding: 26px 32px 0;
  max-width: 520px;
  margin: 0 auto;
  width: 100%;
}
.section-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}
.section-head .num {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 15px;
  color: var(--foil-deep);
}
.section-head .divider {
  flex: 1;
  height: 1px;
  background: var(--paper-rule);
}
.section-head .tag {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.22em;
  color: var(--ink-faint);
}

.login-body h2 {
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: 32px;
  letter-spacing: -0.02em;
  color: var(--ink);
  margin: 0 0 4px;
}
.login-body .lede {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 16px;
  color: var(--ink-soft);
  margin: 0 0 24px;
}

.field { display: block; margin-bottom: 18px; }
.field label {
  display: block;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.16em;
  color: var(--ink-soft);
  text-transform: uppercase;
  margin-bottom: 8px;
}
.field input {
  width: 100%;
  border: none;
  border-bottom: 1.5px solid var(--ink);
  padding: 8px 0 10px;
  font-family: var(--font-serif);
  font-size: 20px;
  background: transparent;
  outline: none;
  color: var(--ink);
}
.field input::placeholder { color: var(--ink-faint); font-style: italic; }
.field input:focus { border-bottom-color: var(--foil-deep); }

.btn-cta {
  width: 100%;
  margin-top: 28px;
  padding: 16px 20px;
  border: none;
  background: var(--green);
  color: var(--paper);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.05em;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background 0.15s;
}
.btn-cta:hover:not(:disabled) { background: var(--green-deep); }
.btn-cta:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-cta .arrow {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 18px;
  color: var(--foil);
}

.login-footer {
  padding: 22px 32px;
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.2em;
  color: var(--ink-faint);
}

.error-banner {
  padding: 12px 14px;
  background: oklch(0.95 0.05 28);
  border-left: 3px solid var(--claret);
  color: var(--claret);
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 14px;
  margin-bottom: 18px;
}

/* ================================================================
   TOP MASTHEAD (shared across game/admin)
   ================================================================ */
.masthead {
  padding: 12px 20px 14px;
  border-bottom: 1px solid var(--paper-rule);
  background: var(--paper);
  position: sticky;
  top: 0;
  z-index: 40;
}
.masthead-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
}
.masthead .eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.2em;
  color: var(--ink-faint);
  text-transform: uppercase;
}
.masthead h1 {
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: 30px;
  line-height: 1;
  letter-spacing: -0.03em;
  color: var(--ink);
  margin: 4px 0 0;
}
.masthead h1 em { font-style: italic; color: var(--foil-deep); }

.masthead-actions { display: flex; gap: 8px; align-items: center; }
.icon-btn {
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid var(--paper-rule);
  background: white;
  font-size: 15px;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: var(--paper-deep); }
.text-link {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.16em;
  color: var(--ink-soft);
  text-transform: uppercase;
  padding: 8px 10px;
  border: 1px solid var(--paper-rule);
  background: white;
}
.text-link:hover { border-color: var(--foil-deep); color: var(--foil-deep); }
.text-link.admin-link { background: var(--foil); color: var(--ink); border-color: var(--foil); }

/* ================================================================
   SEGMENTED TABS (Game phone)
   ================================================================ */
.segmented {
  display: flex;
  background: var(--paper-deep);
  padding: 4px;
  gap: 2px;
  margin: 12px 20px 0;
}
.seg-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  padding: 10px 12px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
}
.seg-btn.active {
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 1px 3px oklch(0 0 0 / 0.08);
}
.seg-btn .count {
  font-family: var(--font-mono);
  font-size: 11px;
  background: transparent;
  color: var(--ink-faint);
  padding: 2px 6px;
}
.seg-btn.active .count {
  background: var(--foil);
  color: var(--ink);
}

/* ================================================================
   GAME DAY — PANELS
   ================================================================ */
.game-layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Search bar — sits at the top of the roster; stays fixed because the
   whole game page is pinned to viewport height and only the player list
   scrolls. No sticky needed. */
.search-row {
  padding: 12px 20px 10px;
  display: flex;
  gap: 10px;
  align-items: center;
  background: var(--paper);
  border-bottom: 1px solid var(--paper-rule);
  flex-shrink: 0;
}
.search-input-wrap { flex: 1; position: relative; }
.search-input-wrap::before {
  content: "⌕";
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-faint);
  pointer-events: none;
}
.search-input {
  width: 100%;
  border: 1px solid var(--paper-rule);
  background: white;
  padding: 10px 36px 10px 34px;
  font-family: var(--font-sans);
  /* 16px is the minimum that prevents iOS Safari from auto-zooming the
     viewport when the input gains focus (and never zooming back out). */
  font-size: 16px;
  outline: none;
  color: var(--ink);
}
.search-input:focus { border-color: var(--foil-deep); }

/* Clear-search X button — appears only when input has text */
.search-clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border: none;
  background: var(--paper-deep);
  color: var(--ink-soft);
  font-size: 18px;
  line-height: 1;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: background 0.12s, color 0.12s;
}
.search-clear:hover {
  background: var(--foil);
  color: var(--ink);
}
.count-badge {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.14em;
  color: var(--ink-soft);
}

.reset-btn {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
  background: transparent;
  border: 1px solid var(--paper-rule);
  padding: 6px 10px;
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.reset-btn:hover {
  color: var(--claret);
  border-color: var(--claret);
  background: white;
}

/* Player list */
.player-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 20px 100px;
  -webkit-overflow-scrolling: touch;
}
.player-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 0;
  border-bottom: 1px dashed var(--paper-rule);
  cursor: default;
  transition: background-color 0.6s ease;
  position: relative;
}
/* Row dimming removed — the green checkmark vs empty circle is sufficient
   signal, and dimming made names hard to read (especially when filtering). */

/* Brief highlight after a toggle so the user can see what they just changed
   even though the row hasn't moved. Fades back to normal in ~1.8s. */
.player-item.just-toggled {
  background-color: rgba(168, 134, 75, 0.14);
  transition: background-color 0.2s ease;
}

/* Toggle button — generous tap area (44px hit target) wrapping a 30px circle. */
.player-item .toggle-playing {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: transparent;
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: rgba(168, 134, 75, 0.3);
  touch-action: manipulation;
}
.player-item .toggle-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: transparent;
  border: 1.5px solid var(--paper-rule);
  color: transparent;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 18px;
  line-height: 1;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, transform 0.12s;
}
.player-item .toggle-playing:active .toggle-mark { transform: scale(0.92); }
.player-item.is-playing .toggle-mark {
  background: var(--green);
  border-color: var(--green);
  color: var(--foil);
}
.player-item .name {
  flex: 1;
  min-width: 0;
  font-family: var(--font-serif);
  font-size: 16px;
  color: var(--ink);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.player-item .name .first-name { color: var(--ink-faint); font-weight: 400; }
.player-item .hcp {
  font-family: var(--font-mono);
  font-size: 13px;
  min-width: 32px;
  text-align: right;
  color: var(--ink);
  font-weight: 500;
  flex-shrink: 0;
}

/* Floating re-sort action — appears whenever the visible order doesn't
   match the natural one (playing-then-not-playing, alphabetical within). */
.panel-players { position: relative; }

/* Roster-mismatch warning shown above the teams panel when the saved
   teams don't match today's "playing" set. */
.stale-banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 0 14px 10px;
  padding: 10px 14px;
  border: 1px solid var(--foil);
  background: #fff4d8;                            /* hex fallback */
  background: oklch(0.96 0.05 75);
  border-radius: 8px;
  font-family: var(--font-serif);
  font-size: 14px;
  color: var(--foil-deep);
}
.stale-banner .stale-icon { font-size: 16px; line-height: 1.4; flex-shrink: 0; }
.stale-banner .stale-text { flex: 1; line-height: 1.45; }
.stale-banner .stale-text strong { color: var(--foil-deep); font-weight: 600; }
.stale-banner .stale-counts {
  display: block;
  font-family: var(--font-sans);
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 2px;
}
.stale-banner .stale-rebuild {
  display: inline-block;
  margin-top: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--foil-deep);
  background: var(--foil-deep);
  color: var(--paper);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
}
.stale-banner .stale-rebuild:hover { filter: brightness(1.06); }
.stale-banner.hidden { display: none; }

/* Floating "back to top" — appears once the roster has been scrolled
   down. Sits just under the search row so it's visible near the header. */
.back-to-top-fab {
  position: absolute;
  top: 76px;
  right: 14px;
  z-index: 5;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--paper-rule);
  background: var(--paper, #f5ecd6);
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(38, 28, 18, 0.16),
              0 1px 2px rgba(38, 28, 18, 0.12);
  /* Hidden until the list is scrolled */
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  touch-action: manipulation;
}
.back-to-top-fab.visible {
  opacity: 0.95;
  pointer-events: auto;
  transform: translateY(0);
}
.back-to-top-fab:hover { opacity: 1; }
.back-to-top-fab:active { transform: translateY(0) scale(0.96); }
.back-to-top-fab .arrow { font-size: 14px; line-height: 1; }
.reorder-fab {
  position: absolute;
  right: 16px;
  /* Lift above iOS Safari's bottom URL bar (env() ~34px on iPhone) and
     give a bit of extra clearance so Android Chrome's bottom gesture
     pill / chrome doesn't eclipse the button. */
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  z-index: 5;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  border-radius: 999px;
  border: 1.5px solid var(--green);
  background: var(--green);
  color: var(--foil, #f5ecd6);
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow:
    0 8px 18px rgba(38, 56, 38, 0.22),
    0 2px 4px rgba(38, 56, 38, 0.18);
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.18s ease;
  animation: reorder-fab-rise 0.22s ease;
  touch-action: manipulation;
}
.reorder-fab .arrow {
  font-size: 18px;
  line-height: 1;
  transform: translateY(-1px);
}
.reorder-fab:hover {
  transform: translateY(-1px);
  box-shadow:
    0 12px 22px rgba(38, 56, 38, 0.26),
    0 3px 6px rgba(38, 56, 38, 0.2);
}
.reorder-fab:active { transform: translateY(0); }
.reorder-fab.hidden {
  display: none;
}
@keyframes reorder-fab-rise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Roster empty state */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 40px;
  text-align: center;
}
.empty-state .icon {
  width: 72px;
  height: 72px;
  margin-bottom: 20px;
}
.empty-state h3 {
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: 26px;
  color: var(--ink);
  margin: 0 0 6px;
  letter-spacing: -0.02em;
}
.empty-state h3 em { font-style: italic; color: var(--foil-deep); }
.empty-state p {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 15px;
  color: var(--ink-soft);
  margin: 0 0 24px;
  line-height: 1.4;
  max-width: 280px;
}

/* Floating "Make Teams" button */
.fab {
  position: fixed;
  bottom: 22px;
  right: 20px;
  padding: 14px 22px;
  border: none;
  background: var(--green);
  color: var(--paper);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.05em;
  box-shadow: 0 10px 24px oklch(0.22 0.08 150 / 0.3);
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 20;
}
.fab .arrow { color: var(--foil); font-family: var(--font-serif); font-style: italic; }

/* ---------- Teams panel ---------- */
.teams-controls {
  padding: 14px 20px 8px;
}
.teams-controls .mono-eyebrow { margin-bottom: 8px; }
.count-options {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.count-btn {
  min-width: 44px;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--paper-rule);
  background: white;
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 500;
}
.count-btn.active {
  border-color: var(--green);
  background: var(--green);
  color: var(--foil);
}

.count-desc {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 13px;
  color: var(--ink-soft);
  margin-top: 8px;
}
.count-desc .swap-hint { color: var(--claret); }

.team-actions-bar {
  padding: 6px 20px 10px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.pill-btn {
  padding: 8px 12px;
  border: 1px solid var(--paper-rule);
  background: white;
  font-family: var(--font-sans);
  font-size: 12px;
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
}
.pill-btn:hover { border-color: var(--foil-deep); }
.pill-btn.primary {
  background: var(--green);
  color: var(--paper);
  border-color: var(--green);
}
.pill-btn.primary:hover { background: var(--green-deep); border-color: var(--green-deep); }
.pill-btn.foil {
  background: var(--foil);
  border-color: var(--foil);
  color: var(--ink);
  font-weight: 500;
}
.pill-btn.foil:hover { background: var(--foil-deep); border-color: var(--foil-deep); color: var(--paper); }
.pill-btn.amber { background: oklch(0.97 0.06 75); border-color: var(--foil); color: var(--foil-deep); }
.spacer { flex: 1; }

/* Selection toolbar */
.selection-toolbar {
  padding: 10px 20px;
  background: oklch(0.95 0.05 75);
  border-top: 1px solid var(--paper-rule);
  border-bottom: 1px solid var(--paper-rule);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 12px;
}
.selection-toolbar .info {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--foil-deep);
  text-transform: uppercase;
}

/* Teams scroll area — wraps action bar + hint + team cards so they scroll
   together, leaving only the "HOW MANY TEAMS?" controls locked above. */
.teams-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Teams container — the inner list; padding lives here so cards have
   breathing room on the sides regardless of outer wrapper. */
.teams-container {
  padding: 8px 20px 24px;
}
.teams-empty {
  text-align: center;
  padding: 50px 20px;
  color: var(--ink-faint);
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 15px;
}

/* Team card */
.team-card {
  background: white;
  border: 1px solid var(--paper-rule);
  margin-bottom: 14px;
  overflow: hidden;
  animation: fadeIn 0.25s ease forwards;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.team-card.locked {
  border-color: var(--foil-deep);
  box-shadow: 0 0 0 1px var(--foil-deep) inset, 0 4px 14px oklch(0.52 0.13 70 / 0.1);
}

.team-head {
  padding: 14px 18px;
  background: var(--green);
  color: var(--paper);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.team-card.locked .team-head { background: var(--foil-deep); }

.team-head .num {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.18em;
  color: var(--foil);
}
.team-card.locked .team-head .num { color: var(--paper); }

.team-name {
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 500;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.team-head .lock-btn {
  border: none;
  background: transparent;
  color: var(--foil);
  font-size: 14px;
  padding: 4px 6px;
}
.team-card.locked .team-head .lock-btn { color: var(--paper); }

.team-avg {
  display: flex;
  align-items: baseline;
  gap: 4px;
  white-space: nowrap;
}
.team-avg-label {
  font-family: var(--font-mono);
  font-size: 11px;
  opacity: 0.75;
  letter-spacing: 0.16em;
}
.team-avg-val {
  font-family: var(--font-serif);
  font-size: 20px;
  color: var(--foil);
}

.team-members { /* container */ }
.team-member {
  padding: 12px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px dashed var(--paper-rule);
  background: white;
  transition: background 0.15s;
}
.team-member:last-child { border-bottom: none; }
.team-member:hover { background: oklch(0.98 0.01 85); }
.team-member.captain { background: oklch(0.98 0.03 80); }
.team-member.selected {
  background: var(--sel-bg);
  outline: 2px solid var(--foil-deep);
  outline-offset: -2px;
}
.team-member .rank {
  width: 26px;
  text-align: center;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 16px;
  color: var(--ink-faint);
  flex-shrink: 0;
}
.team-member.captain .rank { color: var(--foil-deep); }
.team-member .m-name-wrap { flex: 1; min-width: 0; }
.team-member .m-name {
  font-family: var(--font-serif);
  font-size: 16px;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.team-member .m-captain-label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  color: var(--foil-deep);
}
.team-member .m-hcp {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ink-soft);
  font-weight: 500;
  flex-shrink: 0;
}

/* ================================================================
   MODAL
   ================================================================ */
.modal {
  position: fixed;
  inset: 0;
  background: oklch(0 0 0 / 0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}
.modal-card {
  background: var(--paper);
  width: 100%;
  max-width: 560px;
  padding: 18px 24px 24px;
  border-top-left-radius: 22px;
  border-top-right-radius: 22px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
.modal-card .handle {
  width: 40px;
  height: 4px;
  background: var(--paper-rule);
  margin: 0 auto 18px;
  border-radius: 2px;
}
.modal-card h3 {
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 500;
  margin: 0 0 4px;
  color: var(--ink);
  letter-spacing: -0.01em;
}
.modal-card .sub {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 13px;
  color: var(--ink-soft);
  margin: 0 0 18px;
}
.modal-body { overflow-y: auto; flex: 1; }
.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 22px;
}
.btn-secondary {
  flex: 1;
  padding: 14px;
  border: 1px solid var(--paper-rule);
  background: white;
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 13px;
}
.btn-primary {
  flex: 2;
  padding: 14px;
  border: none;
  background: var(--green);
  color: var(--paper);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.04em;
}
.btn-primary:hover { background: var(--green-deep); }
.btn-primary.btn-danger { background: var(--claret); }
.btn-primary.btn-danger:hover { background: oklch(0.35 0.14 28); }

.reset-list {
  font-family: var(--font-serif);
  font-size: 15px;
  color: var(--ink);
  line-height: 1.5;
  margin: 4px 0 0;
  padding-left: 20px;
}
.reset-list li { margin-bottom: 4px; }
.reset-list em { color: var(--foil-deep); font-style: italic; }

/* Reset modal — three-option selector. Each option is a stacked button
   showing a title + short description. */
.reset-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 14px 0 0;
}
.reset-opt {
  text-align: left;
  padding: 12px 14px;
  border: 1px solid var(--paper-rule);
  border-radius: 8px;
  background: #fbf6e8;                            /* hex fallback */
  background: oklch(0.98 0.015 85);
  cursor: pointer;
  font-family: var(--font-serif);
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: border-color 0.12s, background 0.12s;
  touch-action: manipulation;
}
.reset-opt:hover {
  border-color: var(--foil-deep);
  background: var(--paper);
}
.reset-opt:active { transform: scale(0.99); }
.reset-opt-title {
  font-size: 15px;
  font-weight: 500;
  color: var(--ink);
}
.reset-opt-desc {
  font-family: var(--font-sans);
  font-size: 12.5px;
  color: var(--ink-soft);
  line-height: 1.35;
}
.reset-opt.danger { border-color: var(--claret); }
.reset-opt.danger .reset-opt-title { color: var(--claret); }
.reset-opt.danger:hover {
  background: #fbe4e0;                            /* hex fallback */
  background: oklch(0.96 0.04 28);
  border-color: var(--claret);
}

/* Modal form fields */
.modal-field { margin-bottom: 14px; }
.modal-field label {
  display: block;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.2em;
  color: var(--ink-soft);
  text-transform: uppercase;
  margin-bottom: 8px;
}
.modal-field input[type="text"],
.modal-field input[type="email"],
.modal-field input[type="number"],
.modal-field input[type="password"],
.modal-field textarea {
  width: 100%;
  border: none;
  border-bottom: 1.5px solid var(--ink);
  padding: 6px 0 8px;
  font-family: var(--font-serif);
  font-size: 18px;
  background: transparent;
  outline: none;
  color: var(--ink);
}
.modal-field input:focus { border-bottom-color: var(--foil-deep); }
.modal-field.checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
}
.modal-field.checkbox label {
  margin: 0;
  font-family: var(--font-serif);
  font-style: normal;
  font-size: 15px;
  letter-spacing: 0;
  color: var(--ink);
  text-transform: none;
  cursor: pointer;
}
.modal-field.checkbox input {
  margin: 0;
  width: 18px;
  height: 18px;
  accent-color: var(--green);
}

/* ================================================================
   ACTION SHEET — Move / Swap / Cancel picker
   ================================================================ */
.sheet-back-btn {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.16em;
  color: var(--ink-soft);
  background: transparent;
  border: none;
  padding: 6px 8px;
  margin: -6px 0 10px -8px;
  cursor: pointer;
  text-transform: uppercase;
}
.sheet-back-btn:hover { color: var(--foil-deep); }

.sheet-body { padding: 4px 0 8px; }

.sheet-option {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  background: white;
  border: 1px solid var(--paper-rule);
  padding: 16px 18px;
  margin-bottom: 10px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.sheet-option:hover:not(:disabled) {
  border-color: var(--foil-deep);
  background: oklch(0.97 0.02 85);
}
.sheet-option:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.sheet-option-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--green-light);
  color: var(--green);
  font-family: var(--font-serif);
  font-size: 22px;
  flex-shrink: 0;
  border-radius: 50%;
}
.sheet-option-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}
.sheet-option-label {
  font-family: var(--font-serif);
  font-size: 17px;
  color: var(--ink);
  font-weight: 500;
}
.sheet-option-sub {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 13px;
  color: var(--ink-soft);
}
.sheet-option-arrow {
  font-size: 22px;
  color: var(--ink-faint);
  flex-shrink: 0;
}

.sheet-group-label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.22em;
  color: var(--foil-deep);
  text-transform: uppercase;
  padding: 14px 4px 6px;
}
.sheet-group-label:first-child { padding-top: 4px; }

.sheet-pick-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  background: white;
  border: 1px solid var(--paper-rule);
  padding: 14px 16px;
  margin-bottom: 6px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  min-height: 52px;
}
.sheet-pick-row:hover {
  border-color: var(--foil-deep);
  background: oklch(0.97 0.02 85);
}
.sheet-pick-name {
  font-family: var(--font-serif);
  font-size: 16px;
  color: var(--ink);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sheet-pick-hcp {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ink-soft);
  flex-shrink: 0;
}

.sheet-empty {
  padding: 30px 20px;
  text-align: center;
  font-family: var(--font-serif);
  font-style: italic;
  color: var(--ink-soft);
  font-size: 15px;
}

/* Email recipient list */
.email-recipients {
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--paper-rule);
  background: white;
  padding: 8px 12px;
}
.email-recipients label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-serif);
  font-size: 14px;
  color: var(--ink);
  padding: 4px 0;
  text-transform: none;
  letter-spacing: 0;
  margin-bottom: 0;
  cursor: pointer;
}
.email-recipients input {
  width: 16px;
  height: 16px;
  accent-color: var(--green);
}
.email-recipients .email-addr {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-faint);
}
.select-row {
  margin-top: 8px;
  display: flex;
  gap: 12px;
}
.select-row button {
  background: none;
  border: none;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--ink-soft);
  text-transform: uppercase;
  padding: 0;
}
.select-row button:hover { color: var(--foil-deep); }

/* ================================================================
   SAVED CONFIRMATION
   ================================================================ */
.saved-screen {
  flex: 1;
  overflow-y: auto;
  padding: 28px 24px 32px;
  text-align: center;
}
.saved-check {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 48px;
  color: var(--foil-deep);
  margin-bottom: 6px;
}
.saved-eyebrow {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.3em;
  color: var(--foil-deep);
  margin: 4px 0 4px;
}
.saved-screen h2 {
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 36px;
  color: var(--ink);
  margin: 0 0 8px;
  letter-spacing: -0.025em;
}
.saved-screen h2 em { font-style: italic; color: var(--foil-deep); }
.saved-screen .spread {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 15px;
  color: var(--ink-soft);
  margin: 0 0 22px;
}

/* ================================================================
   ADMIN
   ================================================================ */
/* Sticky top — wraps the header + tab row so they lock together as a unit
   regardless of how tall the header renders. */
.admin-topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--paper);
}

.admin-header {
  padding: 10px 20px 14px;
  border-bottom: 1px solid var(--paper-rule);
  background: var(--paper);
}
.admin-header .top-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.admin-header h1 {
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: 32px;
  letter-spacing: -0.03em;
  color: var(--ink);
  margin: 4px 0 0;
}
.admin-header h1 em { font-style: italic; color: var(--foil-deep); }

.admin-tabs {
  display: flex;
  gap: 0;
  padding: 0 20px;
  border-bottom: 1px solid var(--paper-rule);
  background: var(--paper);
}
.admin-tab {
  padding: 14px 16px;
  border: none;
  background: transparent;
  border-bottom: 2px solid transparent;
  color: var(--ink-soft);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  text-transform: capitalize;
  margin-bottom: -1px;
}
.admin-tab.active {
  border-bottom-color: var(--foil-deep);
  color: var(--ink);
}

.admin-panel { padding: 0 0 100px; }

.admin-search-row {
  padding: 16px 20px 12px;
  display: flex;
  gap: 10px;
  align-items: center;
  border-bottom: 1px solid var(--paper-rule);
  background: var(--paper);
}
.admin-search-row .search-input-wrap { flex: 1; }
.admin-search-row + #players-table .admin-row:first-child { border-top: none; }

/* Desktop/tablet — center admin content to ~960px with auto-scaling padding,
   so the sticky top-bar + border still span the full viewport while the rows
   themselves don't stretch across 1920 pixels of dead space. */
@media (min-width: 900px) {
  .admin-header,
  .admin-tabs,
  .admin-panel {
    padding-left: max(20px, calc((100% - 960px) / 2));
    padding-right: max(20px, calc((100% - 960px) / 2));
  }
  .admin-row,
  .admin-search-row {
    padding-left: 0;
    padding-right: 0;
  }
  .admin-panel { padding-bottom: 100px; }
}

.admin-row {
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid var(--paper-rule);
  background: var(--paper);
  cursor: pointer;
  transition: background 0.15s;
}
.admin-row:hover { background: var(--paper-deep); }

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  flex-shrink: 0;
}
.avatar.player { background: var(--green-light); color: var(--green); }
.avatar.user { background: var(--paper-deep); color: var(--ink); font-family: var(--font-mono); }
.avatar.course { background: var(--green); color: var(--foil); font-family: var(--font-serif); font-style: italic; font-size: 18px; }

.admin-row .info { flex: 1; min-width: 0; }
.admin-row .info .primary {
  font-family: var(--font-serif);
  font-size: 16px;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.admin-row .info .secondary {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ink-faint);
  margin-top: 3px;
}
.admin-row .hcp-col { text-align: right; flex-shrink: 0; }
.admin-row .hcp-col .num {
  font-family: var(--font-serif);
  font-size: 22px;
  color: var(--foil-deep);
  line-height: 1;
}
.admin-row .hcp-col .lbl {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--ink-faint);
}
.admin-row .chevron { color: var(--ink-faint); font-size: 18px; flex-shrink: 0; }
.admin-row .tags { display: flex; gap: 6px; margin-top: 4px; flex-wrap: wrap; }

.tag {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  padding: 3px 8px;
  background: var(--paper-deep);
  color: var(--ink-soft);
}
.tag.foil { background: var(--foil); color: var(--ink); }
.tag.green { background: var(--green-light); color: var(--green); }
.tag.red { background: oklch(0.95 0.05 28); color: var(--claret); }

.admin-delete-btn {
  padding: 8px 14px;
  border: 1px solid var(--paper-rule);
  background: white;
  color: var(--claret);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-left: 6px;
}
.admin-delete-btn:hover { background: oklch(0.97 0.05 28); }

/* ================================================================
   NO-SELECT ZONES — scroll/drag shouldn't accidentally select text
   ================================================================ */
.player-list,
.player-item,
.teams-container,
.team-card,
.team-head,
.team-members,
.team-member,
.segmented,
.seg-btn,
.count-options,
.count-btn,
.team-actions-bar,
.pill-btn,
.fab,
.nav-rail,
.masthead h1,
.masthead .eyebrow,
.fairness-meter {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
/* …but re-enable selection inside inputs and the team-name rename field */
.team-name input,
input,
textarea {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

/* ================================================================
   DRAG & DROP
   ================================================================ */
.drag-hint {
  padding: 8px 20px;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 13px;
  color: var(--claret);
}

/* Drag ghost — portal'd to body */
.drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 10000;
  transform: rotate(-1.5deg) scale(1.03);
  filter: drop-shadow(0 20px 30px oklch(0 0 0 / 0.25));
}
.drag-ghost-card {
  background: white;
  border: 2px solid var(--foil-deep);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--font-serif);
  font-size: 16px;
  color: var(--ink);
  min-width: 220px;
}
.drag-ghost-card .g-icon {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 16px;
  color: var(--foil-deep);
  width: 26px;
  text-align: center;
}
.drag-ghost-card .g-hcp {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ink-soft);
}

/* Dragging state on the source row */
.team-member.dragging {
  opacity: 0.25;
}

/* Drop target highlights */
.team-card.drop-target {
  outline: 3px dashed var(--foil-deep);
  outline-offset: 2px;
  transition: outline-color 120ms ease;
}
.team-card.drop-source {
  outline: 2px dashed var(--paper-rule);
  outline-offset: 1px;
}
.team-card.drop-rejected {
  outline: 3px solid var(--claret);
  outline-offset: 2px;
  position: relative;
}
.team-card .lock-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: oklch(0.42 0.14 28 / 0.1);
  pointer-events: none;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.2em;
  color: var(--claret);
  font-weight: 600;
}
.team-member.drop-swap-target {
  background: var(--sel-bg);
  outline: 2px solid var(--foil-deep);
  outline-offset: -2px;
}

/* Captain star (clickable) */
.captain-star {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--ink-faint);
  font-size: 18px;
  line-height: 1;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0.6;
  transition: opacity 0.15s, transform 0.1s;
}
.captain-star:hover { opacity: 1; transform: scale(1.15); }
.captain-star.is-captain {
  color: var(--foil-deep);
  opacity: 1;
}
.captain-star.is-captain:hover {
  color: var(--foil);
}

/* Action handle — tap to open a Move / Swap / Cancel menu.
   ☰ icon with a generous 44px tap target. */
.drag-handle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0 10px;
  margin-right: -6px;
  font-size: 22px;
  line-height: 1;
  color: var(--ink-faint);
  opacity: 0.7;
  flex-shrink: 0;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  border: none;
  background: transparent;
  border-radius: 8px;
  transition: opacity 0.12s, color 0.12s, background 0.12s;
}
.drag-handle:hover {
  opacity: 1;
  color: var(--foil-deep);
  background: oklch(0.97 0.02 85);
}
.drag-handle:active { background: oklch(0.94 0.03 85); }

/* ================================================================
   FAIRNESS METER
   ================================================================ */
.fairness-meter {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-sans);
}
.fairness-meter .f-label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.2em;
  color: var(--ink-faint);
}
.fairness-meter .f-bar {
  width: 70px;
  height: 3px;
  background: var(--paper-rule);
}
.fairness-meter .f-fill {
  height: 100%;
  transition: width 200ms ease, background 200ms ease;
}
.fairness-meter .f-val {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 13px;
}
.fairness-meter .f-status {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.14em;
}
.fair-balanced { color: oklch(0.55 0.12 150); }
.fair-balanced-bg { background: oklch(0.55 0.12 150); }
.fair-tilted { color: var(--foil-deep); }
.fair-tilted-bg { background: var(--foil-deep); }
.fair-uneven { color: var(--claret); }
.fair-uneven-bg { background: var(--claret); }

/* ================================================================
   UNDO TOAST
   ================================================================ */
.undo-toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  padding: 10px 10px 10px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  font-family: var(--font-sans);
  font-size: 13px;
  box-shadow: 0 10px 30px oklch(0 0 0 / 0.3);
  z-index: 200;
  max-width: 90vw;
}
.undo-toast button {
  background: var(--foil);
  color: var(--ink);
  border: none;
  padding: 6px 14px;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
}
.undo-toast button.dismiss {
  background: transparent;
  color: var(--paper);
  opacity: 0.6;
  padding: 6px 8px;
  font-size: 16px;
  font-weight: 400;
}

/* Phone defaults — single-column, full-height panels */
.panel-players, .panel-teams {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* dvh = the actually-visible viewport height. On mobile/tablet browsers
     it accounts for the URL bar and gesture chrome dynamically; on desktop
     it equals vh. Fallback to vh for browsers that don't support dvh. */
  min-height: calc(100vh - 180px);
  min-height: calc(100dvh - 180px);
}

/* Nav rail — hidden by default, desktop-only */
.nav-rail { display: none; }

/* ================================================================
   PHONE — lock game page to viewport so masthead + tabs + search
   stay put and only the player/team list scrolls.
   Scoped to .page-game so other pages (login, admin) are unaffected.
   ================================================================ */
@media (max-width: 899px) {
  html:has(.page-game), body:has(.page-game) {
    height: 100%;
    overflow: hidden;
  }
  .app.page-game {
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  .app.page-game .masthead,
  .app.page-game .segmented {
    flex-shrink: 0;
  }
  .app.page-game .game-layout {
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }
  .app.page-game .panel-players,
  .app.page-game .panel-teams {
    height: 100%;
    min-height: 0;
    max-height: none;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  /* Only the search row and the "HOW MANY TEAMS?" controls are locked.
     The action bar + hint + team cards scroll together below. */
  .app.page-game .panel-players .search-row,
  .app.page-game .panel-teams .teams-controls {
    flex-shrink: 0;
  }
  .app.page-game .panel-players .player-list {
    flex: 1;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
    padding-bottom: 24px;
  }
  .app.page-game .panel-teams .teams-scroll {
    flex: 1;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
  }
  .app.page-game .panel-teams .teams-container {
    flex: none;
    min-height: 0;
    overflow: visible;
  }
}

/* ================================================================
   TABLET BREAKPOINT — Game Day two-column
   ================================================================ */
@media (min-width: 900px) {
  .segmented { display: none; }

  .game-layout { display: grid; grid-template-columns: 320px 1fr; height: calc(100vh - 140px); }
  .panel-players, .panel-teams {
    display: flex !important;
    border-right: 1px solid var(--paper-rule);
    min-height: auto;
    height: 100%;
  }
  #panel-teams.hidden { display: flex !important; }
  .panel-teams { border-right: none; }
  .player-list { max-height: calc(100vh - 180px); padding-bottom: 40px; }
  .teams-scroll { max-height: calc(100vh - 180px); }
  /* Keep the FAB fixed but right-align with the centered content column
     instead of the viewport edge. Matches the same 960px clamp used by
     admin-header / admin-tabs / admin-panel. */
  .fab {
    position: fixed;
    bottom: 22px;
    right: max(20px, calc((100% - 960px) / 2));
    margin: 0;
    width: auto;
  }

  .masthead h1 { font-size: 42px; }
}

/* ================================================================
   DESKTOP BREAKPOINT — more air, bigger teams grid
   ================================================================ */
@media (min-width: 1280px) {
  .masthead { padding: 14px 40px 16px; }
  .masthead h1 { font-size: 48px; }
  .masthead .eyebrow { font-size: 10px; }

  .game-layout { grid-template-columns: 360px 1fr; }

  .search-row { padding: 18px 28px 12px; }
  .player-list { padding: 0 28px 60px; }

  .teams-controls { padding: 18px 32px 10px; }
  .team-actions-bar { padding: 8px 32px 12px; }
  .teams-container { padding: 10px 32px 32px; }

  /* Teams as responsive grid */
  #teams-grid {
    display: grid !important;
    grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
    gap: 16px;
  }
  #teams-grid .team-card { margin-bottom: 0; }
}
@media (min-width: 1600px) {
  .game-layout { grid-template-columns: 380px 1fr; }
  #teams-grid { grid-template-columns: repeat(auto-fit, minmax(400px, 1fr)); gap: 20px; }
  .masthead h1 { font-size: 54px; }
}

/* ================================================================
   DESKTOP BREAKPOINT — three-pane: nav rail · roster · teams canvas
   Scoped to .app so pages without an .app wrapper (e.g. /login) are
   untouched at this breakpoint.
   ================================================================ */
@media (min-width: 1400px) {
  .app:has(.nav-rail) {
    display: grid;
    grid-template-columns: 240px 1fr;
    grid-template-rows: auto 1fr;
    min-height: 100vh;
  }

  .nav-rail {
    display: flex; flex-direction: column;
    background: var(--green-deep); color: var(--paper);
    padding: 28px 24px;
    grid-column: 1; grid-row: 1 / -1;
    position: sticky; top: 0;
    max-height: 100vh; overflow-y: auto;
    border-right: 1px solid oklch(0 0 0 / 0.1);
  }
  .nav-rail-brand { display: flex; align-items: center; gap: 12px; }
  .nav-rail-brand .brand-mark {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--foil); color: var(--green-deep);
    display: flex; align-items: center; justify-content: center; font-size: 18px;
  }
  .brand-name { font-family: var(--font-serif); font-size: 20px; font-weight: 500; letter-spacing: -0.02em; color: var(--paper); }
  .brand-mono { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.26em; opacity: 0.7; }
  .nav-rail-spacer { flex: 1; }
  .nav-rail-user { display: flex; flex-direction: column; }
  .nav-rail-eyebrow { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.22em; opacity: 0.65; margin-bottom: 6px; }
  .nav-rail-username { font-family: var(--font-serif); font-size: 18px; font-weight: 500; margin-bottom: 12px; }
  .nav-rail-link {
    display: block; padding: 14px 0; border: none; background: transparent;
    color: var(--paper); opacity: 0.85;
    font-family: var(--font-sans); font-size: 15px; letter-spacing: 0.02em;
    text-align: left; cursor: pointer;
    border-top: 1px solid oklch(1 0 0 / 0.12);
  }
  .nav-rail-link:hover { opacity: 1; color: var(--foil); }

  /* Masthead + game layout fill column 2 (game page only) */
  .app:has(.nav-rail) > .masthead    { grid-column: 2; grid-row: 1; }
  .app:has(.nav-rail) > .segmented   { grid-column: 2; }
  .app:has(.nav-rail) > .game-layout { grid-column: 2; grid-row: 2; min-width: 0; }

  /* Hide the masthead's user controls — they live in the rail now */
  .masthead-actions { display: none; }
  .masthead { padding: 22px 48px 24px; position: static; }
  .masthead h1 { font-size: 52px; }

  /* Roster + teams canvas */
  .game-layout { grid-template-columns: 400px 1fr; height: calc(100vh - 150px); }
  .search-row { padding: 20px 32px 14px; }
  .player-list { padding: 0 32px 40px; }
  .teams-controls { padding: 20px 40px 12px; }
  .team-actions-bar { padding: 8px 40px 12px; }
  .teams-container { padding: 14px 40px 40px; }
  #teams-grid {
    display: grid !important;
    grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
    gap: 18px;
  }
}

/* ================================================================
   PRINT PAGE
   ================================================================ */
body.print-body {
  background: white;
  font-family: var(--font-serif);
  color: var(--ink);
}
.print-sheet {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 56px 64px;
  background: white;
}
.print-masthead {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  border-bottom: 3px double var(--ink);
  padding-bottom: 18px;
  margin-bottom: 28px;
}
.print-masthead .eyebrow {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.3em;
  color: var(--ink-soft);
}
.print-masthead h1 {
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 56px;
  letter-spacing: -0.03em;
  margin: 8px 0 0;
}
.print-masthead h1 em { font-style: italic; color: var(--foil-deep); }
.print-masthead .course-col { text-align: right; }
.print-masthead .course {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 22px;
  color: var(--ink);
}

.print-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px 36px;
  margin-bottom: 32px;
}
.print-team { break-inside: avoid; padding-bottom: 8px; }
.print-team-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  border-bottom: 1.5px solid var(--ink);
  padding-bottom: 6px;
  margin-bottom: 10px;
}
.print-team-head .num {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.2em;
  color: var(--foil-deep);
  margin-right: 12px;
}
.print-team-head .name {
  font-family: var(--font-serif);
  font-size: 28px;
  font-weight: 500;
}
.print-team-head .avg {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-soft);
}
.print-member {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px dotted var(--paper-rule);
}
.print-member .rank {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 14px;
  width: 18px;
  color: var(--ink-faint);
}
.print-member.captain .rank { color: var(--foil-deep); }
.print-member .pm-name {
  flex: 1;
  font-family: var(--font-serif);
  font-size: 17px;
}
.print-member .pm-hcp {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ink-soft);
}

.print-footer {
  border-top: 1px solid var(--paper-rule);
  padding-top: 18px;
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--ink-soft);
}

.print-actions {
  max-width: 900px;
  margin: 16px auto 40px;
  padding: 0 64px;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

@media print {
  html, body { background: white; }
  .print-actions { display: none; }
  .print-sheet { padding: 24px 36px; max-width: 100%; }
}
