/* القاعدة النورانية — semantic text edition */
:root {
  /* Palette sampled from Furqan colored edition (القاعدة النورانية) */
  --bg: #f5fafc;
  --bg-card: #ffffff;
  --ink: #1e1e1e;
  --muted: #5a6570;
  --border: #c5dde8;
  --frame: #4aa8d4;
  --frame-soft: #c8e6f5;
  --green: #5a9848;
  --green-dark: #3f7340;
  --red: #ef3030;
  --red-soft: #f03834;
  --orange: #c07830;
  --magenta: #ac509c;
  --blue: #40b4f0;
  --blue-soft: #58c0f8;
  --labial: #00a8ec;
  --shadow: 0 2px 12px rgba(40, 110, 150, 0.08);
  --radius: 12px;
  --font: "Scheherazade New", "Amiri", "Traditional Arabic", "Noto Naskh Arabic", "Times New Roman", serif;
  --cell-size: clamp(2.4rem, 4.5vw, 3.4rem);
}

[data-theme="dark"] {
  --bg: #0e161c;
  --bg-card: #172229;
  --ink: #eef5f9;
  --muted: #9ab0bd;
  --border: #2a3d4a;
  --frame: #58c0f8;
  --frame-soft: #1e3544;
  --green: #7cbc68;
  --red: #ff5a5a;
  --red-soft: #ff524e;
  --orange: #e09848;
  --magenta: #d078c0;
  --blue: #68c8ff;
  --blue-soft: #7ad0ff;
  --labial: #40c0ff;
  --shadow: 0 2px 16px rgba(0, 0, 0, 0.35);
}

*, *::before, *::after { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  scroll-padding-top: 4.5rem;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 1.25rem;
  line-height: 1.85;
  color: var(--ink);
  background:
    radial-gradient(ellipse at top, var(--frame-soft) 0%, transparent 55%),
    var(--bg);
  min-height: 100vh;
}

/* Sticky TOC */
.toc {
  position: sticky;
  top: 0;
  z-index: 100;
  background: color-mix(in srgb, var(--bg-card) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.toc-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.85rem;
  max-width: 960px;
  margin: 0 auto;
}

.toc-bar button,
.nav-home {
  font-family: inherit;
  font-size: 1rem;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--ink);
  border-radius: 999px;
  padding: 0.35rem 0.9rem;
  cursor: pointer;
  text-decoration: none;
}

.toc-bar button:hover,
.nav-home:hover {
  border-color: var(--frame);
  color: var(--frame);
}

#theme-toggle {
  margin-inline-start: auto;
  width: 2.4rem;
  padding-inline: 0;
  font-size: 1.2rem;
}

.toc-panel {
  max-width: 960px;
  margin: 0 auto;
  padding: 0.5rem 0.85rem 0.9rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
  gap: 0.4rem;
  max-height: min(60vh, 28rem);
  overflow-y: auto;
}

.toc-panel[hidden] { display: none; }

.nav-link {
  display: block;
  text-decoration: none;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.55rem;
  font-size: 0.95rem;
  text-align: center;
}

.nav-link:hover,
.nav-link:focus-visible {
  background: var(--frame);
  color: #fff;
  border-color: var(--frame);
}

/* Book layout */
.book {
  max-width: 920px;
  margin: 0 auto;
  padding: 1rem 0.75rem 3rem;
}

.lesson,
.cover {
  background: var(--bg-card);
  border: 2px solid var(--frame-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
  padding: 1rem 0.85rem 1.35rem;
  outline: 1px solid color-mix(in srgb, var(--frame) 25%, transparent);
  outline-offset: -6px;
}

.cover {
  text-align: center;
  padding: 2rem 1rem 2.5rem;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--frame-soft) 55%, var(--bg-card)) 0%, var(--bg-card) 45%);
}

.cover-inner { max-width: 36rem; margin: 0 auto; }

.ayah {
  color: #b8860b;
  font-size: clamp(1.05rem, 3.2vw, 1.35rem);
  font-weight: 700;
}

.hadith {
  color: var(--muted);
  font-size: 1.05rem;
}

