/**
 * MLB Live Cast Styles — Dark Glass Edition
 * Premium pitch-by-pitch visualization with cinematic depth
 * Fully fluid — scales from a single full-screen card down to grid-8 thumbnail
 */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

/* ============================================
   TOKENS
   ============================================ */

.mlb-livecast {
  --lc-bg: rgba(10, 12, 18, 0.82);
  --lc-surface: rgba(255, 255, 255, 0.04);
  --lc-surface-2: rgba(255, 255, 255, 0.07);
  --lc-border: rgba(255, 255, 255, 0.08);
  --lc-border-hover: rgba(255, 107, 0, 0.5);
  --lc-text-primary: #f0f2f5;
  --lc-text-muted: rgba(240, 242, 245, 0.45);
  --lc-text-label: rgba(240, 242, 245, 0.3);
  --lc-accent: #ff6b00;
  --lc-accent-glow: rgba(255, 107, 0, 0.25);
  --lc-occupied: #ff6b00;
  --lc-radius: 10px;
  --lc-radius-sm: 6px;
  --lc-font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

  /* Fluid scale tokens — overridden per grid count via .lc-compact-* class */
  --lc-header-h: 60px;
  --lc-subheader-h: 30px;
  --lc-body-min-h: 200px;
  --lc-svg-w: 150px;
  --lc-player-name-size: 13px;
  --lc-player-role-size: 8.5px;
  --lc-player-stats-size: 10px;
  --lc-subheader-font: 9.5px;
  --lc-pitch-result-size: 10.5px;
  --lc-pitch-meta-size: 9px;
  --lc-runner-name-size: 10px;
  --lc-logo-size: 38px;
}

/* ============================================
   ROOT CONTAINER
   ============================================ */

.mlb-livecast {
  position: relative;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1px;
  font-family: var(--lc-font);
  color: var(--lc-text-primary);
  background: rgba(8, 10, 16, 0.78);
  backdrop-filter: blur(24px) saturate(160%);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  border-radius: var(--lc-radius);
  border: 1px solid var(--lc-border);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  overflow: hidden;
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.5),
    0 1px 0 rgba(255, 255, 255, 0.07) inset;
}

/* Accent top edge */
.mlb-livecast::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 107, 0, 0.4), transparent);
  pointer-events: none;
  z-index: 1;
}

/* ============================================
   MATCHUP HEADER
   ============================================ */

.matchup-header {
  display: grid;
  grid-template-columns: 1fr 44px 1fr;
  align-items: stretch;
  gap: 0;
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid var(--lc-border);
  min-height: var(--lc-header-h);
}

.pitcher-section,
.batter-section {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  transition: background 0.35s ease;
  position: relative;
  overflow: hidden;
  min-width: 0;
}

.pitcher-section {
  justify-content: flex-end;
  border-right: 1px solid var(--lc-border);
}

.batter-section {
  justify-content: flex-start;
  border-left: 1px solid var(--lc-border);
}

/* Subtle team-color bleed behind each side */
.pitcher-section::before,
.batter-section::before {
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 0.35s ease;
  pointer-events: none;
}

.pitcher-section,
.batter-section {
  background-clip: padding-box;
}

/* Team logo */
.team-logo-container {
  width: var(--lc-logo-size);
  height: var(--lc-logo-size);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.team-logo-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.5));
}

/* Player info */
.player-details {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.pitcher-section .player-details {
  text-align: right;
}

.batter-section .player-details {
  text-align: left;
}

.player-role {
  font-size: var(--lc-player-role-size);
  font-weight: 700;
  color: var(--lc-text-label);
  text-transform: uppercase;
  letter-spacing: 1.2px;
  white-space: nowrap;
}

.player-name {
  font-size: var(--lc-player-name-size);
  font-weight: 700;
  color: var(--lc-text-primary);
  line-height: 1.2;
  letter-spacing: -0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-stats {
  font-size: var(--lc-player-stats-size);
  font-weight: 500;
  color: var(--lc-text-muted);
  letter-spacing: 0.1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* VS pill */
.vs-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 800;
  color: var(--lc-text-label);
  letter-spacing: 1px;
  background: var(--lc-surface);
  border-left: 1px solid var(--lc-border);
  border-right: 1px solid var(--lc-border);
  flex-shrink: 0;
}

/* ============================================
   INFO BAR  (Pitch Count · On Deck)
   ============================================ */

.sub-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 0;
  background: rgba(0, 0, 0, 0.2);
  border-bottom: 1px solid var(--lc-border);
  min-height: var(--lc-subheader-h);
}

.sub-header-item {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 14px;
  font-size: var(--lc-subheader-font);
  font-weight: 600;
  color: var(--lc-text-label);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  border-right: 1px solid var(--lc-border);
  white-space: nowrap;
}

.sub-header-item:last-child {
  border-right: none;
}

.sub-header-item span {
  font-weight: 700;
  color: var(--lc-text-primary);
  letter-spacing: 0;
  text-transform: none;
}

/* ============================================
   BSO ROW
   ============================================ */

.bso-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 5px 10px;
  background: rgba(0, 0, 0, 0.2);
  border-bottom: 1px solid var(--lc-border);
}

