/* ═══════════════════════════════════════════════════════════════════════════
   League Predictions — Production Stylesheet v2
   Font: DM Sans (UI) + DM Mono (numbers)
   Supports: light/dark mode + manual toggle + sticky landscape columns
   ═══════════════════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=DM+Mono:wght@400;500&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

/* ── Dark tokens (default) ── */
:root {
  --bg:            #0d1117;
  --bg-raised:     #161b22;
  --bg-overlay:    #1c2130;
  --border:        #21262d;
  --border-muted:  #30363d;
  --text-primary:  #f0f6fc;
  --text-secondary:#8b949e;
  --text-muted:    #484f58;
  --green:         #3fb950;
  --green-dim:     rgba(63,185,80,.15);
  --green-glow:    rgba(63,185,80,.08);
  --amber:         #d29922;
  --amber-dim:     rgba(210,153,34,.15);
  --red:           #f85149;
  --red-dim:       rgba(248,81,73,.12);
  --blue:          #58a6ff;
  --best-bg:       rgba(63,185,80,.07);
  --worst-bg:      rgba(248,81,73,.07);
  --sticky-bg:     #161b22;
  --sticky-hdr:    #1c2130;
  --sticky-best:   #162b1a;  /* bg-raised + best-bg composited, opaque */
  --sticky-worst:  #271817;  /* bg-raised + worst-bg composited, opaque */
  --header-h:      56px;
  --max-w:         980px;
  --r-sm: 6px; --r-md: 8px; --r-lg: 12px;
  --font-ui:   'DM Sans', system-ui, sans-serif;
  --font-mono: 'DM Mono', 'Courier New', monospace;
  color-scheme: dark;
}

/* ── Light tokens ── */
[data-theme="light"] {
  --bg:            #ffffff;
  --bg-raised:     #f6f8fa;
  --bg-overlay:    #eaeef2;
  --border:        #d0d7de;
  --border-muted:  #c6cdd5;
  --text-primary:  #1f2328;
  --text-secondary:#636c76;
  --text-muted:    #9198a1;
  --green:         #1a7f37;
  --green-dim:     rgba(26,127,55,.1);
  --green-glow:    rgba(26,127,55,.08);
  --amber:         #9a6700;
  --amber-dim:     rgba(154,103,0,.1);
  --red:           #d1242f;
  --red-dim:       rgba(209,36,47,.08);
  --blue:          #0969da;
  --best-bg:       rgba(26,127,55,.06);
  --worst-bg:      rgba(209,36,47,.06);
  --sticky-bg:     #f6f8fa;
  --sticky-hdr:    #eaeef2;
  --sticky-best:   #eaf4ec;  /* f6f8fa + best-bg composited, opaque */
  --sticky-worst:  #faeaea;  /* f6f8fa + worst-bg composited, opaque */
  color-scheme: light;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg:            #ffffff;
    --bg-raised:     #f6f8fa;
    --bg-overlay:    #eaeef2;
    --border:        #d0d7de;
    --border-muted:  #c6cdd5;
    --text-primary:  #1f2328;
    --text-secondary:#636c76;
    --text-muted:    #9198a1;
    --green:         #1a7f37;
    --green-dim:     rgba(26,127,55,.1);
    --green-glow:    rgba(26,127,55,.08);
    --amber:         #9a6700;
    --amber-dim:     rgba(154,103,0,.1);
    --red:           #d1242f;
    --red-dim:       rgba(209,36,47,.08);
    --blue:          #0969da;
    --best-bg:       rgba(26,127,55,.06);
    --worst-bg:      rgba(209,36,47,.06);
    --sticky-bg:     #f6f8fa;
    --sticky-hdr:    #eaeef2;
    --sticky-best:   #eaf4ec;
    --sticky-worst:  #faeaea;
    color-scheme: light;
  }
}

