:root {
  --bg: #efe5d7;
  --card: #fffdf8;
  --line: #d8c7ae;
  --ink: #2f2418;
  --accent: #a36a2f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Noto Serif SC", "Source Sans 3", serif;
  background:
    radial-gradient(circle at 18% 8%, #fff2dd 0, transparent 36%),
    radial-gradient(circle at 84% 85%, #f8e7cf 0, transparent 38%),
    var(--bg);
}

.app {
  max-width: 1040px;
  margin: 0 auto;
  padding: 16px;
}

.hero,
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 12px;
}

.hero h1 {
  margin: 0 0 8px;
}

.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.toc-card h2 {
  margin: 0 0 8px;
}

.toc {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 6px;
}

.toc-btn {
  width: 100%;
  text-align: left;
  border: 1px solid #dbc8ac;
  border-radius: 10px;
  padding: 7px 10px;
  background: #fff8ec;
  color: #5a3f22;
  cursor: pointer;
  font: inherit;
}

.toc-btn.active {
  border-color: #ba7f40;
  background: #ffeccf;
  font-weight: 700;
}

.book-wrap {
  perspective: 1200px;
}

.page {
  min-height: 430px;
  padding: 20px;
  border: 1px solid #d6cab6;
  border-radius: 14px;
  background: #fffdf8;
  transform-style: preserve-3d;
  transition: transform 0.28s ease;
  box-shadow: 0 12px 28px rgba(109, 76, 40, 0.16);
  touch-action: pan-y;
}

.page h2 {
  margin: 0 0 10px;
}

.page .subtitle {
  margin: 0 0 12px;
  color: #7d5c35;
  font-weight: 700;
}

.page .body {
  line-height: 1.9;
  white-space: pre-line;
}

.page.cover {
  background: linear-gradient(140deg, #fff2d4, #ffe6b6);
}

.page.back {
  background: linear-gradient(140deg, #f8e4c8, #f0d7b4);
}

.page.flip-next {
  transform: rotateY(-13deg);
}

.page.flip-prev {
  transform: rotateY(13deg);
}

.controls {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 8px 14px;
  color: #fff;
  cursor: pointer;
  background: linear-gradient(135deg, #a36a2f, #7f4e20);
  font: inherit;
}

.mode {
  color: #6d4f2c;
  font-weight: 700;
}

@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .page {
    min-height: 360px;
  }
}

/* === Dark Mode Override (auto-generated) === */
:root[data-theme="dark"] {
  --bg: #1a1a2e;
  --card: #242438;
  --line: #3a3a50;
  --ink: #e8e8f0;
  --accent: #ff7b54;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
  --bg: #1a1a2e;
  --card: #242438;
  --line: #3a3a50;
  --ink: #e8e8f0;
  --accent: #ff7b54;
  }
}

/* === CSS Professor Animation Upgrade (Round 22) === */

/* Page entrance */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
.app, main, body > .container { animation: fadeInUp 0.4s ease-out; }

/* Staggered card entrance */
@keyframes cardReveal {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.card, [class*="card"], .mission-card, .module-card, .stat-card {
  animation: cardReveal 0.35s ease-out both;
}
.card:nth-child(2), [class*="card"]:nth-child(2) { animation-delay: 0.05s; }
.card:nth-child(3), [class*="card"]:nth-child(3) { animation-delay: 0.1s; }
.card:nth-child(4), [class*="card"]:nth-child(4) { animation-delay: 0.15s; }
.card:nth-child(5), [class*="card"]:nth-child(5) { animation-delay: 0.2s; }

/* Subtle pulse for primary buttons */
@keyframes btnPulse {
  0%, 100% { box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
  50% { box-shadow: 0 2px 12px rgba(199,73,31,0.25); }
}
button[id*="Btn"]:not(:disabled), .btn-primary {
  animation: btnPulse 3s ease-in-out infinite;
}
button:disabled { animation: none; opacity: 0.6; }

/* Smooth height transitions for collapsible sections */
details { transition: all 0.2s ease; }
details[open] summary { margin-bottom: 8px; }

/* Tooltip fade */
[title] { position: relative; }

/* Progress bar animation */
@keyframes progressFill {
  from { width: 0; }
}
.mc-bar-fill, .mod-progress-fill, .bar-fill, progress::-webkit-progress-value {
  animation: progressFill 0.6s ease-out;
}

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

/* === Loading & Feedback States === */
@keyframes spin { to { transform: rotate(360deg); } }
.btn-loading { position: relative; pointer-events: none; opacity: 0.7; }
.btn-loading::after {
  content: '';
  position: absolute;
  right: 8px; top: 50%;
  width: 14px; height: 14px;
  margin-top: -7px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
.toast-msg {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #333; color: #fff; padding: 10px 20px; border-radius: 8px;
  font-size: 0.9rem; z-index: 9999; opacity: 0;
  transition: opacity 0.3s ease;
}
.toast-msg.show { opacity: 1; }
