/* ─────────────────────────────────────────────────────────────────────────
   CSK TEAM MANAGER — DESIGN SYSTEM
   Aesthetic: editorial cricket annual meets modern dashboard.
   - Cream parchment surfaces in light mode, warm ink in dark.
   - Navy spine (brand), ball-leather red accents, chalk cyan for live state.
   - Playfair Display for titles, Manrope for UI, JetBrains Mono for data.
   ─────────────────────────────────────────────────────────────────────── */

@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,500;0,600;0,700;1,500&family=Manrope:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500;700&display=swap');

/* ─── tokens ─────────────────────────────────────────────────────────── */
/* Palette tuned to the CSK shield mascot:
   - Onyx & charcoal as the spine (the wolf's coat, the shield border).
   - Brushed gold (#c89b35) as the heroic accent (the shield's gilt edge).
   - Cricket-ball red (#c4392c) as the heat / danger accent.
   - Cream paper kept for content surfaces so 16-row tables stay readable.
*/
:root {
  /* light theme — parchment + onyx */
  --ink:           #14141d;
  --ink-soft:      #3d3d4d;
  --ink-muted:     #7a7a8c;
  --ink-faint:     #b0b0bd;

  --paper:         #f3ede0;
  --paper-soft:    #e8e0cf;
  --paper-deep:    #d8cdb6;
  --paper-warm:    #faf5ea;
  --surface:       #ffffff;
  --surface-edge:  rgba(20, 20, 29, 0.10);

  /* Onyx is the new "navy" — used for the masthead band, primary buttons,
     squad tags, and the shield band that frames the app. */
  --onyx:          #1a1a24;
  --onyx-deep:     #0c0c14;
  --onyx-soft:     rgba(20, 20, 29, 0.12);
  --onyx-mist:     rgba(20, 20, 29, 0.04);

  /* navy retained as a secondary brand voice. */
  --navy:          #252459;
  --navy-soft:     rgba(37, 36, 89, 0.12);
  --navy-mist:     rgba(37, 36, 89, 0.04);

  --leather:       #c4392c;        /* cricket ball red — bolder than before */
  --leather-soft:  rgba(196, 57, 44, 0.12);
  --chalk:         #2a7c8e;
  --chalk-soft:    rgba(42, 124, 142, 0.14);

  /* The hero color of the logo. Used sparingly: numerals on the masthead,
     active tab indicator (dark mode), the XI numbering, the ball icon. */
  --gold:          #c89b35;
  --gold-deep:     #8f6e1e;
  --gold-soft:     rgba(200, 155, 53, 0.16);
  --gold-edge:     rgba(200, 155, 53, 0.32);

  --grass:         #2f6b3a;
  --grass-soft:    rgba(47, 107, 58, 0.14);

  /* avatar palette — deterministic per-player color */
  --av-1:  #b54838;   --av-2:  #2a7c8e;   --av-3:  #b8881a;
  --av-4:  #2f6b3a;   --av-5:  #6b3a8a;   --av-6:  #8a4d27;
  --av-7:  #1f5a8c;   --av-8:  #8a3a5a;   --av-9:  #4a6b1f;
  --av-10: #5a4a8a;   --av-11: #8a6a1f;   --av-12: #1f6a6a;

  /* spacing scale (8px base) */
  --s-1: 4px;  --s-2: 8px;   --s-3: 12px;  --s-4: 16px;
  --s-5: 24px; --s-6: 32px;  --s-7: 48px;  --s-8: 64px;

  /* radii */
  --r-sm: 4px; --r-md: 8px; --r-lg: 12px; --r-xl: 18px;

  /* type scale — modular, 1.125 ratio off 13px base for UI, with display
     overrides for serif headers. Use these instead of raw px in app.js. */
  --text-xxs:  10px;   /* eyebrows, micro-labels      */
  --text-xs:   11px;   /* meta, labels, mono captions */
  --text-sm:   12px;   /* secondary, dense rows       */
  --text-base: 14px;   /* body / row text             */
  --text-md:   15px;   /* primary copy                */
  --text-lg:   18px;   /* small h3                    */
  --text-xl:   22px;   /* h1 in masthead, .player-name lead */
  --text-2xl:  26px;   /* h2 / hero stat              */
  --text-3xl:  32px;   /* page title                  */

  /* leading */
  --lh-tight:  1.15;
  --lh-snug:   1.35;
  --lh-base:   1.5;
  --lh-relax:  1.7;

  /* tracking */
  --tr-tight:  -0.015em;
  --tr-base:   0;
  --tr-loose:  0.04em;
  --tr-eyebrow:0.18em;
  --tr-caps:   0.22em;

  /* shadows */
  --shadow-card:   0 1px 2px rgba(26,29,46,0.04), 0 4px 16px -8px rgba(26,29,46,0.10);
  --shadow-pop:    0 2px 4px rgba(26,29,46,0.06), 0 16px 32px -16px rgba(26,29,46,0.18);
  --shadow-inset:  inset 0 1px 0 rgba(255,255,255,0.6);

  /* type */
  --serif:  'Playfair Display', Georgia, 'Times New Roman', serif;
  --sans:   'Manrope', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --mono:   'JetBrains Mono', 'SF Mono', Menlo, monospace;
}

