/* ===== CSS Variables ===== */
:root {
  --jeopardy-blue: #060CE9;
  --jeopardy-blue-dark: #04098B;
  --jeopardy-blue-light: #1E24FF;
  --jeopardy-gold: #D4A843;
  --jeopardy-gold-light: #E8C66A;
  --white: #FFFFFF;
  --black: #000000;
  --gray: #666666;
  --gray-light: #CCCCCC;
  --correct-green: #28a745;
  --wrong-red: #dc3545;

  --font-logo: 'Michroma', sans-serif;
  --font-sans: 'Open Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  --shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
  --shadow-heavy: 0 8px 16px rgba(0, 0, 0, 0.4);
}

/* ===== Reset & Base ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-sans);
  background: linear-gradient(135deg, var(--jeopardy-blue-dark) 0%, var(--jeopardy-blue) 100%);
  color: var(--white);
  -webkit-tap-highlight-color: transparent;
}

/* ===== Screen Management ===== */
.screen {
  display: none;
  width: 100%;
  height: 100%;
  padding: 1rem;
  overflow-y: auto;
}

.screen.active {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ===== Buttons ===== */
.btn {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: bold;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
  touch-action: manipulation;
}

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

.btn-primary {
  background: var(--jeopardy-gold);
  color: var(--black);
  box-shadow: var(--shadow);
}

.btn-primary:hover {
  background: var(--jeopardy-gold-light);
}

.btn-secondary {
  background: var(--gray);
  color: var(--white);
}

.btn-correct {
  background: var(--correct-green);
  color: var(--white);
  font-size: 1.25rem;
  padding: 1rem 2rem;
}

.btn-wrong {
  background: var(--wrong-red);
  color: var(--white);
  font-size: 1.25rem;
  padding: 1rem 2rem;
}

.btn-final {
  background: var(--wrong-red);
  color: var(--white);
}

.btn-icon {
  background: transparent;
  font-size: 1.5rem;
  padding: 0.5rem;
}

.btn-player {
  background: var(--jeopardy-blue-light);
  color: var(--white);
  min-width: 120px;
  padding: 1rem;
}

/* ===== Login Screen ===== */
.login-container {
  background: rgba(0, 0, 0, 0.3);
  padding: 2rem;
  border-radius: 16px;
  max-width: 350px;
  width: 100%;
}

.login-container h2 {
  margin-bottom: 1.5rem;
  text-align: center;
}

.login-inputs {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.login-inputs input {
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border: 2px solid var(--jeopardy-gold);
  border-radius: 8px;
  background: var(--white);
  color: var(--black);
}

.login-error {
  color: var(--wrong-red);
  text-align: center;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.login-error.hidden {
  display: none;
}

#login-btn {
  width: 100%;
}

/* ===== Setup Screen ===== */
.game-title {
  font-family: var(--font-logo);
  font-size: 3rem;
  color: var(--jeopardy-gold);
  text-shadow: 4px 4px 8px rgba(0, 0, 0, 0.5);
  margin-bottom: 2rem;
  text-align: center;
  letter-spacing: 0.1em;
}

.setup-container {
  background: rgba(0, 0, 0, 0.3);
  padding: 2rem;
  border-radius: 16px;
  max-width: 400px;
  width: 100%;
}

.player-setup h2 {
  margin-bottom: 1rem;
  text-align: center;
}

.player-inputs {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.player-inputs input {
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border: 2px solid var(--jeopardy-gold);
  border-radius: 8px;
  background: var(--white);
  color: var(--black);
}

.questions-setup {
  margin-bottom: 1.5rem;
}

#random-questions-btn {
  width: 100%;
  margin-bottom: 0.75rem;
  font-size: 1rem;
}

.or-divider {
  text-align: center;
  color: var(--gray-light);
  font-size: 0.9rem;
  margin: 0.75rem 0;
}

.loading-indicator {
  text-align: center;
  padding: 1rem;
  color: var(--jeopardy-gold);
  font-size: 1.1rem;
}

.loading-indicator.hidden {
  display: none;
}

.questions-loaded {
  color: var(--correct-green);
  text-align: center;
  padding: 0.5rem;
  font-weight: bold;
}

.file-label {
  display: block;
  padding: 1rem;
  background: rgba(255, 255, 255, 0.1);
  border: 2px dashed var(--gray-light);
  border-radius: 8px;
  text-align: center;
  cursor: pointer;
  transition: background 0.2s;
}

.file-label:hover {
  background: rgba(255, 255, 255, 0.2);
}

.file-label input {
  display: none;
}

#start-game-btn {
  width: 100%;
  font-size: 1.25rem;
  padding: 1rem;
}

/* ===== Game Board Screen ===== */
.board-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  max-width: 1200px;
  margin-bottom: 0.5rem;
}

