/* Triangles! — playful, paper-and-crayon theme */
:root {
  --paper: #f7f3e9;
  --paper2: #fdfbf5;
  --ink: #2f3a4a;
  --coral: #e4572e;
  --teal: #17a398;
  --yellow: #f6c445;
  --grape: #7d5ba6;
}

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

body {
  margin: 0;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background:
    radial-gradient(120% 120% at 50% 0%, #fdfbf5 0%, var(--paper) 55%, #f0ead9 100%);
  color: var(--ink);
  font-family: "Nunito", system-ui, -apple-system, sans-serif;
  font-weight: 700;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
    env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#canvas-el {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
}

/* top HUD */
#hud-top {
  position: fixed;
  top: max(8px, env(safe-area-inset-top));
  left: 0;
  right: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  flex-wrap: wrap;
}
#progress-el {
  display: flex;
  gap: 5px;
}
.stage {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  min-width: 34px;
  padding: 3px 6px;
  border-radius: 10px;
  background: #fff;
  border: 2px solid rgba(47, 58, 74, 0.12);
  font-size: 13px;
  line-height: 1.15;
  color: rgba(47, 58, 74, 0.55);
  transition: transform 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}
.stage i {
  font-style: normal;
  font-weight: 800;
}
.stage b {
  font-size: 10px;
  font-weight: 800;
}
.stage.locked {
  opacity: 0.5;
  background: #f0ece1;
}
.stage.locked i {
  color: rgba(47, 58, 74, 0.4);
}
.stage.done {
  border-color: var(--teal);
  color: var(--teal);
  background: #eafaf8;
}
.stage.done b {
  font-size: 12px;
}
.stage.cur {
  border-color: var(--coral);
  color: var(--coral);
  background: #fff3ee;
  box-shadow: 0 3px 10px rgba(228, 87, 46, 0.25);
  transform: translateY(-2px) scale(1.06);
}
#mastery-el {
  font-size: 12px;
  color: rgba(47, 58, 74, 0.55);
}

/* stage / concept label + streak */
#stage-el {
  position: fixed;
  top: 74px;
  left: 12px;
  z-index: 3;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--grape);
  text-transform: capitalize;
}
#streak-el {
  position: fixed;
  top: 70px;
  right: 12px;
  z-index: 3;
  font-size: 20px;
}

#flash-el {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 154px);
  left: 50%;
  z-index: 18;
  max-width: min(86vw, 520px);
  padding: 11px 20px;
  border-radius: 18px;
  border: 2px solid rgba(255, 255, 255, 0.82);
  background: rgba(253, 251, 245, 0.78);
  color: var(--ink);
  box-shadow:
    0 14px 34px rgba(47, 58, 74, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.76);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  font-size: clamp(18px, 2.8vw, 24px);
  font-weight: 800;
  text-align: center;
  line-height: 1.2;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -8px) scale(0.96);
  transition:
    opacity 0.18s ease,
    transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
}
#flash-el.good {
  color: var(--teal);
}
#flash-el.bad {
  color: var(--coral);
}
#flash-el.show {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}
#flash-el.hidden {
  display: none;
}

/* task + hint */
#question-wrap {
  position: fixed;
  top: 96px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
  width: min(92vw, 620px);
  text-align: center;
  pointer-events: none;
}
#question-el {
  font-size: clamp(16px, 4.4vw, 22px);
  font-weight: 800;
  color: var(--ink);
  text-shadow: 0 1px 0 #fff;
}
#target-el {
  margin-top: 4px;
  display: none;
  font-size: 15px;
  font-weight: 800;
  color: var(--coral);
}
#help-el {
  margin-top: 6px;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.25s ease, opacity 0.25s ease;
  font-size: 14px;
  font-weight: 700;
  color: rgba(47, 58, 74, 0.75);
}
#help-el.show {
  max-height: 120px;
  opacity: 1;
}

/* mascot */
#mascot {
  position: fixed;
  bottom: 78px;
  right: 10px;
  width: clamp(64px, 16vw, 104px);
  z-index: 2;
  pointer-events: none;
  filter: drop-shadow(0 5px 7px rgba(47, 58, 74, 0.22));
  transform-origin: bottom center;
  animation: bob 3.2s ease-in-out infinite;
}
@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(-2.5deg); }
  50% { transform: translateY(-9px) rotate(2.5deg); }
}
#mascot.kick {
  animation: kick 0.52s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes kick {
  0% { transform: scale(1) rotate(0); }
  35% { transform: scale(1.28) rotate(-8deg) translateY(-6px); }
  100% { transform: scale(1) rotate(0); }
}
@media (prefers-reduced-motion: reduce) {
  #mascot { animation: none; }
}

/* quiz overlay */
#quiz-el {
  position: fixed;
  inset: 120px 0 90px;
  z-index: 3;
  display: none;
  flex-wrap: wrap;
  align-content: center;
  justify-content: center;
  gap: 14px;
  padding: 12px;
}
.quiz-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 116px;
  padding: 16px 18px;
  border-radius: 18px;
  background: var(--paper2);
  border: 3px solid rgba(47, 58, 74, 0.14);
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.1s ease;
}
.quiz-card:active {
  transform: scale(0.97);
}
.quiz-card.sel {
  border-color: var(--coral);
  background: #fff0eb;
  box-shadow: 0 4px 14px rgba(228, 87, 46, 0.2);
}
.quiz-card .qv {
  font-size: 22px;
  font-weight: 800;
  color: var(--ink);
}
.quiz-card .qv.small {
  font-size: 13px;
  color: rgba(47, 58, 74, 0.6);
}

