/* ============================================
   MLB Scorebug - Modern Design
   Dark / Light theming
   ============================================ */

/* --- Dark theme (default) --- */
:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-elevated: #222639;
  --border: rgba(255, 255, 255, 0.06);
  --text-primary: #f0f2f5;
  --text-secondary: #8b8fa3;
  --text-muted: #555a6e;
  --accent: #3b82f6;
  --accent-glow: rgba(59, 130, 246, 0.25);
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --ball-color: #22c55e;
  --strike-color: #ef4444;
  --out-color: #f59e0b;
  --base-empty: #2a2e3d;
  --base-occupied: #f59e0b;
  --dot-empty: #2a2e3d;
  --info-bg: rgba(0, 0, 0, 0.15);
  --log-bg: rgba(0, 0, 0, 0.25);
  --at-bat-bg: rgba(255, 255, 255, 0.03);
  --toggle-bg: var(--surface);
  --toggle-border: var(--border);
  --radius: 12px;
  --radius-sm: 8px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* --- Light theme --- */
[data-theme="light"] {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface-elevated: #f5f5f7;
  --border: rgba(0, 0, 0, 0.08);
  --text-primary: #1a1d27;
  --text-secondary: #555a6e;
  --text-muted: #8b8fa3;
  --accent: #2563eb;
  --accent-glow: rgba(37, 99, 235, 0.2);
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --ball-color: #16a34a;
  --strike-color: #dc2626;
  --out-color: #d97706;
  --base-empty: #dde0e6;
  --base-occupied: #d97706;
  --dot-empty: #d1d5dc;
  --info-bg: rgba(0, 0, 0, 0.03);
  --log-bg: rgba(0, 0, 0, 0.04);
  --at-bat-bg: rgba(0, 0, 0, 0.025);
  --toggle-bg: var(--surface);
  --toggle-border: var(--border);
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.3s ease, color 0.3s ease;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.app {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 48px;
  padding: 40px 20px;
  width: 100%;
  max-width: 400px;
}

.app-title {
  font-size: 24px;
  font-weight: 800;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
  text-align: center;
}

/* ============================================
   Scorebug
   ============================================ */

.scorebug {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: background 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.1),
    0 4px 16px rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .scorebug {
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.06),
    0 4px 20px rgba(0, 0, 0, 0.04);
}

/* Teams & Score */
.scorebug-main {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
}

.team-card {
  display: flex;
  align-items: center;
  position: relative;
  transition: background 0.3s ease;
}

.team-card.at-bat {
  background: var(--at-bat-bg);
}

.team-color-bar {
  width: 4px;
  flex-shrink: 0;
  background: #666;
}

.team-logo {
  width: 22px;
  height: 22px;
  object-fit: contain;
  flex-shrink: 0;
  margin-left: 6px;
}

.team-card-inner {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 8px 4px;
  flex: 1;
  min-width: 0;
}

.team-abbr {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--text-primary);
  line-height: 1.2;
}

.team-right {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
  width: 48px;
  padding: 0 8px 0 0;
  gap: 1px;
}

.team-score {
  font-size: 24px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1;
}

.team-stat {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  min-height: 13px;
}

.team-player {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.2s ease;
}

.team-card.at-bat .team-player {
  color: var(--text-secondary);
}

.divider-v {
  width: 1px;
  background: var(--border);
}

/* Game Info Panel */
.scorebug-info {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 6px 16px;
  border-top: 1px solid var(--border);
  background: var(--info-bg);
}

/* Inning */
.inning-block {
  display: flex;
  align-items: center;
  gap: 5px;
}

.inning-arrow {
  display: flex;
  align-items: center;
  color: var(--text-secondary);
  transition: transform 0.2s ease, color 0.2s ease;
}

.inning-arrow.bottom {
  transform: rotate(180deg);
}

.inning-number {
  font-size: 15px;
  font-weight: 800;
  color: var(--text-primary);
}

/* Count & Outs */
.count-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  justify-self: center;
}

