:root {
  color-scheme: dark;
  --bg: #07111f;
  --panel: #0f172a;
  --panel-soft: #172033;
  --panel-strong: #1f2a44;
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-strong: #0ea5e9;
  --live: #22c55e;
  --danger: #fb7185;
  --warning: #f59e0b;
  --border: rgba(148, 163, 184, 0.22);
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.36);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top, rgba(14, 165, 233, 0.18), transparent 35%), var(--bg);
  color: var(--text);
}

button, input { font: inherit; }

button { cursor: pointer; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: max(1rem, env(safe-area-inset-top)) 1rem 0.9rem;
  background: linear-gradient(180deg, rgba(7, 17, 31, 0.96), rgba(7, 17, 31, 0.76));
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(16px);
}

.app-header > div { min-width: 0; }

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1, h2, h3, p { margin-top: 0; }

h1 {
  margin-bottom: 0;
  font-size: clamp(1.35rem, 7vw, 2rem);
  line-height: 1.05;
}

main {
  display: grid;
  gap: 1rem;
  width: min(100%, 1100px);
  margin: 0 auto;
  padding: 1rem 1rem 5rem;
}

.panel, .scorecard-panel, .footer-note {
  border: 1px solid var(--border);
  border-radius: 1.25rem;
  background: rgba(15, 23, 42, 0.88);
  box-shadow: var(--shadow);
}

.controls { padding: 1rem; }

.section-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.section-title-row h2 { margin-bottom: 0.25rem; }

.muted {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.icon-button {
  display: grid;
  flex: 0 0 auto;
  width: 2.75rem;
  height: 2.75rem;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--text);
  font-size: 1.35rem;
}

.icon-button:active, .game-card:active { transform: translateY(1px); }

.status-pill, .badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 1.8rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  background: var(--panel-strong);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  white-space: nowrap;
}

.status-pill.live, .badge.live { color: #052e16; background: var(--live); }
.status-pill.error { color: white; background: var(--danger); }

.field-label {
  display: block;
  margin: 1rem 0 0.35rem;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.date-control {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 0.9rem;
  background: var(--panel-soft);
  overflow: hidden;
}

.date-control:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.18);
}

.date-display {
  display: block;
  min-width: 0;
  width: 100%;
  padding: 0.8rem 3rem 0.8rem 0.9rem;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  line-height: 1.2;
  text-align: left;
}

.date-control-icon {
  position: absolute;
  right: 0.85rem;
  width: 1.15rem;
  height: 1.15rem;
  background-color: var(--muted);
  pointer-events: none;
  -webkit-mask: url("data:image/svg+xml,%3Csvg%20viewBox%3D%270%200%2024%2024%27%20xmlns%3D%27http%3A//www.w3.org/2000/svg%27%3E%3Cpath%20d%3D%27M7%202v3M17%202v3M4%209h16M5%204h14a2%202%200%200%201%202%202v15a2%202%200%200%201-2%202H5a2%202%200%200%201-2-2V6a2%202%200%200%201%202-2Zm0%207v10h14V11H5Z%27%20fill%3D%27black%27/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg%20viewBox%3D%270%200%2024%2024%27%20xmlns%3D%27http%3A//www.w3.org/2000/svg%27%3E%3Cpath%20d%3D%27M7%202v3M17%202v3M4%209h16M5%204h14a2%202%200%200%201%202%202v15a2%202%200%200%201-2%202H5a2%202%200%200%201-2-2V6a2%202%200%200%201%202-2Zm0%207v10h14V11H5Z%27%20fill%3D%27black%27/%3E%3C/svg%3E") center / contain no-repeat;
}

.date-input {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: block;
  width: 100%;
  min-width: 0;
  height: 100%;
  margin: 0;
  border: 0;
  opacity: 0.01;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}

.date-input::-webkit-date-and-time-value {
  text-align: left;
}

.date-input::-webkit-calendar-picker-indicator {
  opacity: 0;
}

.game-list {
  display: grid;
  gap: 0.7rem;
  margin-top: 1rem;
}

.game-card {
  width: 100%;
  padding: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--panel-soft);
  color: var(--text);
  text-align: left;
}

.game-card.selected { outline: 2px solid var(--accent); }

.game-matchup {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 2.4rem 2.4rem minmax(0, 1fr);
  align-items: start;
  column-gap: 0.35rem;
  font-weight: 900;
  line-height: 1.15;
}

.game-team {
  min-width: 0;
  overflow-wrap: normal;
}

.home-team { text-align: right; }

.game-score {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.game-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.55rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.scorecard-panel { overflow: hidden; }

.mobile-only { display: none; }

.empty-state {
  padding: 1.25rem;
  color: var(--muted);
}

.game-hero {
  padding: 1.1rem;
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.18), rgba(34, 197, 94, 0.12));
  border-bottom: 1px solid var(--border);
}

.detail-back-button {
  width: 100%;
  margin: 0 0 0.85rem;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  background: rgba(15, 23, 42, 0.78);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 850;
  text-align: left;
}

.scorecard-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.display-toggle {
  display: inline-flex;
  flex: 0 0 auto;
  padding: 0.2rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(7, 17, 31, 0.42);
}

