:root {
  --mint: #bff0de; --cream: #fff6ec; --card: #ffffffcc; --line: #e9e1f3; --text: #3d2c5e; --muted: #7a6a99;
  --pink: #ff6f91; --pink-dark: #d4466b; --yellow: #ffd25e; --yellow-dark: #d9a52a; --beam: #ff8fb1; --floor: #f29bbb;
  --good: #3fbf7f; --glow: #fff07a;
  --n0: #ff6f91; --n1: #ff9f5a; --n2: #ffc93c; --n3: #4fcf92; --n4: #5f9dff; --n5: #a982ff;
  --font: 'Nunito', ui-rounded, 'SF Pro Rounded', system-ui, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; color: var(--text); font-family: var(--font); font-weight: 700; background: linear-gradient(160deg, #d3f5e8, #fbefe4); overscroll-behavior: none; -webkit-user-select: none; user-select: none; overflow: hidden; }
body.paused *, body.paused *::before, body.paused *::after { animation-play-state: paused !important; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--pink); outline-offset: 2px; }
.defs { position: absolute; width: 0; height: 0; }
.splash { height: 100%; display: grid; place-items: center; color: var(--muted); font-weight: 800; }
.screen { position: relative; height: 100%; max-width: 520px; margin: auto; display: flex; flex-direction: column; overflow: hidden; background: linear-gradient(var(--mint), #e9fbf3 55%, var(--cream)); }

/* Floating sparkles and notes behind each screen. */
.sparkles { position: absolute; inset: 0 0 auto 0; width: 100%; height: 46%; pointer-events: none; }
.sp1 { fill: var(--n0); opacity: .3; } .sp2 { fill: var(--n2); opacity: .45; } .sp3 { fill: var(--n3); opacity: .3; }
.sp4 { fill: var(--n4); opacity: .3; } .sp5 { fill: var(--n5); opacity: .3; }
.sp-note { fill: none; stroke: var(--muted); stroke-width: 3; stroke-linecap: round; opacity: .2; }
.sp-note-dot { fill: var(--muted); opacity: .2; }

/* Menu */
#menu { overflow-y: auto; }
.menu-inner { position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: max(28px, env(safe-area-inset-top)) 22px max(18px, env(safe-area-inset-bottom)); }
h1 { font-weight: 900; font-size: clamp(46px, 15vw, 64px); line-height: 1; letter-spacing: -.5px; margin: 6px 0 0; }
.tagline { color: var(--muted); font-size: 17px; font-weight: 700; margin: 6px 0 0; }
.hero-art { flex: 1 1 auto; width: 100%; max-width: 360px; min-height: 140px; max-height: 300px; margin: 14px 0 18px; overflow: visible; }
.big-btn { position: relative; width: min(100%, 300px); min-height: 60px; border-radius: 20px; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 22px; font-weight: 900; line-height: 1.05; margin-bottom: 14px; transition: transform .08s, box-shadow .08s; }
.big-btn small { font-size: 13px; font-weight: 700; opacity: .85; margin-top: 2px; }
.big-btn b { font-weight: 900; }
.big-btn.pink { background: var(--pink); color: #fff; box-shadow: 0 7px 0 var(--pink-dark); }
.big-btn.yellow { background: var(--yellow); color: var(--text); box-shadow: 0 7px 0 var(--yellow-dark); }
.big-btn:active { transform: translateY(5px); box-shadow: 0 2px 0 var(--pink-dark); }
.big-btn.yellow:active { box-shadow: 0 2px 0 var(--yellow-dark); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: min(100%, 300px); margin: 4px 0 0; }
.stats div { display: flex; flex-direction: column; align-items: center; background: var(--card); border-radius: 14px; padding: 6px 4px 5px; }
.stats dd { margin: 0; font-size: 21px; font-weight: 900; line-height: 1.1; }
.stats dt { color: var(--muted); font-size: 12px; font-weight: 700; }

/* Play */
.top-bar { position: relative; flex: none; display: flex; align-items: center; gap: 10px; padding: max(12px, env(safe-area-inset-top)) 14px 0; }
.round-plain { position: relative; flex: none; width: 46px; height: 46px; display: grid; place-items: center; color: var(--text); border-radius: 50%; background: #fff; }
.round-plain svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.round-plain .fill { fill: currentColor; stroke: none; }
#sound[aria-pressed="false"] .waves { display: none; }
#sound[aria-pressed="false"] { opacity: .55; }
.hud-title { flex: 1; min-width: 0; text-align: center; font-size: 23px; font-weight: 800; }
.hud-title strong { font-weight: 900; }
#play.no-sound .hud-title { margin-right: 56px; }
.status-row { position: relative; flex: none; display: flex; justify-content: center; gap: 8px; margin-top: 8px; }
.pill { background: #fff; color: var(--text); border-radius: 30px; padding: 4px 15px 3px; font-size: 16px; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
#moves i { font-style: normal; color: var(--pink); letter-spacing: 1px; margin-right: 3px; }
.tune-card { position: relative; flex: none; display: flex; align-items: center; gap: 10px; background: var(--card); border-radius: 20px; padding: 9px 10px 9px 14px; margin: 10px 14px 0; }
.tune-card > b { font-size: 12.5px; font-weight: 900; line-height: 1.1; width: 52px; text-transform: uppercase; }
.tune { flex: 1; display: flex; justify-content: space-around; gap: 4px; }
.note { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-weight: 900; font-size: 16px; color: #fff; transition: transform .15s; }
.note.ok { box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--good); }
.note.ring { transform: scale(1.18); }
.n0 { background: var(--n0); } .n1 { background: var(--n1); } .n2 { background: var(--n2); }
.n3 { background: var(--n3); } .n4 { background: var(--n4); } .n5 { background: var(--n5); }
.listen { flex: none; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: var(--text); color: #fff; }
.listen svg { width: 18px; height: 18px; fill: currentColor; }
.coach { position: relative; flex: none; min-height: 40px; margin: 4px 18px 0; text-align: center; font-size: 15px; font-weight: 800; color: var(--pink-dark); line-height: 1.3; display: flex; align-items: center; justify-content: center; }
.board-wrap { position: relative; flex: 1; min-height: 0; min-width: 0; margin: 0 8px; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.ropes { position: relative; flex: none; display: flex; gap: 8px; margin: 4px 14px 8px; }
.rope { position: relative; flex: 1 1 0; min-width: 0; background: #fff; border-radius: 18px; padding: 6px 4px 8px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 14px; font-weight: 900; transition: transform .1s; box-shadow: 0 4px 0 var(--line); }
.rope:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--line); }
.rope svg { width: 100%; height: 66px; overflow: visible; }
.rope .cord { stroke: #ffb3c8; stroke-width: 5; stroke-linecap: round; transition: transform .18s; }
.rope .tassel { fill: var(--pink); transition: transform .18s; }
.rope.pulled .cord, .rope.pulled .tassel { transform: translateY(7px); }
.rope .dot { fill: var(--text); opacity: .75; }
.rope .move { fill: none; stroke: var(--pink); stroke-linecap: round; stroke-linejoin: round; }
.rope .move.back { stroke: var(--n4); }
.rope.hint { box-shadow: 0 0 0 4px var(--glow), 0 0 22px #ffe24d, 0 4px 0 var(--line); animation: nudge 1s ease-in-out infinite; }
.tools { position: relative; flex: none; display: flex; justify-content: space-around; background: var(--card); border-radius: 26px; padding: 8px 8px 6px; margin: 0 14px max(12px, env(safe-area-inset-bottom)); }
.tool { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 76px; font-size: 13px; font-weight: 800; color: var(--text); }
.tool-icon { position: relative; width: 46px; height: 46px; display: grid; place-items: center; border-radius: 50%; background: #fff; color: var(--text); transition: transform .08s; }
.tool:active .tool-icon { transform: scale(.92); }
.tool svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.tool.main .tool-icon { background: var(--pink); color: #fff; }
.tool b { position: absolute; top: -4px; right: -5px; min-width: 20px; height: 20px; display: grid; place-items: center; background: var(--text); color: #fff; border: 2px solid #fff; border-radius: 50%; font-size: 11px; font-weight: 900; }
.tool:disabled, .rope:disabled { opacity: .45; cursor: default; }

/* Belfry and bells */
.frame { fill: #ffffffa6; }
.floor { stroke: var(--floor); stroke-width: 14; stroke-linecap: round; }
.beam { fill: var(--beam); }
.hanger { stroke: var(--beam); stroke-width: 4; }
.slot-num { font-weight: 900; text-anchor: middle; fill: var(--muted); }
.bell-swing { transform-box: view-box; }
.bell-body { stroke: none; }
.f0 { fill: var(--n0); } .f1 { fill: var(--n1); } .f2 { fill: var(--n2); } .f3 { fill: var(--n3); } .f4 { fill: var(--n4); } .f5 { fill: var(--n5); }
.bell-shine { fill: none; stroke: #ffffffaa; stroke-width: 5; stroke-linecap: round; }
.bell-lip { stroke: #ffffff88; stroke-width: 5; }
.clapper { fill: var(--text); }
.face-dark { fill: var(--text); }
.face-line { fill: none; stroke: var(--text); stroke-width: 2.6; stroke-linecap: round; }
.cheek { fill: #fff; opacity: .5; }
.bell .awake { visibility: hidden; }
.bell.right .awake { visibility: visible; }
.bell.right .asleep { visibility: hidden; }
.bell.happy .awake { visibility: visible; }
.bell.happy .asleep { visibility: hidden; }
.bell-glow { fill: var(--glow); opacity: .55; visibility: hidden; }
.bell.right .bell-glow { visibility: visible; }
.bell-note { font-weight: 900; text-anchor: middle; fill: #fff; }
.ring-arc { fill: none; stroke: var(--text); stroke-width: 3; stroke-linecap: round; opacity: 0; }
.bell.dinging .ring-arc { animation: ding .5s ease-out; }
.bell.dinging .bell-swing { animation: swing .5s ease-out; }
.hero-wiggle { animation: swing 2.4s ease-in-out infinite; transform-box: fill-box; transform-origin: 50% 0; }

/* Result */
.overlay { position: fixed; inset: 0; background: #3d2c5e88; display: grid; place-items: center; padding: 16px; z-index: 6; overflow-y: auto; }
.card { width: min(100%, 360px); background: var(--cream); border-radius: 30px; overflow: hidden; text-align: center; box-shadow: 0 22px 50px #3d2c5e55; animation: land .34s cubic-bezier(.3, 1.4, .5, 1); }
.card-top { position: relative; height: 136px; display: grid; place-items: center; background: linear-gradient(var(--mint), #e9fbf3); }
.card-top .sparkles { height: 100%; }
#result-art { position: relative; width: 120px; height: 112px; overflow: visible; margin-bottom: 14px; }
.card-body { position: relative; display: flex; flex-direction: column; align-items: center; background: var(--cream); border-radius: 26px 26px 0 0; margin-top: -22px; padding: 12px 22px 8px; }
.card h2 { font-weight: 900; font-size: 26px; margin: 2px 0 0; line-height: 1.15; }
.card p { color: var(--muted); font-size: 15px; font-weight: 700; margin: 2px 0 14px; line-height: 1.35; }
.card .big-btn { min-height: 54px; font-size: 19px; margin-bottom: 12px; }
.result-stars { font-size: 42px; line-height: 1.1; color: var(--line); }
.result-stars span { display: inline-block; margin: 0 1px; }
.result-stars .on { color: var(--yellow); animation: stamp .42s backwards; text-shadow: 0 2px 0 var(--yellow-dark); }
.result-stars .on:nth-child(2) { animation-delay: .15s; }
.result-stars .on:nth-child(3) { animation-delay: .3s; }
.text-btn { color: var(--muted); font-weight: 800; padding: 6px 10px; font-size: 15px; min-height: 44px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: #fff; font-weight: 700; font-size: 15px; padding: 10px 16px; border-radius: 14px; z-index: 8; white-space: nowrap; }
.confetti { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 7; }
.confetti span { position: absolute; top: -24px; width: 12px; height: 12px; border-radius: 3px; animation: fall linear forwards; }

@keyframes swing { 20% { transform: rotate(9deg); } 50% { transform: rotate(-7deg); } 75% { transform: rotate(3deg); } }
@keyframes ding { 0% { opacity: .9; transform: scale(.8); } 100% { opacity: 0; transform: scale(1.3); } }
@keyframes nudge { 50% { transform: translateY(-3px); } }
@keyframes stamp { 0% { transform: scale(2.2); opacity: 0; } 70% { transform: scale(.9); opacity: 1; } 100% { } }
@keyframes land { from { transform: translateY(26px) scale(.94); opacity: 0; } }
@keyframes fall { to { transform: translate3d(var(--drift), 112vh, 0) rotate(var(--spin)); } }

/* Larger screens: the game sits as a framed card on the soft background. */
@media (min-width: 560px) and (min-height: 521px) {
  .screen { max-height: min(100%, 900px); top: 50%; transform: translateY(-50%); border-radius: 34px; box-shadow: 0 24px 60px #3d2c5e26; height: calc(100% - 32px); }
}
/* Short, wide screens: bells on the left, tune and controls on the right. */
@media (max-height: 520px) {
  .screen { max-width: none; }
  #menu .menu-inner { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 300px); grid-template-rows: repeat(5, auto); align-content: center; column-gap: 24px; align-items: center; justify-items: center; padding: 12px 20px; }
  #menu h1 { grid-column: 2; font-size: 44px; margin: 0; }
  #menu .tagline { grid-column: 2; font-size: 15px; margin-bottom: 10px; }
  .hero-art { grid-column: 1; grid-row: 1 / span 5; height: calc(100vh - 24px); max-height: none; min-height: 0; margin: 0; }
  #play-level, #play-daily, .stats { grid-column: 2; }
  .big-btn { min-height: 50px; margin-bottom: 10px; font-size: 19px; }
  .big-btn small { display: none; }
  .stats dd { font-size: 17px; }
  #play { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 330px); grid-template-rows: auto auto auto 1fr auto auto; }
  .top-bar { grid-column: 2; grid-row: 1; padding-top: 8px; }
  .round-plain { width: 40px; height: 40px; }
  .hud-title { font-size: 19px; }
  .status-row { grid-column: 2; grid-row: 2; margin-top: 4px; }
  .tune-card { grid-column: 1; grid-row: 1; margin: 8px 8px 0 12px; padding: 6px 8px 6px 12px; }
  .note, .listen { width: 32px; height: 32px; font-size: 14px; }
  .coach { grid-column: 2; grid-row: 3 / span 2; align-self: center; font-size: 13.5px; margin: 0 8px; }
  .board-wrap { grid-column: 1; grid-row: 2 / span 4; margin: 4px 4px 0 12px; }
  .ropes { grid-column: 1; grid-row: 6; margin: 0 8px 8px 12px; }
  .rope svg { height: 46px; }
  .tools { grid-column: 2; grid-row: 5 / span 2; align-self: end; margin: 0 8px 8px; }
  .tool { min-width: 56px; font-size: 11.5px; }
  .tool-icon { width: 40px; height: 40px; }
  .overlay { padding: 8px; }
  .card { display: grid; grid-template-columns: 36% 1fr; width: min(100%, 560px); }
  .card-top { height: auto; }
  .card-body { margin: 0 0 0 -18px; border-radius: 22px 0 0 22px; padding: 8px 16px 2px; }
  .result-stars { font-size: 30px; }
  .card h2 { font-size: 21px; }
  .card p { margin-bottom: 8px; font-size: 13.5px; }
  .card .big-btn { min-height: 46px; margin-bottom: 8px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
