* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* ---- Theme variables ----
   Dark:  bg #000000, primary text #000000 (as specified).
          Muted/secondary tones use white-opacity accents so everything
          — toggle, hints, translations, grammar deep-dive — stays findable.
   Light: bg #ffffff, text #000000.
*/
:root[data-theme="dark"] {
  --bg: #000000;
  --text: #000000;
  --star: #ffffff;
  --muted-1: rgba(255, 255, 255, 0.72);
  --muted-2: rgba(255, 255, 255, 0.55);
  --muted-3: rgba(255, 255, 255, 0.38);
  --muted-4: rgba(255, 255, 255, 0.24);
  --line: rgba(255, 255, 255, 0.09);
  --line-soft: rgba(255, 255, 255, 0.05);
  --glow: rgba(255, 255, 255, 0.65);
  --good: rgba(150, 220, 160, 0.85);
  --bad: rgba(230, 150, 150, 0.75);
}

:root[data-theme="light"] {
  --bg: #ffffff;
  --text: #000000;
  --star: #000000;
  --muted-1: rgba(0, 0, 0, 0.72);
  --muted-2: rgba(0, 0, 0, 0.52);
  --muted-3: rgba(0, 0, 0, 0.42);
  --muted-4: rgba(0, 0, 0, 0.32);
  --line: rgba(0, 0, 0, 0.11);
  --line-soft: rgba(0, 0, 0, 0.06);
  --glow: rgba(0, 0, 0, 0.35);
  --good: rgba(30, 130, 60, 0.9);
  --bad: rgba(170, 45, 45, 0.85);
}

html, body {
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background 0.5s ease, color 0.5s ease;
}

.screen {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3.5rem 1.5rem;
}

/* Theme toggle — top right, understated */
.theme-toggle {
  position: fixed;
  top: 1.1rem;
  right: 1.1rem;
  z-index: 10;
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  color: var(--muted-3);
  padding: 0.4rem 0.55rem;
  transition: color 0.3s ease;
  user-select: none;
}

.theme-toggle:hover { color: var(--star); }

.content {
  width: 100%;
  max-width: 760px;
}

.legend {
  display: grid;
  grid-template-columns: 1.15fr 1fr 1fr 1fr;
  gap: 0.75rem;
  padding-bottom: 0.85rem;
  margin-bottom: 0.4rem;
  border-bottom: 1px solid var(--line);
}

.legend-item {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.6rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted-3);
}

.legend-item.rtl {
  direction: rtl;
  text-align: right;
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.72rem;
  font-family: "Vazirmatn", "IBM Plex Mono", monospace;
}

.word-list { list-style: none; }

.word-row {
  display: grid;
  grid-template-columns: 1.15fr 1fr 1fr 1fr;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.7rem 0;
  opacity: 0;
  transform: translateY(8px);
  animation: rise 0.9s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes rise {
  to { opacity: 1; transform: translateY(0); }
}

.cell {
  font-family: "Newsreader", Georgia, serif;
  cursor: pointer;
  transition: color 0.25s ease, transform 0.15s ease, text-shadow 0.25s ease;
  border-radius: 4px;
  user-select: none;
  outline: none;
}

.cell:hover { color: var(--star); }
.cell:focus-visible { box-shadow: 0 0 0 1px var(--muted-3); }

.cell.speaking {
  color: var(--star);
  text-shadow: 0 0 14px var(--glow);
  transform: translateY(-1px);
}

.cell-fr {
  font-size: 1.45rem;
  font-weight: 400;
  color: var(--star);
  letter-spacing: 0.01em;
}

.cell-en {
  font-size: 1rem;
  font-style: italic;
  color: var(--muted-2);
}

.cell-fa,
.cell-ckb {
  font-size: 1.15rem;
  color: var(--muted-1);
  font-family: "Vazirmatn", "Newsreader", serif;
}

.cell.rtl {
  direction: rtl;
  text-align: right;
}

.hint {
  margin-top: 2.4rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  color: var(--muted-4);
  text-align: center;
  font-style: italic;
}

/* ---- Grammar Deep-Dive ---- */
.grammar {
  margin: 2.4rem auto 0;
  max-width: 660px;
  padding-top: 1.7rem;
  border-top: 1px solid var(--line);
  opacity: 0;
  transform: translateY(8px);
  animation: rise 1s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.grammar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.1rem;
}

.grammar-label {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.6rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted-3);
}

/* Language lens selector */
.lang-selector {
  display: flex;
  gap: 0.15rem;
}

.lang-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  color: var(--muted-4);
  padding: 0.28rem 0.5rem;
  border-radius: 3px;
  transition: color 0.25s ease, background 0.25s ease;
  user-select: none;
}

