/* ═══════════════════════════════════════════════════════════════
   PianoSmash — "Note Kingdom" cartoon theme (iPad landscape first)
   Palette: sunny sky, grass hills, warm wood, chunky ink outlines
   ═══════════════════════════════════════════════════════════════ */
@font-face {
  font-family: 'Baloo 2';
  src: url('/fonts/Baloo2-Bold.ttf') format('truetype');
  font-weight: 600 800;
}
@font-face {
  font-family: 'Baloo 2';
  src: url('/fonts/Baloo2-Bold.ttf') format('truetype');
  font-weight: 500 700;
}
@font-face {
  font-family: 'Baloo 2';
  src: url('/fonts/Baloo2-ExtraBold.ttf') format('truetype');
  font-weight: 800;
}
/* SMuFL music font — real engraved clefs, accidentals, time signatures */
@font-face {
  font-family: 'Bravura';
  src: url('/fonts/Bravura.woff2') format('woff2');
  font-weight: normal;
  font-style: normal;
}

:root {
  --sky-top: #8ed8ff;
  --sky-mid: #c9efff;
  --sky-low: #eafaff;
  --grass: #63b043;
  --grass-light: #8fd460;
  --hill-far: #bfe6a0;
  --wood: #a5692f;
  --wood-dark: #6b4423;
  --wood-line: #5a3a1e;
  --cream: #fff7e6;
  --cream-dark: #f3e3c3;
  --ink: #4a2f18;
  --red: #ff5252;
  --red-dark: #d63c3c;
  --orange: #ff8a3d;
  --yellow: #ffd93d;
  --green: #58c95b;
  --green-dark: #3da244;
  --blue: #38b6ff;
  --blue-dark: #2491d1;
  --purple: #9b7bff;
  --pink: #ff6fb5;
  --shadow: rgba(74, 47, 24, .25);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Baloo 2', 'Comic Sans MS', 'Segoe UI', sans-serif;
  color: var(--ink);
  background: var(--grass);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
body {
  padding:
    env(safe-area-inset-top, 0px)
    env(safe-area-inset-right, 0px)
    env(safe-area-inset-bottom, 0px)
    env(safe-area-inset-left, 0px);
}
#app { height: 100%; position: relative; }

/* ── shared sky backdrop for menu screens ── */
.screen { display: none; height: 100%; flex-direction: column; position: relative; }
.screen.active { display: flex; }
.sky-bg {
  position: absolute; inset: 0; z-index: 0;
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-mid) 55%, var(--sky-low) 78%, var(--hill-far) 78.2%, var(--grass-light) 92%, var(--grass) 100%);
  overflow: hidden;
  pointer-events: none;
}
/* rolling hills silhouettes */
.sky-bg::before, .sky-bg::after {
  content: ''; position: absolute; left: -10%; right: -10%; height: 26%;
  bottom: -4%; border-radius: 50% 50% 0 0 / 100% 100% 0 0;
  background: var(--hill-far);
}
.sky-bg::after {
  bottom: -9%; left: -30%; right: -20%; height: 30%;
  background: var(--grass-light);
  border-radius: 45% 55% 0 0 / 90% 100% 0 0;
}
/* distant grasslands strip peeking above the CSS hills */
.far-hills {
  position: absolute; left: 0; right: 0; bottom: 15%; height: 38%;
  background: url('/img/bg-grasslands.png') repeat-x bottom center / auto 100%;
  opacity: .5; filter: saturate(.92);
  -webkit-mask-image: linear-gradient(180deg, transparent 0%, #000 46%);
  mask-image: linear-gradient(180deg, transparent 0%, #000 46%);
}
/* gentle music notes drifting up through the sky */
.sky-notes { position: absolute; inset: 0; overflow: hidden; }
.sky-notes span {
  position: absolute; bottom: 14%; left: var(--x, 50%);
  font-size: var(--s, 24px); color: var(--c, var(--pink));
  opacity: 0; pointer-events: none;
  text-shadow: 0 2px 0 rgba(255,255,255,.6), 0 4px 0 rgba(74,47,24,.12);
  animation: noteFloat var(--t, 11s) linear infinite;
  animation-delay: var(--d, 0s);
}
@keyframes noteFloat {
  0%   { transform: translate(0, 0) rotate(-8deg); opacity: 0; }
  10%  { opacity: .85; }
  70%  { opacity: .5; }
  100% { transform: translate(7vw, -62vh) rotate(12deg); opacity: 0; }
}
.sky-notes span:nth-child(1) { --x: 8%;  --s: 22px; --c: var(--pink);   --t: 13s; --d: 0s; }
.sky-notes span:nth-child(2) { --x: 24%; --s: 30px; --c: var(--purple); --t: 16s; --d: 3.2s; }
.sky-notes span:nth-child(3) { --x: 43%; --s: 20px; --c: var(--blue);   --t: 12s; --d: 6.1s; }
.sky-notes span:nth-child(4) { --x: 58%; --s: 26px; --c: var(--orange); --t: 18s; --d: 1.7s; }
.sky-notes span:nth-child(5) { --x: 76%; --s: 32px; --c: var(--green);  --t: 14s; --d: 8.4s; }
.sky-notes span:nth-child(6) { --x: 90%; --s: 22px; --c: var(--purple); --t: 17s; --d: 4.9s; }
.sun {
  position: absolute; top: 5%; right: 7%; width: clamp(70px, 9vw, 120px); aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 35%, #fff3b0, var(--yellow) 60%);
  box-shadow: 0 0 0 14px rgba(255, 217, 61, .28), 0 0 0 30px rgba(255, 217, 61, .13);
  animation: sunPulse 5s ease-in-out infinite;
}
@keyframes sunPulse { 50% { box-shadow: 0 0 0 18px rgba(255,217,61,.34), 0 0 0 36px rgba(255,217,61,.16); } }
.cloud {
  position: absolute; opacity: .95;
  animation: drift linear infinite;
  filter: drop-shadow(0 6px 0 rgba(255,255,255,.65));
}
.cloud img { width: 100%; display: block; }
@keyframes drift { from { transform: translateX(-15vw); } to { transform: translateX(115vw); } }

/* ── chunky cartoon button ─────────────────────────────────── */
.btn3d {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: 12px;
  border-radius: 22px;
  padding: 16px 28px;
  font-family: inherit; font-weight: 800; font-size: 22px;
  color: #fff; cursor: pointer;
  text-shadow: 0 2px 0 rgba(0,0,0,.18);
  border: 4px solid var(--ink);
  box-shadow: inset 0 3px 0 rgba(255,255,255,.35), inset 0 -5px 0 rgba(0,0,0,.16);
  transition: transform .07s ease, filter .15s ease;
}
.btn3d::after {
  content: ''; position: absolute; inset: -4px; border-radius: inherit; z-index: -1;
  transform: translateY(6px);
  filter: brightness(.72);
  border: 4px solid var(--ink);
}
.btn3d:active { transform: translateY(5px); }
.btn3d:active::after { transform: translateY(1px); }
.btn3d.green  { background: linear-gradient(180deg, #79e07c, var(--green)); } .btn3d.green::after  { background: var(--green-dark); }
.btn3d.orange { background: linear-gradient(180deg, #ffb066, var(--orange)); } .btn3d.orange::after { background: #e06b1f; }
.btn3d.blue   { background: linear-gradient(180deg, #6ecbff, var(--blue)); }  .btn3d.blue::after  { background: var(--blue-dark); }
.btn3d.red    { background: linear-gradient(180deg, #ff8080, var(--red)); }   .btn3d.red::after   { background: var(--red-dark); }
.btn3d.purple { background: linear-gradient(180deg, #bb9dff, var(--purple)); }.btn3d.purple::after{ background: #7a5bd6; }
.btn3d.yellow { background: linear-gradient(180deg, #ffe985, var(--yellow)); color: var(--ink); text-shadow: none; }
.btn3d.yellow::after { background: #e0ac00; }
.btn3d.big { font-size: 30px; padding: 22px 46px; border-radius: 28px; letter-spacing: .03em; }
.btn3d.wide { width: 100%; }

/* shine sweep on the big PLAY button */
.btn-play-big { justify-content: space-between; overflow: visible; }
.btn-play-big .sub { font-size: 15px; opacity: .85; font-weight: 800; }
.shine {
  position: absolute; inset: -4px; border-radius: inherit;
  overflow: hidden; pointer-events: none;
}
.shine::before {
  content: ''; position: absolute; top: -40%; bottom: -40%; width: 30%; left: -45%;
  background: linear-gradient(105deg, rgba(255,255,255,0) 0%, rgba(255,255,255,.55) 50%, rgba(255,255,255,0) 100%);
  transform: skewX(-18deg);
  animation: shineSweep 3.4s ease-in-out infinite;
}
@keyframes shineSweep { 0% { left: -45%; } 55% { left: 135%; } 100% { left: 135%; } }

/* wooden sign panel */
.sign {
  background: linear-gradient(180deg, #b97a3c, var(--wood));
  border: 4px solid var(--wood-line);
  border-radius: 20px;
  box-shadow: inset 0 4px 0 rgba(255,255,255,.22), inset 0 -6px 0 rgba(0,0,0,.15), 0 10px 0 var(--wood-dark), 0 16px 30px var(--shadow);
  color: #fff7e6;
}

/* ───────────── HOME ───────────── */
.home-wrap {
  flex: 1; z-index: 1;
  display: grid;
  grid-template-columns: minmax(300px, 430px) 1fr;
  gap: clamp(14px, 3vw, 48px);
  padding: clamp(8px, 1.8vh, 18px) clamp(18px, 4vw, 64px);
  min-height: 0;
  align-items: center;
}
.logo-row { display: flex; align-items: center; gap: 14px; margin-bottom: 2px; }
.logo-note {
  width: clamp(52px, 5vw, 76px); aspect-ratio: 1; flex-shrink: 0;
  filter: drop-shadow(0 4px 0 rgba(74,47,24,.35));
  animation: bob 2.6s ease-in-out infinite;
}
@keyframes bob { 50% { transform: translateY(-7px) rotate(4deg); } }
.game-logo {
  font-size: clamp(34px, 4.6vw, 56px);
  line-height: .95;
  color: #fff;
  text-shadow:
    0 3px 0 var(--wood-dark),
    0 -2px 0 var(--wood-dark), 3px 0 0 var(--wood-dark), -3px 0 0 var(--wood-dark),
    0 8px 0 rgba(74,47,24,.28);
  -webkit-text-stroke: 2px var(--ink);
  paint-order: stroke fill;
}
.tagline {
  color: var(--ink); opacity: .75; font-size: 16px; font-weight: 700;
  margin: 2px 0 10px 4px;
}

.progress-card {
  display: flex; flex-direction: column; gap: 8px;
  background: linear-gradient(180deg, #fffdf4, var(--cream));
  border: 4px solid var(--ink);
  border-radius: 20px;
  padding: 12px 16px;
  box-shadow: 0 6px 0 var(--shadow), inset 0 2px 0 rgba(255,255,255,.7);
}
.progress-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
#home-level { font-weight: 800; font-size: 17px; }
#home-stars { color: var(--ink); font-weight: 800; font-size: 15px; white-space: nowrap; }
.xpbar {
  position: relative; height: 20px; border-radius: 99px;
  background: var(--cream-dark); border: 3px solid var(--ink); overflow: hidden;
}
#home-xp {
  height: 100%; width: 0%;
  background: repeating-linear-gradient(-45deg, #ffd93d 0 12px, #ffc93d 12px 24px);
  transition: width .6s cubic-bezier(.34,1.4,.64,1);
}
.mic-badge {
  align-self: flex-start;
  background: var(--cream); border: 3px solid var(--ink); color: var(--ink);
  border-radius: 99px; font-size: 13.5px; font-weight: 800; padding: 6px 14px;
  box-shadow: 0 3px 0 var(--shadow); cursor: pointer;
}
.mic-badge.on { background: #d9f5cf; }

.menu { display: flex; flex-direction: column; gap: 12px; margin-top: 4px; min-height: 0; }
.home-left { display: flex; flex-direction: column; justify-content: center; min-height: 0; overflow: hidden; }
.mode-btn {
  display: flex; align-items: center; gap: 14px;
  background: linear-gradient(180deg, #fffdf4, var(--cream));
  border: 4px solid var(--ink);
  border-radius: 22px;
  padding: 12px 18px;
  color: var(--ink); cursor: pointer; font-family: inherit; text-align: left;
  box-shadow: 0 7px 0 var(--shadow), inset 0 2px 0 rgba(255,255,255,.7);
  transition: transform .07s ease;
}
.mode-btn:active { transform: translateY(5px); box-shadow: 0 2px 0 var(--shadow); }
.mode-icon {
  width: 54px; height: 54px; flex-shrink: 0;
  display: grid; place-items: center;
  border-radius: 16px; font-size: 30px;
  border: 3px solid var(--ink);
}
.mode-icon.i-smart { background: linear-gradient(160deg, #ffe985, var(--yellow)); }
.mode-icon.i-surv  { background: linear-gradient(160deg, #ff9d9d, var(--red)); }
.mode-icon.i-stop  { background: linear-gradient(160deg, #a5dbff, var(--blue)); }
.mode-icon.i-songs { background: linear-gradient(160deg, #c7f0aa, var(--green)); }
.mode-icon.i-set   { background: linear-gradient(160deg, #d9ccff, var(--purple)); }
.mode-name { font-size: 20px; font-weight: 800; line-height: 1; }
.mode-tag { color: var(--ink); opacity: .62; font-size: 13.5px; font-weight: 600; margin-top: 2px; }
.mode-side { margin-left: auto; text-align: right; font-size: 12px; opacity: .65; font-weight: 700; white-space: nowrap; }
.mode-side b { display: block; font-size: 19px; opacity: 1; }

.continue-card { border-color: var(--blue-dark); background: linear-gradient(180deg, #f2faff, #d7eeff); }
.continue-label { color: var(--blue-dark); font-size: 11.5px; font-weight: 800; letter-spacing: .14em; }
.continue-title { font-weight: 800; font-size: 17px; }
.continue-meta { opacity: .62; font-size: 13px; font-weight: 600; }

.footer-links { display: flex; gap: 10px; margin-top: 4px; flex-wrap: wrap; }
.link-chip {
  background: linear-gradient(180deg, #fffdf4, var(--cream)); border: 3px solid var(--ink); color: var(--ink);
  border-radius: 99px; padding: 9px 18px; font-size: 14.5px; font-weight: 800;
  cursor: pointer; font-family: inherit;
  box-shadow: 0 4px 0 var(--shadow), inset 0 2px 0 rgba(255,255,255,.65);
}
.link-chip:active { transform: translateY(3px); box-shadow: none; }

/* right-side scene: character on hill + flags */
.scene-right { position: relative; height: 100%; min-height: 200px; z-index: 1; pointer-events: none; }
/* slime stays tappable — it's a wired easter egg, not decoration */
.slime-buddy { pointer-events: auto; cursor: pointer; }
.hero {
  position: absolute; bottom: 4%; left: 12%;
  width: clamp(110px, 12vw, 190px);
  animation: heroIdle 3s ease-in-out infinite;
  filter: drop-shadow(0 10px 0 rgba(74,47,24,.18));
}
@keyframes heroIdle { 50% { transform: translateY(-8px); } }
.flagpole { position: absolute; bottom: 6%; width: clamp(46px, 4.4vw, 74px); }
.flagpole.f1 { left: 42%; animation: wave 3.4s ease-in-out infinite; }
.flagpole.f2 { left: 62%; bottom: 3%; width: clamp(36px, 3.6vw, 60px); animation: wave 2.9s .4s ease-in-out infinite reverse; }
@keyframes wave { 50% { transform: rotate(-6deg) translateY(-4px); } }
.slime-buddy {
  position: absolute; bottom: 3.4%; left: 84%;
  width: clamp(60px, 6vw, 100px);
  image-rendering: auto;
  animation: slimeHop 1.6s ease-in-out infinite;
  filter: drop-shadow(0 6px 0 rgba(74,47,24,.18));
}
.slime-buddy.squash { animation: slimeSquash .35s ease; }
@keyframes slimeHop { 0%,100% { transform: scaleY(1) } 12% { transform: translateY(-16px) scaleY(1.05) } 24% { transform: scaleY(.86) } 36% { transform: scaleY(1) } }
@keyframes slimeSquash { 40% { transform: scale(1.25,.6) } }
.slime-note {
  position: absolute; bottom: calc(3.4% + clamp(66px, 7vw, 112px)); left: 88%;
  font-size: clamp(22px, 2.4vw, 38px); font-weight: 900; color: var(--pink);
  opacity: 0; pointer-events: none;
}
.slime-note.pop { animation: notePop 1.1s ease forwards; }
@keyframes notePop { 0% {opacity: 0} 15% {opacity: 1} 100% { opacity: 0; transform: translateY(-46px) rotate(14deg) } }

/* little scenery props around the hero */
.prop { position: absolute; pointer-events: none; filter: drop-shadow(0 4px 0 rgba(74,47,24,.16)); }
.bush-p  { bottom: 3.6%; left: 1%;   width: clamp(70px, 7vw, 118px); opacity: .96; }
.fence-p { bottom: 4.4%; left: 33%;  width: clamp(58px, 5.6vw, 92px); }
.mush-p  { bottom: 5.2%; left: 66%;  width: clamp(24px, 2.4vw, 42px); }
.plant-p { bottom: 4%;   left: 76%;  width: clamp(28px, 2.8vw, 48px); }

footer.home-foot { position: relative; z-index: 1; text-align: center; color: var(--ink); opacity: .85; font-size: 11.5px; font-weight: 700; padding: 0 0 4px; flex-shrink: 0; }
#screen-home .home-wrap { min-height: 0; }

/* ───────────── SONGS BROWSER ───────────── */
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 20px;
  background:
    repeating-linear-gradient(90deg,
      rgba(255,255,255,.055) 0 3px, rgba(0,0,0,0) 3px 30px,
      rgba(0,0,0,.05) 30px 34px, rgba(0,0,0,0) 34px 86px),
    linear-gradient(180deg, #c98a4b, var(--wood));
  border-bottom: 5px solid var(--wood-line);
  box-shadow: inset 0 3px 0 rgba(255,255,255,.18), inset 0 -4px 0 rgba(0,0,0,.14);
  z-index: 2;
}
.topbar h1 { font-size: 22px; font-weight: 800; color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,.25); flex: 1; }
.back-btn {
  background: linear-gradient(180deg, #fffdf4, var(--cream)); border: 3px solid var(--ink); color: var(--ink);
  border-radius: 14px; padding: 9px 18px; font-size: 16px; font-weight: 800;
  cursor: pointer; font-family: inherit;
  box-shadow: 0 4px 0 var(--shadow), inset 0 2px 0 rgba(255,255,255,.65);
}
.back-btn:active { transform: translateY(3px); box-shadow: none; }
#songs-count { color: #fff; opacity: .9; font-size: 14.5px; font-weight: 800; }

.chips { display: flex; gap: 8px; padding: 10px 20px; background: var(--cream-dark); border-bottom: 4px solid var(--wood-line); z-index: 2; }
.chip {
  background: #fff; border: 3px solid var(--ink); color: var(--ink);
  border-radius: 99px; padding: 7px 16px; font-size: 14.5px; font-weight: 800;
  cursor: pointer; font-family: inherit; opacity: .75;
}
.chip.sel { background: var(--yellow); opacity: 1; box-shadow: 0 3px 0 var(--shadow); }

#songs-grid {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; z-index: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
  padding: 16px 20px calc(26px + env(safe-area-inset-bottom));
  align-content: start;
}
.song-card {
  background: var(--cream);
  border: 4px solid var(--ink);
  border-radius: 18px;
  padding: 12px 14px;
  text-align: left; color: var(--ink);
  cursor: pointer; font-family: inherit;
  display: flex; flex-direction: column; gap: 3px;
  box-shadow: 0 6px 0 var(--shadow);
  transition: transform .07s ease;
}
.song-card:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--shadow); }
.song-card.locked { opacity: .55; filter: grayscale(.85); }
.song-card-top { display: flex; justify-content: space-between; align-items: center; }
.tier-chip {
  font-size: 11.5px; font-weight: 800; color: #fff;
  padding: 2px 9px; border-radius: 99px; border: 2px solid var(--ink);
  background: var(--tc, var(--cyan));
}
.song-stars { color: var(--orange); font-size: 13px; letter-spacing: 1px; }
.song-title { font-weight: 800; font-size: 15.5px; line-height: 1.15; }
.song-composer { opacity: .6; font-size: 12.5px; font-weight: 700; }

/* ───────────── GAME SCREEN ───────────── */
#screen-game { background: #000; }
.game-wrap { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.hud {
  display: flex; align-items: center; gap: 14px;
  padding: 8px 16px;
  background:
    repeating-linear-gradient(90deg,
      rgba(255,255,255,.055) 0 3px, rgba(0,0,0,0) 3px 30px,
      rgba(0,0,0,.05) 30px 34px, rgba(0,0,0,0) 34px 86px),
    linear-gradient(180deg, #c98a4b, var(--wood));
  border-bottom: 5px solid var(--wood-line);
  box-shadow: inset 0 3px 0 rgba(255,255,255,.18), inset 0 -4px 0 rgba(0,0,0,.14);
  z-index: 5;
}
.hud-stat {
  display: flex; align-items: center; gap: 7px;
  background: linear-gradient(180deg, #fffdf4, var(--cream));
  border: 3px solid var(--ink);
  border-radius: 14px; padding: 4px 12px;
  box-shadow: 0 3px 0 var(--shadow), inset 0 2px 0 rgba(255,255,255,.7);
}
.hud-label { font-size: 10.5px; font-weight: 800; opacity: .55; letter-spacing: .08em; display: block; line-height: 1; }
.hud-value { font-size: 18px; font-weight: 800; line-height: 1.1; }
#hud-title { font-size: 16px; font-weight: 800; max-width: 21vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#hud-mode { color: #fff; font-size: 12px; font-weight: 800; opacity: .95; text-shadow: 0 1px 0 rgba(0,0,0,.25); }
#hud-combo { color: var(--orange); font-weight: 800; font-size: 15px; min-width: 84px; text-align: center; }
.hearts { display: flex; gap: 2px; }
.hearts img { width: 27px; height: auto; filter: drop-shadow(0 2px 0 rgba(74,47,24,.25)); }
.hearts .beat { animation: heartBeat .9s ease infinite; }
@keyframes heartBeat { 30% { transform: scale(1.22) } }
#stopwatch-pill.danger { animation: pillFlash .45s steps(2) infinite; background: #ffdada; }
@keyframes pillFlash { 50% { background: var(--red); color: #fff; } }

.prog-wrap { height: 14px; background: var(--wood-dark); border-bottom: 3px solid var(--wood-line); box-shadow: inset 0 3px 4px rgba(0,0,0,.28); position: relative; z-index: 4; }
#hud-progress-fill {
  height: 100%; width: 0%;
  background: repeating-linear-gradient(-45deg, #ffd93d 0 14px, #ffc93d 14px 28px);
  transition: width .25s ease;
  box-shadow: inset 0 -4px 0 rgba(0,0,0,.15);
}

.canvas-wrap { position: relative; flex: 1; min-height: 0; }
#game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* count-in bubble */
#countin { position: absolute; inset: 0; display: none; place-items: center; pointer-events: none; z-index: 10; }
.countin-box {
  background: var(--cream); border: 5px solid var(--ink); border-radius: 30px;
  padding: 22px 56px; text-align: center;
  box-shadow: 0 10px 0 var(--shadow);
  transform: rotate(-2deg);
  animation: countinPop .45s cubic-bezier(.34,1.6,.64,1);
}
@keyframes countinPop { 0% { transform: rotate(-8deg) scale(.35); opacity: 0; } }
.countin-label { color: var(--orange); font-size: 14px; font-weight: 800; letter-spacing: .2em; }
#countin-num {
  display: inline-block;
  font-size: 96px; font-weight: 800; color: var(--ink); line-height: .95;
  animation: countPulse .9s ease-in-out infinite;
}
@keyframes countPulse {
  50% { transform: scale(1.14) rotate(2deg); color: var(--orange); }
}

/* pause overlay — everything dead-center */
#pause-overlay {
  position: absolute; inset: 0; display: flex; z-index: 40;
  align-items: center; justify-content: center;
  background: rgba(74, 47, 24, .45);
  backdrop-filter: blur(3px);
}
#pause-overlay.hidden { display: none; }
.pause-box {
  display: flex; flex-direction: column; align-items: stretch; gap: 14px;
  width: min(340px, 84vw);
  text-align: center;
}
.pause-box h2 { font-size: 36px; color: #fff; text-shadow: 0 3px 0 rgba(0,0,0,.3); margin-bottom: 6px; }
.pause-card {
  background: var(--cream); border: 5px solid var(--ink); border-radius: 26px;
  box-shadow: 0 12px 0 var(--shadow);
  padding: 26px 24px;
  display: flex; flex-direction: column; gap: 14px;
}

/* ── answer docks ── */
.dock { display: none; padding: 12px 18px calc(14px + env(safe-area-inset-bottom)); background:
  repeating-linear-gradient(90deg,
    rgba(255,255,255,.045) 0 3px, rgba(0,0,0,0) 3px 34px,
    rgba(0,0,0,.045) 34px 38px, rgba(0,0,0,0) 38px 96px),
  linear-gradient(0deg, #d8a468, #c98a4b);
  border-top: 5px solid var(--wood-line);
  box-shadow: inset 0 4px 0 rgba(255,255,255,.14), inset 0 -4px 0 rgba(0,0,0,.10);
  z-index: 5; }
.dock.active { display: flex; }
#dock-letters { gap: 12px; flex-wrap: wrap; justify-content: center; }
.letter-btn {
  flex: 1 1 0; min-width: 68px; max-width: 140px; min-height: 74px;
  font-family: inherit; font-size: 32px; font-weight: 800;
  color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,.25);
  background: var(--lb, linear-gradient(180deg,#999,#777));
  border: 4px solid var(--ink);
  border-radius: 18px;
  box-shadow: 0 7px 0 rgba(0,0,0,.28);
  cursor: pointer;
  transition: transform .05s ease, box-shadow .05s ease;
}
.letter-btn:active {
  transform: translateY(6px);
  box-shadow: 0 1px 0 rgba(0,0,0,.28);
  filter: brightness(1.12);
}

/* toy piano dock */
#dock-keys { position: relative; height: clamp(120px, 19vh, 170px); }
.pkey { position: absolute; top: 0; bottom: 0; border: none; cursor: pointer; font-family: inherit; }
.pkey.white {
  background: linear-gradient(180deg, #ffffff 82%, #e8e2d2);
  border: 3px solid var(--ink);
  border-radius: 0 0 12px 12px;
  box-shadow: inset 0 -8px 0 rgba(74,47,24,.12);
}
.pkey.white span, .pkey.black span {
  position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%);
  font-size: 13px; font-weight: 800; color: #a08a6a;
}
.pkey.black {
  height: 58%; z-index: 2;
  background: linear-gradient(180deg, #6b4423, #4a2f18);
  border: 3px solid var(--ink);
  border-radius: 0 0 10px 10px;
  box-shadow: 0 4px 0 rgba(0,0,0,.35);
}
.pkey.black span { color: #d8c39c; font-size: 10.5px; bottom: 5px; }
.pkey:active { filter: brightness(1.18); }
.pkey.hit-flash { filter: brightness(1.3) saturate(1.4); }

#dock-mic { flex-direction: column; align-items: center; gap: 6px; }
.mic-status { font-size: 16px; font-weight: 800; color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,.2); }
.mic-meter-wrap {
  width: min(340px, 60vw); height: 14px;
  background: rgba(74,47,24,.35); border: 3px solid var(--ink); border-radius: 99px;
  overflow: hidden;
}
#mic-meter { height: 100%; width: 0%; border-radius: 99px; transition: width .08s linear, background .2s; }
#mic-note { font-size: 52px; font-weight: 800; color: var(--yellow); min-height: 58px; text-shadow: 0 3px 0 rgba(0,0,0,.25); }
.mic-hint { font-size: 12.5px; color: #fff; opacity: .8; font-weight: 700; }
#dock-mic .letters-mini { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 6px; }
.letter-mini {
  min-width: 58px; min-height: 50px; font-family: inherit;
  font-size: 21px; font-weight: 800; color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,.2);
  background: var(--lm, linear-gradient(180deg,#999,#777));
  border: 3px solid var(--ink); border-radius: 14px;
  box-shadow: 0 4px 0 rgba(0,0,0,.28); cursor: pointer;
}
.letter-mini:active { transform: translateY(3px); box-shadow: none; }

/* pause & generic buttons reuse btn3d */
.icon-btn {
  background: linear-gradient(180deg, #fffdf4, var(--cream)); border: 3px solid var(--ink); color: var(--ink);
  border-radius: 14px; width: 46px; height: 46px; font-size: 19px; cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 4px 0 var(--shadow), inset 0 2px 0 rgba(255,255,255,.65);
}
.icon-btn:active { transform: translateY(3px); box-shadow: none; }
.btn.plain {
  background: linear-gradient(180deg, #fffdf4, var(--cream)); border: 3px solid var(--ink); color: var(--ink);
  border-radius: 16px; padding: 13px 18px; font-size: 17px; font-weight: 800;
  cursor: pointer; font-family: inherit;
  box-shadow: 0 5px 0 var(--shadow), inset 0 2px 0 rgba(255,255,255,.65);
}
.btn.plain:active { transform: translateY(4px); box-shadow: none; }

/* ───────────── RESULTS ───────────── */
.results-wrap {
  flex: 1; z-index: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; padding: 16px;
  position: relative;
}
.res-title-wrap {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  padding: clamp(14px, 2.6vh, 26px) clamp(28px, 5vw, 64px);
}
.res-banner {
  position: absolute; left: 50%; top: 50%;
  width: calc(100% + clamp(24px, 4vw, 56px));
  transform: translate(-50%, -50%);
  z-index: 0; pointer-events: none;
  filter: drop-shadow(0 5px 0 rgba(74,47,24,.25));
  animation: bannerSwing 4.2s ease-in-out infinite;
}
@keyframes bannerSwing { 0%,100% { margin-top: 0; } 50% { margin-top: -4px; } }
#res-title {
  position: relative; z-index: 1;
  font-size: clamp(34px, 4.6vw, 54px); color: #fff; font-weight: 800; line-height: 1;
  text-shadow: 0 3px 0 var(--wood-dark), 0 -2px 0 var(--wood-dark), 3px 0 0 var(--wood-dark), -3px 0 0 var(--wood-dark), 0 9px 0 rgba(74,47,24,.3);
  -webkit-text-stroke: 2px var(--ink);
  paint-order: stroke fill;
  animation: titlePop .55s cubic-bezier(.34,1.6,.64,1);
}
@keyframes titlePop { 0% { transform: scale(.3) rotate(-6deg); opacity: 0 } 100% { transform: scale(1) rotate(0); opacity: 1 } }
#res-subtitle { color: var(--ink); opacity: .72; font-size: 17px; font-weight: 700; }
#res-stars { display: flex; align-items: flex-end; gap: clamp(12px, 1.8vw, 24px); margin: 4px 0; }
#res-stars .star-img {
  width: clamp(56px, 6vw, 86px); aspect-ratio: 1;
  /* unearned: visible slate star with ink edge — reads as "empty slot", not ghost */
  filter: grayscale(1) brightness(.62) opacity(.9)
          drop-shadow(0 0 0 rgba(74,47,24,1)) drop-shadow(0 3px 0 rgba(74,47,24,.35));
  transform: scale(.72); transition: all .4s cubic-bezier(.34,1.7,.64,1);
}
/* arch layout — middle star raised & bigger */
#res-stars .star-img:nth-child(2) {
  width: clamp(72px, 7.6vw, 108px);
  margin-bottom: clamp(14px, 2.2vh, 26px);
}
#res-stars .star-img.earned {
  filter: drop-shadow(0 0 16px rgba(255,217,61,.9)) drop-shadow(0 5px 0 rgba(74,47,24,.28));
  transform: scale(1);
  animation: starSpin .6s ease;
}
@keyframes starSpin { 0% { transform: scale(0) rotate(-180deg) } 100% { transform: scale(1) rotate(0) } }
#res-record {
  background: var(--yellow); color: var(--ink); border: 3px solid var(--ink);
  border-radius: 99px; padding: 5px 20px; font-weight: 800; letter-spacing: .06em;
  box-shadow: 0 4px 0 var(--shadow); transform: rotate(-2deg);
  animation: wiggle 1.2s ease infinite;
}
@keyframes wiggle { 0%,100%{transform:rotate(-2.5deg)} 50%{transform:rotate(2.5deg)} }
.res-score-card {
  display: flex; flex-direction: column; align-items: center;
  background: var(--cream); border: 4px solid var(--ink); border-radius: 22px;
  padding: 8px 40px 12px; box-shadow: 0 8px 0 var(--shadow);
}
#res-score { font-size: clamp(40px, 5.4vw, 64px); font-weight: 800; color: var(--orange); line-height: 1; }
.res-score-label { font-size: 12px; font-weight: 800; opacity: .5; letter-spacing: .18em; }
.res-stats { display: grid; grid-template-columns: repeat(5, auto); gap: 6px 30px; align-items: end; text-align: center; }
.res-stat b { font-size: 27px; font-weight: 800; display: block; line-height: 1.05; }
.res-stat span { opacity: .55; font-size: 11px; font-weight: 800; letter-spacing: .1em; }
.res-actions { display: flex; gap: 14px; margin-top: 12px; flex-wrap: wrap; justify-content: center; }

/* confetti canvas */
#confetti-canvas { position: fixed; inset: 0; pointer-events: none; z-index: 90; }

/* ───────────── MODALS ───────────── */
.modal {
  position: fixed; inset: 0; display: none; place-items: center;
  background: rgba(74, 47, 24, .5); z-index: 100; backdrop-filter: blur(3px);
}
.modal.open { display: grid; }
.modal-card {
  width: min(460px, 92vw); max-height: 86vh; overflow-y: auto;
  background: var(--cream); border: 5px solid var(--ink); border-radius: 26px;
  padding: 24px 26px; box-shadow: 0 12px 0 var(--shadow);
  animation: modalPop .3s cubic-bezier(.34,1.5,.64,1);
}
@keyframes modalPop { 0% { transform: scale(.7) translateY(40px); opacity: 0 } }
.modal-card h2 { font-size: 24px; margin-bottom: 12px; }
.pm-songname { font-weight: 800; font-size: 26px; line-height: 1.05; }
.pm-composer { opacity: .6; margin: 2px 0 12px; font-weight: 700; }
.pm-facts { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.pm-fact {
  background: #fff; border: 3px solid var(--ink); border-radius: 99px;
  padding: 4px 14px; font-size: 13.5px; font-weight: 800;
}
.pm-actions { display: flex; gap: 12px; }
.pm-actions .btn3d, .pm-actions .btn { flex: 1; }
.set-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 3px dashed var(--cream-dark); gap: 12px; }
.set-row label.main { font-weight: 800; font-size: 16px; }
.seg { display: flex; background: #fff; border: 3px solid var(--ink); border-radius: 16px; overflow: hidden; }
.seg label { padding: 8px 14px; font-size: 14px; font-weight: 800; color: var(--ink); opacity: .55; cursor: pointer; border-right: 3px solid var(--cream-dark); }
.seg label:last-child { border-right: none; }
.seg input { display: none; }
.seg label:has(input:checked) { background: var(--yellow); opacity: 1; }
.switch {
  appearance: none; width: 62px; height: 36px; border-radius: 99px;
  background: var(--cream-dark); border: 3px solid var(--ink);
  position: relative; cursor: pointer; transition: background .2s;
}
.switch:before {
  content: ''; position: absolute; top: 2px; left: 3px; width: 26px; height: 26px;
  border-radius: 50%; background: #fff; border: 3px solid var(--ink);
  transition: all .2s cubic-bezier(.34,1.5,.64,1);
}
.switch:checked { background: #b8ecad; }
.switch:checked:before { left: 27px; background: var(--green); }
.danger-zone { border-bottom: none !important; margin-top: 10px; }

/* toast */
#toast {
  position: fixed; left: 50%; bottom: calc(30px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(24px);
  background: var(--cream); border: 4px solid var(--ink); color: var(--ink);
  border-radius: 18px; padding: 13px 24px; font-size: 15.5px; font-weight: 800;
  opacity: 0; pointer-events: none; transition: all .25s ease; z-index: 200;
  max-width: 88vw; text-align: center; box-shadow: 0 6px 0 var(--shadow);
}
#toast::before { content: '🎵 '; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); animation: toastBounce .4s cubic-bezier(.34,1.6,.64,1); }
@keyframes toastBounce { 0% { transform: translateX(-50%) translateY(26px) scale(.82); } }

/* portrait fallback */
@media (max-width: 720px) {
  .home-wrap { grid-template-columns: 1fr; overflow-y: auto; align-items: start; padding-top: 16px; }
  .scene-right { display: none; }
  .res-stats { grid-template-columns: repeat(3, auto); row-gap: 14px; }
}

/* ───────────── iPad Pro / large-tablet landscape polish ───────────── */
@media (min-width: 1024px) and (orientation: landscape) {
  html { font-size: 17px; }

  /* home: roomier scene, larger logo & buttons */
  .home-wrap { gap: clamp(24px, 5vw, 90px); padding-inline: clamp(30px, 6vw, 120px); }
  .game-logo { -webkit-text-stroke: 2.5px var(--ink); }
  .mode-btn { padding: 15px 22px; border-radius: 26px; }
  .mode-icon { width: 62px; height: 62px; font-size: 34px; border-radius: 19px; }
  .mode-name { font-size: 23px; }
  .mode-tag { font-size: 14.5px; }
  .btn3d.big { font-size: 33px; padding: 24px 52px; }
  .btn-play-big { font-size: 27px; padding: 21px 28px; }

  /* hero scene scales up */
  .hero { left: 16%; bottom: 6%; }
  .flagpole.f1 { left: 48%; }
  .slime-buddy { left: 86%; }

  /* game: bigger staff, taller toy piano with fat keys */
  .hud { padding: 10px 20px; gap: 18px; }
  #hud-title { font-size: 19px; max-width: 24vw; }
  .hud-value { font-size: 21px; }
  .hearts img { width: 32px; }
  .prog-wrap { height: 16px; }

  #dock-keys { height: clamp(150px, 23vh, 210px); }
  .pkey.white span { font-size: 15px; bottom: 12px; }
  .pkey.black span { font-size: 11.5px; }
  .letter-btn { min-height: 88px; font-size: 38px; border-radius: 22px; }
  .letter-mini { min-height: 56px; min-width: 64px; font-size: 23px; }
  .dock { padding-top: 14px; }

  /* songs grid breathes more */
  #songs-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 18px; padding: 20px 30px 32px; }
  .song-card { padding: 16px 18px; border-radius: 22px; }
  .song-title { font-size: 18px; }
  .topbar h1 { font-size: 25px; }

  /* results celebration */
  .res-stat b { font-size: 34px; }
  #res-stars .star-img { width: clamp(70px, 7vw, 104px); }
  .res-actions .btn3d, .res-actions .btn { font-size: 21px; padding: 16px 30px; }
}

/* tall-ish landscape (iPad mini/air) keeps dock compact */
@media (min-width: 1024px) and (orientation: landscape) and (max-height: 900px) {
  #dock-keys { height: clamp(130px, 20vh, 170px); }
  .letter-btn { min-height: 76px; font-size: 34px; }
}

/* respect accessibility motion settings */
@media (prefers-reduced-motion: reduce) {
  .sky-notes span, .shine::before, .res-banner, #countin-num, #toast.show,
  .sun, .logo-note, .hero, .flagpole, .slime-buddy,
  #res-record, .hearts .beat, #stopwatch-pill.danger, .slime-note.pop,
  #res-stars .star-img.earned { animation: none !important; }
  #res-stars .star-img { transition: none; }
}

/* ═════════ Studio polish pass (review round v9) ═════════ */

/* — WCAG contrast corrections (computed ratios from review) — */
.res-stat b { color: var(--ink); }
#res-perfect  { color: var(--green-dark) !important; }   /* 3.0:1 on sky */
#res-good     { color: var(--blue-dark) !important; }    /* 3.2:1 */
#res-miss     { color: var(--red-dark) !important; }     /* 4.3:1 */
#res-maxcombo { color: #7a5bd6 !important; }             /* 4.6:1 */
#res-accuracy { color: #d96b1f !important; }             /* 3.2:1 */
#res-score    { color: #c25a12; }                        /* 4.1:1 on cream */
.tier-chip { color: var(--ink); text-shadow: none; }     /* ink on tier fill ≥5.4:1 */
.mode-tag { opacity: .72; }
.mode-side { opacity: .78; }
.mic-hint { opacity: 1; text-shadow: 0 1px 0 rgba(74,47,24,.4); }
.home-foot { opacity: .85; }

/* deeper button floors so white labels pass on the gradient bottom edge */
.btn3d.green::after  { background: #2f9e37; }
.btn3d.orange::after { background: #d95f10; }

/* — PLAY = undisputed primary — */
.btn-play-big {
  transform: scale(1.02);
  box-shadow: 0 10px 0 rgba(0,0,0,.22), 0 18px 34px rgba(74,47,24,.35);
}
.btn-play-big:active { transform: scale(1.02) translateY(5px); }
.sky-bg .sun { opacity: .82; }

/* — pause truly dims the world — */
#pause-overlay {
  background: rgba(74, 47, 24, .55);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
body.paused .hud,
body.paused .dock,
body.paused .prog-wrap { opacity: .3; filter: grayscale(.4); transition: opacity .18s ease-out; }
.hud, .dock, .prog-wrap { transition: opacity .18s ease-out; }
.pause-box h2 {
  align-self: center;
  background: var(--cream); color: var(--ink);
  border: 4px solid var(--ink); border-radius: 18px;
  padding: 6px 30px; box-shadow: 0 6px 0 var(--shadow);
  -webkit-text-stroke: 0; margin-bottom: 8px;
}

/* — modal fit & surface discipline — */
.modal-card { width: min(420px, 92vw); }
.pm-facts .pm-fact { background: var(--cream-dark); }

/* — settings: honest static caption + safer reset row — */
.set-caption {
  display: inline-block; font-weight: 800; font-size: 15px;
  color: var(--ink); opacity: .75;
}

/* — touch targets — */
.set-row { min-height: 52px; cursor: pointer; }
.switch { width: 62px; height: 40px; }

/* — focus visibility for switch/keyboard users — */
:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
  border-radius: 8px;
}

/* — songs grid entrance stagger (JS adds .in progressively) — */
.song-card { opacity: 0; transform: translateY(10px); transition: opacity .28s ease-out, transform .28s cubic-bezier(.34,1.4,.64,1); }
.song-card.in { opacity: 1; transform: translateY(0); }
@media (prefers-reduced-motion: reduce) {
  .song-card { opacity: 1; transform: none; transition: none; }
}
