:root {
  --bg: #fdf6ec;
  --bg-accent-1: #ffe3ec;
  --bg-accent-2: #e3f3ff;
  --surface: #ffffff;
  --ink: #2b2440;
  --ink-soft: #756e8c;
  --border: #ece3f5;
  --accent: #7c5cff;
  --accent-2: #ff6ea8;
  --accent-ink: #ffffff;
  --good: #17a673;
  --good-bg: #e0f8ee;
  --warn: #e0602a;
  --warn-bg: #ffece0;
  --flag-bg: #fff2c2;
  --flag-ink: #7a5a00;
  --radius: 20px;
  --shadow: 0 2px 6px rgba(60, 40, 110, 0.08), 0 10px 24px rgba(60, 40, 110, 0.10);
  --tap-min: 48px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1730;
    --bg-accent-1: #241a34;
    --bg-accent-2: #17233a;
    --surface: #26213c;
    --ink: #f2eefc;
    --ink-soft: #b3a9d4;
    --border: #3a3157;
    --accent: #a48cff;
    --accent-2: #ff8fbb;
    --accent-ink: #1b1730;
    --good: #4fd8a4;
    --good-bg: #123729;
    --warn: #ff9a66;
    --warn-bg: #3a2416;
    --flag-bg: #40350f;
    --flag-ink: #f0d675;
    --shadow: 0 2px 6px rgba(0, 0, 0, 0.35), 0 10px 26px rgba(0, 0, 0, 0.35);
  }
}

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

[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: "Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 12% 8%, var(--bg-accent-1) 0%, transparent 45%),
    radial-gradient(circle at 88% 18%, var(--bg-accent-2) 0%, transparent 50%),
    var(--bg);
  background-attachment: fixed;
  color: var(--ink);
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: clamp(16px, 5vw, 28px) clamp(14px, 5vw, 20px) 60px;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

.app-header {
  text-align: center;
  margin-bottom: clamp(20px, 5vw, 30px);
}

.app-header h1 {
  font-family: "Baloo 2", "Nunito", sans-serif;
  font-size: clamp(1.35rem, 5vw, 1.75rem);
  font-weight: 800;
  margin: 0 0 4px;
  background: linear-gradient(100deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.subtitle {
  color: var(--ink-soft);
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.view { width: 100%; }

/* --- Confetti --- */

#confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 50;
}

.confetti-piece {
  position: absolute;
  top: -10%;
  font-size: 1.6rem;
  animation: confetti-fall linear forwards;
  will-change: transform, opacity;
}

@keyframes confetti-fall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(110vh) rotate(360deg); opacity: 0.9; }
}

/* --- Home / batch list --- */

.batch-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.batch-card {
  --batch-color: var(--accent);
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  cursor: pointer;
  box-shadow: var(--shadow);
  text-align: left;
  width: 100%;
  font: inherit;
  color: inherit;
  min-height: var(--tap-min);
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  position: relative;
  overflow: hidden;
}

.batch-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 6px;
  background: var(--batch-color);
}

.batch-card:hover {
  border-color: var(--batch-color);
  transform: translateY(-2px);
}

.batch-card:active {
  transform: translateY(0) scale(0.98);
}

.batch-card-emoji {
  font-size: 1.8rem;
  width: 46px;
  height: 46px;
  min-width: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  background: color-mix(in srgb, var(--batch-color) 16%, transparent);
}

.batch-card-body { flex: 1; min-width: 0; }

.batch-card-title {
  font-family: "Baloo 2", sans-serif;
  font-weight: 700;
  font-size: 1.05rem;
  margin-bottom: 2px;
}

.batch-card-range {
  color: var(--ink-soft);
  font-size: 0.85rem;
  font-weight: 600;
}

.batch-progress {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  min-width: 84px;
}

.batch-progress-bar {
  width: 84px;
  height: 8px;
  border-radius: 4px;
  background: var(--border);
  overflow: hidden;
}

.batch-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--batch-color), var(--accent-2));
  border-radius: 4px;
  transition: width 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.batch-progress-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--ink-soft);
}

.link-btn {
  display: block;
  margin: 28px auto 0;
  background: none;
  border: none;
  color: var(--ink-soft);
  text-decoration: underline;
  cursor: pointer;
  font-size: 0.85rem;
  font-family: inherit;
  padding: 10px;
  min-height: var(--tap-min);
}

