:root {
  --bg-1: #0b1220;
  --bg-2: #131f36;
  --card: #172236;
  --card-2: #131d2f;
  --card-edge: #24314c;
  --text: #eef2fb;
  --muted: #8ea0c0;
  --accent: #ffd54a;
  --accent-soft: rgba(255, 213, 74, 0.25);
  --green-1: #3f8f45;
  --green-2: #2f7137;
  --dirt: #b9793f;
  --pitch: #2e9e4f;
  --pitch-hi: #37c463;
  --danger: #ff5d5d;
  --blue: #6fb6ff;
  --good: #4fd07a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', sans-serif;
  -webkit-font-smoothing: antialiased;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 50% -10%, var(--bg-2), transparent 60%),
    linear-gradient(160deg, var(--bg-1), #0a0f1a);
}

a { color: inherit; text-decoration: none; }

/* ---------- Top nav ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: rgba(11, 18, 32, 0.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--card-edge);
}
.brand { font-weight: 800; font-size: 1.1rem; }
.nav-links { display: flex; gap: 6px; margin-left: 8px; }
.nav-links a {
  padding: 7px 14px;
  border-radius: 9px;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.95rem;
}
.nav-links a:hover { color: var(--text); background: rgba(255, 255, 255, 0.05); }
.nav-links a.active { color: var(--text); background: rgba(255, 255, 255, 0.09); }
.gems {
  margin-left: auto;
  font-weight: 800;
  font-size: 1.05rem;
  padding: 6px 12px;
  border-radius: 10px;
  background: rgba(255, 213, 74, 0.12);
  border: 1px solid rgba(255, 213, 74, 0.3);
}

/* ---------- Page shells ---------- */
.page { max-width: 880px; margin: 0 auto; padding: 26px 20px 60px; }
.page-head h1 { margin: 0 0 4px; font-size: 1.7rem; }
.sub { color: var(--muted); margin: 0 0 20px; }

.center-card {
  max-width: 460px;
  text-align: center;
  margin-top: 40px;
  background: linear-gradient(180deg, var(--card), var(--card-2));
  border: 1px solid var(--card-edge);
  border-radius: 18px;
  padding: 34px 28px;
}
.center-card h1 { margin-top: 0; }

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-block;
  border: none;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.95rem;
  padding: 11px 18px;
  border-radius: 11px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--card-edge);
  transition: filter 0.15s ease, transform 0.05s ease, background 0.15s ease;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.4; cursor: not-allowed; }
.btn.primary {
  color: #06210f;
  background: linear-gradient(180deg, var(--pitch-hi), var(--pitch));
  border: none;
  box-shadow: 0 8px 18px rgba(46, 158, 79, 0.3);
}
.btn.ghost { background: rgba(255, 255, 255, 0.05); }
.btn.danger-ghost { color: var(--danger); border-color: rgba(255, 93, 93, 0.4); background: transparent; }

.text-input, .name-input {
  width: 100%;
  font-size: 1rem;
  color: var(--text);
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--card-edge);
  border-radius: 10px;
  padding: 11px 13px;
}
.text-input { margin: 10px 0 16px; }
.text-input:focus, .name-input:focus { outline: 2px solid var(--accent-soft); }

/* ---------- Roster (My Team) ---------- */
.roster {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}
.player-card {
  background: linear-gradient(180deg, var(--card), var(--card-2));
  border: 1px solid var(--card-edge);
  border-radius: 14px;
  padding: 14px 16px;
}
.player-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.pos-badge {
  flex: none;
  width: 40px; height: 32px;
  display: grid; place-items: center;
  font-weight: 800; font-size: 0.85rem;
  border-radius: 8px;
  background: rgba(255, 213, 74, 0.14);
  color: var(--accent);
  border: 1px solid rgba(255, 213, 74, 0.3);
}
.name-input { padding: 7px 10px; font-weight: 700; }

.stat-row {
  display: grid;
  grid-template-columns: 1fr 70px auto;
  align-items: center;
  gap: 10px;
  margin: 9px 0;
}
.stat-label { font-size: 0.82rem; font-weight: 700; display: flex; flex-direction: column; }
.stat-hint { font-size: 0.68rem; color: var(--muted); font-weight: 500; }
.stat-bar {
  grid-column: 1 / 2;
  grid-row: 2;
  height: 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}
.stat-bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--pitch), var(--pitch-hi)); }
.stat-val { font-variant-numeric: tabular-nums; font-weight: 800; text-align: right; }
.up {
  border: none;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.78rem;
  padding: 7px 10px;
  border-radius: 8px;
  color: var(--accent);
  background: rgba(255, 213, 74, 0.12);
  border: 1px solid rgba(255, 213, 74, 0.3);
  white-space: nowrap;
}
.up[disabled] { opacity: 0.35; cursor: not-allowed; color: var(--muted); border-color: var(--card-edge); background: rgba(255,255,255,0.04); }

