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

:root {
  --bg: #12081f;
  --panel: #1a0f2e;
  --cream: #f5f0e6;
  --gold: #fbbf24;
  --purple: #7c3aed;
  --win: #4ade80;
  --ink: #0f172a;
}

html,
body {
  height: 100%;
  background: var(--bg);
  color: var(--cream);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background:
    radial-gradient(ellipse 70% 45% at 50% 0%, rgba(124, 58, 237, 0.28), transparent 55%),
    radial-gradient(ellipse 50% 40% at 90% 80%, rgba(251, 191, 36, 0.08), transparent 50%),
    var(--bg);
}

#hud {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: max(0.55rem, env(safe-area-inset-top)) 0.9rem 0.35rem;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.hud-left {
  display: flex;
  gap: 0.85rem 1.2rem;
  flex-wrap: wrap;
}

.hud-block {
  display: flex;
  flex-direction: column;
  min-width: 3.5rem;
}

.label {
  font-size: 0.6rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0.5;
}

.hud-block span:last-child {
  font-size: 1.05rem;
  font-weight: 750;
}

.icon-btn {
  width: 2.4rem;
  height: 2.4rem;
  display: grid;
  place-items: center;
  border-radius: 0.5rem;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(0, 0, 0, 0.25);
  color: inherit;
  text-decoration: none;
}

.play-area {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0.25rem 0.75rem;
}

/* ── Caller stage ─────────────────────────────────── */
.caller-stage {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.35rem 0 0.5rem;
}

.caller-row {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: clamp(0.75rem, 3vw, 2rem);
  width: 100%;
  flex-wrap: wrap;
}

.caller-sq-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
}

