:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #273449;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --good: #34d399;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 1.5rem;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 900px;
  margin: 0 auto 1.5rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

h1 {
  font-size: 1.5rem;
  margin: 0;
}

h2 {
  font-size: 1.05rem;
  margin: 0 0 1rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.status {
  font-size: 0.85rem;
  color: var(--muted);
}

.hidden {
  display: none !important;
}

.card {
  background: var(--panel);
  border-radius: 12px;
  padding: 1.5rem;
  max-width: 420px;
  margin: 3rem auto;
}

#join-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.role-choice {
  border: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.role-choice label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
  color: var(--text);
  cursor: pointer;
}

.role-choice input[type="radio"] {
  flex: none;
  width: auto;
}

input {
  flex: 1;
  padding: 0.7rem 0.9rem;
  border-radius: 8px;
  border: 1px solid var(--panel-2);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

input:focus {
  outline: 2px solid var(--accent);
}

button {
  padding: 0.7rem 1.1rem;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

button:hover {
  background: var(--accent-hover);
}

main {
  max-width: 900px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 1.5rem;
}

@media (max-width: 720px) {
  main {
    grid-template-columns: 1fr;
  }
}

.cards-section,
.participants-section {
  background: var(--panel);
  border-radius: 12px;
  padding: 1.5rem;
}

.cards {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.poker-card {
  width: 64px;
  height: 92px;
  border-radius: 10px;
  border: 2px solid var(--panel-2);
  background: var(--panel-2);
  color: var(--text);
  font-size: 1.4rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.12s, background 0.12s;
}

.poker-card:hover {
  transform: translateY(-4px);
  border-color: var(--accent);
}

.poker-card.selected {
  background: var(--accent);
  border-color: var(--accent-hover);
  transform: translateY(-6px);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.45);
  position: relative;
}

/* A check mark on the voter's own chosen card. */
.poker-card.selected::after {
  content: "✓";
  position: absolute;
  top: -8px;
  right: -8px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--good);
  color: #052e1c;
  font-size: 0.75rem;
  line-height: 20px;
  text-align: center;
  font-weight: 700;
}

.poker-card:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  transform: none;
}

/* Keep the voter's own pick prominent even after votes are revealed. */
.poker-card.selected:disabled {
  opacity: 1;
  transform: translateY(-6px);
}

.observer-note {
  color: var(--muted);
  margin: 0;
  font-size: 0.95rem;
}

.reveal-banner {
  margin: 1.25rem 0 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--good);
}

.participants-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.participants-header h2 {
  margin-bottom: 0;
}

.controls {
  display: flex;
  gap: 0.5rem;
}

#reset-btn {
  background: var(--panel-2);
  font-size: 0.8rem;
  padding: 0.45rem 0.8rem;
}

#reset-btn:hover {
  background: #334155;
}

#reveal-btn {
  font-size: 0.8rem;
  padding: 0.45rem 0.8rem;
}

/* Pulse the reveal button once everyone has voted. */
#reveal-btn.ready {
  background: var(--good);
  color: #052e1c;
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.5); }
  50% { box-shadow: 0 0 0 6px rgba(52, 211, 153, 0); }
}

.participants {
  list-style: none;
  padding: 0;
  margin: 1rem 0 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.participant {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.8rem;
  background: var(--bg);
  border-radius: 8px;
}

.participant .name {
  font-weight: 500;
}

.participant.me .name::after {
  content: " (you)";
  color: var(--muted);
  font-weight: 400;
}

.badge {
  min-width: 2rem;
  text-align: center;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  font-weight: 700;
  font-size: 0.9rem;
}

.badge.waiting {
  background: var(--panel-2);
  color: var(--muted);
  font-weight: 400;
}

.badge.voted {
  background: var(--good);
  color: #052e1c;
}

.badge.value {
  background: var(--accent);
  color: white;
}

.badge.observer {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--panel-2);
  font-weight: 400;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.result {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--panel-2);
  font-size: 0.95rem;
  color: var(--muted);
}

.result strong {
  color: var(--text);
  font-size: 1.2rem;
}

/* ---------------------------------------------------------------------------
   Reveal sequence: a 3-2-1 countdown, then the digit detonates.
   The overlay never takes pointer events — it only ever draws.
   --------------------------------------------------------------------------- */
.reveal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  pointer-events: none;
  overflow: hidden;
}

.reveal-overlay > * {
  grid-area: 1 / 1;
  place-self: center;
}

.reveal-overlay.counting {
  background: radial-gradient(
    circle at center,
    rgba(15, 23, 42, 0.85),
    rgba(15, 23, 42, 0.6) 55%,
    rgba(15, 23, 42, 0) 80%
  );
}

.countdown-stack {
  display: grid;
  place-items: center;
}

.countdown-stack > * {
  grid-area: 1 / 1;
}

.countdown-number {
  font-size: clamp(7rem, 26vw, 18rem);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.05em;
  background: linear-gradient(180deg, #ffffff 0%, var(--accent-hover) 55%, var(--accent) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 32px rgba(99, 102, 241, 0.7));
}

/* Re-added on every tick to restart the animation. */
.countdown-number.tick {
  animation: count-pop 1s cubic-bezier(0.16, 0.84, 0.3, 1) both;
}

@keyframes count-pop {
  0% {
    transform: scale(2.6) rotate(-10deg);
    opacity: 0;
  }
  16% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: scale(0.86);
    opacity: 0.75;
  }
}

