:root { --ink: #4a3f55; --card: #fffaf2; --soft: #efe3d6; --shadow: 0 10px 30px rgba(74, 63, 85, .18); }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #f4e9df; color: var(--ink);
  font-family: Nunito, system-ui, sans-serif; -webkit-tap-highlight-color: transparent; user-select: none; }
canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: manipulation; }

#hud { position: fixed; top: 0; left: 0; right: 0; padding: 16px; display: flex; justify-content: space-between; pointer-events: none; }
#title { font-weight: 800; font-size: 20px; }
#subtitle { font-family: Caveat, cursive; font-size: 22px; opacity: .75; margin-top: -2px; }
#dots { display: flex; gap: 8px; margin-top: 8px; align-items: center; }
.dot.s1 { background: #a99bb5; }
.dot.s2 { background: #ffb3c4; }
.dot.s3 { background: #ff7a9a; }
#total { font-size: 12px; font-weight: 800; opacity: .75; margin-left: 2px; }
#score { margin-top: 10px; display: flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 800; }
#score .lbl { opacity: .6; margin-left: 6px; }
.mini { display: inline-grid; place-items: center; width: 18px; height: 20px; border: 2px dotted rgba(74, 63, 85, .35);
  border-radius: 3px; background: #fff; color: #ff7a9a; font-size: 12px; line-height: 1; transition: opacity .3s, transform .3s, color .3s; }
.mini.off { color: #d8cfd8; opacity: .55; transform: scale(.88); }
.stamps { display: flex; gap: 10px; margin: 2px 0 8px; }
.stamps .mini { width: 46px; height: 52px; font-size: 26px; border-width: 3px; border-radius: 5px; }
.stamps .mini.earned { animation: thunk .35s cubic-bezier(.3, 1.6, .5, 1) both; }
@keyframes thunk { from { transform: scale(1.8) rotate(-14deg); opacity: 0; } }
.result { font-weight: 800; font-size: 14px; margin-bottom: 14px; }
.result .best { color: #ff6f91; margin-left: 6px; }
.result.ear { color: #c7922a; margin-top: -8px; }
.settings { margin: 4px 0 14px; display: grid; gap: 6px; }
.settings .group { font-weight: 800; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; opacity: .55; margin-top: 6px; }
.opt { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; background: rgba(74, 63, 85, .05); cursor: pointer; }
.opt span { display: grid; flex: 1; }
.opt small { opacity: .65; font-size: 12px; }
.opt input[type=range] { flex: 1.4; accent-color: var(--ink); }
.opt input[type=radio], .opt input[type=checkbox] { accent-color: var(--ink); width: 18px; height: 18px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: rgba(74, 63, 85, .18); }
.dot.done { background: var(--ink); }
.dot.ear { box-shadow: 0 0 0 2px #f0c24b; }
.dot.cur { outline: 2px solid var(--ink); outline-offset: 2px; }
#levelBtns { display: flex; gap: 8px; pointer-events: auto; }
.icon { flex: none; width: 44px; height: 44px; padding: 0; font-size: 18px; background: var(--card); box-shadow: var(--shadow); }

#panel { position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  width: min(560px, calc(100% - 32px)); background: var(--card); border-radius: 22px; box-shadow: var(--shadow); padding: 12px 14px 14px; }
#rolls { display: grid; grid-template-columns: 64px 1fr; gap: 6px 8px; align-items: center; }
.label { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; opacity: .55; }
.roll { display: flex; gap: 4px; height: 42px; }
.beat { flex: 1; max-width: 38px; position: relative; border-radius: 8px; background: rgba(74, 63, 85, .06); transition: background .15s; }
.beat .n { position: absolute; left: 50%; width: 16px; height: 16px; margin-left: -8px; transition: transform .15s; }
.beat .n svg { display: block; width: 100%; height: 100%; overflow: visible; }
.beat .n.rest { border: 2px dashed rgba(74, 63, 85, .35); border-radius: 50%; }
.beat .n.ear { background: rgba(74, 63, 85, .28); border-radius: 50%; transform: scale(.7); }
.beat.on { background: rgba(74, 63, 85, .18); }
.beat.on .n { transform: scale(1.35); }
.beat.good { box-shadow: inset 0 0 0 2px #5cbf8a; }
.beat.bad { box-shadow: inset 0 0 0 2px #e85d75; }
.beat.extra { box-shadow: inset 0 0 0 2px #e85d75; background: rgba(232, 93, 117, .1); }
.beat[data-note] { cursor: pointer; }
.beat[data-note]:hover { background: rgba(74, 63, 85, .12); }
.label.song { display: flex; align-items: center; gap: 6px; opacity: 1; }
.play { flex: none; width: 28px; height: 28px; padding: 0; border-radius: 50%; font-size: 12px; line-height: 1;
  background: var(--ink); color: var(--card); box-shadow: 0 2px 6px rgba(74, 63, 85, .25); }
.play.playing { background: #ff7a9a; opacity: 1; }
#panel.duet .play { width: 26px; height: 26px; }
#panel.duet .roll { height: 32px; }
#panel.long .roll { gap: 2px; }
#panel.long .beat .n { width: 11px; height: 11px; margin-left: -5.5px; }
#panel.duet .beat .n { width: 14px; height: 14px; margin-left: -7px; }
#panel.duet .rowgap { height: 4px; grid-column: 1 / -1; }

#buttons { display: flex; gap: 8px; margin-top: 12px; }
button { flex: 1; font: inherit; font-weight: 800; font-size: 16px; border: 0; border-radius: 14px; padding: 12px 8px;
  background: var(--soft); color: var(--ink); cursor: pointer; transition: transform .08s, opacity .2s; }
button:active { transform: scale(.96); }
button.primary { background: var(--ink); color: var(--card); }
button:disabled { opacity: .4; cursor: default; }

#toast { position: fixed; left: 50%; top: 92px; transform: translate(-50%, -8px); width: max-content; max-width: calc(100% - 32px);
  background: var(--card); padding: 10px 16px; border-radius: 14px; box-shadow: var(--shadow); font-weight: 800; text-align: center;
  opacity: 0; transition: .25s; pointer-events: none; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

#modal { z-index: 10; position: fixed; inset: 0; display: none; align-items: center; justify-content: center; padding: 16px; background: rgba(74, 63, 85, .35); }
#modal.show { display: flex; }
.postcard { position: relative; width: min(420px, 100%); background: var(--card); border-radius: 10px; padding: 22px 22px 18px;
  box-shadow: 0 20px 50px rgba(74, 63, 85, .35); transform: rotate(-1.5deg); animation: drop .35s cubic-bezier(.2, 1.4, .4, 1);
  background-image: repeating-linear-gradient(transparent 0 33px, rgba(74, 63, 85, .08) 33px 34px); }
@keyframes drop { from { transform: translateY(30px) rotate(-6deg); opacity: 0; } }
.stamp.two { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0; }
.face { vertical-align: middle; display: inline-block; }
.stamp { position: absolute; top: 14px; right: 14px; width: 64px; height: 76px; display: grid; place-items: center; font-size: 38px;
  border: 3px dashed rgba(74, 63, 85, .3); border-radius: 6px; background: #fff; transform: rotate(4deg); }
.postcard .to { font-weight: 800; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; opacity: .5; }
.postcard .body { font-family: Caveat, cursive; font-size: 26px; line-height: 34px; margin: 10px 70px 6px 0; white-space: pre-line; }
.postcard .sign { font-family: Caveat, cursive; font-size: 28px; text-align: right; margin-bottom: 14px; }

/* ---------- Screens ---------- */
.screen { display: none; position: fixed; inset: 0; z-index: 5; }
body:not(.screen-play) #hud, body:not(.screen-play) #panel { display: none; }
body.screen-title #titleScreen { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 16px 16px 26vh; }
body.screen-select #selectScreen { display: block; overflow-y: auto; }

.logo { font-weight: 800; font-size: clamp(40px, 11vw, 68px); letter-spacing: -.02em; text-align: center; line-height: 1;
  text-shadow: 0 3px 0 #fffaf2, 0 8px 24px rgba(74, 63, 85, .15); }
.tagline { font-family: Caveat, cursive; font-size: 28px; opacity: .75; }
.menu { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: min(320px, 86vw); margin-top: 22px; }
.menu .wide { grid-column: 1 / -1; }
.menu button { padding: 14px; font-size: 18px; box-shadow: var(--shadow); }

.selectInner { max-width: 680px; margin: 0 auto; padding: 16px 16px 48px; }
.selectHead { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.selectTitle { font-weight: 800; font-size: 24px; }
#selectTotal { font-weight: 800; font-size: 14px; opacity: .7; }
#worldTabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
@media (max-width: 560px) { #worldTabs { grid-template-columns: repeat(2, 1fr); } }
.tab { display: grid; justify-items: center; gap: 2px; padding: 10px 6px; background: var(--card); box-shadow: var(--shadow); border-radius: 16px; font-size: 13px; }
.tab .ticon { font-size: 24px; line-height: 1.2; }
.tab small { font-size: 11px; opacity: .65; }
.tab.on { outline: 3px solid var(--ink); outline-offset: -3px; }
.tab.locked { opacity: .55; }
#worldInfo { margin: 16px 2px 14px; font-weight: 600; }
.tier { display: inline-block; padding: 2px 9px; margin-right: 8px; border-radius: 999px; font-size: 12px; font-weight: 800; color: #fff; }
.tier.t0 { background: #4fb283; } .tier.t1 { background: #4c9fd6; } .tier.t2 { background: #e2932c; } .tier.t3 { background: #7d72c6; }
.lockmsg { margin-top: 8px; font-weight: 800; }
#levelGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.lcard { position: relative; display: grid; justify-items: center; gap: 6px; padding: 16px 10px 12px; border-radius: 12px;
  background: var(--card); box-shadow: var(--shadow); transform: rotate(-1deg);
  background-image: repeating-linear-gradient(transparent 0 23px, rgba(74, 63, 85, .06) 23px 24px); }
.lcard:nth-child(even) { transform: rotate(1deg); }
.lcard:not(:disabled):hover { transform: rotate(0) translateY(-2px); }
.lnum { position: absolute; top: 8px; left: 10px; font-size: 12px; opacity: .5; }
.lfaces { display: flex; min-height: 44px; align-items: center; font-size: 28px; }
.lplace { font-family: Caveat, cursive; font-size: 23px; font-weight: 700; line-height: 1; }
.lstamps { display: flex; gap: 3px; align-items: center; min-height: 22px; }
.lnew { padding: 2px 9px; border-radius: 999px; background: #ff7a9a; color: #fff; font-size: 11px; }
.lear { color: #c7922a; margin-left: 4px; }
.lcard.locked { opacity: .5; }
.result.unlock { color: #2f8f6a; margin-top: -8px; }

/* ---------- Story, band, parade ---------- */
body.screen-story #storyScreen { display: flex; align-items: flex-end; justify-content: center; padding: 16px 16px max(24px, env(safe-area-inset-bottom)); }
.storyBox { width: min(560px, 100%); background: var(--card); border-radius: 20px; box-shadow: var(--shadow); padding: 18px 18px 14px; }
#storyText { font-family: Caveat, cursive; font-size: 27px; line-height: 1.25; min-height: 68px; }
.storyRow { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.storyRow button { flex: none; padding: 10px 18px; }
#storyDots { display: flex; gap: 6px; flex: 1; }
#storyDots span { width: 8px; height: 8px; border-radius: 50%; background: rgba(74, 63, 85, .2); }
#storyDots span.on { background: var(--ink); }
body.screen-band #bandScreen, body.screen-parade #paradeScreen { display: block; pointer-events: none; }
.screenHead { position: absolute; top: 16px; left: 16px; display: flex; align-items: center; gap: 12px; pointer-events: auto; }
.subhead { font-weight: 800; font-size: 14px; opacity: .7; }
.screenFoot { position: absolute; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  width: min(360px, calc(100% - 32px)); display: grid; gap: 8px; text-align: center; font-weight: 700; pointer-events: auto; }
.screenFoot button { padding: 14px; box-shadow: var(--shadow); }
.paradeHead { position: absolute; top: 16%; left: 0; right: 0; text-align: center; padding: 0 16px; }
#paradeTitle { font-weight: 800; font-size: clamp(28px, 7vw, 44px); text-shadow: 0 3px 0 #fffaf2; }
#paradeSub { font-family: Caveat, cursive; font-size: 26px; opacity: .8; }
.selectHead #selectBandBtn { margin-left: auto; }

/* ---------- Rewards: wardrobe, album, jam ---------- */
#wardrobe:empty { display: none; }
#wardrobe { background: var(--card); border-radius: 16px; box-shadow: var(--shadow); padding: 10px; }
.wtitle { font-weight: 800; font-size: 13px; margin-bottom: 6px; }
.witems { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.witem { display: grid; justify-items: center; gap: 1px; padding: 6px 2px; border-radius: 10px; font-size: 20px; background: rgba(74, 63, 85, .06); }
.witem small { font-size: 9px; font-weight: 800; opacity: .7; line-height: 1.1; }
.witem.on { background: #ffe3a0; box-shadow: inset 0 0 0 2px #e2a83b; }
.screenFoot { width: min(420px, calc(100% - 32px)); }

body.screen-album #albumScreen { display: block; overflow-y: auto; }
.albumWorld h3 { margin: 20px 2px 10px; font-size: 16px; }
.albumGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.lcard.gazette { background-color: #f3efe6; }

body.screen-jam #jamScreen { display: block; pointer-events: none; }
.jamPanel { position: absolute; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  width: min(560px, calc(100% - 24px)); background: var(--card); border-radius: 20px; box-shadow: var(--shadow); padding: 12px; pointer-events: auto; }
#jamGrid { display: grid; gap: 5px; max-height: 44vh; overflow-y: auto; }
.jrow { display: grid; grid-template-columns: 34px repeat(8, 1fr); gap: 4px; align-items: center; }
.jstep { height: 34px; padding: 4px; border-radius: 9px; background: rgba(74, 63, 85, .07); }
.jstep.bar { box-shadow: inset 3px 0 0 rgba(74, 63, 85, .12); }
.jstep.on { background: #fff4df; }
.jstep svg { width: 18px; height: 18px; display: block; margin: 0 auto; overflow: visible; }
.jstep.now { background: rgba(74, 63, 85, .2); }
.jempty { text-align: center; font-weight: 800; padding: 18px; }
.jamBtns { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 10px; }
.jamBtns button { padding: 10px 4px; font-size: 14px; }
video.clip { width: 100%; border-radius: 10px; margin: 6px 0 8px; background: #000; }
a.dl { display: block; text-align: center; font-weight: 800; color: var(--ink); margin-bottom: 12px; }

/* ---------- Launch: demo badge, feedback, trailer ---------- */
.demoBadge { padding: 3px 12px; border-radius: 999px; background: #ff7a9a; color: #fff; font-weight: 800; font-size: 13px; }
.cardBtns { display: grid; gap: 8px; margin: 4px 0 12px; }
.lockmsg a { color: inherit; }
.trailerGo { position: fixed; z-index: 20; left: 50%; bottom: 24px; transform: translateX(-50%); width: auto; padding: 14px 22px; box-shadow: var(--shadow); }
body.trailer .menu, body.trailer #levelBtns, body.trailer #toast, body.trailer #paradeDone { display: none; }
body.trailer { cursor: none; }
