:root {
  --yahtzee-red: #d32f2f;
  --yahtzee-dark-red: #9a0007;
  --background: #f5f5f5;
  --card-bg: #ffffff;
  --border-color: #333;
  --border-light: #ccc;
  --text-dark: #212121;
  --text-light: #757575;
  --highlight: #ffd54f;
  --success: #4caf50;
  --error: #f44336;
  --shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.15);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background-color: var(--background);
  color: var(--text-dark);
  line-height: 1.6;
}

/* Header */
header {
  background-color: var(--yahtzee-red);
  color: white;
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow);
}

.logo {
  font-size: 2.5rem;
  font-weight: bold;
  font-style: italic;
  letter-spacing: 2px;
}

.session-info {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.25rem;
  font-size: 0.9rem;
}

#session-code {
  font-weight: bold;
  font-size: 1.2rem;
  letter-spacing: 2px;
}

/* Main */
main {
  max-width: 1400px;
  margin: 2rem auto;
  padding: 0 1rem;
}

/* Game Setup */
.game-setup {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 2rem;
  max-width: 800px;
  margin: 0 auto;
}

.setup-card {
  background: var(--card-bg);
  border: 2px solid var(--border-color);
  border-radius: 8px;
  padding: 2rem;
  text-align: center;
  box-shadow: var(--shadow);
}

.setup-card h2 {
  margin-bottom: 1.5rem;
  color: var(--yahtzee-red);
}

.setup-card input {
  width: 100%;
  padding: 0.75rem;
  margin-bottom: 1rem;
  border: 2px solid var(--border-light);
  border-radius: 4px;
  font-size: 1rem;
  text-transform: uppercase;
}

.setup-card input::placeholder {
  text-transform: none;
}

/* Buttons */
.btn {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 4px;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
}

.btn-primary {
  background-color: var(--yahtzee-red);
  color: white;
}

.btn-primary:hover {
  background-color: var(--yahtzee-dark-red);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background-color: #6c757d;
  color: white;
}

.btn-secondary:hover {
  background-color: #5a6268;
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.btn-secondary:active {
  transform: translateY(0);
}

/* Player Tabs */
.player-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.player-tab {
  padding: 0.75rem 1.5rem;
  background: var(--card-bg);
  border: 2px solid var(--border-light);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  font-weight: bold;
  transition: all 0.3s ease;
}

.player-tab:hover {
  background: var(--highlight);
}

.player-tab.active {
  background: var(--yahtzee-red);
  color: white;
  border-color: var(--border-color);
}

/* Scorecard Table */
.scorecard {
  background: var(--card-bg);
  border: 2px solid var(--border-color);
  border-radius: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  box-shadow: var(--shadow-lg);
}

.scorecard-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: auto;
}

.scorecard-table th,
.scorecard-table td {
  padding: 0.75rem;
  border: 1px solid var(--border-color);
  text-align: center;
}

.scorecard-table th {
  background-color: var(--yahtzee-red);
  color: white;
  font-weight: bold;
  font-size: 0.9rem;
  text-transform: uppercase;
  white-space: nowrap;
}

.scorecard-table .section-header {
  background-color: var(--text-dark);
  color: white;
  font-size: 1rem;
  text-align: left;
  padding-left: 1rem;
}

.scorecard-table .category-cell {
  text-align: left;
  font-weight: bold;
  padding-left: 1rem;
  white-space: nowrap;
}

.scorecard-table .category-cell .die-icon {
  display: inline-block;
  width: 24px;
  height: 24px;
  margin-right: 0.5rem;
  vertical-align: middle;
}

.scorecard-table .how-to-score {
  font-size: 0.85rem;
  color: var(--text-light);
  font-weight: normal;
}

.scorecard-table .score-cell {
  background-color: #fff;
  cursor: pointer;
  min-width: 60px;
  font-weight: bold;
  font-size: 1.1rem;
  transition: background-color 0.3s ease;
}

.scorecard-table .score-cell:hover {
  background-color: var(--highlight);
}

.scorecard-table .score-cell.filled {
  background-color: #e8f5e9;
  cursor: pointer;
}

.scorecard-table .score-cell.filled:hover {
  background-color: #c8e6c9;
  box-shadow: inset 0 0 0 2px var(--yahtzee-red);
}

.scorecard-table .score-cell.zero {
  background-color: #ffebee;
  color: var(--error);
}

.scorecard-table .total-cell {
  background-color: #f5f5f5;
  font-weight: bold;
  font-size: 1.2rem;
  color: var(--yahtzee-red);
}

.scorecard-table .bonus-cell {
  background-color: var(--highlight);
  font-weight: bold;
}

.scorecard-table .grand-total-cell {
  background-color: var(--yahtzee-red);
  color: white;
  font-weight: bold;
  font-size: 1.3rem;
}

