/* =================================================================
   Joyful Jive — Rhythm Dance Game
   Vibrant arcade-stage aesthetic, mobile-first.
   ================================================================= */

:root {
  --bg-1: #2a1638;
  --bg-2: #4a1c5c;
  --bg-3: #ff7a3d;
  --stage-1: #ff8a4c;
  --stage-2: #c14b2a;
  --stage-floor: #2c0e18;
  --neon-pink: #ff3d8b;
  --neon-yellow: #ffd23d;
  --neon-cyan: #3deaff;
  --good: #6cf;
  --perfect: #ffd23d;
  --miss: #ff3d8b;
  --ink: #1a0b22;
  --paper: #fff7ec;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  min-height: 100%;
  font-family: ui-rounded, 'SF Pro Rounded', 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: var(--paper);
  background: radial-gradient(120% 80% at 50% 0%, var(--bg-2) 0%, var(--bg-1) 60%, #0e0617 100%);
  overflow: hidden;
  overscroll-behavior: none;
  user-select: none;
}

#app {
  position: relative;
  width: 100vw;
  height: 100dvh;
  height: 100vh;
  overflow: hidden;
}

/* ---------- Screens ---------- */
.screen {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  opacity: 0; pointer-events: none;
  transform: translateY(8px);
  transition: opacity .35s ease, transform .35s ease;
}
.screen.is-active { opacity: 1; pointer-events: auto; transform: none; }

/* ---------- Buttons ---------- */
.btn {
  appearance: none; border: none;
  font: inherit; font-weight: 700;
  padding: 14px 22px;
  border-radius: 999px;
  cursor: pointer;
  letter-spacing: .02em;
  transition: transform .12s ease, box-shadow .15s ease, filter .15s ease;
  box-shadow: 0 6px 0 rgba(0,0,0,.25), 0 10px 24px rgba(255,61,139,.25);
}
.btn:active { transform: translateY(2px); box-shadow: 0 4px 0 rgba(0,0,0,.25); }
.btn--primary {
  background: linear-gradient(180deg, #ff5fa2 0%, #ff3d8b 50%, #e0246e 100%);
  color: #fff;
  text-shadow: 0 1px 0 rgba(0,0,0,.2);
}
.btn--ghost {
  background: rgba(255,255,255,.08);
  color: var(--paper);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.18);
}
.iconbtn {
  width: 36px; height: 36px; border-radius: 50%;
  background: rgba(255,255,255,.08);
  color: var(--paper); border: none; cursor: pointer; font-size: 16px;
}

/* =================================================================
   TITLE SCREEN
   ================================================================= */
.title-stage {
  position: relative; width: min(720px, 92vw);
  display: flex; flex-direction: column; align-items: center; gap: 18px;
  padding: 28px 18px;
}
.title-lights {
  position: absolute; inset: -20% -10% auto -10%; height: 60%;
  pointer-events: none; overflow: hidden; z-index: 0;
}
.ray {
  position: absolute; top: -50%; left: 50%;
  width: 30%; height: 200%;
  transform-origin: top center;
  background: linear-gradient(180deg, rgba(255,210,61,.25), rgba(255,210,61,0));
  filter: blur(6px);
  opacity: .7;
}
.ray--1 { transform: translateX(-50%) rotate(-22deg); }
.ray--2 { transform: translateX(-50%) rotate(-8deg);  background: linear-gradient(180deg, rgba(255,61,139,.25), transparent); }
.ray--3 { transform: translateX(-50%) rotate(8deg);   background: linear-gradient(180deg, rgba(61,234,255,.18), transparent); }
.ray--4 { transform: translateX(-50%) rotate(22deg);  background: linear-gradient(180deg, rgba(255,255,255,.18), transparent); }

