:root {
  --bg-color: #111111;       /* Dark Background */
  --card-bg: #1e1e1e;        /* Dark Card Surface */
  --primary: #10b981;        /* Green */
  --text-main: #ffffff;      /* White Text */
  --text-sub: #9ca3af;       /* Light Gray Text */
  --accent: #3b82f6;         /* Blue */
  --font-main: 'Inter', sans-serif;
  --font-display: 'Oswald', sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-color);
  color: var(--text-main);
  min-height: 100dvh;
  width: 100vw;
  /* DELETED: overflow: hidden; */
  /* DELETED: overscroll-behavior: none; */
  display: flex;
  justify-content: center;
  align-items: flex-start;
  touch-action: manipulation;
}

/* --- LAYOUT CONTAINERS --- */

.app-container {
  width: 100%;
  min-height: 100%; /* CHANGED: from height: 100% */
  display: flex;
  justify-content: center;
  align-items: flex-start; /* CHANGED */
  padding: 20px 10px 40px 10px; /* Added a little bottom padding for breathing room */
  position: relative;
}

.game-card {
  background: var(--card-bg);
  width: 100%;
  max-width: 420px; 
  height: auto; /* CHANGED: Prevents unnatural stretching */
  max-height: 850px;
  border-radius: 20px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  border: 1px solid #333;
}

/* --- HEADER & STATS --- */

.stats-bar {
  display: flex;
  justify-content: space-between;
  padding: 15px 10px; /* Reduced side padding slightly to fit 4 items */
  gap: 5px; /* Adds a tiny safety gap between items */
  background: var(--card-bg);
  border-bottom: 1px solid #333;
  flex-shrink: 0; 
}

.stat-box {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-label {
  font-size: 0.7rem;
  font-weight: 800;
  color: var(--text-sub);
  letter-spacing: 1px;
}

.stat-value {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-main);
}

.score-bump {
  animation: score-pop 0.3s ease-out;
  color: var(--primary);
}
@keyframes score-pop {
  50% { transform: scale(1.4); }
}

/* --- DYNAMIC HEADER (UPDATED HEIGHT) --- */

.card__header {
  /* INCREASED HEIGHT: From 170px to 250px to show 4+ goals */
  height: 220px;
  min-height: 220px;
  max-height: 220px;
  
  display: flex;
  flex-direction: column;
  padding: 15px 0 5px 0;
  background: #252525;
  border-bottom: 1px solid #333;
  flex-shrink: 0; 
  overflow: hidden;
}

.competition-label {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-sub);
  margin-bottom: 8px;
  text-transform: uppercase;
  font-weight: 600;
  flex-shrink: 0;
}

.comp-sep { margin: 0 6px; opacity: 0.5; }

.match-info {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 15px;
  margin-bottom: 8px;
  flex-shrink: 0; 
}

.team-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 80px;
}

.header-badge {
  width: 45px;
  height: 45px;
  object-fit: contain;
  margin-bottom: 4px;
}