.cover-title {
  font-size: clamp(2.2rem, 8vw, 3.6rem);
  margin: 1.2rem 0 0.6rem;
  line-height: 1.3;
  font-weight: 700;
  color: #c87820;
  background: linear-gradient(180deg, #e8a838 12%, #1a1a1a 78%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 1px 0 rgba(255,255,255,0.35));
}

.author-label, .editor-label { color: var(--muted); margin: 0.2rem; font-size: 1rem; }
.author { color: var(--ink); font-size: 1.35rem; font-weight: 700; margin: 0.2rem; }
.rahimahullah { color: var(--muted); font-weight: 400; font-size: 0.95em; }
.editor { color: var(--orange); font-size: 1.2rem; font-weight: 700; }
.edition { margin-top: 1.2rem; color: var(--green); font-weight: 600; }
.cover-note { font-size: 0.95rem; color: var(--muted); margin-top: 1.5rem; }

.lesson-header { margin-bottom: 0.85rem; }
.lesson-header h2 {
  text-align: center;
  color: var(--orange);
  font-size: 1.6rem;
  margin: 0.2rem 0 0.8rem;
}

.lesson-banner {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.banner-num,
.banner-title {
  color: #fff;
  padding: 0.55rem 1rem;
  font-weight: 700;
  font-size: clamp(1rem, 3.5vw, 1.25rem);
  text-align: center;
}

.banner-num {
  background: var(--green);
  flex: 0 1 auto;
  min-width: 8rem;
  clip-path: polygon(0 0, calc(100% - 12px) 0, 100% 50%, calc(100% - 12px) 100%, 0 100%);
  padding-inline-end: 1.4rem;
}

.banner-title {
  background: var(--red-soft);
  flex: 1 1 12rem;
}

.sub {
  margin: 1.1rem 0 0.5rem;
  font-size: 1.15rem;
  color: var(--frame);
  border-bottom: 1px dashed var(--border);
  padding-bottom: 0.2rem;
}

.note {
  background: color-mix(in srgb, var(--frame-soft) 40%, var(--bg-card));
  border-inline-start: 4px solid var(--frame);
  padding: 0.65rem 0.85rem;
  border-radius: 0 8px 8px 0;
  font-size: 1.05rem;
  color: var(--muted);
}

.note.tip { border-color: var(--green); }

.prose-body { padding: 0 0.25rem; }
.prose-body p { text-align: justify; hyphens: auto; }

.toc-list {
  padding-inline-start: 1.4rem;
  line-height: 2;
}

.color-legend {
  margin: 1.2rem 0;
  padding: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
}

.color-legend h3 { margin: 0 0 0.5rem; font-size: 1.15rem; }
.color-legend ul { list-style: none; padding: 0; margin: 0; }
.color-legend li {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0.35rem 0;
}

.swatch {
  width: 1.1rem;
  height: 1.1rem;
  border-radius: 4px;
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.15);
}
.swatch.red { background: var(--red); }
.swatch.green { background: var(--green); }
.swatch.orange { background: var(--orange); }
.swatch.blue { background: var(--blue); }
.swatch.magenta { background: var(--magenta); }

/* Letter grids */
.letter-grid {
  display: grid;
  gap: 0;
  border: 1.5px solid var(--ink);
  border-radius: 6px;
  overflow: hidden;
  background: var(--bg-card);
  margin: 0.75rem 0;
}

.cols-4 { grid-template-columns: repeat(4, 1fr); }
.cols-5 { grid-template-columns: repeat(5, 1fr); }
.cols-6 { grid-template-columns: repeat(6, 1fr); }
.cols-7 { grid-template-columns: repeat(7, 1fr); }
.cols-8 { grid-template-columns: repeat(8, 1fr); }

.cell {
  border: 0.5px solid var(--border);
  min-height: calc(var(--cell-size) + 0.8rem);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem 0.2rem;
  background: var(--bg-card);
  text-align: center;
}

.cell.empty { background: color-mix(in srgb, var(--bg) 70%, var(--bg-card)); }

.glyph {
  font-size: var(--cell-size);
  font-weight: 700;
  line-height: 1;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: var(--cell-size);
}

.letter-card {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  min-height: calc(var(--cell-size) + 1.8rem);
  width: 100%;
}

.letter-name {
  color: var(--red);
  font-size: clamp(0.7rem, 2.2vw, 0.95rem);
  font-weight: 600;
  line-height: 1.15;
  text-align: center;
  display: block;
  width: 100%;
  margin: 0;
}

.letter-glyph {
  font-size: var(--cell-size);
  font-weight: 700;
  line-height: 1;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: calc(var(--cell-size) * 1.15);
  margin: 0 auto;
}

/* Colored pedagogy */
.c-red { color: var(--red); }
.c-green { color: var(--green); }
.c-blue { color: var(--blue); }
.c-black { color: var(--ink); }
.c-orange { color: var(--orange); }
.c-magenta { color: var(--magenta); }

.vowel { color: var(--orange); }
.vowel-kasra { color: var(--magenta); }
.madd { color: var(--magenta); }
.leen { color: var(--labial); }
.tanween { color: var(--magenta); }
.tanween-labial { color: var(--labial); }

.makharij {
  margin: 0.85rem 0;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  font-size: 1.15rem;
}
.makharij p { margin: 0.35rem 0; }

.legend-inline {
  text-align: center;
  font-size: 1.1rem;
  color: var(--muted);
}

.phrase-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin: 0.75rem 0;
}