/* welcome / title screen */
#welcome-el {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background:
    radial-gradient(120% 120% at 50% 0%, #fff6e6 0%, #f7f3e9 55%, #efe6d2 100%);
  animation: fadein 0.3s ease;
}
#welcome-el.hidden {
  display: none;
}
#welcome-card {
  text-align: center;
  max-width: 360px;
  animation: pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}
#welcome-mascot {
  width: 130px;
  filter: drop-shadow(0 6px 8px rgba(47, 58, 74, 0.22));
  animation: bob 3s ease-in-out infinite;
}
#welcome-card h1 {
  margin: 6px 0 6px;
  font-size: 30px;
  font-weight: 800;
  color: var(--coral);
  letter-spacing: -0.01em;
}
#welcome-card p {
  margin: 0 0 16px;
  font-size: 15.5px;
  font-weight: 700;
  color: rgba(47, 58, 74, 0.75);
  line-height: 1.5;
}
#welcome-start {
  font-family: inherit;
  font-weight: 800;
  font-size: 18px;
  color: #fff;
  background: var(--coral);
  border: none;
  border-radius: 999px;
  padding: 14px 34px;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(228, 87, 46, 0.4);
  transition: transform 0.1s ease;
}
#welcome-start:active {
  transform: scale(0.95);
}

/* knowledge-unlock / theory overlay */
#unlock-el {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(47, 58, 74, 0.42);
  backdrop-filter: blur(3px);
  animation: fadein 0.25s ease;
}
#unlock-el.hidden {
  display: none;
}
#unlock-card {
  width: min(92vw, 380px);
  background: var(--paper2);
  border-radius: 22px;
  padding: 22px 22px 20px;
  text-align: center;
  box-shadow: 0 18px 50px rgba(47, 58, 74, 0.35);
  border: 3px solid #fff;
  animation: pop 0.42s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes pop {
  0% { transform: scale(0.7) translateY(20px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}
@keyframes fadein {
  from { opacity: 0; }
  to { opacity: 1; }
}
#unlock-badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--coral);
  background: #fdece5;
  padding: 5px 12px;
  border-radius: 999px;
}
#unlock-icon {
  font-size: 46px;
  margin: 8px 0 2px;
  animation: bob 2.6s ease-in-out infinite;
}
#unlock-title {
  margin: 2px 0 10px;
  font-size: 22px;
  font-weight: 800;
  color: var(--grape);
}
#unlock-diagram {
  display: flex;
  justify-content: center;
  margin: 4px 0 12px;
}
#unlock-diagram svg {
  max-width: 100%;
  height: auto;
}
#unlock-theory {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.5;
  color: var(--ink);
}
#unlock-rule {
  font-size: 13.5px;
  font-weight: 800;
  color: var(--teal);
  background: #e7f7f4;
  border-radius: 12px;
  padding: 9px 12px;
  margin-bottom: 16px;
}
#unlock-go {
  font-family: inherit;
  font-weight: 800;
  font-size: 17px;
  color: #fff;
  background: var(--coral);
  border: none;
  border-radius: 999px;
  padding: 12px 30px;
  cursor: pointer;
  box-shadow: 0 5px 14px rgba(228, 87, 46, 0.4);
  transition: transform 0.1s ease;
}
#unlock-go:active {
  transform: scale(0.95);
}

/* controls */
#controls {
  position: fixed;
  bottom: max(10px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 4;
  display: flex;
  gap: 8px;
  align-items: center;
  background: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(6px);
  padding: 8px;
  border-radius: 999px;
  box-shadow: 0 6px 20px rgba(47, 58, 74, 0.14);
}
#controls button {
  font-family: inherit;
  font-weight: 800;
  font-size: 15px;
  border: none;
  border-radius: 999px;
  padding: 10px 14px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 2px 5px rgba(47, 58, 74, 0.1);
  transition: transform 0.1s ease;
}
#controls button:active {
  transform: scale(0.94);
}
#controls button.primary {
  background: var(--coral);
  color: #fff;
  padding: 10px 20px;
  box-shadow: 0 4px 12px rgba(228, 87, 46, 0.35);
}
#controls button.primary.ready {
  background: var(--good);
  animation: readypulse 1.1s ease-in-out infinite;
}
@keyframes readypulse {
  0%, 100% { box-shadow: 0 4px 12px rgba(47, 163, 107, 0.4); transform: scale(1); }
  50% { box-shadow: 0 6px 20px rgba(47, 163, 107, 0.6); transform: scale(1.06); }
}
#prev-btn,
#skip-btn,
#reset-btn,
#mute-btn {
  min-width: 42px;
}

/* student selector */
#players-el {
  margin-left: auto;
}
#players-el.hidden {
  display: none;
}
.select-player {
  font-family: inherit;
  font-weight: 700;
  font-size: 14px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 2px solid var(--teal);
  background: #fff;
  color: var(--ink);
}

#version-el {
  position: fixed;
  bottom: 2px;
  left: 6px;
  z-index: 2;
  font-size: 10px;
  font-weight: 700;
  color: rgba(47, 58, 74, 0.35);
}

/* small screens: tuck the concept label under the progress row */
@media (max-height: 620px) {
  #mascot { width: 60px; bottom: 74px; }
  #question-el { font-size: 16px; }
}
