*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --pink: #ff6b9d;
  --pink-dark: #e84a7f;
  --purple: #9b59b6;
  --bg: #1a0a2e;
  --card: #2d1b4e;
  --text: #fff;
  --gold: #ffd700;
  --green: #2ecc71;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Nunito', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}

#app {
  width: 100%;
  height: 100%;
  position: relative;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.screen.active {
  display: flex;
}

/* ===== MENU ===== */
.menu-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 20% 20%, rgba(155, 89, 182, 0.4) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 80%, rgba(255, 107, 157, 0.35) 0%, transparent 50%),
    linear-gradient(160deg, #1a0a2e 0%, #2d1b4e 50%, #1a0a2e 100%);
  animation: bgPulse 8s ease-in-out infinite alternate;
}

@keyframes bgPulse {
  from { opacity: 1; }
  to { opacity: 0.85; }
}

.menu-content {
  position: relative;
  z-index: 1;
  width: min(920px, 94vw);
  text-align: center;
  padding: 1.5rem 0 2rem;
}

.title {
  font-size: clamp(1.8rem, 5vw, 2.8rem);
  font-weight: 800;
  background: linear-gradient(135deg, #ff6b9d, #ffd700, #c39bd3);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.4rem;
}

.subtitle {
  color: rgba(255, 255, 255, 0.7);
  margin-bottom: 1.8rem;
  font-size: 1.05rem;
}

.games-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}

@media (max-width: 700px) {
  .games-grid {
    grid-template-columns: 1fr;
    max-width: 320px;
    margin-left: auto;
    margin-right: auto;
  }
}

.game-card {
  position: relative;
  background: linear-gradient(145deg, #3d2a5c, #2d1b4e);
  border: 2px solid rgba(255, 107, 157, 0.35);
  border-radius: 20px;
  padding: 1.2rem 0.8rem 1.4rem;
  cursor: pointer;
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
  color: inherit;
  font-family: inherit;
  outline: none;
}

.game-card:hover:not(.done),
.game-card:focus-visible:not(.done) {
  transform: translateY(-6px) scale(1.02);
  border-color: var(--pink);
  box-shadow: 0 12px 30px rgba(255, 107, 157, 0.3);
}

.game-card.done {
  border-color: var(--green);
}

.game-card.done:hover,
.game-card.done:focus-visible {
  transform: translateY(-6px) scale(1.02);
  border-color: var(--green);
  box-shadow: 0 12px 30px rgba(46, 204, 113, 0.3);
}

.card-icon {
  width: 100px;
  height: 100px;
  margin: 0 auto 0.8rem;
  border-radius: 50%;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.25);
  border: 3px solid rgba(255, 255, 255, 0.15);
}

.card-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.game-card h2 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.game-card p {
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.55);
}

.check {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  font-size: 1.1rem;
  font-weight: 800;
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(46, 204, 113, 0.5);
  animation: popIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.check.show {
  display: flex;
}

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

.btn-random {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: linear-gradient(135deg, var(--pink), var(--purple));
  color: #fff;
  border: none;
  border-radius: 50px;
  padding: 0.9rem 2.2rem;
  font-size: 1.15rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(255, 107, 157, 0.4);
  transition: transform 0.15s, box-shadow 0.15s;
}

.btn-random:hover {
  transform: scale(1.05);
  box-shadow: 0 10px 30px rgba(255, 107, 157, 0.55);
}

.btn-random:active {
  transform: scale(0.97);
}

.btn-random:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.progress-text {
  margin-top: 1rem;
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.95rem;
}

/* ===== PRELOADER ===== */
#preloader {
  background: var(--bg);
  z-index: 100;
}

.preloader-inner {
  text-align: center;
}

.spinner-wrap {
  position: relative;
  width: 96px;
  height: 96px;
  margin: 0 auto 1.5rem;
}

.spinner {
  position: absolute;
  inset: 0;
  border: 5px solid rgba(255, 107, 157, 0.2);
  border-top-color: var(--pink);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.spinner-count {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.4rem;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 2px 12px rgba(255, 107, 157, 0.6);
  animation: countPop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes countPop {
  from { transform: scale(0.5); opacity: 0.4; }
  to { transform: scale(1); opacity: 1; }
}

.preloader-text {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 1.2rem;
  color: #ffc0d4;
}

.preloader-bar {
  width: 220px;
  height: 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
  margin: 0 auto;
}

.preloader-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--pink), var(--gold));
  border-radius: 4px;
  transition: width 0.05s linear;
}