.team-name {
  font-size: 0.75rem;
  font-weight: 700;
  text-align: center;
  line-height: 1.1;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.vs-badge {
  background: #000;
  color: #fff;
  font-family: var(--font-display);
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 1px;
  border: 1px solid #333;
}

.center-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

/* FINISH ICON */
.finish-icon-large {
  width: 32px;  
  height: 32px;
  object-fit: contain; 
  opacity: 1;
  filter: none; 
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

/* Timeline */
.timeline {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex-grow: 1; /* Fills the rest of the 250px */
  overflow-y: auto; 
  padding: 0 15px;
  margin-top: 5px;
  
  scrollbar-width: thin;
  scrollbar-color: #444 #222;
}

.timeline::-webkit-scrollbar { width: 4px; }
.timeline::-webkit-scrollbar-track { background: #222; }
.timeline::-webkit-scrollbar-thumb { background: #444; border-radius: 2px; }

.timeline-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  font-size: 0.75rem;
  padding: 3px 0; /* Slightly more breathing room */
  transition: opacity 0.3s;
  color: var(--text-sub);
  min-height: 24px; /* Ensure rows have consistent height */
}

.timeline-row.blurred { opacity: 0.3; }
.timeline-row.active { 
  opacity: 1; 
  font-weight: 700; 
  background: rgba(255,255,255,0.05); 
  border-radius: 4px; 
  color: #fff; 
}

.t-event { display: flex; align-items: center; gap: 6px; }
.t-event.home { justify-content: flex-end; }
.t-score { font-family: monospace; font-weight: 700; color: #666; padding: 0 10px; }
.t-badge-mini { width: 14px; height: 14px; object-fit: contain; }

/* --- PITCH & CANVAS --- */

.canvas-container {
  position: relative;
  flex-grow: 1; 
  width: 100%;
  background: #2a3a2a; 
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}

canvas {
  width: 100%;
  height: 100%; 
  object-fit: contain; 
  display: block;
  /* DELETED: touch-action: none; */
}

/* Drag Hint Overlay */
.drag-hint {
  position: absolute;
  top: 90%; left: 51%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  text-align: center;
  color: rgba(255,255,255,0.8);
  font-weight: 600;
  text-shadow: 0 2px 4px rgba(0,0,0,0.5);
  transition: opacity 0.5s;
}
.hand-icon { font-size: 2rem; animation: float-hand 1.5s infinite ease-in-out; }
@keyframes float-hand { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }

/* --- FOOTER & ACTIONS --- */

.status-bar {
  /* STRICT SIZE SETTINGS */
  height: 60px;       /* Force a specific height */
  min-height: 60px;   /* Prevent shrinking */
  max-height: 60px;   /* Prevent growing */
  overflow: hidden;   /* Hide anything that spills out during calculation */
  
  /* Centering */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px;    /* Add side padding so text doesn't touch edges */
}

#statusMessage {
  width: 100%;
  text-align: center;
  line-height: 1.1;   /* Tighter line height helps multi-line hints fit better */
  margin: 0;
  white-space: normal; /* Allow text to wrap to new lines */
  transition: font-size 0.1s; /* Smooth transition if resized */
}

.action-btn {
  width: 100%;
  padding: 20px;
  border: none;
  background: #10b981; 
  color: #fff;
  font-family: var(--font-display);
  font-size: 1.2rem;
  letter-spacing: 1px;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}
.action-btn:hover { background: #059669; }
.action-btn:active { background: #047857; }
.action-btn:disabled { background: #374151; color: #9ca3af; cursor: not-allowed; }

/* Admin Toggle */
.admin-toggle {
  position: fixed;
  top: 10px; left: 10px;
  background: rgba(0,0,0,0.7);
  color: white;
  border: none;
  padding: 5px 10px;
  font-size: 0.7rem;
  border-radius: 4px;
  cursor: pointer;
  z-index: 9999;
}
.admin-toggle.active { background: #ef4444; }

/* --- ANIMATIONS --- */

.floating-score {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: 4rem;
  font-weight: 900;
  pointer-events: none;
  z-index: 1000;
  font-family: var(--font-display);
  -webkit-text-stroke: 2px white;
}

.floating-miss {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%) scale(0.5);
  font-size: 5rem;
  font-weight: 900;
  color: #ef4444; 
  text-shadow: 0 0 20px rgba(239, 68, 68, 0.6);
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  font-family: system-ui, -apple-system, sans-serif;
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s ease;
}

@keyframes shake-impact {
  0%, 100% { transform: translate(-50%, -50%) scale(1.5); }
  25% { transform: translate(-51%, -49%) scale(1.5); }
  75% { transform: translate(-49%, -51%) scale(1.5); }
}
.shake-it { animation: shake-impact 0.2s ease-in-out; }

@keyframes disintegrate-dust {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(1.5); letter-spacing: 0; filter: blur(0); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(2); letter-spacing: 50px; filter: blur(15px); }
}
.disintegrate { animation: disintegrate-dust 0.6s ease-out forwards; }

.pop-in { animation: pop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
@keyframes pop { 0% { transform: scale(0.8); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }

/* --- HINT BUTTON & BUBBLE --- */

.hint-container {
  position: absolute;
  bottom: 10px;
  right: 10px;
  z-index: 50; 
  display: flex;
  align-items: center;
  display: none; 
}

.hint-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  width: 40px; 
  height: 40px; 
  transition: transform 0.2s ease, filter 0.2s;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,0.5));
}

.hint-btn:hover {
  transform: scale(1.1) rotate(-5deg);
  filter: drop-shadow(0 6px 12px rgba(0,0,0,0.7));
}

.hint-btn:active { transform: scale(0.95); }

.hint-btn img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 12px; 
}

/* "Need a hint?" Bubble */
.hint-bubble {
  background: var(--card-bg); 
  color: var(--text-main);
  border: 1px solid #444;
  padding: 6px 12px;
  border-radius: 15px;
  margin-right: 10px; 
  font-weight: 600;
  font-size: 0.8rem;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  position: relative;
  animation: bounce-horizontal 2s infinite ease-in-out;
  white-space: nowrap;
}

.hint-arrow {
  position: absolute;
  top: 50%;
  right: -6px; 
  transform: translateY(-50%);
  width: 0; height: 0; 
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-left: 6px solid var(--card-bg); 
}

@keyframes bounce-horizontal {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(-5px); }
}

.hidden-bubble {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

/* --- LOADER --- */
.loader-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: var(--bg-color); 
  color: white;
  z-index: 10000;
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  transition: opacity 0.5s;
}
.loader-overlay.hidden { opacity: 0; pointer-events: none; }
.spinner {
  width: 40px; height: 40px; border: 4px solid #333;
  border-top: 4px solid #10b981; border-radius: 50%;
  animation: spin 1s linear infinite; margin-bottom: 10px;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* --- LEADERBOARD BUTTON & MODAL --- */

/* The new 'Leaderboard' button style */
.secondary-btn {
  font-size: 1rem;
  padding: 15px;
  /* Uses the accent color we defined inline in HTML */
}

/* The dark background behind the popup */
.modal-overlay {
  position: fixed; 
  top: 0; 
  left: 0; 
  width: 100%; 
  height: 100%;
  background: rgba(0,0,0,0.85); /* Dark semi-transparent bg */
  backdrop-filter: blur(5px);    /* Blur the game behind it */
  z-index: 9000;                 /* Sit on top of everything */
  display: flex; 
  justify-content: center; 
  align-items: center;
  opacity: 1; 
  transition: opacity 0.3s;
}

/* Hide the modal when not active */
.modal-overlay.hidden { 
  opacity: 0; 
  pointer-events: none; 
}

/* The actual box containing the scores */
.modal-content {
  background: var(--card-bg);
  width: 90%; 
  max-width: 400px;
  border-radius: 16px;
  border: 1px solid #444;
  box-shadow: 0 20px 50px rgba(0,0,0,0.5);
  display: flex; 
  flex-direction: column;
  overflow: hidden;
  max-height: 80vh; /* Don't get too tall on mobile */
}

.modal-header {
  padding: 20px;
  background: #252525;
  display: flex; 
  justify-content: space-between; 
  align-items: center;
  border-bottom: 1px solid #333;
}

.modal-header h2 { 
  font-family: var(--font-display); 
  margin: 0; 
  letter-spacing: 1px; 
  color: #fff;
}

.close-icon {
  background: none; 
  border: none; 
  color: #fff; 
  font-size: 2rem; 
  cursor: pointer; 
  line-height: 1;
}

/* Allow scrolling if the list is long */
.lb-scroller { 
  flex-grow: 1; 
  overflow-y: auto; 
  padding: 0; 
}

/* The Table of Scores */
.lb-table { 
  width: 100%; 
  border-collapse: collapse; 
  font-size: 0.9rem; 
}

.lb-table th { 
  text-align: left; 
  padding: 12px 15px; 
  color: var(--text-sub); 
  font-size: 0.75rem; 
  text-transform: uppercase; 
  border-bottom: 1px solid #333; 
}

.lb-table td { 
  padding: 12px 15px; 
  border-bottom: 1px solid #2a2a2a; 
  color: #fff;
}

/* Highlight the Top 3 */
.lb-table tr:nth-child(1) td { color: #ffd700; font-weight: bold; } /* Gold */
.lb-table tr:nth-child(2) td { color: #c0c0c0; font-weight: bold; } /* Silver */
.lb-table tr:nth-child(3) td { color: #cd7f32; font-weight: bold; } /* Bronze */

/* --- LEADERBOARD FOOTER (UPDATED FOR SHARE BTN) --- */

.lb-footer { 
  padding: 20px; 
  border-top: 1px solid #333; 
  background: #252525; 
}

.lb-input-group { 
  display: flex; 
  flex-direction: column; /* Changed to Stack Vertical */
  gap: 10px; 
}

#playerName {
  background: #111; 
  border: 1px solid #444; 
  color: #fff; 
  padding: 12px; 
  border-radius: 6px; 
  width: 100%;
  outline: none;
  font-family: inherit;
  font-size: 1rem;
}

/* New container for the button row */
.action-row {
  display: flex;
  gap: 10px;
  width: 100%;
}

#submitScoreBtn {
  background: var(--primary); 
  color: #fff; 
  border: none; 
  border-radius: 6px; 
  font-weight: 700; 
  cursor: pointer; 
  font-family: var(--font-display);
  transition: background 0.2s;
  
  flex: 1;        /* Take up available space */
  height: 44px;   /* Match height of share button */
  display: flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
}

#submitScoreBtn:disabled { 
  background: #444; 
  cursor: not-allowed; 
}

/* Square Share Button */
.icon-btn {
  width: 44px;
  height: 44px;
  background: var(--accent); /* Uses your blue variable */
  border: none;
  border-radius: 6px;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: filter 0.2s;
  flex-shrink: 0;
}

.icon-btn:hover { filter: brightness(1.1); }
.icon-btn:active { transform: scale(0.95); }

.lb-status { 
  font-size: 0.8rem; 
  margin: 10px 0 0 0; 
  text-align: center; 
  color: var(--text-sub); 
  min-height: 1rem; 
}

/* --- LIVES SYSTEM --- */
.lives-container {
    display: flex;
    flex-direction: column; /* Stack label on top of balls */
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.4); /* Darker, professional bg */
    padding: 4px 12px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    min-width: 80px;
}

.lives-label {
    font-size: 0.6rem;
    font-weight: 800;
    color: var(--text-sub); /* Grey text */
    letter-spacing: 1px;
    margin-bottom: 2px;
}

.lives-row {
    display: flex;
    gap: 6px;
}

.life-ball {
    width: 22px;
    height: 22px;
    object-fit: contain;
    transition: all 0.4s ease; /* Smooth transition for the color change */
    filter: drop-shadow(0 2px 2px rgba(0,0,0,0.5));
    opacity: 1;
    transform: scale(1);
}

/* THE RED GHOST EFFECT */
.life-ball.lost {
    opacity: 0.3; /* Fade out */
    /* This filter combination turns the white ball RED */
    filter: sepia(1) saturate(100) hue-rotate(-50deg) contrast(1.5); 
    transform: scale(0.8); /* Shrink slightly */
}

/* Shake animation for critical state (1 life left) */
.lives-critical .life-ball:not(.lost) {
    animation: pulse-red 1s infinite;
}

@keyframes pulse-red {
    0% { filter: drop-shadow(0 0 0 rgba(239, 68, 68, 0)); }
    50% { filter: drop-shadow(0 0 4px rgba(239, 68, 68, 0.8)); }
    100% { filter: drop-shadow(0 0 0 rgba(239, 68, 68, 0)); }
}

.lb-highlight {
    background-color: rgba(234, 179, 8, 0.2); /* Gold tint */
    border: 1px solid rgba(234, 179, 8, 0.5);
    font-weight: bold;
    color: #fbbf24;
}

/* --- GAME OVER MODAL --- */
.game-over-card {
    text-align: center;
    border-top: 4px solid #ef4444; /* Red accent for game over */
    transform: translateY(20px);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* When the overlay loses the 'hidden' class, animate the card up */
.modal-overlay:not(.hidden) .game-over-card {
    transform: translateY(0);
}

.go-header {
    padding: 25px 20px 15px;
    background: #252525;
    border-bottom: 1px solid #333;
}

.go-header h2 {
    font-family: var(--font-display);
    font-size: 2.2rem;
    margin: 0;
    color: #ef4444;
    letter-spacing: 2px;
}

.go-header p {
    color: var(--text-sub);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 5px;
}

.go-body {
    padding: 30px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.final-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.go-score-value {
    font-family: var(--font-display);
    font-size: 4rem;
    font-weight: 700;
    color: #fff;
    line-height: 1;
    text-shadow: 0 4px 10px rgba(0,0,0,0.5);
}

.new-best-badge {
    background: rgba(251, 191, 36, 0.1);
    color: #fbbf24;
    border: 1px solid rgba(251, 191, 36, 0.3);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 1px;
    animation: pulse-gold 2s infinite;
}

@keyframes pulse-gold {
    0% { box-shadow: 0 0 0 0 rgba(251, 191, 36, 0.4); }
    70% { box-shadow: 0 0 0 10px rgba(251, 191, 36, 0); }
    100% { box-shadow: 0 0 0 0 rgba(251, 191, 36, 0); }
}

.final-stat-row {
    display: flex;
    gap: 40px;
    justify-content: center;
    width: 100%;
    padding-top: 15px;
    border-top: 1px solid #333;
}

.go-footer {
    padding: 20px;
    background: #252525;
    border-top: 1px solid #333;
}

/* --- UTILITY CLASSES --- */
.hidden {
  display: none !important;
}

#goFinalScore {
    font-size: 48px; /* Increase or decrease this number to get the perfect size */
}

.float-left {
  position: absolute;
  bottom: 15px;
  left: 15px;
  z-index: 10;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 20px;
  cursor: pointer;
  /* Centering Fixes */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0; 
  line-height: 1; 
  box-sizing: border-box;
  backdrop-filter: blur(4px);
  transition: transform 0.2s, background 0.3s ease; /* Added background to transition so it fades to red smoothly */
}

.float-left:hover {
  background: rgba(0, 0, 0, 0.8);
  transform: scale(1.05);
}

/* ---> NEW: The Red Muted State <--- */
.float-left.is-muted {
  background: rgba(220, 38, 38, 0.85); /* A clean, semi-transparent red */
}

.float-left.is-muted:hover {
  background: rgba(220, 38, 38, 1); /* Solid red on hover */
}

/* Ensure the Modal overlay covers everything and centers the content */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  display: flex; /* Key for centering */
  justify-content: center;
  align-items: center;
  z-index: 2000;
  padding: 20px;
}

/* Specific styling for the How To Play box */
.how-to-content {
  width: 100%;
  max-width: 400px; /* Keeps it readable on desktop */
  background: var(--bg-card, #1a1a1a);
  border: 2px solid #10b981;
  border-radius: 16px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
}

.modal-footer {
  width: 100%;
  display: flex;
  justify-content: center;
  margin-top: 10px;
}

/* Instruction Step styling */
.instruction-step {
  display: flex;
  align-items: center;
  gap: 15px;
  margin-bottom: 12px;
  background: rgba(255, 255, 255, 0.05);
  padding: 15px;
  border-radius: 12px;
  text-align: left;
}

.step-icon {
  font-size: 28px;
}

.main-btn {
  background: #10b981; /* Your theme green */
  color: white;
  border: none;
  padding: 12px 30px;
  font-size: 1.1rem;
  font-weight: 800;
  border-radius: 8px;
  cursor: pointer;
  text-transform: uppercase;
  transition: transform 0.1s, background 0.2s;
  width: 100%; /* Makes it easy to tap on mobile */
}

.main-btn:active {
  transform: scale(0.96);
}