:root {
  --bg: #faf7f0;
  --surface: #ffffff;
  --surface-2: #f2ede1;
  --text: #1f1d1a;
  --muted: #6b655a;
  --border: #e2dccd;
  --accent: #0f6b5c;
  --accent-soft: #dcefe9;
  --ism: #1d5fbf;
  --ism-soft: #e3edfb;
  --fil: #1e7d3a;
  --fil-soft: #e1f3e6;
  --harf: #b5401f;
  --harf-soft: #fbe7e0;
  --hl: #fff1b8;
  --warn-bg: #fff4d6;
  --warn-text: #7a5200;
  --radius: 12px;
  --ar: "Noto Naskh Arabic", "Amiri", serif;
  --quran: "Amiri Quran", "Noto Naskh Arabic", serif;
  --ur: "Noto Nastaliq Urdu", "Jameel Noori Nastaleeq", serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141412; --surface: #1d1d1a; --surface-2: #26251f; --text: #ece8de; --muted: #a39d90;
    --border: #36342c; --accent: #4fc0a8; --accent-soft: #1d3a33;
    --ism: #7fb0ff; --ism-soft: #1c2a40; --fil: #6fd18b; --fil-soft: #1b3323;
    --harf: #ff9a7a; --harf-soft: #3d2219; --hl: #4a4115; --warn-bg: #3a2f12; --warn-text: #f3cf7a;
  }
}
:root[data-theme="dark"] {
  --bg: #141412; --surface: #1d1d1a; --surface-2: #26251f; --text: #ece8de; --muted: #a39d90;
  --border: #36342c; --accent: #4fc0a8; --accent-soft: #1d3a33;
  --ism: #7fb0ff; --ism-soft: #1c2a40; --fil: #6fd18b; --fil-soft: #1b3323;
  --harf: #ff9a7a; --harf-soft: #3d2219; --hl: #4a4115; --warn-bg: #3a2f12; --warn-text: #f3cf7a;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--ur); font-size: 17px; line-height: 2.1;
}
a { color: var(--accent); }
.ar { font-family: var(--ar); line-height: 1.9; }
main { max-width: 1000px; margin: 0 auto; padding: 8px 16px 48px; }

.site-header {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 1000px; margin: 0 auto; padding: 12px 16px;
}
.brand { text-decoration: none; color: var(--text); display: flex; align-items: baseline; gap: 10px; }
.brand-ur { font-size: 1.5rem; font-weight: 600; }
.brand-en { font-family: system-ui, sans-serif; font-size: .85rem; color: var(--muted); line-height: 1; }
.icon-btn {
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  border-radius: 999px; width: 40px; height: 40px; font-size: 1.1rem; cursor: pointer;
}
.site-footer { max-width: 1000px; margin: 0 auto; padding: 16px; color: var(--muted); font-size: .85rem; border-top: 1px solid var(--border); }
.site-footer p { margin: 4px 0; }

/* Home */
.hero { padding: 16px 0 8px; }
.hero h1 { font-family: var(--quran); font-size: 2.4rem; font-weight: 400; margin: 0; line-height: 1.8; }
.hero p { color: var(--muted); margin: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin: 16px 0 24px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; text-decoration: none; color: var(--text); display: block;
}
a.card:hover { border-color: var(--accent); }
.card .label { font-size: .8rem; color: var(--accent); }
.card .ayah-mini { font-family: var(--quran); font-size: 1.3rem; line-height: 1.9; }
.badge { display: inline-block; font-size: .72rem; padding: 0 8px; border-radius: 999px; background: var(--warn-bg); color: var(--warn-text); }
h2 { font-size: 1.25rem; font-weight: 600; margin: 24px 0 4px; }
.how { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 20px; }
.how ol { margin: 0; padding-inline-start: 20px; }

