:root {
  --bg: #efe7d6;
  --paper: rgba(255, 252, 245, 0.94);
  --paper-strong: #f3dfb4;
  --ink: #1f2a1f;
  --muted: #57615d;
  --forest: #204c3a;
  --forest-strong: #143428;
  --gold: #c08a31;
  --border: #d9c8a8;
  --correct: #deefe1;
  --incorrect: #f6dddd;
  --shadow: 0 18px 44px rgba(31, 42, 31, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: Baskerville, "Palatino Linotype", "Book Antiqua", serif;
  background:
    radial-gradient(circle at top left, rgba(192, 138, 49, 0.18), transparent 28%),
    radial-gradient(circle at bottom right, rgba(32, 76, 58, 0.14), transparent 24%),
    linear-gradient(180deg, #f6f0e3 0%, #eadfc8 100%);
}

.page-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  padding: 2rem;
  background:
    linear-gradient(180deg, rgba(20, 52, 40, 0.98), rgba(27, 63, 49, 0.97)),
    #17382b;
  color: #f7f1e4;
  position: sticky;
  top: 0;
  height: 100vh;
}

.eyebrow,
.hero-kicker {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.8rem;
  color: var(--gold);
  margin: 0 0 0.8rem;
}

.sidebar h1 {
  margin: 0;
  font-size: 2.3rem;
  line-height: 1;
}

.sidebar-copy,
.topic-meta {
  margin-top: 1rem;
  color: rgba(247, 241, 228, 0.85);
  line-height: 1.55;
}

.topic-label {
  display: block;
  margin: 1.75rem 0 0.6rem;
  font-weight: bold;
}

.mode-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-top: 1rem;
}

.mode-toggle.has-memorize {
  grid-template-columns: 1fr 1fr 1fr;
}

.mode-button {
  max-width: none;
  background: rgba(255, 253, 248, 0.1);
  color: #f7f1e4;
  border: 1px solid rgba(247, 241, 228, 0.24);
}

.mode-button.active {
  background: linear-gradient(135deg, #d7b56d, #f0d49b);
  color: var(--forest-strong);
}

#topic-select,
button {
  width: 100%;
  padding: 0.9rem 1rem;
  border-radius: 14px;
  border: 1px solid var(--border);
  font: inherit;
}

#topic-select {
  background: #fffdf8;
  color: var(--ink);
}

.lesson-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  margin-top: 0.75rem;
}

.lesson-nav-button {
  background: rgba(255, 253, 248, 0.12);
  color: #f7f1e4;
  border-color: rgba(247, 241, 228, 0.24);
}

.lesson-nav-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.content {
  padding: 2rem;
  display: grid;
  gap: 1.5rem;
}

.panel {
  background: var(--paper);
  border: 1px solid rgba(217, 200, 168, 0.9);
  border-radius: 22px;
  padding: 1.6rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(4px);
}

.hero-panel {
  background:
    linear-gradient(135deg, rgba(243, 223, 180, 0.9), rgba(255, 252, 245, 0.95)),
    var(--paper);
}

.hero-panel h2 {
  margin: 0;
  font-size: clamp(2rem, 3vw, 3rem);
}

.hero-summary {
  max-width: 68ch;
  font-size: 1.08rem;
  line-height: 1.6;
  color: var(--muted);
}

.print-review-button {
  margin-top: 0.5rem;
}

