:root {
  color-scheme: light;
  --bg: #f5f2e9;
  --surface: #fffdf7;
  --surface-2: #ebe6d8;
  --text: #1d2c26;
  --muted: #66736d;
  --border: #d7d1c4;
  --primary: #12372a;
  --primary-2: #2f6b50;
  --accent: #d6a94b;
  --code-bg: #eef6f0;
  --on-primary: #fffdf7;
  --brand-bg: #12372a;
  --on-brand: #fffdf7;
  --focus: #8a5a00;
  --shadow: 0 12px 36px rgba(26, 45, 36, .11);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101815;
  --surface: #18231f;
  --surface-2: #22312b;
  --text: #ecf2ee;
  --muted: #aab9b1;
  --border: #34483f;
  --primary: #a9ddbd;
  --primary-2: #7fc49a;
  --accent: #e8bf65;
  --code-bg: #22372d;
  --on-primary: #0d1f17;
  --brand-bg: #0c1713;
  --on-brand: #ecf2ee;
  --focus: #e8bf65;
  --shadow: 0 12px 36px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.65 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input { font: inherit; }
button { color: inherit; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 6px;
}
/* The main region is focused programmatically to move the reading position,
   so it should not draw a control-sized focus ring around the whole page. */
#main:focus, #main:focus-visible { outline: none; }

.app-shell {
  display: grid;
  grid-template:
    "header header" 68px
    "sidebar main" calc(100vh - 68px) / 320px minmax(0, 1fr);
}

.topbar {
  grid-area: header;
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 20px;
  background: var(--brand-bg);
  color: var(--on-brand);
  box-shadow: 0 2px 12px rgba(0, 0, 0, .16);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 2px solid color-mix(in srgb, currentColor 65%, transparent);
  border-radius: 50%;
  font-weight: 800;
  letter-spacing: .04em;
}
.brand strong, .brand small { display: block; line-height: 1.2; }
.brand small { opacity: .74; font-size: 11px; margin-top: 2px; }
.topbar-actions { margin-left: auto; }
.icon-button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: color-mix(in srgb, currentColor 18%, transparent);
  cursor: pointer;
}
#menu-button { display: none; }

.sidebar {
  grid-area: sidebar;
  overflow-y: auto;
  padding: 20px 14px 32px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.search-wrap { padding: 0 7px 14px; }
.search-wrap label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.search-wrap input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
}
.search-wrap select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
}
.voice-wrap { padding-top: 0; }
.voice-hint {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}
.progress-summary {
  margin: 0 7px 16px;
  padding: 12px;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
}
.progress-track {
  height: 7px;
  margin-top: 8px;
  overflow: hidden;
  border-radius: 20px;
  background: var(--border);
}
.progress-track span {
  display: block;
  height: 100%;
  background: var(--primary-2);
}
.chapter-link {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 10px 9px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.chapter-link:hover, .chapter-link.active { background: var(--surface-2); }
.chapter-number {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--primary);
  color: var(--on-primary);
  font-weight: 800;
}
.chapter-title { font-size: 13px; line-height: 1.25; }
.completion-dot {
  width: 10px;
  height: 10px;
  border: 1px solid var(--border);
  border-radius: 50%;
}
.completion-dot.done { background: #4a9b67; border-color: #4a9b67; }

.main-content {
  grid-area: main;
  overflow-y: auto;
  padding: 34px clamp(20px, 5vw, 70px) 120px;
}
.content-card {
  width: min(900px, 100%);
  margin: 0 auto;
  padding: clamp(22px, 5vw, 54px);
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.eyebrow {
  color: var(--primary-2);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .09em;
  text-transform: uppercase;
}
.document-header h1 { margin: 4px 0 8px; line-height: 1.15; }
.document-header p { margin-top: 0; color: var(--muted); }
.document-tabs {
  display: flex;
  gap: 7px;
  margin: 22px 0 30px;
  padding-bottom: 4px;
  overflow-x: auto;
}
.document-tab {
  flex: none;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  cursor: pointer;
}
.document-tab.active {
  border-color: var(--primary-2);
  background: var(--primary);
  color: var(--on-primary);
}
.completion-button {
  margin: 4px 0 20px;
  padding: 10px 14px;
  border: 1px solid var(--primary-2);
  border-radius: 10px;
  background: transparent;
  color: var(--primary-2);
  cursor: pointer;
  font-weight: 700;
}
.completion-button.done { background: var(--primary-2); color: var(--on-primary); }

.lesson-body h1 { display: none; }
.lesson-body h2 {
  margin: 2.2em 0 .55em;
  padding-top: .3em;
  border-top: 1px solid var(--border);
  font-size: 1.45rem;
  line-height: 1.25;
}
.lesson-body h2:first-of-type { border-top: 0; margin-top: 0; }
.lesson-body h3 { margin: 1.5em 0 .45em; color: var(--primary-2); }
.lesson-body p { max-width: 72ch; }
.lesson-body li { margin: .35em 0; }
.lesson-body blockquote {
  margin: 1.5em 0;
  padding: 14px 18px;
  border-left: 4px solid var(--accent);
  background: var(--surface-2);
}
code.speakable {
  padding: 2px 5px;
  border-radius: 5px;
  background: var(--code-bg);
  color: var(--text);
  font: 600 .94em/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  cursor: pointer;
}
code.speakable:hover { outline: 2px solid var(--accent); }
.answer-block {
  margin: 1.2em 0 1.6em;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
}
.answer-block > summary {
  padding: 11px 16px;
  cursor: pointer;
  font-weight: 700;
  color: var(--primary-2);
  list-style: none;
  user-select: none;
}
.answer-block > summary::-webkit-details-marker { display: none; }
.answer-block > summary::before {
  content: "▸ ";
  display: inline-block;
  width: 1em;
}
.answer-block[open] > summary::before { content: "▾ "; }
.answer-block[open] > summary { border-bottom: 1px solid var(--border); }
.answer-body {
  padding: 2px 16px 12px;
  border-radius: 0 0 12px 12px;
  background: var(--surface);
}
.answer-body > :first-child { margin-top: .9em; }
.answer-body > :last-child { margin-bottom: .4em; }
.table-wrap { overflow-x: auto; margin: 1.2em 0; }
table { width: 100%; border-collapse: collapse; min-width: 480px; }
th, td { padding: 10px 12px; border: 1px solid var(--border); text-align: left; }
th { background: var(--surface-2); }
.reference-link { color: var(--primary-2); font-weight: 650; }

/* Drill tables stay side-by-side at every width: the whole point is to read
   the English and check the French without horizontal scrolling. */
.translation-wrap { overflow-x: visible; }
.translation-table { min-width: 0; table-layout: fixed; }
.translation-table th, .translation-table td {
  width: 50%;
  padding: 9px 10px;
  overflow-wrap: anywhere;
}
.translation-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
}
.translation-table tbody tr:nth-child(even) { background: var(--surface-2); }
.translation-wrap.masked tbody tr:not(.revealed) td:last-child code.speakable {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  vertical-align: middle;
  color: transparent;
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--border);
  user-select: none;
}

