/* ===== DARK MODE / LIGHT MODE ===== */
:root {
  --bg-primary: #f8fafb;
  --bg-secondary: #ffffff;
  --bg-section: #f9f9f9;
  --text-primary: #1a1a2e;
  --text-secondary: #4a4a6a;
  --text-muted: #6b7280;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-light: rgba(79, 70, 229, 0.08);
  --border: #e5e7eb;
  --card-shadow: 0 2px 8px rgba(0,0,0,0.06);
  --hero-gradient: linear-gradient(135deg, #4f46e5, #7c3aed, #ec4899);
  --nav-bg: rgba(255,255,255,0.92);
  --nav-shadow: 0 1px 8px rgba(0,0,0,0.08);
  --code-bg: #f1f5f9;
  --table-header: #4f46e5;
  --toggle-bg: #e5e7eb;
}

[data-theme="dark"] {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-section: #1e293b;
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #818cf8;
  --accent-hover: #a5b4fc;
  --accent-light: rgba(129, 140, 248, 0.1);
  --border: #334155;
  --card-shadow: 0 2px 8px rgba(0,0,0,0.3);
  --hero-gradient: linear-gradient(135deg, #312e81, #581c87, #831843);
  --nav-bg: rgba(15,23,42,0.95);
  --nav-shadow: 0 1px 8px rgba(0,0,0,0.4);
  --code-bg: #1e293b;
  --table-header: #312e81;
  --toggle-bg: #334155;
}

/* ===== SITE NAV ===== */
.site-nav {
  position: sticky;
  top: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 1.25rem;
  background: var(--nav-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--nav-shadow);
  border-bottom: 1px solid var(--border);
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
}

.site-nav a {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.35rem 0.6rem;
  border-radius: 6px;
  transition: background 0.2s, color 0.2s;
  white-space: nowrap;
}

.site-nav a:hover {
  background: var(--accent-light);
  color: var(--accent-hover);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-wrap: wrap;
}

.nav-brand {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-primary) !important;
  letter-spacing: -0.02em;
}

.nav-sep {
  color: var(--text-muted);
  font-size: 0.75rem;
  user-select: none;
}

/* Theme toggle */
.theme-toggle {
  background: var(--toggle-bg);
  border: 1px solid var(--border);
  border-radius: 9999px;
  width: 2.5rem;
  height: 1.5rem;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: background 0.3s;
}

.theme-toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 1.15rem;
  height: 1.15rem;
  border-radius: 50%;
  background: #fbbf24;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: transform 0.3s, background 0.3s;
}

[data-theme="dark"] .theme-toggle::after {
  transform: translateX(1rem);
  background: #818cf8;
}

/* ===== PREV / NEXT NAV ===== */
.lesson-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin: 2.5rem 0 1.5rem;
  padding: 1.25rem 0;
  border-top: 1px solid var(--border);
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
}

.lesson-nav a {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--accent);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: all 0.2s;
  background: var(--bg-secondary);
}

.lesson-nav a:hover {
  background: var(--accent-light);
  border-color: var(--accent);
}

.lesson-nav .spacer {
  flex: 1;
}

/* ===== MOBILE ===== */
@media (max-width: 768px) {
  .site-nav {
    flex-wrap: wrap;
    padding: 0.5rem 0.75rem;
    gap: 0.4rem;
  }

  .nav-links {
    order: 2;
    width: 100%;
    justify-content: center;
    gap: 0.1rem;
  }

  .nav-brand {
    font-size: 0.85rem;
  }

  .site-nav a {
    font-size: 0.78rem;
    padding: 0.3rem 0.45rem;
  }

  .lesson-nav {
    flex-direction: column;
    gap: 0.75rem;
  }

  .lesson-nav a {
    width: 100%;
    justify-content: center;
  }
}

/* ===== GLOBAL DARK MODE OVERRIDES ===== */
[data-theme="dark"] body {
  background-color: var(--bg-primary) !important;
  color: var(--text-primary) !important;
}