/* Leaderboard */
.leaderboard {
  margin-top: 2rem;
  background: var(--card-bg);
  border: 2px solid var(--border-color);
  border-radius: 8px;
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.leaderboard h3 {
  margin-bottom: 1rem;
  color: var(--yahtzee-red);
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
}

.leaderboard-table th,
.leaderboard-table td {
  padding: 0.75rem;
  border-bottom: 1px solid var(--border-light);
  text-align: left;
}

.leaderboard-table th {
  background-color: var(--yahtzee-red);
  color: white;
  font-weight: bold;
}

.leaderboard-table tr:hover {
  background-color: var(--background);
}

.leaderboard-table .rank-1 {
  background-color: #ffd700;
  font-weight: bold;
}

.leaderboard-table .rank-2 {
  background-color: #c0c0c0;
}

.leaderboard-table .rank-3 {
  background-color: #cd7f32;
}

/* Game Actions */
.game-actions {
  margin-top: 2rem;
  padding: 1.5rem;
  text-align: center;
}

.game-actions button {
  width: 100%;
  max-width: 300px;
}

/* Active Games List */
.active-games-card {
  grid-column: 1 / -1;
}

.active-games-list {
  max-height: 400px;
  overflow-y: auto;
  text-align: left;
}

.active-game-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  margin-bottom: 0.75rem;
  background: var(--background);
  border: 2px solid var(--border-light);
  border-radius: 6px;
  transition: all 0.2s ease;
}

.active-game-item .game-info {
  flex: 1;
  cursor: pointer;
}

.active-game-item .game-info:hover {
  color: var(--yahtzee-red);
}

.active-game-item:hover {
  border-color: var(--yahtzee-red);
  background: white;
  box-shadow: var(--shadow);
}

.active-game-item .game-code {
  font-size: 1.3rem;
  font-weight: bold;
  color: var(--yahtzee-red);
  letter-spacing: 2px;
  margin-bottom: 0.5rem;
}

.active-game-item .game-players {
  font-size: 1rem;
  color: var(--text-dark);
  margin-bottom: 0.25rem;
}

.active-game-item .game-player-count {
  font-size: 0.85rem;
  color: var(--text-light);
}

.game-actions-inline {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.btn-small {
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
}

.btn-reset {
  background-color: #ff9800;
  color: white;
}

.btn-reset:hover {
  background-color: #f57c00;
}

.btn-delete {
  background-color: var(--error);
  color: white;
}

.btn-delete:hover {
  background-color: #d32f2f;
}

.active-games-list .loading,
.active-games-list .no-games,
.active-games-list .error {
  text-align: center;
  padding: 2rem;
  color: var(--text-light);
}

.active-games-list .error {
  color: var(--error);
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1000;
  display: flex;
  justify-content: center;
  align-items: center;
}

.modal.hidden {
  display: none;
}

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
}

.modal-content {
  position: relative;
  background-color: white;
  padding: 2rem;
  border-radius: 8px;
  max-width: 90%;
  max-height: 90%;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  z-index: 1001;
}

/* Joker Rule Categories */
.joker-rule-categories {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.btn-joker-category {
  padding: 0.75rem 1rem;
  background-color: #fff;
  border: 2px solid var(--yahtzee-red);
  color: var(--yahtzee-red);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  transition: all 0.2s;
  text-align: center;
}

.btn-joker-category:hover {
  background-color: var(--yahtzee-red);
  color: white;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(204, 41, 54, 0.3);
}

.btn-joker-zero {
  background-color: #fff;
  border-color: #6c757d;
  color: #6c757d;
}

.btn-joker-zero:hover {
  background-color: #6c757d;
  border-color: #6c757d;
  color: white;
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  font-size: 2rem;
  cursor: pointer;
  color: var(--text-light);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.3s ease;
}

.modal-close:hover {
  background-color: var(--background);
  color: var(--text-dark);
}

/* Score Input Modal Styles */
.dice-selector {
  text-align: center;
}

.dice-selector h3 {
  margin-bottom: 1.5rem;
  color: var(--yahtzee-red);
}

.dice-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 1rem;
}

