:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #252836;
  --border: #2e3147;
  --accent: #e8543a;
  --accent2: #3a8de8;
  --green: #2ecc71;
  --yellow: #f39c12;
  --red: #e74c3c;
  --text: #e8eaf0;
  --muted: #8a8fa8;
  --radius: 8px;
}

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

html { overflow-x: hidden; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  overflow-x: hidden;
}

header {
  background: var(--surface);
  border-bottom: 2px solid var(--accent2);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: relative;
}

header h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  transition: color 0.2s;
}

header h1:hover { color: var(--accent2); }

header h1 span { color: var(--accent2); }

.team-badge {
  background: var(--accent2);
  color: white;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: opacity 0.2s;
}

.team-badge:hover { opacity: 0.8; }

.dev-badge {
  background: #f39c12;
  color: #1a1d27;
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  white-space: nowrap;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  box-shadow: 0 0 8px rgba(243, 156, 18, 0.5);
  animation: dev-pulse 2s ease-in-out infinite;
}

@keyframes dev-pulse {
  0%, 100% { box-shadow: 0 0 8px rgba(243, 156, 18, 0.5); }
  50% { box-shadow: 0 0 16px rgba(243, 156, 18, 0.8); }
}

nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  padding: 0 24px;
}

@media (max-width: 600px) {
  header {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    padding: 12px 16px;
  }

  .team-badge {
    white-space: normal;
    font-size: 13px;
  }

  .dev-badge {
    position: static;
    transform: none;
    margin-top: 8px;
    width: 100%;
    text-align: center;
  }

  nav {
    padding: 0;
  }

  nav button {
    flex: 1;
    padding: 14px 4px;
    text-align: center;
    font-size: 12px;
  }
}

nav button {
  background: none;
  border: none;
  color: var(--muted);
  padding: 14px 20px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}

nav button:hover { color: var(--text); }

nav button.active {
  color: var(--accent2);
  border-bottom-color: var(--accent2);
}

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

.view { display: none; }
.view.active { display: block; }

.view-toolbar {
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.proj-toggle {
  display: flex;
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 3px;
  gap: 2px;
}

.proj-toggle button {
  background: transparent;
  color: var(--muted);
  border: none;
  border-radius: calc(var(--radius) - 2px);
  padding: 4px 14px;
  font-size: 13px;
  cursor: pointer;
}

.proj-toggle button.active {
  background: var(--accent2);
  color: white;
  font-weight: 600;
}

.card-clickable {
  cursor: pointer;
}

.card-clickable:hover {
  border-color: var(--accent2);
  background: var(--surface2);
}

.view-toolbar select {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 12px;
  font-size: 14px;
  cursor: pointer;
  min-width: 0;
  flex: 0 1 auto;
}

@media (max-width: 600px) {
  .view-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .view-toolbar select { width: 100%; }
  .proj-toggle { align-self: flex-start; }
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  overflow: hidden;
}

.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 16px;
}

/* Tables */
.table-wrap { overflow-x: auto; }

.player-meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

/* Roster table */
table.roster-table { max-width: 700px; }
col.col-slot   { width: 10%; }
col.col-player { width: 52%; }
col.col-zscore { width: 20%; }
col.col-keeps  { width: 18%; }

@media (max-width: 600px) {
  col.col-slot   { width: 14%; }
  col.col-player { width: 48%; }
  col.col-zscore { width: 21%; }
  col.col-keeps  { width: 17%; }
}

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

tr:last-child td { border-bottom: none; }

tr:hover td { background: var(--surface2); }

/* Position badge */
.pos {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  background: var(--surface2);
  color: var(--muted);
  border: 1px solid var(--border);
}

.pos.il { background: rgba(231, 76, 60, 0.15); color: var(--red); border-color: var(--red); }

/* Points */
.pts-high { color: var(--green); font-weight: 600; }
.pts-med { color: var(--yellow); font-weight: 600; }
.pts-low { color: var(--red); font-weight: 600; }

/* Matchup */
.matchup-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 24px;
  align-items: start;
  overflow-x: auto;
}