/* Dark theme tokens. Applied when:
     - the user has data-theme="dark" set on <html>, OR
     - data-theme is unset AND the OS prefers dark.
   The light theme block above is the default; data-theme="light" pins it. */
:root[data-theme="dark"],
:root:not([data-theme]) {
  /* (overrides only kick in when the OS is in dark, via the @media block) */
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --ink:           #ece6d4;
    --ink-soft:      #b5b0a3;
    --ink-muted:     #7c7669;
    --ink-faint:     #4a463d;

    --paper:         #0c0c14;
    --paper-soft:    #14141d;
    --paper-deep:    #1d1d28;
    --paper-warm:    #14141a;
    --surface:       #1a1a24;
    --surface-edge:  rgba(236, 230, 212, 0.10);

    --onyx:          #ece6d4;
    --onyx-deep:     #ffffff;
    --onyx-soft:     rgba(236, 230, 212, 0.14);
    --onyx-mist:     rgba(236, 230, 212, 0.05);

    --navy:          #8b8fc4;
    --navy-soft:     rgba(139, 143, 196, 0.18);
    --navy-mist:     rgba(139, 143, 196, 0.06);

    --leather:       #e2553f;
    --leather-soft:  rgba(226, 85, 63, 0.16);
    --chalk:         #6dc5d6;
    --chalk-soft:    rgba(109, 197, 214, 0.16);

    --gold:          #e5b04a;
    --gold-deep:     #c89b35;
    --gold-soft:     rgba(229, 176, 74, 0.18);
    --gold-edge:     rgba(229, 176, 74, 0.40);

    --grass:         #6fb37e;
    --grass-soft:    rgba(111, 179, 126, 0.16);

    --av-1:  #e2553f;   --av-2:  #6dc5d6;   --av-3:  #e5b04a;
    --av-4:  #6fb37e;   --av-5:  #b88dd6;   --av-6:  #d68f5f;
    --av-7:  #5fa3d6;   --av-8:  #d67aa3;   --av-9:  #a3c66a;
    --av-10: #9d8dd6;   --av-11: #d6b35f;   --av-12: #5fc4c4;

    --shadow-card:   0 1px 2px rgba(0,0,0,0.4), 0 4px 16px -8px rgba(0,0,0,0.55);
    --shadow-pop:    0 2px 4px rgba(0,0,0,0.5), 0 16px 32px -16px rgba(0,0,0,0.7);
    --shadow-inset:  inset 0 1px 0 rgba(255,255,255,0.04);
  }
}

/* Manual override: data-theme="dark" forces dark regardless of OS. */
:root[data-theme="dark"] {
  --ink:           #ece6d4;
  --ink-soft:      #b5b0a3;
  --ink-muted:     #7c7669;
  --ink-faint:     #4a463d;

  --paper:         #0c0c14;
  --paper-soft:    #14141d;
  --paper-deep:    #1d1d28;
  --paper-warm:    #14141a;
  --surface:       #1a1a24;
  --surface-edge:  rgba(236, 230, 212, 0.10);

  --onyx:          #ece6d4;
  --onyx-deep:     #ffffff;
  --onyx-soft:     rgba(236, 230, 212, 0.14);
  --onyx-mist:     rgba(236, 230, 212, 0.05);

  --navy:          #8b8fc4;
  --navy-soft:     rgba(139, 143, 196, 0.18);
  --navy-mist:     rgba(139, 143, 196, 0.06);

  --leather:       #e2553f;
  --leather-soft:  rgba(226, 85, 63, 0.16);
  --chalk:         #6dc5d6;
  --chalk-soft:    rgba(109, 197, 214, 0.16);

  --gold:          #e5b04a;
  --gold-deep:     #c89b35;
  --gold-soft:     rgba(229, 176, 74, 0.18);
  --gold-edge:     rgba(229, 176, 74, 0.40);

  --grass:         #6fb37e;
  --grass-soft:    rgba(111, 179, 126, 0.16);

  --av-1:  #e2553f;   --av-2:  #6dc5d6;   --av-3:  #e5b04a;
  --av-4:  #6fb37e;   --av-5:  #b88dd6;   --av-6:  #d68f5f;
  --av-7:  #5fa3d6;   --av-8:  #d67aa3;   --av-9:  #a3c66a;
  --av-10: #9d8dd6;   --av-11: #d6b35f;   --av-12: #5fc4c4;

  --shadow-card:   0 1px 2px rgba(0,0,0,0.4), 0 4px 16px -8px rgba(0,0,0,0.55);
  --shadow-pop:    0 2px 4px rgba(0,0,0,0.5), 0 16px 32px -16px rgba(0,0,0,0.7);
  --shadow-inset:  inset 0 1px 0 rgba(255,255,255,0.04);
}

/* ─── base ────────────────────────────────────────────────────────────── */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: var(--text-md);
  line-height: var(--lh-base);
  font-feature-settings: 'ss01', 'ss02', 'cv11';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background 240ms ease, color 240ms ease;
}

/* parchment grain — barely visible texture for depth */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.4;
  background-image:
    radial-gradient(circle at 1px 1px, var(--surface-edge) 1px, transparent 1px);
  background-size: 3px 3px;
  mix-blend-mode: multiply;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) body::before { mix-blend-mode: screen; opacity: 0.3; }
}
:root[data-theme="dark"] body::before { mix-blend-mode: screen; opacity: 0.3; }

