/* &CODE brand colours: #47445C (slate), #FFFFC5 (cream), #FFFFFF (white).
   Light mode: slate is ink/accent, cream is a soft highlight.
   Dark mode: slate becomes the surface colour, cream becomes the pop accent. */
:root {
  color-scheme: light;
  --page: #ffffff;
  --surface: #ffffff;
  --surface-2: #fffff0;
  --surface-3: #ffffe5;
  --ink: #47445c;
  --ink-2: #726f86;
  --ink-muted: #918f9d;
  --border: rgba(71, 68, 92, 0.14);
  --border-strong: rgba(71, 68, 92, 0.28);
  --accent: #47445c;
  --accent-ink: #ffffff;
  --accent-soft: rgba(71, 68, 92, 0.08);
  --accent-soft-2: rgba(71, 68, 92, 0.16);
  --good: #006300;
  --good-bg: rgba(12, 163, 12, 0.12);
  --warning: #8a5a00;
  --warning-bg: rgba(250, 178, 25, 0.2);
  --critical: #b23030;
  --critical-bg: rgba(208, 59, 59, 0.12);
  --shadow: 0 1px 2px rgba(71, 68, 92, 0.08), 0 8px 24px rgba(71, 68, 92, 0.1);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #302e3d;
    --surface: #47445c;
    --surface-2: #59576c;
    --surface-3: #686679;
    --ink: #ffffff;
    --ink-2: #d1d0d6;
    --ink-muted: #acabb6;
    --border: rgba(255, 255, 255, 0.12);
    --border-strong: rgba(255, 255, 255, 0.24);
    --accent: #ffffc5;
    --accent-ink: #47445c;
    --accent-soft: rgba(255, 255, 197, 0.16);
    --accent-soft-2: rgba(255, 255, 197, 0.28);
    --good: #6fe07a;
    --good-bg: rgba(12, 163, 12, 0.22);
    --warning: #ffce5c;
    --warning-bg: rgba(250, 178, 25, 0.22);
    --critical: #ff9d9c;
    --critical-bg: rgba(208, 59, 59, 0.24);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 8px 24px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--page);
  color: var(--ink);
}

a { color: var(--accent); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 12px;
}

.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand-logo { height: 26px; width: auto; display: block; }
.brand-logo-light { display: block; }
.brand-logo-dark { display: none; }
.brand-suffix { font-weight: 700; font-size: 15px; color: var(--ink); letter-spacing: -0.01em; }

/* Brand logos ship as separate black/white PNGs (no single file adapts to
   theme) — swap which one is shown based on the OS colour scheme. There's no
   in-app theme toggle, so this is the only signal that matters here. */
@media (prefers-color-scheme: dark) {
  .brand-logo-light { display: none; }
  .brand-logo-dark { display: block; }
}

/* Sizing only — display (show/hide per colour scheme) stays governed by the
   .brand-logo-light/.brand-logo-dark rules above, which must win the cascade. */
.login-logo { max-width: 240px; width: 100%; height: auto; margin-bottom: 16px; }

.public-logo { height: 28px; width: auto; margin-bottom: 18px; }

nav.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
nav.tabs a {
  padding: 8px 14px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 500;
}
nav.tabs a:hover { background: var(--surface-2); }
nav.tabs a.active { background: var(--accent-soft); color: var(--accent); }

.user-box { display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--ink-2); }
.user-box a { color: var(--ink-muted); text-decoration: none; }
.user-box a:hover { text-decoration: underline; }

main { max-width: 1200px; margin: 0 auto; padding: 24px; }

.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; flex-wrap: wrap; gap: 10px; }
.page-header h1 { font-size: 22px; margin: 0; }
.page-header p.subtitle { color: var(--ink-muted); margin: 4px 0 0; font-size: 14px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); }
.stat-tile .value { font-size: 26px; font-weight: 700; }
.stat-tile .label { font-size: 13px; color: var(--ink-muted); margin-top: 2px; }