.countdown-ring {
  width: clamp(9rem, 32vw, 22rem);
  height: clamp(9rem, 32vw, 22rem);
  border-radius: 50%;
  border: 3px solid rgba(129, 140, 248, 0.55);
  opacity: 0;
}

.countdown-ring.tick {
  animation: ring-pulse 1s ease-out both;
}

@keyframes ring-pulse {
  0% {
    transform: scale(0.35);
    opacity: 0;
  }
  20% {
    opacity: 0.9;
  }
  100% {
    transform: scale(1.25);
    opacity: 0;
  }
}

/* The blast: white flash, expanding shockwave, and the digit tearing apart. */
.reveal-overlay.exploding::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(
    circle at center,
    rgba(255, 255, 255, 0.9),
    rgba(129, 140, 248, 0.4) 28%,
    rgba(15, 23, 42, 0) 62%
  );
  animation: flash 0.6s ease-out forwards;
}

.reveal-overlay.exploding::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 48px;
  height: 48px;
  margin: -24px 0 0 -24px;
  border-radius: 50%;
  border: 6px solid rgba(255, 255, 255, 0.85);
  animation: shockwave 0.85s cubic-bezier(0.15, 0.7, 0.25, 1) forwards;
}

.reveal-overlay.exploding .countdown-number {
  animation: digit-blast 0.45s ease-out forwards;
}

.reveal-overlay.exploding .countdown-ring {
  animation: shockwave 0.7s cubic-bezier(0.15, 0.7, 0.25, 1) 0.08s forwards;
  border-color: rgba(52, 211, 153, 0.7);
  opacity: 1;
}

@keyframes flash {
  0% { opacity: 0; }
  12% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes shockwave {
  0% {
    transform: scale(0.2);
    opacity: 1;
    border-width: 8px;
  }
  100% {
    transform: scale(14);
    opacity: 0;
    border-width: 1px;
  }
}

@keyframes digit-blast {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  100% {
    transform: scale(3.6);
    opacity: 0;
  }
}

/* Debris. Each particle carries its own vector/size/timing as custom props. */
.burst {
  position: absolute;
  inset: 0;
}

.particle {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--size);
  height: var(--size);
  margin-left: calc(var(--size) / -2);
  margin-top: calc(var(--size) / -2);
  border-radius: 50%;
  will-change: transform, opacity;
  animation: particle-fly var(--dur) cubic-bezier(0.12, 0.7, 0.3, 1) var(--delay) both;
}

.particle.streak {
  width: calc(var(--size) * 8);
  height: calc(var(--size) / 1.5);
  margin-left: calc(var(--size) * -4);
  border-radius: 999px;
  animation-name: streak-fly;
}

@keyframes particle-fly {
  0% {
    transform: translate(0, 0) scale(0.4);
    opacity: 1;
  }
  14% {
    transform: translate(calc(var(--dx) * 0.28), calc(var(--dy) * 0.28)) scale(1);
    opacity: 1;
  }
  100% {
    /* Falling debris — the extra Y gives it a bit of gravity. */
    transform: translate(var(--dx), calc(var(--dy) + 110px)) scale(0.2);
    opacity: 0;
  }
}

@keyframes streak-fly {
  0% {
    transform: rotate(var(--rot)) translateX(0) scaleX(0.3);
    opacity: 1;
  }
  100% {
    transform: rotate(var(--rot)) translateX(var(--dist)) scaleX(1.8);
    opacity: 0;
  }
}

/* The room takes the hit too. */
.blast-shake {
  animation: blast-shake 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

@keyframes blast-shake {
  0%, 100% { transform: translate(0, 0); }
  10% { transform: translate(-9px, 5px); }
  22% { transform: translate(8px, -6px); }
  36% { transform: translate(-6px, -4px); }
  50% { transform: translate(5px, 4px); }
  66% { transform: translate(-3px, 2px); }
  82% { transform: translate(2px, -1px); }
}

/* Vote badges land one after another as the debris settles. */
.badge.value.pop {
  animation: badge-pop 0.5s cubic-bezier(0.2, 1.5, 0.4, 1) both;
  animation-delay: calc(240ms + var(--i) * 70ms);
}

@keyframes badge-pop {
  0% {
    transform: scale(0) rotate(-25deg);
    opacity: 0;
  }
  60% {
    transform: scale(1.35) rotate(6deg);
    opacity: 1;
  }
  100% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
}

.result.pop {
  animation: result-rise 0.55s cubic-bezier(0.2, 1.2, 0.4, 1) 0.45s both;
}

@keyframes result-rise {
  0% {
    transform: translateY(14px);
    opacity: 0;
  }
  100% {
    transform: translateY(0);
    opacity: 1;
  }
}

/* Keep the information, drop the fireworks. */
@media (prefers-reduced-motion: reduce) {
  .countdown-number.tick,
  .countdown-ring.tick,
  .reveal-overlay.exploding::before,
  .reveal-overlay.exploding::after,
  .reveal-overlay.exploding .countdown-number,
  .reveal-overlay.exploding .countdown-ring,
  .blast-shake,
  .badge.value.pop,
  .result.pop {
    animation: none;
  }

  .countdown-ring {
    opacity: 0.5;
  }
}
