@import url('https://fonts.googleapis.com/css2?family=Luckiest+Guy&family=Nunito:wght@500;700;800;900&display=swap');

:root {
  --bg: #f7f8ff;
  --bg-soft: #edf0ff;
  --surface: rgba(255, 255, 255, 0.82);
  --surface-strong: rgba(255, 255, 255, 0.94);
  --text: #13213a;
  --muted: #5d6885;
  --primary: #5a62ff;
  --primary-strong: #3f46d9;
  --accent: #ffb703;
  --accent-2: #ff6b9f;
  --success: #1fbf75;
  --danger: #ff5277;
  --border: rgba(72, 93, 176, 0.18);
  --shadow: 0 20px 55px rgba(73, 90, 155, 0.16);
  --glass-blur: blur(18px);
}

body[data-theme='dark'] {
  --bg: #0d1326;
  --bg-soft: #151f3d;
  --surface: rgba(18, 27, 52, 0.76);
  --surface-strong: rgba(20, 31, 59, 0.92);
  --text: #f3f6ff;
  --muted: #b8c3ea;
  --primary: #8c93ff;
  --primary-strong: #7380ff;
  --accent: #ffd166;
  --accent-2: #ff8bb3;
  --success: #4fe39f;
  --danger: #ff7292;
  --border: rgba(163, 180, 255, 0.18);
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.36);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: 'Nunito', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background:
    radial-gradient(circle at top left, rgba(125, 143, 255, 0.24), transparent 28%),
    radial-gradient(circle at right bottom, rgba(255, 183, 3, 0.18), transparent 24%),
    linear-gradient(180deg, var(--bg), var(--bg-soft));
  color: var(--text);
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
  border: 0;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.background-glow {
  position: fixed;
  inset: auto;
  width: 28rem;
  height: 28rem;
  border-radius: 999px;
  filter: blur(70px);
  opacity: 0.55;
  pointer-events: none;
  z-index: -1;
}

.glow-1 {
  top: -7rem;
  left: -7rem;
  background: rgba(111, 126, 255, 0.38);
}

.glow-2 {
  right: -7rem;
  bottom: -8rem;
  background: rgba(255, 183, 3, 0.28);
}

.app-shell {
  width: min(1100px, calc(100% - 1.25rem));
  margin: 0 auto;
  padding: 1rem 0 2.5rem;
}

.topbar,
.card {
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-radius: 26px;
}

.glass {
  background: var(--surface);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
}

.nested-card {
  background: var(--surface-strong);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.18);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.15rem;
  margin-bottom: 1rem;
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.brand-badge {
  width: 3.2rem;
  height: 3.2rem;
  display: grid;
  place-items: center;
  font-size: 1.5rem;
  border-radius: 20px;
  background: linear-gradient(145deg, var(--accent), #ffe08a);
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, 0.08);
}

.topbar h1,
.hero-card h2,
.reward-summary h2,
.reward-play h3 {
  margin: 0;
  font-family: 'Luckiest Guy', cursive;
  font-weight: 400;
  letter-spacing: 0.04em;
  line-height: 1.05;
}

.topbar h1 {
  font-size: clamp(1.4rem, 2vw, 1.9rem);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.best-chip,
.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.6rem;
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-strong);
  font-weight: 800;
}

.icon-button {
  width: 3rem;
  height: 3rem;
  border-radius: 18px;
  background: linear-gradient(145deg, var(--primary), var(--primary-strong));
  color: white;
  display: grid;
  place-items: center;
  box-shadow: 0 12px 25px rgba(90, 98, 255, 0.28);
}

.theme-label {
  font-size: 1.2rem;
}

.eyebrow {
  margin: 0 0 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.74rem;
  font-weight: 900;
  color: var(--primary);
}

.subtitle,
.reward-note,
.rule-item p,
.side-note,
.feedback-text,
.small {
  color: var(--muted);
}

.hero-grid,
.reward-grid {
  display: grid;
  grid-template-columns: 1.3fr 0.9fr;
  gap: 1rem;
}

.hero-card,
.mascot-card,
.reward-summary,
.reward-play,
.problem-card,
.progress-card,
.hud-card {
  padding: 1.25rem;
}

.hero-card {
  min-height: 100%;
}