.count-text {
  font-size: 15px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.outs-dots {
  display: flex;
  gap: 4px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--dot-empty);
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

.outs-dots .dot.active {
  background: var(--out-color);
  box-shadow: 0 0 6px rgba(245, 158, 11, 0.4);
}

/* Bases Diamond */
.bases-block {
  display: flex;
  align-items: center;
  justify-content: center;
}

.bases-diamond {
  display: block;
}

.base {
  fill: var(--dot-empty);
  stroke: var(--border);
  stroke-width: 0.5;
  transition: fill 0.2s ease, filter 0.2s ease;
}

.base.occupied {
  fill: var(--base-occupied);
  filter: drop-shadow(0 0 4px rgba(245, 158, 11, 0.5));
  stroke: rgba(245, 158, 11, 0.3);
}

/* ============================================
   Variant 2 - Player bar above, info on right
   ============================================ */

.v2-body {
  display: flex;
}

.v2-teams {
  flex: 1;
  display: flex;
  min-width: 0;
}

.v2-team-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  transition: background 0.3s ease;
}

.v2-team-col.at-bat {
  background: var(--at-bat-bg);
}

.v2-team-col-divider {
  width: 1px;
  background: var(--border);
}

.v2-player-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 3px 6px 3px 12px;
  min-height: 22px;
  border-bottom: 1px solid var(--border);
}

.v2-player-text {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.2s ease;
}

.v2-team-col.at-bat .v2-player-text {
  color: var(--text-secondary);
}

.v2-player-stat {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
  margin-left: 8px;
}

.v2-game-info {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 0 14px;
  border-left: 1px solid var(--border);
  background: var(--info-bg);
}

.v2-info-left {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.v2-info-left .count-text {
  font-size: 12px;
}

.v2-info-left .dot {
  width: 6px;
  height: 6px;
}

.v2 .inning-arrow svg {
  width: 8px;
  height: 5px;
}

.v2 .team-card {
  padding: 6px 0;
}

.v2 .team-right {
  align-items: flex-end;
}

.v2 .team-score {
  font-size: 22px;
}

.v2 .bases-block {
  align-self: center;
}

.v2 .scorebug-info {
  display: none;
}

/* ============================================
   Variant 3 - Info bar below teams
   ============================================ */

.v3 {
  background: var(--surface);
  border: none;
  box-shadow: none;
  max-width: 260px;
  align-self: center;
}

.v3 .scorebug-info {
  display: none;
}

.v3 .team-card.at-bat,
.v3 .v2-team-col.at-bat {
  background: none;
}

.v3 .inning-arrow svg {
  width: 8px;
  height: 5px;
}

/* Teams with bases in between */
.v3-main {
  display: flex;
  align-items: center;
}

.v3-team {
  flex: 1;
  display: flex;
  align-items: center;
  min-width: 0;
  padding: 8px 0 0 0;
}

.v3-team .team-score {
  font-size: 20px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  margin-left: auto;
  padding: 0 4px;
}

.v3-bases-center {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0 10px;
}

/* Inning & Count */
.v3-info-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 4px 14px 8px;
}

.v3-info-bar .count-text {
  justify-self: center;
}

.v3-info-bar .outs-dots {
  justify-self: end;
}

.v3-info-bar .count-text {
  font-size: 12px;
}

.v3-info-bar .dot {
  width: 6px;
  height: 6px;
}

.v3-info-bar .inning-number {
  font-size: 13px;
}

/* Players */
.v3-players {
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--border);
  background: var(--info-bg);
}

.v3-player-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 6px 2px 12px;
  min-height: 20px;
}

.v3-player-bar+.v3-player-bar {
  border-top: 1px solid var(--border);
}

.v3 .scorebug-info {
  display: none;
}

.v3 .team-card {
  padding: 6px 0;
}

.v3 .team-right {
  align-items: flex-end;
}

.v3 .team-score {
  font-size: 22px;
}

.v3 .inning-arrow svg {
  width: 8px;
  height: 5px;
}
/* ============================================
   Score flash animation
   ============================================ */