[data-theme="dark"] .section,
[data-theme="dark"] .example-box,
[data-theme="dark"] .practice-box,
[data-theme="dark"] .cultural-note,
[data-theme="dark"] .pos-card,
[data-theme="dark"] .verb-card,
[data-theme="dark"] .sound-card,
[data-theme="dark"] .number-card,
[data-theme="dark"] .time-card,
[data-theme="dark"] .language-card,
[data-theme="dark"] .scenario-card,
[data-theme="dark"] .ai-tool-card,
[data-theme="dark"] .family-tree,
[data-theme="dark"] .interactive-chat,
[data-theme="dark"] .pronoun-card,
[data-theme="dark"] .relationship-card,
[data-theme="dark"] .social-hierarchy,
[data-theme="dark"] .word-anatomy,
[data-theme="dark"] .interactive-sentence,
[data-theme="dark"] .vocab-card,
[data-theme="dark"] .search-container,
[data-theme="dark"] .stats-bar,
[data-theme="dark"] .alphabet-nav,
[data-theme="dark"] .daily-schedule,
[data-theme="dark"] .progress-tracker,
[data-theme="dark"] .interactive-demo,
[data-theme="dark"] .workflow-visual {
  background-color: var(--bg-secondary) !important;
  color: var(--text-primary) !important;
  border-color: var(--border) !important;
}

[data-theme="dark"] .section {
  border-left-color: var(--accent) !important;
}

/* Dark-mode recolour of the heading band that main.css paints on every h1-h4.
   The :where() keeps this selector at the same specificity as main.css's own
   `h1,h2,h3,h4` rule (0,0,1), so it still wins on source order (shared.css is
   linked after main.css) but no longer out-specifies components that opt OUT
   of the band -- .lx-cat-title, .cs-cat and the landing page's own reset all
   declare `background:none!important` and were being silently overridden here,
   so those headings were banded in dark mode but plain in light.
   Do NOT drop the :where(): a bare [data-theme="dark"] h2 scores 0,1,1 and
   re-breaks every one of those opt-outs. */
:where([data-theme="dark"]) h1,
:where([data-theme="dark"]) h2,
:where([data-theme="dark"]) h3,
:where([data-theme="dark"]) h4 {
  background-color: var(--table-header) !important;
  color: #e2e8f0 !important;
}

[data-theme="dark"] strong {
  color: var(--text-primary) !important;
}

[data-theme="dark"] a {
  color: var(--accent) !important;
}

/* ...but a .lx-btn is a component, not a prose link. The blanket rule above
   (0,1,1 + !important) out-ranks .lx-btn-primary's own `color:#fff` (0,1,0),
   repainting the label var(--accent) -- the exact colour of that button's own
   background -- so the Start/Continue CTA on all three landing pages rendered
   as a blank slab in dark mode. Same specificity trap as the heading band.
   These need to stay at 0,2,1+ to outrank it, hover states included. */
