/* ==========================================================================
   CSS CHO ỨNG DỤNG "BÉ HỌC TOÁN" - PHONG CÁCH PASTEL 3D TRẺ EM
   ========================================================================== */

/* 1. Thiết lập biến màu sắc (Color Tokens) & Reset */
:root {
  --font-family: 'Fredoka', 'Segoe UI', -apple-system, sans-serif;
  
  /* Bảng màu Pastel */
  --bg-gradient-start: #e0f2fe; /* Xanh trời nhạt */
  --bg-gradient-end: #fae8ff;   /* Hồng phấn nhạt */
  
  --color-primary: #ff708a;     /* Hồng đậm Phép Cộng */
  --color-primary-shadow: #e04a66;
  
  --color-secondary: #4ea8de;   /* Xanh dương Phép Trừ */
  --color-secondary-shadow: #3b88b5;
  
  --color-back: #a78bfa;        /* Tím nút quay lại */
  --color-back-shadow: #8b5cf6;

  /* Màu sắc cho 4 ô đáp án */
  --color-peach: #ffadad;
  --color-peach-shadow: #f88787;
  --color-mint: #caffbf;
  --color-mint-shadow: #9de28f;
  --color-lemon: #fdffb6;
  --color-lemon-shadow: #e1e389;
  --color-skyblue: #9bf6ff;
  --color-skyblue-shadow: #63dbeb;
  
  --color-text-dark: #2d3748;
  --color-text-light: #ffffff;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body {
  font-family: var(--font-family);
  background-color: #f7fafc;
  color: var(--color-text-dark);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

/* 2. Container chính: Tối ưu hướng ngang (Tablet Landscape 4:3 / 16:10) */
.app-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  max-width: 1280px;
  max-height: 800px;
  background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
  border-radius: 0;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.08);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Cho màn hình desktop rộng hơn tỷ lệ tablet: hiển thị bo góc như máy tính bảng */
@media (min-width: 1281px), (min-height: 801px) {
  .app-container {
    width: 95vw;
    height: 90vh;
    border-radius: 36px;
    border: 8px solid rgba(255, 255, 255, 0.9);
  }
}

/* 3. Hiệu ứng bong bóng bay nhẹ nhàng phía sau */
.bubble-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  z-index: 1;
  pointer-events: none;
}

.bubble {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
  animation: float-bubble 15s infinite linear;
  bottom: -150px;
}

.bubble-1 { width: 80px; height: 80px; left: 10%; animation-duration: 18s; }
.bubble-2 { width: 120px; height: 120px; left: 30%; animation-duration: 25s; animation-delay: 2s; }
.bubble-3 { width: 60px; height: 60px; left: 55%; animation-duration: 14s; animation-delay: 4s; }
.bubble-4 { width: 100px; height: 100px; left: 75%; animation-duration: 22s; animation-delay: 1s; }
.bubble-5 { width: 90px; height: 90px; left: 90%; animation-duration: 20s; animation-delay: 5s; }

@keyframes float-bubble {
  0% { transform: translateY(0) rotate(0deg); opacity: 0; }
  10% { opacity: 0.6; }
  90% { opacity: 0.6; }
  100% { transform: translateY(-110vh) rotate(360deg); opacity: 0; }
}

/* 4. Định nghĩa Màn hình (Screens) */
.screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  flex-direction: column;
  z-index: 2;
  padding: 24px;
}

.screen.active {
  display: flex;
}

/* 5. Giao diện MÀN HÌNH CHÍNH */
#home-screen {
  justify-content: center;
  align-items: center;
  text-align: center;
}

