/* ===== Kids Games - Main Stylesheet ===== */
:root {
  /* Primary palette - bright, kid-friendly */
  --sky-blue: #6EC6FF;
  --sun-yellow: #FFD93D;
  --strawberry: #FF6B9D;
  --mint-green: #6BCB77;
  --lavender: #B19CD9;
  --orange-pop: #FF9F43;
  
  /* Neutrals */
  --cream: #FFF9E6;
  --soft-white: #FFFFFF;
  --cloud-gray: #F0F4F8;
  --text-dark: #2D3748;
  --text-medium: #5A6677;
  
  /* UI tokens */
  --radius-lg: 24px;
  --radius-xl: 32px;
  --radius-full: 999px;
  --shadow-soft: 0 8px 24px rgba(0,0,0,0.08);
  --shadow-bouncy: 0 12px 0 rgba(0,0,0,0.1), 0 16px 32px rgba(0,0,0,0.12);
  --shadow-pressed: 0 4px 0 rgba(0,0,0,0.1);
}

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

html, body {
  height: 100%;
  font-family: 'Comic Neue', 'Baloo 2', 'Nunito', system-ui, sans-serif;
  background: linear-gradient(180deg, #E3F2FD 0%, #FFF9E6 50%, #FCE4EC 100%);
  color: var(--text-dark);
  overflow-x: hidden;
  -webkit-user-select: none;
  user-select: none;
}

/* Floating background decorations */
body::before,
body::after {
  content: '';
  position: fixed;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
  opacity: 0.4;
}

body::before {
  width: 300px;
  height: 300px;
  background: var(--sun-yellow);
  top: -80px;
  right: -80px;
  filter: blur(40px);
  animation: floatBg 8s ease-in-out infinite;
}

body::after {
  width: 250px;
  height: 250px;
  background: var(--mint-green);
  bottom: -60px;
  left: -60px;
  filter: blur(50px);
  animation: floatBg 10s ease-in-out infinite reverse;
}

@keyframes floatBg {
  0%, 100% { transform: translate(0, 0); }
  50% { transform: translate(20px, 30px); }
}

/* ===== Header ===== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  border-bottom: 4px solid rgba(255,255,255,0.5);
  box-shadow: 0 4px 20px rgba(0,0,0,0.06);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 28px;
  font-weight: 900;
  cursor: pointer;
  flex-shrink: 0;
}

.logo-mark {
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, var(--strawberry), var(--orange-pop));
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(255,107,157,0.4);
}

.logo-mark svg {
  width: 28px;
  height: 28px;
}

.logo-text {
  background: linear-gradient(135deg, var(--strawberry), var(--orange-pop));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.search-wrap {
  flex: 1;
  max-width: 500px;
  margin: 0 auto;
  position: relative;
}

.search-input {
  width: 100%;
  padding: 14px 20px 14px 52px;
  border: 3px solid var(--cloud-gray);
  border-radius: var(--radius-full);
  font-size: 18px;
  font-family: inherit;
  background: white;
  transition: all 0.2s ease;
  outline: none;
}

.search-input:focus {
  border-color: var(--sky-blue);
  box-shadow: 0 0 0 4px rgba(110,198,255,0.25);
}

.search-icon {
  position: absolute;
  left: 18px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  color: var(--text-medium);
}

.stars-display {
  display: flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, var(--sun-yellow), var(--orange-pop));
  color: white;
  padding: 10px 20px;
  border-radius: var(--radius-full);
  font-weight: 800;
  font-size: 18px;
  box-shadow: 0 4px 12px rgba(255,159,67,0.35);
}

.parent-btn {
  background: var(--lavender);
  color: white;
  border: none;
  padding: 12px 20px;
  border-radius: var(--radius-full);
  font-size: 16px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 0 #8B7AB8;
}

.parent-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 0 #8B7AB8;
}

.parent-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #8B7AB8;
}

/* ===== Category Tabs ===== */
.category-tabs {
  display: flex;
  gap: 12px;
  padding: 20px 24px;
  overflow-x: auto;
  scrollbar-width: none;
  position: relative;
  z-index: 1;
}

.category-tabs::-webkit-scrollbar {
  display: none;
}

.cat-tab {
  flex-shrink: 0;
  padding: 12px 24px;
  background: white;
  border: 3px solid transparent;
  border-radius: var(--radius-full);
  font-size: 18px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--text-medium);
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow-soft);
}