.caller-sq {
  width: 3.6rem;
  height: 3.6rem;
  border-radius: 0.55rem;
  background: linear-gradient(160deg, #c4b5fd, #7c3aed 55%, #5b21b6);
  border: 2px solid rgba(255, 255, 255, 0.8);
  box-shadow: 0 0 18px rgba(167, 139, 250, 0.5);
  display: grid;
  place-items: center;
  will-change: transform;
  transition: filter 0.2s ease;
}

.caller-label,
.basket-label,
.current-label {
  margin-top: 0.3rem;
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  opacity: 0.45;
  font-weight: 650;
}

/* Face */
.sq-face {
  position: relative;
  width: 1.8rem;
  height: 1.25rem;
}

.sq-face .brow {
  position: absolute;
  top: -0.06rem;
  width: 0.48rem;
  height: 0.12rem;
  background: #0f172a;
  border-radius: 2px;
  transition: transform 0.15s ease, top 0.15s ease;
}

.sq-face .brow.left {
  left: 0.12rem;
}
.sq-face .brow.right {
  right: 0.12rem;
}

.sq-face .eye {
  position: absolute;
  top: 0.16rem;
  width: 0.34rem;
  height: 0.34rem;
  background: #0f172a;
  border-radius: 50%;
  transition: width 0.15s ease, height 0.15s ease, top 0.15s ease, border-radius 0.15s ease;
}

.sq-face .eye.left {
  left: 0.14rem;
}
.sq-face .eye.right {
  right: 0.14rem;
}

.sq-face .eye::after {
  content: "";
  position: absolute;
  top: 0.05rem;
  right: 0.05rem;
  width: 0.1rem;
  height: 0.1rem;
  background: rgba(255, 255, 255, 0.55);
  border-radius: 50%;
}

.sq-face .mouth {
  position: absolute;
  left: 50%;
  bottom: 0.02rem;
  width: 0.72rem;
  height: 0.3rem;
  border-bottom: 2.5px solid #0f172a;
  border-radius: 0 0 50% 50%;
  transform: translateX(-50%);
  transition: width 0.15s ease, height 0.15s ease, border 0.15s ease, bottom 0.15s ease;
}

.sq-face .cheek {
  position: absolute;
  bottom: 0.28rem;
  width: 0.28rem;
  height: 0.18rem;
  border-radius: 50%;
  background: rgba(244, 114, 182, 0.55);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.sq-face .cheek.left {
  left: -0.05rem;
}
.sq-face .cheek.right {
  right: -0.05rem;
}

/* Moods */
.caller-sq[data-mood="call"] .brow.left,
.caller-sq[data-mood="call"] .brow.right {
  top: -0.14rem;
}
.caller-sq[data-mood="call"] .eye {
  width: 0.4rem;
  height: 0.4rem;
  top: 0.1rem;
}
.caller-sq[data-mood="call"] .mouth {
  width: 0.45rem;
  height: 0.4rem;
  border: 2.5px solid #0f172a;
  border-radius: 50%;
  bottom: 0;
}

.caller-sq[data-mood="hit"] .mouth {
  width: 0.95rem;
  height: 0.35rem;
}
.caller-sq[data-mood="hit"] .cheek {
  opacity: 0.85;
}

.caller-sq[data-mood="miss"] .eye {
  height: 0.14rem;
  border-radius: 2px;
  top: 0.28rem;
}
.caller-sq[data-mood="miss"] .eye::after {
  display: none;
}
.caller-sq[data-mood="miss"] .mouth {
  width: 0.45rem;
  height: 0;
  border-radius: 0;
  bottom: 0.16rem;
}

.caller-sq[data-mood="bingo"] .brow.left,
.caller-sq[data-mood="bingo"] .brow.right {
  top: -0.18rem;
}
.caller-sq[data-mood="bingo"] .eye {
  height: 0.12rem;
  border-radius: 2px;
  top: 0.28rem;
}
.caller-sq[data-mood="bingo"] .eye::after {
  display: none;
}
.caller-sq[data-mood="bingo"] .mouth {
  width: 1.05rem;
  height: 0.45rem;
  border-bottom: 3px solid #0f172a;
  bottom: -0.05rem;
}
.caller-sq[data-mood="bingo"] .cheek {
  opacity: 0.9;
}

.caller-sq.react-pull {
  animation: sq-pull 0.55s cubic-bezier(0.22, 1, 0.36, 1);
}

.caller-sq.react-dance {
  animation: sq-dance 0.55s ease-in-out infinite;
}

@keyframes sq-pull {
  0% {
    transform: scale(1) rotate(0);
  }
  35% {
    transform: scale(1.12) rotate(-12deg) translateY(-4px);
  }
  70% {
    transform: scale(1.08) rotate(10deg) translateY(-2px);
  }
  100% {
    transform: scale(1) rotate(0);
  }
}

@keyframes sq-dance {
  0%,
  100% {
    transform: translateX(0) rotate(0) scale(1.05);
  }
  25% {
    transform: translateX(-10px) rotate(-12deg) scale(1.1);
  }
  50% {
    transform: translateX(0) rotate(0) scale(1.08);
  }
  75% {
    transform: translateX(10px) rotate(12deg) scale(1.1);
  }
}

/* Basket */
.basket-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
}

.basket {
  position: relative;
  width: 7.5rem;
  height: 5.2rem;
}

.basket-bowl {
  position: absolute;
  left: 50%;
  bottom: 0.35rem;
  transform: translateX(-50%);
  width: 6.4rem;
  height: 3.6rem;
  border-radius: 0 0 50% 50% / 0 0 70% 70%;
  background: linear-gradient(180deg, #4c1d95 0%, #2e1065 55%, #1e1b4b 100%);
  border: 3px solid #c4b5fd;
  box-shadow:
    inset 0 -8px 16px rgba(0, 0, 0, 0.35),
    0 6px 16px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

.basket.spinning .basket-bowl {
  animation: bowl-shake 0.35s ease-in-out infinite;
}

.basket.spinning .basket-balls {
  animation: balls-tumble 0.4s linear infinite;
}

@keyframes bowl-shake {
  0%,
  100% {
    transform: translateX(-50%) rotate(-3deg);
  }
  50% {
    transform: translateX(-50%) rotate(3deg);
  }
}

@keyframes balls-tumble {
  from {
    transform: rotate(0);
  }
  to {
    transform: rotate(360deg);
  }
}

.basket-balls {
  position: absolute;
  inset: 0.2rem;
  transform-origin: 50% 60%;
}

.mini-ball {
  position: absolute;
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.42rem;
  font-weight: 800;
  color: #1c1917;
  box-shadow: inset 0 -2px 3px rgba(0, 0, 0, 0.2);
}

.basket-rim {
  position: absolute;
  left: 50%;
  top: 0.85rem;
  transform: translateX(-50%);
  width: 6.8rem;
  height: 1.1rem;
  border-radius: 50%;
  border: 3px solid #a78bfa;
  background: radial-gradient(ellipse at 50% 40%, rgba(196, 181, 253, 0.35), transparent 70%);
  box-shadow: 0 2px 0 #5b21b6;
}

/* Current ball display */
.current-ball-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
}

.current-ball {
  width: 5.2rem;
  height: 5.2rem;
  border-radius: 50%;
  background: linear-gradient(145deg, #fef3c7, #f59e0b 55%, #b45309);
  border: 3px solid rgba(255, 255, 255, 0.75);
  box-shadow:
    0 8px 24px rgba(0, 0, 0, 0.4),
    inset 0 -6px 12px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #1c1917;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.current-ball[data-state="empty"] {
  background: linear-gradient(145deg, #334155, #1e293b);
  color: rgba(245, 240, 230, 0.45);
  border-color: rgba(255, 255, 255, 0.2);
}

.current-ball[data-state="hit"] {
  box-shadow:
    0 0 0 3px rgba(74, 222, 128, 0.55),
    0 8px 24px rgba(0, 0, 0, 0.4);
  transform: scale(1.06);
}

.current-ball.pop {
  animation: ball-pop 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes ball-pop {
  0% {
    transform: scale(0.5) translateY(20px);
    opacity: 0.4;
  }
  60% {
    transform: scale(1.12);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.ball-letter {
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  line-height: 1;
  opacity: 0.75;
}

.ball-num {
  font-size: 1.85rem;
  font-weight: 900;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.message {
  margin-top: 0.55rem;
  min-height: 1.3rem;
  text-align: center;
  font-weight: 700;
  font-size: 0.95rem;
  color: #fef3c7;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.message.hit {
  color: var(--win);
}
.message.bingo {
  color: #fde68a;
  font-size: 1.1rem;
}

.called-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.28rem;
  justify-content: center;
  max-width: 42rem;
  margin-top: 0.45rem;
  min-height: 1.5rem;
  max-height: 3.6rem;
  overflow: auto;
  padding: 0 0.25rem;
}

.called-pip {
  min-width: 1.55rem;
  height: 1.45rem;
  padding: 0 0.28rem;
  border-radius: 0.28rem;
  display: grid;
  place-items: center;
  font-size: 0.68rem;
  font-weight: 800;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  animation: pip-in 0.25s ease both;
}

.called-pip.latest {
  outline: 2px solid #fde68a;
  background: rgba(251, 191, 36, 0.2);
}

@keyframes pip-in {
  from {
    opacity: 0;
    transform: scale(0.6);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* Setup */
.setup {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  text-align: center;
}

.setup[hidden] {
  display: none !important;
}

.setup h2 {
  font-size: 1.45rem;
  font-weight: 800;
  color: #e9d5ff;
}

.setup-sub {
  font-size: 0.88rem;
  opacity: 0.55;
  margin-bottom: 0.5rem;
}

.setup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  justify-content: center;
}

/* Cards */
.cards-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.55rem;
  padding-bottom: 0.25rem;
}

.cards-stage[hidden] {
  display: none !important;
}

.cards-row {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
  align-items: flex-start;
  align-content: flex-start;
  overflow: auto;
  padding: 0.25rem;
}

.bingo-card {
  background: linear-gradient(165deg, #fefce8, #f5f0e6 60%, #e7e5e4);
  color: var(--ink);
  border-radius: 0.55rem;
  border: 3px solid #c9a227;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35);
  padding: 0.4rem 0.45rem 0.5rem;
  width: min(15.5rem, 92vw);
  flex-shrink: 0;
}

.bingo-card.winner {
  outline: 3px solid #4ade80;
  box-shadow:
    0 0 0 2px rgba(74, 222, 128, 0.4),
    0 8px 28px rgba(74, 222, 128, 0.25);
}

.card-head {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.2rem;
  margin-bottom: 0.25rem;
}

.card-head span {
  text-align: center;
  font-weight: 900;
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  color: #6d28d9;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.22rem;
}

.cell {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 0.3rem;
  font-weight: 800;
  font-size: 0.92rem;
  font-variant-numeric: tabular-nums;
  background: #fff;
  border: 1px solid rgba(15, 23, 42, 0.1);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
  transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease;
}

.cell.free {
  background: linear-gradient(145deg, #ede9fe, #c4b5fd);
  color: #5b21b6;
  font-size: 0.58rem;
  font-weight: 900;
  letter-spacing: 0.04em;
}

.cell.marked {
  background: linear-gradient(145deg, #86efac, #22c55e);
  color: #052e16;
  border-color: rgba(21, 128, 61, 0.35);
  transform: scale(0.96);
}

.cell.just-marked {
  animation: mark-pop 0.4s ease;
}

.cell.win-line {
  background: linear-gradient(145deg, #fde68a, #f59e0b);
  color: #1c1917;
  box-shadow: 0 0 0 2px #fbbf24;
}

@keyframes mark-pop {
  0% {
    transform: scale(1.25);
  }
  100% {
    transform: scale(0.96);
  }
}

.card-tag {
  text-align: center;
  margin-top: 0.3rem;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(15, 23, 42, 0.45);
}

.play-actions {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  align-items: center;
  padding: 0.2rem 0 0.15rem;
}

/* Buttons */
.btn {
  min-width: 6.5rem;
  padding: 0.65rem 1rem;
  border-radius: 0.5rem;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.08);
  color: var(--cream);
  font: inherit;
  font-weight: 700;
  font-size: 0.92rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
}

.btn.primary {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  border-color: transparent;
  color: #1c1917;
}

.btn.ghost {
  background: transparent;
}

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

.btn .key-label {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
  font-weight: 800;
  color: #1c1917;
}

.btn.key-flash {
  outline: 2px solid #fde68a;
  box-shadow: 0 0 0 3px rgba(251, 191, 36, 0.35);
  transform: scale(1.04);
}

/* Bingo overlay */
.bingo-overlay {
  position: fixed;
  inset: var(--rg-bar) 0 0 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  background: rgba(8, 4, 16, 0.72);
  backdrop-filter: blur(4px);
  animation: overlay-in 0.35s ease both;
}

.bingo-overlay[hidden] {
  display: none !important;
}

@keyframes overlay-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.bingo-burst {
  position: absolute;
  width: 18rem;
  height: 18rem;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(251, 191, 36, 0.35), transparent 65%);
  animation: burst-pulse 1.2s ease-in-out infinite;
  pointer-events: none;
}

@keyframes burst-pulse {
  0%,
  100% {
    transform: scale(0.9);
    opacity: 0.7;
  }
  50% {
    transform: scale(1.15);
    opacity: 1;
  }
}

.bingo-title {
  position: relative;
  font-size: clamp(3.2rem, 12vw, 5.5rem);
  font-weight: 900;
  letter-spacing: 0.08em;
  color: #fde68a;
  text-shadow:
    0 4px 0 #b45309,
    0 8px 24px rgba(0, 0, 0, 0.45),
    0 0 40px rgba(251, 191, 36, 0.55);
  animation: bingo-bounce 0.7s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes bingo-bounce {
  0% {
    transform: scale(0.3) rotate(-8deg);
    opacity: 0;
  }
  60% {
    transform: scale(1.12) rotate(2deg);
  }
  100% {
    transform: scale(1) rotate(0);
    opacity: 1;
  }
}

.bingo-sub {
  position: relative;
  font-size: 1.05rem;
  font-weight: 650;
  color: #e9d5ff;
}

.footer {
  flex-shrink: 0;
  text-align: center;
  padding: 0.35rem 0.75rem max(0.55rem, env(safe-area-inset-bottom));
}

.hint {
  font-size: 0.65rem;
  opacity: 0.4;
}

.version {
  margin-top: 0.25rem;
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  opacity: 0.4;
  color: #c4b5fd;
}

@media (max-width: 560px) {
  .caller-sq {
    width: 3rem;
    height: 3rem;
  }

  .basket {
    width: 6rem;
    height: 4.4rem;
  }

  .basket-bowl {
    width: 5.2rem;
    height: 3rem;
  }

  .current-ball {
    width: 4.2rem;
    height: 4.2rem;
  }

  .ball-num {
    font-size: 1.5rem;
  }

  .bingo-card {
    width: min(14.5rem, 94vw);
  }

  .cell {
    font-size: 0.82rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .caller-sq.react-pull,
  .caller-sq.react-dance,
  .basket.spinning .basket-bowl,
  .basket.spinning .basket-balls,
  .current-ball.pop,
  .bingo-title,
  .bingo-burst {
    animation: none !important;
  }
}
