:root {
  --night: #0e2a47;
  --night2: #17395c;
  --cream: #fbf6ea;
  --ink: #1d2b3a;
  --gold: #f4c542;
  --red: #c0392b;
  --green: #1e8449;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100vh;
  background: radial-gradient(ellipse at top, var(--night2), var(--night) 70%);
  color: #fff;
  font-family: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- gentle falling snow (decorative) ---------- */
.snowfall {
  position: fixed; inset: 0; pointer-events: none; z-index: 0; opacity: .55;
  background-image:
    radial-gradient(2px 2px at 20px 30px, #fff, transparent),
    radial-gradient(2px 2px at 90px 110px, #fff, transparent),
    radial-gradient(3px 3px at 160px 60px, #fff, transparent),
    radial-gradient(2px 2px at 230px 150px, #fff, transparent),
    radial-gradient(3px 3px at 300px 20px, #fff, transparent);
  background-size: 320px 180px;
  animation: snow 14s linear infinite;
}
@keyframes snow { to { background-position: 40px 180px; } }

.page {
  position: relative; z-index: 1;
  max-width: 940px; margin: 0 auto;
  padding: 18px 14px 28px;
  padding-left: max(14px, env(safe-area-inset-left));
  padding-right: max(14px, env(safe-area-inset-right));
}

/* ---------- header ---------- */
.head { text-align: center; }
.head h1 {
  margin: 4px 0 6px;
  font-size: clamp(28px, 7vw, 44px);
  letter-spacing: .5px;
  color: var(--gold);
  text-shadow: 0 2px 0 rgba(0,0,0,.35);
}
.tag { margin: 0 auto 10px; max-width: 34em; color: #dbe8f5; font-size: clamp(14px, 3.6vw, 17px); line-height: 1.4; }

.demo-note {
  margin: 0 auto 14px; max-width: 560px;
  background: rgba(255,255,255,.1); border: 1px dashed rgba(255,255,255,.35);
  border-radius: 12px; padding: 8px 12px;
}
.demo-note p { margin: 0; font-size: 13.5px; line-height: 1.4; color: #eef4fb; text-align: center; }
.star { color: var(--gold); }

/* ---------- stage: board with singing snowmen around it ---------- */
.stage {
  display: grid;
  grid-template-columns: auto minmax(0, 560px) auto;
  grid-template-areas:
    ". top ."
    "left board right"
    ". bottom .";
  justify-content: center;
  align-items: center;
  gap: 8px 12px;
}
.sm-top { grid-area: top; }
.sm-bottom { grid-area: bottom; }
.sm-left { grid-area: left; }
.sm-right { grid-area: right; }
.board-wrap { grid-area: board; }

.sm-row { display: flex; justify-content: space-between; align-items: flex-end; padding: 0 4px; }
.sm-col { display: flex; flex-direction: column; justify-content: space-around; align-self: stretch; }

.snowman { position: relative; width: 78px; flex: none; }
.snowman svg { display: block; width: 100%; height: auto; overflow: visible; animation: bob 1.6s ease-in-out infinite; animation-delay: var(--delay, 0s); transform-origin: 50% 100%; }
.snowman .mouth { transform-box: fill-box; transform-origin: center; animation: sing .8s ease-in-out infinite; animation-delay: var(--delay, 0s); }
.snowman .arm-r { transform-box: fill-box; transform-origin: 0% 100%; animation: conduct 1.6s ease-in-out infinite; animation-delay: var(--delay, 0s); }
.note {
  position: absolute; top: 0; left: 62%;
  font-size: 22px; color: var(--ncol, #ffd86b); opacity: 0;
  animation: note 3s ease-out infinite; animation-delay: var(--ndelay, 0s);
  text-shadow: 0 1px 2px rgba(0,0,0,.4);
  pointer-events: none;
}
.note.n2 { left: 8%; animation-delay: calc(var(--ndelay, 0s) + 1.5s); --ncol: #9fe0ff; }

@keyframes bob { 0%,100% { transform: translateY(0) rotate(-1.5deg); } 50% { transform: translateY(-5px) rotate(1.5deg); } }
@keyframes sing { 0%,100% { transform: scale(.75, .55); } 50% { transform: scale(1, 1.25); } }
@keyframes conduct { 0%,100% { transform: rotate(-8deg); } 50% { transform: rotate(10deg); } }
@keyframes note {
  0%   { transform: translate(0, 6px) rotate(-10deg); opacity: 0; }
  15%  { opacity: 1; }
  100% { transform: translate(10px, -46px) rotate(14deg); opacity: 0; }
}

/* ---------- the bingo grid ---------- */
.board-wrap {
  background: linear-gradient(160deg, #2a5a3b, #1d4a30);
  border: 4px solid var(--gold);
  border-radius: 18px;
  padding: 8px;
  box-shadow: 0 10px 28px rgba(0,0,0,.45), inset 0 0 0 2px rgba(255,255,255,.12);
}
.grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
}

.cell {
  position: relative;
  aspect-ratio: 1 / 1;
  min-width: 0;
  padding: 3px 2px;
  border: 0; border-radius: 10px;
  background: var(--cream); color: var(--ink);
  font: inherit; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.12);
  transition: transform .15s ease, box-shadow .25s ease, background .25s ease;
}
.cell:active { transform: scale(.96); }
.cell:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.cell .ico { font-size: clamp(16px, 4.6vw, 28px); line-height: 1; filter: grayscale(.55) opacity(.75); transition: filter .25s; }
.cell .nm {
  font-size: clamp(7.5px, 2.15vw, 12.5px); line-height: 1.12; font-weight: 700;
  text-align: center; overflow-wrap: anywhere; hyphens: auto;
}
.cell .badge {
  position: absolute; top: 2px; right: 4px;
  font-size: clamp(9px, 2.4vw, 14px); line-height: 1; color: #d49a00;
}

.cell.lit {
  background: var(--c1); color: var(--c2);
  box-shadow: 0 0 0 2px rgba(255,255,255,.75), 0 0 16px 3px var(--c1), inset 0 -3px 0 rgba(0,0,0,.18);
  animation: pop .45s ease;
}
.cell.lit .ico { filter: none; }
.cell.lit .badge { color: #fff; }
.cell.line { animation: twinkle 1.2s ease-in-out infinite; }
@keyframes pop { 0% { transform: scale(.82); } 60% { transform: scale(1.08); } 100% { transform: scale(1); } }
@keyframes twinkle { 0%,100% { box-shadow: 0 0 0 2px #fff, 0 0 14px 3px var(--c1); } 50% { box-shadow: 0 0 0 3px #fff, 0 0 26px 8px var(--c1); } }

/* ---------- BLIZZARD: every square lit, and every square becomes a snowflake ---------- */
.board-wrap.blizzard {
  background: linear-gradient(160deg, #2d5f8a, #17395c);
  border-color: #e8f6ff;
  box-shadow: 0 0 44px 10px rgba(190, 230, 255, .5), 0 10px 28px rgba(0,0,0,.45);
}
.board-wrap.blizzard .cell,
.board-wrap.blizzard .cell.lit {
  background: radial-gradient(circle at 35% 30%, #ffffff, #cfe9fb 65%, #98cdf1);
  color: transparent;
  animation: none;
  box-shadow: 0 0 14px 2px rgba(255,255,255,.7), inset 0 0 0 2px rgba(255,255,255,.85);
}
.board-wrap.blizzard .cell .ico,
.board-wrap.blizzard .cell .nm,
.board-wrap.blizzard .cell .badge { visibility: hidden; }
.board-wrap.blizzard .cell::after {
  content: "\2744";
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(30px, 11vw, 62px); line-height: 1;
  color: #2e86de;
  text-shadow: 0 0 10px rgba(255,255,255,.9);
  animation: flake 2.6s ease-in-out infinite; animation-delay: var(--d, 0s);
}
@keyframes flake {
  0%, 100% { transform: rotate(0deg) scale(1); }
  50%      { transform: rotate(60deg) scale(1.18); }
}

/* ---------- status + controls ---------- */
.status {
  display: flex; justify-content: center; gap: 28px; flex-wrap: wrap;
  margin: 16px 0 6px; color: #dbe8f5;
}
.status .num { font-size: 26px; font-weight: 800; color: var(--gold); }
.status .lbl { font-size: 14px; }

.controls { display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap; margin-top: 8px; }
.toggle { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.toggle input { width: 20px; height: 20px; accent-color: var(--gold); }
.btn {
  border: 0; border-radius: 999px; padding: 9px 18px; cursor: pointer;
  background: rgba(255,255,255,.16); color: #fff; font: inherit; font-size: 14px; font-weight: 700;
  border: 1px solid rgba(255,255,255,.35);
}
.btn:hover { background: rgba(255,255,255,.26); }
.btn:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.btn.big { background: var(--red); border-color: var(--red); padding: 11px 24px; font-size: 16px; margin-top: 6px; }
.btn.big:hover { background: #a93226; }

.foot { margin-top: 22px; text-align: center; font-size: 12px; color: #9db6cf; }
.foot p { margin: 0; }

/* ---------- message popup ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(5, 15, 28, .72);
  display: flex; align-items: center; justify-content: center; padding: 18px;
}
.modal[hidden] { display: none; }
.card {
  position: relative; width: min(420px, 100%);
  background: var(--cream); color: var(--ink);
  border: 4px solid var(--gold); border-radius: 20px;
  padding: 22px 20px 20px; text-align: center;
  box-shadow: 0 18px 50px rgba(0,0,0,.55);
  animation: rise .35s ease;
}
@keyframes rise { from { transform: translateY(18px) scale(.95); opacity: 0; } to { transform: none; opacity: 1; } }
.close {
  position: absolute; top: 6px; right: 10px; width: 36px; height: 36px;
  border: 0; background: transparent; font-size: 28px; line-height: 1; color: #6b7a89; cursor: pointer;
}
.m-icon { font-size: 54px; line-height: 1; margin-bottom: 6px; }
.card h2 { margin: 0 0 8px; font-size: 24px; color: var(--red); }
.m-msg { margin: 0 0 10px; font-size: 19px; line-height: 1.4; font-weight: 600; }
.m-tag { margin: 0 0 8px; font-size: 12.5px; color: #5d6c7b; }
.ribbon {
  margin: -6px auto 12px; display: inline-block;
  background: var(--gold); color: #4a3200; font-weight: 800; letter-spacing: 1px;
  padding: 7px 16px; border-radius: 999px; font-size: 17px;
  animation: pop .5s ease;
}
.ribbon[hidden] { display: none; }

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  z-index: 60; max-width: min(90vw, 420px);
  background: #fff; color: var(--ink); border-radius: 999px; padding: 10px 18px;
  font-size: 14px; font-weight: 600; box-shadow: 0 6px 20px rgba(0,0,0,.4); text-align: center;
}
.toast[hidden] { display: none; }

/* ---------- confetti ---------- */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 70; overflow: hidden; }
.confetti span {
  position: absolute; top: -14px; width: 9px; height: 14px; border-radius: 2px;
  animation: fall linear forwards;
}
.confetti span.flake {
  width: auto; height: auto; border-radius: 0; line-height: 1; background: none;
  text-shadow: 0 0 8px rgba(150, 210, 255, .95);
}
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

/* ---------- small screens: snowmen above and below only ---------- */
@media (max-width: 760px) {
  .stage {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "top" "board" "bottom";
  }
  .sm-col { display: none; }
  .snowman { width: 60px; }
  .note { font-size: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  .snowfall, .snowman svg, .snowman .mouth, .snowman .arm-r, .note, .cell.lit, .cell.line, .card, .ribbon,
  .board-wrap.blizzard .cell::after { animation: none !important; }
  .confetti { display: none; }
}
