:root {
  --green: #1f7a3f;
  --green-dark: #155a2e;
  --cream: #fdf6e3;
  --red: #c0392b;
  --ink: #222;
  --gold: #e3a712;

  --bat-color: #2457c5;
  --bat-color-dark: #173d8f;
  --bowl-color: #d9701e;
  --bowl-color-dark: #a8530f;

  /* role accent, swapped by JS via .theme-bat / .theme-bowl */
  --accent: var(--green);
  --accent-dark: var(--green-dark);
}

#screen-game.theme-bat {
  --accent: var(--bat-color);
  --accent-dark: var(--bat-color-dark);
}

#screen-game.theme-bowl {
  --accent: var(--bowl-color);
  --accent-dark: var(--bowl-color-dark);
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  font-family: 'Segoe UI', Roboto, Arial, sans-serif;
  background: linear-gradient(180deg, var(--green) 0%, var(--green-dark) 100%);
  color: var(--ink);
  /* Reserve space so the fixed ad banner never covers game controls. */
  padding-bottom: 76px;
}

.site-footer {
  text-align: center;
  padding: 8px 16px 4px;
}

.site-footer a {
  color: rgba(253, 246, 227, 0.75);
  font-size: 0.75rem;
  text-decoration: underline;
}

.ad-banner {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  justify-content: center;
  padding: 8px;
  background: rgba(10, 20, 15, 0.9);
  box-shadow: 0 -4px 14px rgba(0, 0, 0, 0.25);
}

.ad-banner-slot {
  width: 100%;
  max-width: 480px;
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed rgba(253, 246, 227, 0.35);
  border-radius: 8px;
  color: rgba(253, 246, 227, 0.5);
  font-size: 0.75rem;
  letter-spacing: 1px;
  text-transform: uppercase;
}

@media (min-width: 600px) {
  .ad-banner-slot {
    max-width: 560px;
  }
}

header {
  text-align: center;
  padding: 24px 0 8px;
}

header h1 {
  color: var(--cream);
  margin: 0;
  font-size: 2rem;
}

main {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px;
  width: 100%;
}

.screen {
  background: var(--cream);
  border-radius: 16px;
  padding: 28px 20px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
  text-align: center;
  width: 100%;
}

.hidden { display: none !important; }

.btn {
  font-size: 1rem;
  padding: 12px 20px;
  border-radius: 10px;
  border: none;
  background: #e0e0e0;
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.1s ease;
}

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

.btn-primary {
  background: var(--green);
  color: white;
  width: 100%;
}

.or-divider {
  margin: 16px 0;
  color: #888;
}

.home-choice {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px 0;
}

.btn-big {
  width: 100%;
  padding: 22px;
  font-size: 1.2rem;
  border-radius: 14px;
  color: white;
  background: var(--green);
}

.btn-big-alt {
  background: var(--bat-color);
}

.btn-big-quick {
  background: var(--gold);
  color: #3a2a00;
}

.stats-strip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 6px;
  font-size: 0.8rem;
  color: #777;
}

.stats-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #2fb35c;
  box-shadow: 0 0 0 0 rgba(47, 179, 92, 0.6);
  animation: statsDotPulse 2s ease infinite;
}

@keyframes statsDotPulse {
  0% { box-shadow: 0 0 0 0 rgba(47, 179, 92, 0.5); }
  70% { box-shadow: 0 0 0 6px rgba(47, 179, 92, 0); }
  100% { box-shadow: 0 0 0 0 rgba(47, 179, 92, 0); }
}

.install-btn {
  width: 100%;
  margin-top: 16px;
  background: none;
  border: 2px solid var(--green);
  color: var(--green-dark);
}

#install-hint {
  margin-top: 8px;
}

.back-btn {
  background: none;
  border: none;
  color: var(--green-dark);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0;
  margin-bottom: 10px;
}

.screen-title {
  margin: 0 0 16px;
  font-size: 1.3rem;
  color: var(--ink);
}

.field {
  text-align: left;
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: #555;
}

.field input {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid #ccc;
  font-size: 1rem;
  text-transform: uppercase;
}

.field input[readonly] {
  background: #f0ece0;
  color: #777;
  font-weight: 700;
  letter-spacing: 1px;
}

.field-hint {
  font-size: 0.75rem;
  color: #999;
  margin-top: 4px;
}