.board-title {
  font-family: var(--font-logo);
  font-size: 1.75rem;
  color: var(--jeopardy-gold);
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
  letter-spacing: 0.1em;
}

.game-board {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  width: 100%;
  max-width: 1200px;
  flex: 1;
  min-height: 0;
}

.category-header {
  background: var(--jeopardy-blue);
  color: var(--white);
  font-family: var(--font-sans);
  font-size: clamp(0.6rem, 2vw, 1rem);
  font-weight: 700;
  text-transform: uppercase;
  text-align: center;
  padding: 0.5rem 0.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
  border: 2px solid var(--jeopardy-blue-dark);
  min-height: 60px;
}

.tile {
  background: var(--jeopardy-blue);
  color: var(--jeopardy-gold);
  font-family: var(--font-sans);
  font-size: clamp(1rem, 4vw, 2rem);
  font-weight: bold;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: 2px solid var(--jeopardy-blue-dark);
  transition: transform 0.1s, background 0.2s;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
  min-height: 50px;
}

.tile:hover:not(.answered) {
  background: var(--jeopardy-blue-light);
  transform: scale(1.02);
}

.tile.answered {
  background: var(--jeopardy-blue-dark);
  color: transparent;
  cursor: default;
}

/* ===== Scoreboard ===== */
.scoreboard {
  display: flex;
  justify-content: center;
  gap: 1rem;
  width: 100%;
  max-width: 1200px;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}

.player-score-card {
  background: rgba(0, 0, 0, 0.4);
  padding: 0.5rem 1rem;
  border-radius: 8px;
  text-align: center;
  min-width: 150px;
}

.player-name {
  font-size: 0.9rem;
  margin-bottom: 0.25rem;
  cursor: pointer;
}

.player-name:hover {
  text-decoration: underline;
}

.player-score-value {
  font-size: 1.5rem;
  font-weight: bold;
  color: var(--jeopardy-gold);
}

.player-score-value.negative {
  color: var(--wrong-red);
}

.score-controls {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 0.25rem;
}

.score-controls .btn {
  padding: 0.25rem 0.75rem;
  font-size: 1rem;
}

.board-controls {
  margin-top: 0.5rem;
}

/* ===== Question Screen ===== */
#question-screen {
  justify-content: center;
}

.question-container {
  background: var(--jeopardy-blue);
  border: 4px solid var(--jeopardy-gold);
  border-radius: 16px;
  padding: 2rem;
  max-width: 900px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-heavy);
}

.question-header {
  margin-bottom: 1.5rem;
}

.question-category {
  font-family: var(--font-display);
  font-size: 1.5rem;
  text-transform: uppercase;
  display: block;
  margin-bottom: 0.5rem;
}

.question-value {
  font-size: 2rem;
  font-weight: bold;
  color: var(--jeopardy-gold);
}

.question-text {
  font-family: var(--font-sans);
  font-size: clamp(1.5rem, 5vw, 2.5rem);
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: 2rem;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.answer-text {
  font-family: var(--font-sans);
  font-size: clamp(1.5rem, 5vw, 2.25rem);
  font-weight: 700;
  color: var(--jeopardy-gold);
  margin-bottom: 2rem;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
}

.question-controls {
  margin-bottom: 1rem;
}

.scoring-controls, .correct-wrong-controls {
  margin-top: 1rem;
}

.scoring-prompt, .selected-player {
  font-size: 1.25rem;
  margin-bottom: 1rem;
}

.player-buttons {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.verdict-buttons {
  display: flex;
  gap: 1rem;
  justify-content: center;
}

/* ===== Daily Double Screen ===== */
#daily-double-screen {
  justify-content: center;
}

.daily-double-container {
  text-align: center;
}

.daily-double-title {
  font-family: var(--font-logo);
  font-size: clamp(2rem, 8vw, 4rem);
  color: var(--jeopardy-gold);
  text-shadow: 4px 4px 8px rgba(0, 0, 0, 0.5);
  animation: pulse 1s ease-in-out infinite alternate;
  margin-bottom: 2rem;
  letter-spacing: 0.1em;
}

@keyframes pulse {
  from { transform: scale(1); }
  to { transform: scale(1.05); }
}

.dd-player-select p,
.dd-wager-section p {
  font-size: 1.5rem;
  margin-bottom: 1rem;
}

.dd-player-name {
  font-size: 2rem;
  color: var(--jeopardy-gold);
}

.dd-player-score {
  font-size: 1.25rem;
  color: var(--gray-light);
}

.wager-input-group {
  margin: 1.5rem 0;
}

.wager-input-group label {
  display: block;
  margin-bottom: 0.5rem;
}

#dd-wager-input {
  padding: 0.75rem 1rem;
  font-size: 1.5rem;
  width: 150px;
  text-align: center;
  border: 2px solid var(--jeopardy-gold);
  border-radius: 8px;
}

