:root {
  --primary-color: #EF5350; 
  --secondary-color: #26A69A; 
  --bg-color: #F5F5F6;
  --text-color: #333;
  --btn-text: #FFF;
  --card-bg: #FFFFFF;
  --locked-bg: #EEEEEE;
  --locked-text: #000000;
  --border-radius: 12px;
}
[data-theme="dark"] {
  --primary-color: #EF5350;
  --secondary-color: #26A69A;
  --bg-color: #121212;
  --text-color: #E0E0E0;
  --btn-text: #FFF;
  --card-bg: #1E1E1E;
  --locked-bg: #333333;
  --locked-text: #FFFFFF;
}
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: radial-gradient(circle at center top, #e3f2fd 0%, #bbdefb 100%);
  background-color: var(--bg-color);
  color: var(--text-color);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100vh;
  overflow: hidden;
  user-select: none;
}

.screen {
  width: 100%;
  max-width: 600px;
  height: 100vh;
  height: 100dvh;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  background: radial-gradient(circle at center top, #e3f2fd 0%, #bbdefb 100%);
  transition: opacity 0.3s ease;
  box-sizing: border-box;
}

[data-theme="dark"] body,
[data-theme="dark"] .screen {
  background: var(--bg-color);
}

.hidden { display: none !important; opacity: 0; pointer-events: none; }

h1, h2, h3 { text-align: center; margin-bottom: 10px; color: var(--primary-color); }

.header-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.btn {
  padding: 10px 16px;
  border: none;
  border-radius: 20px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(0,0,0,0.1);
  transition: transform 0.1s, box-shadow 0.1s, opacity 0.2s;
  text-align: center;
}
.btn.small { padding: 6px 12px; font-size: 14px; margin: 0; border-radius: 16px; }
.btn:active {
  transform: translateY(4px);
  box-shadow: 0 0 0 rgba(0,0,0,0);
}
.btn.primary { background-color: var(--primary-color); color: var(--btn-text); width: 100%; margin: 8px 0; }
.btn.secondary { background-color: var(--secondary-color); color: var(--btn-text); }

.timer-badge {
  background-color: var(--primary-color);
  color: white;
  padding: 5px 15px;
  border-radius: 20px;
  font-weight: bold;
}

.levels-header { margin-bottom: 10px; }
.horizontal-scroll {
  display: flex;
  overflow-x: auto;
  gap: 8px;
  padding-bottom: 8px;
}
.horizontal-scroll::-webkit-scrollbar { height: 6px; }
.horizontal-scroll::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }

.level-card {
  min-width: 80px;
  background: var(--card-bg);
  padding: 8px;
  border-radius: 8px;
  text-align: center;
  font-size: 13px;
  font-weight: bold;
  border: 2px solid transparent;
  flex-shrink: 0;
  color: var(--text-color);
}
.level-card.locked { opacity: 0.5; background: var(--locked-bg); color: var(--locked-text); cursor: not-allowed; }
.level-card.unlocked { border-color: var(--secondary-color); cursor: pointer; }
.level-card.active { background: var(--secondary-color); color: #FFF; }

#game-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#current-sublevel-info {
  text-align: center;
  font-weight: bold;
  font-size: 16px;
  color: var(--secondary-color);
  margin-bottom: 6px;
  cursor: pointer;
  user-select: none;
}

.progress-bar-container {
  width: 100%; height: 16px; background-color: #E0E0E0;
  border-radius: 8px; position: relative; margin-bottom: 6px;
}
#progress-bar {
  height: 100%; background-color: var(--secondary-color);
  border-radius: 8px; transition: width 0.3s ease;
}
#progress-text {
  position: absolute; width: 100%; text-align: center;
  top: 0px; left: 0; font-size: 12px; color: #333; font-weight: bold;
}

