:root {
  color-scheme: light;
  --font-ui: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-arabic: "Noto Naskh Arabic", "Scheherazade New", "Amiri", serif;
  --font-quran: "KFGQPC Hafs Uthmanic Script", "Amiri Quran", "Noto Naskh Arabic", serif;
  --color-bg: #fffaf0;
  --color-surface: #ffffff;
  --color-surface-2: #f8f3e8;
  --color-text: #17201c;
  --color-muted: #66736d;
  --color-border: rgba(23, 32, 28, 0.14);
  --app-accent: #0f766e;
  --color-primary: var(--app-accent);
  --color-primary-contrast: #ffffff;
  --color-success: #15803d;
  --color-warning: #b45309;
  --color-danger: #b91c1c;
  --shadow-soft: 0 10px 30px rgba(15, 23, 42, 0.08);
  --motion-fast: 140ms ease;
  --motion-med: 220ms ease;
  --ink: var(--color-text);
  --muted: var(--color-muted);
  --paper: var(--color-bg);
  --panel: var(--color-surface);
  --line: var(--color-border);
  --brand: var(--color-primary);
  --brand-2: #c97b3c;
  --soft: #edf6f1;
  --accent: #f4dfbd;
  --wrong: var(--color-danger);
  --right: var(--color-success);
  font-family: var(--font-ui);
}

[data-theme="dark"] {
  color-scheme: dark;
  --color-bg: #0d1512;
  --color-surface: #14211d;
  --color-surface-2: #1b2a25;
  --color-text: #f5fbf7;
  --color-muted: #b8c7c0;
  --color-border: rgba(245, 251, 247, 0.14);
  --brand-2: #f0b35d;
  --soft: #1f342e;
  --accent: #2d2a20;
  --shadow-soft: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
}

[lang="ar"],
.arabic,
.arabic-token,
.example-row strong,
.flashcard strong,
.review-card strong {
  font-family: var(--font-arabic);
  font-feature-settings: "kern";
}

button,
a {
  font: inherit;
}

.topbar {
  min-height: 94px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 20px clamp(18px, 4vw, 48px);
  border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, var(--panel) 0%, var(--color-surface-2) 100%);
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: flex-end;
}

.install-button {
  min-width: 132px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.7rem, 4vw, 2.6rem);
}

h2 {
  font-size: clamp(1.55rem, 3vw, 2.4rem);
  line-height: 1.05;
}

h3 {
  font-size: 1.15rem;
}

.eyebrow,
.label {
  margin-bottom: 8px;
  color: var(--brand);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.streak-box {
  min-width: 108px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  text-align: center;
}

.streak-box span {
  display: block;
  color: var(--brand-2);
  font-size: 1.8rem;
  font-weight: 900;
}

.streak-box small {
  color: var(--muted);
}

.app-shell {
  display: grid;
  grid-template-columns: 108px 1fr;
  min-height: calc(100vh - 94px);
}

.rail {
  padding: 18px 14px;
  border-right: 1px solid var(--line);
  background: var(--color-surface-2);
}

.nav-button {
  width: 100%;
  min-height: 74px;
  display: grid;
  place-items: center;
  gap: 4px;
  margin-bottom: 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.nav-button span {
  font-size: 1.45rem;
}

.nav-button strong {
  font-size: 0.78rem;
}

.nav-button.active {
  border-color: #b8d6ca;
  background: var(--panel);
  color: var(--brand);
  box-shadow: 0 8px 20px rgba(24, 75, 60, 0.08);
}

.workspace {
  padding: clamp(18px, 4vw, 42px);
  overflow: hidden;
}

.view {
  display: none;
}

.active-view {
  display: block;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 24px;
  align-items: stretch;
  margin-bottom: 30px;
  padding-bottom: 26px;
  border-bottom: 1px solid var(--line);
}

.hero p {
  max-width: 760px;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.65;
}

.daily-card,
.lesson-panel,
.trainer,
.lesson-card,
.quiz-card,
.builder-card,
.flashcard,
.summary-card,
.onboarding-card,
.search-panel,
.review-card,
.review-sidebar,
.glossary-card,
.session-card,
.resource-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow-soft);
}