/* Lesson */
.crumbs { font-size: .85rem; color: var(--muted); }
.crumbs a { text-decoration: none; }
.ayah-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 18px; margin: 8px 0 12px; text-align: center;
}
.ayah-text { font-family: var(--quran); font-size: 2rem; line-height: 2.2; }
.ayah-num { font-family: var(--ar); font-size: 1rem; color: var(--accent); margin: 0 4px; }
.draft { background: var(--warn-bg); color: var(--warn-text); border-radius: 8px; padding: 4px 12px; font-size: .88rem; margin: 8px 0; }

.tabs { display: flex; gap: 6px; overflow-x: auto; border-bottom: 1px solid var(--border); margin: 8px 0 16px; }
.tab {
  background: none; border: 0; border-bottom: 3px solid transparent; color: var(--muted);
  font-family: var(--ur); font-size: 1rem; padding: 4px 12px 8px; cursor: pointer; white-space: nowrap;
}
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.hint { color: var(--muted); font-size: .9rem; margin: 0 0 8px; }

.translation { display: flex; flex-wrap: wrap; gap: 4px 6px; font-size: 1.15rem; }
.chunk {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 0 10px;
  cursor: pointer; font-family: var(--ur); font-size: 1.05rem; color: var(--text);
}
.chunk.on { background: var(--hl); border-color: var(--accent); }

.tokens { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.tok {
  font-family: var(--ar); font-size: 1.6rem; line-height: 1.6; padding: 4px 14px;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
}
.tok.ism { border-bottom: 4px solid var(--ism); }
.tok.fil { border-bottom: 4px solid var(--fil); }
.tok.harf { border-bottom: 4px solid var(--harf); }
.tok.on { background: var(--hl); }
.tok.sel { outline: 3px solid var(--accent); }

.legend { display: flex; gap: 14px; font-size: .85rem; color: var(--muted); flex-wrap: wrap; }
.legend span::before { content: ""; display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-inline-end: 6px; vertical-align: middle; }
.legend .l-ism::before { background: var(--ism); }
.legend .l-fil::before { background: var(--fil); }
.legend .l-harf::before { background: var(--harf); }

.word-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 18px; }
.word-card .big { font-family: var(--ar); font-size: 2.4rem; line-height: 1.6; }
.pill { display: inline-block; padding: 0 12px; border-radius: 999px; font-size: .9rem; }
.pill.ism { background: var(--ism-soft); color: var(--ism); }
.pill.fil { background: var(--fil-soft); color: var(--fil); }
.pill.harf { background: var(--harf-soft); color: var(--harf); }
dl.feats { display: grid; grid-template-columns: max-content 1fr; gap: 0 16px; margin: 8px 0; }
dl.feats dt { color: var(--muted); }
dl.feats dd { margin: 0; }
.role { font-weight: 600; color: var(--accent); }
.note { background: var(--surface-2); border-radius: 8px; padding: 4px 12px; margin-top: 8px; }

