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

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: linear-gradient(135deg, #1a472a 0%, #2d5a3d 50%, #1a472a 100%);
  min-height: 100vh;
  padding: 1.5rem;
  color: #f0f0f0;
}

/* Full-screen coin toss */
.toss-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  visibility: visible;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.toss-overlay[hidden] {
  display: none !important;
  visibility: hidden;
  pointer-events: none;
}

.toss-overlay-bg {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  backdrop-filter: blur(8px);
}

.toss-coin-scene {
  position: relative;
  z-index: 1;
  perspective: 1000px;
  width: min(78vmin, 340px);
  height: min(78vmin, 340px);
}

.toss-coin {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  border-radius: 50%;
}

.toss-coin-face {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  backface-visibility: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1rem, 4.5vmin, 1.5rem);
  font-weight: 700;
  text-align: center;
  padding: 1rem;
  box-shadow: inset 0 0 0 3px rgba(0, 0, 0, 0.2);
}

.toss-coin-front {
  background: linear-gradient(145deg, #d4af37 0%, #f4e4a6 50%, #c9a227 100%);
  color: #2a2000;
  transform: translateZ(10px);
}

.toss-coin-back {
  background: linear-gradient(145deg, #8b7355 0%, #c4a574 50%, #6b5344 100%);
  color: #fff;
  transform: rotateX(180deg) translateZ(10px);
}

.toss-overlay-result {
  position: relative;
  z-index: 1;
  margin-top: 2rem;
  font-size: clamp(1.1rem, 4vmin, 1.4rem);
  font-weight: 700;
  color: #f0c14b;
  text-align: center;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.toss-overlay-result.visible {
  opacity: 1;
}

.toss-overlay.toss-done .toss-overlay-result {
  opacity: 1;
}

.toss-continue-btn {
  position: relative;
  z-index: 1;
  margin-top: 1rem;
}

.toss-continue-btn[hidden] {
  display: none !important;
}

@keyframes toss-flip-team1 {
  to {
    transform: rotateX(1800deg);
  }
}

@keyframes toss-flip-team2 {
  to {
    transform: rotateX(1980deg);
  }
}

.toss-coin.toss-animate-1 {
  animation: toss-flip-team1 2.6s ease-out forwards;
  -webkit-animation: toss-flip-team1 2.6s ease-out forwards;
}

.toss-coin.toss-animate-2 {
  animation: toss-flip-team2 2.6s ease-out forwards;
  -webkit-animation: toss-flip-team2 2.6s ease-out forwards;
}

.screen {
  max-width: 560px;
  margin: 0 auto;
}

.screen.scoreboard-screen .scoreboard {
  margin: 0 auto;
}

.setup-card {
  margin: 0 auto;
}

.setup-form {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.setup-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.setup-field label {
  font-size: 0.85rem;
  font-weight: 600;
  opacity: 0.95;
}

.setup-field input {
  padding: 0.6rem 0.75rem;
  font-size: 1rem;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  color: #fff;
}

.setup-field input:focus {
  outline: none;
  border-color: #f0c14b;
}

.setup-field input::placeholder {
  color: rgba(255, 255, 255, 0.4);
}

.setup-hint {
  font-size: 0.75rem;
  opacity: 0.7;
  margin-top: 0.15rem;
}

.toss-section {
  padding: 1rem 0;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}

.toss-desc {
  font-size: 0.9rem;
  opacity: 0.85;
  margin-bottom: 0.5rem;
}

.toss-btn {
  align-self: flex-start;
  margin-bottom: 0.75rem;
}

.toss-result {
  font-size: 1rem;
  font-weight: 600;
  color: #f0c14b;
  min-height: 1.5rem;
}

.extras-rules {
  margin-top: 0.25rem;
}

.extras-rules-grid {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.extras-rule-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.extras-rule-name {
  min-width: 4.5rem;
  font-size: 0.9rem;
}

.extras-rules input.extras-runs {
  width: 3rem;
  padding: 0.35rem 0.4rem;
  text-align: center;
}

.extras-ball-label {
  font-size: 0.85rem;
  font-weight: normal;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
}

.setup-checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  cursor: pointer;
}

.setup-checkbox-label input {
  width: auto;
}

.bat-first-choice {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.bat-first-choice[hidden],
.toss-choose-bat[hidden] {
  display: none !important;
}

.bat-first-buttons,
.toss-choose-buttons {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.bat-first-btn,
.toss-choose-btn {
  flex: 1;
  min-width: 120px;
}

.toss-choose-bat {
  position: relative;
  z-index: 1;
  margin-top: 1rem;
  text-align: center;
}

.toss-choose-label {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}

.start-btn {
  margin-top: 0.5rem;
  padding: 0.75rem 1.5rem;
  font-size: 1.05rem;
}

.start-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.new-match-btn {
  margin-top: 0.5rem;
  min-width: 0;
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
}

.match-info {
  font-size: 0.9rem;
  opacity: 0.95;
  margin-top: 0.35rem;
  margin-bottom: 0.25rem;
}

.target-runrate-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.target-display,
.runrate-display {
  font-size: 1rem;
  font-weight: 600;
  color: #f0c14b;
}

.target-display:empty,
.runrate-display:empty {
  display: none;
}

.runrate-line {
  font-size: 0.9rem;
  opacity: 0.9;
}

.team-name-display {
  display: block;
  font-size: 1rem;
  margin-bottom: 0.5rem;
  font-weight: 600;
}

.scoreboard {
  max-width: 560px;
  margin: 0 auto;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 16px;
  padding: 1.5rem;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

header {
  text-align: center;
  margin-bottom: 1.5rem;
}

header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.subtitle {
  font-size: 0.85rem;
  opacity: 0.85;
  margin-top: 0.25rem;
}

.overs-setting {
  margin-top: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.overs-setting label {
  font-size: 0.85rem;
  opacity: 0.9;
}

.overs-setting input {
  width: 4rem;
  padding: 0.35rem 0.5rem;
  font-size: 1rem;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  color: #fff;
  text-align: center;
}

.overs-setting input:focus {
  outline: none;
  border-color: #f0c14b;
}

.overs-setting input::placeholder {
  color: rgba(255, 255, 255, 0.4);
}

.overs-setting-hint {
  font-size: 0.75rem;
  opacity: 0.7;
}

.teams-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.team-card {
  flex: 1;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 1rem;
  border: 2px solid transparent;
  transition: border-color 0.2s, background 0.2s;
}

.team-card.batting {
  border-color: #f0c14b;
  background: rgba(240, 193, 75, 0.12);
}

.team-card label {
  display: block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.9;
  margin-bottom: 0.35rem;
}

.team-card .team-name-display {
  margin-bottom: 0.5rem;
}

.score-display {
  font-size: 1.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.score-display .separator {
  opacity: 0.7;
  margin: 0 0.1rem;
}

.overs {
  font-size: 0.9rem;
  font-weight: 600;
  opacity: 0.9;
  margin-left: 0.35rem;
}

.vs {
  font-size: 1rem;
  font-weight: 700;
  opacity: 0.7;
}

.controls {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 12px;
  padding: 1.25rem;
}

.controls.innings-complete .runs-section,
.controls.innings-complete .extras-section,
.controls.innings-complete .wicket-section,
.controls.match-over .runs-section,
.controls.match-over .extras-section,
.controls.match-over .wicket-section {
  pointer-events: none;
  opacity: 0.6;
}

.controls.match-over .action-btn.switch {
  display: none;
}

.batting-label {
  margin-bottom: 1rem;
  font-size: 0.95rem;
}

.batting-label strong {
  color: #f0c14b;
}

.controls h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.85;
  margin-bottom: 0.5rem;
}

.runs-section,
.extras-section,
.wicket-section {
  margin-bottom: 1rem;
}

.runs-buttons,
.extras-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.run-btn,
.extra-btn,
.wicket-btn {
  padding: 0.6rem 1rem;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, background 0.2s;
}

.run-btn:active,
.extra-btn:active,
.wicket-btn:active {
  transform: scale(0.97);
}

.run-btn {
  background: #2d5a3d;
  color: #fff;
  min-width: 2.5rem;
}

.run-btn:hover {
  background: #3d7a4d;
}

.run-btn.run-dot {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 0.9rem;
}

.run-btn.run-dot:hover {
  background: rgba(255, 255, 255, 0.3);
}

.run-btn[data-runs="4"] {
  background: #c9a227;
  color: #1a1a1a;
}

.run-btn[data-runs="6"] {
  background: #e8b923;
  color: #1a1a1a;
}

.extra-btn {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 0.85rem;
}

.extra-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

.wicket-btn {
  background: #8b2635;
  color: #fff;
}

.wicket-btn:hover {
  background: #a62d3f;
}

.actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.25rem;
  flex-wrap: wrap;
}

.action-btn {
  flex: 1;
  min-width: 140px;
  padding: 0.6rem 1rem;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.action-btn.switch {
  background: #f0c14b;
  color: #1a1a1a;
}

.action-btn.switch:hover {
  background: #e5b63a;
}

.action-btn.reset {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

.action-btn.reset:hover {
  background: rgba(255, 255, 255, 0.3);
}

.action-btn.undo-btn {
  background: rgba(255, 180, 80, 0.35);
  color: #fff;
}

.action-btn.undo-btn:hover:not(:disabled) {
  background: rgba(255, 180, 80, 0.5);
}

.action-btn.undo-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.last-ball {
  margin-top: 1rem;
  text-align: center;
  font-size: 0.9rem;
  min-height: 1.5rem;
  opacity: 0.9;
}

.controls.innings-complete + .last-ball {
  color: #f0c14b;
  font-weight: 600;
}

.last-ball.innings-over-notification {
  color: #f0c14b;
  font-weight: 700;
  font-size: 1rem;
  padding: 0.5rem;
  background: rgba(240, 193, 75, 0.15);
  border-radius: 8px;
  border: 1px solid rgba(240, 193, 75, 0.4);
}

.history-section {
  margin-top: 1.5rem;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 12px;
  padding: 1rem;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.history-header h2 {
  font-size: 1rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.95;
}

.history-header .clear-history {
  flex: 0 0 auto;
  min-width: 0;
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
}

.history-list {
  max-height: 220px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.history-empty {
  font-size: 0.9rem;
  opacity: 0.7;
  padding: 0.5rem 0;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.4rem 0.6rem;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 6px;
  font-size: 0.85rem;
}

.history-item .history-over {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  min-width: 2.2rem;
  opacity: 0.9;
}

.history-item .history-desc {
  flex: 1;
}

.history-item .history-team {
  font-size: 0.75rem;
  opacity: 0.75;
}

.history-item.history-boundary .history-desc {
  color: #f0c14b;
  font-weight: 600;
}

.history-item.history-wicket .history-desc {
  color: #e88a8a;
  font-weight: 600;
}

.history-item.history-extra .history-desc {
  opacity: 0.9;
}

.history-item.history-dot .history-desc {
  opacity: 0.8;
}

.history-item.history-switch {
  background: rgba(240, 193, 75, 0.15);
  font-weight: 600;
}

@media (max-width: 480px) {
  .teams-row {
    flex-direction: column;
  }

  .vs {
    margin: 0;
  }

  .runs-buttons .run-btn {
    flex: 1;
    min-width: calc(33.33% - 0.35rem);
  }
}