.bso-group {
  display: flex;
  align-items: center;
  gap: 5px;
}

.bso-label {
  font-size: var(--lc-subheader-font);
  font-weight: 700;
  color: var(--lc-text-label);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  min-width: 10px;
}

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

.bso-dots .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.2);
  transition: background 0.15s ease, border-color 0.15s ease;
}

[data-ball-indicator] .dot.active {
  background: #22c55e;
  border-color: #22c55e;
}

[data-strike-indicator] .dot.active {
  background: #f59e0b;
  border-color: #f59e0b;
}

[data-out-indicator] .dot.active {
  background: #ef4444;
  border-color: #ef4444;
}

/* Legacy selectors kept for compatibility */
.pitch-count-info,
.ondeck-info {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 14px;
  font-size: var(--lc-subheader-font);
  font-weight: 600;
  color: var(--lc-text-label);
  letter-spacing: 0.4px;
  border-right: 1px solid var(--lc-border);
  white-space: nowrap;
  flex: 1;
  justify-content: center;
}

.ondeck-info {
  border-right: none;
}

.pitch-count-info span,
.ondeck-info span {
  font-weight: 700;
  color: var(--lc-text-primary);
  letter-spacing: 0;
  text-transform: none;
  margin-left: 2px;
}

/* ============================================
   LIVECAST BODY
   ============================================ */

.livecast-body {
  display: grid;
  grid-template-columns: minmax(90px, 1.2fr) 1fr minmax(80px, 1fr);
  min-height: var(--lc-body-min-h);
  background: transparent;
}

/* ============================================
   BASES PANEL — Left
   ============================================ */

.bases-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px 8px;
  gap: 8px;
  border-right: 1px solid var(--lc-border);
  min-width: 0;
  overflow: hidden;
}

/* Diamond */
.base-diamond-display {
  position: relative;
  width: 72px;
  height: 72px;
  flex-shrink: 0;
}

.base-node {
  position: absolute;
  width: 18px;
  height: 18px;
  transform: rotate(45deg);
  border: 1.5px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.04);
  border-radius: 3px;
  transition: all 0.25s ease;
}

.base-node.occupied {
  background: var(--lc-occupied);
  border-color: var(--lc-occupied);
  box-shadow: 0 0 10px var(--lc-accent-glow), 0 0 3px var(--lc-occupied);
}

.base-node[data-base="2"] {
  top: 4px;
  left: 55%;
  transform: rotate(45deg) translateX(-50%);
}

.base-node[data-base="3"] {
  left: 4px;
  top: 50%;
  transform: rotate(45deg) translateY(-50%);
}

.base-node[data-base="1"] {
  right: 4px;
  top: 50%;
  transform: rotate(45deg) translateY(-50%);
}

/* Runner list */
.base-runner-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  width: auto;
  align-self: center;
  box-sizing: border-box;
}

.base-runner-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px 2px 5px;
  border-radius: var(--lc-radius-sm);
  transition: background 0.2s ease;
  width: auto;
  box-sizing: border-box;
}

.base-runner-row:not(.empty) {
  background: rgba(255, 107, 0, 0.1);
  border: 1px solid rgba(255, 107, 0, 0.2);
}

.base-runner-label {
  font-size: 8px;
  font-weight: 800;
  color: var(--lc-text-label);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  width: 16px;
  flex-shrink: 0;
}

.base-runner-row:not(.empty) .base-runner-label {
  color: var(--lc-accent);
}

.base-runner-name {
  font-size: var(--lc-runner-name-size);
  font-weight: 600;
  color: var(--lc-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.base-runner-row:not(.empty) .base-runner-name {
  color: var(--lc-text-primary);
}

/* ============================================
   STRIKE ZONE — Center
   ============================================ */

.strike-zone-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 10px;
  gap: 0;
  position: relative;
  min-width: 0;
  overflow: hidden;
}

/* Subtle vignette framing the zone */
.strike-zone-section::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.25) 100%);
  pointer-events: none;
}

#strikeZoneSVG,
.strike-zone-svg {
  width: 100%;
  max-width: var(--lc-svg-w);
  height: auto;
  position: relative;
  z-index: 1;
}

/* SVG element styles */
.strike-zone-box {
  stroke: rgba(255, 255, 255, 0.2);
  stroke-width: 1.5;
  fill: rgba(255, 255, 255, 0.02);
}

.zone-line {
  stroke: rgba(255, 255, 255, 0.1);
  stroke-width: 1;
  stroke-dasharray: 3 4;
}