.cat-tab:hover {
  transform: translateY(-2px);
}

.cat-tab.active {
  color: white;
  transform: translateY(-2px);
}

.cat-tab.active[data-cat="all"] { background: linear-gradient(135deg, var(--sky-blue), var(--lavender)); }
.cat-tab.active[data-cat="memory"] { background: linear-gradient(135deg, var(--strawberry), #FF8FAB); }
.cat-tab.active[data-cat="puzzle"] { background: linear-gradient(135deg, var(--mint-green), #8FD9A8); }
.cat-tab.active[data-cat="difference"] { background: linear-gradient(135deg, var(--orange-pop), #FFB366); }
.cat-tab.active[data-cat="shapes"] { background: linear-gradient(135deg, var(--sky-blue), #8ED0FF); }
.cat-tab.active[data-cat="math"] { background: linear-gradient(135deg, var(--sun-yellow), #FFE066); color: var(--text-dark); }
.cat-tab.active[data-cat="letters"] { background: linear-gradient(135deg, var(--lavender), #C9B8E8); }
.cat-tab.active[data-cat="music"] { background: linear-gradient(135deg, #FF9AA2, #FFB7B2); }
.cat-tab.active[data-cat="coloring"] { background: linear-gradient(135deg, #A0E7E5, #B4F8C8); color: var(--text-dark); }
.cat-tab.active[data-cat="sorting"] { background: linear-gradient(135deg, #D4A5FF, #E8CCFF); }
.cat-tab.active[data-cat="reaction"] { background: linear-gradient(135deg, #FF6B6B, #FF8E8E); }

.cat-tab .cat-icon {
  width: 22px;
  height: 22px;
}

/* ===== Games Grid ===== */
.games-section {
  padding: 0 24px 60px;
  position: relative;
  z-index: 1;
}

.section-title {
  font-size: 32px;
  font-weight: 900;
  margin-bottom: 20px;
  color: var(--text-dark);
  display: flex;
  align-items: center;
  gap: 12px;
}

.games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 20px;
}

.game-card {
  background: white;
  border-radius: var(--radius-xl);
  padding: 16px;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  border: 4px solid transparent;
}

.game-card:hover {
  transform: translateY(-6px) scale(1.02);
  box-shadow: 0 16px 32px rgba(0,0,0,0.12);
}

.game-card:active {
  transform: translateY(-2px) scale(0.98);
}

.game-thumb {
  width: 100%;
  aspect-ratio: 1;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.game-thumb svg {
  width: 60%;
  height: 60%;
}

.game-title {
  font-size: 18px;
  font-weight: 800;
  text-align: center;
  color: var(--text-dark);
  line-height: 1.3;
}

.game-card .game-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: white;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 700;
  color: var(--text-medium);
}

.no-results {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  color: var(--text-medium);
  font-size: 20px;
}

/* ===== Game Page ===== */
.game-page {
  position: fixed;
  inset: 0;
  background: var(--cream);
  z-index: 200;
  display: flex;
  flex-direction: column;
}

.game-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: rgba(255,255,255,0.9);
  backdrop-filter: blur(8px);
  border-bottom: 4px solid rgba(255,255,255,0.5);
  flex-shrink: 0;
}

.back-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--sky-blue);
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: var(--radius-full);
  font-size: 18px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 0 #4A9FD6;
}

.back-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 0 #4A9FD6;
}

.back-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #4A9FD6;
}

.game-info {
  display: flex;
  align-items: center;
  gap: 16px;
}

.game-title-bar {
  font-size: 22px;
  font-weight: 900;
  color: var(--text-dark);
}

.game-score {
  display: flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, var(--sun-yellow), var(--orange-pop));
  color: white;
  padding: 10px 20px;
  border-radius: var(--radius-full);
  font-weight: 800;
  font-size: 18px;
}

.game-canvas-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow: auto;
}

.game-canvas {
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-bouncy);
  max-width: 100%;
  max-height: 100%;
  background: white;
}

/* ===== Encouragement Popup ===== */
.encourage-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  background: white;
  padding: 40px 60px;
  border-radius: var(--radius-xl);
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  z-index: 500;
  text-align: center;
  pointer-events: none;
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.encourage-popup.show {
  transform: translate(-50%, -50%) scale(1);
}

.encourage-popup .emoji-big {
  font-size: 80px;
  margin-bottom: 12px;
}

.encourage-popup .encourage-text {
  font-size: 36px;
  font-weight: 900;
  background: linear-gradient(135deg, var(--strawberry), var(--orange-pop));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ===== Game Over / Win Modal ===== */
.game-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.game-modal.show {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: white;
  border-radius: var(--radius-xl);
  padding: 48px;
  text-align: center;
  max-width: 420px;
  width: 90%;
  transform: scale(0.8);
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.game-modal.show .modal-content {
  transform: scale(1);
}

.modal-stars {
  font-size: 64px;
  margin-bottom: 16px;
}

.modal-title {
  font-size: 36px;
  font-weight: 900;
  margin-bottom: 8px;
  color: var(--text-dark);
}

.modal-score {
  font-size: 24px;
  color: var(--text-medium);
  margin-bottom: 32px;
}

.modal-score strong {
  color: var(--orange-pop);
  font-size: 32px;
}

.modal-buttons {
  display: flex;
  gap: 16px;
  justify-content: center;
}

.btn-primary, .btn-secondary {
  padding: 16px 32px;
  border-radius: var(--radius-full);
  font-size: 20px;
  font-weight: 800;
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
}

.btn-primary {
  background: linear-gradient(135deg, var(--mint-green), #8FD9A8);
  color: white;
  box-shadow: 0 4px 0 #4A9E57;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 0 #4A9E57;
}

.btn-primary:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #4A9E57;
}

.btn-secondary {
  background: var(--cloud-gray);
  color: var(--text-dark);
  box-shadow: 0 4px 0 #CBD5E0;
}

.btn-secondary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 0 #CBD5E0;
}

.btn-secondary:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #CBD5E0;
}

/* ===== Parent Zone ===== */
.parent-zone {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, var(--lavender), #8B7AB8);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.parent-card {
  background: white;
  border-radius: var(--radius-xl);
  padding: 48px;
  max-width: 560px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.parent-card h2 {
  font-size: 32px;
  font-weight: 900;
  color: var(--text-dark);
  margin-bottom: 8px;
  text-align: center;
}

.parent-card .subtitle {
  color: var(--text-medium);
  text-align: center;
  margin-bottom: 32px;
  font-size: 18px;
}

.math-challenge {
  background: var(--cloud-gray);
  border-radius: var(--radius-lg);
  padding: 32px;
  text-align: center;
  margin-bottom: 24px;
}

.math-question {
  font-size: 48px;
  font-weight: 900;
  color: var(--text-dark);
  margin-bottom: 20px;
}

.math-input {
  width: 160px;
  padding: 16px;
  font-size: 32px;
  font-weight: 800;
  text-align: center;
  border: 4px solid var(--sky-blue);
  border-radius: var(--radius-lg);
  font-family: inherit;
  outline: none;
}

.math-input:focus {
  box-shadow: 0 0 0 4px rgba(110,198,255,0.3);
}

.parent-content {
  display: none;
}

.parent-content.show {
  display: block;
}

.time-settings {
  margin-bottom: 32px;
}

.time-settings h3 {
  font-size: 22px;
  margin-bottom: 16px;
  color: var(--text-dark);
}

.time-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.time-option {
  padding: 20px;
  border: 3px solid var(--cloud-gray);
  border-radius: var(--radius-lg);
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 700;
}

.time-option:hover {
  border-color: var(--sky-blue);
  transform: translateY(-2px);
}

.time-option.active {
  border-color: var(--mint-green);
  background: rgba(107,203,119,0.1);
  color: #2D8A3E;
}

.age-settings h3 {
  font-size: 22px;
  margin-bottom: 16px;
  color: var(--text-dark);
}

.age-slider {
  width: 100%;
  margin-bottom: 12px;
}

.age-value {
  text-align: center;
  font-size: 24px;
  font-weight: 800;
  color: var(--strawberry);
}

.close-parent {
  margin-top: 32px;
  width: 100%;
  padding: 16px;
  background: var(--strawberry);
  color: white;
  border: none;
  border-radius: var(--radius-full);
  font-size: 20px;
  font-weight: 800;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 4px 0 #D14D7B;
  transition: all 0.2s ease;
}

.close-parent:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 0 #D14D7B;
}

.error-msg {
  color: var(--strawberry);
  text-align: center;
  margin-top: 12px;
  font-weight: 700;
  min-height: 24px;
}

/* ===== Footer ===== */
.app-footer {
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(12px);
  border-top: 4px solid rgba(255,255,255,0.5);
  padding: 32px 24px;
  position: relative;
  z-index: 1;
  margin-top: 40px;
}

.footer-content {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}

.footer-left {
  flex: 1;
  min-width: 200px;
}

.footer-logo {
  font-size: 24px;
  font-weight: 900;
  background: linear-gradient(135deg, var(--strawberry), var(--orange-pop));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

.footer-desc {
  color: var(--text-medium);
  font-size: 15px;
}

.footer-right {
  text-align: right;
  min-width: 200px;
}

.download-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 28px;
  background: linear-gradient(135deg, var(--mint-green), #4CAF50);
  color: white;
  text-decoration: none;
  border-radius: var(--radius-full);
  font-weight: 800;
  font-size: 17px;
  box-shadow: 0 4px 0 #2E7D32;
  transition: all 0.2s ease;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.download-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 0 #2E7D32;
}

.download-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #2E7D32;
}

.footer-tip {
  color: var(--text-medium);
  font-size: 13px;
  margin-top: 10px;
}

.parent-download-btn {
  display: inline-block;
  padding: 14px 28px;
  background: linear-gradient(135deg, #4CAF50, #2E7D32);
  color: white;
  text-decoration: none;
  border-radius: var(--radius-full);
  font-weight: 800;
  font-size: 16px;
  box-shadow: 0 4px 0 #1B5E20;
  transition: all 0.2s ease;
}

.parent-download-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 0 #1B5E20;
}

.parent-download-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #1B5E20;
}

/* ===== Hidden ===== */
.hidden {
  display: none !important;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .app-header {
    padding: 12px 16px;
    gap: 10px;
    flex-wrap: wrap;
  }
  
  .logo {
    font-size: 22px;
  }
  
  .logo-mark {
    width: 40px;
    height: 40px;
  }
  
  .search-wrap {
    order: 3;
    max-width: 100%;
    flex-basis: 100%;
  }
  
  .stars-display {
    padding: 8px 16px;
    font-size: 16px;
  }
  
  .parent-btn {
    padding: 10px 16px;
    font-size: 14px;
  }
  
  .category-tabs {
    padding: 16px;
    gap: 8px;
  }
  
  .cat-tab {
    padding: 10px 18px;
    font-size: 16px;
  }
  
  .games-section {
    padding: 0 16px 20px;
  }
  
  .section-title {
    font-size: 26px;
  }
  
  .games-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 14px;
  }
  
  .game-title {
    font-size: 15px;
  }
  
  .game-topbar {
    padding: 12px 16px;
  }
  
  .back-btn {
    padding: 10px 18px;
    font-size: 16px;
  }
  
  .game-title-bar {
    font-size: 18px;
  }
  
  .game-score {
    padding: 8px 16px;
    font-size: 16px;
  }
  
  .parent-card {
    padding: 32px 24px;
  }
  
  .parent-card h2 {
    font-size: 26px;
  }
  
  .time-options {
    grid-template-columns: 1fr 1fr;
  }
}
