:root {
  --bg: #f4efe4;
  --paper: #fffaf0;
  --ink: #22201b;
  --muted: #6f6759;
  --line: #dccdb4;
  --accent: #1f5a44;
  --accent-soft: #dceee6;
  --ok: #2f7d32;
  --danger: #912d2d;
  --shadow: 0 10px 30px rgba(43, 35, 21, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Manrope", sans-serif;
  color: var(--ink);
  min-height: 100vh;
  background:
    radial-gradient(circle at 18% 10%, rgba(188, 223, 196, 0.45), transparent 35%),
    radial-gradient(circle at 85% 90%, rgba(208, 183, 143, 0.35), transparent 28%),
    var(--bg);
}

body.menu-open {
  overflow: hidden;
}

.mobile-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 16, 13, 0.44);
  z-index: 19;
}

.app-shell {
  display: grid;
  grid-template-columns: 320px 1fr;
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, #f6efe0 0%, #f8f2e8 100%);
  padding: 1.1rem;
  overflow-y: auto;
}

.sidebar-mobile-head {
  display: none;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.8rem;
}

.brand h1 {
  margin: 0;
  font-family: "Literata", serif;
  font-size: 1.8rem;
}

.brand p {
  margin: 0.2rem 0 0;
  color: var(--muted);
}

.resume-card {
  margin-top: 1rem;
  padding: 0.9rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
}

.resume-card h2 {
  margin: 0 0 0.4rem;
  font-size: 1rem;
}

.resume-card p {
  margin: 0 0 0.7rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.search-wrap {
  display: block;
  margin: 1rem 0;
}

.search-wrap span {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.search-wrap input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 0.65rem 0.75rem;
  font: inherit;
}

.directory {
  display: grid;
  gap: 0.45rem;
  padding-bottom: 0.8rem;
}

.dir-item {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 10px;
  text-align: left;
  padding: 0.55rem 0.65rem;
  background: transparent;
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.dir-item:hover {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.55);
}

.dir-item.active {
  border-color: #9db9aa;
  background: var(--accent-soft);
}

.dir-item small {
  color: var(--muted);
}

.main {
  padding: 1rem;
  display: grid;
  grid-template-rows: auto auto auto auto;
  gap: 1rem;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.menu-btn {
  display: none;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.kicker {
  margin: 0;
  color: var(--muted);
  letter-spacing: 0.04em;
  font-size: 0.8rem;
  text-transform: uppercase;
}

.topbar h2 {
  margin: 0.2rem 0 0;
  font-family: "Literata", serif;
  font-size: 1.45rem;
}

.content-card,
.quiz-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
  box-shadow: var(--shadow);
  padding: 1rem;
}

.section-content {
  line-height: 1.56;
  white-space: pre-wrap;
}

.teach-head {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fffdf7;
  padding: 0.75rem 0.85rem;
  margin-bottom: 0.75rem;
}

.teach-head h3 {
  margin: 0;
  font-family: "Literata", serif;
}

.teach-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
}

.level-picker {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.level-picker select {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.38rem 0.5rem;
  background: #fff;
  font: inherit;
  color: var(--ink);
}

.teach-head p {
  margin: 0.35rem 0 0;
  color: var(--muted);
}

.lesson-summary {
  border-left: 4px solid #a7c4b7;
  background: #f8fcf9;
  border-radius: 8px;
  padding: 0.75rem;
  margin-bottom: 0.75rem;
  line-height: 1.6;
}

.lesson-block {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fffef9;
  padding: 0.7rem;
  margin-bottom: 0.65rem;
}

.lesson-block h4 {
  margin: 0 0 0.4rem;
  font-family: "Literata", serif;
  font-size: 1rem;
}

.lesson-list {
  margin: 0;
  padding-left: 1.15rem;
}

.lesson-list li {
  margin-bottom: 0.35rem;
  line-height: 1.5;
}

.lesson-rule {
  margin: 0;
  line-height: 1.6;
}

.lesson-warning {
  border-color: #e6c59a;
  background: #fff7ea;
}

.lesson-warning p {
  margin: 0;
  line-height: 1.6;
}

.lesson-points {
  margin: 0;
  padding: 0 0 0 1.2rem;
}

.lesson-points li {
  margin-bottom: 0.5rem;
  line-height: 1.55;
}

.lesson-glossary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.55rem;
  margin-top: 0.7rem;
}

.glossary-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fffef9;
  padding: 0.65rem;
}

.glossary-card strong {
  display: block;
  margin-bottom: 0.25rem;
}

.worked-examples {
  margin-top: 0.9rem;
}