.daily-card {
  display: grid;
  align-content: center;
  gap: 12px;
  padding: 22px;
}

.daily-card strong {
  font-size: 1.35rem;
  line-height: 1.2;
}

.daily-card p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.45;
}

.step-mini {
  border: 1px solid #d8c6a4;
  border-radius: 999px;
  padding: 8px 12px;
  background: #fff8e9;
  color: #7a4c2b;
  font-size: 0.85rem;
  font-weight: 900;
  text-align: center;
}

.primary-button,
.ghost-button,
.icon-button,
.resource-card a,
.option-button,
.word-chip {
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 10px 14px;
  cursor: pointer;
  text-decoration: none;
}

.primary-button {
  background: var(--brand);
  color: #fff;
  font-weight: 800;
}

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

.ghost-button,
.icon-button,
.resource-card a {
  border-color: var(--line);
  background: var(--panel);
  color: var(--ink);
  font-weight: 700;
}

.icon-button {
  width: 44px;
  padding: 0;
  font-size: 1.2rem;
}

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--brand) 62%, white);
  outline-offset: 3px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.progress-meter {
  min-width: 210px;
  color: var(--muted);
  font-size: 0.9rem;
}

.progress-meter div {
  height: 9px;
  margin-top: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--color-surface-2);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}

.summary-card,
.onboarding-card,
.search-panel,
.review-card,
.review-sidebar {
  padding: 18px;
}

.summary-card strong {
  display: block;
  color: var(--brand);
  font-size: clamp(1.8rem, 5vw, 2.8rem);
  line-height: 1;
}

.summary-card p,
.onboarding-card p,
.review-sidebar p,
.quiz-source {
  color: var(--muted);
  line-height: 1.5;
}

.onboarding-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(240px, 0.75fr);
  gap: 18px;
  align-items: start;
  margin-bottom: 22px;
}

.onboarding-steps {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.onboarding-steps li {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--color-surface-2);
  color: var(--muted);
  font-weight: 700;
}

.onboarding-steps li.active {
  border-color: color-mix(in srgb, var(--brand) 45%, var(--line));
  color: var(--ink);
  background: var(--soft);
}

.search-panel {
  display: grid;
  gap: 10px;
  margin-bottom: 22px;
}

input[type="search"] {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
}

.search-results {
  display: grid;
  gap: 8px;
}

.search-result {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--panel);
  color: var(--ink);
  text-align: left;
}

.progress-meter i {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--brand-2);
  transition: width 0.25s ease;
}

.session-grid,
.resource-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}

.session-card,
.resource-card {
  display: grid;
  gap: 13px;
  padding: 18px;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.session-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 18px 38px rgba(41, 56, 50, 0.13);
}

.session-card.complete {
  border-color: #91c6ae;
  background: color-mix(in srgb, var(--soft) 58%, var(--panel));
}

.session-picture {
  width: 100%;
  aspect-ratio: 16 / 9;
  display: block;
  border: 1px solid #e5dcc7;
  border-radius: 8px;
  object-fit: cover;
  background: #fff8eb;
}

.session-card h3 {
  margin-bottom: 0;
}

