:root {
  --bg: #F3ECDF;
  --ink: #26302A;
  --muted: #6A7468;
  --card: #FFFCF6;
  --line: rgba(38, 48, 42, 0.12);
  --green: #5E9C5B;
  --green-d: #467F45;
  --accent: #E07A5F;
  --accent-d: #B9573C;
  --chrome: 150px;
  --stage-w: min(calc(100vw - 32px), calc((100svh - var(--chrome)) * 16 / 9), 1280px);
  --font: ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }

body {
  background:
    radial-gradient(1100px 520px at 50% -12%, #FFF9EE 0%, rgba(255, 249, 238, 0) 65%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--green-d); text-decoration: none; font-weight: 500; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }

.app {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: max(12px, env(safe-area-inset-top)) 16px max(14px, env(safe-area-inset-bottom));
}

/* ---------- Top bar ---------- */
.topbar {
  width: var(--stage-w);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.brand:hover { text-decoration: none; }
.brand img { border-radius: 10px; box-shadow: 0 6px 14px -8px rgba(70, 127, 69, 0.8); }
.top-actions { display: flex; gap: 8px; }

.icon-btn {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease, opacity 0.2s ease;
}
.icon-btn svg { width: 20px; height: 20px; fill: currentColor; }
.icon-btn:hover:not(:disabled) { transform: translateY(-1px); background: #fff; }
.icon-btn:disabled { opacity: 0.35; cursor: default; }
.icon-btn:focus-visible, .btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
#btn-sound .ic-off { display: none; }
#btn-sound.is-muted .ic-on { display: none; }
#btn-sound.is-muted .ic-off { display: block; }

/* ---------- Stage ---------- */
.stage-wrap {
  position: relative;
  width: var(--stage-w);
  aspect-ratio: 16 / 9;
  border-radius: 24px;
  overflow: hidden;
  background: #EEF1E4;
  box-shadow:
    0 0 0 1px rgba(38, 48, 42, 0.08),
    0 24px 60px -28px rgba(70, 55, 30, 0.45),
    0 3px 8px rgba(70, 55, 30, 0.06);
  container-type: inline-size;
  user-select: none;
  -webkit-user-select: none;
}
canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: pointer;
}

/* ---------- HUD ---------- */
.hud { position: absolute; inset: 0; pointer-events: none; }
.hud[hidden] { display: none; }
.hud-left {
  position: absolute;
  top: 2.2cqw;
  left: 2.2cqw;
  display: flex;
  gap: 0.8cqw;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.55em;
  padding: 0.45em 1em;
  border-radius: 999px;
  background: rgba(255, 252, 246, 0.9);
  border: 1px solid var(--line);
  box-shadow: 0 6px 16px -10px rgba(70, 55, 30, 0.5);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  font-size: clamp(12px, 1.9cqw, 21px);
  font-weight: 600;
  line-height: 1;
}
.pill-label {
  font-size: 0.7em;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.pill-speed { color: var(--accent-d); }
.pill.bump { animation: bump 0.35s ease; }

.hud-lives { position: absolute; top: 2.2cqw; right: 2.2cqw; gap: 0.35em; padding: 0.4em 0.8em; }
.egg {
  width: 0.9em;
  height: 1.15em;
  border-radius: 50% 50% 50% 50% / 62% 62% 40% 40%;
  background:
    radial-gradient(circle at 35% 40%, #9CC48F 0 12%, transparent 13%),
    radial-gradient(circle at 65% 65%, #9CC48F 0 10%, transparent 11%),
    radial-gradient(circle at 60% 28%, #9CC48F 0 7%, transparent 8%),
    #FBF4E2;
  box-shadow: inset 0 0 0 2px var(--green), inset -3px -4px 0 rgba(94, 156, 91, 0.18);
  transition: opacity 0.3s ease, transform 0.3s ease, filter 0.3s ease;
}
.egg.lost { opacity: 0.28; filter: grayscale(1); transform: scale(0.82) rotate(-12deg); }
.egg.crack { animation: crack 0.5s ease; }

.timer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: max(6px, 0.9cqw);
  background: rgba(38, 48, 42, 0.08);
}
.timer-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--green), #8CC084);
  transform-origin: left center;
  transform: scaleX(1);
}
.timer.low .timer-fill { background: linear-gradient(90deg, var(--accent-d), var(--accent)); }

/* ---------- Overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3cqw;
  background: rgba(243, 236, 223, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fade 0.25s ease;
}
.overlay[hidden] { display: none; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: clamp(14px, 2.4cqw, 28px);
  padding: clamp(14px, 3.4cqw, 40px);
  box-shadow: 0 30px 60px -30px rgba(70, 55, 30, 0.5);
  max-width: min(92%, 600px);
  max-height: 100%;
  overflow: auto;
  animation: pop 0.4s cubic-bezier(0.2, 1.3, 0.4, 1);
}
.card-wide { max-width: min(94%, 720px); }
.card-center { text-align: center; }

.overlay-title {
  justify-content: flex-start;
  padding-left: 6cqw;
  background: linear-gradient(90deg, rgba(243, 236, 223, 0.94) 0%, rgba(243, 236, 223, 0.7) 40%, rgba(243, 236, 223, 0) 66%);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
.overlay-title .card {
  background: none;
  border: 0;
  box-shadow: none;
  padding: 0;
  max-width: 46cqw;
  overflow: visible;
  animation: rise 0.6s cubic-bezier(0.2, 1, 0.3, 1);
}

.eyebrow {
  margin: 0;
  font-size: clamp(10px, 1.35cqw, 14px);
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent-d);
}
h1 {
  margin: 0.12em 0 0.22em;
  font-size: clamp(34px, 9cqw, 112px);
  line-height: 0.9;
  font-weight: 700;
  letter-spacing: -0.025em;
}
h1 span { color: var(--green); }
h2 {
  margin: 0.25em 0 0.35em;
  font-size: clamp(18px, 3.2cqw, 34px);
  line-height: 1.1;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.lead {
  margin: 0 0 1.3em;
  max-width: 40ch;
  font-size: clamp(12px, 1.85cqw, 20px);
  line-height: 1.45;
  color: var(--muted);
}
.muted { margin: 0 0 1em; color: var(--muted); font-size: clamp(12px, 1.6cqw, 17px); line-height: 1.45; }

.btn-row { display: flex; flex-wrap: wrap; gap: 0.7em; }
.btn-row.center { justify-content: center; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45em;
  padding: 0.72em 1.45em;
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-size: clamp(13px, 1.8cqw, 19px);
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}
.btn svg { width: 1.05em; height: 1.05em; fill: currentColor; }
.btn-primary {
  background: var(--green);
  color: #fff;
  box-shadow: 0 4px 0 var(--green-d), 0 12px 22px -12px rgba(70, 127, 69, 0.9);
}
.btn-primary:hover { transform: translateY(-1px); background: #66A663; }
.btn-primary:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--green-d); }
.btn-ghost {
  background: rgba(255, 255, 255, 0.75);
  color: var(--ink);
  box-shadow: inset 0 0 0 1.5px var(--line);
}
.btn-ghost:hover { background: #fff; transform: translateY(-1px); }
.btn-ghost:active { transform: translateY(1px); }

.best { margin: 1.2em 0 0; color: var(--muted); font-size: clamp(11px, 1.5cqw, 15px); }
.best strong { color: var(--ink); }

kbd {
  display: inline-block;
  min-width: 1.8em;
  padding: 0.12em 0.45em;
  margin: 0 0.12em;
  border-radius: 6px;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: 0 2px 0 var(--line);
  font: inherit;
  font-size: 0.85em;
  font-weight: 600;
  text-align: center;
}

.games {
  list-style: none;
  margin: 0 0 1em;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.55em;
}
.games li {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 0.6em;
  align-items: center;
  padding: 0.65em 0.75em;
  border-radius: 14px;
  background: #F6F0E3;
  font-size: clamp(11px, 1.5cqw, 16px);
}
.games .g-ico { grid-row: span 2; font-size: 1.7em; line-height: 1; }
.games small { color: var(--muted); font-size: 0.85em; line-height: 1.25; }
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5em 1.4em;
  margin: 0 0 1.3em;
  color: var(--muted);
  font-size: clamp(11px, 1.45cqw, 15px);
}

.final-score {
  font-size: clamp(54px, 13cqw, 150px);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.04em;
  color: var(--ink);
  margin: 0.08em 0 0.05em;
}
.rank {
  display: inline-block;
  margin: 0 0 0.7em;
  padding: 0.35em 0.95em;
  border-radius: 999px;
  background: rgba(94, 156, 91, 0.14);
  color: var(--green-d);
  font-weight: 600;
  font-size: clamp(13px, 1.9cqw, 20px);
}
.new-best {
  display: inline-block;
  margin-left: 0.4em;
  padding: 0.15em 0.6em;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.8em;
  font-weight: 600;
  animation: bump 0.6s ease 0.2s both;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 4cqw;
  transform: translate(-50%, 20px);
  padding: 0.6em 1.2em;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-size: clamp(12px, 1.6cqw, 16px);
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Footer ---------- */
.foot {
  width: var(--stage-w);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
}
.foot .dot { opacity: 0.6; }
.rotate-hint { display: none; }

/* ---------- Responsive ---------- */
@media (max-height: 540px) {
  :root { --chrome: 72px; }
  .foot { display: none; }
  .app { gap: 8px; }
  .icon-btn { width: 36px; height: 36px; }
  .brand { font-size: 18px; }
  .brand img { width: 28px; height: 28px; }
}
@media (orientation: portrait) and (max-width: 640px) {
  .rotate-hint { display: inline; }
  .stage-wrap { border-radius: 16px; }
  .overlay-title { padding-left: 4cqw; background: linear-gradient(90deg, rgba(243, 236, 223, 0.95) 0%, rgba(243, 236, 223, 0.75) 55%, rgba(243, 236, 223, 0.1) 80%); }
  .overlay-title .card { max-width: 60cqw; }
  .overlay-title .lead, .overlay-title .best { display: none; }
  .games { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- Motion ---------- */
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(0.92) translateY(8px); } }
@keyframes rise { from { opacity: 0; transform: translateY(18px); } }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.18); } 100% { transform: scale(1); } }
@keyframes crack {
  0% { transform: scale(1); }
  30% { transform: scale(1.25) rotate(10deg); }
  60% { transform: scale(0.9) rotate(-14deg); }
  100% { transform: scale(0.82) rotate(-12deg); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* Rumbleberry local adaptation: whole-page game screen and roomy physical controls. */
:root{--bg:#edf0df;--chrome:205px;--stage-w:min(calc(100vw - 32px),calc((100svh - var(--chrome))*16/9),1280px)}
body{font-size:16px;background:radial-gradient(ellipse at 50% 0,#fff5dd,transparent 60%),#e8eddd}
.app{gap:12px}.brand>span{line-height:1.05;font-size:24px;font-weight:750;letter-spacing:-1px}.brand small{display:block;font-size:11px;letter-spacing:2px;margin-top:6px;font-weight:600}.brand img{width:40px;height:40px}
.stage-wrap{border:5px solid #fffaf0;box-shadow:0 0 0 1px #3c5a3730,0 20px 65px -25px #3d5a3c70}
.overlay-title{background:linear-gradient(90deg,#fff8e8eb 0%,#f3efdfc4 41%,#f3efdf00 70%)}
h1{font-size:clamp(30px,7cqw,92px);line-height:.98;letter-spacing:-3px}.overlay-title .card{max-width:50cqw}.lead{font-size:clamp(14px,1.65cqw,19px)}.eyebrow{font-size:clamp(12px,1.3cqw,14px)}.best{font-size:clamp(12px,1.3cqw,15px)}
.practice-menu{margin-top:15px;font-size:14px;max-width:360px}.practice-menu summary{color:#467F45;font-weight:650;cursor:pointer}.practice-menu p{font-size:12px;margin:5px 0 8px;line-height:1.4}.practice-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:6px}.practice-btn{border:1px solid #467f4540;background:#fff9eb;color:#26302a;border-radius:8px;padding:7px 8px;font:inherit;font-size:13px;cursor:pointer}.practice-btn:hover{background:#dce9d0}.practice-menu[open]{position:relative;background:#fff9efed;border-radius:9px;padding:10px;margin-top:8px}.practice-menu[open]~*{display:none}
.control-deck{width:var(--stage-w);display:grid;grid-template-columns:1fr auto;align-items:center;gap:3px 16px;padding:5px 4px 0}.live-status{display:flex;flex-direction:column;gap:2px}.live-status strong{font-size:18px;color:#304b2a}.live-status span{font-size:14px;color:#596651}.touch-controls{display:flex;gap:8px}.touch-controls button{font:inherit;font-size:14px;font-weight:700;padding:12px 18px;min-width:60px;border:1px solid #47644344;background:#fffcf2;color:#304b2a;border-radius:13px;box-shadow:0 3px 0 #b6c5a0;touch-action:none;user-select:none;-webkit-user-select:none;cursor:pointer}.touch-controls button:active{transform:translateY(2px);box-shadow:0 1px 0 #b6c5a0}.touch-controls #action-button{background:#5e9c5b;color:white;min-width:120px}.touch-controls button:disabled{opacity:.35;cursor:default}.touch-controls button:focus-visible,.practice-btn:focus-visible,summary:focus-visible{outline:3px solid #E07A5F;outline-offset:3px}.keyboard-note{grid-column:1/-1;font-size:12px;color:#65725b;margin:7px 0 0}.foot{font-size:12px}.games li{font-size:clamp(13px,1.5cqw,16px)}.games small{font-size:12px}.controls{font-size:13px}
@media(orientation:portrait) and (max-width:640px){:root{--chrome:245px;--stage-w:calc(100vw - 24px)}.app{padding-left:12px;padding-right:12px;justify-content:flex-start;padding-top:18px;gap:14px}.topbar{padding-bottom:2px}.brand>span{font-size:22px}.brand small{font-size:9px;letter-spacing:1.7px}.brand img{width:36px;height:36px}.stage-wrap{border-radius:16px;border-width:3px;overflow:visible}.stage-wrap canvas{border-radius:13px}.overlay{border-radius:13px;overflow:auto}.overlay-title{padding:16px;overflow:visible}.overlay-title .card{max-width:62cqw}.overlay-title h1{font-size:35px;letter-spacing:-1.4px}.overlay-title .lead,.overlay-title .best{display:none}.overlay-title .eyebrow{font-size:10px;letter-spacing:1px}.overlay-title .btn{font-size:13px;padding:9px 13px}.overlay-title .practice-menu{font-size:12px;margin-top:12px}.practice-menu[open]{z-index:3;box-shadow:0 10px 20px #365c3333;min-width:270px}.practice-menu p{font-size:12px}.practice-btn{font-size:12px;padding:8px}.control-deck{display:flex;flex-direction:column;align-items:stretch;gap:13px;padding:8px 3px}.live-status strong{font-size:20px}.live-status span{font-size:14px;min-height:42px}.touch-controls{justify-content:space-between;gap:10px}.touch-controls button{flex:1;padding:16px 12px;font-size:16px}.touch-controls #action-button{flex:1.7}.keyboard-note{font-size:12px;line-height:1.7;margin:0}.foot{font-size:12px;line-height:1.7}.rotate-hint{flex-basis:100%;text-align:center;font-size:13px;color:#467f45}.card-wide{max-height:100%;padding:14px}.card-wide h2{font-size:20px}.card-wide .games{gap:5px}.card-wide .games li{padding:7px;font-size:13px}.card-wide .games small{font-size:12px}.card-wide .controls{font-size:12px}.card-wide .muted{font-size:14px}}
@media(max-height:540px) and (orientation:landscape){:root{--chrome:102px;--stage-w:min(calc(100vw - 28px),calc((100svh - var(--chrome))*16/9),1280px)}.app{gap:6px;padding-top:7px;padding-bottom:7px;flex-direction:column}.brand>span{font-size:18px}.brand small{display:none}.brand img{width:28px;height:28px}.control-deck{grid-template-columns:1fr auto;gap:1px 12px}.live-status strong{font-size:14px}.live-status span{font-size:12px}.touch-controls button{padding:7px 14px;font-size:13px}.touch-controls #action-button{min-width:100px}.keyboard-note,.foot{display:none}.topbar .icon-btn{width:30px;height:30px}.practice-menu{margin-top:8px;font-size:12px}.practice-menu[open]{padding:6px}.practice-menu p{display:none}.practice-btn{font-size:11px;padding:5px}.overlay-title .best{display:none}.overlay-title .lead{font-size:14px;line-height:1.3;margin-bottom:10px}.overlay-title .eyebrow{font-size:11px}.overlay-title h1{font-size:clamp(30px,7cqw,75px)}.btn{font-size:14px;padding:9px 14px}.stage-wrap{border-width:3px}}

/* Keep bitmap intrinsic dimensions out of the responsive stage layout. */
.stage-wrap canvas{position:absolute;inset:0;width:100%;height:100%}

.stage-wrap{z-index:1}
/* A short landscape screen gives the open practice chooser its own compact view. */
@media(max-height:540px) and (orientation:landscape){
 .overlay-title:has(.practice-menu[open]) .lead,.overlay-title:has(.practice-menu[open]) .best,.overlay-title:has(.practice-menu[open]) .btn-row,.overlay-title:has(.practice-menu[open]) .eyebrow{display:none}
 .overlay-title:has(.practice-menu[open]) h1{font-size:32px;line-height:.98;margin:0 0 12px;letter-spacing:-1px}
 .overlay-title .practice-menu[open]{margin:0;padding:9px;min-width:240px}
 .overlay-title .practice-menu[open] summary{font-size:13px}
 .overlay-title .practice-menu[open] .practice-grid{margin-top:8px}
}