.top-grid,
.split-panel {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.section-heading h2 {
  margin: 0;
  font-size: 1.4rem;
}

.fact-stack,
.term-grid {
  display: grid;
  gap: 0.85rem;
}

.fact-card,
.term-card,
.review-section,
.question-card {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(255, 253, 248, 0.92);
}

.fact-card,
.term-card {
  padding: 1rem;
}

.fact-card h3,
.term-card h3,
.review-section h3,
.question-card h3 {
  margin: 0 0 0.45rem;
}

.fact-card p,
.term-card p {
  margin: 0;
  line-height: 1.55;
  color: var(--muted);
}

.lesson-review {
  display: grid;
  gap: 1rem;
}

.review-section {
  padding: 1.2rem;
}

.review-section p {
  line-height: 1.7;
  margin: 0.75rem 0;
}

.tough-concepts-section {
  background:
    linear-gradient(135deg, rgba(192, 138, 49, 0.12), rgba(32, 76, 58, 0.08)),
    rgba(255, 253, 248, 0.95);
}

.tough-concept-group {
  margin-top: 1rem;
}

.tough-concept-group h4 {
  margin: 0 0 0.6rem;
  font-size: 1.1rem;
}

.concept-table-wrap {
  overflow-x: auto;
  margin: 1rem 0;
  border: 1px solid rgba(217, 200, 168, 0.9);
  border-radius: 14px;
  background: #fffdf8;
}

.concept-table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.concept-table th,
.concept-table td {
  padding: 0.85rem;
  border-bottom: 1px solid rgba(217, 200, 168, 0.78);
  border-right: 1px solid rgba(217, 200, 168, 0.58);
  text-align: left;
  vertical-align: top;
  line-height: 1.45;
}

.concept-table th {
  background: rgba(32, 76, 58, 0.1);
  color: var(--forest-strong);
}

.concept-table tr:last-child td {
  border-bottom: 0;
}

.concept-table th:last-child,
.concept-table td:last-child {
  border-right: 0;
}

.subsection-grid {
  display: grid;
  gap: 0.85rem;
  margin-top: 1rem;
}

.subsection {
  padding: 1rem;
  border-radius: 14px;
  background: rgba(243, 223, 180, 0.2);
  border: 1px solid rgba(217, 200, 168, 0.8);
}

.subsection h4 {
  margin: 0 0 0.45rem;
  font-size: 1.05rem;
}

.subsection p {
  margin: 0.55rem 0;
}

.subsection-list {
  margin: 0.5rem 0 0;
  padding-left: 1.2rem;
  line-height: 1.65;
}

.subsection-note {
  color: var(--muted);
  font-style: italic;
}

.practice-grid {
  display: grid;
  gap: 0.9rem;
  margin-top: 1rem;
}

.practice-card {
  padding: 1rem;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(217, 200, 168, 0.85);
}

.practice-card h4 {
  margin: 0 0 0.45rem;
}

.practice-question,
.practice-answer,
.practice-solution {
  margin: 0.45rem 0;
  line-height: 1.6;
}

.practice-answer {
  color: var(--forest-strong);
}

.video-section {
  background:
    linear-gradient(135deg, rgba(32, 76, 58, 0.08), rgba(192, 138, 49, 0.08)),
    rgba(255, 253, 248, 0.92);
}

.video-grid {
  display: grid;
  gap: 1rem;
  margin-top: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.video-card {
  overflow: hidden;
  border: 1px solid rgba(217, 200, 168, 0.9);
  border-radius: 14px;
  background: #fffdf8;
}

.video-frame {
  aspect-ratio: 16 / 9;
  background: var(--forest-strong);
}

.video-frame iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

.video-speed-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid rgba(217, 200, 168, 0.75);
  background: rgba(243, 223, 180, 0.22);
}

.video-speed-controls label {
  display: grid;
  grid-template-columns: auto minmax(8rem, 1fr);
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  color: var(--forest-strong);
  font-weight: bold;
}

.video-speed-controls input[type="range"] {
  width: 100%;
  min-width: 0;
  accent-color: var(--forest);
}

.video-speed-controls output {
  min-width: 3.2rem;
  text-align: right;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.video-speed-note {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.35;
}

.video-card-body {
  padding: 1rem;
}

.video-card-body h4 {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
}

.video-card-body p {
  margin: 0.45rem 0;
  line-height: 1.55;
}

.video-meta {
  color: var(--muted);
  font-size: 0.92rem;
}

.video-card a {
  display: inline-block;
  margin-top: 0.5rem;
  color: var(--forest-strong);
  font-weight: bold;
}

.detail-list,
.plain-list {
  margin: 0;
  padding-left: 1.2rem;
  line-height: 1.7;
}

.detail-list li,
.plain-list li {
  margin-bottom: 0.45rem;
}

.callout {
  margin-top: 1rem;
  padding: 0.9rem 1rem;
  border-left: 4px solid var(--gold);
  border-radius: 12px;
  background: rgba(192, 138, 49, 0.09);
}

.callout p {
  margin-bottom: 0;
}

button {
  max-width: 190px;
  border: none;
  background: linear-gradient(135deg, var(--forest), var(--forest-strong));
  color: #fff;
  cursor: pointer;
}

button:hover {
  filter: brightness(1.05);
}

.mcq-list {
  display: grid;
  gap: 1rem;
}

.question-card {
  margin: 0;
  padding: 1rem;
}

.question-card.correct {
  background: var(--correct);
}

.question-card.incorrect {
  background: var(--incorrect);
}

.choice-list {
  display: grid;
  gap: 0.55rem;
  margin-top: 0.85rem;
}

.choice-item {
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
  line-height: 1.5;
}

.explanation {
  margin-top: 0.9rem;
  padding-top: 0.9rem;
  border-top: 1px dashed rgba(31, 42, 31, 0.2);
  color: var(--muted);
  line-height: 1.6;
}

.score-output {
  margin-top: 1rem;
  font-weight: bold;
}

.memorize-section {
  background:
    linear-gradient(135deg, rgba(32, 76, 58, 0.08), rgba(192, 138, 49, 0.1)),
    rgba(255, 253, 248, 0.95);
}

.memorize-deck-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin: 1rem 0;
}

.memorize-deck-button {
  max-width: none;
  width: auto;
  padding: 0.7rem 0.9rem;
  border: 1px solid rgba(32, 76, 58, 0.18);
  background: rgba(255, 253, 248, 0.94);
  color: var(--forest-strong);
}

.memorize-deck-button.active {
  background: linear-gradient(135deg, var(--forest), var(--forest-strong));
  color: #fff;
}

.memorize-deck h4 {
  margin: 0 0 1rem;
  font-size: 1.2rem;
}

.memorize-deck-description {
  margin: -0.35rem 0 1rem;
  color: var(--muted);
  line-height: 1.55;
}

.memorize-carousel {
  display: grid;
  gap: 0.9rem;
}

.memorize-carousel-meta,
.memorize-carousel-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.memorize-progress,
.memorize-stats {
  margin: 0;
  color: var(--muted);
  font-weight: 700;
}

.memorize-stats {
  color: var(--forest-strong);
}

.memorize-carousel-viewport {
  position: relative;
  min-height: 25rem;
  overflow: hidden;
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(32, 76, 58, 0.08), rgba(243, 223, 180, 0.24));
}