.backup-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 26px;
  padding-top: 20px;
  border-top: 1px solid var(--card-edge);
}

/* ---------- Ladder ---------- */
.ladder {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}
.ladder-card {
  background: linear-gradient(180deg, var(--card), var(--card-2));
  border: 1px solid var(--card-edge);
  border-radius: 14px;
  padding: 16px;
  text-align: center;
}
.ladder-card.next { border-color: var(--pitch); box-shadow: 0 0 0 1px var(--pitch), 0 10px 24px rgba(46,158,79,0.18); }
.ladder-card.locked { opacity: 0.55; }
.ladder-card .tier { font-size: 0.72rem; letter-spacing: 0.1em; color: var(--muted); font-weight: 700; }
.ladder-card .cpu-name { font-size: 1.1rem; font-weight: 800; margin: 6px 0 2px; }
.ladder-card .cpu-rating { font-size: 0.8rem; color: var(--muted); margin-bottom: 12px; }
.ladder-card .btn { width: 100%; }

/* ---------- Game view ---------- */
.game-page { max-width: 480px; }
.scoreboard {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--card-edge);
  border-radius: 14px;
}
.scoreboard .team { display: flex; align-items: center; gap: 10px; }
.scoreboard .team:last-child { justify-content: flex-end; }
.team-name { font-size: 0.9rem; font-weight: 700; color: var(--muted); letter-spacing: 0.02em; }
.team.at-bat .team-name { color: var(--accent); }
.team-score { font-size: 2rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.you {
  font-size: 0.6rem; font-weight: 800; letter-spacing: 0.08em;
  color: var(--good); border: 1px solid rgba(79,208,122,0.4);
  padding: 1px 5px; border-radius: 6px; margin-left: 4px; vertical-align: middle;
}
.inning {
  display: flex; flex-direction: column; align-items: center;
  min-width: 54px; padding: 5px 10px; border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
}
.inning-arrow { font-size: 0.7rem; color: var(--accent); }
.inning-num { font-size: 0.95rem; font-weight: 800; }

.field { display: flex; justify-content: center; margin: 18px 0 6px; }
.diamond-box { position: relative; width: 220px; height: 220px; } /* BOX in game.js must match */
.diamond { width: 220px; height: 220px; filter: drop-shadow(0 10px 20px rgba(0,0,0,0.4)); }
.runners { position: absolute; inset: 0; pointer-events: none; }
.runner {
  position: absolute;
  width: 18px; height: 18px;
  margin-left: -9px; margin-top: -9px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffe89a, #ffbf3a 70%);
  border: 2px solid #7a5a00;
  box-shadow: 0 0 9px rgba(255, 213, 74, 0.8);
  transition: transform 0.5s cubic-bezier(0.5, 0.05, 0.3, 1), opacity 0.4s ease;
  z-index: 2;
}
.runner.ghost { z-index: 1; }
@media (prefers-reduced-motion: reduce) {
  .runner { transition: opacity 0.4s ease; }
}
.infield { fill: var(--green-1); stroke: var(--green-2); stroke-width: 2; }
.basepath { fill: none; stroke: var(--dirt); stroke-width: 7; stroke-linejoin: round; }
.mound { fill: var(--dirt); opacity: 0.85; }
.base {
  fill: #e9eef7; stroke: #9aa7bd; stroke-width: 1.5;
  transform-box: fill-box; transform-origin: center; transform: rotate(45deg);
  transition: fill 0.25s ease, filter 0.25s ease;
}
.base.occupied {
  fill: var(--accent); stroke: #d9ae1f;
  filter: drop-shadow(0 0 6px var(--accent-soft)) drop-shadow(0 0 3px var(--accent));
}

.situation { display: flex; justify-content: center; margin-bottom: 14px; }
.outs { display: flex; align-items: center; gap: 8px; }
.count-label { font-size: 0.8rem; font-weight: 800; color: var(--muted); }
.pips { display: flex; gap: 5px; }
.pips i {
  width: 12px; height: 12px; border-radius: 50%;
  background: rgba(255,255,255,0.09); border: 1px solid rgba(255,255,255,0.12);
}
.pips.balls i.on   { background: var(--good);   box-shadow: 0 0 6px rgba(79,208,122,0.6); border-color: transparent; }
.pips.strikes i.on { background: var(--accent); box-shadow: 0 0 6px var(--accent-soft); border-color: transparent; }
.pips.outs i.on    { background: var(--danger); box-shadow: 0 0 6px rgba(255,93,93,0.55); border-color: transparent; }
.pips i.on { background: var(--danger); }

.game-controls {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  flex-wrap: wrap;
  margin: 6px 0 18px;
}
.game-controls select:disabled { opacity: 0.5; }
.unit-select { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.unit-select select {
  margin-left: 6px; font-size: 0.9rem; font-weight: 700;
  color: var(--text); background: var(--card); border: 1px solid var(--card-edge);
  border-radius: 9px; padding: 8px 10px;
}

/* Play-by-play log */
.log { margin-top: 8px; }
.log h2 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); margin: 0 0 8px; }
.log-lines {
  max-height: 260px; overflow-y: auto;
  border: 1px solid var(--card-edge); border-radius: 12px;
  background: rgba(0,0,0,0.2);
}
.log-line {
  display: flex; gap: 10px; align-items: baseline;
  padding: 8px 12px; font-size: 0.9rem;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.log-line:first-child { background: rgba(255,255,255,0.04); }
.log-tag { flex: none; font-size: 0.72rem; font-weight: 800; color: var(--muted); font-variant-numeric: tabular-nums; }
.ev-homeRun span:last-child, .ev-grandSlam span:last-child { color: var(--good); font-weight: 700; }
.ev-single span:last-child, .ev-double span:last-child, .ev-triple span:last-child { color: var(--good); }
.ev-strikeout span:last-child { color: var(--accent); }
.ev-walk span:last-child { color: var(--blue); }
.ev-error span:last-child { color: #ffa24a; }
.ev-stolenBase span:last-child { color: #45d3c0; font-weight: 700; }
.ev-caughtStealing span:last-child { color: #ff8080; }
.ev-gameOver span:last-child { color: var(--text); font-weight: 800; }

/* End panel */
.end-panel {
  text-align: center;
  border: 1px solid var(--card-edge);
  border-radius: 16px;
  padding: 22px;
  margin: 4px 0 18px;
  background: linear-gradient(180deg, var(--card), var(--card-2));
}
.end-panel.win { border-color: rgba(79,208,122,0.5); }
.end-panel h2 { margin: 0 0 6px; }
.gems-earned { font-size: 1.4rem; font-weight: 800; color: var(--accent); margin-bottom: 12px; }
.gem-breakdown { list-style: none; padding: 0; margin: 0 auto 16px; max-width: 280px; }
.gem-breakdown li { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid rgba(255,255,255,0.06); font-size: 0.92rem; }
.gem-breakdown li b { color: var(--good); }
.gem-breakdown .muted { color: var(--muted); justify-content: center; }
.end-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ---------- Line score ---------- */
.linescore-wrap { overflow-x: auto; margin-bottom: 14px; }
.linescore {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--card-edge);
  border-radius: 12px;
  overflow: hidden;
}
.linescore th, .linescore td {
  padding: 6px 9px;
  text-align: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.linescore thead th { color: var(--muted); font-size: 0.75rem; font-weight: 700; }
.linescore tbody tr:last-child td { border-bottom: none; }
.linescore .ls-team { text-align: left; font-weight: 700; white-space: nowrap; }
.linescore .ls-tot { font-weight: 800; background: rgba(255, 255, 255, 0.04); }
.linescore thead th:nth-last-child(1),
.linescore thead th:nth-last-child(2) { color: var(--text); }
.linescore tr.batting .ls-team { color: var(--accent); }

/* ---------- Pitch count grid + feed ---------- */
.situation.count-full { flex-direction: column; align-items: center; gap: 8px; }
.count-grid { display: flex; gap: 22px; }
.count-row { display: flex; align-items: center; gap: 7px; }
.pitch-feed {
  min-height: 1.4em;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  text-align: center;
}

/* ---------- Matchup spotlight ---------- */
.spotlight {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  margin: 4px 0 16px;
}
.sl-card {
  background: linear-gradient(180deg, var(--card), var(--card-2));
  border: 1px solid var(--card-edge);
  border-radius: 12px;
  padding: 10px 12px;
}
.sl-card.you-card { border-color: rgba(79, 208, 122, 0.5); }
.sl-vs { color: var(--muted); font-weight: 800; font-size: 0.8rem; }
.sl-role { font-size: 0.62rem; letter-spacing: 0.1em; color: var(--muted); font-weight: 800; }
.sl-card.you-card .sl-role { color: var(--good); }
.sl-name { font-size: 0.98rem; font-weight: 800; margin: 2px 0 7px; }
.sl-pos {
  font-size: 0.62rem; font-weight: 800; color: var(--accent);
  border: 1px solid rgba(255, 213, 74, 0.35); border-radius: 5px; padding: 0 4px; vertical-align: middle;
}
.mini-stat { display: flex; align-items: center; gap: 7px; font-size: 0.7rem; color: var(--muted); margin: 3px 0; }
.mini-stat > span:first-child { width: 52px; flex: none; }
.mini-bar { flex: 1; height: 5px; border-radius: 3px; background: rgba(255, 255, 255, 0.08); overflow: hidden; }
.mini-bar b { display: block; height: 100%; background: linear-gradient(90deg, var(--pitch), var(--pitch-hi)); }
.pitcher .mini-bar b { background: linear-gradient(90deg, #4a7bd0, var(--blue)); }

/* ---------- Base arrival animation ---------- */
.base.arrive { animation: bagPop 0.4s ease; }
@keyframes bagPop {
  0%   { transform: rotate(45deg) scale(0.4); }
  55%  { transform: rotate(45deg) scale(1.35); }
  100% { transform: rotate(45deg) scale(1); }
}

/* ---------- Confetti ---------- */
.confetti-layer {
  position: fixed; inset: 0; pointer-events: none; z-index: 50; overflow: hidden;
}
.confetti-layer i {
  position: absolute; top: -14px; border-radius: 2px;
  animation-name: confettiFall; animation-timing-function: ease-in; animation-fill-mode: forwards;
}
@keyframes confettiFall {
  0%   { transform: translate(0, -10px) rotate(0deg); opacity: 1; }
  100% { transform: translate(var(--drift), 105vh) rotate(720deg); opacity: 0.9; }
}
@media (prefers-reduced-motion: reduce) {
  .base.arrive { animation: none; }
}

/* ---------- Roster sections ---------- */
.roster-section {
  font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--muted); margin: 22px 0 10px; font-weight: 800;
}
.roster-section:first-of-type { margin-top: 8px; }

/* ---------- Pitcher stamina bar ---------- */
.stamina { margin: 8px 0 4px; }
.stamina-head {
  display: flex; justify-content: space-between;
  font-size: 0.7rem; color: var(--muted); font-weight: 700; margin-bottom: 3px;
}
.stamina-bar {
  height: 8px; border-radius: 5px; overflow: hidden;
  background: rgba(255, 255, 255, 0.08);
}
.stamina-bar b { display: block; height: 100%; transition: width 0.3s ease, background 0.3s ease; }
.stamina-bar.ok b   { background: linear-gradient(90deg, var(--pitch), var(--pitch-hi)); }
.stamina-bar.warn b { background: linear-gradient(90deg, #c9a227, var(--accent)); }
.stamina-bar.low b  { background: linear-gradient(90deg, #d67b2e, #ffa24a); }
.stamina-bar.crit b { background: linear-gradient(90deg, #c23636, var(--danger)); }

/* ---------- Tiny action buttons in the spotlight ---------- */
.btn.tiny {
  width: 100%; margin-top: 9px;
  height: 30px; padding: 0 10px; font-size: 0.78rem;
  border-radius: 8px; color: var(--text);
  background: rgba(255, 255, 255, 0.07); border: 1px solid var(--card-edge);
}
.btn.tiny:hover { filter: brightness(1.2); }
.batter .btn.tiny { color: var(--good); border-color: rgba(79, 208, 122, 0.4); }
.pitcher .btn.tiny { color: var(--blue); border-color: rgba(111, 182, 255, 0.4); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  background: rgba(4, 8, 15, 0.7); backdrop-filter: blur(3px);
}
.modal {
  width: 100%; max-width: 380px;
  background: linear-gradient(180deg, var(--card), var(--card-2));
  border: 1px solid var(--card-edge); border-radius: 16px; padding: 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}
.modal h3 { margin: 0 0 14px; font-size: 1.15rem; }
.reliever-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.reliever {
  text-align: left; cursor: pointer;
  background: rgba(255, 255, 255, 0.04); border: 1px solid var(--card-edge);
  border-radius: 11px; padding: 12px 14px; color: var(--text);
  transition: border-color 0.15s ease, background 0.15s ease;
}
.reliever:hover { border-color: var(--pitch); background: rgba(46, 158, 79, 0.12); }
.rel-name { font-weight: 800; font-size: 1rem; margin-bottom: 5px; }
.rel-stats { display: flex; gap: 16px; font-size: 0.82rem; color: var(--muted); }
.rel-stats b { color: var(--text); font-variant-numeric: tabular-nums; }
.modal .btn { width: 100%; }

/* ---------- New log event colors ---------- */
.ev-hitByPitch span:last-child { color: #ff9f6e; }
.ev-sub span:last-child { color: var(--blue); font-style: italic; }

/* ---------- Pitch selection tray ---------- */
.controls-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.pitch-tray {
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: center;
  margin-bottom: 2px;
}
.pitch-choice {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  min-width: 92px; padding: 8px 12px;
  color: #06210f;
  background: linear-gradient(180deg, var(--pitch-hi), var(--pitch));
  border: none; border-radius: 12px;
  box-shadow: 0 6px 14px rgba(46, 158, 79, 0.28);
}
.pitch-choice:hover { filter: brightness(1.07); }
.pc-name { font-size: 0.95rem; font-weight: 800; }
.pc-cost { font-size: 0.68rem; font-weight: 700; opacity: 0.7; }
