/* =========================================
   WONDER WORKSHOP — Full App Styles
   Kid-friendly, colourful, responsive
   ========================================= */

/* ===== CSS ROOT VARIABLES ===== */
:root {
  --blue: #4A90D9;
  --yellow: #FFD700;
  --orange: #FF6B35;
  --green: #4CAF50;
  --purple: #9C27B0;
  --red: #F44336;
  --pink: #FF69B4;
  --teal: #4ECDC4;
  --dark: #2D2D2D;
  --light: #FFF8E1;
  --grey: #888;
  --bg: #fef9ef;
  --shadow: 0 4px 16px rgba(0,0,0,0.12);
  --radius: 16px;
  --radius-sm: 10px;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

/* ===== FONTS & BASE ===== */
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Comic Sans MS', cursive, sans-serif;
  background: var(--bg);
  color: var(--dark);
  overflow-x: hidden;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  background: white;
  position: relative;
  overflow: hidden;
  box-shadow: 0 0 40px rgba(0,0,0,0.08);
}

/* ===== SCREENS ===== */
.screen {
  display: none;
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: 20px;
  animation: slideUp 0.4s ease-out;
}
.screen.active { display: block; }
.screen-center {
  display: flex !important;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 20px;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}
@keyframes wiggle {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-3deg); }
  75% { transform: rotate(3deg); }
}
@keyframes sparkle {
  0% { opacity: 0; transform: scale(0) rotate(0); }
  50% { opacity: 1; transform: scale(1) rotate(180deg); }
  100% { opacity: 0; transform: scale(0) rotate(360deg); }
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}
@keyframes confettiFall {
  0% { transform: translateY(-10px) rotate(0); opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}
@keyframes dotPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.2); }
}
@keyframes slideInDown {
  from { transform: translateY(-100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
@keyframes slideInLeft {
  from { transform: translateX(-100px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes progressFill {
  from { width: 0%; }
}
@keyframes glow {
  0%, 100% { box-shadow: 0 0 5px var(--yellow); }
  50% { box-shadow: 0 0 20px var(--yellow), 0 0 40px var(--yellow); }
}
@keyframes bounceIn {
  0% { transform: scale(0.3); opacity: 0; }
  50% { transform: scale(1.08); }
  70% { transform: scale(0.95); }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-6px); }
  20%, 40%, 60%, 80% { transform: translateX(6px); }
}
@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
@keyframes hammerHit {
  0% { transform: rotate(-20deg); }
  25% { transform: rotate(10deg); }
  50% { transform: rotate(-5deg); }
  75% { transform: rotate(2deg); }
  100% { transform: rotate(0deg); }
}

/* ===== TOP BAR ===== */
.topbar {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: linear-gradient(135deg, var(--blue), #357ABD);
  color: white;
  position: sticky;
  top: 0;
  z-index: 10;
  gap: 10px;
  min-height: 56px;
}
.topbar h2 {
  flex: 1;
  font-size: 18px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.back-btn {
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  font-size: 22px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  flex-shrink: 0;
}
.back-btn:hover { background: rgba(255,255,255,0.35); transform: scale(1.1); }
.back-btn:active { transform: scale(0.9); }
.sparks-badge {
  background: rgba(255,255,255,0.2);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 4px;
}
.sparks-badge:hover { background: rgba(255,255,255,0.35); }

/* ===== AUTH SCREEN ===== */
.auth-box {
  width: 100%;
  max-width: 340px;
  text-align: center;
  animation: fadeIn 0.5s ease-out;
}
.auth-box h1 {
  font-size: 28px;
  background: linear-gradient(135deg, var(--blue), var(--purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 4px;
}
.auth-tabs {
  display: flex;
  background: #f0f0f0;
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 16px;
}
.auth-tab {
  flex: 1;
  padding: 10px;
  border: none;
  background: transparent;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  color: #888;
  cursor: pointer;
  transition: var(--transition);
}
.auth-tab.active {
  background: white;
  color: var(--dark);
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.auth-input {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid #e0e0e0;
  border-radius: var(--radius-sm);
  font-size: 16px;
  margin-bottom: 10px;
  transition: var(--transition);
  font-family: inherit;
}
.auth-input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(74,144,217,0.15);
}

/* ===== BUTTONS ===== */
.btn {
  padding: 14px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn:active { transform: scale(0.96); }
.btn-block { width: 100%; }
.btn-primary { background: var(--blue); color: white; }
.btn-primary:hover { background: #357ABD; }
.btn-success { background: var(--green); color: white; }
.btn-success:hover { background: #388E3C; }
.btn-gold { background: linear-gradient(135deg, #FFD700, #FFA000); color: var(--dark); }
.btn-gold:hover { background: linear-gradient(135deg, #FFC107, #FF8F00); }
.btn-orange { background: var(--orange); color: white; }
.btn-orange:hover { background: #E55D2B; }
.btn-default { background: #f5f5f5; color: #555; }
.btn-default:hover { background: #e0e0e0; }

/* ===== GIZMO SPEECH BUBBLE ===== */
.gizmo {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 14px 16px;
  margin: 10px;
  background: #f8f9ff;
  border-radius: var(--radius);
  animation: slideInLeft 0.4s ease-out;
}
.gizmo-avatar {
  font-size: 40px;
  flex-shrink: 0;
  animation: float 3s ease-in-out infinite;
}
.gizmo-msg {
  font-size: 14px;
  line-height: 1.5;
  color: #555;
  padding: 8px 12px;
  background: white;
  border-radius: 12px;
  border-top-left-radius: 4px;
  position: relative;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

/* ===== HOME SCREEN ===== */
.daily-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px;
  padding: 12px 16px;
  background: linear-gradient(135deg, #FFD700, #FFA000);
  border-radius: var(--radius);
  color: white;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  animation: pulse 2s ease-in-out infinite;
  box-shadow: 0 4px 12px rgba(255, 215, 0, 0.3);
}
.daily-banner:active { transform: scale(0.98); }
.daily-banner-icon {
  font-size: 24px;
  animation: bounce 2s ease-in-out infinite;
}
.home-subtitle {
  text-align: center;
  padding: 4px 16px;
  font-size: 14px;
  color: #888;
  font-weight: 600;
}
.home-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 12px 16px;
}
.home-card {
  background: white;
  border: 2px solid #f0f0f0;
  border-radius: var(--radius);
  padding: 20px 12px;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
}
.home-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.home-card:active { transform: scale(0.96); }
.home-card-icon { font-size: 36px; margin-bottom: 6px; }
.home-card-label { font-size: 15px; font-weight: 700; color: var(--dark); }
.home-card-desc { font-size: 11px; color: #888; margin-top: 2px; }

/* ===== CHAPTER LIST ===== */
.chapter-list {
  padding: 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chapter-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: white;
  border: 2px solid #f0f0f0;
  border-left: 4px solid var(--blue);
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  transition: var(--transition);
  animation: slideInLeft 0.3s ease-out;
  animation-fill-mode: both;
}
.chapter-card:nth-child(1) { animation-delay: 0s; }
.chapter-card:nth-child(2) { animation-delay: 0.05s; }
.chapter-card:nth-child(3) { animation-delay: 0.1s; }
.chapter-card:nth-child(4) { animation-delay: 0.15s; }
.chapter-card:nth-child(5) { animation-delay: 0.2s; }
.chapter-card:hover { box-shadow: var(--shadow); transform: translateX(3px); }
.chapter-card:active { transform: scale(0.98); }
.chapter-card.locked { opacity: 0.6; cursor: default; }
.chapter-card.complete { border-color: var(--green) !important; }
.chapter-icon { font-size: 32px; flex-shrink: 0; }
.chapter-info { flex: 1; min-width: 0; }
.chapter-title { font-size: 15px; font-weight: 700; }
.chapter-progress { font-size: 12px; color: #888; margin-top: 2px; }
.chapter-bar {
  height: 6px;
  background: #e0e0e0;
  border-radius: 3px;
  margin-top: 6px;
  overflow: hidden;
}
.chapter-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.6s ease;
  animation: progressFill 0.8s ease-out;
}
.chapter-badge {
  display: inline-block;
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  color: white;
  margin-top: 4px;
  font-weight: 600;
}
.chapter-status {
  font-size: 18px;
  flex-shrink: 0;
}

/* ===== CHALLENGE LIST ===== */
.challenge-list {
  padding: 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.challenge-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: white;
  border: 2px solid #f0f0f0;
  border-radius: var(--radius-sm);
  padding: 12px;
  cursor: pointer;
  transition: var(--transition);
  animation: slideInLeft 0.3s ease-out;
  animation-fill-mode: both;
  flex-wrap: wrap;
}
.challenge-card:nth-child(1) { animation-delay: 0s; }
.challenge-card:nth-child(2) { animation-delay: 0.05s; }
.challenge-card:nth-child(3) { animation-delay: 0.1s; }
.challenge-card:nth-child(4) { animation-delay: 0.15s; }
.challenge-card:nth-child(5) { animation-delay: 0.2s; }
.challenge-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.challenge-card:active { transform: scale(0.97); }
.challenge-card.completed {
  opacity: 0.6;
  background: #f9fff9;
  border-color: var(--green);
  cursor: default !important;
  pointer-events: none;
}
.challenge-num {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 800;
  color: white;
  flex-shrink: 0;
}
.challenge-num.easy { background: var(--green); }
.challenge-num.medium { background: var(--orange); }
.challenge-num.hard { background: var(--red); }
.challenge-title {
  font-size: 14px;
  font-weight: 600;
  flex: 1;
  min-width: 0;
}
.challenge-sparks {
  font-size: 12px;
  color: var(--yellow);
  font-weight: 700;
  white-space: nowrap;
}
.challenge-desc {
  font-size: 12px;
  color: #888;
  width: 100%;
  padding-left: 40px;
  margin-top: -4px;
}

/* ===== CHALLENGE PLAY ===== */
.challenge-play {
  padding: 20px 16px;
  text-align: center;
  animation: fadeIn 0.3s ease-out;
}
.big-emoji {
  font-size: 64px;
  margin-bottom: 12px;
  animation: bounce 2s ease-in-out infinite;
}
.challenge-play h3 {
  font-size: 20px;
  margin-bottom: 8px;
}
.challenge-play p {
  font-size: 14px;
  color: #555;
  margin-bottom: 20px;
  line-height: 1.5;
}

/* Mock Quiz */
.mock-quiz {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 300px;
  margin: 0 auto;
}
.mock-option {
  padding: 14px 16px;
  background: white;
  border: 2px solid #e0e0e0;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  text-align: left;
}
.mock-option:hover { border-color: var(--blue); background: #f0f4ff; }
.mock-option:active { transform: scale(0.97); }
.mock-option.correct {
  border-color: var(--green) !important;
  background: #e8f5e9 !important;
  animation: pulse 0.5s ease;
}
.mock-option.wrong {
  border-color: var(--red) !important;
  background: #ffebee !important;
  animation: wiggle 0.4s ease;
}

/* ===== INVENTIONS ===== */
.inv-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 10px 16px;
}
.inv-card {
  background: white;
  border: 2px solid #f0f0f0;
  border-radius: var(--radius);
  padding: 14px 10px;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  animation: fadeIn 0.3s ease-out;
  animation-fill-mode: both;
}
.inv-card:hover { box-shadow: var(--shadow); transform: translateY(-2px); }
.inv-card:active { transform: scale(0.96); }
.inv-card.built { border-color: var(--green); background: #f9fff9; cursor: default; }
.inv-card.locked { opacity: 0.5; }
.inv-icon { font-size: 32px; margin-bottom: 4px; }
.inv-name { font-size: 13px; font-weight: 700; }
.inv-cost { font-size: 12px; color: var(--yellow); font-weight: 600; margin-top: 2px; }
.inv-cat { font-size: 10px; color: #aaa; margin-top: 2px; }

/* ===== NOTEBOOK ===== */
.rank-card {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 10px;
  padding: 14px;
  background: linear-gradient(135deg, #ffecd2, #fcb69f);
  border-radius: var(--radius);
}
.rank-icon { font-size: 40px; }
.rank-info { flex: 1; }
.rank-name { font-size: 18px; font-weight: 800; }
.rank-progress { font-size: 12px; color: #666; margin-top: 2px; }

.notebook-tabs {
  display: flex;
  margin: 10px;
  background: #f0f0f0;
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
}
.notebook-tab {
  flex: 1;
  padding: 10px 8px;
  border: none;
  background: transparent;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  color: #888;
  cursor: pointer;
  transition: var(--transition);
}
.notebook-tab.active {
  background: white;
  color: var(--dark);
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.tab-content {
  padding: 0 10px;
  display: block;
}

/* Journals */
.journal-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 10px 0;
}
.journal-card {
  background: white;
  border: 2px solid #f0f0f0;
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
  transition: var(--transition);
}
.journal-card.locked { opacity: 0.4; }
.journal-icon { font-size: 28px; margin-bottom: 4px; }
.journal-name { font-size: 13px; font-weight: 700; }
.journal-desc { font-size: 11px; color: #888; margin-top: 2px; }
.journal-badge {
  display: inline-block;
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 10px;
  color: white;
  margin-top: 6px;
  font-weight: 600;
}

/* ===== PRICING ===== */
.pricing-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 10px 16px;
}
.pricing-card {
  background: white;
  border: 2px solid #f0f0f0;
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
}
.pricing-card:hover { box-shadow: var(--shadow); transform: translateY(-2px); }
.pricing-card.featured {
  border-color: var(--yellow);
  box-shadow: 0 0 20px rgba(255,215,0,0.2);
}
.pricing-name {
  font-size: 18px;
  font-weight: 800;
  margin-bottom: 4px;
}
.pricing-price {
  font-size: 32px;
  font-weight: 800;
  color: var(--blue);
}
.pricing-price small {
  font-size: 14px;
  font-weight: 400;
  color: #888;
}
.pricing-desc {
  font-size: 13px;
  color: #555;
  margin: 8px 0;
  line-height: 1.4;
}

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  animation: fadeIn 0.2s ease-out;
}
.modal-box {
  position: relative;
  background: white;
  border-radius: 20px;
  padding: 28px 24px;
  max-width: 340px;
  width: 100%;
  text-align: center;
  animation: slideUp 0.3s ease-out;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}
.modal-icon { font-size: 48px; margin-bottom: 8px; }
.modal-title { font-size: 20px; font-weight: 800; margin-bottom: 8px; }
.modal-text { font-size: 14px; color: #555; line-height: 1.5; margin-bottom: 16px; }

/* ===== CONFETTI ===== */
.confetti {
  position: fixed;
  top: -10px;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  animation: confettiFall linear forwards;
  z-index: 2000;
  pointer-events: none;
}

/* ===== LOADING ===== */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  font-size: 18px;
  color: #888;
  flex-direction: column;
  gap: 12px;
}
.loading-dot {
  font-size: 48px;
  animation: dotPulse 1s infinite;
}

/* ===== RESPONSIVE ===== */
@media (min-width: 481px) {
  #app { border-radius: 20px; margin-top: 20px; min-height: calc(100vh - 40px); }
}
@media (max-width: 360px) {
  .home-grid, .inv-grid { grid-template-columns: 1fr; }
  .journal-grid { grid-template-columns: 1fr; }
  .topbar h2 { font-size: 15px; }
}
@media (min-width: 768px) {
  #app { max-width: 600px; }
  .home-grid { grid-template-columns: 1fr 1fr; }
  .inv-grid { grid-template-columns: 1fr 1fr 1fr; }
  .journal-grid { grid-template-columns: 1fr 1fr 1fr; }
}

/* ===== Streak Badge ===== */
.streak-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: linear-gradient(135deg, #FF6B6B, #FF8E53);
  color: white;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
}

/* ===== Number Pad (for daily challenge) ===== */
.number-pad-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  max-width: 240px;
  margin: 12px auto;
}
.numpad-btn {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 2px solid #e0e0e0;
  background: white;
  font-size: 24px;
  font-weight: 800;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
}
.numpad-btn:hover { border-color: var(--blue); background: #f0f4ff; }
.numpad-btn:active { transform: scale(0.9); background: var(--blue); color: white; }
.numpad-btn.del { font-size: 18px; }
.numpad-btn.submit { background: var(--green); color: white; border-color: var(--green); }
.numpad-btn.submit:hover { background: #388E3C; }
.numpad-display {
  font-size: 36px;
  font-weight: 800;
  color: var(--dark);
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
  letter-spacing: 4px;
}

/* ===== Purchase Success Animation ===== */
.purchase-success {
  text-align: center;
  padding: 40px 20px;
}
.purchase-success .checkmark {
  font-size: 80px;
  animation: bounce 1s ease-in-out 3;
}