.wager-range {
  font-size: 0.9rem;
  color: var(--gray-light);
  margin-top: 0.5rem;
}

/* ===== Final Jeopardy Screen ===== */
#final-jeopardy-screen {
  justify-content: center;
}

.final-container {
  text-align: center;
  width: 100%;
  max-width: 900px;
}

.fj-phase {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.fj-phase.hidden {
  display: none;
}

.fj-title {
  font-family: var(--font-logo);
  font-size: clamp(1.5rem, 6vw, 3rem);
  color: var(--jeopardy-gold);
  text-shadow: 4px 4px 8px rgba(0, 0, 0, 0.5);
  margin-bottom: 1rem;
  letter-spacing: 0.1em;
}

.fj-label {
  font-size: 1.5rem;
  margin-bottom: 1rem;
}

.fj-category {
  font-family: var(--font-sans);
  font-size: clamp(1.5rem, 6vw, 2.5rem);
  font-weight: 700;
  text-transform: uppercase;
  margin-bottom: 2rem;
  padding: 1rem 2rem;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 8px;
}

.fj-wager-inputs {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 2rem;
}

.fj-wager-card {
  background: rgba(0, 0, 0, 0.3);
  padding: 1rem;
  border-radius: 8px;
  min-width: 150px;
}

.fj-wager-card label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: bold;
}

.fj-wager-card .player-score-display {
  font-size: 0.9rem;
  color: var(--gray-light);
  margin-bottom: 0.5rem;
}

.fj-wager-card input {
  width: 100%;
  padding: 0.5rem;
  font-size: 1.25rem;
  text-align: center;
  border: 2px solid var(--jeopardy-gold);
  border-radius: 4px;
}

.fj-question-category {
  font-family: var(--font-sans);
  font-size: 1.5rem;
  font-weight: 700;
  text-transform: uppercase;
  margin-bottom: 1rem;
}

.fj-question-text {
  font-family: var(--font-sans);
  font-size: clamp(1.25rem, 4vw, 2rem);
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: 2rem;
  padding: 1.5rem;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
}

.fj-timer {
  margin-bottom: 1.5rem;
}

#fj-timer-display {
  font-size: clamp(3rem, 10vw, 6rem);
  font-weight: bold;
  color: var(--jeopardy-gold);
  font-family: var(--font-sans);
}

.fj-timer-controls {
  display: flex;
  gap: 1rem;
  justify-content: center;
}

.fj-answer-text {
  font-family: var(--font-sans);
  font-size: clamp(1.5rem, 5vw, 2.5rem);
  font-weight: 700;
  color: var(--jeopardy-gold);
  margin-bottom: 2rem;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 8px;
}

.fj-scoring {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 2rem;
}

.fj-score-card {
  background: rgba(0, 0, 0, 0.3);
  padding: 1rem;
  border-radius: 8px;
  min-width: 150px;
  text-align: center;
}

.fj-score-card .player-name-label {
  font-weight: bold;
  margin-bottom: 0.5rem;
}

.fj-score-card .wager-display {
  font-size: 0.9rem;
  color: var(--gray-light);
  margin-bottom: 0.5rem;
}

.fj-score-card .verdict-toggle {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
}

.fj-score-card .btn-toggle {
  padding: 0.5rem 1rem;
  border-radius: 4px;
  opacity: 0.5;
}

.fj-score-card .btn-toggle.active {
  opacity: 1;
}

.fj-score-card .new-score {
  font-size: 1.25rem;
  font-weight: bold;
  color: var(--jeopardy-gold);
  margin-top: 0.5rem;
}

/* ===== Winner Screen ===== */
#winner-screen {
  justify-content: center;
}

.winner-container {
  text-align: center;
}