.home-content {
  background: rgba(255, 255, 255, 0.65);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 4px solid rgba(255, 255, 255, 0.8);
  border-radius: 40px;
  padding: 40px 60px;
  box-shadow: 0 15px 35px rgba(103, 80, 164, 0.08);
  max-width: 800px;
  width: 90%;
  animation: bounce-in 1.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.app-title {
  font-size: 3.8rem;
  font-weight: 800;
  color: #ff5274;
  text-shadow: 4px 4px 0px #ffe4e9, 0 10px 20px rgba(255, 82, 116, 0.15);
  letter-spacing: 2px;
  margin-bottom: 8px;
  animation: title-bob 3s ease-in-out infinite;
}

.app-subtitle {
  font-size: 1.6rem;
  color: #5a6a85;
  font-weight: 500;
  margin-bottom: 30px;
}

.greeting-box {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: #ffffff;
  border-radius: 25px;
  padding: 12px 28px;
  font-size: 1.3rem;
  color: #4a5568;
  box-shadow: 0 6px 15px rgba(0,0,0,0.03);
  margin-bottom: 35px;
  border: 2px solid #edf2f7;
}

.greeting-emoji {
  animation: hand-wave 1.5s ease infinite alternate;
  display: inline-block;
  transform-origin: 70% 70%;
}

.mode-selection {
  display: flex;
  justify-content: center;
  gap: 40px;
  flex-wrap: wrap;
}

/* 6. NÚT BẤM 3D CHUNKY (TACTILE BUTTONS) */
.btn-3d {
  position: relative;
  border: none;
  font-family: var(--font-family);
  font-size: 1.6rem;
  font-weight: 700;
  border-radius: 28px;
  padding: 16px 40px;
  color: var(--color-text-dark);
  cursor: pointer;
  outline: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 15px;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

/* Hiệu ứng nhấn nút 3D */
.btn-3d:hover {
  transform: translateY(-4px);
}

.btn-3d:active {
  transform: translateY(6px);
}

/* Phân loại các nút bấm */
.btn-primary {
  background-color: var(--color-primary);
  color: white;
  box-shadow: 0 8px 0 var(--color-primary-shadow), 0 15px 25px rgba(255, 112, 138, 0.3);
}
.btn-primary:hover {
  box-shadow: 0 12px 0 var(--color-primary-shadow), 0 18px 30px rgba(255, 112, 138, 0.4);
}
.btn-primary:active {
  box-shadow: 0 2px 0 var(--color-primary-shadow), 0 5px 10px rgba(255, 112, 138, 0.2);
}

.btn-secondary {
  background-color: var(--color-secondary);
  color: white;
  box-shadow: 0 8px 0 var(--color-secondary-shadow), 0 15px 25px rgba(78, 168, 222, 0.3);
}
.btn-secondary:hover {
  box-shadow: 0 12px 0 var(--color-secondary-shadow), 0 18px 30px rgba(78, 168, 222, 0.4);
}
.btn-secondary:active {
  box-shadow: 0 2px 0 var(--color-secondary-shadow), 0 5px 10px rgba(78, 168, 222, 0.2);
}

.btn-back-nav {
  background-color: var(--color-back);
  color: white;
  font-size: 1.1rem;
  padding: 8px 20px;
  border-radius: 18px;
  box-shadow: 0 5px 0 var(--color-back-shadow);
}
.btn-back-nav:hover {
  box-shadow: 0 7px 0 var(--color-back-shadow);
}
.btn-back-nav:active {
  box-shadow: 0 1px 0 var(--color-back-shadow);
}

/* 7. MÀN HÌNH CHƠI (GAME SCREEN) LAYOUT */
#game-screen {
  padding: 20px 30px;
}

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  z-index: 3;
  position: relative;
}

.game-mode-title {
  font-size: 2.2rem;
  font-weight: 800;
  color: #4a5568;
  text-shadow: 2px 2px 0px #ffffff;
}

.score-board {
  display: flex;
  align-items: center;
  gap: 10px;
  background: white;
  border-radius: 20px;
  padding: 8px 24px;
  font-size: 1.5rem;
  font-weight: 700;
  box-shadow: 0 6px 15px rgba(0,0,0,0.05);
  border: 3px solid #edf2f7;
}

.star-icon {
  font-size: 1.8rem;
  animation: star-spin 2s infinite ease-in-out;
  display: inline-block;
}