.memorize-carousel-track {
  position: relative;
  min-height: 25rem;
}

.memorize-slide {
  position: absolute;
  inset: 1.1rem auto 1.1rem 50%;
  width: min(42rem, calc(100% - 3rem));
  opacity: 0;
  transform: translateX(-50%) scale(0.86);
  pointer-events: none;
  transition: transform 180ms ease, opacity 180ms ease, filter 180ms ease;
  filter: saturate(0.7);
}

.memorize-slide.active {
  z-index: 3;
  opacity: 1;
  transform: translateX(-50%) scale(1);
  pointer-events: auto;
  filter: none;
}

.memorize-slide.previous,
.memorize-slide.next {
  z-index: 1;
  opacity: 0.34;
}

.memorize-slide.previous {
  transform: translateX(calc(-50% - min(38vw, 27rem))) scale(0.86);
}

.memorize-slide.next {
  transform: translateX(calc(-50% + min(38vw, 27rem))) scale(0.86);
}

.memorize-slide-preview,
.memorize-card {
  min-height: 22.8rem;
  padding: 1.2rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255, 253, 248, 0.94);
  box-shadow: 0 18px 45px rgba(31, 42, 31, 0.12);
}

.memorize-slide-preview {
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
  font-weight: 800;
}

.memorize-card h5 {
  margin: 0 0 0.7rem;
  font-size: clamp(1.05rem, 1.6vw, 1.35rem);
  line-height: 1.3;
}

