/* =============================================
   SnapStudy — Kid-Friendly Styles
   ============================================= */

/* ---------- Variables ---------- */
:root {
  --purple:    #6C63FF;
  --purple-dk: #5046e5;
  --purple-lt: #ede9ff;
  --yellow:    #FFD93D;
  --yellow-dk: #f5c400;
  --coral:     #FF6B6B;
  --green:     #51CF66;
  --green-dk:  #3dba52;
  --red:       #FF4757;
  --bg:        #F0EFFF;
  --white:     #FFFFFF;
  --text:      #2d2b55;
  --text-soft: #6b68a0;
  --radius:    20px;
  --radius-sm: 12px;
  --shadow:    0 8px 30px rgba(108, 99, 255, 0.15);
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ---------- Base ---------- */
body {
  font-family: 'Nunito', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 16px 60px;
}

/* ---------- Header ---------- */
.header { text-align: center; padding: 28px 0 14px; }

.logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 6px;
}

.logo-icon { font-size: 2.4rem; }
.logo-text { font-size: 2.6rem; font-weight: 900; color: var(--purple); letter-spacing: -0.5px; }
.logo-accent { color: var(--yellow-dk); }
.tagline { font-size: 1.05rem; color: var(--text-soft); font-weight: 600; }

/* ---------- Screens ---------- */
.screen {
  width: 100%;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: fadeIn 0.35s ease;
}
.screen.hidden { display: none !important; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}
.hidden { display: none !important; }

/* ---------- Card ---------- */
.card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 28px 24px;
  box-shadow: var(--shadow);
  width: 100%;
}

/* ---------- Upload Card ---------- */
.card-title { font-size: 1.5rem; font-weight: 800; color: var(--text); margin-bottom: 6px; }
.card-subtitle { font-size: 0.95rem; color: var(--text-soft); margin-bottom: 20px; line-height: 1.5; }

/* ---------- Upload Buttons (camera + gallery) ---------- */
.upload-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 14px;
}

.upload-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 18px 12px;
  border: 2.5px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.15s, box-shadow 0.15s;
  text-align: center;
}

.upload-btn:active { transform: scale(0.96); }