.equation-area {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; background: var(--card-bg); padding: 8px 10px;
  border-radius: var(--border-radius); box-shadow: 0 4px 10px rgba(0,0,0,0.1);
  margin-bottom: 6px;
}
.equation-part { font-size: 26px; font-weight: bold; color: var(--primary-color); }
.equation-equals { font-size: 26px; margin: 0 8px; color: #888; }
.options-container { display: flex; flex-direction: column; gap: 6px; flex: 1; }

.option-btn {
  padding: 6px; font-size: 18px; font-weight: bold;
  border: 2px solid var(--secondary-color); background-color: var(--card-bg);
  color: var(--secondary-color); border-radius: 8px; cursor: pointer;
  transition: all 0.2s;
}
.option-btn:active { background-color: #ddd; }
.option-btn.correct { background-color: #4CAF50 !important; color: white !important; border-color: #4CAF50 !important; }
.option-btn.incorrect { background-color: #F44336 !important; color: white !important; border-color: #F44336 !important; }

#cooldown-screen { justify-content: center; align-items: center; text-align: center; }
#cooldown-screen p { font-size: 18px; color: #666; margin-top: 10px; }
#cooldown-timer { font-size: 72px; font-weight: bold; color: var(--primary-color); margin-top: 20px; line-height: 1; user-select: none; }
#btn-parent-panel-cooldown { margin-top: 30px; width: 100%; max-width: 280px; }

/* Модальное окно подтверждения сброса */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999999;
  padding: 16px;
  box-sizing: border-box;
}

.modal-backdrop.hidden {
  display: none !important;
}

.modal-card {
  background: var(--card-bg);
  color: var(--text-color);
  border-radius: var(--border-radius);
  padding: 24px 20px;
  text-align: center;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.45);
  box-sizing: border-box;
  max-width: 360px;
  width: 100%;
  animation: modalPop 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes modalPop {
  0% { transform: scale(0.8); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.modal-icon {
  font-size: 44px;
  margin-bottom: 8px;
  line-height: 1;
}

.modal-title {
  font-size: 19px;
  font-weight: bold;
  color: var(--primary-color);
  margin-bottom: 10px;
}

.modal-message {
  font-size: 15px;
  line-height: 1.4;
  margin-bottom: 12px;
  color: var(--text-color);
}

.modal-warning {
  font-size: 13px;
  line-height: 1.4;
  color: #e53935;
  background: rgba(229, 57, 53, 0.1);
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 18px;
  text-align: left;
  border-left: 3px solid #e53935;
}

.modal-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn.danger {
  background-color: #d32f2f;
  color: #ffffff;
  border: none;
  padding: 12px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: bold;
  cursor: pointer;
  transition: background-color 0.2s;
  width: 100%;
}

.btn.danger:active {
  background-color: #b71c1c;
}

#question-container {
  width: 100%;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.timer-bar { width: 100%; height: 6px; background-color: #E0E0E0; border-radius: 3px; margin-bottom: 6px; }
#question-timer-bar { height: 100%; background-color: var(--primary-color); border-radius: 3px; width: 100%; }

.next-btn-slot {
  height: 42px;
  min-height: 42px;
  max-height: 42px;
  margin: 4px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

#btn-next-question {
  width: 100%;
  max-width: 320px;
  height: 40px;
  margin: 0;
  opacity: 1;
  visibility: visible;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

#btn-next-question.hidden {
  display: block !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

.visual-grid-wrapper {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  overflow: hidden;
}

.success-title { font-size: 48px; color: var(--secondary-color); margin-top: 40%; text-align: center; }
.stat-card { background: var(--card-bg); padding: 15px; margin-bottom: 10px; border-radius: 12px; font-size: 14px; }
#stats-container { overflow-y: auto; flex: 1; margin-bottom: 15px; }

.visual-grid {
  display: grid;
  grid-template-columns: min(20px, 8%) repeat(10, 1fr);
  grid-template-rows: min(20px, 8%) repeat(10, 1fr);
  gap: 1px;
  width: auto;
  height: 100%;
  max-width: 100%;
  max-height: 320px;
  aspect-ratio: 1 / 1;
  margin: auto;
  background-color: transparent;
}
.visual-cell {
  background-color: var(--card-bg);
  border-radius: 2px;
  border: 1px solid #ccc;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.3s;
}
.visual-cell.active {
  background-color: var(--secondary-color);
  border-color: var(--secondary-color);
  color: white;
  font-weight: bold;
  font-size: 11px;
}
.grid-sum-text {
  opacity: 0;
  transition: opacity 0.3s ease;
}
.visual-grid.answered .grid-sum-text {
  opacity: 1;
}
.diagonal-text {
  font-size: 11px;
  color: var(--primary-color);
  opacity: 0.6;
  font-weight: bold;
}
.visual-cell.active .diagonal-text {
  color: white;
  opacity: 0.8;
}
.visual-header {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: bold;
  color: #666;
}

.visual-header.pulse-multiplier {
  position: relative;
  z-index: 5;
  color: #E53935 !important;
  font-weight: 900 !important;
  font-size: 13px !important;
  animation: multiplier-pulse 0.8s infinite alternate ease-in-out;
}

[data-theme="dark"] .visual-header.pulse-multiplier {
  color: #FF5252 !important;
}

@keyframes multiplier-pulse {
  0% {
    transform: scale(1);
    opacity: 0.85;
  }
  100% {
    transform: scale(1.65);
    opacity: 1;
    text-shadow: 0 0 6px currentColor;
  }
}

.diagonal-red {
  color: #E53935 !important;
  font-weight: 800 !important;
  opacity: 1 !important;
  font-size: 11px;
}
[data-theme="dark"] .diagonal-red {
  color: #FF5252 !important;
}

.table-cell-text {
  font-size: 10px;
  color: var(--text-color);
  opacity: 0.7;
  font-weight: 500;
}
[data-theme="dark"] .table-cell-text {
  color: #CCC;
  opacity: 0.8;
}
[data-theme="dark"] .visual-cell {
  border-color: #444;
}

/* ==============================
   Праздничный экран поздравлений
   ============================== */
#success-screen {
  justify-content: center;
  align-items: center;
  text-align: center;
  position: relative;
  overflow: hidden;
  padding: 20px 15px;
}

.confetti-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: hidden;
  z-index: 1;
}

.confetti-piece {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  opacity: 0.9;
  animation: confetti-fall 3s linear infinite;
}

@keyframes confetti-fall {
  0% {
    transform: translateY(-20px) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(105vh) rotate(720deg);
    opacity: 0;
  }
}

.success-card {
  position: relative;
  z-index: 2;
  background: var(--card-bg);
  border-radius: 16px;
  padding: 30px 20px;
  max-width: 440px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.success-card.festive {
  border-radius: 20px;
  padding: 24px 20px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.15);
  border: 2px solid rgba(239, 83, 80, 0.2);
}

.success-hero-icon {
  font-size: 56px;
  line-height: 1;
  animation: hero-bounce 1.5s ease-in-out infinite alternate;
}

@keyframes hero-bounce {
  0% { transform: translateY(0) scale(1); }
  100% { transform: translateY(-8px) scale(1.1); }
}

.success-hero-title {
  font-size: 26px;
  font-weight: 800;
  color: var(--primary-color);
  margin: 0;
  line-height: 1.2;
}

.success-hero-subtitle {
  font-size: 20px;
  font-weight: 700;
  color: var(--secondary-color);
  line-height: 1.3;
}

.stars-celebration {
  display: flex;
  gap: 8px;
  font-size: 26px;
  margin: 4px 0;
}

.star-anim {
  display: inline-block;
  animation: star-pulse 1s ease-in-out infinite alternate;
}

@keyframes star-pulse {
  0% { transform: scale(0.85) rotate(-5deg); }
  100% { transform: scale(1.15) rotate(10deg); }
}

.success-message-text {
  font-size: 15px;
  color: var(--text-color);
  opacity: 0.85;
  margin: 0;
}

/* Баннер прохождения ВСЕЙ таблицы (на 9) */
.grand-celebration-box {
  background: linear-gradient(135deg, rgba(255, 215, 0, 0.15), rgba(255, 110, 64, 0.18));
  border: 2px dashed #FFA000;
  border-radius: 14px;
  padding: 14px 12px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  animation: grand-glow 2s ease-in-out infinite alternate;
}

@keyframes grand-glow {
  0% { box-shadow: 0 0 10px rgba(255, 193, 7, 0.3); }
  100% { box-shadow: 0 0 25px rgba(255, 193, 7, 0.6); }
}

.grand-badge-header {
  font-size: 15px;
  font-weight: 900;
  color: #E65100;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 6px;
}
[data-theme="dark"] .grand-badge-header {
  color: #FFD54F;
}

.grand-subtext {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-color);
  margin: 0;
}

.grand-subtext-highlight {
  font-size: 13px;
  color: var(--secondary-color);
  font-weight: bold;
  margin: 0;
  line-height: 1.3;
}

.festive-stickers {
  display: flex;
  gap: 12px;
  font-size: 28px;
  margin-top: 4px;
}

.sticker {
  display: inline-block;
  animation: sticker-wiggle 1.8s ease-in-out infinite alternate;
}
.sticker:nth-child(2n) {
  animation-delay: 0.3s;
}
.sticker:nth-child(3n) {
  animation-delay: 0.6s;
}

@keyframes sticker-wiggle {
  0% { transform: translateY(0) rotate(-8deg); }
  100% { transform: translateY(-5px) rotate(8deg); }
}

.btn-continue-festive {
  width: 100%;
  padding: 14px;
  font-size: 18px;
  font-weight: bold;
  margin-top: 6px;
  box-shadow: 0 4px 15px rgba(239, 83, 80, 0.4);
  letter-spacing: 0.5px;
}

.backup-actions {
  display: flex;
  gap: 10px;
  margin-top: 10px;
  width: 100%;
}

.backup-actions .btn {
  flex: 1;
  font-size: 13px;
  padding: 10px 4px;
  line-height: 1.2;
}

/* ==============================
   Детское оформление
   ============================== */
.equation-part {
  font-weight: 900;
  color: #1565c0;
}
[data-theme="dark"] .equation-part {
  color: #90caf9;
}

/* Звездочки прогресса */
.stars-progress {
  display: flex;
  gap: 5px;
  font-size: 20px;
  align-items: center;
  justify-content: center;
}
.star-empty {
  opacity: 0.25;
  filter: grayscale(100%);
  transition: transform 0.2s ease;
}
.star-filled {
  color: #ffd700;
  animation: starPop 0.3s ease-out forwards;
  text-shadow: 0 0 6px rgba(255, 215, 0, 0.6);
}

@keyframes starPop {
  0% { transform: scale(0); }
  70% { transform: scale(1.4); }
  100% { transform: scale(1); }
}

/* Анимация ошибки */
.shake-error {
  animation: shake 0.4s;
  color: #d32f2f !important;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-10px); }
  40%, 80% { transform: translateX(10px); }
}

/* Капибара */
.capy-wrapper {
  position: fixed;
  bottom: -20px;
  z-index: 1000;
  transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  pointer-events: none;
}
.animal-sprite {
  width: 280px;
  height: 280px;
  max-width: 48vw;
  max-height: 48vw;
  filter: drop-shadow(0 10px 10px rgba(0,0,0,0.25));
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}
.capy-right {
  right: 0px;
  transform: translateX(400px);
}
.capy-right.peek {
  transform: translateX(-10px);
}
.capy-left {
  left: 0px;
  transform: translateX(-400px);
}
.capy-left.peek {
  transform: translateX(10px);
}