/* ── Base ── */
html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body { background: var(--bg); color: var(--text-primary); font-family: var(--font-ui); line-height: 1.5; min-height: 100vh; display: flex; flex-direction: column; transition: background .2s, color .2s; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Header ── */
.site-header { background: var(--bg-raised); border-bottom: 1px solid var(--border); height: var(--header-h); position: sticky; top: 0; z-index: 200; }
.header-inner { max-width: var(--max-w); margin: 0 auto; padding: 0 16px; height: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.site-logo { font-weight: 700; font-size: .95rem; color: var(--text-primary); display: flex; align-items: center; gap: 7px; flex-shrink: 0; text-decoration: none; }
.site-nav { display: flex; align-items: center; gap: 4px; font-size: .875rem; }
.site-nav a { color: var(--text-secondary); padding: 6px 10px; border-radius: var(--r-sm); transition: color .15s, background .15s; text-decoration: none; }
.site-nav a:hover { color: var(--text-primary); background: var(--bg-overlay); }
.btn-nav { background: var(--green) !important; color: #fff !important; font-weight: 600; padding: 6px 14px !important; border-radius: var(--r-sm); }
.btn-nav:hover { opacity: .88; }
.theme-toggle { background: none; border: 1px solid var(--border-muted); border-radius: var(--r-sm); color: var(--text-secondary); cursor: pointer; font-size: .85rem; padding: 5px 8px; line-height: 1; transition: color .15s, border-color .15s; flex-shrink: 0; }
.theme-toggle:hover { color: var(--text-primary); border-color: var(--text-secondary); }

/* ── Main ── */
.main-content { max-width: var(--max-w); margin: 0 auto; padding: 20px 12px 40px; flex: 1; width: 100%; }

/* ── Footer ── */
.site-footer { border-top: 1px solid var(--border); margin-top: auto; }
.footer-inner { max-width: var(--max-w); margin: 0 auto; padding: 16px; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; font-size: .78rem; color: var(--text-muted); }
.footer-inner nav { display: flex; gap: 16px; }
.footer-inner a { color: var(--text-muted); text-decoration: none; }
.footer-inner a:hover { color: var(--text-secondary); }

/* ── Prize table ── */
.prize-table-wrap { background: var(--bg-raised); border: 1px solid var(--border); border-radius: var(--r-lg); margin-bottom: 20px; overflow: hidden; position: relative; }
.prize-table-wrap::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: linear-gradient(90deg, var(--green), var(--amber), var(--green)); opacity: .7; }
.prize-table { width: 100%; border-collapse: collapse; }
.prize-table th { padding: 10px 14px; font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); text-align: left; border-bottom: 1px solid var(--border); }
.prize-table td { padding: 11px 14px; border-bottom: 1px solid var(--border); font-size: .9rem; }
.prize-table tr:last-child td { border-bottom: none; }
.prize-pos { font-weight: 700; font-size: .85rem; white-space: nowrap; }
.prize-name { font-weight: 500; }
.prize-amount { font-family: var(--font-mono); font-size: .9rem; font-weight: 500; color: var(--green); text-align: right; }

/* ── Search ── */
.search-wrap { display: flex; align-items: center; margin-bottom: 12px; position: relative; }
.search-wrap input { flex: 1; background: var(--bg-raised); border: 1px solid var(--border-muted); color: var(--text-primary); border-radius: var(--r-md); padding: 9px 36px 9px 14px; font-size: .9rem; font-family: var(--font-ui); transition: border-color .15s, box-shadow .15s; min-height: 44px; }
.search-wrap input::placeholder { color: var(--text-muted); }
.search-wrap input:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px var(--green-glow); }
.search-clear { position: absolute; right: 10px; background: transparent; border: none; color: var(--text-muted); cursor: pointer; font-size: .9rem; padding: 4px; }
.data-freshness { font-size: .75rem; color: var(--text-muted); margin-bottom: 10px; font-family: var(--font-mono); }

