:root {
  --ink: #2a1d3a;
  --sun: #ffcc33;
  --sun-deep: #f5a400;
  --card: #fffaf0;
  --muted: #6b5b7b;
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #6ec4ff;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
/* Never wider than 9:16 so the full 640-unit-tall play area always fits (landscape phones get a centred column). */
#app { position: fixed; inset: 0; max-width: min(520px, 56.25vh); max-width: min(520px, 56.25dvh); margin: 0 auto; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }

#hud {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: calc(env(safe-area-inset-top) + 10px) 56px 0 14px;
  pointer-events: none;
}
.stat { display: flex; flex-direction: column; line-height: 1; }
.stat.right { align-items: flex-end; }
.label { font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; opacity: 0.75; }
#height, #score {
  font-size: 30px; font-weight: 900; color: #fff;
  text-shadow: 0 2px 0 var(--ink), 0 0 6px rgb(42 29 58 / 0.4);
  font-variant-numeric: tabular-nums;
}
.stat .label { color: #fff; text-shadow: 0 1px 0 var(--ink); }

#meter {
  position: absolute; right: 12px; top: calc(env(safe-area-inset-top) + 64px); bottom: 40px;
  width: 8px; border-radius: 4px; background: rgb(255 255 255 / 0.35);
  pointer-events: none;
}
#meter-fill {
  position: absolute; inset: 0; border-radius: 4px; background: var(--sun);
  transform-origin: bottom; transform: scaleY(0);
}
#meter .moon {
  position: absolute; top: -18px; left: 50%; width: 16px; height: 16px; margin-left: -8px;
  border-radius: 50%; background: #fff4c4; box-shadow: 0 0 10px #fff4c4;
}
#meter-cat {
  position: absolute; left: 50%; width: 14px; height: 14px; margin: 0 0 -7px -7px;
  border-radius: 50%; background: #f39a3d; border: 2px solid #fff;
}
#hud[hidden], #hud[hidden] ~ #meter { display: none; }

#mute {
  position: absolute; top: calc(env(safe-area-inset-top) + 8px); right: 8px;
  width: 36px; height: 36px; border: 0; border-radius: 50%;
  background: rgb(255 255 255 / 0.4); font-size: 18px; cursor: pointer;
}

.screen {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 20px;
  background: rgb(42 29 58 / 0.25);
  overflow-y: auto;
}
.screen[hidden] { display: none; }
.card {
  width: 100%; max-width: 360px; background: var(--card); border-radius: 24px;
  padding: 22px 20px 20px; text-align: center;
  box-shadow: 0 6px 0 rgb(42 29 58 / 0.25), 0 20px 40px rgb(42 29 58 / 0.25);
}
.hero { width: 72px; height: 72px; }
h1, h2 { margin: 4px 0 8px; font-weight: 900; letter-spacing: -0.01em; }
h1 { font-size: 40px; color: var(--sun-deep); text-shadow: 0 2px 0 var(--ink); }
h2 { font-size: 28px; }
.lead { margin: 0 0 10px; font-size: 17px; font-weight: 600; line-height: 1.35; }
.how { margin: 0 0 12px; font-size: 14px; color: var(--muted); line-height: 1.35; }
.legend { list-style: none; margin: 0 0 16px; padding: 0; text-align: left; }
.legend li { display: flex; align-items: center; gap: 8px; padding: 2px 0; font-size: 14px; }
.legend canvas { width: 36px; height: 36px; flex: none; }
.legend span { flex: 1; }
.legend b { font-weight: 900; color: #1f8a3d; }
.final { margin: 6px 0 4px; display: flex; flex-direction: column; align-items: center; }
.final .label { color: var(--muted); }
#end-score { font-size: 56px; font-weight: 900; line-height: 1.05; font-variant-numeric: tabular-nums; }
#end-best { margin: 0 0 16px; font-weight: 700; color: var(--muted); }
#end[data-result="won"] h2 { color: var(--sun-deep); }
.play {
  width: 100%; border: 0; border-radius: 16px; padding: 14px 18px;
  font: inherit; font-size: 20px; font-weight: 900; color: var(--ink);
  background: var(--sun); box-shadow: 0 5px 0 var(--sun-deep); cursor: pointer;
}
.play:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--sun-deep); }
.play:focus-visible, #mute:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
@media (max-height: 700px) {
  .hero { display: none; }
  h1 { font-size: 32px; }
  .card { padding: 16px 16px 16px; }
  .legend li { font-size: 13px; padding: 0; }
  .legend canvas { width: 30px; height: 30px; }
}