.title-logo {
  position: relative; z-index: 1;
  font-size: clamp(48px, 11vw, 96px);
  line-height: .9; margin: 6px 0 0;
  text-align: center;
  font-weight: 900;
  letter-spacing: -.02em;
}
.title-logo__joy {
  display: block;
  background: linear-gradient(180deg, #fff 0%, #ffe39a 100%);
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
  text-shadow: 0 4px 0 rgba(0,0,0,.15);
}
.title-logo__jive {
  display: block;
  background: linear-gradient(180deg, #ffd23d 0%, #ff7a3d 60%, #ff3d8b 100%);
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
  transform: rotate(-3deg);
}
.title-tagline {
  position: relative; z-index: 1;
  margin: 0; font-weight: 700; opacity: .9;
  letter-spacing: .15em; text-transform: uppercase; font-size: 12px;
}

.dancers {
  position: relative; z-index: 1;
  display: flex; gap: 16px; align-items: flex-end; margin-top: 10px;
}
.dancer {
  width: 90px; height: 130px;
  filter: drop-shadow(0 6px 0 rgba(0,0,0,.3));
  animation: bob 600ms ease-in-out infinite alternate;
}
.dancer--big { width: 110px; height: 160px; animation-duration: 540ms; }
.dancer--small:nth-child(3) { animation-delay: 140ms; }

@keyframes bob {
  from { transform: translateY(0) }
  to   { transform: translateY(-8px) }
}

.title-actions { position: relative; z-index: 1; display: flex; gap: 12px; margin-top: 10px; }
.title-tip {
  position: relative; z-index: 1; font-size: 12px; opacity: .7; margin-top: 6px;
  text-align: center;
}

/* Floating decorative sprites */
.floaters {
  position: absolute; inset: 0; pointer-events: none; z-index: 0;
}
.floater {
  position: absolute; width: 28px; height: 28px;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,.25));
}
.floater--note  { top: 18%; left: 8%;  animation: floatA 4.2s ease-in-out infinite; }
.floater--note2 { top: 55%; right: 6%; left: auto; animation: floatA 3.6s ease-in-out infinite .8s; }
.floater--star  { top: 8%;  right: 12%; left: auto; width: 24px; height: 24px; animation: floatB 3.4s ease-in-out infinite .3s; }
.floater--star2 { top: 70%; left: 14%; width: 22px; height: 22px; animation: floatB 4s ease-in-out infinite 1.2s; }

@keyframes floatA {
  0%,100% { transform: translateY(0) rotate(-6deg); }
  50%     { transform: translateY(-14px) rotate(6deg); }
}
@keyframes floatB {
  0%,100% { transform: translateY(0) scale(1); opacity: .9; }
  50%     { transform: translateY(-10px) scale(1.15); opacity: 1; }
}

/* =================================================================
   HOW-TO MODAL
   ================================================================= */
