:root {
  --ink: #1d2b53;
  --paper: #fffaf0;
  --red: #e63946;
  --sky: #3fa9f5;
  --sky-soft: #e3f2ff;
  --good: #2fbf71;
  --ok: #f4b400;
  --bad: #ef476f;
  --shadow: 0 6px 0 rgba(29, 43, 83, 0.22), 0 16px 34px rgba(29, 43, 83, 0.18);
  --display: 'Fredoka', 'Nunito', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #bfe2f8;
  color: var(--ink);
  font-family: 'Nunito', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 20; } /* confetti, above everything */
.hidden { display: none !important; }
/* tap modes (keyboard / touch): no calories, a camera dare instead */
body[data-mode="keyboard"] .kcal-only, body[data-mode="touch"] .kcal-only { display: none !important; } /* taps aren't exercise */
.kb-only { display: none !important; }
body[data-mode="keyboard"] .kb-only, body[data-mode="touch"] .kb-only { display: revert !important; }
body[data-mode="keyboard"] #btnAgain, body[data-mode="touch"] #btnAgain { background: #fff; color: var(--ink); }
.dare { background: #fff1e0; border: 2px dashed var(--red); border-radius: 16px; padding: 12px 16px; margin: 0 auto 16px; max-width: 440px; }
.dare p { margin: 0 0 10px; font-weight: 700; }

.card {
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 22px;
  box-shadow: var(--shadow);
}
.pill {
  font-family: var(--display);
  font-weight: 600;
  font-size: 20px;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 999px;
  padding: 6px 16px;
  box-shadow: 0 4px 0 rgba(29, 43, 83, 0.22);
  white-space: nowrap;
}
.pill.hot { background: #ffe1e6; animation: pulse 0.6s ease-in-out infinite alternate; }

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  top: 16px; left: 16px; right: 16px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}
#hud .col { flex: 0 1 540px; display: flex; flex-direction: column; align-items: center; gap: 10px; min-width: 0; }
#phaseCard {
  width: 100%;
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 2px 14px;
  padding: 12px 18px 14px;
}
#phaseCard .icon {
  grid-row: 1;
  width: 64px; height: 64px;
  padding: 6px;
  border-radius: 16px;
  background: var(--sky-soft);
  color: var(--ink);
}
#phaseCard .icon svg, .ic svg { width: 100%; height: 100%; display: block; }
#phaseCard .label { font-size: 12px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; opacity: 0.6; }
#phaseCard .name { font-family: var(--display); font-weight: 700; font-size: 28px; line-height: 1.05; }
#phaseCard .hint { font-size: 14px; font-weight: 700; line-height: 1.3; margin-top: 2px; }
#phaseCard .bar {
  grid-column: 1 / -1;
  height: 8px;
  margin-top: 8px;
  border-radius: 99px;
  background: #e6e1d5;
  overflow: hidden;
}
#phaseCard .bar i { display: block; height: 100%; width: 0; background: var(--sky); border-radius: inherit; }

#sync {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px 6px 8px;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 999px;
  box-shadow: 0 4px 0 rgba(29, 43, 83, 0.22);
  font-family: var(--display);
  font-weight: 600;
}
#sync .meter { position: relative; width: min(170px, 34vw); height: 14px; border-radius: 99px; background: #e6e1d5; overflow: hidden; }
#sync .meter i { display: block; height: 100%; width: 0; border-radius: inherit; transition: background 0.2s; }
#sync.good .meter i { background: var(--good); }
#sync.ok .meter i, #sync.low .meter i { background: #ff9f43; }
#sync.bad .meter i { background: var(--bad); }
#sync.bad #syncLabel { color: var(--bad); }
#syncLabel { white-space: nowrap; }
#sync.low #syncLabel { color: #d9480f; }

#bankArrow {
  font-family: var(--display);
  font-weight: 700;
  font-size: 34px;
  color: #fff;
  background: var(--sky);
  border: 3px solid var(--ink);
  border-radius: 18px;
  padding: 4px 22px;
  box-shadow: 0 5px 0 rgba(29, 43, 83, 0.25);
  white-space: nowrap;
}
#bankArrow.right { background: #8b5cf6; }

