* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; height: 100%; overflow: hidden; }
body {
  font-family: 'Fredoka', 'Trebuchet MS', sans-serif;
  color: #fff;
  user-select: none; -webkit-user-select: none;
  touch-action: none;
  /* Letterbox: snowy holiday night */
  background: radial-gradient(ellipse at 50% 115%, #2d5a8a 0%, #15275a 42%, #070c22 100%);
  background-color: #070c22;
}
#bgSnow { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; }

/* ---------- Stage (fixed 540x960 portrait, scaled to fit) ---------- */
#stage {
  position: absolute; left: 50%; top: 50%;
  width: 540px; height: 960px;
  transform-origin: center center;
  transform: translate(-50%, -50%) scale(0.5);
  overflow: hidden;
  background: #0b1433;
  box-shadow: 0 0 0 3px #f2c14e, 0 0 0 8px #b3202d, 0 0 70px rgba(0,0,0,.85);
}
#game { position: absolute; left: 0; top: 0; width: 540px; height: 960px; display: block; touch-action: none; }
.hidden { display: none !important; }

/* ---------- Letterbox side panels (decorative) ---------- */
.side {
  position: fixed; top: 50%; transform: translateY(-50%);
  display: flex; align-items: center; justify-content: center;
  pointer-events: none; text-align: center;
}
.side-inner {
  width: 100%; max-width: 290px; padding: 24px 20px;
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(20,34,78,.88), rgba(10,18,44,.88));
  border: 3px solid rgba(242,193,78,.75);
  box-shadow: 0 0 0 6px rgba(179,32,45,.55), 0 12px 40px rgba(0,0,0,.5);
}
.side h3 { font-family: 'Luckiest Guy', sans-serif; font-weight: normal; font-size: 29px; line-height: 1.05; letter-spacing: 1px; color: #fff; text-shadow: 0 3px 0 #3a0710; }
.side h3 span { color: #ffd23f; }
.side p { margin-top: 10px; font-size: 16px; color: #cfe3ff; line-height: 1.35; }
.side ul { list-style: none; margin-top: 12px; text-align: left; font-size: 15px; color: #e6efff; }
.side li { padding: 7px 0 7px 22px; position: relative; border-bottom: 1px dashed rgba(255,255,255,.15); }
.side li::before { content: '❄'; position: absolute; left: 0; color: #8fd3ff; }
.side li b { color: #ffd23f; }
.side-tag { display: inline-block; font-family: 'Luckiest Guy', sans-serif; font-size: 19px; letter-spacing: 3px; background: #d42a36; padding: 6px 14px 2px; border-radius: 10px; border: 2px solid #fff; margin-bottom: 12px; transform: rotate(-3deg); }
.side-art { display: block; margin: 10px auto 0; width: 220px; height: auto; }
.side-cta { margin-top: 10px; font-size: 14px; color: #9fb3d9; border: 2px dashed rgba(255,255,255,.25); border-radius: 12px; padding: 12px; }

/* ---------- Screens ---------- */
.screen {
  position: absolute; inset: 0; z-index: 20;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 28px; text-align: center;
}
.screen.dim { background: rgba(5, 10, 30, .62); }

.brand-tag {
  font-family: 'Luckiest Guy', 'Fredoka', sans-serif;
  font-size: 26px; letter-spacing: 5px;
  background: #d42a36; color: #fff; padding: 8px 20px 3px; border-radius: 12px;
  border: 3px solid #fff; box-shadow: 0 5px 0 #6e0f1a, 0 8px 18px rgba(0,0,0,.4);
  transform: rotate(-4deg);
}
.title {
  font-family: 'Luckiest Guy', 'Fredoka', sans-serif; font-weight: normal;
  display: flex; flex-direction: column; line-height: .92; margin-top: 14px;
}
.title span { paint-order: stroke fill; -webkit-text-stroke: 8px #3a0710; letter-spacing: 2px; }
.title .t1 { font-size: 62px; color: #fff; text-shadow: 0 5px 0 #3a0710, 0 0 24px rgba(140,210,255,.5); }
.title .t2 { font-size: 96px; color: #ffd23f; text-shadow: 0 7px 0 #3a0710, 0 0 28px rgba(255,210,63,.55); }
.title .t3 { font-size: 80px; color: #8ff0b0; -webkit-text-stroke: 8px #0d3a22; text-shadow: 0 6px 0 #0d3a22; margin-top: 2px; letter-spacing: 8px; animation: rush 1.6s ease-in-out infinite; }
@keyframes rush { 0%,100% { transform: translateX(0) skewX(0); } 50% { transform: translateX(6px) skewX(-8deg); } }
#menu { justify-content: flex-start; padding-top: 40px; }
.menu-gap { flex: 0 0 236px; }
#menu .btn { margin: 6px 0; }

.btn {
  font-family: 'Fredoka', sans-serif; font-weight: 700; color: #fff;
  border: none; cursor: pointer; border-radius: 18px;
  font-size: 26px; padding: 12px 30px; min-width: 260px; margin: 7px 0;
  transition: transform .08s ease, filter .15s;
}
.btn:active { transform: translateY(3px) scale(.98); }
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .55; cursor: default; filter: grayscale(.4); }
.btn.primary { background: linear-gradient(180deg, #ff4a55, #c41d2b); box-shadow: 0 6px 0 #6e0f1a, 0 10px 22px rgba(0,0,0,.35); border: 3px solid #ffd23f; }
.btn.big { font-size: 38px; padding: 14px 50px; min-width: 300px; }
.btn.small { font-size: 20px; padding: 8px 22px; min-width: 0; margin: 10px 0 0; }
.btn.ghost { background: rgba(11,20,51,.72); border: 3px solid rgba(255,255,255,.65); box-shadow: 0 4px 0 rgba(0,0,0,.3); }
.btn.half { min-width: 0; flex: 1; }
.btn.music { font-size: 22px; min-width: 230px; padding: 10px 24px; background: linear-gradient(180deg, #2e9a5e, #1c6b3f); border: 3px solid #bff5d2; box-shadow: 0 4px 0 #0c3a21; }
.btn.music .note { display: inline-block; margin-right: 6px; }
.btn.music.on .note { animation: bob 1s ease-in-out infinite; }
.btn.music.off { background: linear-gradient(180deg, #5b6378, #3a4152); border-color: #9aa3b8; box-shadow: 0 4px 0 #23283a; }
@keyframes bob { 0%,100% { transform: translateY(0) rotate(-8deg); } 50% { transform: translateY(-5px) rotate(8deg); } }

.campaign { position: absolute; bottom: 22px; left: 50%; transform: translateX(-50%); width: 470px; background: rgba(10,16,48,.85); border: 2px solid rgba(255,210,63,.6); border-radius: 14px; padding: 8px 14px; font-size: 17px; color: #dbe8ff; line-height: 1.35; text-shadow: 0 2px 0 rgba(0,0,0,.5); }
.campaign-tag { display: inline-block; font-family: 'Luckiest Guy', sans-serif; background: #ffd23f; color: #6e0f1a; padding: 3px 8px 0; border-radius: 7px; margin-right: 6px; }

/* ---------- Cards ---------- */
.card {
  width: 460px; max-width: 100%;
  background: linear-gradient(180deg, #1c2b63 0%, #121d47 100%);
  border: 3px solid #e8b13a; border-radius: 24px;
  box-shadow: 0 0 0 6px #8e1b26, 0 16px 44px rgba(0,0,0,.55);
  padding: 24px 26px 20px;
  display: flex; flex-direction: column; align-items: center;
  position: relative;
}
.card::before { /* snow cap */
  content: ''; position: absolute; left: 14px; right: 14px; top: -11px; height: 18px;
  background: #fff; border-radius: 12px 12px 16px 16px;
  box-shadow: 0 3px 0 rgba(180,210,240,.8);
}
.card-title { font-family: 'Luckiest Guy', sans-serif; font-weight: normal; font-size: 40px; letter-spacing: 1px; color: #ffd23f; text-shadow: 0 3px 0 #3a0710; margin: 4px 0 12px; }
.card .btn { width: 100%; }
.row { display: flex; gap: 12px; width: 100%; }

#howArt { width: 400px; height: 209px; border-radius: 16px; background: #0b1433; border: 2px solid rgba(255,255,255,.2); }
.how-text { font-size: 20px; line-height: 1.35; font-weight: 600; color: #e6efff; margin: 14px 4px 8px; min-height: 84px; }
.how-text b { color: #ffd23f; }
.dots { display: flex; gap: 8px; margin: 4px 0 8px; }
.dots i { width: 12px; height: 12px; border-radius: 50%; background: rgba(255,255,255,.25); }
.dots i.on { background: #ffd23f; transform: scale(1.2); }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; z-index: 10; pointer-events: none; }
.hud-top {
  position: absolute; left: 0; right: 0; top: 0; height: 96px;
  display: flex; align-items: center; justify-content: space-between; padding: 0 12px;
  background: linear-gradient(180deg, rgba(6,10,30,.85), rgba(6,10,30,.35));
}
.hud-score, .hud-stat, .hud-time { display: flex; flex-direction: column; align-items: center; text-shadow: 0 3px 0 rgba(0,0,0,.5); }
.hud-score span, .hud-stat span, .hud-time span { font-size: 13px; font-weight: 700; letter-spacing: 2px; color: #bfe6ff; }
.hud-score b { font-family: 'Luckiest Guy', sans-serif; font-weight: normal; font-size: 46px; line-height: 1; color: #fff; min-width: 120px; }
.hud-stat b { font-family: 'Luckiest Guy', sans-serif; font-weight: normal; font-size: 32px; line-height: 1.05; color: #ffd23f; }
.hud-stat { width: 76px; }
.hud-time { width: 86px; background: rgba(255,255,255,.1); border: 3px solid rgba(255,255,255,.55); border-radius: 18px; padding: 3px 0 1px; }
.hud-time b { font-family: 'Luckiest Guy', sans-serif; font-weight: normal; font-size: 34px; line-height: 1.05; color: #8ff0b0; }
.hud-time.urgent { border-color: #ff5a64; background: rgba(212,42,54,.35); animation: urgent .5s ease-in-out infinite alternate; }
.hud-time.urgent b { color: #fff; }
@keyframes urgent { from { transform: scale(1); } to { transform: scale(1.1); } }
.hud-score.pop b { animation: pop .3s ease-out; }
@keyframes pop { 0% { transform: scale(1.35); color: #ffd23f; } 100% { transform: scale(1); } }

.icon-btn {
  pointer-events: auto; width: 54px; height: 54px; border-radius: 50%;
  background: rgba(255,255,255,.14); border: 3px solid rgba(255,255,255,.7);
  display: flex; align-items: center; justify-content: center; cursor: pointer; flex: 0 0 auto;
}
.icon-btn:active { transform: scale(.94); }
.icon-btn svg { width: 28px; height: 28px; fill: #fff; stroke: #fff; }
.icon-btn .slash { display: none; }
.icon-btn.muted .wave { display: none; }
.icon-btn.muted .slash { display: inline; }

.hud-tut-label { display: none; position: absolute; top: 26px; left: 0; right: 0; text-align: center; font-family: 'Luckiest Guy', sans-serif; font-size: 40px; color: #ffd23f; text-shadow: 0 4px 0 #3a0710; letter-spacing: 3px; }
#hud.tut .hud-top { justify-content: center; }
#hud.tut .hud-top > * { visibility: hidden; }
#hud.tut .hud-tut-label { display: block; }
#hud.tut .hud-info .streak { visibility: hidden; }

.hud-info { position: absolute; left: 0; right: 0; top: 744px; display: flex; justify-content: center; gap: 12px; }
.pill { display: flex; align-items: baseline; gap: 6px; background: rgba(11,20,51,.82); border: 2px solid rgba(255,255,255,.35); border-radius: 16px; padding: 6px 14px 4px; }
.pill span { font-size: 13px; font-weight: 700; letter-spacing: 1.5px; color: #bfe6ff; }
.pill b { font-family: 'Luckiest Guy', sans-serif; font-weight: normal; font-size: 24px; color: #fff; }
.pill i { font-style: normal; color: #7f93c4; font-weight: 700; margin: 0 2px; }
.pill b.over { color: #ff8a8a; }
.pill.streak b { color: #ffd23f; }

.hud-actions { position: absolute; left: 0; right: 0; top: 800px; display: flex; justify-content: center; gap: 22px; }
.act-btn {
  pointer-events: auto; cursor: pointer;
  font-family: 'Fredoka', sans-serif; font-weight: 700; font-size: 22px; color: #fff;
  width: 170px; height: 64px; border-radius: 20px;
  background: linear-gradient(180deg, #2e9a5e, #1c6b3f); border: 3px solid #bff5d2; box-shadow: 0 5px 0 #0c3a21;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .08s, opacity .2s;
}
.act-btn i { font-style: normal; font-size: 30px; line-height: 1; }
#btnReset { background: linear-gradient(180deg, #ff9f1c, #d96c00); border-color: #ffe0a8; box-shadow: 0 5px 0 #7a3c00; }
.act-btn:active { transform: translateY(3px); }
.act-btn:disabled { opacity: .45; cursor: default; }

#countdown, #timeup {
  position: absolute; left: 0; right: 0; top: 400px; z-index: 15; pointer-events: none;
  text-align: center; font-family: 'Luckiest Guy', sans-serif; font-size: 130px; color: #ffd23f;
  -webkit-text-stroke: 8px #3a0710; paint-order: stroke fill; text-shadow: 0 8px 0 #3a0710;
}
#timeup { font-size: 76px; top: 430px; color: #fff; animation: cd .6s ease-out; }
#countdown.tick { animation: cd .6s ease-out; }
@keyframes cd { 0% { transform: scale(1.8); opacity: 0; } 30% { transform: scale(1); opacity: 1; } 100% { transform: scale(.92); opacity: .95; } }

/* ---------- Tutorial overlay ---------- */
#tut { position: absolute; inset: 0; z-index: 12; pointer-events: none; }
.skip-btn { pointer-events: auto; position: absolute; top: 24px; right: 14px; font-family: 'Fredoka', sans-serif; font-weight: 700; font-size: 18px; color: #fff; background: rgba(255,255,255,.14); border: 2px solid rgba(255,255,255,.7); border-radius: 14px; padding: 8px 14px; cursor: pointer; }
.bubble {
  position: absolute; left: 30px; right: 30px; top: 600px;
  background: #fffaf0; color: #2a1a3a; border: 4px solid #d42a36; border-radius: 22px;
  padding: 14px 18px; text-align: center; box-shadow: 0 8px 0 rgba(0,0,0,.25);
  font-size: 21px; font-weight: 700; line-height: 1.3;
  transition: top .3s ease;
}
.bubble b { color: #d42a36; }
.bubble.in { animation: bubbleIn .35s cubic-bezier(.2,1.6,.4,1); }
@keyframes bubbleIn { from { transform: scale(.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.bubble .btn { pointer-events: auto; width: auto; }

/* ---------- Result ---------- */
.banner { font-family: 'Luckiest Guy', sans-serif; font-weight: normal; font-size: 56px; color: #fff; -webkit-text-stroke: 7px #3a0710; paint-order: stroke fill; text-shadow: 0 6px 0 #3a0710; margin-bottom: 22px; }
.banner.newbest { color: #ffd23f; animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.06); } }
.label { font-size: 16px; font-weight: 700; letter-spacing: 3px; color: #bfe6ff; }
.label.small { font-size: 13px; margin-top: 4px; }
.score-big { font-family: 'Luckiest Guy', sans-serif; font-size: 84px; line-height: 1; color: #ffd23f; text-shadow: 0 5px 0 #3a0710; margin: 4px 0; }
.best { font-size: 19px; color: #dbe8ff; }
.best b { color: #fff; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; width: 100%; margin: 16px 0 12px; }
.stats div { background: rgba(255,255,255,.08); border-radius: 14px; padding: 8px 2px; display: flex; flex-direction: column; align-items: center; }
.stats b { font-family: 'Luckiest Guy', sans-serif; font-weight: normal; font-size: 30px; color: #fff; }
.stats span { font-size: 12px; color: #bfe6ff; font-weight: 600; }
.badges { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; width: 100%; margin: 8px 0 12px; }
.badge { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px; border-radius: 12px; background: rgba(255,255,255,.05); opacity: .35; filter: grayscale(1); }
.badge i { font-style: normal; font-size: 28px; }
.badge span { font-size: 10px; font-weight: 700; line-height: 1.1; color: #dbe8ff; }
.badge.got { opacity: 1; filter: none; background: rgba(255,210,63,.18); border: 2px solid rgba(255,210,63,.7); animation: badgeIn .5s cubic-bezier(.2,1.6,.4,1) both; }
@keyframes badgeIn { from { transform: scale(.4); } to { transform: scale(1); } }

/* ---------- Form ---------- */
.form-score { font-size: 20px; margin-bottom: 12px; color: #dbe8ff; }
.form-score b { color: #ffd23f; font-family: 'Luckiest Guy', sans-serif; font-weight: normal; font-size: 30px; }
#playerForm { width: 100%; display: flex; flex-direction: column; align-items: stretch; }
.field { display: flex; flex-direction: column; text-align: left; margin-bottom: 12px; }
.field span { font-size: 15px; font-weight: 700; color: #bfe6ff; margin-bottom: 4px; letter-spacing: 1px; }
.field input { font-family: 'Fredoka', sans-serif; font-size: 22px; padding: 10px 14px; border-radius: 12px; border: 3px solid rgba(255,255,255,.4); background: #0b1433; color: #fff; outline: none; user-select: text; -webkit-user-select: text; }
.field input:focus { border-color: #ffd23f; }
.check { display: flex; gap: 10px; align-items: flex-start; text-align: left; font-size: 14px; color: #cfe3ff; margin: 2px 0 8px; }
.check input { width: 22px; height: 22px; flex: 0 0 22px; accent-color: #d42a36; }
.form-msg { min-height: 24px; font-size: 16px; font-weight: 600; color: #ff9a9a; margin-bottom: 4px; }
.form-msg.ok { color: #8ff0b0; }

/* ---------- Leaderboard ---------- */
.lb-state { font-size: 18px; color: #cfe3ff; min-height: 0; }
.lb-state:not(:empty) { margin: 6px 0 10px; }
.lb-list { list-style: none; width: 100%; max-height: 430px; overflow: auto; margin-bottom: 10px; }
.lb-list li { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-radius: 12px; font-size: 20px; font-weight: 600; }
.lb-list li:nth-child(odd) { background: rgba(255,255,255,.06); }
.lb-list li.me { background: rgba(255,210,63,.25); border: 2px solid #ffd23f; }
.lb-list .rk { width: 40px; font-family: 'Luckiest Guy', sans-serif; font-weight: normal; font-size: 22px; color: #ffd23f; text-align: left; }
.lb-list .nm { flex: 1; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-list .sc { font-family: 'Luckiest Guy', sans-serif; font-weight: normal; font-size: 24px; }