.camera-btn {
  background: linear-gradient(135deg, #6C63FF 0%, #a78bfa 100%);
  color: var(--white);
  box-shadow: 0 4px 16px rgba(108,99,255,0.35);
}
.camera-btn:hover { box-shadow: 0 6px 22px rgba(108,99,255,0.5); transform: translateY(-2px); }

.gallery-btn {
  background: var(--white);
  color: var(--purple-dk);
  border-color: var(--purple);
}
.gallery-btn:hover { background: var(--purple-lt); transform: translateY(-2px); }

.upload-btn-icon { font-size: 2rem; }
.upload-btn-label { font-size: 1rem; font-weight: 800; }
.upload-btn-sub { font-size: 0.75rem; font-weight: 600; opacity: 0.75; }

/* ---------- Drop Zone ---------- */
.drop-zone {
  border: 2px dashed #c4c0f0;
  border-radius: var(--radius-sm);
  padding: 12px;
  text-align: center;
  cursor: pointer;
  margin-bottom: 16px;
  transition: background 0.2s, border-color 0.2s;
}
.drop-zone:hover, .drop-zone.drag-over {
  background: var(--purple-lt);
  border-color: var(--purple);
}
.drop-zone-text { font-size: 0.82rem; color: var(--text-soft); font-weight: 600; }

/* ---------- Thumbnails ---------- */
.thumbnails-container {
  margin-bottom: 16px;
  animation: fadeIn 0.3s ease;
}

.thumbnails-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.page-count-badge {
  background: var(--purple);
  color: var(--white);
  font-size: 0.82rem;
  font-weight: 800;
  padding: 4px 12px;
  border-radius: 50px;
}

.btn-clear-all {
  background: none;
  border: none;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--red);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.15s;
}
.btn-clear-all:hover { background: #fff0f0; }

.thumbnails-grid {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 6px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.thumbnail-item {
  position: relative;
  flex-shrink: 0;
  width: 90px;
  height: 90px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 2.5px solid var(--purple-lt);
  background: var(--bg);
}

.thumbnail-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumbnail-page-num {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(44, 43, 85, 0.7);
  color: var(--white);
  font-size: 0.7rem;
  font-weight: 800;
  text-align: center;
  padding: 2px 0;
}

.thumbnail-remove {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 22px;
  height: 22px;
  background: var(--red);
  color: var(--white);
  border: none;
  border-radius: 50%;
  font-size: 0.75rem;
  font-weight: 900;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: transform 0.15s;
}
.thumbnail-remove:hover { transform: scale(1.15); }

.hint-text { font-size: 0.78rem; color: var(--text-soft); text-align: center; margin-top: 10px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 50px;
  font-family: inherit;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
  padding: 14px 28px;
  font-size: 1rem;
}
.btn:active { transform: scale(0.96); }

.btn-primary {
  background: var(--purple);
  color: var(--white);
  box-shadow: 0 4px 16px rgba(108, 99, 255, 0.4);
}
.btn-primary:hover {
  background: var(--purple-dk);
  box-shadow: 0 6px 20px rgba(108, 99, 255, 0.5);
  transform: translateY(-2px);
}

.btn-secondary {
  background: var(--white);
  color: var(--purple);
  border: 2.5px solid var(--purple);
}
.btn-secondary:hover { background: var(--purple-lt); transform: translateY(-2px); }

.btn-large { font-size: 1.1rem; padding: 16px 36px; width: 100%; }

/* ---------- Loading Card ---------- */
.loading-card { text-align: center; }
.loading-animation { margin-bottom: 20px; }
.book-spinner { font-size: 4rem; display: inline-block; animation: bounce 0.7s infinite alternate; }

@keyframes bounce {
  from { transform: translateY(0) rotate(-5deg); }
  to   { transform: translateY(-12px) rotate(5deg); }
}

.loading-title { font-size: 1.4rem; font-weight: 800; color: var(--purple); margin-bottom: 24px; }

.loading-steps { display: flex; flex-direction: column; gap: 14px; text-align: left; }

.step {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-soft);
  transition: background 0.3s, color 0.3s;
}
.step.done { background: #e8fbe9; color: var(--green-dk); }
.step-icon { font-size: 1.3rem; }
.step-text { flex: 1; }
.step-status { font-weight: 700; color: var(--purple); min-width: 30px; }

/* ---------- Quiz Header ---------- */
.quiz-header { width: 100%; margin-bottom: 16px; }

.quiz-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  gap: 10px;
  flex-wrap: wrap;
}

.quiz-topic-badge {
  background: var(--purple-lt);
  color: var(--purple-dk);
  font-weight: 800;
  font-size: 0.85rem;
  padding: 6px 14px;
  border-radius: 50px;
}

.quiz-score-live {
  background: var(--yellow);
  color: var(--text);
  font-weight: 800;
  font-size: 0.85rem;
  padding: 6px 14px;
  border-radius: 50px;
}

.progress-bar-container { background: #ddd9ff; border-radius: 50px; height: 10px; overflow: hidden; margin-bottom: 8px; }
.progress-bar { height: 100%; background: linear-gradient(90deg, var(--purple), #a78bfa); border-radius: 50px; transition: width 0.5s ease; }
.question-counter { font-size: 0.85rem; font-weight: 700; color: var(--text-soft); text-align: right; }

/* ---------- Quiz Card ---------- */
.question-text { font-size: 1.2rem; font-weight: 800; color: var(--text); line-height: 1.5; margin-bottom: 24px; }

.options-container { display: flex; flex-direction: column; gap: 12px; margin-bottom: 20px; }

.option-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 14px 18px;
  background: var(--bg);
  border: 2.5px solid transparent;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}
.option-btn:hover:not(:disabled) { background: var(--purple-lt); border-color: var(--purple); transform: translateX(4px); }
.option-btn:focus { outline: 3px solid var(--yellow); outline-offset: 2px; }

.option-letter {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--purple-lt);
  color: var(--purple-dk);
  font-weight: 900;
  font-size: 0.9rem;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}

.option-btn.correct { background: #e8fbe9; border-color: var(--green); color: var(--green-dk); }
.option-btn.correct .option-letter { background: var(--green); color: var(--white); }
.option-btn.wrong { background: #fff0f0; border-color: var(--red); color: var(--red); }
.option-btn.wrong .option-letter { background: var(--red); color: var(--white); }
.option-btn:disabled { cursor: default; }

/* ---------- Feedback Box ---------- */
.feedback-box {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
  animation: fadeIn 0.3s ease;
}
.feedback-box.correct-fb { background: #e8fbe9; }
.feedback-box.wrong-fb   { background: #fff0f0; }
.feedback-icon { font-size: 1.8rem; flex-shrink: 0; }
.feedback-result { font-weight: 800; font-size: 1rem; margin-bottom: 4px; }
.feedback-explanation { font-size: 0.9rem; font-weight: 600; color: var(--text-soft); line-height: 1.5; }

/* ---------- Results ---------- */
.results-card { text-align: center; }
.result-emoji { font-size: 5rem; margin-bottom: 12px; display: block; animation: pop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); }

@keyframes pop {
  from { transform: scale(0); }
  to   { transform: scale(1); }
}

.result-title { font-size: 1.8rem; font-weight: 900; color: var(--purple); margin-bottom: 6px; }
.result-subtitle { font-size: 1rem; color: var(--text-soft); font-weight: 600; margin-bottom: 28px; line-height: 1.5; }

.score-display { display: flex; align-items: baseline; justify-content: center; gap: 8px; margin-bottom: 16px; }
.final-score { font-size: 4rem; font-weight: 900; color: var(--purple); line-height: 1; }
.score-label { font-size: 1.2rem; font-weight: 700; color: var(--text-soft); }

.score-bar-container { background: var(--bg); border-radius: 50px; height: 16px; overflow: hidden; margin-bottom: 28px; }
.score-bar { height: 100%; border-radius: 50px; transition: width 1s ease; }

.results-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.results-actions .btn { flex: 1; min-width: 140px; }

/* ---------- Confetti ---------- */
#confetti-canvas {
  position: fixed; top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 999;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--text);
  color: var(--white);
  padding: 14px 24px;
  border-radius: 50px;
  font-weight: 700;
  font-size: 0.92rem;
  box-shadow: 0 4px 20px rgba(0,0,0,0.25);
  z-index: 1000;
  max-width: 90vw;
  text-align: center;
  transition: transform 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ---------- Responsive ---------- */
@media (max-width: 420px) {
  .card { padding: 22px 16px; }
  .logo-text { font-size: 2rem; }
  .question-text { font-size: 1.05rem; }
  .result-title { font-size: 1.4rem; }
  .final-score { font-size: 3rem; }
  .upload-btn-label { font-size: 0.9rem; }
}