.modal {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.55);
  display: none; align-items: center; justify-content: center;
  z-index: 50;
}
.modal.is-open { display: flex; }
.modal__card {
  background: #fff; color: var(--ink);
  width: min(440px, 92vw);
  border-radius: 22px; padding: 22px 22px 18px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: stretch; gap: 12px;
}
.modal__card h2 { margin: 0; font-size: 22px; }
.how-list { padding-left: 18px; margin: 0; line-height: 1.55; font-size: 15px; }
.how-grade { display: flex; gap: 8px; justify-content: center; margin: 6px 0 4px; }
.pill {
  padding: 6px 12px; border-radius: 999px; font-weight: 800; font-size: 12px;
  color: #fff;
}
.pill--perfect { background: #f0a500; }
.pill--good    { background: #2bb3ff; }
.pill--miss    { background: #ff3d8b; }

/* =================================================================
   CAMERA LOBBY
   ================================================================= */
.screen--lobby { gap: 14px; padding: 18px; }
.lobby__title {
  margin: 0;
  font-size: clamp(22px, 5vw, 32px);
  background: linear-gradient(180deg, #ffd23d, #ff7a3d);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.lobby__hint { margin: 0; opacity: .85; text-align: center; max-width: 480px; font-size: 14px; }
.lobby__preview {
  position: relative;
  width: min(440px, 92vw);
  aspect-ratio: 4/3;
  border-radius: 18px;
  overflow: hidden;
  background: #111;
  box-shadow: var(--shadow);
  border: 3px solid rgba(255,255,255,.18);
}
.lobby__video, .lobby__canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
}
.lobby__video  { object-fit: cover; transform: scaleX(-1); }
.lobby__canvas { pointer-events: none; }
.lobby__overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: rgba(0,0,0,.7);
  color: #fff; font-weight: 700; gap: 8px;
  text-align: center; padding: 16px;
}
.lobby__overlay.is-hidden { display: none; }
.lobby__overlay-icon { font-size: 40px; }
.lobby__status {
  font-size: 14px; opacity: .9; min-height: 20px; text-align: center;
}
.lobby__actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

/* =================================================================
   GAME SCREEN
   ================================================================= */
.screen--game { justify-content: flex-start; padding: 12px 12px 16px; gap: 10px; }

/* HUD */
.hud {
  width: min(720px, 100%);
  display: grid; grid-template-columns: 1fr auto 1fr;
  align-items: center; gap: 8px;
}
.hud__left  { display: flex; gap: 8px; }
.hud__right { display: flex; justify-content: flex-end; }
.hud__chip {
  background: rgba(255,255,255,.08);
  border: 2px solid rgba(255,255,255,.15);
  padding: 6px 12px; border-radius: 12px;
  display: flex; flex-direction: column; align-items: flex-start; line-height: 1.1;
  min-width: 70px;
}
.hud__chip--score { border-color: rgba(255,210,61,.5); }
.hud__chip--combo { border-color: rgba(255,61,139,.5); transition: transform .12s ease; }
.hud__chip--combo.is-pulse { transform: scale(1.08); }
.hud__chip--level { background: linear-gradient(180deg, #ffd23d, #ff7a3d); color: #2a1638; border-color: transparent; }
.hud__chip--level .hud__label { color: rgba(42,22,56,.7); }
.hud__label { font-size: 10px; letter-spacing: .1em; text-transform: uppercase; opacity: .8; }
.hud__value { font-size: 18px; font-weight: 900; }

/* Timer bar */
.timerbar {
  position: relative; width: min(720px, 100%);
  height: 22px; border-radius: 999px;
  background: rgba(0,0,0,.35);
  overflow: hidden;
  border: 2px solid rgba(255,255,255,.18);
}
.timerbar__fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 100%;
  background: linear-gradient(90deg, #3deaff 0%, #ffd23d 50%, #ff3d8b 100%);
  transition: width .08s linear;
}
.timerbar__label {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 12px; color: #fff;
  text-shadow: 0 1px 0 rgba(0,0,0,.45);
}

/* Stage */
.stage {
  position: relative;
  width: min(720px, 100%);
  flex: 1; min-height: 280px;
  border-radius: 22px;
  background:
    radial-gradient(120% 80% at 50% 100%, var(--stage-floor) 0%, transparent 60%),
    linear-gradient(180deg, var(--stage-1) 0%, var(--stage-2) 65%, var(--stage-floor) 100%);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.stage__floor {
  position: absolute; bottom: 0; left: 0; right: 0; height: 38%;
  background:
    radial-gradient(60% 80% at 50% 100%, rgba(0,0,0,.55), transparent 80%),
    repeating-linear-gradient(90deg, rgba(255,255,255,.06) 0 2px, transparent 2px 26px);
}
.stage__lights {
  position: absolute; top: -10%; left: 0; right: 0; height: 70%;
  background:
    radial-gradient(40% 60% at 20% 10%, rgba(255,210,61,.45), transparent 70%),
    radial-gradient(40% 60% at 80% 10%, rgba(255,61,139,.45), transparent 70%),
    radial-gradient(60% 60% at 50% 0%,  rgba(255,255,255,.25), transparent 70%);
  filter: blur(4px);
}

.stage__characters {
  position: absolute; inset: 0;
  display: flex; align-items: flex-end; justify-content: center; gap: 8%;
  padding: 0 6% 9%;
}
.char {
  position: relative;
  width: 38%; max-width: 220px;
  aspect-ratio: 3/4;
  display: flex; align-items: flex-end; justify-content: center;
  transition: transform .12s ease;
}
.char__label {
  position: absolute; top: 6px; left: 50%; transform: translateX(-50%);
  font-size: 10px; font-weight: 800; letter-spacing: .12em;
  text-transform: uppercase;
  background: rgba(0,0,0,.4); padding: 4px 8px; border-radius: 999px;
}
.char--player .char__label { background: rgba(255,61,139,.7); z-index: 5; }

/* SVG character layer — the stick-figure "You" used when camera is off. */
.char__svg {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: flex; align-items: flex-end; justify-content: center;
}

/* Live camera + skeleton overlay inside the "You" panel */
.char__video, .char__canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  border-radius: 16px;
}
.char__video  {
  object-fit: cover;
  transform: scaleX(-1);
  background: #0a0511;
  display: none;     /* shown only when camera mode active */
}
.char__canvas { pointer-events: none; display: none; }

/* When camera mode is active, the panel shows live video + skeleton,
   and the SVG character is hidden. */
.char--has-cam { background: #000; border-radius: 16px; overflow: hidden; }
.char--has-cam .char__video,
.char--has-cam .char__canvas { display: block; }
.char--has-cam .char__svg    { display: none; }

/* Small "detected pose" debug label on the player panel, helps players see
   what the detector currently thinks they're doing. */
.char__detected {
  position: absolute; bottom: 6px; left: 50%; transform: translateX(-50%);
  font-size: 10px; font-weight: 800; letter-spacing: .08em;
  text-transform: uppercase;
  background: rgba(0,0,0,.55); color: #ffd23d;
  padding: 3px 8px; border-radius: 999px;
  pointer-events: none; z-index: 6;
  opacity: 0; transition: opacity .2s ease;
}
.char--has-cam .char__detected { opacity: 1; }

/* "Match" indicator ring around player when detector matches target */
.char__match {
  position: absolute; inset: 4px;
  border-radius: 14px;
  pointer-events: none;
  border: 4px solid transparent;
  transition: border-color .15s ease, box-shadow .15s ease;
  z-index: 4;
}
.char__match.is-near    { border-color: rgba(255,210,61,.5); box-shadow: inset 0 0 22px rgba(255,210,61,.25); }
.char__match.is-matched { border-color: #ffd23d; box-shadow: inset 0 0 30px rgba(255,210,61,.45), 0 0 18px rgba(255,210,61,.45); }
.char.is-perfect { animation: pop 240ms ease; }
.char.is-good    { animation: nudge 220ms ease; }
.char.is-miss    { animation: shake 280ms ease; }
@keyframes pop   { 0%{transform:scale(1)} 40%{transform:scale(1.12)} 100%{transform:scale(1)} }
@keyframes nudge { 0%{transform:translateY(0)} 50%{transform:translateY(-6px)} 100%{transform:translateY(0)} }
@keyframes shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-6px)} 75%{transform:translateX(6px)} }

/* Judge banner */
.judge {
  position: absolute; left: 50%; top: 36%;
  transform: translate(-50%, -50%) scale(.6);
  font-weight: 900; font-size: clamp(28px, 7vw, 56px);
  letter-spacing: .04em;
  opacity: 0; pointer-events: none;
  text-shadow: 0 4px 0 rgba(0,0,0,.35);
}
.judge.is-show { animation: judgePop .7s ease forwards; }
.judge.is-perfect { color: var(--perfect); }
.judge.is-good    { color: var(--good); }
.judge.is-miss    { color: var(--miss); }
.judge.is-combo   { color: var(--neon-yellow); }
@keyframes judgePop {
  0%   { opacity: 0; transform: translate(-50%,-30%) scale(.6) rotate(-6deg); }
  20%  { opacity: 1; transform: translate(-50%,-50%) scale(1.15) rotate(2deg); }
  100% { opacity: 0; transform: translate(-50%,-65%) scale(1) rotate(-2deg); }
}

/* Countdown overlay */
.countdown {
  position: absolute; inset: 0;
  display: none;
  align-items: center; justify-content: center;
  background: rgba(0,0,0,.4);
  font-weight: 900; font-size: clamp(80px, 22vw, 180px);
  color: #fff;
  text-shadow: 0 6px 0 rgba(0,0,0,.4);
}
.countdown.is-show { display: flex; }
.countdown.is-tick { animation: tick .9s ease forwards; }
@keyframes tick {
  0%   { transform: scale(.6); opacity: 0 }
  40%  { transform: scale(1.1); opacity: 1 }
  100% { transform: scale(1.4); opacity: 0 }
}

/* Pose row */
.poses {
  width: min(720px, 100%);
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px;
}
.pose-btn {
  position: relative;
  appearance: none; border: none; padding: 0;
  background: linear-gradient(180deg, #fff7ec 0%, #ffe3bd 100%);
  color: var(--ink);
  aspect-ratio: 1;
  border-radius: 14px;
  box-shadow: 0 4px 0 #b78054, 0 8px 18px rgba(0,0,0,.3);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: transform .08s ease, box-shadow .08s ease, filter .15s ease;
}
.pose-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #b78054, 0 4px 8px rgba(0,0,0,.3); }
.pose-btn svg { width: 70%; height: 70%; }
.pose-btn.is-target { animation: hintPulse .8s ease infinite; box-shadow: 0 4px 0 #b78054, 0 0 0 3px var(--neon-yellow), 0 8px 18px rgba(0,0,0,.4); }
.pose-btn.is-hit { animation: hit .25s ease; }
@keyframes hintPulse { 0%,100% { filter: brightness(1) } 50% { filter: brightness(1.2) } }
@keyframes hit { 0% { transform: scale(1) } 50% { transform: scale(1.15) } 100% { transform: scale(1) } }
.pose-btn.is-correct { background: linear-gradient(180deg, #ffe066, #ffd23d); }
.pose-btn.is-wrong   { background: linear-gradient(180deg, #ffb3c8, #ff7aa1); }

/* =================================================================
   DANCER SVG (built via CSS - simple cute character)
   We render an inline SVG via CSS background-image (data uri) per pose.
   Actually we place an <svg> in JS — keep this for stylable layers.
   ================================================================= */
.dancer-svg { width: 100%; height: 100%; overflow: visible; }
.dancer-svg .body { fill: #ff3d8b; }
.dancer-svg .body-alt { fill: #3d8bff; }
.dancer-svg .skin { fill: #ffd6a8; }
.dancer-svg .hat  { fill: #2a1638; }
.dancer-svg .pants { fill: #2a1638; }
.dancer-svg .shoe { fill: #1a0b22; }
.dancer-svg .stroke { stroke: #1a0b22; stroke-width: 3; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.dancer-svg .accent { fill: #ffd23d; }

/* Title dancer styling via data attribute */
.dancer { background-size: contain; background-position: bottom center; background-repeat: no-repeat; }

/* =================================================================
   FINALE SCREEN
   ================================================================= */
.screen--finale { gap: 16px; padding: 16px; }
.finale__frame {
  position: relative;
  width: min(640px, 100%);
  flex: 1; max-height: 80vh;
  border-radius: 22px;
  overflow: hidden;
  background: #000;
  box-shadow: var(--shadow);
}
.finale__video {
  width: 100%; height: 100%; object-fit: cover;
  transform: scaleX(-1);  /* mirror, like a selfie */
}
.finale__overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: 18px;
  background:
    radial-gradient(80% 60% at 50% 0%, rgba(0,0,0,.4), transparent 60%),
    radial-gradient(80% 60% at 50% 100%, rgba(0,0,0,.5), transparent 60%);
  color: #fff; pointer-events: none;
}
.finale__title {
  font-weight: 900; font-size: clamp(28px, 7vw, 48px);
  letter-spacing: .04em;
  background: linear-gradient(180deg, #ffd23d, #ff7a3d);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 4px 0 rgba(0,0,0,.4);
}
.finale__sub { font-weight: 700; opacity: .9; margin-top: 4px; text-align: center; }
.finale__moves {
  display: flex; gap: 6px; margin-top: auto;
  background: rgba(0,0,0,.4); padding: 8px 10px; border-radius: 14px;
}
.finale__moves .finale-move {
  width: 46px; height: 46px; border-radius: 10px;
  background: #fff7ec; display: flex; align-items: center; justify-content: center;
  opacity: .35; transition: opacity .2s ease, transform .2s ease;
}
.finale__moves .finale-move.is-active {
  opacity: 1; transform: scale(1.15);
  box-shadow: 0 0 0 3px var(--neon-yellow);
}
.finale__moves .finale-move svg { width: 70%; height: 70%; }
.finale__timer {
  position: absolute; top: 14px; right: 14px;
  background: rgba(0,0,0,.6); padding: 6px 14px; border-radius: 999px;
  font-weight: 900; font-size: 22px;
}
.finale__noCam {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 18px;
  background: #2a1638; color: #fff; text-align: center;
}

/* =================================================================
   SUMMARY
   ================================================================= */
.summary__card {
  background: #fff; color: var(--ink);
  width: min(420px, 92vw);
  border-radius: 22px; padding: 22px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 14px;
}
.summary__title { margin: 0 0 4px; font-size: 22px; text-align: center; }
.summary__rows { display: flex; flex-direction: column; gap: 8px; }
.summary__row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px;
  background: #fff7ec; border-radius: 12px;
  font-weight: 700;
}
.summary__row b { color: var(--neon-pink); font-size: 18px; }
.reward { display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
.reward__label { font-size: 12px; letter-spacing: .12em; text-transform: uppercase; opacity: .6; text-align: center; }
.reward__card {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: linear-gradient(135deg, #ffd23d, #ff7a3d);
  color: #2a1638;
  animation: rewardPop .9s ease;
}
@keyframes rewardPop {
  0% { transform: scale(.85); opacity: 0 }
  50% { transform: scale(1.05); opacity: 1 }
  100% { transform: scale(1); opacity: 1 }
}
.reward__icon { width: 40px; height: 40px; }
.reward__name { font-weight: 900; }
.summary__actions { display: flex; gap: 10px; justify-content: center; }

/* =================================================================
   Responsive niceties
   ================================================================= */
@media (max-width: 380px) {
  .poses { grid-template-columns: repeat(8, 1fr); gap: 4px; }
  .hud__chip { padding: 5px 9px; min-width: 60px; }
  .hud__value { font-size: 16px; }
}
@media (min-width: 720px) {
  .pose-btn { border-radius: 18px; }
}