/* ─── app shell ──────────────────────────────────────────────────────── */
.app {
  position: relative;
  z-index: 1;
  max-width: 1100px;
  margin: 0 auto;
  padding: var(--s-5) var(--s-5) var(--s-8);
}

@media (max-width: 700px) {
  .app { padding: var(--s-4) var(--s-3) var(--s-7); }
}

/* ─── masthead ───────────────────────────────────────────────────────── */
.masthead {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: var(--s-5);
  padding: var(--s-4) 0 var(--s-5);
  margin-bottom: var(--s-5);
  position: relative;
}
/* Twin rule: thin onyx hairline + a 24px gold detail near the start.
   Echoes the shield's gilt edge without being decorative for its own sake. */
.masthead::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 1px;
  background:
    linear-gradient(to right,
      var(--gold) 0,
      var(--gold) 56px,
      var(--surface-edge) 56px,
      var(--surface-edge) 100%);
}

.masthead-mark {
  display: flex;
  align-items: center;
  gap: var(--s-4);
}

/* Team crest: 56px square block holding either the user-supplied JPEG
   logo or the inline SVG fallback. The fallback is hidden by default
   and revealed via onerror when the JPEG is missing. */
.masthead-crest {
  width: 64px;
  height: 64px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.masthead-crest img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: var(--r-md);
  /* Lift the crest off the parchment without a hard frame: combined drop +
     ground shadow + a subtle gold outer ring keyed to the shield's gilt. */
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.22));
}
.masthead-crest-fallback {
  display: none;
  width: 100%;
  height: 100%;
}
.masthead-crest-fallback svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.18));
}

.masthead-title {
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-left: 1px solid var(--surface-edge);
  padding-left: var(--s-4);
  align-self: stretch;
  justify-content: center;
}
.masthead-title .eyebrow {
  font-family: var(--mono);
  font-size: var(--text-xxs);
  font-weight: 600;
  letter-spacing: var(--tr-caps);
  text-transform: uppercase;
  color: var(--ink-muted);
}
.masthead-title .eyebrow .gold-rule {
  color: var(--gold);
  font-weight: 700;
  margin: 0 6px;
}
.masthead-title h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-style: italic;
  font-size: var(--text-2xl);
  line-height: var(--lh-tight);
  margin: 0;
  letter-spacing: var(--tr-tight);
  color: var(--ink);
}

.masthead-meta {
  font-family: var(--mono);
  font-size: var(--text-xs);
  color: var(--ink-muted);
  letter-spacing: var(--tr-loose);
  text-align: right;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.masthead-meta .live-dot {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--grass);
  margin-right: var(--s-2);
  box-shadow: 0 0 0 0 var(--grass-soft);
  animation: pulse 2.4s ease-out infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 var(--grass-soft); }
  70%  { box-shadow: 0 0 0 6px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

@media (max-width: 700px) {
  .masthead { grid-template-columns: auto 1fr; }
  .masthead-meta { display: none; }
}

/* ─── toolbar ────────────────────────────────────────────────────────── */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  align-items: center;
  margin-bottom: var(--s-5);
  padding: var(--s-2);
  background: var(--surface);
  border: 1px solid var(--surface-edge);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-card);
}

.toolbar-spacer { flex: 1; }

.status {
  font-family: var(--mono);
  font-size: var(--text-xs);
  letter-spacing: var(--tr-loose);
  color: var(--ink-muted);
  padding: 0 var(--s-3);
  min-height: 14px;
}
.status:not(:empty)::before {
  content: "▸ ";
  color: var(--chalk);
}

/* ─── buttons ────────────────────────────────────────────────────────── */
button {
  font-family: var(--sans);
  font-weight: 600;
  font-size: var(--text-sm);
  letter-spacing: 0.01em;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  padding: 8px 14px;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease, transform 120ms ease;
  white-space: nowrap;
  background: transparent;
  color: var(--ink);
}

button:hover { background: var(--onyx-mist); }
button:active { transform: translateY(1px); }
button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--chalk-soft);
}
button[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none !important;
}
button[disabled]:hover { background: transparent; }

