:root {
  --bg: #0a1628;
  --card: #0f2040;
  --accent: #e8c040;
  --green: #22c55e;
  --red: #ef4444;
  --text: #e2e8f0;
  --muted: #8899aa;
  --border: #1e3a5f;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  min-height: 100vh;
}

header {
  background: linear-gradient(135deg, #0f2040 0%, #1a3a60 100%);
  padding: 24px 32px;
  border-bottom: 2px solid var(--accent);
}
header h1 { font-size: 1.8rem; color: var(--accent); }
.subtitle { font-size: 0.9rem; color: var(--muted); margin-top: 4px; }

/* ── Page layout: sidebar + main ── */
.page-layout {
  max-width: 1600px;
  margin: 0 auto;
  padding: 28px 16px;
  display: flex;
  gap: 24px;
  align-items: flex-start;
}

/* Scoring info sidebar — sits on the left */
.scoring-sidebar {
  flex: 0 0 180px;
  order: 0;        /* left side */
  position: sticky;
  top: 16px;
}

.scoring-intro {
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 14px;
  line-height: 1.5;
}

.scoring-table {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 14px;
}
.scoring-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  padding: 4px 8px;
  border-radius: 6px;
}
.scoring-row.header-row {
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  padding-bottom: 6px;
  margin-bottom: 2px;
}
.scoring-row.top8-row {
  background: #070f1e;
  border: 1px solid var(--border);
}
.scoring-row.top8-row span:last-child {
  color: var(--accent);
  font-weight: 700;
}
.scoring-row.miss-row {
  color: var(--muted);
  font-size: 0.8rem;
}
.scoring-row.miss-row span:last-child {
  color: var(--red);
  font-weight: 600;
}

.scoring-note {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.5;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

/* Ladder sidebar — sits on the right by default */
.ladder-sidebar {
  flex: 0 0 200px;
  order: 2;        /* right side */
  position: sticky;
  top: 16px;
}

main {
  flex: 1 1 0;
  min-width: 0;
  order: 1;        /* left side */
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
}
.card h2 {
  font-size: 1.15rem;
  color: var(--accent);
  margin-bottom: 6px;
}

.hint {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 16px;
}
.hint code {
  background: #070f1e;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
  color: #a5c3e8;
}

/* ── Tips section ── */
.csv-actions { display: flex; flex-direction: column; gap: 12px; }

textarea {
  background: #070f1e;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 12px;
  font-family: monospace;
  font-size: 0.85rem;
  resize: vertical;
  width: 100%;
}
textarea:focus { outline: 1px solid var(--accent); }

.csv-buttons { display: flex; gap: 10px; flex-wrap: wrap; }

/* ── Buttons ── */
.btn {
  padding: 9px 20px;
  border-radius: 8px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: opacity 0.15s, transform 0.1s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:hover { opacity: 0.85; }
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: #0a1628; }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }

/* ── Ladder ── */
.round-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 0.85rem;
  color: var(--muted);
}
.round-selector select {
  flex: 1;
  background: #070f1e;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 4px 8px;
  font-size: 0.85rem;
  cursor: pointer;
}
.round-selector select:focus { outline: 1px solid var(--accent); }

.ladder-grid {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 12px;
}
.ladder-row {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #070f1e;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
}
.pos-label {
  font-size: 0.85rem;
  color: var(--muted);
  width: 30px;
  flex-shrink: 0;
  text-align: right;
  font-weight: 600;
}
.pos-label.top8 { color: var(--accent); }
.team-select {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
  outline: none;
}
.team-select option { background: #0f2040; }

.ladder-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }

/* ── Leaderboard ── */
.banner {
  padding: 10px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 0.88rem;
}
.banner.warn {
  background: rgba(234,179,8,0.1);
  color: #facc15;
  border: 1px solid rgba(234,179,8,0.25);
}

.leaderboard-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.leaderboard-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}

.round-badge {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  background: #070f1e;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 10px;
  margin-bottom: 6px;
}

.leaderboard-subtitle {
  font-size: 0.84rem;
  color: var(--muted);
}

.export-copy {
  font-size: 0.84rem;
  color: var(--muted);
}

.export-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.table-scroll { overflow-x: auto; }

.leaderboard {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.93rem;
}
.leaderboard th {
  background: #070f1e;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.leaderboard td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(30,58,95,0.5);
  vertical-align: middle;
}
.leaderboard tbody tr:last-child td { border-bottom: none; }
.leaderboard tbody tr:hover { background: rgba(255,255,255,0.025); }

.rank-cell { font-size: 1.2rem; text-align: center; width: 48px; }
.name-cell { font-weight: 600; min-width: 110px; }
.score-cell { font-size: 1.1rem; font-weight: 700; color: var(--accent); min-width: 70px; }
.num-cell  { text-align: center; }

.row-gold   { background: rgba(255,215,0,0.04); }
.row-silver { background: rgba(192,192,192,0.03); }
.row-bronze { background: rgba(205,127,50,0.03); }

/* ── Pick chips ── */
.chips-cell { line-height: 2; min-width: 500px; }
.chip {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 0.78rem;
  margin: 2px 3px 2px 0;
  font-weight: 500;
  white-space: nowrap;
}
.chip.correct {
  background: rgba(34,197,94,0.18);
  color: var(--green);
  border: 1px solid rgba(34,197,94,0.3);
}
.chip.wrong {
  background: rgba(239,68,68,0.08);
  color: #f87171;
  border: 1px solid rgba(239,68,68,0.18);
  opacity: 0.65;
}

.mobile-picks { display: none; }
.desktop-picks { display: block; }