/* ===== GAME COMMON ===== */
.game-screen {
  background: linear-gradient(180deg, #1a0a2e 0%, #16213e 100%);
}

.game-hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.7rem 1rem;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.55) 0%, transparent 100%);
  pointer-events: none;
}

.game-hud > * {
  pointer-events: auto;
}

.btn-back {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  border-radius: 20px;
  padding: 0.4rem 0.9rem;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(6px);
}

.btn-back:hover {
  background: rgba(255, 255, 255, 0.2);
}

.hud-stat {
  background: rgba(0, 0, 0, 0.4);
  border-radius: 20px;
  padding: 0.4rem 1rem;
  font-weight: 700;
  font-size: 0.95rem;
  backdrop-filter: blur(6px);
}

.btn-primary {
  background: linear-gradient(135deg, var(--pink), var(--pink-dark));
  color: #fff;
  border: none;
  border-radius: 50px;
  padding: 0.75rem 2rem;
  font-size: 1.05rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(255, 107, 157, 0.4);
  transition: transform 0.15s;
}

.btn-primary:hover {
  transform: scale(1.05);
}

.btn-primary:active {
  transform: scale(0.96);
}

.dialog {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  padding: 1rem;
}

.dialog.hidden {
  display: none;
}

.dialog-box {
  background: linear-gradient(145deg, #3d2a5c, #2d1b4e);
  border: 2px solid var(--pink);
  border-radius: 24px;
  padding: 1.8rem 1.5rem;
  text-align: center;
  max-width: 360px;
  width: 100%;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  animation: dialogIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes dialogIn {
  from { transform: scale(0.7); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.dialog-avatar {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--pink);
  margin-bottom: 1rem;
}

.dialog-avatar.big {
  width: 160px;
  height: 160px;
}

.dialog-box p {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 1.2rem;
  line-height: 1.35;
}

.overlay-msg {
  position: absolute;
  inset: 0;
  z-index: 25;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  gap: 0.5rem;
  text-align: center;
  padding: 1rem;
}

.overlay-msg.hidden {
  display: none;
}

.overlay-msg p {
  font-size: 1.3rem;
  font-weight: 700;
}

.overlay-msg .small {
  font-size: 0.95rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.7);
  margin-bottom: 1rem;
}

/* ===== GAME 1 ===== */
.g1-stage {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  overflow: hidden;
  background:
    radial-gradient(ellipse at center, #3d2a5c 0%, #1a0a2e 70%);
}

.g1-masha {
  width: min(280px, 55vw);
  height: auto;
  border-radius: 24px;
  box-shadow: 0 0 40px rgba(155, 89, 182, 0.4);
  transition: transform 0.08s;
  pointer-events: none;
  z-index: 2;
}

.g1-masha.pulse {
  transform: scale(0.92);
}

.g1-masha.awake {
  box-shadow: 0 0 50px rgba(255, 80, 80, 0.5);
}

.g1-floaters {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 3;
}

.floater {
  position: absolute;
  width: 110px;
  height: 110px;
  object-fit: contain;
  border-radius: 12px;
  pointer-events: none;
  animation: floatUp 2.8s ease-out forwards;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

@keyframes floatUp {
  0% {
    opacity: 1;
    transform: translate(0, 0) scale(0.55) rotate(0deg);
  }
  25% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(var(--fx, 40px), var(--fy, -280px)) scale(1.25) rotate(var(--fr, 20deg));
  }
}

.click-burst {
  position: absolute;
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--gold);
  pointer-events: none;
  z-index: 4;
  animation: burstUp 0.7s ease-out forwards;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

@keyframes burstUp {
  0% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-60px) scale(1.3); }
}

/* ===== GAME 2 ===== */
#game2 {
  background: #0d0618;
}

#game2 .g2-frame {
  position: relative;
  width: min(420px, 92vw);
  height: min(92vh, 780px);
  margin: auto;
  border: 4px solid var(--pink);
  border-radius: 16px;
  overflow: hidden;
  box-shadow:
    0 0 0 6px rgba(255, 107, 157, 0.2),
    0 12px 40px rgba(0, 0, 0, 0.55);
  background: #1a0a2e;
}