/* ── Table container ── */
.table-wrap { background: var(--bg-raised); border: 1px solid var(--border); border-radius: var(--r-lg); margin-bottom: 20px; }
.leaderboard-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ── Leaderboard table ── */
.leaderboard-table { width: 100%; border-collapse: collapse; font-size: .85rem; }

.leaderboard-table thead th {
  background: var(--sticky-hdr);
  padding: 9px 10px;
  font-size: .68rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border-muted);
  white-space: nowrap; text-align: left;
}

/* Column sizing — explicit widths needed for sticky */
.col-rank   { width: 44px;  min-width: 44px;  text-align: center; }
.col-name   { width: 150px; min-width: 150px; }
.col-pts    { width: 52px;  min-width: 52px;  text-align: right; }
.col-gd     { width: 52px;  min-width: 52px;  text-align: right; }
.col-fa     { width: 36px;  min-width: 36px;  text-align: right; }
.col-league { min-width: 130px; }

/* Sticky column classes — positions */
.sticky-rank { left: 0px; }
.sticky-name { left: 44px; }
.sticky-pts  { left: 194px; }
.sticky-gd   { left: 246px; border-right: 2px solid var(--border-muted); }

/* Cells */
.leaderboard-table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
.leaderboard-table tr:last-child td { border-bottom: none; }
td.col-rank { font-family: var(--font-mono); font-size: .8rem; color: var(--text-muted); font-weight: 500; text-align: center; }
td.col-pts  { font-family: var(--font-mono); font-weight: 600; font-size: .9rem; color: var(--text-primary); text-align: right; }
td.col-gd   { font-family: var(--font-mono); font-size: .82rem; text-align: right; }
td.col-fa   { font-family: var(--font-mono); font-size: .78rem; color: var(--text-secondary); text-align: right; }

.gd-pos { color: var(--green); }
.gd-neg { color: var(--red); }
.gd-zer { color: var(--text-muted); }

/* Player rows */
.player-row { cursor: pointer; transition: background .1s; }
.player-row:hover td,
.player-row.is-expanded td { background: rgba(128,128,128,.04); }

.name-cell { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.player-name { font-weight: 500; }
.expand-chevron { color: var(--text-muted); font-size: .75rem; transition: transform .2s; flex-shrink: 0; }
.player-row.is-expanded .expand-chevron { transform: rotate(90deg); }

/* Best / worst rows — ensure full height never clips */
.row-best td, .row-worst td { padding: 11px 10px; }
.row-best td  { background: var(--best-bg); }
.row-worst td { background: var(--worst-bg); }
.label-best  { color: var(--green); font-weight: 600; font-size: .85rem; }
.label-worst { color: var(--red);   font-weight: 600; font-size: .85rem; }
.cell-best  { color: var(--green); }
.cell-worst { color: var(--red); }

/* Detail row — CSS-controlled visibility */
.detail-row { display: none !important; }
.player-row.is-expanded + .detail-row { display: table-row !important; }

.detail-row td { background: var(--bg) !important; padding: 12px !important; border-bottom: 1px solid var(--border) !important; }
.detail-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.detail-card { background: var(--bg-raised); border: 1px solid var(--border-muted); border-radius: var(--r-md); padding: 10px 12px; }
.detail-card-league { display: block; font-size: .65rem; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--text-muted); }
.detail-card-team   { display: block; font-size: .85rem; font-weight: 600; color: var(--text-primary); margin-top: 2px; white-space: normal; line-height: 1.3; }
.detail-card-stats  { display: block; font-family: var(--font-mono); font-size: .75rem; color: var(--text-secondary); margin-top: 4px; }
.detail-card-pts    { display: block; font-family: var(--font-mono); font-size: .8rem; font-weight: 500; color: var(--green); }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 18px; border-radius: var(--r-md); font-size: .875rem; font-weight: 600; font-family: var(--font-ui); cursor: pointer; border: none; transition: opacity .15s; text-decoration: none; min-height: 44px; }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover { opacity: .88; text-decoration: none; color: #fff; }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--text-secondary); border: 1px solid var(--border-muted); }
.btn-ghost:hover { color: var(--text-primary); border-color: var(--text-secondary); text-decoration: none; }

/* ── Forms ── */
.signup-page h1 { margin-bottom: 6px; }
.form-intro { color: var(--text-secondary); margin-bottom: 24px; font-size: .9rem; }
.form-section { background: var(--bg-raised); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 20px; margin-bottom: 16px; }
.form-section h2 { font-size: .75rem; font-weight: 600; margin-bottom: 16px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .05em; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 4px; }
.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field label { display: block; font-size: .75rem; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px; }
.field input, .field select { display: block; width: 100%; background: var(--bg); border: 1px solid var(--border-muted); color: var(--text-primary); border-radius: var(--r-md); padding: 10px 12px; font-size: .9rem; font-family: var(--font-ui); transition: border-color .15s; min-height: 44px; -webkit-appearance: none; appearance: none; }
.field select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238b949e' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }
.field input:focus, .field select:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px var(--green-glow); }
.field-error { display: block; font-size: .75rem; color: var(--red); margin-top: 5px; min-height: 1.1em; }
.checkbox-label { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; font-size: .875rem; color: var(--text-secondary); margin-bottom: 12px; user-select: none; line-height: 1.4; }
.checkbox-label input[type=checkbox] { flex-shrink: 0; width: 16px; height: 16px; margin-top: 2px; accent-color: var(--green); cursor: pointer; }
.form-actions { display: flex; gap: 12px; margin-top: 8px; }
.form-banner { border-radius: var(--r-md); padding: 11px 14px; font-size: .875rem; margin-top: 14px; }
.form-banner.error   { background: var(--red-dim);   color: var(--red);   border: 1px solid rgba(248,81,73,.25); }
.form-banner.success { background: var(--green-dim); color: var(--green); border: 1px solid rgba(63,185,80,.25); }
.token-form { max-width: 420px; margin-top: 24px; }

