: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: #155e75;
  --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: #8a5a16;
  --soft: #e8f4f5;
  --accent: #f2dfbd;
  --wrong: var(--color-danger);
  --right: var(--color-success);
  font-family: var(--font-ui);
}

[data-theme="dark"] {
  color-scheme: dark;
  --color-bg: #0c1416;
  --color-surface: #142022;
  --color-surface-2: #1a2a2d;
  --color-text: #f5fbf7;
  --color-muted: #b8c7c0;
  --color-border: rgba(245, 251, 247, 0.14);
  --brand-2: #f0b35d;
  --soft: #1d3439;
  --accent: #302b1f;
  --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,
.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: color-mix(in srgb, var(--brand), var(--line) 45%);
  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,
.session-card,
.resource-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 12px 32px rgba(41, 56, 50, 0.08);
}

.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: var(--accent);
  color: #7a4c2b;
  font-size: 0.85rem;
  font-weight: 900;
  text-align: center;
}

.primary-button,
.ghost-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,
.resource-card a {
  border-color: var(--line);
  background: var(--panel);
  color: var(--ink);
  font-weight: 700;
}

.icon-button {
  width: 44px;
  height: 44px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--brand);
  cursor: pointer;
  font-size: 1.15rem;
  font-weight: 900;
}

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

.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: #e7e1d4;
}

.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: #f7fcf9;
}

.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;
}

.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: #fff;
  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: #f1faf5;
}

.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: #fff;
  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: #fff;
  color: var(--muted);
  cursor: pointer;
  text-align: left;
}

.step-dot span {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #edf6f1;
  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 {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fffdf8;
}

.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: #fff;
}

.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: #fff;
  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: #f8fbf9;
}

.answer-tray {
  background: #fff9ec;
}

.word-chip {
  border-color: #d7bea1;
  background: #fff;
  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;
}

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

.summary-card,
.search-panel,
.source-note,
.topic-card,
.topic-route,
.review-card,
.challenge-runner,
.bookmarks-panel,
.note-editor,
.note-panel,
.topic-mini {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow-soft);
}

.summary-card {
  min-height: 126px;
  display: grid;
  align-content: center;
  gap: 8px;
  padding: 18px;
}

.summary-card strong {
  color: var(--brand-2);
  font-size: clamp(1.5rem, 3vw, 2.1rem);
  line-height: 1;
}

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

.search-panel,
.note-panel,
.topic-mini {
  display: grid;
  gap: 10px;
  margin-bottom: 22px;
  padding: 18px;
}

.topic-mini {
  margin-top: 16px;
  margin-bottom: 0;
}

.search-panel input,
.select-control,
.note-editor textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
}

.note-editor textarea {
  resize: vertical;
  line-height: 1.55;
}

.search-results,
.topic-grid,
.topic-lesson-list {
  display: grid;
  gap: 10px;
}

.topic-grid {
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  margin-bottom: 18px;
}

.search-result,
.topic-card,
.bookmark-item {
  display: grid;
  gap: 6px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--color-surface-2);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.search-result small,
.topic-card p,
.topic-route p,
.bookmarks-panel p,
.challenge-runner p,
.source-note {
  color: var(--muted);
  line-height: 1.55;
}

.topic-route,
.review-card,
.challenge-runner,
.bookmarks-panel,
.note-editor {
  display: grid;
  gap: 14px;
  padding: clamp(16px, 3vw, 26px);
}

.review-card,
.challenge-runner {
  text-align: center;
}

.review-card strong {
  display: block;
  font-size: clamp(2.2rem, 8vw, 5rem);
  line-height: 1.35;
}

.challenge-runner h3 {
  font-size: clamp(1.35rem, 3vw, 2.1rem);
  line-height: 1.25;
}

.notes-layout {
  display: grid;
  grid-template-columns: minmax(220px, 320px) minmax(0, 1fr);
  gap: 16px;
}

.source-note {
  padding: 14px 16px;
}

.source-note:empty {
  display: none;
}

[data-theme="dark"] .daily-card,
[data-theme="dark"] .lesson-panel,
[data-theme="dark"] .trainer,
[data-theme="dark"] .lesson-card,
[data-theme="dark"] .quiz-card,
[data-theme="dark"] .builder-card,
[data-theme="dark"] .flashcard,
[data-theme="dark"] .session-card,
[data-theme="dark"] .resource-card,
[data-theme="dark"] .example-row,
[data-theme="dark"] .tab,
[data-theme="dark"] .step-dot,
[data-theme="dark"] .session-lesson,
[data-theme="dark"] .pattern-box,
[data-theme="dark"] .coach-box,
[data-theme="dark"] .challenge-box,
[data-theme="dark"] .word-bank,
[data-theme="dark"] .answer-tray,
[data-theme="dark"] .word-chip,
[data-theme="dark"] .option-button {
  background: var(--panel);
}

@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(8, minmax(0, 1fr));
    gap: 8px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    overflow-x: auto;
  }

  .nav-button {
    min-width: 76px;
    min-height: 58px;
    margin-bottom: 0;
    padding-inline: 6px;
  }

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

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

  .hero,
  .practice-layout,
  .example-row,
  .lesson-visual-wrap,
  .dashboard-grid,
  .notes-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 {
    gap: 6px;
    padding: 10px;
  }

  .nav-button {
    min-width: 72px;
    padding-inline: 4px;
  }

  .flashcard strong,
  .review-card strong {
    overflow-wrap: anywhere;
  }
}