.hero-card h2 {
  font-size: clamp(2rem, 5vw, 3.55rem);
  max-width: 14ch;
}

.hero-card .subtitle {
  font-size: clamp(1rem, 2.2vw, 1.2rem);
  margin: 0.8rem 0 1rem;
  max-width: 42rem;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-bottom: 1rem;
}

.rules {
  display: grid;
  gap: 0.8rem;
  padding: 1rem;
  margin-bottom: 1.1rem;
}

.rule-item {
  display: flex;
  gap: 0.9rem;
  align-items: flex-start;
}

.rule-icon {
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, rgba(90,98,255,0.17), rgba(255,183,3,0.17));
  font-size: 1.15rem;
}

.rule-item strong {
  display: block;
  margin-bottom: 0.2rem;
}

.rule-item p {
  margin: 0;
}

.mascot-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  text-align: center;
  min-height: 100%;
}

.mascot {
  font-size: clamp(4rem, 12vw, 7rem);
  line-height: 1;
  filter: drop-shadow(0 14px 24px rgba(255,183,3,0.24));
  animation: floaty 3.2s ease-in-out infinite;
}

.mascot-bubbles {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: center;
}

.mascot-bubbles span {
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  background: var(--surface-strong);
  border: 1px solid var(--border);
  font-weight: 900;
}

.launch-button,
.primary-button,
.secondary-button {
  min-height: 3.3rem;
  border-radius: 20px;
  padding: 0.85rem 1.2rem;
  font-weight: 900;
  transition: transform 160ms ease, box-shadow 160ms ease, opacity 160ms ease;
}

.primary-button {
  color: white;
  background: linear-gradient(145deg, var(--primary), var(--primary-strong));
  box-shadow: 0 14px 30px rgba(90, 98, 255, 0.3);
}

.launch-button {
  width: min(100%, 18rem);
  font-size: 1.1rem;
}

.secondary-button {
  color: var(--text);
  background: var(--surface-strong);
  border: 1px solid var(--border);
}

.primary-button:hover,
.secondary-button:hover,
.icon-button:hover {
  transform: translateY(-2px);
}

.primary-button:active,
.secondary-button:active,
.icon-button:active {
  transform: translateY(0);
}

.hud-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.8rem;
}

.hud-card {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.hud-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-weight: 900;
  color: var(--muted);
}

.hud-value {
  font-size: clamp(1.3rem, 3vw, 2.2rem);
  line-height: 1;
}

.star-bank {
  position: relative;
  overflow: hidden;
}

.star-bank::after {
  content: '⭐';
  position: absolute;
  right: 0.9rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.2rem;
  opacity: 0.7;
}

.progress-card {
  margin: 0.9rem 0;
}

.progress-copy {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  margin-bottom: 0.8rem;
  font-weight: 900;
}

.progress-track {
  width: 100%;
  height: 0.95rem;
  background: rgba(127, 145, 229, 0.16);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--primary));
  transition: width 280ms ease;
}

.problem-card {
  text-align: center;
  position: relative;
  overflow: hidden;
}

.problem-row {
  display: grid;
  grid-template-columns: auto minmax(2.2ch, auto);
  grid-template-rows: auto auto auto;
  align-items: end;
  column-gap: 0.2rem;
  row-gap: 0.1rem;
  width: fit-content;
  margin: 0.5rem auto 1rem;
}

#problem-a {
  grid-column: 2;
  grid-row: 1;
  text-align: right;
}

.problem-operator {
  grid-column: 1;
  grid-row: 2;
  align-self: center;
}

#problem-b {
  grid-column: 2;
  grid-row: 2;
  text-align: right;
}

.problem-row::after {
  content: '';
  grid-column: 1 / span 2;
  grid-row: 3;
  height: 4px;
  border-radius: 999px;
  background: var(--text);
  margin-top: 0.25rem;
}

.problem-number,
.problem-operator {
  font-family: 'Luckiest Guy', cursive;
  font-weight: 400;
  line-height: 1;
}

.problem-number {
  font-size: clamp(4rem, 16vw, 7.5rem);
}

.problem-operator {
  font-size: clamp(2.6rem, 9vw, 4.8rem);
  color: var(--accent-2);
}