/* on-beat prompt: UP / DOWN while flapping, breathing or stretching on holds */
#beatCue {
  font-family: var(--display);
  font-weight: 700;
  font-size: 30px;
  min-width: 170px;
  text-align: center;
  color: #fff;
  background: var(--good);
  border: 3px solid var(--ink);
  border-radius: 18px;
  padding: 2px 20px;
  box-shadow: 0 5px 0 rgba(29, 43, 83, 0.25);
  white-space: nowrap;
}
#beatCue.down { background: var(--sky); }
#beatCue.soft { background: #8b5cf6; font-size: 24px; }

#next {
  position: fixed;
  left: 50%; top: 42%;
  transform: translate(-50%, -50%);
  display: grid;
  grid-template-columns: auto auto;
  grid-template-areas: 'nl nl' 'ic nn' 'ic cd';
  align-items: center;
  gap: 0 14px;
  padding: 14px 22px;
  border-color: var(--ink);
  background: #fff7d6;
}
#next .nl { grid-area: nl; font-size: 13px; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; opacity: 0.7; }
#next .ic { grid-area: ic; width: 76px; height: 76px; }
#next .nn { grid-area: nn; font-family: var(--display); font-weight: 700; font-size: 30px; }
#next .cd { grid-area: cd; font-family: var(--display); font-weight: 700; font-size: 40px; color: var(--red); line-height: 1; }

#warn {
  position: fixed;
  left: 50%; bottom: 13%;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  background: var(--bad);
  color: #fff;
  font-family: var(--display);
  font-weight: 600;
  font-size: 22px;
  padding: 10px 22px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  box-shadow: 0 5px 0 rgba(29, 43, 83, 0.3);
  text-align: center;
  animation: shake 0.5s ease-in-out infinite;
}

#toast {
  position: fixed;
  left: 50%; top: 58%;
  transform: translate(-50%, 10px);
  font-family: var(--display);
  font-weight: 700;
  font-size: 24px;
  color: var(--ink);
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 16px;
  padding: 8px 18px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  white-space: nowrap;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: #ffe1e6; }

#center {
  position: fixed;
  left: 50%; top: 45%;
  transform: translate(-50%, -50%);
  font-family: var(--display);
  font-weight: 700;
  font-size: min(160px, 26vw);
  color: #fff;
  -webkit-text-stroke: 6px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 8px 0 rgba(29, 43, 83, 0.25);
  pointer-events: none;
  white-space: nowrap;
}
#center.small { font-size: min(76px, 13vw); -webkit-text-stroke-width: 5px; }
#center.pop { animation: bigpop 1s ease-out forwards; }

/* webcam preview */
#cam {
  position: fixed;
  right: 16px; bottom: 16px;
  width: min(240px, 34vw);
  aspect-ratio: 4 / 3;
  border: 3px solid var(--ink);
  border-radius: 18px;
  overflow: hidden;
  background: #233;
  box-shadow: var(--shadow);
  transition: width 0.3s;
}
#cam.big { width: min(460px, 80vw); right: 50%; transform: translateX(50%); bottom: 24px; }
#cam .mirror { position: absolute; inset: 0; transform: scaleX(-1); }
#cam video, #cam canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#cam .camlabel {
  position: absolute; left: 8px; top: 8px;
  background: rgba(29, 43, 83, 0.75); color: #fff;
  font-size: 12px; font-weight: 800; padding: 2px 8px; border-radius: 99px;
}

#keys {
  position: fixed; right: 16px; bottom: 16px;
  padding: 10px 16px;
  display: flex; flex-direction: column; gap: 2px;
  font-weight: 800;
}
#keys b { font-family: var(--display); font-size: 18px; }
#keys kbd { font-size: 15px; }

#hud .stack { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.pill.kcal { background: #fff1e0; }
#cam .camdebug {
  position: absolute; left: 8px; right: 8px; bottom: 8px;
  background: rgba(0, 0, 0, 0.6); color: #fff;
  font: 700 11px/1.3 ui-monospace, Menlo, monospace; padding: 3px 6px; border-radius: 6px;
}