@keyframes score-flash {
  0% { color: var(--text-primary); }
  20% { color: var(--accent); text-shadow: 0 0 12px var(--accent-glow); }
  100% { color: var(--text-primary); text-shadow: none; }
}

.team-score.flash {
  animation: score-flash 0.6s ease-out;
}

/* Game Over Banner */
.game-over-banner {
  text-align: center;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--info-bg);
  border-top: 1px solid var(--border);
}

/* ============================================
   Simulator Controls
   ============================================ */

.controls {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.controls-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.controls-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

.btn:hover {
  background: var(--surface-elevated);
  border-color: rgba(128, 128, 128, 0.2);
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}

.btn-primary:hover {
  background: #2563eb;
  border-color: transparent;
}

.btn-danger {
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.2);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.08);
  border-color: rgba(239, 68, 68, 0.3);
}

.btn-icon {
  width: 14px;
  height: 14px;
}

.hidden {
  display: none !important;
}

/* Speed Slider */
.speed-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 40px;
}

.speed-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  background: var(--dot-empty);
  outline: none;
  cursor: pointer;
}

.speed-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
  box-shadow: 0 0 0 1px var(--accent-glow);
  cursor: pointer;
  transition: transform 0.1s ease;
}

.speed-slider::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

.speed-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
  cursor: pointer;
}

.speed-value {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  min-width: 28px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Game Log */
.game-log-details {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  transition: border-color 0.2s ease;
}

.game-log-summary {
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: color 0.15s ease;
}

.game-log-summary::-webkit-details-marker {
  display: none;
}

.game-log-summary::before {
  content: '';
  display: inline-block;
  width: 5px;
  height: 5px;
  border-right: 1.5px solid var(--text-muted);
  border-bottom: 1.5px solid var(--text-muted);
  transform: rotate(-45deg);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.game-log-details[open] .game-log-summary::before {
  transform: rotate(45deg);
}

.game-log-summary:hover {
  color: var(--text-secondary);
}

.game-log {
  max-height: 200px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px;
  background: var(--log-bg);
  border-top: 1px solid var(--border);
}

.game-log::-webkit-scrollbar {
  width: 4px;
}

.game-log::-webkit-scrollbar-track {
  background: transparent;
}

.game-log::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: 2px;
}

.log-entry {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  line-height: 1.6;
  font-variant-numeric: tabular-nums;
}

.log-entry.log-score {
  color: var(--success);
}

.log-entry.log-out {
  color: var(--text-secondary);
}

.log-entry.log-info {
  color: var(--text-muted);
  font-style: italic;
}

.log-entry.log-inning {
  color: var(--accent);
  font-weight: 700;
  padding-top: 4px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

/* ============================================
   Theme Toggle
   ============================================ */

.theme-toggle {
  position: fixed;
  bottom: 20px;
  left: 20px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.theme-toggle:hover {
  background: var(--surface-elevated);
  color: var(--text-primary);
  transform: scale(1.08);
}

.theme-toggle:active {
  transform: scale(0.95);
}

.theme-icon {
  width: 18px;
  height: 18px;
  position: absolute;
  transition: opacity 0.2s ease, transform 0.3s ease;
}

/* Dark mode: show sun icon (to switch to light) */
.theme-icon-sun {
  opacity: 1;
  transform: rotate(0deg);
}

.theme-icon-moon {
  opacity: 0;
  transform: rotate(-90deg);
}

/* Light mode: show moon icon (to switch to dark) */
[data-theme="light"] .theme-icon-sun {
  opacity: 0;
  transform: rotate(90deg);
}

[data-theme="light"] .theme-icon-moon {
  opacity: 1;
  transform: rotate(0deg);
}

/* ============================================
   Responsive
   ============================================ */

@media (max-width: 420px) {
  .scorebug-info {
    gap: 8px;
    padding: 8px 12px;
  }

  .team-card-inner {
    padding: 6px 8px;
  }

  .team-abbr {
    font-size: 14px;
  }

  .team-score {
    font-size: 18px;
  }
}