.btn-primary {
  background: var(--onyx);
  color: #f3ede0;
  border-color: var(--onyx);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.06), 0 1px 2px rgba(0,0,0,0.15);
}
.btn-primary:hover { background: var(--onyx-deep); border-color: var(--onyx-deep); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .btn-primary { color: #14141d; box-shadow: 0 1px 2px rgba(0,0,0,0.25); }
}
:root[data-theme="dark"] .btn-primary { color: #14141d; box-shadow: 0 1px 2px rgba(0,0,0,0.25); }

.btn-secondary {
  border-color: var(--surface-edge);
  background: var(--surface);
}
.btn-secondary:hover { border-color: var(--onyx); background: var(--onyx-mist); }

.btn-danger {
  color: var(--leather);
  border-color: transparent;
}
.btn-danger:hover { background: var(--leather-soft); }

.btn-ghost { background: transparent; }

.btn-icon {
  padding: 6px 8px;
  font-size: var(--text-base);
  line-height: 1;
  background: transparent;
}
.btn-icon:hover { background: var(--onyx-soft); }

/* Theme toggle: a small pill that flips between sun / moon glyphs.
   Active glyph is opaque, inactive is faint. The rotating background
   tells you at a glance which mode is active. */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0;
  padding: 2px;
  border: 1px solid var(--surface-edge);
  border-radius: 999px;
  background: var(--surface);
}
.theme-toggle button {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: var(--text-sm);
  line-height: 1;
  background: transparent;
  color: var(--ink-muted);
  border: none;
  font-family: var(--sans);
  font-weight: 600;
  letter-spacing: 0.04em;
}
.theme-toggle button[aria-pressed="true"] {
  background: var(--onyx);
  color: var(--gold);
}
.theme-toggle button:hover { background: var(--onyx-mist); }
.theme-toggle button[aria-pressed="true"]:hover { background: var(--onyx-deep); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle button[aria-pressed="true"] {
    color: #14141d;
  }
}
:root[data-theme="dark"] .theme-toggle button[aria-pressed="true"] { color: #14141d; }

/* ─── nav (segmented tabs) ──────────────────────────────────────────── */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  margin-bottom: var(--s-5);
  border-bottom: 1px solid var(--surface-edge);
  position: relative;
}

.tabs button {
  padding: var(--s-3) var(--s-4);
  background: transparent;
  border: none;
  border-radius: 0;
  color: var(--ink-muted);
  font-weight: 600;
  font-size: var(--text-sm);
  letter-spacing: 0.01em;
  position: relative;
  transition: color 160ms ease;
}

.tabs button::after {
  content: "";
  position: absolute;
  left: var(--s-4);
  right: var(--s-4);
  bottom: -1px;
  height: 2px;
  background: var(--gold);
  transform: scaleX(0);
  transform-origin: center;
  transition: transform 200ms cubic-bezier(.2,.8,.2,1);
}

.tabs button:hover { color: var(--ink); background: transparent; }
.tabs button.active { color: var(--ink); font-weight: 700; }
.tabs button.active::after { transform: scaleX(1); }

/* ─── pane visibility ───────────────────────────────────────────────── */
.pane { display: none; animation: paneIn 240ms cubic-bezier(.2,.8,.2,1); }
.pane.active { display: block; }
@keyframes paneIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── sectioning + headings ─────────────────────────────────────────── */
h2 {
  font-family: var(--serif);
  font-weight: 600;
  font-style: italic;
  font-size: var(--text-3xl);
  line-height: var(--lh-tight);
  margin: 0 0 var(--s-3);
  letter-spacing: var(--tr-tight);
  color: var(--ink);
}

h3 {
  font-family: var(--mono);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: var(--tr-eyebrow);
  text-transform: uppercase;
  color: var(--ink-muted);
  margin: var(--s-6) 0 var(--s-3);
  padding-bottom: var(--s-2);
  border-bottom: 1px solid var(--surface-edge);
}
h3:first-child { margin-top: 0; }

.eyebrow {
  font-family: var(--mono);
  font-size: var(--text-xxs);
  font-weight: 500;
  letter-spacing: var(--tr-eyebrow);
  text-transform: uppercase;
  color: var(--ink-muted);
}

.muted { color: var(--ink-muted); }
.mono  { font-family: var(--mono); }

/* small subdued instruction line (e.g. "Click ✎ to edit a row…") */
.hint {
  font-family: var(--mono);
  font-size: var(--text-xs);
  letter-spacing: var(--tr-loose);
  color: var(--ink-muted);
  margin: calc(var(--s-2) * -1) 0 var(--s-3);
}

/* compact date column inside data tables */
.cell-date {
  font-family: var(--mono);
  font-size: var(--text-sm);
  color: var(--ink);
  white-space: nowrap;
}

/* opposing-team name in event rows / tables — editorial italic. */
.opp-name {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 600;
  color: var(--ink);
}

/* ─── empty state ───────────────────────────────────────────────────── */
.empty {
  font-family: var(--sans);
  color: var(--ink-muted);
  text-align: center;
  padding: var(--s-7) var(--s-4);
  border: 1px dashed var(--surface-edge);
  border-radius: var(--r-lg);
  background: var(--paper-warm);
  font-size: var(--text-base);
}
.empty::before {
  content: "—  ";
  color: var(--ink-faint);
  letter-spacing: 0.4em;
}
.empty::after {
  content: "  —";
  color: var(--ink-faint);
  letter-spacing: 0.4em;
}

/* ─── squad tag ─────────────────────────────────────────────────────── */
/* Onyx field with a hairline gold rule beneath — echoes the shield. */
.squad-tag {
  display: inline-block;
  padding: 3px 8px 2px;
  border-radius: var(--r-sm);
  background: var(--onyx);
  color: var(--gold);
  font-family: var(--mono);
  font-size: var(--text-xxs);
  font-weight: 700;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  vertical-align: middle;
  margin-right: var(--s-2);
  white-space: nowrap;
  border: 1px solid var(--gold-edge);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .squad-tag { background: rgba(236,230,212,0.05); }
}
:root[data-theme="dark"] .squad-tag { background: rgba(236,230,212,0.05); }

/* ─── event view-mode toggle (above the list) ───────────────────── */
.event-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  margin-bottom: var(--s-4);
}
.event-toolbar .count {
  font-family: var(--mono);
  font-size: var(--text-xs);
  letter-spacing: var(--tr-loose);
  color: var(--ink-muted);
}
.view-toggle {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--surface-edge);
  border-radius: 999px;
  background: var(--surface);
}
.view-toggle button {
  padding: 4px 12px;
  border-radius: 999px;
  font-size: var(--text-sm);
  line-height: 1;
  background: transparent;
  color: var(--ink-muted);
  border: none;
  font-family: var(--sans);
  font-weight: 600;
  letter-spacing: 0.04em;
}
.view-toggle button[aria-pressed="true"] {
  background: var(--onyx);
  color: var(--gold);
}
.view-toggle button:hover { background: var(--onyx-mist); }
.view-toggle button[aria-pressed="true"]:hover { background: var(--onyx-deep); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .view-toggle button[aria-pressed="true"] { color: #14141d; }
}
:root[data-theme="dark"] .view-toggle button[aria-pressed="true"] { color: #14141d; }

/* ─── event list (cards) ─────────────────────────────────────────── */
.event-list {
  display: grid;
  gap: var(--s-3);
}

/* Grid view: 2-up on tablet+, 3-up on wider screens. Cards collapse to
   a tighter layout — date chip on top, headline below — to fit. */
.event-list.view-grid {
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--s-4);
}
.view-grid .event-row {
  grid-template-columns: 1fr;
  align-items: stretch;
  padding: var(--s-4);
}
.view-grid .event-row::before {
  top: 0; bottom: 0; left: 0;
  border-radius: var(--r-lg) 0 0 var(--r-lg);
}
.view-grid .event-date {
  flex-direction: row;
  align-items: baseline;
  border-right: none;
  border-bottom: 1px dashed var(--surface-edge);
  padding: 0 0 var(--s-3) 0;
  min-width: 0;
  text-align: left;
  gap: var(--s-2);
}
.view-grid .event-date .day {
  font-size: var(--text-lg);
}
.view-grid .event-date .month {
  margin-top: 0;
}
.view-grid .event-counts {
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
  margin-top: var(--s-3);
  padding-top: var(--s-3);
  border-top: 1px dashed var(--surface-edge);
}
.view-grid .event-headline {
  margin-top: var(--s-3);
}

/* Calendar view: month sections, each with a 7-col grid (Sun…Sat).
   Empty cells render as faint dashes — readable but quiet. Cells with
   events show a stack of mini event-cards. */
.calendar {
  display: flex;
  flex-direction: column;
  gap: var(--s-6);
}
.cal-month {
  background: var(--surface);
  border: 1px solid var(--surface-edge);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.cal-month-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: var(--s-4) var(--s-5);
  border-bottom: 1px solid var(--surface-edge);
  background: var(--paper-warm);
}
.cal-month-head .month-name {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 600;
  font-size: var(--text-xl);
  letter-spacing: var(--tr-tight);
  color: var(--ink);
}
.cal-month-head .month-count {
  font-family: var(--mono);
  font-size: var(--text-xs);
  letter-spacing: var(--tr-eyebrow);
  text-transform: uppercase;
  color: var(--ink-muted);
}
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}
.cal-dow {
  font-family: var(--mono);
  font-size: var(--text-xxs);
  letter-spacing: var(--tr-eyebrow);
  text-transform: uppercase;
  color: var(--ink-muted);
  text-align: center;
  padding: var(--s-2) 0;
  border-bottom: 1px solid var(--surface-edge);
  background: var(--paper-warm);
}
.cal-cell {
  position: relative;
  min-height: 96px;
  padding: 6px;
  border-right: 1px solid var(--surface-edge);
  border-bottom: 1px solid var(--surface-edge);
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: var(--mono);
  font-size: var(--text-xxs);
}
.cal-cell:nth-child(7n) { border-right: none; }
.cal-cell.muted { background: var(--paper-warm); }
.cal-cell.muted .cal-day-num { color: var(--ink-faint); }
.cal-cell.today { background: var(--gold-soft); }
.cal-cell.today .cal-day-num { color: var(--gold-deep); font-weight: 700; }
.cal-day-num {
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  margin-bottom: 2px;
}
.cal-event {
  display: block;
  padding: 4px 6px;
  border-radius: var(--r-sm);
  background: var(--onyx);
  color: var(--gold);
  font-family: var(--sans);
  font-size: var(--text-xxs);
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: transform 120ms ease;
  border: 1px solid var(--gold-edge);
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cal-event:hover { transform: translateY(-1px); }
.cal-event.selected {
  background: var(--gold);
  color: var(--onyx);
  border-color: var(--gold-deep);
}
.cal-event.complete::before {
  content: "✓ ";
  color: var(--grass);
}
.cal-event.partial::before {
  content: "◐ ";
  color: var(--gold);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .cal-event { background: rgba(236,230,212,0.08); }
}
:root[data-theme="dark"] .cal-event { background: rgba(236,230,212,0.08); }

@media (max-width: 600px) {
  .cal-cell { min-height: 64px; padding: 4px; }
  .cal-event { padding: 2px 4px; font-size: 9px; }
  .event-list.view-grid { grid-template-columns: 1fr; }
}

.event-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: var(--s-4);
  padding: var(--s-4);
  background: var(--surface);
  border: 1px solid var(--surface-edge);
  border-radius: var(--r-lg);
  cursor: pointer;
  transition: border-color 160ms ease, transform 200ms cubic-bezier(.2,.8,.2,1), box-shadow 200ms ease;
  position: relative;
}
.event-row::before {
  content: "";
  position: absolute;
  left: 0; top: 12px; bottom: 12px;
  width: 3px;
  background: var(--gold);
  border-radius: 2px;
  opacity: 0;
  transition: opacity 160ms ease;
}
.event-row:hover {
  border-color: var(--onyx-soft);
  transform: translateY(-1px);
  box-shadow: var(--shadow-card);
}
.event-row.selected {
  border-color: var(--onyx);
  box-shadow: var(--shadow-card);
  background: var(--paper-warm);
}
.event-row.selected::before { opacity: 1; }