#mute { position: fixed; left: 16px; bottom: 16px; cursor: pointer; font-size: 18px; padding: 6px 12px; }

/* ---------- screens ---------- */
.screen {
  position: fixed; inset: 0;
  display: flex;
  padding: 16px;
  background: rgba(29, 43, 83, 0.18);
  overflow-y: auto;
}
.panel { width: 100%; max-width: 580px; margin: auto; padding: 28px 30px; text-align: center; }  /* margin:auto centers but still scrolls on short screens */
.kicker { font-size: 13px; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; color: var(--red); }
h1 { font-family: var(--display); font-weight: 700; font-size: clamp(44px, 9vw, 68px); line-height: 1; margin: 6px 0 10px; }
h2 { font-family: var(--display); font-weight: 700; font-size: 28px; margin: 0 0 4px; }
.lead { font-size: 17px; font-weight: 700; line-height: 1.45; margin: 0 auto 18px; max-width: 46ch; }
.fine { font-size: 13px; font-weight: 600; opacity: 0.65; line-height: 1.45; margin: 14px auto 0; max-width: 52ch; }
.status { min-height: 1.4em; font-weight: 800; margin: 12px 0 0; }
.status.err { color: var(--bad); }

.moves { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin-bottom: 22px; }
.mv { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 84px; font-weight: 800; font-size: 13px; }
.mv .ic { width: 60px; height: 60px; padding: 6px; border-radius: 16px; background: var(--sky-soft); }

.actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.btn {
  font-family: var(--display);
  font-weight: 600;
  font-size: 20px;
  color: var(--ink);
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 16px;
  padding: 12px 24px;
  box-shadow: 0 5px 0 var(--ink);
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.08s;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn.primary { background: var(--red); color: #fff; }
.btn.ghost { background: transparent; box-shadow: none; border-color: transparent; text-decoration: underline; text-underline-offset: 3px; }
.btn.ghost:active { transform: none; }

/* keyboard how-to */
.keylist { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 0 auto 20px; max-width: 460px; text-align: left; }
.keyrow { display: flex; align-items: center; gap: 10px; background: var(--sky-soft); border-radius: 14px; padding: 8px 12px; font-weight: 800; }
.keyrow .ic { width: 40px; height: 40px; flex: none; }
.keyrow small { display: block; font-weight: 700; opacity: 0.7; }
kbd {
  display: inline-block;
  font: 700 13px/1 ui-monospace, Menlo, monospace;
  background: #fff;
  border: 2px solid var(--ink);
  border-bottom-width: 4px;
  border-radius: 7px;
  padding: 3px 7px;
}
@media (max-width: 520px) { .keylist { grid-template-columns: 1fr; } }
.btn:focus-visible { outline: 3px solid var(--sky); outline-offset: 3px; }

/* calibration */
#calib { position: fixed; top: 16px; left: 16px; right: 16px; display: flex; justify-content: center; }
#calib .panel {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 12px 18px;
  text-align: left;
  max-width: 620px;
  margin: 0;
  padding: 16px 22px;
}
#calib .actions { grid-column: 1 / -1; justify-content: flex-start; }
#calib .btn { font-size: 17px; padding: 8px 16px; }
#calib p { margin: 0; font-weight: 700; }
#calib p.sub { margin-top: 4px; font-size: 13px; font-weight: 600; opacity: 0.65; }
#calib p.good { color: var(--good); }
#calib p.bad { color: var(--bad); }
.ring {
  --p: 0;
  flex: none;
  width: 88px; height: 88px;
  border-radius: 50%;
  padding: 8px;
  background: conic-gradient(var(--good) calc(var(--p) * 360deg), #e6e1d5 0);
}
.ring .ic { width: 100%; height: 100%; border-radius: 50%; background: var(--paper); padding: 8px; }

/* results */
.score { font-family: var(--display); font-weight: 700; font-size: 84px; line-height: 1; margin: 8px 0 4px; }
.score small { display: block; font-size: 18px; font-weight: 600; opacity: 0.6; }
.chips { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 12px 0 18px; }
.chip { background: var(--sky-soft); border-radius: 99px; padding: 6px 14px; font-weight: 800; }
.phases { display: flex; flex-direction: column; gap: 8px; margin: 0 auto 18px; max-width: 420px; }
.row { display: grid; grid-template-columns: 34px 92px 1fr 44px; align-items: center; gap: 10px; text-align: left; font-weight: 800; }
.row .ic { width: 34px; height: 34px; }
.row .track { height: 12px; background: #e6e1d5; border-radius: 99px; overflow: hidden; }
.row .track i { display: block; height: 100%; background: var(--good); border-radius: inherit; }
.row .v { text-align: right; font-variant-numeric: tabular-nums; }

/* motion */
.pop { animation: pop 0.35s ease-out; }
@keyframes pop { 0% { transform: scale(0.85); } 60% { transform: scale(1.06); } 100% { transform: scale(1); } }
#next .cd.pop { display: inline-block; }
#next.card { animation: slidein 0.3s ease-out; }
@keyframes slidein { from { opacity: 0; transform: translate(-50%, -40%); } to { opacity: 1; transform: translate(-50%, -50%); } }
@keyframes bigpop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.4); }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
  35% { transform: translate(-50%, -50%) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -60%) scale(1); }
}
@keyframes shake { 0%, 100% { transform: translateX(-50%); } 25% { transform: translateX(calc(-50% - 4px)); } 75% { transform: translateX(calc(-50% + 4px)); } }
@keyframes pulse { to { transform: scale(1.08); } }