/* ── Status & misc ── */
.status {
  display: inline-block;
  margin-top: 10px;
  font-size: 0.87rem;
  padding: 5px 12px;
  border-radius: 6px;
}
.status.ok    { background: rgba(34, 197, 94,0.14); color: var(--green); }
.status.error { background: rgba(239, 68, 68,0.14); color: var(--red); }
.status.warn  { background: rgba(234,179,  8,0.14); color: #facc15; }

.empty-state { color: var(--muted); font-style: italic; padding: 12px 0; }

.last-updated { font-size: 0.78rem; color: var(--muted); margin-top: 12px; text-align: right; }

.print-title {
  display: none;
}

.site-footnote {
  max-width: 1600px;
  margin: 0 auto 18px;
  padding: 0 16px;
}

.site-footnote p {
  font-size: 0.74rem;
  color: var(--muted);
  opacity: 0.9;
  text-align: center;
}

/* ── Scoring key ── */
.scoring-key {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.key-item {
  font-size: 0.78rem;
  color: var(--muted);
  background: #070f1e;
  border-radius: 6px;
  padding: 4px 10px;
}
.key-item strong { color: var(--accent); }

@media (max-width: 1100px) {
  .scoring-sidebar { flex: none; width: 100%; order: 3; position: static; }
}
@media (max-width: 900px) {
  .page-layout { flex-direction: column; }
  .ladder-sidebar { flex: none; width: 100%; order: 2; position: static; }
  main { order: 1; }
  .ladder-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
}
@media (max-width: 600px) {
  header { padding: 16px; }
  header h1 { font-size: 1.4rem; }
  .page-layout { padding: 16px 10px; }
  .card { padding: 16px; }
  .ladder-grid { grid-template-columns: 1fr 1fr; }
  .site-footnote { padding: 0 10px; }
}

@media (max-width: 700px) {
  .scoring-sidebar,
  .ladder-sidebar {
    width: 100%;
    position: static;
  }

  .leaderboard-toolbar {
    align-items: stretch;
  }

  .export-copy {
    display: none;
  }

  .export-actions {
    width: 100%;
    display: none;
  }

  .export-actions .btn {
    flex: 1 1 0;
    justify-content: center;
  }

  .leaderboard thead {
    display: none;
  }

  .leaderboard,
  .leaderboard tbody,
  .leaderboard tr,
  .leaderboard td {
    display: block;
    width: 100%;
  }

  .leaderboard tbody tr {
    border: 1px solid rgba(30,58,95,0.5);
    border-radius: 10px;
    margin-bottom: 10px;
    padding: 10px;
    background: rgba(7,15,30,0.55);
  }

  .leaderboard tbody tr:hover {
    background: rgba(7,15,30,0.75);
  }

  .leaderboard td {
    border: none;
    padding: 5px 0;
    min-width: 0;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
  }

  .leaderboard td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.74rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    flex: 0 0 auto;
  }

  .rank-cell,
  .score-cell,
  .num-cell,
  .name-cell {
    text-align: right;
    font-size: 0.95rem;
  }

  .chips-cell {
    display: block;
    line-height: 1.6;
    min-width: 0;
    padding-top: 8px;
  }

  .chips-cell::before {
    display: none;
  }

  .desktop-picks {
    display: none;
  }

  .mobile-picks {
    display: block;
  }

  .mobile-picks summary {
    list-style: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text);
    background: #070f1e;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 6px 10px;
    cursor: pointer;
  }

  .mobile-picks summary::-webkit-details-marker {
    display: none;
  }

  .mobile-picks[open] summary {
    color: var(--accent);
    border-color: var(--accent);
  }

  .mobile-picks-body {
    margin-top: 8px;
    line-height: 1.55;
  }

  .chip {
    font-size: 0.72rem;
    margin: 2px 4px 2px 0;
    padding: 3px 7px;
  }
}

@media print {
  @page {
    size: A4 landscape;
    margin: 8mm;
  }

  body {
    background: #ffffff;
    color: #111111;
  }

  header,
  .scoring-sidebar,
  .ladder-sidebar,
  .no-print,
  .last-updated,
  .site-footnote {
    display: none !important;
  }

  .page-layout,
  main,
  .card {
    display: block;
    max-width: none;
    width: 100%;
    margin: 0;
    padding: 0;
    border: none;
    background: #ffffff;
    box-shadow: none;
  }

  .leaderboard-heading {
    margin-bottom: 6px;
  }

  .round-badge {
    color: #111111;
    background: transparent;
    border-color: #d1d5db;
    padding: 2px 8px;
    margin-bottom: 4px;
  }

  .leaderboard-subtitle {
    font-size: 9px;
    color: #4b5563;
  }

  .print-title {
    display: block;
    margin-bottom: 8px;
  }

  .print-title h1 {
    font-size: 16px;
    margin-bottom: 2px;
    color: #111111;
  }

  .print-title p {
    font-size: 10px;
    color: #4b5563;
  }

  .leaderboard {
    font-size: 9px;
  }

  .leaderboard th,
  .leaderboard td {
    color: #111111;
    border-color: #d1d5db;
    padding: 4px 6px;
  }

  .leaderboard th {
    font-size: 8px;
  }

  .rank-cell {
    width: 28px;
    font-size: 10px;
  }

  .name-cell,
  .score-cell {
    min-width: 0;
  }

  .score-cell {
    font-size: 10px;
  }

  .chips-cell {
    min-width: 0;
    line-height: 1.35;
  }

  .chip.correct,
  .chip.wrong {
    color: #111111;
    background: transparent;
    border-color: #d1d5db;
    opacity: 1;
    font-size: 7px;
    padding: 1px 5px;
    margin: 1px 2px 1px 0;
  }
}