/* --- Study view --- */

.study-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.text-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.95rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  padding: 10px 4px;
  min-height: var(--tap-min);
}

.study-progress-label {
  color: var(--ink-soft);
  font-size: 0.85rem;
  font-weight: 700;
}

.study-track {
  height: 8px;
  border-radius: 4px;
  background: var(--border);
  overflow: hidden;
  margin-bottom: 20px;
}

.study-track-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 4px;
  transition: width 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.card-area {
  margin-bottom: 22px;
  perspective: 1200px;
}

.card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 30px 24px;
  min-height: 220px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  transform-origin: center;
}

.card.flip-anim {
  animation: card-flip 0.42s cubic-bezier(0.45, 0, 0.55, 1);
}

@keyframes card-flip {
  0% { transform: rotateY(0deg) scale(1); }
  50% { transform: rotateY(90deg) scale(0.94); }
  51% { transform: rotateY(-90deg) scale(0.94); }
  100% { transform: rotateY(0deg) scale(1); }
}

.card.pop-in {
  animation: card-pop-in 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes card-pop-in {
  0% { transform: scale(0.9) translateY(10px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

.card-question {
  font-family: "Baloo 2", sans-serif;
  font-size: clamp(1.05rem, 4.5vw, 1.25rem);
  font-weight: 700;
  line-height: 1.4;
  text-align: center;
}

.card-answer {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.answer-summary {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.4;
}

.answer-summary ul {
  margin: 0;
  padding-left: 1.2em;
}

.answer-summary li { margin-bottom: 4px; }

.answer-context {
  font-size: 0.95rem;
  line-height: 1.55;
  color: var(--ink);
}

.answer-flag {
  font-size: 0.8rem;
  font-weight: 700;
  background: var(--flag-bg);
  color: var(--flag-ink);
  padding: 10px 12px;
  border-radius: 12px;
}

.card-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.primary-btn {
  background: linear-gradient(100deg, var(--accent), var(--accent-2));
  color: var(--accent-ink);
  border: none;
  border-radius: 999px;
  padding: 14px 28px;
  font-size: 1.05rem;
  font-family: "Baloo 2", sans-serif;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  max-width: 320px;
  min-height: var(--tap-min);
  box-shadow: 0 6px 16px color-mix(in srgb, var(--accent) 40%, transparent);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.primary-btn:hover { transform: translateY(-1px); }

.primary-btn:active {
  transform: translateY(0) scale(0.97);
  box-shadow: 0 3px 8px color-mix(in srgb, var(--accent) 40%, transparent);
}

.grade-controls {
  display: flex;
  gap: 12px;
  width: 100%;
  max-width: 360px;
}

.grade-btn {
  flex: 1;
  border: none;
  border-radius: 999px;
  padding: 14px 16px;
  font-size: 0.98rem;
  font-family: "Baloo 2", sans-serif;
  font-weight: 700;
  cursor: pointer;
  min-height: var(--tap-min);
  transition: transform 0.12s ease;
}

.grade-btn:active { transform: scale(0.96); }

.grade-btn.got-it {
  background: var(--good-bg);
  color: var(--good);
}

.grade-btn.needs-practice {
  background: var(--warn-bg);
  color: var(--warn);
}

/* --- Summary view --- */

#summary-view {
  text-align: center;
  padding-top: clamp(24px, 8vw, 48px);
}

.summary-emoji {
  font-size: 3.2rem;
  margin-bottom: 6px;
  animation: summary-bounce 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes summary-bounce {
  0% { transform: scale(0.3) translateY(-20px); opacity: 0; }
  60% { transform: scale(1.15) translateY(0); opacity: 1; }
  100% { transform: scale(1); }
}

#summary-view h2 {
  font-family: "Baloo 2", sans-serif;
  margin: 0 0 8px;
}

.summary-text {
  color: var(--ink-soft);
  font-weight: 600;
  margin-bottom: 26px;
}

.summary-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

/* --- Mobile refinements --- */

@media (max-width: 420px) {
  .grade-controls {
    flex-direction: column;
  }

  .batch-card-emoji {
    font-size: 1.5rem;
    width: 40px;
    height: 40px;
    min-width: 40px;
  }

  .card {
    padding: 24px 18px;
    min-height: 190px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