@media (max-width: 720px) {
  #hud { top: 10px; left: 10px; right: 10px; gap: 6px; }
  .pill { font-size: 16px; padding: 4px 10px; }
  #phaseCard { grid-template-columns: 48px 1fr; padding: 10px 12px; }
  #phaseCard .icon { width: 48px; height: 48px; }
  #phaseCard .name { font-size: 22px; }
  #phaseCard .hint { font-size: 12px; }
  #bankArrow { font-size: 24px; }
  #beatCue { font-size: 22px; min-width: 130px; }
  #warn { font-size: 16px; }
}
/* animated move icons: arms rotate around the shoulder */
.fig .arm, .fig .bar, .fig .body { transform-box: view-box; transform-origin: 50px 38px; }
.fig { --b: var(--beat, 0.47s); }
.fig-flap .arm.l { animation: armL var(--b) ease-in-out infinite alternate; }  /* up on one beat, down on the next */
.fig-flap .arm.r { animation: armR var(--b) ease-in-out infinite alternate; }
.fig-glide .arm.l { animation: glideL calc(var(--b) * 8) ease-in-out infinite alternate; }  /* breathe in 2 bars, out 2 bars */
.fig-glide .arm.r { animation: glideR calc(var(--b) * 8) ease-in-out infinite alternate; }
.fig-glide .body { animation: breathe calc(var(--b) * 8) ease-in-out infinite alternate; }
.fig-reach .arm.l { animation: reachL calc(var(--b) * 8) ease-in-out infinite; }
.fig-reach .arm.r { animation: reachR calc(var(--b) * 8) ease-in-out infinite; }
.fig-reach .body { animation: tall calc(var(--b) * 8) ease-in-out infinite; }
.fig-bank .bar { animation: bankLR calc(var(--b) * 16) ease-in-out infinite; }
.fig-bank-l .bar { animation: bankL calc(var(--b) * 8) ease-in-out infinite; }
.fig-bank-r .bar { animation: bankR calc(var(--b) * 8) ease-in-out infinite; }

