:root {
  --ink: #2b2140;
  --ink-soft: #5d5470;
  --paper: #fffdf8;
  --coral: #ff7a45;
  --sun: #ffd23f;
  --mint: #3ddc97;
  --sky: #4fb0ff;
  --berry: #ff5c7a;
  --radius: 26px;
  --shadow: 6px 6px 0 var(--ink);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #cde9ff;
  color: var(--ink);
  font-family: 'Fredoka', 'Arial Rounded MT Bold', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
}

.hidden { display: none !important; }

h1, h2, p { margin: 0; }
h2 { font-size: 34px; font-weight: 700; line-height: 1.05; }
b { font-weight: 600; }

/* ------------------------------------------------------------ cards & buttons */

.card {
  background: rgba(255, 253, 248, 0.94);
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 32px;
  backdrop-filter: blur(6px);
}

.btn {
  font: 600 18px/1 'Fredoka', system-ui, sans-serif;
  color: var(--ink);
  border: 3px solid var(--ink);
  border-radius: 16px;
  padding: 13px 22px;
  cursor: pointer;
  background: #fff;
  box-shadow: 0 5px 0 var(--ink);
  transition: transform 0.08s, box-shadow 0.08s, background 0.15s;
}
.btn:hover { background: #fff7e6; }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.btn:focus-visible { outline: 3px solid var(--sky); outline-offset: 3px; }
.btn.primary { background: var(--mint); }
.btn.primary:hover { background: #5be6aa; }
.btn.big { font-size: 22px; padding: 17px 28px; }
.btn.small { font-size: 15px; padding: 9px 14px; border-radius: 12px; box-shadow: 0 4px 0 var(--ink); }

.actions { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-top: 22px; }
.actions.tight { margin-top: 16px; justify-content: center; }

.cta {
  margin-top: 14px;
  font-size: 26px;
  font-weight: 700;
  color: var(--coral);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  animation: pulse 1.1s ease-in-out infinite;
}
@keyframes pulse { 50% { transform: scale(1.06); } }

.meter {
  height: 16px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: #fff;
  overflow: hidden;
  margin-top: 16px;
}
.meter > div { height: 100%; width: 0%; background: var(--mint); transition: width 0.1s linear; }

/* ------------------------------------------------------------ screens */

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  pointer-events: none;
  z-index: 10;
}
.screen > * { pointer-events: auto; }
.screen.center { align-items: center; justify-content: center; padding: 16px; }
.screen.top { justify-content: center; align-items: flex-start; padding-top: 24px; }

.start { align-items: center; padding: 24px 24px 24px 6vw; }
.start-card { max-width: 560px; padding: 34px 38px 28px; }

.logo {
  display: flex;
  flex-direction: column;
  font-size: clamp(64px, 8vw, 96px);
  font-weight: 700;
  line-height: 0.86;
  letter-spacing: -1px;
  margin-bottom: 18px;
}
.logo span {
  -webkit-text-stroke: 4px var(--ink);
  paint-order: stroke fill;
  text-shadow: 5px 5px 0 var(--ink);
}
.logo span:first-child { color: var(--coral); }
.logo span:last-child { color: var(--sun); margin-left: 64px; transform: rotate(-3deg); transform-origin: left; animation: bounce 1.8s ease-in-out infinite; display: inline-block; }
@keyframes bounce { 0%, 100% { transform: rotate(-3deg) translateY(0); } 50% { transform: rotate(-3deg) translateY(-8px); } }

.tag { font-size: 19px; line-height: 1.35; color: var(--ink-soft); max-width: 46ch; }
.tag b { color: var(--ink); }

.moves {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 22px;
}
.move {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  background: #fff;
  border: 2.5px solid var(--ink);
  border-radius: 18px;
  padding: 10px 6px 12px;
}
.move svg { width: 56px; height: 56px; color: var(--ink); }
.move b { font-size: 16px; margin-top: 4px; }
.move span { font-size: 12.5px; color: var(--ink-soft); line-height: 1.2; }
.move.off { opacity: 0.35; }

.fine { margin-top: 18px; font-size: 13.5px; line-height: 1.45; color: var(--ink-soft); max-width: 52ch; }

.small-card { max-width: 440px; text-align: center; }
.small-card p { margin-top: 10px; font-size: 18px; line-height: 1.4; color: var(--ink-soft); }
.small-card .actions { justify-content: center; }

.spinner {
  width: 54px; height: 54px;
  margin: 0 auto 6px;
  border: 6px solid #ffe2d4;
  border-top-color: var(--coral);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Calibration: camera goes big in the middle */
.calibrate { flex-direction: column; align-items: center; justify-content: space-between; padding: 26px 16px; }
.calib-head {
  text-align: center;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 16px 26px;
  max-width: 720px;
}
.calib-head p { margin-top: 6px; font-size: 19px; color: var(--ink-soft); min-height: 1.4em; }
.calib-foot { width: min(520px, 80vw); }

.banner { text-align: center; max-width: 560px; padding: 20px 30px 22px; }
.banner p { margin-top: 6px; font-size: 19px; color: var(--ink-soft); }
.banner .cta { margin-top: 10px; }

.over-card { text-align: center; min-width: 380px; }
.over-card h2 { font-size: 46px; color: var(--berry); -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; }
.stats { display: flex; gap: 12px; margin-top: 18px; justify-content: center; }
.stats div {
  background: #fff;
  border: 2.5px solid var(--ink);
  border-radius: 16px;
  padding: 10px 18px;
  min-width: 104px;
  display: flex; flex-direction: column;
}
.stats span { font-size: 13px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--ink-soft); }
.stats b { font-size: 30px; font-weight: 700; }
.best { margin-top: 14px; font-size: 18px; color: var(--ink-soft); }
.best.new { color: var(--coral); font-weight: 700; }

.settings-card { width: min(460px, 92vw); }
.settings-card .slider { display: block; margin-top: 20px; }
.settings-card .slider span { display: flex; justify-content: space-between; font-weight: 600; font-size: 17px; }
.settings-card .slider em { font-style: normal; color: var(--ink-soft); }
.settings-card small { display: block; color: var(--ink-soft); font-size: 13px; margin-top: 2px; }
.settings-card input[type=range] { width: 100%; accent-color: var(--coral); margin-top: 8px; }
.settings-card .check { display: flex; gap: 10px; align-items: center; margin-top: 16px; font-size: 17px; cursor: pointer; }
.settings-card .check input { width: 20px; height: 20px; accent-color: var(--mint); }

/* ------------------------------------------------------------ webcam panel */

.cam {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 270px;
  aspect-ratio: 4 / 3;
  border: 3px solid var(--ink);
  border-radius: 20px;
  overflow: hidden;
  background: #1d1728;
  box-shadow: var(--shadow);
  z-index: 20;
  transition: width 0.45s ease, right 0.45s ease, bottom 0.45s ease, transform 0.45s ease;
}
.cam.big {
  right: 50%;
  bottom: 50%;
  width: min(640px, 62vw, calc((100vh - 290px) * 1.333));
  transform: translate(50%, 50%);
}
.cam video, .cam canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.cam video { object-fit: cover; transform: scaleX(-1); }
.cam-badge {
  position: absolute;
  left: 8px; right: 8px; bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  font-weight: 600;
}
.cam-badge .status {
  background: rgba(43, 33, 64, 0.8);
  color: #fff;
  padding: 4px 10px;
  border-radius: 999px;
}
.cam-badge .status::before { content: '●'; margin-right: 6px; color: #aaa; }
.cam-badge .status.ok::before { color: var(--mint); }
.cam-badge .status.bad::before { color: var(--berry); }
.lanes { display: flex; gap: 5px; background: rgba(43, 33, 64, 0.8); padding: 6px 8px; border-radius: 999px; }
.lanes i { width: 14px; height: 14px; border-radius: 50%; background: rgba(255,255,255,0.3); display: block; transition: background 0.15s, transform 0.15s; }
.lanes i.on { background: var(--sun); transform: scale(1.15); }

/* ------------------------------------------------------------ HUD */

.hud {
  position: fixed;
  top: 18px; left: 20px; right: 20px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
  z-index: 15;
}
.hud-score {
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 20px;
  box-shadow: 5px 5px 0 var(--ink);
  padding: 8px 18px 10px;
  min-width: 150px;
}
.hud-label { font-size: 13px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--ink-soft); font-weight: 600; }
.hud-big { font-size: 40px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.hud-coins { display: flex; align-items: center; gap: 7px; font-size: 22px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }
.coin-dot {
  width: 20px; height: 20px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff2a8, #ffc933 55%, #d99a00);
  border: 2px solid var(--ink);
  display: inline-block;
}
.hud-coins.pop { animation: pop 0.25s ease; }
@keyframes pop { 50% { transform: scale(1.18); } }

.hud-right { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.hearts { display: flex; gap: 6px; }
.hearts svg { width: 40px; height: 40px; filter: drop-shadow(3px 3px 0 var(--ink)); transition: transform 0.2s; }
.hearts svg.lost { opacity: 0.35; transform: scale(0.85); }
.hearts.hurt { animation: shake 0.4s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

.powers { display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.power {
  display: flex; align-items: center; gap: 8px;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 14px;
  padding: 5px 10px;
  font-weight: 600;
  font-size: 15px;
  box-shadow: 3px 3px 0 var(--ink);
}
.power .bar { width: 70px; height: 9px; border-radius: 9px; background: #eee; overflow: hidden; border: 2px solid var(--ink); }
.power .bar > div { height: 100%; background: var(--berry); }
.power.shield .bar > div { background: var(--sky); }

/* ------------------------------------------------------------ countdown & toast */

.countdown {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 180px;
  font-weight: 700;
  color: var(--sun);
  -webkit-text-stroke: 6px var(--ink);
  paint-order: stroke fill;
  text-shadow: 8px 8px 0 var(--ink);
  pointer-events: none;
  z-index: 30;
}
.countdown.tick { animation: count 0.7s ease-out; }
@keyframes count { from { transform: scale(1.6); opacity: 0; } 30% { transform: scale(1); opacity: 1; } to { transform: scale(0.9); opacity: 0.85; } }

.toast {
  position: fixed;
  top: 22px;
  left: 50%;
  transform: translate(-50%, -220%);
  background: var(--sun);
  border: 3px solid var(--ink);
  border-radius: 999px;
  box-shadow: 4px 4px 0 var(--ink);
  padding: 9px 22px;
  font-size: 22px;
  font-weight: 700;
  z-index: 40;
  pointer-events: none;
  transition: transform 0.3s cubic-bezier(0.3, 1.6, 0.5, 1);
  white-space: nowrap;
}
.toast.show { transform: translate(-50%, 0); }

@media (max-width: 900px) {
  .start { padding: 16px; justify-content: center; }
  .moves { grid-template-columns: repeat(2, 1fr); }
  .cam { width: 200px; }
}