#g2-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#game2 .game-hud {
  width: min(420px, 92vw);
  left: 50%;
  transform: translateX(-50%);
  right: auto;
}

#game2 .g2-frame .dialog,
#game2 .g2-frame .overlay-msg {
  position: absolute;
  inset: 0;
  border-radius: 0;
}

.math-label {
  font-size: 1rem !important;
  color: rgba(255, 255, 255, 0.75) !important;
  font-weight: 600 !important;
}

.math-q {
  font-size: 2rem !important;
  font-weight: 800 !important;
  color: var(--gold) !important;
  margin: 0.5rem 0 1.2rem !important;
}

.math-answers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.7rem;
}

.math-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.25);
  color: #fff;
  border-radius: 14px;
  padding: 0.85rem;
  font-size: 1.25rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.math-btn:hover {
  background: rgba(255, 107, 157, 0.3);
  border-color: var(--pink);
  transform: scale(1.04);
}

.math-btn.wrong {
  background: rgba(231, 76, 60, 0.4);
  border-color: #e74c3c;
}

.math-btn.correct {
  background: rgba(46, 204, 113, 0.4);
  border-color: var(--green);
}

/* ===== GAME 3 ===== */
#game3 {
  background: #0d0618;
}

#game3 .g3-frame {
  position: relative;
  width: min(420px, 92vw);
  height: min(92vh, 780px);
  margin: auto;
  border: 4px solid var(--pink);
  border-radius: 16px;
  overflow: hidden;
  box-shadow:
    0 0 0 6px rgba(255, 107, 157, 0.2),
    0 12px 40px rgba(0, 0, 0, 0.55);
  background: #1a0a2e;
}

#g3-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#game3 .game-hud {
  width: min(420px, 92vw);
  left: 50%;
  transform: translateX(-50%);
  right: auto;
}

#game3 .g3-frame .dialog,
#game3 .g3-frame .overlay-msg {
  position: absolute;
  inset: 0;
  border-radius: 0;
}

.g3-win-box .win-title {
  font-size: 1.6rem !important;
  color: var(--gold) !important;
}

/* ===== FINAL ===== */
#final {
  background: #1a0a2e;
  z-index: 50;
}

.final-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 40%, rgba(255, 107, 157, 0.35) 0%, transparent 55%),
    radial-gradient(circle at 20% 80%, rgba(255, 215, 0, 0.2) 0%, transparent 40%),
    radial-gradient(circle at 80% 20%, rgba(155, 89, 182, 0.3) 0%, transparent 40%),
    linear-gradient(160deg, #1a0a2e, #2d1b4e);
}

.final-content {
  position: relative;
  z-index: 2;
  text-align: center;
  padding: 2rem 1.5rem;
  animation: finalIn 0.8s ease-out;
}

@keyframes finalIn {
  from { opacity: 0; transform: scale(0.85) translateY(30px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.final-masha {
  width: min(220px, 50vw);
  height: auto;
  border-radius: 50%;
  border: 5px solid var(--gold);
  box-shadow: 0 0 60px rgba(255, 215, 0, 0.5);
  margin-bottom: 1.5rem;
  animation: bounce 1.5s ease-in-out infinite;
}

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

.final-title {
  font-size: clamp(1.6rem, 5.5vw, 2.6rem);
  font-weight: 800;
  background: linear-gradient(135deg, #ff6b9d, #ffd700, #ff6b9d);
  background-size: 200% auto;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: shimmer 3s linear infinite;
  margin-bottom: 1rem;
  line-height: 1.25;
}

@keyframes shimmer {
  to { background-position: 200% center; }
}

.final-text {
  font-size: clamp(1.1rem, 3.5vw, 1.5rem);
  font-weight: 600;
  color: rgba(255, 255, 255, 0.9);
  max-width: 400px;
  margin: 0 auto;
  line-height: 1.4;
}

.confetti {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 1;
}

.confetti-piece {
  position: absolute;
  width: 10px;
  height: 14px;
  top: -20px;
  animation: confettiFall linear forwards;
  border-radius: 2px;
}

@keyframes confettiFall {
  0% {
    transform: translateY(0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(100vh) rotate(720deg);
    opacity: 0.3;
  }
}