@keyframes armL { from { transform: rotate(38deg); } to { transform: rotate(-32deg); } }
@keyframes armR { from { transform: rotate(-38deg); } to { transform: rotate(32deg); } }
@keyframes glideL { from { transform: rotate(4deg); } to { transform: rotate(-3deg); } }
@keyframes glideR { from { transform: rotate(-4deg); } to { transform: rotate(3deg); } }
@keyframes breathe { from { transform: translateY(0); } to { transform: translateY(-1.5px); } }
@keyframes reachL { 0%, 12% { transform: rotate(0); } 45%, 75% { transform: rotate(72deg); } 100% { transform: rotate(0); } }
@keyframes reachR { 0%, 12% { transform: rotate(0); } 45%, 75% { transform: rotate(-72deg); } 100% { transform: rotate(0); } }
@keyframes tall { 0%, 12% { transform: translateY(0); } 45%, 75% { transform: translateY(-3px); } 100% { transform: translateY(0); } }
@keyframes bankLR { 0%, 35% { transform: rotate(-24deg); } 50%, 85% { transform: rotate(24deg); } 100% { transform: rotate(-24deg); } }
@keyframes bankL { 0%, 10% { transform: rotate(0); } 40%, 80% { transform: rotate(-26deg); } 100% { transform: rotate(0); } }
@keyframes bankR { 0%, 10% { transform: rotate(0); } 40%, 80% { transform: rotate(26deg); } 100% { transform: rotate(0); } }

@media (prefers-reduced-motion: reduce) {
  #warn, .pill.hot { animation: none; }
  .fig * { animation: none !important; }
}

/* ---------- touch mode buttons ---------- */
html, body { -webkit-tap-highlight-color: transparent; }
#pad {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: grid;
  grid-template-columns: 1fr 1.2fr 1.6fr 1.2fr 1fr;
  gap: 8px;
  padding: 10px max(10px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  z-index: 5;
}
.pb {
  height: 74px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-family: var(--display); font-weight: 700; font-size: 15px;
  color: var(--ink);
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 18px;
  box-shadow: 0 5px 0 var(--ink);
  touch-action: none;
}
.pb.arrow { font-size: 26px; }
.pb .ic { width: 30px; height: 30px; }
.pb .fig * { animation: none !important; }
.pb.want { background: var(--good); color: #fff; animation: glow 0.94s ease-in-out infinite alternate; }
.pb.hit { animation: press 0.15s ease-out; }
.pb.want.hit { animation: press 0.15s ease-out, glow 0.94s ease-in-out infinite alternate; }
@keyframes glow { from { box-shadow: 0 5px 0 var(--ink), 0 0 0 0 rgba(47, 191, 113, 0.6); } to { box-shadow: 0 5px 0 var(--ink), 0 0 0 8px rgba(47, 191, 113, 0); } }
@keyframes press { from { transform: translateY(4px); } to { transform: translateY(0); } }
/* keep the warning and mute button above the buttons */
body:has(#pad:not(.hidden)) #warn { bottom: calc(110px + env(safe-area-inset-bottom)); }
body:has(#pad:not(.hidden)) #mute { bottom: calc(106px + env(safe-area-inset-bottom)); }

/* phones held sideways: compact HUD so there's sky left to fly in */
@media (max-height: 500px) {
  #hud { top: 8px; }
  #hud .col { gap: 6px; }
  #phaseCard { grid-template-columns: 40px 1fr; padding: 6px 12px 8px; gap: 0 10px; }
  #phaseCard .icon { width: 40px; height: 40px; padding: 4px; }
  #phaseCard .label, #phaseCard .hint { display: none; }
  #phaseCard .name { font-size: 20px; }
  #phaseCard .bar { margin-top: 4px; height: 6px; }
  #sync { display: none !important; }
  #beatCue, #bankArrow { font-size: 18px; padding: 0 14px; min-width: 0; }
  .pill { font-size: 15px; padding: 3px 10px; }
  #next { top: 50%; padding: 8px 14px; }
  #next .ic { width: 48px; height: 48px; }
  #next .nn { font-size: 22px; }
  #next .cd { font-size: 28px; }
  .pb { height: 56px; }
  body:has(#pad:not(.hidden)) #warn { bottom: calc(84px + env(safe-area-inset-bottom)); }
  body:has(#pad:not(.hidden)) #mute { bottom: calc(80px + env(safe-area-inset-bottom)); }
  .screen .panel { padding: 16px 18px; }
  #calib .panel { grid-template-columns: auto 1fr; padding: 10px 14px; }
  #calib .ring { width: 56px; height: 56px; padding: 5px; }
  #cam.big { width: min(300px, 42vw); }
}