.winner-label {
  font-family: var(--font-display);
  font-size: 2rem;
  color: var(--white);
  margin-bottom: 1rem;
}

.winner-name {
  font-family: var(--font-logo);
  font-size: clamp(2rem, 8vw, 4rem);
  color: var(--jeopardy-gold);
  text-shadow: 4px 4px 8px rgba(0, 0, 0, 0.5);
  margin-bottom: 1rem;
  letter-spacing: 0.05em;
}

.winner-score {
  font-size: 2rem;
  color: var(--jeopardy-gold-light);
  margin-bottom: 2rem;
}

.winner-controls {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
}

/* ===== Exit Button ===== */
.btn-exit {
  color: var(--gray-light);
  font-size: 1.5rem;
  font-weight: bold;
}

.btn-exit:hover {
  color: var(--wrong-red);
}

/* ===== Final Jeopardy Disabled State ===== */
.btn-final:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ===== Leaderboard Button ===== */
#leaderboard-btn {
  width: 100%;
  margin-top: 0.75rem;
}

/* ===== Leaderboard Screen ===== */
.leaderboard-container {
  width: 100%;
  max-width: 600px;
  text-align: center;
}

.overall-leader {
  background: rgba(0, 0, 0, 0.3);
  padding: 1.5rem;
  border-radius: 12px;
  margin-bottom: 1.5rem;
}

.overall-leader h2 {
  font-size: 1.25rem;
  margin-bottom: 0.75rem;
  color: var(--gray-light);
}

.overall-leader-display {
  font-family: var(--font-logo);
  font-size: 1.5rem;
  color: var(--jeopardy-gold);
  letter-spacing: 0.05em;
}

.overall-leader-display .leader-score {
  font-family: var(--font-sans);
  font-size: 1rem;
  color: var(--gray-light);
  margin-top: 0.25rem;
}

.game-history {
  background: rgba(0, 0, 0, 0.3);
  padding: 1.5rem;
  border-radius: 12px;
  margin-bottom: 1.5rem;
  max-height: 400px;
  overflow-y: auto;
}

.game-history h2 {
  font-size: 1.25rem;
  margin-bottom: 1rem;
  color: var(--gray-light);
}

.game-history-list {
  text-align: left;
}

.no-games {
  color: var(--gray);
  text-align: center;
  font-style: italic;
}

.game-record {
  background: rgba(255, 255, 255, 0.05);
  padding: 0.75rem;
  border-radius: 8px;
  margin-bottom: 0.5rem;
  border-left: 3px solid var(--jeopardy-gold);
}

.game-record-date {
  font-size: 0.8rem;
  color: var(--gray);
  margin-bottom: 0.5rem;
}

.game-record-players {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.game-record-player {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
}

.game-record-player.winner {
  color: var(--jeopardy-gold);
  font-weight: bold;
}

.game-record-player .score {
  font-weight: 600;
}

.leaderboard-controls {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
}

#clear-leaderboard-btn {
  background: var(--wrong-red);
}

/* ===== Utilities ===== */
.hidden {
  display: none !important;
}

/* ===== Host-Only Controls (hidden on large screens / TV) ===== */
@media (min-width: 1024px) {
  .host-only {
    /* Uncomment below to hide controls on TV */
    /* display: none !important; */
  }
}

/* ===== Responsive Adjustments ===== */
@media (max-width: 600px) {
  .screen {
    padding: 0.5rem;
  }

  .game-title {
    font-size: 2.5rem;
  }

  .board-title {
    font-size: 1.5rem;
  }

  .game-board {
    gap: 2px;
  }

  .category-header {
    padding: 0.25rem;
    min-height: 50px;
  }

  .tile {
    min-height: 40px;
  }

  .scoreboard {
    gap: 0.5rem;
  }

  .player-score-card {
    padding: 0.5rem;
    min-width: 100px;
  }

  .player-score-value {
    font-size: 1.25rem;
  }

  .question-container {
    padding: 1rem;
  }

  .btn {
    padding: 0.5rem 1rem;
  }
}

/* Large TV screens */
@media (min-width: 1200px) {
  .game-board {
    gap: 6px;
  }

  .category-header {
    font-size: 1.25rem;
    min-height: 80px;
  }

  .tile {
    font-size: 2.5rem;
    min-height: 80px;
  }

  .player-score-card {
    min-width: 200px;
    padding: 1rem 1.5rem;
  }

  .player-score-value {
    font-size: 2rem;
  }
}
