:root {
  --field: #e2245f;
  --field2: #b8124a;
  --deep: #7a0a31;
  --btn: #c6f432;
  --btn2: #97c418;
  --ink: #3b0717;
  --paper: #fff4f7;
  --cream: #fff6e4;
  --cream2: #f3dfbf;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  font-family: 'Nunito', system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--field); color: var(--paper); overscroll-behavior: none; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
#app { position: fixed; inset: 0; }
.screen { position: absolute; inset: 0; }
[hidden] { display: none !important; }

.key { display: inline-flex; align-items: center; justify-content: center; min-width: 1.6em; height: 1.6em; padding: 0 .35em; margin-right: .45em; border-radius: .35em; background: rgba(59, 7, 23, .22); font-size: .72em; font-weight: 900; line-height: 1; }
body.touch .key { display: none; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .2em; padding: .7em 1.3em; border-radius: 14px; background: var(--paper); color: var(--ink); font-weight: 900; font-size: 18px; box-shadow: 0 5px 0 rgba(59, 7, 23, .45); transition: transform .08s; min-height: 48px; }
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(59, 7, 23, .45); }
.btn.primary { background: var(--btn); color: var(--ink); box-shadow: 0 5px 0 var(--btn2), 0 5px 0 2px rgba(59, 7, 23, .3); }
.btn.big { font-size: 26px; padding: .55em 1.4em; min-width: 220px; }
.btn.alt { background: var(--deep); color: var(--paper); }
.btn:focus-visible, .chip:focus-visible, .pick:focus-visible, .lvbtn:focus-visible { outline: 4px solid var(--paper); outline-offset: 3px; }
.chip { display: inline-flex; align-items: center; padding: .5em .9em; min-height: 44px; border-radius: 12px; background: rgba(59, 7, 23, .28); font-weight: 900; font-size: 16px; }