.answer-form {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.answer-form input {
  width: min(100%, 14rem);
  min-height: 4rem;
  text-align: right;
  padding-right: 0.8rem;
  border-radius: 20px;
  border: 2px solid rgba(127, 145, 229, 0.22);
  background: var(--surface-strong);
  color: var(--text);
  font-size: clamp(1.7rem, 5vw, 2.5rem);
  font-weight: 900;
  outline: none;
}

.answer-form input::-webkit-outer-spin-button,
.answer-form input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.answer-form input[type='number'] {
  -moz-appearance: textfield;
}

.answer-form input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 5px rgba(90, 98, 255, 0.13);
}

.feedback-text {
  min-height: 1.6rem;
  margin: 0.9rem 0 0;
  font-weight: 800;
}

.feedback-success {
  color: var(--success);
}

.feedback-danger {
  color: var(--danger);
}

.reward-summary h2 {
  font-size: clamp(1.9rem, 5vw, 3.1rem);
}

.summary-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  margin: 1rem 0;
}

.stat-block,
.reward-timer {
  padding: 1rem;
  text-align: center;
}

.stat-block span,
.reward-timer span {
  display: block;
  margin-bottom: 0.25rem;
  color: var(--muted);
  font-weight: 800;
}

.stat-block strong,
.reward-timer strong {
  font-size: clamp(1.4rem, 4vw, 2.25rem);
}

.reward-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin: 1rem 0 0.8rem;
}

.reward-actions > * {
  flex: 1 1 220px;
}

.reward-play-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: end;
}

.mini-score {
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  background: var(--surface-strong);
  border: 1px solid var(--border);
  font-weight: 900;
}

.game-catalog {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
}

.game-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  text-align: left;
  padding: 1rem;
  border-radius: 22px;
  border: 1px solid var(--border);
  background: var(--surface-strong);
  color: var(--text);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.08);
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.game-card:hover {
  transform: translateY(-2px);
  border-color: rgba(111, 126, 255, 0.42);
}

.game-card-active {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(111, 126, 255, 0.16), var(--shadow);
}

.game-card-icon {
  font-size: 1.7rem;
}

.game-card-title {
  font-family: 'Luckiest Guy', cursive;
  font-size: 1.15rem;
  letter-spacing: 0.04em;
}

.game-card-copy {
  color: var(--muted);
  font-weight: 800;
  font-size: 0.95rem;
}

.reward-stage-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 1rem;
}

.active-game-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 2.8rem;
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-strong);
  font-weight: 900;
}

.compact-button {
  min-height: 2.8rem;
  padding: 0.7rem 1rem;
}

.reward-arena {
  position: relative;
  min-height: 26rem;
  border-radius: 26px;
  margin-top: 0.85rem;
  padding: 0.8rem;
  border: 1px solid rgba(127, 145, 229, 0.24);
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 22%, rgba(255,255,255,0.2), transparent 14%),
    radial-gradient(circle at 82% 76%, rgba(255,255,255,0.14), transparent 18%),
    linear-gradient(180deg, rgba(111,126,255,0.18), rgba(255,183,3,0.12));
}

.reward-game-status {
  margin: 0.75rem 0 0;
  min-height: 1.5rem;
  font-weight: 800;
  color: var(--muted);
}

.mini-game-empty {
  min-height: 22rem;
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
  gap: 0.5rem;
  padding: 1rem;
  color: var(--muted);
}

.mini-game-empty strong {
  color: var(--text);
  font-size: 1.15rem;
}

.mini-game-empty-icon {
  font-size: 2.2rem;
}

.mini-game-shell {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  width: 100%;
}

.mini-game-canvas-wrap {
  display: flex;
  justify-content: center;
}

.mini-game-canvas {
  display: block;
  max-width: 100%;
  border-radius: 22px;
  border: 1px solid rgba(127, 145, 229, 0.24);
  background: #081121;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.04);
  touch-action: none;
}

.mini-game-help {
  text-align: center;
  color: var(--muted);
  font-weight: 800;
  min-height: 1.4rem;
}

.mini-game-controls {
  display: grid;
  gap: 0.55rem;
  justify-content: center;
}

.dpad-controls {
  grid-template-columns: repeat(3, minmax(0, 4rem));
  grid-template-areas:
    '. up .'
    'left down right';
  align-items: center;
}