.btn {
  display: inline-block;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { opacity: 0.92; }
.btn-danger { color: var(--critical); border-color: var(--critical); background: transparent; }
.btn-sm { padding: 4px 10px; font-size: 13px; }

form.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
form.filters input, form.filters select {
  padding: 7px 10px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--ink); font-size: 14px;
}

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { color: var(--ink-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
tr:hover td { background: var(--surface-2); }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-ok { background: var(--surface-3); color: var(--ink-2); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-critical { background: var(--critical-bg); color: var(--critical); }
.badge-accent { background: var(--accent-soft); color: var(--accent); }

.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.form-grid.full { grid-template-columns: 1fr; }
.form-field { display: flex; flex-direction: column; gap: 5px; }
.form-field label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.form-field input, .form-field select, .form-field textarea {
  padding: 9px 11px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--ink); font-size: 14px; font-family: inherit;
}
.form-field textarea { resize: vertical; min-height: 70px; }
.form-field input[readonly] { background: var(--surface-2); color: var(--ink-muted); cursor: not-allowed; }
.form-actions { margin-top: 16px; display: flex; gap: 10px; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 14px; }
.flash-success { background: var(--good-bg); color: var(--good); }
.flash-error { background: var(--critical-bg); color: var(--critical); }
.flash-info { background: var(--accent-soft); color: var(--accent); }

.note { border-bottom: 1px solid var(--border); padding: 10px 0; }
.note .meta { font-size: 12px; color: var(--ink-muted); margin-bottom: 3px; }

.empty-state { color: var(--ink-muted); padding: 30px 0; text-align: center; font-size: 14px; }

.checkbox-row { display: flex; align-items: center; gap: 8px; }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 30px; box-shadow: var(--shadow); }
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card p { color: var(--ink-muted); font-size: 14px; margin: 0 0 20px; }

.readonly-banner {
  background: var(--accent-soft); color: var(--accent); text-align: center;
  padding: 8px; font-size: 13px; font-weight: 600;
}

/* Position-group heading (&CODE Roster tab + public share page) - one per position bucket,
   ahead of that bucket's card grid. */
.position-heading {
  font-size: 18px; margin: 32px 0 14px; padding-bottom: 8px; border-bottom: 1px solid var(--border);
}
.position-heading:first-of-type { margin-top: 0; }

.player-card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.player-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); }
.player-card h3 { margin: 0 0 4px; font-size: 16px; }
.player-card .meta { font-size: 13px; color: var(--ink-muted); margin-bottom: 10px; }
.player-card .stats { display: flex; gap: 14px; font-size: 13px; margin-bottom: 10px; }
.player-card .links { display: flex; gap: 10px; font-size: 13px; }

/* Player photo avatars */
.player-photo { border-radius: 10px; object-fit: cover; display: block; background: var(--surface-2); }
.player-photo-sm { width: 48px; height: 48px; }
.player-photo-lg { width: 96px; height: 96px; }
.player-photo-xl { width: 192px; height: 192px; }
.player-photo-placeholder {
  display: flex; align-items: center; justify-content: center;
  color: var(--ink-muted); font-weight: 700; border: 1px solid var(--border);
}
.player-photo-placeholder.player-photo-lg { font-size: 32px; }
.player-photo-placeholder.player-photo-sm { font-size: 16px; }
.player-photo-placeholder.player-photo-xl { font-size: 64px; }

.player-card-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 10px; }
.player-card-clickable { cursor: pointer; }
.player-card-clickable:hover { border-color: var(--border-strong); }

/* Public share page's player grid - deliberately separate from .player-card-grid above
   (used by the Roster tab and share builder) so this bigger layout doesn't affect those. */
.share-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; justify-content: center; }
/* A position group with fewer than 3 players gets a fixed-width, centred row instead of
   stretching 1 or 2 tiles across the full 3-column width - .share-grid-count-1/-2 modifier
   classes are added in the template based on that group's actual player count. */
.share-grid.share-grid-count-2 { grid-template-columns: repeat(2, minmax(260px, 340px)); }
.share-grid.share-grid-count-1 { grid-template-columns: minmax(260px, 340px); }
@media (max-width: 900px) {
  .share-grid, .share-grid.share-grid-count-2 { grid-template-columns: repeat(2, minmax(240px, 1fr)); }
}
@media (max-width: 600px) {
  .share-grid, .share-grid.share-grid-count-2, .share-grid.share-grid-count-1 { grid-template-columns: minmax(0, 1fr); }
}

/* Public share page's position headings are centred; the same heading class on the Roster
   tab is left-aligned (no .position-heading-center there), so this only affects this page. */
.position-heading-center { text-align: center; }

.share-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 20px; box-shadow: var(--shadow); text-align: center; cursor: pointer;
}
.share-card:hover { border-color: var(--border-strong); }
.share-card-name { margin: 0 0 14px; font-size: 19px; }
.share-card .player-photo { margin: 0 auto 14px; }
.share-card-meta { font-size: 13px; color: var(--ink-muted); margin-bottom: 14px; }
.share-card-details {
  text-align: left; font-size: 13px; display: flex; flex-direction: column;
  gap: 6px; margin-bottom: 14px;
}
.share-card-details .label { color: var(--ink-muted); font-weight: 600; margin-right: 4px; }
.share-card-links { display: flex; gap: 14px; font-size: 13px; justify-content: center; }

/* Click-to-preview video modal (Roster tab + public share view) */
.video-modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6);
  align-items: center; justify-content: center; z-index: 1000; padding: 20px;
}
.video-modal-overlay.open { display: flex; }
.video-modal {
  background: var(--surface); border-radius: 14px; max-width: 720px; width: 100%;
  max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow); position: relative;
}
.video-modal-close {
  position: absolute; top: 10px; right: 10px; background: var(--surface-2); border: none;
  border-radius: 999px; width: 32px; height: 32px; font-size: 18px; cursor: pointer;
  color: var(--ink); z-index: 1;
}
.video-modal-body { padding: 20px; }
.video-modal-embed { position: relative; width: 100%; padding-top: 56.25%; margin-top: 14px; border-radius: 10px; overflow: hidden; background: #000; }
.video-modal-embed iframe, .video-modal-embed video {
  position: absolute; inset: 0; width: 100%; height: 100%; border: 0;
}
.video-modal-noplayer { margin-top: 14px; color: var(--ink-muted); font-size: 14px; }
