:root {
  --pine: #0d3b2a;
  --pine-2: #145238;
  --red: #c8102e;
  --red-dark: #9a0c23;
  --gold: #f2c14e;
  --cream: #fdf6e3;
  --ink: #1d1d1d;
  --g1: #e05252; /* red */
  --g2: #43a96a; /* green */
  --g3: #e8b931; /* gold */
  --g4: #7fb6e3; /* ice blue */
  --g5: #b48ad6; /* plum */
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Nunito", system-ui, sans-serif;
  color: var(--cream);
  background:
    radial-gradient(circle at 20% 10%, rgba(255,255,255,.06) 0 2px, transparent 3px) 0 0 / 60px 60px,
    radial-gradient(circle at 70% 60%, rgba(255,255,255,.05) 0 1.5px, transparent 2.5px) 0 0 / 45px 45px,
    linear-gradient(180deg, var(--pine) 0%, #0a2c20 100%);
  overflow-x: hidden;
}

header {
  text-align: center;
  padding: 1.2rem 1rem .4rem;
  border-bottom: 6px solid transparent;
  border-image: repeating-linear-gradient(90deg, var(--red) 0 24px, var(--cream) 24px 48px) 6;
}

h1 {
  font-family: "Mountains of Christmas", cursive;
  font-size: clamp(2rem, 6vw, 3.4rem);
  margin: 0 0 .6rem;
  color: var(--gold);
  text-shadow: 0 3px 0 var(--red-dark), 0 6px 18px rgba(0,0,0,.4);
}

h2 { font-family: "Mountains of Christmas", cursive; color: var(--gold); font-size: 2rem; margin: 0 0 .8rem; text-align: center; }

nav { display: flex; gap: .5rem; justify-content: center; margin-bottom: .8rem; }

main { max-width: 640px; margin: 0 auto; padding: 1.2rem 1rem 3rem; position: relative; z-index: 1; }

.panel { background: rgba(0,0,0,.25); border: 2px solid rgba(242,193,78,.35); border-radius: 16px; padding: 1.5rem; text-align: center; }
.panel.error { border-color: var(--red); white-space: pre-wrap; text-align: left; font-family: monospace; }
.intro { font-size: 1.15rem; margin: 0 0 .6rem; }
.small { font-size: .95rem; opacity: .8; }
.hint { font-size: .85rem; opacity: .75; margin: .4rem 0; text-align: center; }

/* Buttons */
.btn, .nav-btn, .tab {
  font: inherit; font-weight: 800; cursor: pointer;
  border-radius: 999px; padding: .6rem 1.2rem;
  border: 2px solid var(--cream); background: transparent; color: var(--cream);
  transition: transform .1s, background .2s, opacity .2s;
}
.btn:hover:not(:disabled), .nav-btn:hover, .tab:hover { transform: translateY(-1px); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--red-dark); }
.btn.big { font-size: 1.4rem; padding: .8rem 2.4rem; margin-top: .6rem; }
.btn.link { border: none; text-decoration: underline; opacity: .8; }
.nav-btn.active, .tab.active { background: var(--cream); color: var(--pine); }

/* Stats */
.stats { display: flex; justify-content: center; gap: 2.5rem; margin-bottom: 1rem; }
.stat { display: flex; flex-direction: column; align-items: center; }
.label { font-size: .75rem; text-transform: uppercase; letter-spacing: .1em; opacity: .75; }
.value { font-size: 1.8rem; font-weight: 800; color: var(--gold); font-variant-numeric: tabular-nums; }

/* Board */
#board { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }

