/**
 * Layout Styles
 *
 * Covers the points HUD bar, AI commentary bar, game summary bar,
 * bets container, event log strip, pregame/live mode visibility,
 * sport selector screen, game selector screen, and responsive
 * breakpoints for the selector screens and HUD.
 *
 * Header elements (team matchup, scores, MLB scoreboard strip, sport
 * info board) live in header.css.  Pre-game brief, featured player
 * cards, and the debug panel live in game-brief.css.
 */

/* === Points / HUD Bar ===
 * Lives inside .game-header (sticky) so it never scrolls away.
 * Laid out as a single compact row: [🪙 1000 · 0W–0L · 48%] ····· [🔥 streak]
 */
.points-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px calc(12px + env(safe-area-inset-right, 0px)) 0 calc(12px + env(safe-area-inset-left, 0px));
  margin-top: 4px;
  border-top: 1px solid var(--border);
}

.points-bar-compact {
  padding-top: 2px;
  margin-top: 2px;
}

/* Left group: coin display + W/L stats on one line */
.points-left {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.points-display {
  font-size: 1.1rem;
  font-weight: 700;
  transition: transform 0.3s var(--spring);
  /* Tabular figures for smooth counter — digits don't jump when value changes */
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.points-display.bump { animation: pointsBump 0.4s var(--spring); }

.points-display .pts-value { color: var(--gold); }

.rank-badge {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 12px;
  font-weight: 600;
  display: none !important;
  width: fit-content;
}

.streak-badge {
  font-size: 0.8rem;
  padding: 3px 10px;
  border-radius: 20px;
  font-weight: 600;
  animation: badgePop 0.35s var(--spring) both;
  white-space: nowrap;
}

.streak-hot {
  background: var(--green-glow);
  color: var(--green);
  border: 1px solid rgba(102, 187, 106, 0.3);
}

.streak-cold {
  background: var(--red-glow);
  color: var(--red);
  border: 1px solid rgba(239, 83, 80, 0.3);
}

.streak-neutral {
  background: rgba(136, 145, 168, 0.1);
  color: var(--text-dim);
  border: 1px solid rgba(136, 145, 168, 0.2);
}

/* Stats sit inline next to the coin total */
.stats-row {
  display: flex;
  gap: 10px;
  font-size: 0.8rem;
  color: var(--text-dim);
  align-items: center;
}

.live-status {
  display: none;
  font-size: 0.75rem;
  font-weight: 700;
  color: #f59e0b;
  animation: feedDelayPulse 2s ease-in-out infinite;
}

.points-right {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* === AI Commentary Bar === */
.commentary-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: linear-gradient(135deg, var(--surface) 0%, rgba(79, 195, 247, 0.05) 100%);
  border-bottom: 1px solid var(--border);
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.4s ease, opacity 0.4s ease, padding 0.4s ease;
}

.commentary-bar.show {
  max-height: 200px;
  opacity: 1;
  padding: 8px 16px;
}

/* === Game Situation Summary Bar === */
/* Uses max-height + opacity transition so it slides in smoothly rather than
   snapping from display:none, which would cause a jarring layout jump.      */
.game-summary-bar {
  background: linear-gradient(135deg, rgba(79, 195, 247, 0.04) 0%, rgba(168, 85, 247, 0.04) 100%);
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--text-dim);
  font-style: italic;
  letter-spacing: 0.01em;
  /* Hidden state */
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  padding-top: 0;
  padding-bottom: 0;
  padding-left: 16px;
  padding-right: 16px;
  transition: max-height 0.4s ease, opacity 0.4s ease, padding 0.4s ease;
}

.game-summary-bar.show {
  max-height: 200px;
  opacity: 1;
  padding: 10px 16px;
}

.commentary-label {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-glow);
  padding: 3px 7px;
  border-radius: 4px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  flex-shrink: 0;
}

.commentary-text {
  font-size: 0.82rem;
  color: var(--text-dim);
  line-height: 1.45;
}

/* === Bets Container === */
.bets-container {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  /* Extra bottom padding so last card is never hidden behind the fixed event log + home bar */
  padding-bottom: calc(100px + env(safe-area-inset-bottom, 0px));
  /* Prevent slide-out card animations from causing horizontal scrollbar */
  overflow-x: hidden;
}

.section-label {
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  padding: 4px 4px 0;
}

/* === Event Log Strip (bottom of screen) === */
.event-log {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  max-height: 80px;
  overflow: hidden;
  /* Respect iOS home indicator / bottom safe area */
  padding: 6px calc(12px + env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) calc(12px + env(safe-area-inset-left, 0px));
  z-index: 50;
}