.event-date {
  font-family: var(--mono);
  display: flex;
  flex-direction: column;
  text-align: center;
  min-width: 56px;
  line-height: 1;
  padding: var(--s-2) var(--s-3);
  border-right: 1px solid var(--surface-edge);
}
.event-date .day {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--ink);
}
.event-date .month {
  font-size: var(--text-xxs);
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--leather);
  margin-top: 4px;
}

.event-main { min-width: 0; }
.event-headline {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: var(--s-2);
  margin-bottom: 4px;
}
.event-opponent {
  font-family: var(--serif);
  font-weight: 600;
  font-size: var(--text-xl);
  font-style: italic;
  letter-spacing: var(--tr-tight);
  color: var(--ink);
}
.event-vs {
  font-family: var(--serif);
  font-style: italic;
  font-size: var(--text-sm);
  color: var(--ink-muted);
  font-weight: 400;
  margin-right: 2px;
}
.event-meta {
  font-family: var(--mono);
  font-size: var(--text-xs);
  color: var(--ink-soft);
  letter-spacing: 0.02em;
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-3);
}
.event-meta .dot { color: var(--ink-faint); }

.event-counts {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  text-align: right;
}
.count-pill {
  font-family: var(--mono);
  font-size: var(--text-xxs);
  font-weight: 600;
  letter-spacing: 0.06em;
  padding: 3px 8px;
  border-radius: var(--r-sm);
  background: var(--onyx-mist);
  color: var(--ink-soft);
  white-space: nowrap;
}
.count-pill.complete { background: var(--grass-soft); color: var(--grass); }
.count-pill.partial  { background: var(--gold-soft);  color: var(--gold); }
.count-pill.empty    { background: transparent; color: var(--ink-muted); border: 1px dashed var(--surface-edge); }