.phrase {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  font-size: clamp(1.35rem, 4vw, 1.85rem);
  font-weight: 700;
  text-align: center;
  background: var(--bg);
  line-height: 1.7;
}

.site-footer {
  text-align: center;
  padding: 1.5rem 1rem 2rem;
  color: var(--muted);
  font-size: 1rem;
}
.site-footer .small { font-size: 0.9rem; }

/* Mobile */
@media (max-width: 640px) {
  body { font-size: 1.15rem; }
  .book { padding: 0.65rem 0.45rem 2.5rem; }
  .lesson, .cover { padding: 0.85rem 0.55rem 1.1rem; outline-offset: -4px; }

  .cols-8 { grid-template-columns: repeat(4, 1fr); }
  .cols-7 { grid-template-columns: repeat(4, 1fr); }
  .cols-6 { grid-template-columns: repeat(3, 1fr); }
  .cols-5 { grid-template-columns: repeat(3, 1fr); }
  .cols-4 { grid-template-columns: repeat(2, 1fr); }

  :root { --cell-size: clamp(1.85rem, 7.5vw, 2.5rem); }

  .banner-num {
    clip-path: none;
    width: 100%;
    border-radius: 8px 8px 0 0;
  }
  .banner-title { border-radius: 0 0 8px 8px; }
  .lesson-banner { flex-direction: column; }
}

@media (max-width: 380px) {
  .cols-8, .cols-7 { grid-template-columns: repeat(3, 1fr); }
  .cols-6, .cols-5 { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 900px) {
  .book { padding: 1.5rem 1rem 4rem; }
  .lesson, .cover { padding: 1.4rem 1.5rem 1.8rem; }
}

@media print {
  .toc { display: none; }
  .lesson, .cover {
    break-inside: avoid;
    box-shadow: none;
    border-color: #999;
  }
  body { background: #fff; }
}

.cell.accent-a .glyph { color: var(--ink); }
.cell.accent-b .glyph { color: var(--green); }
.cell.accent-c .glyph { color: var(--red); }
.cell.accent-d .glyph { color: var(--blue); }


/* Keep Arabic base+harakat as one unit */
.glyph {
  white-space: nowrap;
  overflow: visible;
  padding-block: 0.35em 0.25em;
  min-height: calc(var(--cell-size) * 1.35);
  line-height: 1.35;
}

.letter-glyph {
  white-space: nowrap;
  overflow: visible;
  padding-block: 0.2em;
}

.cell {
  overflow: visible;
  align-items: center;
  justify-content: center;
}

.letter-grid {
  overflow: visible;
}