/* Phần chia đôi màn hình ngang */
.game-main {
  flex: 1;
  display: grid;
  grid-template-columns: 1.4fr 0.6fr;
  gap: 30px;
  z-index: 3;
  position: relative;
  min-height: 0; /* Cho phép các khối con co giãn hợp lý */
}

/* Cột Trái: Trực quan & Số */
.game-left-panel {
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 4px solid #ffffff;
  border-radius: 32px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.04);
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  padding: 20px;
  min-height: 0;
}

/* Container trực quan hoa quả */
.visual-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  flex: 1.2;
  min-height: 0;
}

.visual-group {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: center;
  gap: 12px;
  padding: 15px;
  background: rgba(255, 255, 255, 0.5);
  border: 3px dashed rgba(0,0,0,0.08);
  border-radius: 24px;
  min-height: 120px;
  flex: 1;
}

.visual-operator-sign {
  font-size: 3rem;
  font-weight: 800;
  color: #4a5568;
  text-shadow: 2px 2px 0px white;
  width: 40px;
  text-align: center;
}

/* Item SVG hoa quả sinh động */
.fruit-item {
  width: 70px;
  height: 70px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  animation: item-wobble 3s infinite ease-in-out;
}

.fruit-item svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0px 5px 4px rgba(0,0,0,0.08));
  transition: transform 0.3s ease;
}

/* Hiệu ứng nhún nhảy cho quả khi đúng */
.fruit-item.correct-dance {
  animation: correct-jump 0.6s 3 alternate ease-in-out;
}

/* Trạng thái bị trừ (Dimmed & Gạch chéo đỏ) */
.fruit-item.dimmed svg {
  opacity: 0.15;
  filter: grayscale(100%);
}

.fruit-item.crossed-out::after {
  content: "❌";
  position: absolute;
  font-size: 2.2rem;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #e53e3e;
  text-shadow: 0 0 10px white;
  z-index: 5;
  animation: cross-in 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Container Con số bên dưới */
.equation-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  flex: 0.8;
  margin-top: 10px;
}

.num-box {
  width: 90px;
  height: 90px;
  background: white;
  border: 4px solid #cbd5e0;
  border-radius: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  font-weight: 800;
  color: #2d3748;
  box-shadow: 0 8px 0px #cbd5e0, 0 10px 15px rgba(0,0,0,0.04);
  transition: all 0.2s ease;
}

.num-box.question-mark {
  background: #fef3c7;
  border-color: #f59e0b;
  color: #d97706;
  box-shadow: 0 8px 0px #d97706, 0 10px 15px rgba(245, 158, 11, 0.15);
  animation: pulse-active 2s infinite ease-in-out;
}

.num-box.correct-animation {
  background: var(--color-mint);
  border-color: var(--color-mint-shadow);
  color: #1b5e20;
  box-shadow: 0 8px 0px var(--color-mint-shadow);
  transform: scale(1.1);
}

.equation-operator-sign {
  font-size: 2.8rem;
  font-weight: 800;
  color: #718096;
}

/* Cột Phải: Danh sách nút chọn đáp án */
.game-right-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 15px;
}

.panel-hint {
  font-size: 1.3rem;
  font-weight: 700;
  color: #4a5568;
  text-align: center;
  margin-bottom: 5px;
}

.answers-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.answer-btn {
  width: 100%;
  font-size: 2.8rem;
  padding: 14px 0;
  border-radius: 24px;
  color: var(--color-text-dark);
}

/* Các lớp màu sắc cho nút đáp án */
.btn-peach {
  background-color: var(--color-peach);
  box-shadow: 0 8px 0 var(--color-peach-shadow), 0 10px 15px rgba(255, 173, 173, 0.2);
}
.btn-peach:hover { box-shadow: 0 10px 0 var(--color-peach-shadow); }
.btn-peach:active { box-shadow: 0 2px 0 var(--color-peach-shadow); }