.mode-button {
  min-height: 1.75rem;
  padding: 0.25rem 0.65rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
}

.mode-button.active {
  background: var(--accent);
  color: #082f49;
}

.hero-score {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.75rem;
  margin: 0.9rem 0 0.6rem;
}

.team-line {
  display: grid;
  min-width: 0;
  gap: 0.25rem;
}
.team-line.away { justify-items: start; text-align: left; }
.team-line.home { justify-items: end; text-align: right; }
.team-logo {
  width: clamp(2.35rem, 8vw, 3.4rem);
  height: clamp(2.35rem, 8vw, 3.4rem);
  object-fit: contain;
  filter: drop-shadow(0 0.35rem 0.55rem rgba(0, 0, 0, 0.28));
}
.team-name {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.team-runs { font-size: clamp(2rem, 13vw, 3.4rem); font-weight: 950; line-height: 1; }
.versus { color: var(--muted); font-weight: 800; }

.base-state {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.45rem;
  margin-top: 0.9rem;
}

.base {
  padding: 0.45rem 0.35rem;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  color: var(--muted);
  text-align: center;
  font-size: 0.8rem;
  font-weight: 800;
}
.base.occupied { color: #042f2e; background: #5eead4; border-color: transparent; }

.latest-play, .inning-group { padding: 1rem; border-bottom: 1px solid var(--border); }
.latest-play { background: rgba(15, 23, 42, 0.66); }
.play-title-row, .inning-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.notation {
  display: inline-grid;
  width: 3.8rem;
  min-height: 3rem;
  place-items: center;
  padding: 0.35rem 0.65rem;
  border-radius: 0.85rem;
  background: var(--accent);
  color: #082f49;
  font-size: 1.3rem;
  font-weight: 950;
  line-height: 1;
  text-align: center;
}
.reverse-k-glyph {
  display: inline-block;
  font-weight: 950;
  transform: scaleX(-1);
}
.description { margin: 0.75rem 0 0; line-height: 1.45; }
.context-line { margin: 0.55rem 0 0; color: var(--muted); font-size: 0.86rem; }

.play-list { display: grid; gap: 0.6rem; margin-top: 0.75rem; }
.play-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.65rem;
  align-items: start;
  padding: 0.7rem;
  border: 1px solid var(--border);
  border-radius: 0.9rem;
  background: rgba(23, 32, 51, 0.7);
}
.play-row .notation { width: 3.8rem; min-height: 2.35rem; padding-inline: 0.35rem; font-size: 0.92rem; }
.play-row p { margin-bottom: 0; }
.small { color: var(--muted); font-size: 0.78rem; }

.play-row.classic-row {
  grid-template-columns: auto 1fr;
  align-items: center;
}

.scorecard-svg {
  display: block;
  width: 6rem;
  height: 6rem;
  overflow: visible;
}

.play-row .scorecard-svg {
  width: 4.6rem;
  height: 4.6rem;
}

.latest-play .scorecard-svg {
  flex: 0 0 auto;
  width: 5rem;
  height: 5rem;
}

.scorecard-box { fill: #f8fafc; stroke: #0f172a; stroke-width: 2.2; }
.scorecard-diamond { fill: none; stroke: #334155; stroke-width: 1.8; stroke-linejoin: round; }
.advance-line { stroke: #0f172a; stroke-linecap: round; }
.advance-line.base-path { stroke-width: 1.2; opacity: 0.32; }
.advance-line.marked { stroke-width: 5.6; opacity: 0.95; }
.pitch-box { fill: #e2e8f0; stroke: #334155; stroke-width: 1.1; }
.pitch-box.marked { fill: var(--accent); }
.classic-result, .classic-k {
  fill: #0f172a;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-weight: 950;
}
.classic-result { font-size: 14px; text-anchor: end; }
.classic-k { font-size: 29px; text-anchor: middle; }

.footer-note {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
  justify-content: center;
  margin: -4rem 1rem 1rem;
  padding: 0.55rem 0.85rem;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.25;
  text-align: center;
}

.footer-note p { margin: 0; }
.footer-note a { color: var(--accent); font-weight: 800; text-decoration: none; }
.footer-note a:hover { text-decoration: underline; }

@media (max-width: 819px) {
  body.mobile-detail-open .controls { display: none; }
  body.mobile-detail-open .footer-note { display: none; }
  body:not(.mobile-detail-open) .scorecard-panel { display: none; }

  main { padding-bottom: 1rem; }
  .mobile-only { display: block; }
  .scorecard-panel { border-radius: 0; border-left: 0; border-right: 0; }
  .scorecard-toolbar { align-items: flex-start; }
  .display-toggle { align-self: flex-start; }
  .footer-note { margin: 0 1rem calc(1rem + env(safe-area-inset-bottom)); }
}

@media (min-width: 820px) {
  main { grid-template-columns: 350px 1fr; align-items: start; }
  .controls { position: sticky; top: 6rem; }
  .footer-note { width: min(calc(100% - 2rem), 1100px); margin-inline: auto; }
  .scorecard-panel { min-height: 20rem; }
}