.worked-examples h4 {
  margin: 0 0 0.55rem;
  font-family: "Literata", serif;
}

.example-card {
  border: 1px solid var(--line);
  background: #fffef9;
  border-radius: 10px;
  padding: 0.7rem;
  margin-bottom: 0.6rem;
}

.example-card h5 {
  margin: 0 0 0.35rem;
  font-size: 0.98rem;
}

.example-card p {
  margin: 0.32rem 0;
  line-height: 1.55;
}

.example-card ul {
  margin: 0.4rem 0 0.4rem 1.1rem;
  padding: 0;
}

.example-card li {
  margin-bottom: 0.35rem;
}

.immediate-practice {
  margin-top: 0.85rem;
}

#practicePrompt {
  margin: 0 0 0.55rem;
  line-height: 1.55;
}

.practice-input-wrap {
  display: block;
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
}

#practiceInput {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.6rem 0.7rem;
  font: inherit;
  resize: vertical;
  min-height: 88px;
  background: #fff;
}

.practice-actions {
  display: flex;
  gap: 0.55rem;
  flex-wrap: wrap;
  margin-top: 0.55rem;
}

#practiceFeedback {
  margin: 0.55rem 0 0;
  min-height: 1.4rem;
  line-height: 1.5;
}

.feedback-ok {
  color: var(--ok);
  font-weight: 600;
}

.feedback-mid {
  color: #7b5d1a;
  font-weight: 600;
}

.feedback-bad {
  color: var(--danger);
  font-weight: 600;
}

.source-details {
  margin-top: 0.8rem;
  border-top: 1px dashed var(--line);
  padding-top: 0.7rem;
}

.source-details summary {
  cursor: pointer;
  font-weight: 600;
}

.source-details .section-content {
  margin-top: 0.6rem;
}

.quiz-head h3 {
  margin: 0;
  font-family: "Literata", serif;
}

.quiz-head p {
  margin: 0.35rem 0 0.9rem;
  color: var(--muted);
}

.quiz-question {
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 0.65rem;
  background: #fffdf7;
}

.quiz-question p {
  margin: 0 0 0.45rem;
  font-weight: 600;
}

.quiz-option {
  display: block;
  margin: 0.3rem 0;
}

.quiz-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-top: 0.7rem;
}

#quizResult {
  margin: 0;
  min-height: 1.4rem;
  color: var(--muted);
}

.nav-footer {
  display: flex;
  justify-content: space-between;
  gap: 0.6rem;
}

.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 10px;
  min-height: 44px;
  padding: 0.62rem 0.9rem;
  font: inherit;
  cursor: pointer;
}

.btn:hover {
  filter: brightness(0.98);
}

.btn-primary {
  border-color: #2d694e;
  background: var(--accent);
  color: #fff;
}

.status-ok {
  color: var(--ok) !important;
  font-weight: 600;
}

.status-bad {
  color: var(--danger) !important;
  font-weight: 600;
}

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

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: min(88vw, 360px);
    height: 100vh;
    border-right: 1px solid var(--line);
    border-bottom: 0;
    transform: translateX(-100%);
    transition: transform 220ms ease;
    z-index: 20;
    padding-bottom: 1.4rem;
  }

  .sidebar-mobile-head {
    display: flex;
    position: sticky;
    top: 0;
    background: #f8f2e8;
    padding-bottom: 0.4rem;
  }

  .main {
    padding: 0.75rem;
    gap: 0.8rem;
    padding-bottom: 5rem;
  }

  .main h2 {
    word-break: break-word;
  }

  .topbar {
    padding: 0.72rem 0.75rem;
    align-items: flex-start;
  }

  .topbar h2 {
    font-size: 1.2rem;
  }

  .top-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .menu-btn {
    display: inline-flex;
  }

  .section-content {
    font-size: 0.98rem;
    line-height: 1.64;
  }

  .lesson-glossary {
    grid-template-columns: 1fr;
  }

  .teach-head-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .level-picker {
    width: 100%;
    justify-content: space-between;
  }

  .level-picker select {
    min-width: 140px;
  }

  .practice-actions .btn {
    flex: 1;
  }

  .search-wrap input,
  .dir-item,
  .quiz-option {
    font-size: 0.98rem;
  }

  .nav-footer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 15;
    padding: 0.65rem 0.75rem calc(0.65rem + env(safe-area-inset-bottom));
    background: rgba(248, 242, 232, 0.96);
    border-top: 1px solid var(--line);
    backdrop-filter: blur(4px);
  }

  .nav-footer .btn {
    flex: 1;
  }

  body.menu-open .sidebar {
    transform: translateX(0);
  }
}