/* ── Confirmation ── */
.confirm-page { display: flex; align-items: center; justify-content: center; min-height: 55vh; padding: 20px; }
.confirm-box { text-align: center; max-width: 400px; }
.confirm-icon { font-size: 2.8rem; margin-bottom: 14px; }
.confirm-box h1 { margin-bottom: 10px; }
.confirm-hint { color: var(--text-secondary); font-size: .875rem; margin-bottom: 24px; line-height: 1.6; }
.confirm-picks { background: var(--bg-raised); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 16px; margin-bottom: 24px; text-align: left; }
.confirm-picks-title { font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin-bottom: 12px; }
.confirm-pick-row { display: flex; justify-content: space-between; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: .875rem; }
.confirm-pick-row:last-child { border-bottom: none; }
.confirm-pick-league { color: var(--text-muted); font-size: .78rem; }
.confirm-pick-team { font-weight: 500; }
.confirm-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ── Status ── */
.status-overall { display: inline-flex; align-items: center; gap: 8px; padding: 6px 14px; border-radius: 999px; font-size: .8rem; font-weight: 600; margin-bottom: 16px; }
.status-overall.ok    { background: var(--green-dim); color: var(--green); }
.status-overall.warn  { background: var(--amber-dim); color: var(--amber); }
.status-overall.error { background: var(--red-dim);   color: var(--red); }
.status-section { margin-bottom: 24px; }
.status-section h2 { font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); margin-bottom: 10px; }
.status-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px,1fr)); gap: 10px; }
.status-card { background: var(--bg-raised); border: 1px solid var(--border); border-radius: var(--r-md); padding: 12px 14px; }
.status-card.ok    { border-left: 3px solid var(--green); }
.status-card.warn  { border-left: 3px solid var(--amber); }
.status-card.error { border-left: 3px solid var(--red); }
.status-label  { font-weight: 600; font-size: .82rem; margin-bottom: 2px; }
.status-detail { font-size: .75rem; color: var(--text-secondary); font-family: var(--font-mono); }