@media (max-width: 600px) {
  .event-row { grid-template-columns: auto 1fr; }
  .event-counts { grid-column: 1 / -1; flex-direction: row; justify-content: flex-end; }
  .event-date { border-right: none; border-bottom: 1px solid var(--surface-edge); padding-bottom: var(--s-2); }
}

/* ─── event detail ──────────────────────────────────────────────────── */
.event-detail {
  margin-top: var(--s-6);
  padding-top: var(--s-6);
  border-top: 1px solid var(--surface-edge);
}

.event-detail-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: var(--s-3);
  margin-bottom: var(--s-2);
}
.event-detail-meta {
  font-family: var(--mono);
  font-size: var(--text-sm);
  color: var(--ink-soft);
  letter-spacing: 0.02em;
  margin-bottom: var(--s-5);
  padding-bottom: var(--s-4);
  border-bottom: 1px solid var(--surface-edge);
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-6);
}
@media (max-width: 760px) {
  .detail-grid { grid-template-columns: 1fr; gap: var(--s-5); }
}

/* available list as checkbox tiles */
.avail-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.avail-item {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--surface-edge);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease;
  font-size: var(--text-sm);
  user-select: none;
}
.avail-item:hover { border-color: var(--onyx-soft); }
.avail-item input[type="checkbox"] {
  appearance: none;
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--ink-faint);
  border-radius: var(--r-sm);
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  background: transparent;
  transition: background 120ms, border-color 120ms;
}
.avail-item input[type="checkbox"]:checked {
  background: var(--onyx);
  border-color: var(--onyx);
}
.avail-item input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 4px; top: 1px;
  width: 5px; height: 9px;
  border: solid var(--gold);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.avail-item:has(input:checked) {
  background: var(--onyx-mist);
  border-color: var(--onyx);
}

/* Read-only avail-item (no checkbox; just a read-marker glyph). */
.avail-item.is-picked {
  background: var(--onyx-mist);
  border-color: var(--onyx);
}
.avail-item .readonly-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  font-family: var(--mono);
  font-size: var(--text-sm);
  color: var(--ink-faint);
}
.avail-item.is-picked .readonly-mark {
  color: var(--gold);
  font-weight: 700;
}

/* Visual hint that the entire app is read-only — the live-dot pulses the
   leather color instead of grass to differentiate from the editable badge. */
body.readonly .live-dot {
  background: var(--leather);
}