.memorize-card-label {
  margin: 0 0 0.45rem;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.memorize-choice-grid {
  display: grid;
  gap: 0.65rem;
  margin-top: 1rem;
}

.memorize-choice-button {
  width: 100%;
  max-width: none;
  padding: 0.85rem 1rem;
  border: 1px solid rgba(32, 76, 58, 0.16);
  border-radius: 12px;
  background: #fffdf8;
  color: var(--ink);
  text-align: left;
}

.memorize-choice-button.correct-choice {
  background: var(--correct);
  border-color: rgba(38, 120, 74, 0.35);
}

.memorize-choice-button.incorrect-choice {
  background: var(--incorrect);
  border-color: rgba(154, 66, 48, 0.35);
}

.memorize-feedback {
  min-height: 2.8rem;
  margin: 1rem 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.flashcard-back {
  color: var(--forest-strong);
  font-weight: bold;
  font-size: 1.05rem;
}

.flashcard-extra,
.text-entry-feedback {
  color: var(--muted);
  line-height: 1.55;
}

.memorize-card-actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

.memorize-card-actions button,
.memorize-carousel-controls button {
  width: auto;
  max-width: none;
  padding: 0.65rem 0.9rem;
}

.memorize-secondary-button {
  background: rgba(255, 253, 248, 0.94);
  color: var(--forest-strong);
  border: 1px solid rgba(32, 76, 58, 0.2);
}

.memorize-dots {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: center;
}

.memorize-dot {
  width: 0.75rem;
  height: 0.75rem;
  min-width: 0;
  padding: 0;
  border-radius: 999px;
  border: 1px solid rgba(32, 76, 58, 0.24);
  background: rgba(255, 253, 248, 0.9);
}

.memorize-dot.active {
  background: var(--forest);
}

.memorize-dot.known {
  background: #58a76f;
}

.memorize-dot.review {
  background: #d18b49;
}

.math-entry {
  width: 100%;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  font: 1.05rem ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  background: #fffdf8;
  color: var(--ink);
}

.symbol-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.75rem 0;
}

.symbol-bar button {
  width: auto;
  max-width: none;
  min-width: 2.35rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid rgba(32, 76, 58, 0.16);
  border-radius: 10px;
  background: rgba(243, 223, 180, 0.35);
  color: var(--forest-strong);
}

.text-entry-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.text-entry-actions button {
  width: auto;
  max-width: none;
  padding: 0.65rem 0.9rem;
}

.text-entry-card.correct {
  background: var(--correct);
}

.text-entry-card.incorrect {
  background: var(--incorrect);
}

@media (max-width: 980px) {
  .page-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .top-grid,
  .split-panel {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .content,
  .sidebar {
    padding: 1.2rem;
  }

  .section-heading {
    flex-direction: column;
    align-items: stretch;
  }

  button {
    max-width: none;
  }

  .mode-toggle {
    grid-template-columns: 1fr;
  }

  .memorize-carousel-viewport,
  .memorize-carousel-track {
    min-height: 28rem;
  }

  .memorize-slide {
    width: calc(100% - 1.4rem);
  }

  .memorize-slide.previous {
    transform: translateX(calc(-50% - 88vw)) scale(0.84);
  }

  .memorize-slide.next {
    transform: translateX(calc(-50% + 88vw)) scale(0.84);
  }

  .memorize-carousel-controls {
    display: grid;
    grid-template-columns: 1fr;
  }
}

@media print {
  @page {
    margin: 0.55in;
  }

  body {
    background: #fff;
    color: #111;
    font-size: 10.5pt;
  }

  .page-shell {
    display: block;
    min-height: auto;
  }

  .sidebar,
  .mode-toggle,
  #lesson-controls,
  .print-review-button,
  .video-section,
  #score-button,
  .score-output {
    display: none !important;
  }

  .content {
    display: block;
    padding: 0;
  }

  .panel,
  .fact-card,
  .term-card,
  .review-section,
  .question-card {
    border: 0;
    border-radius: 0;
    box-shadow: none;
    background: #fff;
  }

  .panel {
    padding: 0 0 0.16in;
    break-inside: avoid;
  }

  .hero-panel {
    border-bottom: 2px solid #111;
    margin-bottom: 0.18in;
  }

  .hero-panel h2 {
    font-size: 22pt;
  }

  .hero-summary,
  .review-section p,
  .plain-list,
  .detail-list {
    color: #111;
  }

  .top-grid,
  .split-panel {
    grid-template-columns: 1fr 1fr;
    gap: 0.18in;
  }

  .section-heading {
    margin-bottom: 0.08in;
  }

  .section-heading h2,
  .review-section h3 {
    font-size: 14pt;
  }

  .tough-concepts-section {
    break-before: page;
    background: #fff;
  }

  .concept-table-wrap {
    overflow: visible;
    border: 0;
    border-radius: 0;
  }

  .concept-table {
    min-width: 0;
    font-size: 8.2pt;
    border: 1px solid #111;
  }

  .concept-table thead {
    display: table-header-group;
  }

  .concept-table th,
  .concept-table td {
    padding: 0.08in;
    border: 1px solid #111;
  }

  .concept-table th {
    background: #eee !important;
    color: #111;
  }

  .question-card {
    break-inside: avoid;
    padding: 0.08in 0;
    border-top: 1px solid #bbb;
  }

  .choice-item input {
    display: none;
  }
}