/* Tree */
.tree-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.tree { display: grid; gap: 4px 6px; min-width: max-content; }
.tree .t-word { font-family: var(--ar); font-size: 1.45rem; text-align: center; padding: 0 6px; line-height: 1.6; }
.tree-caption { font-weight: 600; color: var(--accent); margin-bottom: 4px; }
.tree .t-type, .tree .t-role { animation: pop .35s ease; display: flex; flex-direction: column; align-items: center; }
.tree .t-layer {
  align-self: start; margin-top: 10px; padding: 0 10px; border-radius: 999px; white-space: nowrap;
  background: var(--accent-soft); color: var(--accent); font-size: .78rem; font-weight: 600; line-height: 1.9;
  animation: pop .35s ease;
}
.tree .t-word { padding-inline: 10px; }
.l1-main { font-weight: 700; }
.l1-sub { font-weight: 400; color: var(--text); font-size: 1em; line-height: 2; }
.l1-sub::before { content: ""; display: block; width: 10px; height: 1px; background: var(--muted); margin: 0 auto; }
.word-card .l1-sub::before { display: none; }
.word-card .l1-sub { font-size: 1em; }
.l1-add { text-decoration: underline dotted var(--muted); text-underline-offset: 6px; opacity: .85; }
.tree-key { font-size: .78rem; color: var(--muted); margin: 8px 0 0; }
.vline { display: block; width: 2px; height: 26px; background: var(--muted); margin-bottom: 2px; }
.vline.short { height: 14px; }
.gif { max-width: 100%; border: 1px solid var(--border); border-radius: var(--radius); display: block; }
.tree .t-type { text-align: center; font-size: .9rem; font-weight: 600; line-height: 1.6; }
.tree .t-type.ism { color: var(--ism); } .tree .t-type.fil { color: var(--fil); } .tree .t-type.harf { color: var(--harf); }
.tree .t-role { text-align: center; font-size: .9rem; font-weight: 600; color: var(--text); line-height: 1.9; max-width: 140px; justify-self: center; }
.bracket { text-align: center; margin-top: 4px; animation: pop .35s ease; min-width: 0; }
.bracket .b-label { display: block; white-space: normal; overflow-wrap: break-word; }
.bracket .line { border: 2px solid var(--accent); border-top: 0; border-radius: 0 0 10px 10px; height: 12px; margin: 0 6px; }
.bracket .b-label { font-size: .82rem; line-height: 1.9; padding: 0 4px; }
@keyframes pop { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.controls { display: flex; gap: 8px; margin: 12px 0; flex-wrap: wrap; align-items: center; }
.btn {
  font-family: var(--ur); font-size: .95rem; padding: 2px 16px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--accent); background: var(--accent); color: #fff;
}
.btn { color: var(--bg); text-decoration: none; }
.header-btns { display: flex; gap: 8px; align-items: center; }
.pill-btn { font-family: var(--ur); font-size: .9rem; padding: 0 14px; height: 40px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; }
.pill-btn[aria-pressed="true"] { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.card .date { font-size: .78rem; color: var(--muted); }
.alert { background: var(--warn-bg); color: var(--warn-text); border-inline-start: 4px solid var(--warn-text); border-radius: 8px; padding: 6px 14px; margin: 8px 0; }
.alert .ar { font-size: 1.15em; }

/* Class mode: large text for a projector */
body.class-mode { font-size: 22px; }
body.class-mode main, body.class-mode .site-header { max-width: 1400px; }
body.class-mode .ayah-text { font-size: 3rem; }
body.class-mode .tok { font-size: 2.2rem; }
body.class-mode .tree .t-word { font-size: 2.1rem; }
body.class-mode .tree .t-type { font-size: 1rem; }
body.class-mode .tree .t-layer { font-size: .9rem; }
body.class-mode .tree .t-role { font-size: .95rem; max-width: 180px; }
body.class-mode .bracket .b-label { font-size: 1rem; }
body.class-mode .word-card .big { font-size: 3.4rem; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn:disabled { opacity: .4; cursor: default; }
.step-count { color: var(--muted); font-size: .9rem; }

/* Concepts */
.concepts { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; margin-top: 16px; }
details.concept { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 16px; }
details.concept summary { cursor: pointer; font-weight: 600; }
details.concept table { border-collapse: collapse; width: 100%; font-size: .9rem; }
details.concept th, details.concept td { border: 1px solid var(--border); padding: 0 8px; text-align: center; }
details.concept td.ar { font-size: 1.1rem; }

/* Practice */
.q { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 16px; margin-bottom: 10px; display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; }
.q .qw { font-family: var(--ar); font-size: 1.6rem; min-width: 110px; text-align: center; }
.choice { font-family: var(--ur); font-size: .95rem; padding: 0 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); cursor: pointer; }
.choice.right { background: var(--fil-soft); border-color: var(--fil); color: var(--fil); }
.choice.wrong { background: var(--harf-soft); border-color: var(--harf); color: var(--harf); }
select { font-family: var(--ur); font-size: .95rem; padding: 2px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); max-width: 100%; }
.score { font-weight: 600; color: var(--accent); }
.mark { font-size: .9rem; }

@media (max-width: 600px) {
  body { font-size: 16px; }
  .ayah-text { font-size: 1.6rem; }
  .hero h1 { font-size: 1.9rem; }
  .tok { font-size: 1.35rem; padding: 2px 10px; }
}