/* selected XI as numbered card */
.xi-list {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: xi;
}
.xi-list li {
  counter-increment: xi;
  display: grid;
  grid-template-columns: 32px 1fr;
  align-items: center;
  gap: var(--s-3);
  padding: 8px 10px;
  border-bottom: 1px dashed var(--surface-edge);
  font-size: var(--text-base);
}
.xi-list li:last-child { border-bottom: none; }
.xi-list li::before {
  content: counter(xi, decimal-leading-zero);
  font-family: var(--mono);
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--leather);
  letter-spacing: 0.08em;
}

.xi-empty {
  color: var(--ink-muted);
  font-style: italic;
  font-family: var(--serif);
  padding: var(--s-5) var(--s-3);
  text-align: center;
}

.xi-counter {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  font-family: var(--mono);
  font-size: var(--text-sm);
}
.xi-counter .now {
  font-weight: 700;
  color: var(--onyx);
  font-size: var(--text-lg);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .xi-counter .now { color: var(--ink); }
}
:root[data-theme="dark"] .xi-counter .now { color: var(--ink); }
.xi-counter .of { color: var(--ink-muted); }

.xi-action-bar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  margin-top: var(--s-4);
  padding-top: var(--s-4);
  border-top: 1px dashed var(--surface-edge);
}

.water-line {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  margin: var(--s-3) 0;
  padding: var(--s-3) var(--s-4);
  background: var(--paper-warm);
  border-radius: var(--r-md);
  font-size: var(--text-sm);
}
.water-line .label {
  font-family: var(--mono);
  font-size: var(--text-xxs);
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-muted);
}
.water-line .name {
  font-family: var(--serif);
  font-style: italic;
  font-size: var(--text-md);
  color: var(--ink);
  flex: 1;
  min-width: 0;
}
.water-line .name.tbd { color: var(--ink-faint); }

.gen-warning {
  font-family: var(--mono);
  font-size: var(--text-xs);
  letter-spacing: 0.04em;
  color: var(--leather);
  margin-top: var(--s-2);
}

.message-box {
  margin-top: var(--s-5);
  background: var(--paper-warm);
  border: 1px solid var(--surface-edge);
  border-radius: var(--r-lg);
  padding: var(--s-4) var(--s-5);
  font-family: var(--mono);
  font-size: var(--text-sm);
  line-height: var(--lh-relax);
  white-space: pre-wrap;
  color: var(--ink);
  position: relative;
}
.message-box::before {
  content: "WHATSAPP";
  position: absolute;
  top: -8px;
  left: 16px;
  background: var(--paper);
  padding: 0 8px;
  font-size: var(--text-xxs);
  font-weight: 700;
  letter-spacing: 0.2em;
  color: var(--ink-muted);
}

/* ─── conflict banner ───────────────────────────────────────────────── */
.conflict {
  background: var(--gold-soft);
  border-left: 3px solid var(--gold);
  border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4);
  margin-bottom: var(--s-4);
  font-size: var(--text-sm);
}
.conflict-title {
  font-family: var(--mono);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gold-deep);
  margin-bottom: var(--s-2);
}
.conflict ul { margin: 0; padding-left: var(--s-4); }

/* ─── tables (editorial scorecard style) ────────────────────────────── */
.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--surface-edge);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.table thead th {
  text-align: left;
  font-family: var(--mono);
  font-size: var(--text-xxs);
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-muted);
  padding: var(--s-3) var(--s-4);
  background: var(--paper-warm);
  border-bottom: 1px solid var(--surface-edge);
  white-space: nowrap;
}
.table thead th.num { text-align: right; }
.table tbody td {
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--surface-edge);
  font-size: var(--text-base);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background 120ms ease; }
.table tbody tr:hover { background: var(--onyx-mist); }
.table tbody tr:nth-child(even) { background: rgba(20, 20, 29, 0.015); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .table tbody tr:nth-child(even) { background: rgba(236,230,212,0.015); }
}
:root[data-theme="dark"] .table tbody tr:nth-child(even) { background: rgba(236,230,212,0.015); }
.table .num {
  text-align: right;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.table-wrap {
  border: 1px solid var(--surface-edge);
  border-radius: var(--r-lg);
  background: var(--surface);
  overflow: hidden;
}
.table-wrap .table { border: none; border-radius: 0; }

/* ─── avatars ───────────────────────────────────────────────────────── */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-family: var(--mono);
  font-size: var(--text-xs);
  font-weight: 700;
  color: #f5f0e6;
  letter-spacing: 0.04em;
  flex-shrink: 0;
  background: var(--ink-muted);
  box-shadow: inset 0 0 0 1.5px rgba(255,255,255,0.08), 0 1px 2px rgba(0,0,0,0.12);
}
.avatar-row {
  display: flex;
  align-items: center;
  gap: var(--s-3);
}
.avatar.sm { width: 24px; height: 24px; font-size: var(--text-xxs); }
.avatar.lg { width: 44px; height: 44px; font-size: var(--text-base); }

/* ─── inputs ────────────────────────────────────────────────────────── */
input[type="text"], input:not([type]), select {
  font-family: var(--sans);
  font-size: var(--text-sm);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--surface-edge);
  border-radius: var(--r-md);
  padding: 8px 10px;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
input[type="text"]:focus, input:not([type]):focus, select:focus {
  outline: none;
  border-color: var(--onyx);
  box-shadow: 0 0 0 3px var(--gold-soft);
}
input::placeholder { color: var(--ink-faint); }