/* ---------- home ---------- */
#homecv { position: absolute; inset: 0; width: 100%; height: 100%; }
.home-ui { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding: calc(28px + var(--sat)) 16px calc(16px + var(--sab)); gap: 18px; pointer-events: none; }
.home-ui > * { pointer-events: auto; }
#logo { margin: 2vh 0 0; font-weight: 900; font-size: clamp(64px, 15vw, 150px); line-height: .82; text-align: center; color: var(--field); letter-spacing: -.02em; text-transform: uppercase; -webkit-text-stroke: 0; text-shadow: 0 .06em 0 var(--deep), 0 0 0 #fff; paint-order: stroke fill; filter: drop-shadow(0 6px 0 rgba(59, 7, 23, .35)); animation: bob 2.4s ease-in-out infinite; }
#logo { color: var(--paper); text-shadow: 0 .07em 0 var(--field), 0 .12em 0 var(--deep); }
@keyframes bob { 50% { transform: translateY(-6px) rotate(-1deg); } }
.home-btns { display: flex; flex-direction: column; gap: 14px; align-items: stretch; margin-top: auto; }
.homechips { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.homechips .chip { background: var(--deep); }
.shelf:empty { display: none; }
body.land .home-ui { justify-content: center; }
body.land #logo { font-size: clamp(56px, 13vh, 140px); }
body.land .home-btns { margin-top: 0; flex-direction: row; }

/* ---------- bars ---------- */
.bar { display: flex; align-items: center; gap: 12px; height: 56px; padding: 0 calc(12px + var(--sar)) 0 calc(12px + var(--sal)); margin-top: var(--sat); background: var(--deep); }
.bar .title { font-weight: 900; font-size: 20px; white-space: nowrap; }
.bar .spacer { flex: 1; }
#hud .title { flex: 1; min-width: 0; font-size: 21px; }
#hud { background: linear-gradient(var(--deep), rgba(122, 10, 49, .88)); box-shadow: 0 3px 0 rgba(59, 7, 23, .35); }
.runs { display: flex; align-items: center; gap: 6px; font-weight: 900; font-size: 19px; white-space: nowrap; }
.pips { display: flex; gap: 3px; margin-right: 6px; }
.pip { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; border: 2px dashed rgba(255, 244, 247, .45); }
.pip.used { border: 2px solid var(--cream); background: rgba(255, 246, 228, .2); animation: pop .35s cubic-bezier(.2, 1.6, .4, 1); }
.pip.over { border-color: #ff9ab4; }
.pip.over.used { background: rgba(255, 90, 122, .35); }
.pip canvas { width: 24px !important; height: 24px !important; }
@keyframes pop { from { transform: scale(.3); } }
@media (max-width: 700px) { .pips { display: none; } }
.runs b#runs { font-size: 28px; display: inline-block; min-width: 1ch; text-align: center; }
.runs.over b#runs { color: #ffd0dc; }
.runs .par { opacity: .8; margin-left: 4px; font-size: 16px; }
.clock { font-weight: 900; font-variant-numeric: tabular-nums; min-width: 4.2em; text-align: right; opacity: .85; }
.chip.icon .pz { font-weight: 900; letter-spacing: -2px; }

/* ---------- play ---------- */
#play { display: flex; flex-direction: column; }
#stage { flex: 1 1 auto; display: flex; align-items: center; justify-content: center; min-height: 0; position: relative; }
#boardwrap { position: relative; flex: none; }
#sky { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 0; }
#hud, #stage, #picker, #keys { position: relative; z-index: 1; }
.pads { position: relative; z-index: 2; }
#board { display: block; }
.zone { display: none; }
#picker { flex: none; height: 78px; display: flex; gap: 10px; align-items: center; justify-content: center; padding: 6px 12px; }
.pick { position: relative; display: flex; align-items: center; gap: 6px; height: 64px; padding: 0 14px 0 6px; border-radius: 14px; background: var(--deep); font-weight: 900; font-size: 16px; opacity: .55; border: 3px solid var(--ink); transition: transform .12s, opacity .12s; }
.pick .bi { display: grid; place-items: center; width: 34px; height: 34px; margin-left: -14px; margin-top: 22px; border-radius: 50%; background: var(--cream); border: 2px solid var(--ink); }
.pick .bi canvas { width: 26px !important; height: 26px !important; }
#picker.choosing .pick:not(.empty):hover { transform: translateY(-3px); }
.pick .ic canvas { display: block;  }
.pick .nm { white-space: nowrap; }
.pick .ct { font-size: 20px; }
#picker.choosing .pick:not(.empty) { opacity: 1; background: var(--btn); color: var(--ink); box-shadow: 0 5px 0 var(--ink); animation: nudge 1.2s ease-in-out infinite; }
#picker.choosing .pick.sel { outline: 4px solid var(--paper); outline-offset: 2px; }
.pick.live { opacity: 1; background: var(--cream); color: var(--ink); transform: translateY(-4px); box-shadow: 0 5px 0 var(--ink); }
.pick.empty { opacity: .3; }
@keyframes nudge { 50% { box-shadow: 0 5px 0 var(--ink), 0 0 0 6px rgba(198, 244, 50, .4); } }

.toast { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); padding: 8px 14px; border-radius: 10px; background: var(--ink); color: var(--paper); font-weight: 900; font-size: 15px; white-space: nowrap; opacity: 0; pointer-events: none; }
.toast.show { animation: toast 2.6s ease forwards; }
@keyframes toast { 0% { opacity: 0; transform: translate(-50%, -6px); } 8%, 80% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; } }
.resetring { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 110px; height: 110px; border-radius: 50%; display: grid; place-items: center; font-weight: 900; color: var(--ink); background: conic-gradient(var(--btn) calc(var(--f) * 360deg), rgba(255, 244, 247, .85) 0); }