/* Matchups tab: league matchup cards */
.matchup-teams-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
  gap: 8px;
}
.matchup-team-block { flex: 1 1 0; min-width: 0; }
.matchup-team-block--away { text-align: right; }
.matchup-team-name  { font-size: 15px; font-weight: 700; margin-bottom: 4px; word-break: break-word; }
.matchup-record     { font-size: 28px; font-weight: 800; }
.matchup-proj-label { font-size: 11px; color: var(--muted); margin-top: 2px; }

.matchup-cats-table {
  border-collapse: collapse;
  font-size: 12px;
  width: 100%;
}

@media (max-width: 600px) {
  .matchup-record { font-size: 22px; }
  .matchup-cats-table td { padding: 4px 4px !important; }
  .card { padding: 14px; overflow: hidden; }
}

.matchup-team { }

.team-logo {
  width: 48px;
  height: 48px;
  object-fit: contain;
  border-radius: 4px;
  vertical-align: middle;
  margin-right: 10px;
}

.matchup-team h2 {
  display: flex;
  align-items: center;
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 4px;
}

.matchup-score {
  font-size: 36px;
  font-weight: 800;
  margin-bottom: 4px;
}

.matchup-score.winning { color: var(--green); }
.matchup-score.losing { color: var(--red); }

.matchup-proj {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 16px;
}

.vs {
  text-align: center;
  padding-top: 24px;
}

.vs span {
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface2);
  padding: 6px 12px;
  border-radius: 20px;
}

/* Recommendations */
.rec-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.rec-card:hover { border-color: var(--accent2); }

.rec-action {
  background: var(--accent2);
  color: white;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.rec-action.add { background: var(--green); }
.rec-action.swap { background: var(--accent2); }

.rec-body { flex: 1; }

.rec-reason { font-size: 13px; margin-bottom: 4px; }

.rec-detail { font-size: 12px; color: var(--muted); }

.rec-improvement {
  font-size: 16px;
  font-weight: 700;
  color: var(--green);
  white-space: nowrap;
}

/* Loading / error */
.loading {
  text-align: center;
  padding: 48px;
  color: var(--muted);
}

.error-msg {
  background: rgba(231, 76, 60, 0.1);
  border: 1px solid var(--red);
  color: var(--red);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  font-size: 13px;
}

.empty {
  text-align: center;
  padding: 32px;
  color: var(--muted);
  font-size: 13px;
}

/* Summary stats row */
.stats-row {
  display: flex;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.stat-box {
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 14px 16px;
  flex: 1 1 90px;
  max-width: 130px;
  text-align: center;
}

.stat-box .val {
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
  margin-top: 6px;
}

.stat-box .val.pts-high { color: var(--green); }
.stat-box .val.pts-med  { color: var(--yellow); }
.stat-box .val.pts-low  { color: var(--red); }

.stat-box .lbl {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
  word-break: break-word;
}

.stat-box-wide {
  min-width: 120px;
  max-width: 160px;
}

.cat-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  justify-content: center;
}

.cat-pill {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 10px;
}

.cat-pill-strong {
  background: rgba(46, 204, 113, 0.15);
  color: var(--green);
  border: 1px solid rgba(46, 204, 113, 0.3);
}

.cat-pill-weak {
  background: rgba(231, 76, 60, 0.15);
  color: var(--red);
  border: 1px solid rgba(231, 76, 60, 0.3);
}

/* Daily grid table */
.dg-table {
  border-collapse: collapse;
  width: max-content;
  min-width: 100%;
}

.dg-th {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 8px 12px;
  border-bottom: 2px solid var(--border);
  border-right: 1px solid var(--border);
  background: var(--surface);
  white-space: nowrap;
  min-width: 80px;
  position: sticky;
  top: 0;
  z-index: 3;
}

.dg-th-slot {
  min-width: 54px;
  width: 54px;
  position: sticky;
  left: 0;
  top: 0;
  z-index: 4;
}

.dg-slot {
  padding: 8px 10px;
  border-right: 2px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  vertical-align: top;
  text-align: center;
  position: sticky;
  left: 0;
  z-index: 2;
}

.dg-td {
  padding: 6px 8px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  min-width: 80px;
}

.dg-cell {
  padding: 4px 2px;
}

.dg-cell.dg-off {
  opacity: 0.35;
}

.dg-cell.dg-sub .dg-name {
  color: var(--accent2);
}

.dg-th.dg-th-completed {
  background: #1e4d7a;
  color: var(--text);
  font-weight: 600;
  border-bottom: 3px solid var(--accent2);
}

.dg-td.dg-td-completed {
  background: rgba(58, 141, 232, 0.15);
}

.dg-cell.dg-bench-actual .dg-name,
.dg-cell.dg-bench-actual .dg-team,
.dg-cell.dg-bench-actual .dg-stats {
  opacity: 0.45;
  font-style: italic;
}

.dg-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
  white-space: nowrap;
}

