@font-face { font-family: 'Luckiest Guy'; src: url('assets/fonts/LuckiestGuy-Regular.ttf') format('truetype'); }
@font-face { font-family: 'Oswald'; src: url('assets/fonts/Oswald.ttf') format('truetype'); }

:root {
  --ink: rgba(29, 46, 89, 0.88);
  --cream: #FFF1D1;
  --gold: #FFD84A;
  --red: #FF5B57;
  --navy: #1D2E59;
  --shadow: 0 3px 0 rgba(15, 23, 45, 0.9), 0 0 9px rgba(15, 23, 45, 0.6);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #74C9FF; }
#stage { position: fixed; inset: 0; } /* fixed, so the "swipe up for full screen" scroll doesn't move it */
#stage canvas { display: block; }

.display { font-family: 'Luckiest Guy', system-ui, sans-serif; letter-spacing: 0.02em; text-shadow: var(--shadow); }
.small { font-family: 'Oswald', system-ui, sans-serif; }
.gold { color: var(--gold); }

#hud { position: fixed; inset: 0; pointer-events: none; color: var(--cream); user-select: none; }

.plate { position: absolute; top: 20px; background: var(--ink); border: 2px solid rgba(255,255,255,0.12); border-radius: 14px; padding: 10px 14px; }
#combo-plate { left: 26px; }
#combo { font-size: 40px; line-height: 1; color: var(--gold); }
#hearts { display: flex; gap: 4px; margin-top: 4px; }
#hearts i { width: 15px; height: 15px; border-radius: 7px; background: rgba(255,255,255,0.16); }
#hearts i.on { background: var(--red); }

#score-plate { right: 178px; text-align: right; }
.score-row { display: flex; align-items: center; gap: 10px; font-size: 30px; line-height: 1; }
.pip { width: 18px; height: 18px; border-radius: 9px; background: var(--gold); border: 2px solid #A1641C; }
#distance { font-size: 18px; color: rgba(255,255,255,0.55); margin-top: 2px; }

#menu { position: absolute; top: 20px; right: 22px; width: 130px; height: 64px; pointer-events: auto; font-size: 22px;
  color: var(--cream); background: var(--ink); border: 2px solid rgba(255,255,255,0.12); border-radius: 14px; cursor: pointer; }

.pop { position: absolute; left: 50%; transform: translate(-50%, -50%); white-space: nowrap; opacity: 0; }
#cue { top: 30%; font-size: 52px; color: var(--gold); }
#verdict { top: 74%; font-size: 72px; }

#screen { position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); text-align: center; opacity: 0; transition: opacity 0.25s; }
#screen.shown { opacity: 1; }
#screen.shown .buttons { pointer-events: auto; }
#screen.over .buttons { display: none; }
#screen-title { font-size: clamp(48px, 9vw, 86px); line-height: 1; }
#screen-line { font-size: clamp(14px, 2vw, 24px); margin-top: 4px; }
.buttons { display: flex; gap: 14px; justify-content: center; margin-top: 14px; }

button.display { font-size: 22px; color: var(--navy); background: var(--gold); border: none; border-radius: 12px;
  min-width: 200px; height: 52px; padding: 6px 18px 0; cursor: pointer; text-shadow: none; box-shadow: 0 5px 0 #B8891B; }
button.display:active { transform: translateY(3px); box-shadow: 0 2px 0 #B8891B; }
#how-open { background: var(--cream); box-shadow: 0 5px 0 #BBA67A; }
#menu.display { color: var(--cream); background: var(--ink); box-shadow: none; min-width: 0; text-shadow: var(--shadow); }

#fps { position: absolute; left: 26px; bottom: 16px; font-size: 16px; color: rgba(255,255,255,0.45); }
#badge { position: absolute; right: 26px; bottom: 16px; font-size: 15px; color: rgba(255,255,255,0.5); }

/* The pose keys, each drawn as its own gate's hole. Shown while a gate is on the road. */
#poses { position: absolute; left: 50%; bottom: 44px; transform: translate(-50%, 20px); display: flex; gap: 10px; opacity: 0; transition: opacity 0.2s, transform 0.2s; }
#poses.shown { opacity: 1; transform: translate(-50%, 0); }
.pose-key { position: relative; background: var(--ink); border-radius: 10px; padding: 6px; border: 2px solid rgba(255,255,255,0.12); }
.pose-key canvas { display: block; width: 60px; height: 64px; image-rendering: pixelated; border-radius: 4px; }
.pose-key .key { position: absolute; top: -12px; left: -8px; width: 26px; height: 26px; border-radius: 13px; background: var(--gold); color: var(--navy);
  font: 18px/28px 'Luckiest Guy', sans-serif; text-align: center; }

#how { position: fixed; inset: 0; display: none; place-items: center; background: rgba(15, 23, 45, 0.55); padding: 16px; }
#how.shown { display: grid; }
.how-card { background: var(--ink); color: var(--cream); border-radius: 18px; border: 2px solid rgba(255,255,255,0.14); padding: 26px 30px; max-width: 620px; width: 100%; max-height: 100%; overflow: auto; }
.how-title { font-size: 44px; color: var(--gold); }
.how-card p { font-size: 17px; color: rgba(255,241,209,0.8); }
.how-card dl { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; margin: 14px 0; font-family: 'Oswald', sans-serif; font-size: 18px; }
.how-card dt { color: var(--gold); font-size: 20px; }
.how-card dd { margin: 0; }
.how-poses { display: flex; gap: 10px; margin: 18px 0 6px 8px; flex-wrap: wrap; }
#how-close { margin-top: 8px; }

#loading { position: fixed; inset: 0; display: grid; place-content: center; gap: 18px; background: #4C8FE8; color: var(--cream); text-align: center; transition: opacity 0.4s; }
#loading .display { font-size: 64px; }
#loading .track { width: 320px; height: 12px; border-radius: 6px; background: rgba(255,255,255,0.25); overflow: hidden; margin: 0 auto; }
#loading-bar { width: 0; height: 100%; background: var(--gold); transition: width 0.15s; }
#loading.done { opacity: 0; pointer-events: none; }

@media (max-width: 700px) {
  #score-plate { right: 16px; top: 96px; }
  #menu { width: 100px; height: 52px; }
  #combo-plate { left: 16px; }
  .buttons { flex-direction: column; align-items: center; }
  .pose-key canvas { width: 42px; height: 45px; }
}

/* The camera's view, mirrored like a mirror, with the skeleton and lane lines over it. */
#cam { position: absolute; right: 26px; bottom: 44px; width: 288px; aspect-ratio: 16 / 9; border-radius: 12px; overflow: hidden;
  background: var(--navy); border: 3px solid rgba(255,255,255,0.35); box-shadow: 0 6px 20px rgba(15,23,45,0.35); }
#cam.tracked { border-color: #68C96B; }
#cam video, #cam canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#cam video { transform: scaleX(-1); opacity: 0.85; }
.cam-status { position: absolute; left: 8px; top: 6px; font-size: 14px; }
.cam-events { position: absolute; right: 8px; top: 6px; display: flex; gap: 4px; }
.cam-events b { font-weight: normal; font-size: 13px; background: var(--gold); color: var(--navy); border-radius: 6px; padding: 3px 6px 0; text-shadow: none; }
.cam-wave { position: absolute; left: 8px; right: 8px; bottom: 14px; height: 5px; border-radius: 3px; background: rgba(255,255,255,0.2); }
.cam-wave i { display: block; height: 100%; width: 0; border-radius: 3px; background: var(--gold); }
#cam-toggle { background: #74C9FF; box-shadow: 0 5px 0 #3F7FB0; }
#cam-toggle.on { background: #68C96B; box-shadow: 0 5px 0 #3C8A3F; }
@media (max-width: 700px) { #cam { width: 180px; right: 16px; } }

/* --- loading: percentage and the controls to read while it loads --- */
#loading-pct { font-size: 18px; color: rgba(255,241,209,0.85); }
#loading .controls { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 10px; max-width: 640px; padding: 0 16px; font-size: 16px; }
#loading .controls span { display: inline-flex; align-items: center; gap: 8px; background: rgba(29,46,89,0.45); border-radius: 999px; padding: 6px 14px 6px 6px; }
#loading .controls b { font-weight: normal; font-size: 15px; line-height: 1; padding: 6px 9px 3px; border-radius: 999px; background: var(--gold); color: var(--navy); text-shadow: none; }

/* --- phones and tablets --- */
html, body { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; overscroll-behavior: none; }
body.touch #cam-toggle, body.touch #how-open, body.touch #fps, body.touch #badge { display: none; }
/* The pose keys are buttons on a touch screen: bigger, and tappable while a gate is coming. */
body.touch #poses.shown { pointer-events: auto; }
body.touch .pose-key { cursor: pointer; }
body.touch .pose-key:active { transform: scale(0.94); border-color: var(--gold); }
body.touch .pose-key canvas { width: 66px; height: 70px; }

/* Short landscape phones. */
@media (max-height: 500px) {
  #loading { gap: 12px; }
  #loading .display { font-size: 44px; }
  #screen-title { font-size: 52px; }
  .buttons { flex-direction: row; }
  #poses { bottom: 14px; }
  body.touch .pose-key canvas { width: 52px; height: 56px; }
}

/* Phones held upright: ask for landscape. */
#rotate { display: none; position: fixed; inset: 0; z-index: 100; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 24px;
  text-align: center; background: #4C8FE8; color: var(--cream); }
#rotate b { font-weight: normal; font-size: 30px; color: var(--gold); text-shadow: var(--shadow); }
#rotate span { font-size: 18px; }
#rotate .phone { width: 46px; height: 80px; border: 4px solid var(--gold); border-radius: 10px; margin-bottom: 14px; animation: turn 2.2s ease-in-out infinite; }
@keyframes turn { 0%, 25% { transform: rotate(0); } 55%, 100% { transform: rotate(-90deg); } }
@media (pointer: coarse) and (orientation: portrait) { #rotate { display: flex; } }