.mode-cards {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.mode-card {
  flex: 1;
  min-width: 100px;
  padding: 10px 8px;
  border-radius: 10px;
  border: 2px solid #ddd;
  background: white;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.mode-card.selected {
  border-color: var(--green);
  background: #eef7f0;
}

.mode-card-title {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--ink);
}

.mode-card-desc {
  font-size: 0.7rem;
  color: #777;
  margin-top: 3px;
}

.matchup-line {
  font-weight: 700;
  color: var(--accent-dark, var(--green-dark));
  margin-bottom: 10px;
  letter-spacing: 0.5px;
}

#form-join {
  display: flex;
  gap: 8px;
}

#input-room-code {
  flex: 1;
  min-width: 0;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid #ccc;
  font-size: 1rem;
  text-transform: uppercase;
}

.error-text {
  color: var(--red);
  min-height: 1.2em;
  margin-top: 12px;
}

.share-box {
  display: flex;
  gap: 8px;
  margin: 16px 0;
  flex-wrap: wrap;
}

#share-link {
  flex: 1;
  min-width: 0;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #ccc;
  font-size: 1rem;
}

.code-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 16px 0;
  padding: 10px 16px;
  border-radius: 10px;
  border: 2px dashed var(--green);
  background: #eef7f0;
  flex-wrap: wrap;
}

.code-value {
  font-family: 'Courier New', Consolas, monospace;
  font-weight: 800;
  font-size: 1.5rem;
  letter-spacing: 3px;
  color: var(--green-dark);
}

.spinner-text {
  color: #666;
  margin-top: 20px;
}

/* ---------- Scorecard (the big broadcast-style score display) ---------- */

.scorecard {
  background: linear-gradient(145deg, #16342a 0%, #0a1b14 100%);
  border-radius: 18px;
  padding: 18px 20px 16px;
  margin-bottom: 16px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35), inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  transition: box-shadow 0.2s ease;
}

.scorecard.pulse {
  animation: scorecardPulse 0.5s ease;
}

@keyframes scorecardPulse {
  0% { box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35), inset 0 0 0 1px rgba(255, 255, 255, 0.08); }
  40% { box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35), inset 0 0 0 2px var(--gold), 0 0 18px rgba(227, 167, 18, 0.5); }
  100% { box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35), inset 0 0 0 1px rgba(255, 255, 255, 0.08); }
}

.scorecard-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: rgba(253, 246, 227, 0.6);
}

.scorecard-batting-team {
  color: var(--gold);
}

.scorecard-main {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 2px;
  font-family: 'Courier New', Consolas, monospace;
  font-weight: 800;
  line-height: 1;
  color: #fdf6e3;
  margin: 10px 0 8px;
  font-size: 3.1rem;
  letter-spacing: 1px;
}

.scorecard-dash {
  color: rgba(253, 246, 227, 0.4);
  font-size: 0.7em;
  padding: 0 2px;
}

.scorecard-wickets {
  color: var(--gold);
}

.scorecard-bottom {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.scorecard-pill {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(253, 246, 227, 0.1);
  color: rgba(253, 246, 227, 0.85);
}

.status-line {
  min-height: 1.4em;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--green-dark);
}

.reveal-box {
  display: flex;
  justify-content: center;
  gap: 40px;
  margin: 16px 0;
  min-height: 70px;
  visibility: hidden;
}

.reveal-box.show { visibility: visible; }

.reveal-label {
  font-size: 0.8rem;
  color: #666;
}

.reveal-number {
  font-size: 2.4rem;
  font-weight: bold;
}

.number-picker {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 18px 0;
  flex-wrap: wrap;
}

.num-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: white;
  font-size: 1.3rem;
  font-weight: bold;
  color: var(--accent-dark);
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, color 0.15s ease;
}

.num-btn.selected {
  background: var(--accent);
  color: white;
  transform: scale(1.08);
}

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

.btn-action {
  width: 100%;
  background: var(--accent);
  color: white;
  font-size: 1.2rem;
  padding: 16px;
  text-transform: uppercase;
  letter-spacing: 1px;
  transition: background 0.15s ease;
}

.btn-action:disabled {
  background: #aaa;
  cursor: not-allowed;
}

#over-title {
  font-size: 1.8rem;
  margin-bottom: 6px;
}

#btn-rematch {
  width: 100%;
  margin-bottom: 10px;
}