.event-log-item {
  font-size: 0.85rem;
  color: var(--text-dim);
  padding: 3px 0;
  line-height: 1.45;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.event-log-item.goal    { color: var(--gold); font-weight: 600; }
.event-log-item.penalty { color: var(--red); }

/* === Pregame Mode (game not yet started) === */
/* Hide live-game-only elements until the puck drops / tip-off / kickoff */
#gameView.pregame-mode .commentary-bar,
#gameView.pregame-mode .event-log,
#gameView.pregame-mode #dailyChallenge,
#gameView.pregame-mode #comboMeter {
  display: none !important;
}

/* Hide pregame brief card once the game is live — it's stale context */
#gameView:not(.pregame-mode) #gameBriefContainer {
  display: none !important;
}

/* === Logo Splash Overlay === */
.splash-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  background: var(--bg);
  pointer-events: none;
}

.splash-logo {
  height: 72px;
  width: auto;
  animation: splashLogoIn 0.65s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.splash-subtitle {
  font-family: 'Space Grotesk', system-ui, sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  opacity: 0;
  animation: splashSubIn 0.5s ease 0.7s forwards;
}

.splash-tagline {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  opacity: 0;
  margin-top: 10px;
  animation: splashSubIn 0.5s ease 1.1s forwards;
}

/* === Sport Selector Screen === */
.sport-selector {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100dvh - 60px);
  padding: 24px 16px;
  text-align: center;
}

.sport-selector h1 {
  font-size: 1.6rem;
  margin-bottom: 4px;
  letter-spacing: -0.03em;
}

.app-logo {
  display: block;
  margin: 0 auto 8px;
  height: 48px;
  width: auto;
  filter: brightness(0) invert(1);
}

.free-play-label {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-dim);
  letter-spacing: 0.04em;
  opacity: 0.55;
  margin-top: auto;
  padding-top: 32px;
  margin-bottom: 8px;
}

.sport-selector .subtitle {
  color: var(--text-dim);
  font-size: 0.95rem;
  margin-bottom: 8px;
}

.sport-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  max-width: 400px;
  margin: 0 auto;
}

.sport-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 20px 12px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform 0.25s var(--spring-soft), border-color 0.15s ease,
              background 0.15s ease, box-shadow 0.25s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  /* Minimum comfortable tap area */
  min-height: 90px;
}

.sport-option:active { transform: scale(0.94); box-shadow: 0 0 0 4px var(--tap-glow); transition-duration: 0.06s; }

.sport-option:hover {
  border-color: var(--accent);
  background: var(--surface-bright);
}

.sport-icon { font-size: 2.4rem; }

.sport-name {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 1.1rem;
}

.sport-badge {
  font-size: 0.82rem;
  color: var(--text-dim);
  min-height: 1em;
}

.sport-badge .live-count {
  color: var(--green);
  font-weight: 600;
}

.reset-link {
  margin-top: 24px;
  display: flex;
  justify-content: center;
  gap: 12px;
}

.reset-btn, .debug-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.72rem;
  /* 44px min touch target */
  min-height: 44px;
  padding: 4px 14px;
  border-radius: 20px;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  display: inline-flex;
  align-items: center;
}

.reset-btn:hover, .debug-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* === Game Selector Screen === */
.game-selector {
  padding: 20px 16px;
  text-align: center;
}

.selector-header {
  text-align: left;
  margin-bottom: 8px;
}

.game-selector h1 {
  font-size: 1.6rem;
  margin-bottom: 4px;
  letter-spacing: -0.03em;
}

.game-selector .subtitle {
  color: var(--text-dim);
  font-size: 0.95rem;
  margin-bottom: 20px;
}

.game-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.game-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform 0.25s var(--spring-soft), border-color 0.15s ease,
              background 0.15s ease, box-shadow 0.25s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  /* Generous touch target for live-game list rows */
  min-height: 60px;
}

.game-option:active { transform: scale(0.97); box-shadow: 0 0 0 3px var(--tap-glow); transition-duration: 0.06s; }
.game-option.live     { border-color: var(--green); }
.game-option.upcoming { border-color: var(--sport-accent); opacity: 1; }

.game-option .teams {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  font-size: 1.1rem;
}

.game-option .status          { font-size: 0.88rem; color: var(--text-dim); }
.game-option.live .status     { color: var(--green); font-weight: 600; }
.game-option.upcoming .status { color: var(--sport-accent); font-weight: 500; }

.no-games {
  color: var(--text-dim);
  padding: 40px 20px;
  font-size: 0.9rem;
}

/* ===================================================================
 * Beginner Mode — progressive disclosure
 * body.beginner hides advanced UI elements until the player places 5+ bets.
 * Toggled by updateHUD() in ui.js based on state.totalBets.
 * =================================================================== */

/* Hide stats the player hasn't earned yet */
body.beginner .stats-row        { display: none; }
body.beginner .streak-badge     { display: none; }
body.beginner .daily-chip       { display: none !important; }