.session-card p,
.resource-card p,
.lesson-panel p {
  color: var(--muted);
  line-height: 1.5;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill {
  border-radius: 999px;
  padding: 7px 10px;
  background: var(--soft);
  color: var(--brand);
  font-size: 0.82rem;
  font-weight: 800;
}

.pill.warning {
  background: #fff7e4;
  color: var(--color-warning);
}

.lesson-pill {
  border: 0;
  font-family: inherit;
  line-height: 1;
}

.lesson-pill:hover,
.lesson-pill:focus-visible {
  background: #dff3e9;
  outline: 2px solid #96c7b5;
  outline-offset: 2px;
}

.lesson-pill.complete {
  background: #dff3e9;
  color: #175944;
}

.session-actions,
.control-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.practice-layout {
  display: grid;
  grid-template-columns: minmax(240px, 340px) minmax(0, 1fr);
  gap: 18px;
}

.lesson-panel {
  padding: 20px;
  align-self: start;
}

.lesson-panel h2 {
  font-size: clamp(1.45rem, 2.4vw, 2.25rem);
  line-height: 1.08;
}

.lesson-switcher {
  margin-top: 18px;
}

.session-lesson-list {
  display: grid;
  gap: 8px;
}

.session-lesson {
  display: grid;
  gap: 3px;
  width: 100%;
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.session-lesson span {
  color: var(--brand);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.session-lesson strong {
  font-size: 0.95rem;
}

.session-lesson.active {
  border-color: #96c7b5;
  background: var(--soft);
}

.trainer {
  padding: 18px;
  min-width: 0;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.tab {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
  font-weight: 800;
}

.tab.active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

.learning-path {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.step-dot {
  min-height: 58px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
  text-align: left;
}

.step-dot span {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--soft);
  color: var(--brand);
  font-weight: 900;
}

.step-dot strong {
  font-size: 0.9rem;
}

.step-dot.active {
  border-color: #96c7b5;
  color: var(--ink);
  box-shadow: 0 8px 18px rgba(25, 115, 94, 0.1);
}

.step-dot.done span {
  background: var(--brand);
  color: #fff;
}

.mode {
  display: none;
}

.active-mode {
  display: block;
}

.flashcard {
  min-height: 360px;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 14px;
  padding: clamp(20px, 4vw, 42px);
  margin-bottom: 14px;
  cursor: pointer;
  text-align: center;
}

.card-image {
  width: min(280px, 72vw);
  aspect-ratio: 3 / 2;
  border: 1px solid #eadfca;
  border-radius: 8px;
  object-fit: cover;
  background: #fff8eb;
}

.card-image[hidden] {
  display: none;
}

.flashcard strong {
  font-size: clamp(2.4rem, 8vw, 5rem);
  line-height: 1.28;
}

.flashcard.flipped strong {
  font-size: clamp(2rem, 7vw, 4.5rem);
}

.flashcard p {
  color: var(--muted);
  font-size: 1.18rem;
}

.quiz-card,
.lesson-card,
.builder-card {
  padding: clamp(18px, 3vw, 30px);
}

.lesson-card {
  display: grid;
  gap: 16px;
}

.lesson-visual-wrap {
  display: grid;
  grid-template-columns: minmax(120px, 190px) 1fr;
  gap: 18px;
  align-items: center;
}

.lesson-visual {
  width: 100%;
  aspect-ratio: 4 / 3;
  display: block;
  border: 1px solid #e5dcc7;
  border-radius: 8px;
  object-fit: cover;
  background: #fff8eb;
}

.reward-chip {
  width: fit-content;
  max-width: 100%;
  margin-top: 10px;
  border: 1px solid #e5d1a8;
  border-radius: 999px;
  padding: 8px 12px;
  background: #fff7e4;
  color: #7a4c2b;
  font-size: 0.88rem;
  font-weight: 800;
}

.lesson-card p,
.coach-box li {
  color: var(--muted);
  line-height: 1.65;
}

.pattern-box,
.coach-box,
.challenge-box,
.token-insight {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: var(--color-surface-2);
}

.pattern-box strong {
  display: block;
  font-size: clamp(1.4rem, 4vw, 2.4rem);
  line-height: 1.55;
}

.example-list {
  display: grid;
  gap: 10px;
}

.example-row {
  display: grid;
  grid-template-columns: 104px minmax(120px, 0.7fr) 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.arabic-token-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  direction: rtl;
  justify-content: flex-end;
}

.arabic-token {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  font-size: 1.35rem;
  line-height: 1.5;
}

.arabic-token:hover,
.arabic-token:focus-visible {
  border-color: color-mix(in srgb, var(--brand) 55%, var(--line));
  background: var(--soft);
}

.token-insight {
  display: grid;
  gap: 6px;
}

.token-insight p {
  margin-bottom: 0;
  color: var(--muted);
}

.example-row.no-picture {
  grid-template-columns: minmax(100px, 0.7fr) 1fr;
}

.speak-button {
  min-width: 84px;
  justify-self: end;
  white-space: nowrap;
}

.voice-status {
  min-height: 24px;
  margin: -6px 0 10px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.voice-status.playing {
  color: var(--right);
}

.voice-status.try {
  color: var(--wrong);
}

.example-picture {
  width: 100%;
  aspect-ratio: 3 / 2;
  display: block;
  border: 1px solid #eadfca;
  border-radius: 8px;
  object-fit: contain;
  background: #fff8eb;
  transition: filter 0.2s ease, transform 0.2s ease;
}

.example-row strong {
  direction: rtl;
  font-size: 1.35rem;
  line-height: 1.65;
  text-align: right;
}

.coach-box ol {
  margin: 0;
  padding-left: 20px;
}

.options {
  display: grid;
  gap: 10px;
}

.option-button {
  border-color: var(--line);
  background: var(--panel);
  color: var(--ink);
  text-align: left;
  font-weight: 700;
}

.option-button.correct {
  border-color: #7db79a;
  background: #e4f3ec;
}

.option-button.wrong {
  border-color: #d79a9a;
  background: #fae9e9;
}

.feedback {
  min-height: 26px;
  margin-top: 14px;
  font-weight: 800;
}

.feedback.good {
  color: var(--right);
}

.feedback.try {
  color: var(--wrong);
}

.next-step-bar {
  position: sticky;
  bottom: 12px;
  display: flex;
  justify-content: flex-end;
  margin-top: 16px;
  padding-top: 12px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0), var(--panel) 45%);
}

.next-step-bar .primary-button {
  min-width: 148px;
  box-shadow: 0 12px 24px rgba(25, 115, 94, 0.18);
}

.word-bank,
.answer-tray {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  min-height: 58px;
  padding: 12px;
  margin: 12px 0;
  border: 1px dashed #c9d3ce;
  border-radius: 8px;
  background: var(--color-surface-2);
}

.answer-tray {
  background: color-mix(in srgb, var(--accent) 28%, var(--panel));
}

.word-chip {
  border-color: #d7bea1;
  background: var(--panel);
  color: var(--ink);
  font-weight: 900;
}

.word-chip.arabic {
  font-size: 1.3rem;
}

.resource-card a {
  display: inline-flex;
  width: fit-content;
  align-items: center;
}

.review-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(240px, 320px);
  gap: 18px;
}

.review-card {
  display: grid;
  gap: 14px;
  min-height: 360px;
  align-content: center;
}

.review-card strong {
  font-size: clamp(2.4rem, 8vw, 5rem);
  line-height: 1.25;
  text-align: center;
}

.review-actions {
  justify-content: center;
}

.glossary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.glossary-card {
  display: grid;
  gap: 8px;
  padding: 18px;
}

.glossary-card h3 {
  margin-bottom: 0;
}

.glossary-card p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.55;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

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

  .rail {
    position: sticky;
    top: 0;
    z-index: 2;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav-button {
    min-height: 58px;
    margin-bottom: 0;
  }

  .nav-button strong {
    font-size: 0.68rem;
  }

  .nav-button span {
    font-size: 1.05rem;
  }

  .hero,
  .practice-layout,
  .example-row,
  .lesson-visual-wrap,
  .onboarding-card,
  .dashboard-grid,
  .review-layout {
    grid-template-columns: 1fr;
  }

  .speak-button {
    justify-self: stretch;
  }

  .tabs {
    grid-template-columns: repeat(2, 1fr);
  }

  .learning-path {
    grid-template-columns: repeat(2, 1fr);
  }

  .section-head,
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
    justify-content: space-between;
  }

  .next-step-bar {
    bottom: 0;
    margin-inline: -18px;
    padding: 12px 18px;
    border-top: 1px solid var(--line);
  }

  .next-step-bar .primary-button {
    width: 100%;
  }

  .progress-meter {
    width: 100%;
  }
}

@media (max-width: 420px) {
  .workspace {
    padding: 16px;
  }

  .rail {
    padding: 10px 8px;
    gap: 6px;
  }

  .nav-button {
    min-height: 54px;
    padding: 6px 4px;
  }

  .arabic-token,
  .example-row strong {
    font-size: 1.25rem;
  }

  .tabs,
  .learning-path {
    grid-template-columns: 1fr;
  }
}
