:root {
  --bg-1: #1b1036;
  --bg-2: #3a1a5c;
  --bg-3: #ff7a59;
  --ink: #fff8f0;
  --ink-soft: rgba(255, 248, 240, 0.72);
  --ink-faint: rgba(255, 248, 240, 0.45);
  --glass: rgba(255, 255, 255, 0.08);
  --glass-strong: rgba(255, 255, 255, 0.14);
  --line: rgba(255, 255, 255, 0.16);
  --done-1: #ffb347;
  --done-2: #ff5e7e;
  --gold: #ffd166;
  --mint: #6ee7b7;
  --sheet: #24143f;
  --radius: 18px;
  --font-display: "Fredoka", ui-rounded, system-ui, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--ink);
  font-family: var(--font-body);
  background: linear-gradient(180deg, var(--bg-1) 0%, var(--bg-2) 55%, #8a2f5c 85%, var(--bg-3) 120%) fixed;
  background-color: var(--bg-1);
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

button { font: inherit; color: inherit; }

/* ── Background decoration ─────────────────────────────── */
.sky { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.sky::before {
  content: ""; position: absolute; inset: 0;
  background-image:
    radial-gradient(1.5px 1.5px at 12% 18%, #fff9 50%, transparent 51%),
    radial-gradient(1px 1px at 78% 9%, #fff8 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 55% 24%, #fff6 50%, transparent 51%),
    radial-gradient(1px 1px at 30% 6%, #fff7 50%, transparent 51%),
    radial-gradient(1px 1px at 90% 30%, #fff5 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 4% 38%, #fff5 50%, transparent 51%);
  animation: twinkle 6s ease-in-out infinite alternate;
}
.sun {
  position: absolute; left: 50%; bottom: -38vmin; width: 80vmin; height: 80vmin;
  transform: translateX(-50%); border-radius: 50%;
  background: radial-gradient(circle, #ffcf7a 0%, #ff8a5b 45%, transparent 70%);
  opacity: 0.45; filter: blur(10px);
}
@keyframes twinkle { from { opacity: 0.5; } to { opacity: 1; } }

#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 50; }

/* ── Layout ────────────────────────────────────────────── */
.app {
  position: relative; z-index: 1;
  max-width: 560px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 20px) 16px calc(env(safe-area-inset-bottom) + 28px);
}

.hero { text-align: center; margin-bottom: 18px; }
.badge {
  display: inline-block; margin: 0 0 8px; padding: 4px 12px; border-radius: 999px;
  background: rgba(255, 209, 102, 0.16); border: 1px solid rgba(255, 209, 102, 0.4);
  color: var(--gold); font-size: 0.78rem; font-weight: 600;
}
.eyebrow {
  margin: 0; color: var(--ink-soft); font-size: 0.78rem;
  letter-spacing: 0.14em; text-transform: uppercase; font-weight: 600;
}
h1 {
  margin: 4px 0 16px; font-family: var(--font-display); font-weight: 700;
  font-size: clamp(1.7rem, 7.5vw, 2.4rem); line-height: 1.05;
  background: linear-gradient(90deg, #ffe29a, #ffa36c, #ff6f91);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

/* ── Countdown ─────────────────────────────────────────── */
.countdown {
  margin: 0 0 14px; padding: 12px 12px 10px; border-radius: 20px;
  background: linear-gradient(135deg, rgba(255, 179, 71, 0.16), rgba(255, 94, 126, 0.16));
  border: 1px solid rgba(255, 179, 71, 0.35);
}
.cd-units { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.cd-unit { position: relative; }
.cd-unit + .cd-unit::before {
  content: ":"; position: absolute; left: -5px; top: 2px;
  font-family: var(--font-display); font-size: 1.5rem; color: var(--ink-faint);
}
.cd-unit strong {
  display: block; font-family: var(--font-display); font-weight: 600;
  font-size: clamp(1.6rem, 8vw, 2.1rem); line-height: 1.1; font-variant-numeric: tabular-nums;
}
.cd-unit small { color: var(--ink-soft); font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.08em; }
.cd-label { margin: 8px 0 0; font-size: 0.82rem; color: var(--ink-soft); }
.countdown.urgent { border-color: rgba(255, 94, 126, 0.7); animation: urgent 2s ease-in-out infinite; }
.countdown.urgent .cd-unit strong { color: #ffb3c1; }
.countdown.over .cd-units { display: none; }
.countdown.over .cd-label { margin: 0; font-size: 1rem; font-weight: 600; color: var(--ink); }
@keyframes urgent { 50% { box-shadow: 0 0 22px rgba(255, 94, 126, 0.45); } }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stat {
  background: var(--glass); border: 1px solid var(--line); border-radius: 14px;
  padding: 10px 6px; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.stat strong { display: block; font-family: var(--font-display); font-size: 1.4rem; font-weight: 600; }
.stat small { color: var(--ink-soft); font-size: 0.72rem; }
.stat.pop strong { animation: pop 0.5s ease; }

.overall { height: 8px; border-radius: 999px; background: var(--glass); overflow: hidden; }
.overall-fill {
  height: 100%; width: 0; border-radius: inherit;
  background: linear-gradient(90deg, var(--done-1), var(--done-2));
  transition: width 0.6s cubic-bezier(.2, .8, .2, 1);
}

/* ── Board ─────────────────────────────────────────────── */
.board {
  display: grid; gap: 8px;
  grid-template-columns: repeat(var(--size, 3), 1fr);
  padding: 10px; border-radius: 24px;
  background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}
.board-loading { grid-column: 1 / -1; padding: 60px 0; text-align: center; color: var(--ink-soft); }

.tile {
  position: relative; aspect-ratio: 1; min-width: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  padding: 8px 6px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--glass); cursor: pointer; text-align: center; overflow: hidden;
  transition: transform 0.15s ease, background 0.3s ease, box-shadow 0.3s ease;
  animation: tile-in 0.45s backwards cubic-bezier(.2, .8, .2, 1);
}
.tile:active { transform: scale(0.95); }
.tile:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.tile .emoji { font-size: clamp(1.6rem, 9vw, 2.4rem); line-height: 1; transition: transform 0.3s; }
.tile .label {
  font-weight: 600; font-size: clamp(0.66rem, 3.1vw, 0.85rem); line-height: 1.15;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.size-5 .tile .emoji { font-size: clamp(1.1rem, 6vw, 1.7rem); }
.size-5 .tile .label { font-size: clamp(0.55rem, 2.3vw, 0.72rem); -webkit-line-clamp: 3; }

.pips { display: flex; flex-wrap: wrap; justify-content: center; gap: 3px; max-width: 90%; }
.pip { width: 6px; height: 6px; border-radius: 50%; background: rgba(255, 255, 255, 0.22); transition: background 0.3s; }
.pip.on { background: var(--gold); box-shadow: 0 0 6px rgba(255, 209, 102, 0.7); }
.tile .count { font-size: 0.68rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }

.tile.done {
  background: linear-gradient(145deg, var(--done-1), var(--done-2));
  border-color: transparent; box-shadow: 0 8px 22px rgba(255, 94, 126, 0.35);
}
.tile.done .count { color: rgba(255, 255, 255, 0.85); }
.tile.done .pip.on { background: #fff; box-shadow: none; }
.tile .stamp {
  position: absolute; top: 6px; right: 6px; width: 20px; height: 20px; border-radius: 50%;
  display: grid; place-items: center; font-size: 0.7rem; font-weight: 700;
  background: rgba(255, 255, 255, 0.95); color: #e2456b;
  transform: scale(0); transition: transform 0.35s cubic-bezier(.3, 1.6, .5, 1);
}
.tile.done .stamp { transform: scale(1); }

.tile.free { background: linear-gradient(145deg, #7c5cff, #c86bfa); border-color: transparent; }
.tile.free .emoji { animation: spin-star 8s linear infinite; }

.tile.bingo { animation: tile-in 0.45s backwards, glow 2.2s ease-in-out infinite; }
.tile.just-changed .emoji { transform: scale(1.3) rotate(-8deg); }

@keyframes tile-in { from { opacity: 0; transform: translateY(10px) scale(0.92); } }
@keyframes glow {
  0%, 100% { box-shadow: 0 0 0 2px var(--gold), 0 0 14px rgba(255, 209, 102, 0.45); }
  50% { box-shadow: 0 0 0 2px var(--gold), 0 0 26px rgba(255, 209, 102, 0.85); }
}
@keyframes spin-star { to { transform: rotate(360deg); } }
@keyframes pop { 50% { transform: scale(1.35); } }

.hint { text-align: center; color: var(--ink-faint); font-size: 0.8rem; margin: 14px 0 6px; }

.foot { display: flex; gap: 10px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 12px 20px; min-height: 44px;
  border-radius: 999px; text-decoration: none; color: var(--ink); font-weight: 600; font-size: 0.9rem;
  background: var(--glass-strong); border: 1px solid var(--line); cursor: pointer;
}
.pill.ghost { background: transparent; }

/* ── Bottom sheet ──────────────────────────────────────── */
.backdrop {
  position: fixed; inset: 0; z-index: 20; background: rgba(10, 4, 24, 0.55);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  opacity: 0; transition: opacity 0.25s;
}
.backdrop.open { opacity: 1; }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  max-width: 560px; margin: 0 auto; padding: 10px 20px calc(env(safe-area-inset-bottom) + 20px);
  background: var(--sheet); border-radius: 26px 26px 0 0; border: 1px solid var(--line); border-bottom: 0;
  box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.45);
  transform: translateY(105%); transition: transform 0.32s cubic-bezier(.2, .9, .25, 1);
  touch-action: pan-x;
}
.sheet.open { transform: translateY(0); }
.grabber { width: 42px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 14px; }
.sheet-head { display: flex; align-items: center; gap: 14px; }
.sheet-emoji {
  flex: none; width: 60px; height: 60px; border-radius: 18px; display: grid; place-items: center;
  font-size: 2rem; background: var(--glass-strong);
}
.sheet-emoji.done { background: linear-gradient(145deg, var(--done-1), var(--done-2)); }
.sheet-kind { margin: 0; color: var(--gold); font-size: 0.72rem; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; }
.sheet h2 { margin: 2px 0 0; font-family: var(--font-display); font-weight: 600; font-size: 1.35rem; line-height: 1.15; }
.sheet-desc { color: var(--ink-soft); font-size: 0.92rem; line-height: 1.45; margin: 14px 0 0; }
.sheet-desc:empty { display: none; }
.sheet-progress { margin-top: 18px; }
.sheet-bar { height: 10px; border-radius: 999px; background: var(--glass); overflow: hidden; }
.sheet-bar-fill {
  height: 100%; width: 0; border-radius: inherit;
  background: linear-gradient(90deg, var(--done-1), var(--done-2));
  transition: width 0.45s cubic-bezier(.2, .8, .2, 1);
}
.sheet-count { margin: 8px 0 0; color: var(--ink-soft); font-size: 0.85rem; font-variant-numeric: tabular-nums; }

.controls { margin-top: 18px; display: grid; gap: 10px; }
.controls:empty { display: none; }
.stepper { display: grid; grid-template-columns: 64px 1fr 64px; gap: 10px; align-items: center; }
.stepper .num { text-align: center; font-family: var(--font-display); font-size: 2.2rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.stepper .num small { font-size: 1rem; color: var(--ink-faint); }
.round {
  width: 64px; height: 64px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--glass-strong); font-size: 1.8rem; font-weight: 600; cursor: pointer;
  transition: transform 0.12s;
}
.round:active { transform: scale(0.9); }
.round.plus { background: linear-gradient(145deg, var(--done-1), var(--done-2)); border-color: transparent; }
.round:disabled { opacity: 0.35; cursor: default; }

.primary, .secondary {
  width: 100%; min-height: 52px; border-radius: 16px; border: 0; cursor: pointer;
  font-weight: 600; font-size: 1rem; transition: transform 0.12s, opacity 0.2s;
}
.primary { background: linear-gradient(90deg, var(--done-1), var(--done-2)); color: #fff; }
.secondary { background: var(--glass-strong); border: 1px solid var(--line); }
.primary:active, .secondary:active { transform: scale(0.98); }
.primary:disabled { opacity: 0.6; }

.close {
  display: block; width: 100%; margin-top: 12px; min-height: 44px;
  background: none; border: 0; color: var(--ink-faint); cursor: pointer; font-size: 0.9rem;
}

/* ── Login gate ────────────────────────────────────────── */
.gate {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px;
  background: rgba(15, 6, 32, 0.7); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.gate-card {
  width: 100%; max-width: 360px; padding: 28px 22px; border-radius: 26px; text-align: center;
  background: var(--sheet); border: 1px solid var(--line); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
  animation: tile-in 0.4s cubic-bezier(.2, .8, .2, 1);
}
.gate-card.shake { animation: shake 0.4s; }
.gate-emoji { font-size: 3rem; }
.gate-card h2 { font-family: var(--font-display); margin: 6px 0 4px; font-size: 1.5rem; }
.gate-card p { color: var(--ink-soft); margin: 0 0 18px; font-size: 0.92rem; }
.gate-card input[type="password"] {
  width: 100%; min-height: 52px; padding: 0 16px; margin-bottom: 12px; border-radius: 14px;
  border: 1px solid var(--line); background: rgba(255, 255, 255, 0.06); color: var(--ink);
  font-size: 16px; /* prevents iOS zoom */
}
.gate-card input:focus { outline: 2px solid var(--done-1); outline-offset: 1px; }
.error { color: #ff9aa9 !important; min-height: 1.2em; margin: 10px 0 4px !important; font-size: 0.85rem !important; }
.muted-link { color: var(--ink-faint); font-size: 0.85rem; text-decoration: none; }
@keyframes shake { 25% { transform: translateX(-8px); } 50% { transform: translateX(8px); } 75% { transform: translateX(-4px); } }

/* ── Toast ─────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 14px); z-index: 60;
  transform: translate(-50%, -150%); padding: 10px 18px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.95); color: #2a1450; font-weight: 600; font-size: 0.9rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3); transition: transform 0.35s cubic-bezier(.3, 1.4, .5, 1);
  white-space: nowrap; max-width: calc(100vw - 32px); overflow: hidden; text-overflow: ellipsis;
  visibility: hidden;
}
.toast.show { transform: translate(-50%, 0); visibility: visible; }

[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