/* Hide advanced features */
body.beginner #sheetModeToggle  { display: none !important; }
body.beginner #challengeBtn     { display: none !important; }
body.beginner .crew-btn         { display: none !important; }
body.beginner .audio-toggle-btn { display: none !important; }
body.beginner .combo-meter      { display: none !important; }

/* ===================================================================
 * Mobile Responsive Breakpoints — selectors & HUD
 * (Header responsive rules live in header.css)
 * =================================================================== */

/* ── Small phones (≤ 390px: iPhone SE, older Androids) ── */
@media (max-width: 390px) {
  /* Tighten HUD bar further on very small screens */
  .points-display {
    font-size: 1rem;
  }

  .stats-row {
    gap: 7px;
    font-size: 0.75rem;
  }

  .sport-selector,
  .game-selector {
    padding: 20px 12px;
    min-height: calc(100dvh - 40px);
  }

  /* Stack the reset/debug/help buttons if they wrap */
  .reset-link {
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
  }

  /* Slightly narrower selector header so back + help don't collide */
  .selector-header {
    gap: 8px;
  }

  /* Reduce bets container horizontal padding to gain usable width */
  .bets-container {
    padding-left: 8px;
    padding-right: 8px;
  }
}

/* ── General mobile (≤ 600px) ── */
@media (max-width: 600px) {
  .event-log-item {
    font-size: 0.88rem;
    color: var(--text-dim-mobile);
  }

  .commentary-text {
    font-size: 0.85rem;
    color: var(--text-dim-mobile);
  }

  .game-summary-bar {
    font-size: 0.9rem;
  }

  .stats-row {
    font-size: 0.82rem;
    color: var(--text-dim-mobile);
  }
}

/* ── Landscape on small phones (height ≤ 430px) ── */
@media (max-height: 430px) and (orientation: landscape) {
  /* Shrink combo meter */
  .combo-meter {
    padding: 4px 16px;
  }

  /* Hide non-essential chrome in landscape to save vertical space */
  .commentary-bar { max-height: 0 !important; opacity: 0 !important; padding: 0 !important; }
}

/* ===================================================================
 * Desktop Layout (≥ 860px)
 * Selector screens: wider, more spacious, sport grid in a single row.
 * =================================================================== */
@media (min-width: 860px) {
  /* Sport selector: show all 4 sport cards in one row */
  .sport-list {
    grid-template-columns: repeat(4, 1fr);
    max-width: 680px;
    gap: 16px;
  }

  .sport-option {
    padding: 28px 16px;
    min-height: 110px;
  }

  .sport-selector {
    padding: 56px 24px 48px;
    min-height: auto;
  }

  /* Game selector: constrained width, centred, more breathing room */
  .game-selector {
    max-width: 760px;
    margin: 0 auto;
    padding: 40px 32px;
  }

  .game-list {
    gap: 14px;
    text-align: left;
  }

  .game-option {
    padding: 20px 28px;
    min-height: 72px;
  }

  .game-option .teams {
    font-size: 1.15rem;
  }
}

/* ===================================================================
 * Desktop Game View (≥ 960px)
 * The event log is promoted from a fixed bottom strip to a fixed
 * right sidebar.  Main content is inset by the sidebar width so
 * nothing slides under it.  Bet cards are width-capped and centred
 * within the remaining content area.
 * =================================================================== */
@media (min-width: 960px) {
  /* Inset the whole game view to leave room for the fixed sidebar */
  #gameView {
    padding-right: 300px;
  }

  /* No sidebar needed before a game starts — remove the inset */
  #gameView.pregame-mode {
    padding-right: 0;
  }

  /* === Right sidebar: event log === */
  .event-log {
    /* Convert from bottom strip → fixed right column */
    top: 0;
    right: 0;
    bottom: 0;
    left: auto;
    width: 280px;
    max-height: 100vh;
    border-top: none;
    border-left: 1px solid var(--border);
    overflow-y: auto;
    overflow-x: hidden;
    /* Top padding keeps content below the sticky game header */
    padding: 72px 14px 24px;
    background: var(--surface);
    display: flex;
    flex-direction: column;
    gap: 0;
  }

  /* Sidebar heading injected via pseudo-element */
  .event-log::before {
    content: "Live Feed";
    display: block;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-dim);
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 4px;
    flex-shrink: 0;
  }

  /* Sidebar items: wrap text, stacked vertically */
  .event-log-item {
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
    padding: 7px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    line-height: 1.45;
    font-size: 0.8rem;
  }

  /* Bet cards: constrained width, centred in the content column */
  .bets-container {
    max-width: 740px;
    margin-left: auto;
    margin-right: auto;
    /* No longer needs huge bottom clearance — event log is on the side */
    padding-bottom: 32px;
  }
}