.practice-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 0 0 22px;
}
.practice-jump {
  padding: 9px 14px;
  border: 1px solid var(--primary-2);
  border-radius: 999px;
  background: var(--primary-2);
  color: var(--on-primary);
  cursor: pointer;
  font-weight: 700;
}
.outline-toggle, .mask-toggle {
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  cursor: pointer;
  font-weight: 650;
}
.mask-toggle[aria-pressed="true"] {
  border-color: var(--primary-2);
  background: var(--primary-2);
  color: var(--on-primary);
}
.lesson-outline {
  display: grid;
  gap: 4px;
  margin: 0 0 24px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
}
.lesson-outline[hidden] { display: none; }
.lesson-outline button {
  padding: 6px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--primary-2);
  cursor: pointer;
  font-weight: 650;
  text-align: left;
}
.lesson-outline button:hover { background: var(--surface-2); }
.practice-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 1.4em 0 .4em;
}
.practice-controls .hint { color: var(--muted); font-size: 13px; }

.home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-top: 24px;
}
.home-card {
  display: block;
  width: 100%;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg);
  color: inherit;
  cursor: pointer;
  text-align: left;
}
.home-card:hover { border-color: var(--primary-2); transform: translateY(-1px); }
.home-card span { color: var(--muted); font-size: 13px; }
.home-card h2 { margin: 5px 0 0; font-size: 17px; line-height: 1.3; }

.search-results { display: grid; gap: 10px; }
.search-result {
  width: 100%;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  cursor: pointer;
  text-align: left;
}
.search-result strong, .search-result span { display: block; }
.search-result span { color: var(--muted); font-size: 13px; }

.speak-bar {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 30;
  display: flex;
  gap: 8px;
  align-items: center;
}
.speak-button {
  padding: 12px 16px;
  border: 0;
  border-radius: 999px;
  background: var(--primary);
  color: var(--on-primary);
  box-shadow: var(--shadow);
  cursor: pointer;
  font-weight: 750;
}
.speak-button-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
.speed-range {
  width: 100%;
  margin: 2px 0 0;
  accent-color: var(--primary);
}
.toast {
  position: fixed;
  left: 50%;
  bottom: 82px;
  z-index: 40;
  max-width: min(360px, calc(100vw - 30px));
  padding: 10px 14px;
  border-radius: 10px;
  background: #202620;
  color: white;
  opacity: 0;
  transform: translate(-50%, 8px);
  pointer-events: none;
  transition: .18s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.backdrop { display: none; }

.settings-group {
  margin: 18px 7px 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
}
.settings-group > summary {
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  list-style: none;
  text-transform: uppercase;
  user-select: none;
}
.settings-group > summary::-webkit-details-marker { display: none; }
.settings-group > summary::after { content: " ▸"; }
.settings-group[open] > summary::after { content: " ▾"; }
.settings-group[open] > summary { margin-bottom: 12px; }
.settings-group .search-wrap { padding: 0 0 14px; }
.settings-group .search-wrap:last-child { padding-bottom: 2px; }

@media (max-width: 760px) {
  .app-shell {
    display: block;
  }
  .topbar { height: 64px; padding: 0 12px; }
  #menu-button { display: grid; }
  .brand small { display: none; }
  .sidebar {
    position: fixed;
    inset: 64px auto 0 0;
    z-index: 50;
    width: min(88vw, 340px);
    transform: translateX(-102%);
    transition: transform .2s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .backdrop {
    position: fixed;
    inset: 64px 0 0;
    z-index: 45;
    background: rgba(0,0,0,.38);
  }
  .backdrop.show { display: block; }
  .main-content { min-height: calc(100vh - 64px); padding: 18px 12px 100px; }
  .content-card { padding: 22px 17px 36px; border-radius: 14px; }
  .document-header h1 { font-size: 1.65rem; }
  .lesson-body h2 { font-size: 1.28rem; }
  .document-tabs { flex-wrap: wrap; overflow-x: visible; }
  .translation-table th, .translation-table td {
    padding: 7px 8px;
    font-size: .92rem;
  }
  .translation-table code.speakable { font-size: .9em; }
  .speak-bar { right: 12px; bottom: 12px; gap: 6px; }
  .speak-button { padding: 9px 13px; font-size: .9rem; }
}