.zone-number {
  fill: rgba(255, 255, 255, 0.12);
  font-family: 'Inter', sans-serif;
  font-weight: 700;
}

/* SVG scale fix for pitch highlights */
.pitch-marker {
  transform-box: fill-box;
  transform-origin: center;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

/* ============================================
   PITCH HISTORY — Right
   ============================================ */

.pitch-history-panel {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 3px;
  padding: 6px 6px;
  overflow-y: auto;
  overflow-x: hidden;
  max-height: 260px;
  border-left: 1px solid var(--lc-border);
  min-width: 0;
}

.pitch-history-panel::-webkit-scrollbar {
  width: 2px;
}

.pitch-history-panel::-webkit-scrollbar-track {
  background: transparent;
}

.pitch-history-panel::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 2px;
}

.pitch-card {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 6px;
  background: var(--lc-surface);
  border: 1px solid var(--lc-border);
  border-radius: var(--lc-radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  animation: lc-slide-in 0.2s ease-out;
}

.pitch-card:hover {
  background: var(--lc-surface-2);
  border-color: var(--lc-border-hover);
  transform: translateX(-1px);
}

.pitch-card-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: 9px;
  font-weight: 800;
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.pitch-card-info {
  flex: 1;
  min-width: 0;
}

.pitch-card-result {
  font-size: var(--lc-pitch-result-size);
  font-weight: 600;
  color: var(--lc-text-primary);
  white-space: nowrap;
  line-height: 1.3;
}

.pitch-card-meta {
  font-size: var(--lc-pitch-meta-size);
  font-weight: 500;
  color: var(--lc-text-muted);
  white-space: nowrap;
  line-height: 1.3;
}

/* ============================================
   PITCH RESULT COLORS  (number dot in history list)
   Colored by CALL RESULT, not pitch type — matches ESPN
   ============================================ */

/* Ball outcomes */
.pitch-result-ball      { background: #22c55e; } /* Ball            */
.pitch-result-hbp       { background: #22c55e; } /* Hit by pitch    */

/* Strike outcomes */
.pitch-result-strike    { background: #dd0000; } /* Called strike   */
.pitch-result-swinging  { background: #dd0000; } /* Swinging strike */

/* Foul outcomes */
.pitch-result-foul      { background: #f59e0b; } /* Foul ball       */
.pitch-result-foultip   { background: #f59e0b; } /* Foul tip        */
.pitch-result-foultipbunt { background: #f59e0b; }

/* In-play outcomes */
.pitch-result-inplay    { background: #3b82f6; } /* In play         */

/* Default */
.pitch-result-unknown   { background: #6b7280; }

/* ============================================
   COMPACT MODES
   Applied as a class on .mlb-livecast by JS
   based on the grid count of the parent card.
   ============================================ */

/* Medium compact — grids 3-4 */
.mlb-livecast.lc-compact-md {
  --lc-header-h: 50px;
  --lc-subheader-h: 24px;
  --lc-body-min-h: 160px;
  --lc-svg-w: 120px;
  --lc-player-name-size: 11px;
  --lc-player-role-size: 7.5px;
  --lc-player-stats-size: 9px;
  --lc-subheader-font: 8.5px;
  --lc-pitch-result-size: 9.5px;
  --lc-pitch-meta-size: 8px;
  --lc-runner-name-size: 9px;
  --lc-logo-size: 30px;
}

.mlb-livecast.lc-compact-md .base-diamond-display {
  width: 58px;
  height: 58px;
}

.mlb-livecast.lc-compact-md .base-node {
  width: 15px;
  height: 15px;
}

.mlb-livecast.lc-compact-md .base-runner-list {
  width: auto;
}

.mlb-livecast.lc-compact-md .pitch-history-panel {
  max-height: 190px;
}

/* Small compact — grids 5-6 */
.mlb-livecast.lc-compact-sm {
  --lc-header-h: 42px;
  --lc-subheader-h: 20px;
  --lc-body-min-h: 130px;
  --lc-svg-w: 96px;
  --lc-player-name-size: 10px;
  --lc-player-role-size: 7px;
  --lc-player-stats-size: 8px;
  --lc-subheader-font: 7.5px;
  --lc-pitch-result-size: 8.5px;
  --lc-pitch-meta-size: 7.5px;
  --lc-runner-name-size: 8px;
  --lc-logo-size: 24px;
}

.mlb-livecast.lc-compact-sm .matchup-header {
  grid-template-columns: 1fr 34px 1fr;
}

.mlb-livecast.lc-compact-sm .pitcher-section,
.mlb-livecast.lc-compact-sm .batter-section {
  gap: 5px;
  padding: 5px 8px;
}

.mlb-livecast.lc-compact-sm .base-diamond-display {
  width: 48px;
  height: 48px;
}

.mlb-livecast.lc-compact-sm .base-node {
  width: 13px;
  height: 13px;
}

.mlb-livecast.lc-compact-sm .base-runner-list {
  width: auto;
}

.mlb-livecast.lc-compact-sm .bases-panel {
  padding: 6px 4px;
  gap: 4px;
}

.mlb-livecast.lc-compact-sm .pitch-history-panel {
  max-height: 155px;
  gap: 2px;
  padding: 4px 4px;
}

.mlb-livecast.lc-compact-sm .pitch-card {
  padding: 3px 5px;
  gap: 4px;
}

.mlb-livecast.lc-compact-sm .pitch-card-number {
  width: 15px;
  height: 15px;
  font-size: 8px;
}

/* Micro compact — grids 7-8 (non-featured cards) */
.mlb-livecast.lc-compact-xs {
  --lc-header-h: 36px;
  --lc-subheader-h: 18px;
  --lc-body-min-h: 108px;
  --lc-svg-w: 78px;
  --lc-player-name-size: 9px;
  --lc-player-role-size: 6.5px;
  --lc-player-stats-size: 7.5px;
  --lc-subheader-font: 7px;
  --lc-pitch-result-size: 8px;
  --lc-pitch-meta-size: 7px;
  --lc-runner-name-size: 7.5px;
  --lc-logo-size: 20px;
}

.mlb-livecast.lc-compact-xs .matchup-header {
  grid-template-columns: 1fr 28px 1fr;
}

.mlb-livecast.lc-compact-xs .pitcher-section,
.mlb-livecast.lc-compact-xs .batter-section {
  gap: 4px;
  padding: 4px 6px;
}

.mlb-livecast.lc-compact-xs .vs-divider {
  font-size: 7.5px;
}

.mlb-livecast.lc-compact-xs .base-diamond-display {
  width: 40px;
  height: 40px;
}

.mlb-livecast.lc-compact-xs .base-node {
  width: 11px;
  height: 11px;
}

.mlb-livecast.lc-compact-xs .bases-panel {
  padding: 5px 3px;
  gap: 3px;
}

/* hide runner names at micro size — diamond only */
.mlb-livecast.lc-compact-xs .base-runner-list {
  display: none;
}

.mlb-livecast.lc-compact-xs .pitch-history-panel {
  max-height: 130px;
  gap: 2px;
  padding: 3px 3px;
}

.mlb-livecast.lc-compact-xs .pitch-card {
  padding: 2px 4px;
  gap: 3px;
}

.mlb-livecast.lc-compact-xs .pitch-card-number {
  width: 13px;
  height: 13px;
  font-size: 7px;
}

/* hide pitch type/speed line at micro size */
.mlb-livecast.lc-compact-xs .pitch-card-meta {
  display: none;
}

.mlb-livecast.lc-compact-xs .pitch-count-info,
.mlb-livecast.lc-compact-xs .ondeck-info {
  padding: 3px 8px;
}

/* ============================================
   WIN PROBABILITY WATERMARK CHART
   Inside .fs-scoreboard (position:relative, overflow:visible)
   Extends upward to cover the logo area above the scoreboard bar
   ============================================ */

.wp-chart-watermark {
  position: absolute;
  /* Centered above the scoreboard, fills the logo area */
  left: 50%;
  transform: translateX(-50%);
  bottom: 100%;
  /* viewBox is 100x240 — keep aspect ratio by sizing via height */
  height: 160px;
  width: calc(160px * 100 / 240); /* ~67px — matches viewBox ratio */
  pointer-events: none;
  opacity: 0.28;
  overflow: hidden;
  border-radius: 4px;
}

.wp-chart-watermark svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* ============================================
   ANIMATIONS
   ============================================ */

@keyframes lc-slide-in {
  from {
    opacity: 0;
    transform: translateX(8px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* ============================================
   RESPONSIVE (standalone / mobile fallback)
   ============================================ */

@media (max-width: 768px) {
  .mlb-livecast {
    --lc-svg-w: 130px;
    --lc-player-name-size: 12px;
  }

  .mlb-livecast .base-diamond-display {
    width: 62px;
    height: 62px;
  }

  .mlb-livecast .base-node {
    width: 17px;
    height: 17px;
  }
}

@media (max-width: 480px) {
  .livecast-body {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
  }

  .bases-panel {
    border-right: none;
    border-bottom: 1px solid var(--lc-border);
    flex-direction: row;
    justify-content: center;
    padding: 10px 16px;
    gap: 16px;
  }

  .strike-zone-section {
    padding: 12px;
  }

  #strikeZoneSVG,
  .strike-zone-svg {
    width: 150px;
  }

  .pitch-history-panel {
    border-left: none;
    border-top: 1px solid var(--lc-border);
    max-height: 110px;
  }
}