.keys { flex: none; display: flex; gap: 22px; justify-content: center; flex-wrap: wrap; padding: 4px 12px 14px; font-weight: 700; font-size: 15px; opacity: .9; }
.keys .key { font-size: .85em; margin-right: .2em; }
body.touch .keys { display: none; }
.pads { display: none; }
body.touch .pads { display: flex; flex: 1 0 190px; justify-content: space-between; align-items: center; padding: 8px calc(14px + var(--sar)) calc(12px + var(--sab)) calc(14px + var(--sal)); }
.padl, .padr { display: flex; gap: 10px; align-items: center; touch-action: none; }
.pad { width: 82px; height: 82px; border-radius: 22px; background: var(--deep); color: var(--paper); font-weight: 900; font-size: 30px; touch-action: none; box-shadow: 0 5px 0 rgba(59, 7, 23, .5); }
.pad.on { transform: translateY(3px); box-shadow: 0 2px 0 rgba(59, 7, 23, .5); background: #5a0624; }
.pad.jump { width: 104px; height: 104px; border-radius: 50%; background: var(--btn); color: var(--ink); font-size: 22px; box-shadow: 0 6px 0 var(--btn2); }
.pad.die { position: relative; width: 70px; height: 70px; border-radius: 50%; font-size: 17px; align-self: flex-start; margin-top: -10px; background: var(--ink); overflow: hidden; }
.pad.die .ring { position: absolute; inset: 0; border-radius: 50%; background: conic-gradient(#ff5a7a 0deg, transparent 0); }
.pad.die.arming .ring { animation: arm .25s linear forwards; }
.pad.die span { position: relative; }
@keyframes arm { to { background: conic-gradient(#ff5a7a 360deg, transparent 0); } }
@property --a { syntax: '<angle>'; inherits: false; initial-value: 0deg; }

/* phone landscape: controls beside the board, never over it */
body.touch.land #play .pads { position: absolute; left: 0; right: 0; top: calc(52px + var(--sat)); bottom: 78px; padding: 0 calc(10px + var(--sar)) 0 calc(10px + var(--sal)); pointer-events: none; }
body.touch.land .padl, body.touch.land .padr { pointer-events: auto; }
body.touch.land .padl { flex-direction: row; }
body.touch.land .padr { flex-direction: column-reverse; align-items: center; }
body.touch.land .pad.die { margin: 0; }
body.touch.land .pad { width: 66px; height: 66px; }
body.touch.land .pad.jump { width: 92px; height: 92px; }
body.touch.land #picker .nm { display: none; }

/* ---------- levels: the world map ---------- */
#levels { display: flex; flex-direction: column; background: var(--ink); }
#worlds { flex: 1; overflow-y: auto; padding: 0 0 calc(24px + var(--sab)); }
.lvmsg { position: absolute; left: 50%; top: calc(66px + var(--sat)); transform: translateX(-50%); z-index: 3; margin: 0; padding: 8px 14px; border-radius: 10px; background: var(--ink); font-weight: 900; text-align: center; }
.lvmsg:empty { display: none; }
.world { position: relative; padding: 14px calc(18px + var(--sar)) 22px calc(18px + var(--sal)); background: var(--bg) center 65% / cover; border-bottom: 4px solid var(--ink); }
.world::before { content: ''; position: absolute; inset: 0; background: linear-gradient(rgba(59, 7, 23, .55), rgba(59, 7, 23, 0) 45%, rgba(59, 7, 23, .25)); }
.world > * { position: relative; }
.wh { display: flex; align-items: center; gap: 10px; }
.wh h2 { margin: 0; font-size: 24px; font-weight: 900; text-shadow: 0 3px 0 var(--ink); }
.wstars { margin-left: auto; padding: 4px 10px; border-radius: 99px; background: rgba(59, 7, 23, .6); font-weight: 900; color: var(--btn); white-space: nowrap; }
.wicon { display: grid; place-items: center; width: 50px; height: 50px; border-radius: 50%; background: var(--cream); border: 3px solid var(--ink); }
.path { display: flex; flex-wrap: wrap; gap: 18px 26px; align-items: flex-end; padding: 18px 6px 4px; }
.seed { position: relative; display: grid; place-items: center; width: 74px; height: 74px; border-radius: 50% 50% 46% 46%; background: var(--deep); border: 4px solid var(--ink); box-shadow: 0 6px 0 var(--ink); font-weight: 900; transform: translateY(calc(sin(var(--i) * 1.3) * 10px)); transition: transform .12s; }
.seed b { font-size: 30px; line-height: 1; }
.seed .st { position: absolute; bottom: -24px; left: 50%; transform: translateX(-50%); color: var(--btn); font-size: 17px; letter-spacing: 1px; text-shadow: 0 2px 0 var(--ink); white-space: nowrap; }
.seed .st i { font-style: normal; color: rgba(255, 244, 247, .45); }
.seed.done { background: var(--cream); color: var(--ink); }
.seed.next { background: var(--btn); color: var(--ink); animation: beckon 1.3s ease-in-out infinite; }
.seed.open { background: var(--field); }
.seed.locked { background: rgba(59, 7, 23, .55); border-style: dashed; box-shadow: none; }
.seed.locked::after { content: ''; width: 18px; height: 22px; background: no-repeat center / contain url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 18 22'%3E%3Crect x='1' y='9' width='16' height='12' rx='3' fill='%23fff4f7' opacity='.7'/%3E%3Cpath d='M4.5 9V6a4.5 4.5 0 0 1 9 0v3' stroke='%23fff4f7' stroke-width='2.6' fill='none' opacity='.7'/%3E%3C/svg%3E"); }
.seed:not(.locked):hover { transform: translateY(calc(sin(var(--i) * 1.3) * 10px - 4px)); }
.seed:focus-visible { outline: 4px solid var(--paper); outline-offset: 4px; }
@keyframes beckon { 50% { box-shadow: 0 6px 0 var(--ink), 0 0 0 9px rgba(198, 244, 50, .35); } }
@media (max-width: 420px) { .path { gap: 18px 16px; } .seed { width: 62px; height: 62px; } .seed b { font-size: 26px; } }

/* ---------- panels ---------- */
.panel { position: fixed; inset: 0; z-index: 10; display: flex; align-items: flex-end; justify-content: center; background: rgba(59, 7, 23, .55); animation: fade .2s; }
.sheet { width: 100%; max-height: 100%; overflow-y: auto; background: var(--cream); color: var(--ink); border-top: 5px solid var(--ink); box-shadow: 0 -4px 0 rgba(59, 7, 23, .25); padding: 22px 20px calc(22px + var(--sab)); display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; animation: up .25s cubic-bezier(.2, 1.4, .4, 1); }
@media (min-width: 700px) { .panel { align-items: center; } .sheet { width: min(560px, 92vw); border: 5px solid var(--ink); border-radius: 22px; box-shadow: 0 10px 0 var(--ink); } }
.sheet .btn { background: var(--field); color: var(--paper); box-shadow: 0 5px 0 var(--ink); }
.sheet .btn.primary { background: var(--btn); color: var(--ink); box-shadow: 0 5px 0 var(--ink); }
.sheet .btn:focus-visible { outline-color: var(--ink); }
.sheet .key { background: rgba(59, 7, 23, .18); }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet h2 { margin: 0; font-size: 34px; font-weight: 900; }
.sheet p { margin: 0; font-weight: 700; font-size: 17px; }
.sheet .col { display: flex; flex-direction: column; gap: 12px; width: min(320px, 100%); }
.result { font-size: 68px; font-weight: 900; line-height: 1; text-transform: uppercase; color: var(--field); text-shadow: 0 5px 0 var(--ink); animation: stamp .45s cubic-bezier(.2, 1.6, .4, 1); }
.result.ace { color: var(--btn); -webkit-text-stroke: 2px var(--ink); }
.result.over { color: var(--deep); font-size: 54px; }
@keyframes stamp { from { transform: scale(2.2) rotate(-8deg); opacity: 0; } }
.stars { display: flex; gap: 6px; font-size: 48px; line-height: 1; }
.stars b, .stars i { font-style: normal; display: inline-block; animation: star .4s calc(.35s + var(--d, 0) * .18s) cubic-bezier(.2, 1.7, .4, 1) both; }
.stars b { color: var(--btn); -webkit-text-stroke: 2px var(--ink); text-shadow: 0 4px 0 var(--ink); }
.stars i { color: var(--cream2); -webkit-text-stroke: 2px rgba(59, 7, 23, .3); }
@keyframes star { from { transform: scale(0) rotate(-40deg); } }
.seq { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.seq .li { display: flex; flex-direction: column; align-items: center; padding: 4px 4px 2px; border-radius: 12px; background: var(--cream2); border: 2px solid var(--ink); animation: pop .3s calc(var(--d, 0) * .08s) cubic-bezier(.2, 1.6, .4, 1) both; }
.seq .li canvas:last-child { margin-top: -8px; }
.seq canvas {  }
.winbtns { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; margin-top: 6px; }
.endpanel:empty { display: none; }
.lb { width: 100%; max-width: 420px; }
.lb:empty { display: none; }
.lb h3 { margin: 4px 0; }
.lb ol { list-style: none; margin: 0; padding: 0; }
.lb li { display: grid; grid-template-columns: 2em 1fr auto auto; gap: 10px; padding: 6px 10px; border-radius: 8px; font-weight: 700; text-align: left; }
.lb li:nth-child(odd) { background: rgba(59, 7, 23, .08); }
.lb li.me { background: var(--btn); color: var(--ink); }
.bodycard { display: flex; gap: 14px; align-items: center; text-align: left; width: min(500px, 100%); padding: 10px 14px; border-radius: 14px; background: #fff; border: 3px solid var(--ink); box-shadow: 0 4px 0 var(--ink); }
.bodycard .becomes { display: flex; align-items: center; flex: none; color: var(--field); }
.bodycard .arrow { width: 22px; height: 22px; margin: 0 -2px; }
#cardbody { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.bodycard h3 { margin: 0 0 2px; font-size: 22px; }
.bodycard p { font-size: 16px; }
.bodycard .ic canvas { display: block;  }
.intro { max-width: 480px; }
#credit-list p { font-size: 15px; font-weight: 700; margin: 4px 0; }

@media (max-width: 560px) { #hud .title .nm { display: none; } }
.banner { position: absolute; left: 0; right: 0; top: 38%; text-align: center; font-weight: 900; font-size: clamp(26px, 6vw, 56px); color: var(--paper); text-shadow: 0 4px 0 var(--deep), 0 0 18px rgba(59, 7, 23, .4); opacity: 0; pointer-events: none; }
.banner.show { animation: banner 1.8s ease forwards; }
@keyframes banner { 0% { opacity: 0; transform: scale(1.4); } 12%, 70% { opacity: 1; transform: scale(1); } 100% { opacity: 0; transform: translateY(-20px); } }
body:not(.land) .homechips { margin-top: auto; }
@media (max-width: 380px) {
  body.touch .pads { padding-left: calc(10px + var(--sal)); padding-right: calc(10px + var(--sar)); }
  .padl, .padr { gap: 8px; }
  .pad { width: 70px; height: 76px; }
  .pad.jump { width: 94px; height: 94px; }
  .pad.die { width: 62px; height: 62px; font-size: 15px; }
}
.key[data-k]::before { content: attr(data-k); }
.chip.icon .mi { display: inline-flex; }
#mute-btn.off { opacity: .7; }

/* controller: prompts in the pad's glyphs; the focused control shows the press glyph */
body.pad-mode .btn .key, body.pad-mode .chip .key, body.pad-mode .pick .key { display: none; }
body.pad-mode button:focus { outline: 4px solid var(--paper); outline-offset: 3px; }
body.pad-mode button:focus::after { content: var(--glyph-a); margin-left: .5em; padding: 0 .35em; border-radius: .35em; background: rgba(59, 7, 23, .22); font-size: .72em; }
body.pad-mode .keys { display: flex; }
body.pad-mode #picker.choosing .pick.sel::after { content: var(--glyph-a); margin-left: .2em; padding: 0 .35em; border-radius: .35em; background: rgba(59, 7, 23, .22); font-size: .8em; }

/* ?tweaks Options panel */
.tweaks { position: fixed; right: calc(10px + var(--sar)); bottom: calc(10px + var(--sab)); z-index: 50; display: grid; gap: 6px; padding: 10px; background: var(--deep); color: var(--paper); border-radius: 8px; font: 700 14px/1.2 Nunito, sans-serif; }
.tweaks button { font: inherit; padding: 8px 10px; border: 0; border-radius: 6px; background: var(--btn); color: var(--ink); cursor: pointer; text-align: left; }

/* chips and bars inside cream sheets */
.sheet .chip { background: var(--field); color: var(--paper); }

/* narrow phones: the HUD and picker pieces tighten */
@media (max-width: 420px) {
  #hud { gap: 8px; }
  #hud .title { font-size: 17px; }
  .runs { font-size: 16px; gap: 4px; }
  .runs b#runs { font-size: 24px; }
  .runs .par { font-size: 14px; }
  .clock { min-width: 3.6em; font-size: 15px; }
  .pick { padding-right: 12px; font-size: 18px; }
}
/* short screens (phone landscape): panels compact so every button stays on screen */
@media (max-height: 520px) {
  .sheet { gap: 6px; padding-top: 12px; padding-bottom: calc(12px + var(--sab)); }
  .sheet h2 { font-size: 26px; }
  .result { font-size: 44px; }
  .result.over { font-size: 36px; }
  #wintitle { font-size: 22px; }
  .stars { font-size: 32px; }
  .seq .li canvas:first-child { width: 30px !important; height: 30px !important; }
  .seq .li canvas:last-child { width: 20px !important; height: 20px !important; }
  .bodycard { padding: 6px 10px; }
  .bodycard .becomes canvas { width: 44px !important; height: 44px !important; }
  .bodycard p { font-size: 14px; }
  #cardbody { gap: 6px; }
  .btn { min-height: 44px; padding: .5em 1.1em; }
}