.dg-team {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 3px;
}

.dg-stats {
  font-size: 10px;
  color: var(--text);
  line-height: 1.7;
}

.dg-key {
  color: var(--muted);
  margin-right: 2px;
}

.dg-spacer td {
  height: 12px;
  border: none;
  background: var(--surface2);
}

.roster-section-divider td {
  background: rgba(58, 141, 232, 0.12);
  color: var(--accent2);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 8px 12px;
  border-top: 2px solid var(--accent2);
  border-bottom: 2px solid var(--accent2);
}

.roster-section-divider.hitters td {
  background: rgba(26, 188, 156, 0.12);
  color: #1abc9c;
  border-top-color: #1abc9c;
  border-bottom-color: #1abc9c;
}

.pitcher-row td {
  background: rgba(58, 141, 232, 0.04);
}

.pitcher-row:hover td {
  background: rgba(58, 141, 232, 0.10);
}


/* Daily breakdown button */
.btn-breakdown {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 12px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}
.btn-breakdown:hover { border-color: var(--accent2); color: var(--accent2); }

/* Daily tab toolbar */
.daily-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 8px;
}

.daily-switcher {
  display: flex;
  gap: 8px;
}

.daily-switcher .btn-breakdown.active {
  border-color: var(--accent2);
  color: var(--accent2);
  background: rgba(58, 141, 232, 0.1);
}

/* Daily grid scroll container */
#daily-grid-wrap {
  overflow: auto;
  max-height: calc(100vh - 160px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.league-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(480px, 100%), 1fr));
  gap: 16px;
}

.league-grid .card {
  margin-bottom: 0;
}

/* History tab */
.accuracy-hero {
  text-align: center;
  padding: 32px 24px;
}

.accuracy-pct {
  font-size: 64px;
  font-weight: 900;
  line-height: 1;
  margin-bottom: 6px;
}

.accuracy-bar {
  height: 8px;
  background: var(--surface2);
  border-radius: 4px;
  overflow: hidden;
  margin: 0 auto;
  max-width: 320px;
}

.accuracy-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.4s ease;
}

.week-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.week-pill {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}

.week-pill:hover { border-color: var(--accent2); color: var(--accent2); }

.week-pill.active {
  border-color: var(--accent2);
  color: var(--accent2);
  background: rgba(58, 141, 232, 0.1);
}

.history-matchup {
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent2);
  border-radius: var(--radius);
  margin-bottom: 20px;
  overflow: hidden;
}

.history-matchup-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  padding: 12px 16px;
  background: rgba(58, 141, 232, 0.08);
  gap: 6px;
  border-bottom: 1px solid var(--border);
}

.history-matchup-accuracy {
  margin-left: auto;
}

@media (max-width: 600px) {
  .history-matchup-accuracy {
    margin-left: 0;
    width: 100%;
  }
  .history-matchup-accuracy-spacer {
    display: none;
  }
}

.history-matchup-panels {
  display: grid;
  grid-template-columns: 1fr 1px 1fr;
  gap: 0;
}

@media (max-width: 600px) {
  .history-matchup-panels {
    grid-template-columns: 1fr;
  }
  .history-panel-divider {
    display: none;
  }
}

.history-panel {
  padding: 16px 20px;
}

.history-panel-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.history-panel-divider {
  background: var(--border);
}

.cat-correct { color: var(--green); font-weight: 700; }
.cat-wrong   { color: var(--red);   font-weight: 700; }

.ytd-table th, .ytd-table td { padding: 8px 14px; }

@media (max-width: 768px) {
  .matchup-grid {
    grid-template-columns: 1fr;
  }
  .vs { display: none; }
  main { padding: 16px; }
}