.alias-input {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  font-family: var(--sans);
  font-size: var(--text-sm);
  padding: 6px 8px;
  border-radius: var(--r-sm);
  transition: background 120ms;
  color: var(--ink);
}
.alias-input:hover { background: var(--paper-warm); }
.alias-input:focus { background: var(--surface); border-color: var(--onyx); outline: none; box-shadow: 0 0 0 3px var(--gold-soft); }

/* ─── stat strip ────────────────────────────────────────────────────── */
.stat-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--s-3);
  margin-bottom: var(--s-5);
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--surface-edge);
  border-radius: var(--r-lg);
  padding: var(--s-4);
  transition: transform 200ms cubic-bezier(.2,.8,.2,1);
}
.stat-card:hover { transform: translateY(-2px); }
.stat-value {
  font-family: var(--mono);
  font-size: var(--text-2xl);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  line-height: 1;
  margin-bottom: var(--s-2);
  letter-spacing: -0.02em;
}
.stat-label {
  font-family: var(--mono);
  font-size: var(--text-xxs);
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-muted);
}
.stat-card.accent .stat-value { color: var(--leather); }

/* ─── player view summary ───────────────────────────────────────────── */
.player-summary {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--s-5);
  align-items: center;
  margin-bottom: var(--s-5);
  padding: var(--s-5);
  background: var(--surface);
  border: 1px solid var(--surface-edge);
  border-radius: var(--r-lg);
}
.player-summary .avatar { width: 64px; height: 64px; font-size: var(--text-lg); }
.player-summary-info { min-width: 0; }
.player-name {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 600;
  font-size: var(--text-2xl);
  letter-spacing: var(--tr-tight);
  margin-bottom: 2px;
  line-height: var(--lh-tight);
}
.player-squads {
  font-family: var(--mono);
  font-size: var(--text-xs);
  color: var(--ink-muted);
  letter-spacing: 0.06em;
  margin-bottom: var(--s-3);
}
.player-stat-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-5);
}
.player-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.player-stat .v {
  font-family: var(--mono);
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.player-stat .l {
  font-family: var(--mono);
  font-size: var(--text-xxs);
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

@media (max-width: 600px) {
  .player-summary { grid-template-columns: 1fr; text-align: left; }
  .player-summary .avatar { width: 48px; height: 48px; font-size: var(--text-base); }
}

.player-picker {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  margin-bottom: var(--s-4);
}
.player-picker label {
  font-family: var(--mono);
  font-size: var(--text-xxs);
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

/* outcome cells in player history */
.outcome-picked { color: var(--grass); font-weight: 600; }
.outcome-not-picked { color: var(--leather); font-weight: 500; }
.outcome-pending { color: var(--ink-muted); font-style: italic; }
.outcome-na { color: var(--ink-faint); }
.outcome-water { color: var(--chalk); font-weight: 600; }

.check-mark { color: var(--grass); font-weight: 700; }
.dash-mark  { color: var(--ink-faint); }

/* ─── water tab edit row ────────────────────────────────────────────── */
.water-cell {
  display: flex;
  align-items: center;
  gap: var(--s-2);
}
.water-cell .editing {
  display: flex;
  gap: var(--s-2);
  align-items: center;
  flex-wrap: wrap;
}

.delta-positive { color: var(--gold); font-weight: 600; }
.delta-negative { color: var(--leather); font-weight: 600; }
.delta-neutral  { color: var(--ink-muted); }

/* ─── settings ──────────────────────────────────────────────────────── */
.settings-section {
  background: var(--surface);
  border: 1px solid var(--surface-edge);
  border-radius: var(--r-lg);
  overflow: hidden;
  margin-bottom: var(--s-5);
}
.settings-section .table { border: none; border-radius: 0; }
.settings-help {
  padding: var(--s-3) var(--s-4);
  font-family: var(--mono);
  font-size: var(--text-xs);
  letter-spacing: 0.02em;
  color: var(--ink-muted);
  background: var(--paper-warm);
  border-top: 1px solid var(--surface-edge);
}

.venue-input {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  padding: 6px 8px;
  font-family: var(--mono);
  font-size: var(--text-sm);
  border-radius: var(--r-sm);
  color: var(--ink);
  transition: background 120ms, border-color 120ms;
}
.venue-input:hover { background: var(--paper-warm); }
.venue-input:focus { outline: none; background: var(--surface); border-color: var(--onyx); box-shadow: 0 0 0 3px var(--gold-soft); }
.venue-input::placeholder { font-family: var(--sans); font-size: var(--text-sm); color: var(--ink-faint); }

/* ─── footer signature ──────────────────────────────────────────────── */
.signoff {
  margin-top: var(--s-7);
  padding-top: var(--s-5);
  border-top: 1px solid var(--surface-edge);
  font-family: var(--serif);
  font-style: italic;
  font-size: var(--text-sm);
  color: var(--ink-faint);
  text-align: center;
}
.signoff::before { content: "❡ "; color: var(--leather); }

/* ─── motion: respect reduced motion ────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ─── selection ─────────────────────────────────────────────────────── */
::selection {
  background: var(--leather-soft);
  color: var(--ink);
}