.btn-mint {
  background-color: var(--color-mint);
  box-shadow: 0 8px 0 var(--color-mint-shadow), 0 10px 15px rgba(202, 255, 191, 0.2);
}
.btn-mint:hover { box-shadow: 0 10px 0 var(--color-mint-shadow); }
.btn-mint:active { box-shadow: 0 2px 0 var(--color-mint-shadow); }

.btn-lemon {
  background-color: var(--color-lemon);
  box-shadow: 0 8px 0 var(--color-lemon-shadow), 0 10px 15px rgba(253, 255, 182, 0.2);
}
.btn-lemon:hover { box-shadow: 0 10px 0 var(--color-lemon-shadow); }
.btn-lemon:active { box-shadow: 0 2px 0 var(--color-lemon-shadow); }

.btn-skyblue {
  background-color: var(--color-skyblue);
  box-shadow: 0 8px 0 var(--color-skyblue-shadow), 0 10px 15px rgba(155, 246, 255, 0.2);
}
.btn-skyblue:hover { box-shadow: 0 10px 0 var(--color-skyblue-shadow); }
.btn-skyblue:active { box-shadow: 0 2px 0 var(--color-skyblue-shadow); }

/* Khi bé chọn sai, nút rung lắc */
.answer-btn.shake-wrong {
  animation: shake-error 0.5s ease-in-out;
}

/* 8. CANVAS CONFETTI HIỆU ỨNG PHÁO HOA */
#confetti-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
}

/* 9. ĐỊNH NGHĨA HOẠT ẢNH (KEYFRAMES) */

/* Zoom-in nhẹ lúc vào màn hình */
@keyframes bounce-in {
  0% { transform: scale(0.3); opacity: 0; }
  50% { transform: scale(1.05); }
  70% { transform: scale(0.9); }
  100% { transform: scale(1); opacity: 1; }
}

/* Tiêu đề dập dềnh vui mắt */
@keyframes title-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

/* Vẫy bàn tay chào mừng */
@keyframes hand-wave {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(20deg); }
}

/* Xoay ngôi sao chậm */
@keyframes star-spin {
  0%, 100% { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(15deg) scale(1.1); }
}

/* Lắc lư nhẹ nhàng từng trái quả */
@keyframes item-wobble {
  0%, 100% { transform: rotate(0deg) translateY(0); }
  33% { transform: rotate(-5deg) translateY(-2px); }
  66% { transform: rotate(5deg) translateY(2px); }
}

/* Nhảy múa ăn mừng khi đúng */
@keyframes correct-jump {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-30px) scale(1.15) rotate(10deg); }
}

/* Dấu X xuất hiện của phép trừ */
@keyframes cross-in {
  0% { transform: translate(-50%, -50%) scale(0); opacity: 0; }
  80% { transform: translate(-50%, -50%) scale(1.3); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); }
}

/* Rung lắc khi trả lời sai */
@keyframes shake-error {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-10px); }
  40%, 80% { transform: translateX(10px); }
}

/* Nháy nút chấm hỏi mời gọi */
@keyframes pulse-active {
  0%, 100% { transform: scale(1); box-shadow: 0 8px 0px #d97706, 0 10px 15px rgba(245, 158, 11, 0.15); }
  50% { transform: scale(1.05); box-shadow: 0 8px 0px #d97706, 0 12px 25px rgba(245, 158, 11, 0.35); }
}

/* 10. ĐIỀU CHỈNH RESPONSIVE THIẾT BỊ DI ĐỘNG */
@media (max-width: 768px) {
  .game-main {
    grid-template-columns: 1fr; /* Chuyển thành 1 cột trên màn hình siêu hẹp dọc */
    grid-template-rows: 1.2fr 0.8fr;
    gap: 15px;
  }
  
  .game-right-panel {
    justify-content: start;
  }
  
  .answers-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }
  
  .num-box {
    width: 70px;
    height: 70px;
    font-size: 2.2rem;
  }
  
  .fruit-item {
    width: 48px;
    height: 48px;
  }

  .fruit-item.crossed-out::after {
    font-size: 1.5rem;
  }
}