.lang-btn:hover { color: var(--muted-1); }

.lang-btn.lang-active {
  color: var(--star);
  border-bottom: 1px solid var(--muted-2);
  border-radius: 0;
}

/* The lesson body — cross-fades on language change */
.lesson {
  text-align: left;
  transition: opacity 0.18s ease;
}

.lesson.fading { opacity: 0; }

.lesson.rtl {
  text-align: right;
  direction: rtl;
  font-family: "Vazirmatn", "Newsreader", serif;
}

.lesson-title {
  font-family: "Newsreader", Georgia, serif;
  font-weight: 500;
  font-size: 1.5rem;
  line-height: 1.25;
  color: var(--star);
  margin-bottom: 0.45rem;
  letter-spacing: 0.005em;
}

.lesson.rtl .lesson-title {
  font-family: "Vazirmatn", "Newsreader", serif;
}

.lesson-summary {
  font-family: "Newsreader", Georgia, serif;
  font-style: italic;
  font-weight: 400;
  font-size: 1.08rem;
  line-height: 1.5;
  color: var(--muted-1);
  margin-bottom: 1rem;
}

.lesson.rtl .lesson-summary { font-style: normal; }

.lesson-explanation {
  font-family: "Newsreader", Georgia, serif;
  font-weight: 300;
  font-size: 1.02rem;
  line-height: 1.75;
  color: var(--muted-2);
  margin-bottom: 1.2rem;
}

.lesson.rtl .lesson-explanation {
  font-family: "Vazirmatn", sans-serif;
  font-weight: 300;
  line-height: 1.95;
}

.lesson-examples {
  border-left: 2px solid var(--line);
  padding: 0.2rem 0 0.2rem 1rem;
  margin-bottom: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.lesson.rtl .lesson-examples {
  border-left: none;
  border-right: 2px solid var(--line);
  padding: 0.2rem 1rem 0.2rem 0;
}

.example {
  display: flex;
  align-items: baseline;
  gap: 0.55rem;
  font-family: "Newsreader", Georgia, serif;
  font-size: 0.98rem;
  line-height: 1.55;
}

/* Examples are English sentences — always LTR even in an RTL lesson */
.lesson.rtl .example {
  direction: ltr;
  text-align: left;
  flex-direction: row;
}

.ex-mark {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.85rem;
  flex-shrink: 0;
  line-height: 1.55;
}

.ex-mark-good { color: var(--good); }
.ex-mark-bad { color: var(--bad); }

.ex-text { color: var(--muted-1); }
.example-bad .ex-text {
  color: var(--muted-3);
  text-decoration: line-through;
  text-decoration-color: var(--bad);
  text-decoration-thickness: 1px;
}

.lesson-mnemonic {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.82rem;
  line-height: 1.65;
  color: var(--muted-2);
  padding-top: 0.4rem;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.lesson.rtl .lesson-mnemonic {
  font-family: "Vazirmatn", monospace;
  flex-direction: row-reverse;
}

.mnemonic-key {
  color: var(--muted-3);
  font-size: 0.7rem;
  flex-shrink: 0;
}

.meta {
  margin-top: 2rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  font-weight: 300;
  letter-spacing: 0.08em;
  color: var(--muted-3);
  text-align: center;
}

.footer {
  margin-top: 1.25rem;
  text-align: center;
}

.footer a {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  color: var(--muted-4);
  text-decoration: none;
  transition: color 0.3s ease;
}

.footer a:hover { color: var(--muted-1); }

@media (max-width: 640px) {
  .screen { padding: 2.6rem 1rem 2rem; }
  .theme-toggle {
    top: 0.7rem;
    right: 0.7rem;
    font-size: 0.62rem;
  }
  .legend,
  .word-row {
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem 0.9rem;
  }
  .legend { padding-bottom: 0.6rem; }
  .legend-item { font-size: 0.55rem; }
  .legend-item.rtl { font-size: 0.64rem; }
  .word-row {
    padding: 0.85rem 0;
    border-bottom: 1px solid var(--line-soft);
  }
  .cell-fr { font-size: 1.25rem; }
  .cell-en { font-size: 0.9rem; }
  .cell-fa,
  .cell-ckb { font-size: 1.05rem; }

  .grammar-header {
    align-items: flex-start;
    gap: 0.6rem;
  }
  .lesson-title { font-size: 1.3rem; }
  .lesson-summary { font-size: 1rem; }
  .lesson-explanation { font-size: 0.96rem; line-height: 1.7; }
  .example { font-size: 0.92rem; }
  .lesson-mnemonic { font-size: 0.76rem; }
  .lang-btn { font-size: 0.6rem; padding: 0.3rem 0.42rem; }
}