.tile {
  aspect-ratio: 1.5 / 1;
  display: flex; align-items: center; justify-content: center; text-align: center;
  padding: .3rem; border: none; border-radius: 10px; cursor: pointer;
  background: var(--cream); color: var(--ink);
  font: 800 clamp(.8rem, 3.4vw, 1.15rem) "Nunito", sans-serif;
  word-break: break-word; user-select: none;
  box-shadow: 0 3px 0 rgba(0,0,0,.3);
  transition: transform .12s, background .15s, color .15s;
}
.tile:hover { transform: translateY(-2px); }
.tile.selected { background: var(--red); color: #fff; transform: scale(.96); }
.tile.shake { animation: shake .45s; }
.tile.pop { animation: pop .35s; }

.solved {
  grid-column: 1 / -1;
  border-radius: 10px; padding: .8rem; text-align: center; color: var(--ink);
  box-shadow: 0 3px 0 rgba(0,0,0,.3);
  animation: reveal .45s ease-out;
}
.solved .cat { font-weight: 800; text-transform: uppercase; letter-spacing: .05em; font-size: 1rem; }
.solved .words { font-size: .95rem; margin-top: .15rem; }
.solved.g0 { background: var(--g1); color: #fff; }
.solved.g1 { background: var(--g2); color: #fff; }
.solved.g2 { background: var(--g3); }
.solved.g3 { background: var(--g4); }
.solved.g4 { background: var(--g5); }

.controls { display: flex; gap: .6rem; justify-content: center; margin-top: 1.2rem; flex-wrap: wrap; }

#toast {
  min-height: 2rem; margin-top: .8rem; text-align: center; font-weight: 800; color: var(--gold);
  opacity: 0; transition: opacity .25s;
}
#toast.show { opacity: 1; }

@keyframes shake {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-6px); } 40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); } 80% { transform: translateX(4px); }
}
@keyframes pop { 50% { transform: translateY(-8px) scale(1.05); } }
@keyframes reveal { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* Emoji bursts */
.burst {
  position: fixed; pointer-events: none; z-index: 50;
  font-size: var(--size, 2rem);
  animation: burst var(--dur, 1.4s) cubic-bezier(.2,.7,.3,1) forwards;
}
@keyframes burst {
  0% { transform: translate(0,0) rotate(0) scale(.4); opacity: 1; }
  70% { opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)) scale(1); opacity: 0; }
}
.rain {
  position: fixed; top: -3rem; pointer-events: none; z-index: 50;
  font-size: var(--size, 2rem);
  animation: rain var(--dur, 3s) linear forwards;
}
@keyframes rain { to { transform: translateY(110vh) rotate(var(--rot)); } }

/* Background snow */
#snow { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.flake {
  position: absolute; top: -10px; color: #fff; opacity: .7;
  animation: fall linear infinite;
}
@keyframes fall { to { transform: translateY(105vh) translateX(var(--drift)); } }

/* Leaderboard */
.tabs { display: flex; gap: .4rem; justify-content: center; flex-wrap: wrap; }
table { width: 100%; border-collapse: collapse; margin-top: .8rem; }
th, td { padding: .55rem .4rem; text-align: left; border-bottom: 1px solid rgba(253,246,227,.15); font-variant-numeric: tabular-nums; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; opacity: .7; }
td.num, th.num { text-align: right; }
td.sorted { color: var(--gold); font-weight: 800; }
tr.me td { background: rgba(200,16,46,.35); }
.rank { width: 2.5rem; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 40; padding: 1rem; }
.modal[hidden] { display: none; }
.modal-card {
  background: var(--pine-2); border: 3px solid var(--gold); border-radius: 18px;
  padding: 1.6rem; max-width: 460px; width: 100%; text-align: center;
  box-shadow: 0 10px 40px rgba(0,0,0,.5);
  animation: reveal .4s ease-out;
}
.scores { display: flex; justify-content: space-around; margin: .6rem 0 1.2rem; gap: .5rem; }
.score { display: flex; flex-direction: column; align-items: center; }
#name-form label { display: block; margin-bottom: .5rem; }
.row { display: flex; gap: .5rem; }
#name-input {
  flex: 1; min-width: 0; font: inherit; padding: .6rem .9rem; border-radius: 999px;
  border: 2px solid var(--cream); background: var(--cream); color: var(--ink);
}

[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  .flake, .burst, .rain { display: none; }
}

.btn.skip { margin-top: 1rem; font-size: .9rem; padding: .45rem 1rem; opacity: .85; }