.control-up {
  grid-area: up;
}

.control-left {
  grid-area: left;
}

.control-down {
  grid-area: down;
}

.control-right {
  grid-area: right;
}

.lane-controls {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.control-button {
  min-height: 3rem;
  padding: 0.7rem 0.9rem;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--surface-strong);
  color: var(--text);
  font-weight: 900;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.08);
}

.control-button:active {
  transform: scale(0.98);
}

.reward-star {
  position: absolute;
  width: clamp(2.9rem, 8vw, 4rem);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #fff7c4, #ffd166 55%, #ffb703 100%);
  box-shadow: 0 12px 20px rgba(255, 183, 3, 0.35);
  user-select: none;
  animation: popIn 180ms ease, twinkle 1.8s ease-in-out infinite;
}

.reward-star.fade-out {
  animation: fadeStar 260ms ease forwards;
}

#overlay-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.flying-star,
.spark-burst,
.reward-pop {
  position: fixed;
  z-index: 30;
  pointer-events: none;
}

.flying-star {
  font-size: clamp(2rem, 5vw, 3.4rem);
  animation: flyToBank 720ms cubic-bezier(0.18, 0.82, 0.23, 1.02) forwards;
  transform-origin: center;
}

.spark-burst {
  font-size: clamp(1.3rem, 4vw, 2rem);
  animation: burstAway 620ms ease forwards;
}

.reward-pop {
  font-weight: 900;
  font-size: 1.4rem;
  color: var(--accent);
  animation: burstAway 600ms ease forwards;
}

.pulse-bank {
  animation: pulseBank 380ms ease;
}

.correct-flash {
  animation: correctFlash 360ms ease;
}

.wrong-shake {
  animation: wrongShake 280ms ease;
}

@keyframes floaty {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

@keyframes pulseBank {
  0% { transform: scale(1); }
  45% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

@keyframes correctFlash {
  0% { box-shadow: var(--shadow); }
  45% { box-shadow: 0 0 0 8px rgba(31, 191, 117, 0.18), var(--shadow); }
  100% { box-shadow: var(--shadow); }
}

@keyframes wrongShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-9px); }
  50% { transform: translateX(9px); }
  75% { transform: translateX(-6px); }
}

@keyframes flyToBank {
  0% {
    opacity: 1;
    transform: translate(var(--tx-start, 0), var(--ty-start, 0)) scale(0.9) rotate(-6deg);
  }
  65% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(var(--tx-end, 0), var(--ty-end, 0)) scale(0.38) rotate(18deg);
  }
}

@keyframes burstAway {
  0% {
    opacity: 1;
    transform: translate(0, 0) scale(0.9);
  }
  100% {
    opacity: 0;
    transform: translate(var(--dx, 0), var(--dy, -75px)) scale(1.4);
  }
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.65);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes twinkle {
  0%, 100% { transform: scale(1) rotate(0deg); }
  50% { transform: scale(1.08) rotate(5deg); }
}

@keyframes fadeStar {
  from { opacity: 1; transform: scale(1); }
  to { opacity: 0; transform: scale(0.45); }
}

@media (max-width: 980px) {
  .hero-grid,
  .reward-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 780px) {
  .app-shell {
    width: min(100% - 1rem, 100%);
    padding-top: 0.75rem;
  }

  .topbar {
    padding: 0.9rem;
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
    justify-content: space-between;
  }

  .hud-grid,
  .summary-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .reward-arena {
    min-height: 20rem;
  }

  .reward-stage-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (max-width: 560px) {
  .hud-grid,
  .summary-stats {
    grid-template-columns: 1fr 1fr;
  }

  .hero-card,
  .mascot-card,
  .reward-summary,
  .reward-play,
  .problem-card,
  .progress-card,
  .hud-card {
    padding: 1rem;
  }

  .hero-card h2 {
    font-size: clamp(1.7rem, 10vw, 2.8rem);
  }

  .problem-number {
    font-size: clamp(3.2rem, 20vw, 5.4rem);
  }

  .answer-form input,
  .primary-button,
  .secondary-button {
    width: 100%;
  }

  .answer-form {
    flex-direction: column;
  }

  .reward-actions {
    flex-direction: column;
  }

  .lane-controls {
    grid-template-columns: 1fr;
  }
}