.dice-option {
  background: white;
  border: 2px solid var(--border-light);
  border-radius: 8px;
  padding: 1rem;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.dice-option:hover {
  border-color: var(--yahtzee-red);
  background-color: var(--highlight);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.dice-count {
  font-size: 2rem;
  line-height: 1;
  min-height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
}

.dice-score {
  font-weight: bold;
  color: var(--yahtzee-red);
  font-size: 0.9rem;
}

.fixed-scores {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 400px;
  margin: 0 auto;
}

.btn-score {
  padding: 1.5rem;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  font-size: 1.2rem;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
}

.btn-score-value {
  background: var(--yahtzee-red);
  color: white;
}

.btn-score-value:hover {
  background: var(--yahtzee-dark-red);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.btn-score-zero {
  background: white;
  color: var(--text-dark);
  border-color: var(--border-light);
}

.btn-score-zero:hover {
  background: var(--background);
  border-color: var(--border-color);
}

.variable-score-input {
  text-align: center;
}

.variable-score-input h3 {
  margin-bottom: 1.5rem;
  color: var(--yahtzee-red);
}

.score-input-group {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.score-input-field {
  flex: 1;
  padding: 1rem;
  font-size: 1.5rem;
  text-align: center;
  border: 2px solid var(--border-light);
  border-radius: 8px;
  font-weight: bold;
}

.score-input-field:focus {
  outline: none;
  border-color: var(--yahtzee-red);
}

.btn-score-submit {
  background: var(--yahtzee-red);
  color: white;
  padding: 1rem 2rem;
}

.btn-score-submit:hover {
  background: var(--yahtzee-dark-red);
}

.quick-scores {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}

.quick-scores small {
  color: var(--text-light);
  margin-right: 0.5rem;
}

.btn-quick-score {
  padding: 0.5rem 1rem;
  background: white;
  border: 1px solid var(--border-light);
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.3s ease;
}

.btn-quick-score:hover {
  background: var(--highlight);
  border-color: var(--yahtzee-red);
}

/* Utility Classes */
.hidden {
  display: none !important;
}

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

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }

/* Responsive */
@media (max-width: 768px) {
  .logo {
    font-size: 1.8rem;
  }

  header {
    flex-direction: column;
    gap: 0.5rem;
    padding: 1rem;
  }

  .session-info {
    align-items: center;
  }

  main {
    margin: 1rem auto;
    padding: 0 0.5rem;
  }

  .scorecard-table th,
  .scorecard-table td {
    padding: 0.5rem 0.25rem;
    font-size: 0.85rem;
  }

  .scorecard-table .category-cell {
    font-size: 0.9rem;
    padding-left: 0.5rem;
  }

  .modal-content {
    padding: 1.5rem;
    max-width: 95%;
  }
}

@media (max-width: 480px) {
  /* Allow horizontal scrolling for the table */
  .scorecard {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Make the table minimum width smaller to fit better */
  .scorecard-table {
    min-width: 400px;
  }

  /* Make category cells more compact and narrower */
  .scorecard-table .category-cell {
    font-size: 0.8rem;
    padding: 0.4rem 0.3rem;
    padding-left: 0.4rem;
    white-space: normal;
    max-width: 120px;
  }

  .scorecard-table .category-cell .die-icon {
    width: 18px;
    height: 18px;
    margin-right: 0.2rem;
  }

  /* Make first column header narrower */
  .scorecard-table thead th:first-child {
    max-width: 120px;
    font-size: 0.7rem;
    padding: 0.5rem 0.3rem;
  }

  /* Adjust score cell sizing - keep at reasonable width */
  .scorecard-table .score-cell {
    min-width: 45px;
    max-width: 60px;
    font-size: 1rem;
    padding: 0.4rem 0.2rem;
  }

  /* Adjust "How to Score" column for mobile - allow wrapping and make narrower */
  .scorecard-table .how-to-score {
    font-size: 0.7rem;
    padding: 0.4rem 0.3rem;
    white-space: normal;
    max-width: 100px;
    line-height: 1.2;
  }

  /* Make second column header narrower and allow wrapping */
  .scorecard-table thead th:nth-child(2) {
    max-width: 100px;
    white-space: normal;
    font-size: 0.7rem;
    padding: 0.5rem 0.3rem;
    line-height: 1.2;
  }

  /* Third column header */
  .scorecard-table thead th:nth-child(3) {
    font-size: 0.75rem;
    padding: 0.5rem 0.3rem;
  }

  .player-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
  }

  /* Reduce table padding overall */
  .scorecard-table th,
  .scorecard-table td {
    padding: 0.4rem 0.25rem;
    font-size: 0.8rem;
  }

  /* Adjust total/bonus cells */
  .scorecard-table .total-cell,
  .scorecard-table .bonus-cell {
    font-size: 0.95rem;
  }

  .scorecard-table .grand-total-cell {
    font-size: 1.05rem;
  }

  /* Section headers */
  .scorecard-table .section-header {
    font-size: 0.85rem;
    padding: 0.5rem 0.5rem;
  }
}

/* QR Code Section */
.qr-code-section {
  margin-top: 2rem;
  padding: 1.5rem;
  background: white;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
}

.qr-code-section h3 {
  margin-bottom: 1rem;
  color: var(--yahtzee-red);
}

#qr-code {
  display: flex;
  justify-content: center;
  margin: 1rem 0;
}

#join-url {
  font-size: 0.85rem;
  color: var(--text-light);
  word-break: break-all;
  margin-top: 1rem;
}