/* ── Error / Prose ── */
.error-page { display: flex; align-items: center; justify-content: center; min-height: 60vh; padding: 20px; }
.error-box  { text-align: center; }
.error-code { font-size: 6rem; font-weight: 900; color: var(--border-muted); line-height: 1; margin-bottom: 12px; font-family: var(--font-mono); }
.prose-page { max-width: 660px; }
.prose-date { font-size: .78rem; color: var(--text-muted); margin-bottom: 1.5rem; font-family: var(--font-mono); }
.prose-page h1 { margin-bottom: 6px; }
.prose-page h2 { font-size: 1rem; margin-top: 1.8rem; margin-bottom: .5rem; }
.prose-page p, .prose-page ul, .prose-page ol { color: var(--text-secondary); font-size: .9rem; margin-bottom: .85rem; line-height: 1.7; }
.prose-page ul, .prose-page ol { padding-left: 1.4rem; }

/* ── Utilities ── */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }

/* ── JS sticky header clone ── */
.sticky-header-clone {
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.sticky-header-clone table {
  width: 100%;
  border-collapse: collapse;
}
.sticky-header-clone thead th {
  padding: 9px 10px;
  font-size: .68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  background: var(--sticky-hdr);
  white-space: nowrap;
  text-align: left;
  border: none;
}

/* ════════════════════════════════════════════════════════════
   BREAKPOINTS
   ════════════════════════════════════════════════════════════ */

/* Portrait mobile — default */
.landscape-only { display: none !important; }
.portrait-only  { display: table-cell !important; }
.expand-chevron { display: inline-block; }
/* Sticky cols off in portrait */
.leaderboard-table .sticky-rank,
.leaderboard-table .sticky-name,
.leaderboard-table .sticky-pts,
.leaderboard-table .sticky-gd { position: static; }

/* Landscape / 600px+ — show all cols, enable sticky, hide expand */
@media (min-width: 600px), (orientation: landscape) and (max-height: 600px) {
  .landscape-only { display: table-cell !important; }
  .expand-chevron { display: none !important; }
  .detail-row     { display: none !important; }

  /* Activate sticky left columns */
  .leaderboard-table .sticky-rank { position: sticky; left: 0px;   background: var(--sticky-bg); z-index: 5; }
  .leaderboard-table .sticky-name { position: sticky; left: 44px;  background: var(--sticky-bg); z-index: 5; }
  .leaderboard-table .sticky-pts  { position: sticky; left: 194px; background: var(--sticky-bg); z-index: 5; }
  .leaderboard-table .sticky-gd   { position: sticky; left: 246px; background: var(--sticky-bg); z-index: 5; border-right: 2px solid var(--border-muted); }

  .leaderboard-table thead th.sticky-rank,
  .leaderboard-table thead th.sticky-name,
  .leaderboard-table thead th.sticky-pts,
  .leaderboard-table thead th.sticky-gd { background: var(--sticky-hdr); z-index: 5; }

  /* Hover/expanded sticky col bg */
  .player-row:hover .sticky-rank,
  .player-row:hover .sticky-name,
  .player-row:hover .sticky-pts,
  .player-row:hover .sticky-gd,
  .player-row.is-expanded .sticky-rank,
  .player-row.is-expanded .sticky-name,
  .player-row.is-expanded .sticky-pts,
  .player-row.is-expanded .sticky-gd { background: var(--bg-overlay); }

  .row-best .sticky-rank, .row-best .sticky-name,
  .row-best .sticky-pts,  .row-best .sticky-gd { background: var(--sticky-best) !important; }
  .row-worst .sticky-rank, .row-worst .sticky-name,
  .row-worst .sticky-pts,  .row-worst .sticky-gd { background: var(--sticky-worst) !important; }
}

@media (min-width: 768px) {
  .main-content { padding: 24px 20px 48px; }
  .field-row    { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 380px) {
  .site-nav a:not(.btn-nav):not(:last-child) { display: none; }
  .field-row { grid-template-columns: 1fr; }
}