#btn-rematch:disabled {
  background: #7fa98f;
  cursor: not-allowed;
}

.rematch-status {
  min-height: 1.2em;
  color: #666;
  font-size: 0.9rem;
  margin: 0 0 14px;
}

/* ---------- Role badge ---------- */

.role-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 18px;
  border-radius: 999px;
  background: var(--accent);
  color: white;
  font-weight: 700;
  letter-spacing: 0.5px;
  font-size: 0.95rem;
  margin-bottom: 14px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
  animation: badgePop 0.4s ease;
}

.role-badge-icon {
  font-size: 1.2rem;
}

@keyframes badgePop {
  0% { transform: scale(0.6); opacity: 0; }
  60% { transform: scale(1.12); opacity: 1; }
  100% { transform: scale(1); }
}

/* ---------- Result banner ---------- */

.result-banner {
  min-height: 0;
  max-height: 0;
  overflow: hidden;
  border-radius: 12px;
  font-weight: 800;
  font-size: 1.3rem;
  margin: 0;
  opacity: 0;
  transform: scale(0.85);
  transition: opacity 0.15s ease;
}

.result-banner.show {
  min-height: 52px;
  max-height: 100px;
  margin: 14px 0;
  padding: 12px;
  opacity: 1;
  animation: bannerPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.result-banner.good {
  background: #fff4d6;
  color: #8a5a00;
  border: 2px solid var(--gold);
}

.result-banner.bad {
  background: #fbe2df;
  color: var(--red);
  border: 2px solid var(--red);
}

@keyframes bannerPop {
  0% { transform: scale(0.5); opacity: 0; }
  60% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); }
}

.shake {
  animation: shake 0.5s ease;
}

@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-6px); }
  40%, 60% { transform: translateX(6px); }
}

.celebrate {
  animation: celebrate 0.6s ease;
}

@keyframes celebrate {
  0% { transform: scale(1); }
  30% { transform: scale(1.03) rotate(-1deg); }
  60% { transform: scale(1.03) rotate(1deg); }
  100% { transform: scale(1); }
}

/* ---------- Mobile responsiveness ---------- */

@media (max-width: 480px) {
  main {
    padding: 10px;
  }

  header {
    padding: 16px 0 6px;
  }

  header h1 {
    font-size: 1.5rem;
  }

  .screen {
    padding: 20px 14px;
    border-radius: 12px;
  }

  .number-picker {
    gap: 6px;
    margin: 14px 0;
  }

  .num-btn {
    width: 50px;
    height: 50px;
    font-size: 1.15rem;
  }

  .reveal-box {
    gap: 20px;
  }

  .reveal-number {
    font-size: 2rem;
  }

  .result-banner {
    font-size: 1.1rem;
  }

  .role-badge {
    padding: 7px 14px;
    font-size: 0.85rem;
  }

  .matchup-line {
    font-size: 0.9rem;
  }

  .scorecard {
    padding: 14px 14px 12px;
    border-radius: 14px;
  }

  .scorecard-main {
    font-size: 2.3rem;
    margin: 6px 0;
  }

  .scorecard-top {
    font-size: 0.68rem;
  }

  .scorecard-pill {
    font-size: 0.62rem;
    padding: 3px 8px;
  }

  .btn-action {
    font-size: 1.05rem;
    padding: 14px;
  }

  .mode-card-desc {
    display: none;
  }
}

@media (max-width: 340px) {
  .num-btn {
    width: 44px;
    height: 44px;
    font-size: 1rem;
  }

  .number-picker {
    gap: 5px;
  }

  .scorecard-main {
    font-size: 1.9rem;
  }
}

/* ---------- Roomier layout on larger screens ---------- */

@media (min-width: 600px) {
  main {
    max-width: 560px;
  }

  header h1 {
    font-size: 2.3rem;
  }

  .screen {
    padding: 34px 32px;
    border-radius: 20px;
  }

  .scorecard {
    padding: 24px 28px 20px;
  }

  .scorecard-main {
    font-size: 4rem;
  }

  .scorecard-top {
    font-size: 0.85rem;
  }

  .scorecard-pill {
    font-size: 0.78rem;
    padding: 5px 12px;
  }

  .num-btn {
    width: 64px;
    height: 64px;
    font-size: 1.5rem;
  }

  .number-picker {
    gap: 14px;
  }
}