[data-theme="dark"] a.lx-btn { color: var(--text-primary) !important; }
[data-theme="dark"] a.lx-btn-primary { color: #fff !important; }
[data-theme="dark"] a.lx-btn:hover { color: var(--accent) !important; }
[data-theme="dark"] a.lx-btn-primary:hover { color: #fff !important; }

[data-theme="dark"] table,
[data-theme="dark"] td,
[data-theme="dark"] tr,
[data-theme="dark"] th {
  border-color: var(--border) !important;
}

[data-theme="dark"] th,
[data-theme="dark"] .conjugation-table th,
[data-theme="dark"] .comparison-table th,
[data-theme="dark"] .formation-table th,
[data-theme="dark"] .pronoun-table th {
  background-color: var(--table-header) !important;
}

[data-theme="dark"] code, [data-theme="dark"] pre {
  background-color: var(--code-bg) !important;
}

[data-theme="dark"] blockquote {
  background-color: var(--bg-secondary) !important;
  color: var(--text-primary) !important;
}

[data-theme="dark"] .search-box {
  background: var(--bg-secondary) !important;
  color: var(--text-primary) !important;
  border-color: var(--border) !important;
}

[data-theme="dark"] .pronunciation-guide {
  background: var(--bg-secondary) !important;
  color: var(--text-primary) !important;
}

[data-theme="dark"] .mermaid_container,
[data-theme="dark"] .mermaid-diagram,
[data-theme="dark"] .mermaid {
  background-color: var(--bg-secondary) !important;
  border-color: var(--border) !important;
}

[data-theme="dark"] canvas {
  border-color: var(--border) !important;
}

/* Dark mode for lesson 9 specific elements */
[data-theme="dark"] .category-section {
  background: var(--bg-secondary) !important;
  border-left-color: var(--accent) !important;
  color: var(--text-primary) !important;
}

[data-theme="dark"] .category-title {
  color: var(--accent) !important;
  background: none !important;
}

[data-theme="dark"] .kapampangan-word {
  color: var(--accent) !important;
}

[data-theme="dark"] .english-meaning {
  color: var(--text-secondary) !important;
}

[data-theme="dark"] .word-type {
  background: var(--bg-primary) !important;
  color: var(--text-muted) !important;
}

[data-theme="dark"] .example-sentence {
  background: var(--bg-primary) !important;
  color: var(--text-secondary) !important;
}

[data-theme="dark"] .pronunciation {
  color: #f87171 !important;
}

[data-theme="dark"] .meaning {
  color: var(--text-muted) !important;
}

/* BEGIN footer-nav-styles (managed by add_footer_nav.py) */
/* Static lesson footer (inserted by add_footer_nav.py into each lesson HTML) */
.site-footer {
    text-align: center;
    padding: 1.5rem 1rem;
    font-size: .85rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    margin-top: 2rem;
    font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
}
.site-footer a { color: var(--accent); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }
.site-footer p { margin: .35rem 0; }

.footer-links {
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
    margin-top: .5rem;
}

/* Home-link: outlined "ghost" variant to distinguish from prev/next */
.lesson-nav .home-link {
    background: transparent;
    color: var(--accent);
    border: 2px solid var(--accent);
}
.lesson-nav .home-link:hover {
    background: var(--accent);
    color: #fff;
}

/* First lesson uses <span></span> as a prev placeholder; keep it inert */
.lesson-nav > span:empty { flex: 0 0 auto; }
/* END footer-nav-styles */

/* ---------------------------------------------------------------
   Token aliases for the audio layer (this course names its custom
   properties differently). Appended to shared.css, which owns both
   the :root and [data-theme="dark"] scopes.
   --------------------------------------------------------------- */
:root {
    --card-bg: var(--bg-secondary);
    --bg-color: var(--bg-primary);
    --text-color: var(--text-primary);
    --text-light: var(--text-muted);
    --border-color: var(--border);
    --primary-color: var(--accent);
    --primary-light: var(--accent-light);
    --radius-sm: 6px;
    --shadow-sm: var(--card-shadow);
    --warning-bg: #fffbeb;
    --warning-border: #f59e0b;
}
[data-theme="dark"] {
    --warning-bg: rgba(245, 158, 11, .12);
}

/* ===========================
   Audio buttons
   Injected by audio.js next to target-language text. When no matching
   voice is installed the whole layer is hidden rather than left to
   mispronounce the text with an English voice.
   =========================== */
.audio-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.55rem;
    height: 1.55rem;
    margin-left: .4rem;
    padding: 0;
    vertical-align: middle;
    background: transparent;
    color: var(--text-light);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    font-size: .7rem;
    line-height: 1;
    cursor: pointer;
    transition: color .2s, border-color .2s, background .2s;
}
.audio-btn:hover  { color: var(--primary-color); border-color: var(--primary-color); background: var(--primary-light); }
.audio-btn:focus-visible { outline: 2px solid var(--primary-color); outline-offset: 2px; }
.audio-btn.speaking { color: #fff; background: var(--primary-color); border-color: var(--primary-color); }

html.no-tts-voice .audio-btn { display: none; }

/* Both notices are injected right after the page's first <h1>, which on every
   tier sits inside a saturated gradient hero. They therefore carry their own
   OPAQUE background and a single uniform text colour — black on light, white
   on dark — so the gradient cannot bleed through and the bold lead-in does not
   read as a second, dimmer colour. The amber/blue split is kept: amber means
   no voice at all, blue means a stand-in voice is speaking. */
.audio-notice,
.audio-fallback {
    display: none;
    font-size: .85rem;
    color: #000;
    border-radius: var(--radius-sm);
    padding: .6rem .9rem;
    margin: 1rem 0;
}
/* !important because the dark theme sets `[data-theme="dark"] strong` with
   !important; this keeps the bold lead-in the same colour as the body text. */
.audio-notice strong,
.audio-fallback strong { color: inherit !important; }

.audio-notice {
    background: #fffbeb;
    border-left: 4px solid var(--warning-border);
}
html.no-tts-voice .audio-notice { display: block; }

/* Shown only when a stand-in voice is speaking (e.g. Spanish reading Kapampangan). */
.audio-fallback {
    background: #eff6ff;
    border-left: 4px solid var(--primary-color);
}
html.tts-fallback .audio-fallback { display: block; }

[data-theme="dark"] .audio-notice,
[data-theme="dark"] .audio-fallback { color: #fff; }
[data-theme="dark"] .audio-notice   { background: #2b2011; }
[data-theme="dark"] .audio-fallback { background: #11203a; }

/* ===========================
   Listener panel (voice + speed), injected by audio.js.
   A floating collapsible control, like the ESL courses.
   =========================== */
.tts-settings {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 1150;
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
html.no-tts-voice .tts-settings { display: none; }

.tts-toggle {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .5rem .85rem;
    font: inherit;
    font-size: .85rem;
    font-weight: 600;
    color: #fff;
    background: var(--primary-color);
    border: none;
    border-radius: 999px;
    box-shadow: 0 4px 14px rgba(0,0,0,.22);
    cursor: pointer;
    transition: filter .15s, transform .15s;
}
.tts-toggle:hover { filter: brightness(1.08); transform: translateY(-1px); }
.tts-caret { font-size: .7rem; }

.tts-panel {
    position: absolute;
    right: 0;
    bottom: calc(100% + .55rem);
    width: 260px;
    max-width: 78vw;
    padding: 1rem;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 12px 34px rgba(0,0,0,.28);
}
.tts-row { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .85rem; }
.tts-row label { font-size: .78rem; font-weight: 600; color: var(--text-light); }
.tts-panel select {
    width: 100%;
    padding: .45rem .5rem;
    font: inherit;
    font-size: .88rem;
    color: var(--text-color);
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
}
.tts-panel input[type="range"] { width: 100%; accent-color: var(--primary-color); }
.tts-rate-val { font-weight: 400; color: var(--text-light); }
.tts-test {
    width: 100%;
    padding: .5rem;
    font: inherit;
    font-size: .88rem;
    font-weight: 600;
    color: #fff;
    background: var(--primary-color);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
}
.tts-test:hover { filter: brightness(1.08); }

@media print { .tts-settings { display: none !important; } }

/* ===========================
   Pronunciation reader (kapampangan_reader.html)
   Uses the audio-layer token aliases defined above.
   =========================== */
.reader-panel {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 1.25rem;
    margin: 1.5rem 0;
    box-shadow: var(--shadow-sm);
}
.reader-label {
    display: block;
    font-size: .78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-light);
    margin-bottom: .4rem;
}
.reader-input {
    width: 100%;
    padding: .75rem .9rem;
    font-family: inherit;
    font-size: 1.05rem;
    line-height: 1.6;
    color: var(--text-color);
    background: var(--bg-color);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    resize: vertical;
}
.reader-input:focus { outline: none; border-color: var(--primary-color); }

.reader-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 1rem;
    margin-top: 1rem;
}
.reader-control { display: flex; flex-direction: column; gap: .3rem; min-width: 11rem; flex: 1 1 11rem; }
.reader-control > label { font-size: .78rem; font-weight: 600; color: var(--text-light); }
.reader-control select,
.reader-control input[type="range"] {
    width: 100%;
    padding: .4rem .5rem;
    font-family: inherit;
    font-size: .9rem;
    color: var(--text-color);
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
}
.reader-control input[type="range"] { padding: 0; border: none; background: transparent; }

.reader-buttons { display: flex; gap: .5rem; flex: 0 0 auto; }
.reader-btn {
    padding: .55rem 1rem;
    font-family: inherit;
    font-size: .92rem;
    color: var(--text-color);
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background .2s, border-color .2s, opacity .2s;
}
.reader-btn:hover:not(:disabled) { border-color: var(--primary-color); background: var(--primary-light); }
.reader-btn:disabled { opacity: .45; cursor: default; }
.reader-btn-primary { color: #fff; background: var(--primary-color); border-color: var(--primary-color); }
.reader-btn-primary:hover:not(:disabled) { filter: brightness(1.08); }

.reader-notice,
.reader-fallback {
    font-size: .85rem;
    color: var(--text-light);
    border-radius: var(--radius-sm);
    padding: .6rem .9rem;
    margin: 1rem 0 0;
}
.reader-notice   { background: var(--warning-bg); border-left: 4px solid var(--warning-border); }
.reader-fallback { background: var(--primary-light); border-left: 4px solid var(--primary-color); }

.reader-display {
    margin-top: 1rem;
    padding: 1rem;
    min-height: 4rem;
    font-size: 1.15rem;
    line-height: 2;
    background: var(--bg-color);
    border-radius: var(--radius-sm);
}
.r-word { padding: .1rem .12rem; border-radius: 3px; cursor: pointer; transition: background .15s; }
.r-word:hover { background: var(--primary-light); }
.speaking-sentence { background: var(--primary-light); border-radius: 4px; }
.speaking-word { background: var(--primary-color); color: #fff; }
.reader-summary { font-size: .8rem; color: var(--text-light); margin: .5rem 0 0; }

/* The 4-column analysis table is wider than a phone. Let it scroll inside its own
   wrapper rather than pushing the whole page sideways. */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.reader-table { width: 100%; border-collapse: collapse; }
.reader-table th, .reader-table td {
    padding: .55rem .7rem;
    border-bottom: 1px solid var(--border-color);
    text-align: left;
    vertical-align: middle;
}
.reader-table th { background: var(--table-header, var(--primary-color)); color: #fff; }
.reader-table .r-ipa { font-family: 'Cascadia Code', 'Fira Code', Consolas, monospace; }
.r-stress {
    font-weight: 700;
    color: var(--primary-color);
    border-bottom: 2px solid var(--primary-color);
}

.r-tag {
    display: inline-block;
    margin: 0 .25rem .2rem 0;
    padding: .1rem .45rem;
    font-size: .72rem;
    border-radius: 999px;
    white-space: nowrap;
    border: 1px solid var(--border-color);
    color: var(--text-light);
}
.r-tag-malumay  { background: rgba(34,197,94,.12);  color: #16a34a; border-color: #22c55e; }
.r-tag-mabilis  { background: rgba(59,130,246,.12); color: #2563eb; border-color: #3b82f6; }
.r-tag-malumi   { background: rgba(245,158,11,.12); color: #b45309; border-color: #f59e0b; }
.r-tag-maragsa  { background: rgba(239,68,68,.12);  color: #dc2626; border-color: #ef4444; }
.r-tag-assumed  { background: transparent; font-style: italic; }
.r-tag-ng       { background: var(--primary-light); color: var(--primary-color); border-color: var(--primary-color); }
.r-tag-glottal  { background: transparent; }

@media (max-width: 640px) {
    .reader-buttons { width: 100%; }
    .reader-btn { flex: 1; }
}

/* ===========================
   Diagrams: canvas and mermaid
   =========================== */

/* The lesson canvases carry fixed width attributes (up to 900px) and were pushing the
   whole page sideways on a phone. height:auto keeps their aspect ratio while they scale. */
canvas {
    max-width: 100%;
    height: auto;
}

@media (max-width: 640px) {
    /* Mermaid emits <svg width="100%" style="max-width:…">, so on a phone a wide
       flowchart scales down until its labels are unreadable. Clearing max-width alone
       does nothing — width:100% still binds it to the container. Give it a floor and
       let the block scroll instead. */
    .mermaid {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .mermaid svg {
        max-width: none !important;
        min-width: 34rem;
    }

    /* Several lesson tables sit outside a .table-wrap and pushed the page sideways.
       Let each scroll within its own box. */
    table {
        display: block;
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* .comparison-grid is declared "1fr 1fr" in each page's own <style> block, and two
       columns cannot fit a phone — the grid items' min-content width (216px each) forces
       the row past the viewport. Stack them instead. The `body` prefix is only there to
       out-specify the page rule, which wins on document order otherwise. min-width:0
       lets a grid item shrink below its content, which grid does not allow by default. */
    body .comparison-grid {
        grid-template-columns: 1fr;
    }
    body .comparison-grid > * {
        min-width: 0;
    }

    /* Lesson 8's prompt templates contain unbreakable tokens such as
       "[conversation/lesson/exercise/story]". They fit no line, so they paint outside
       their paragraph and inflate the page's scrollWidth. overflow-wrap is inherited,
       so one declaration on body covers the nested prose containers. */
    body {
        overflow-wrap: break-word;
    }
}
