/* ==========================================================================
   Qalam & Kitab design system: readability layer (Bookstore Styling v1.4.0)
   Printed last in <head> (priority 150), after the responsive layer, so it
   wins over the theme's Additional CSS and the Qalam plugin stylesheets.

   One goal: every block a student reads is easy to read on a phone first.
     - Body text 17px on phones, 18px on desktop, line height 1.7+.
     - Secondary text never below 15px; labels never below 13px.
     - Headings step down clearly (more space above than below).
     - About 65-72 characters per line.
     - Numbers line up (tabular figures) in tables, dates and fees.
     - Every tap target 44px or more.

   Designed blocks (home page, .qk-section, pg-*, zw-*, Elementor layouts,
   the Print Studio, Dashboard, shop) are left alone: rules below are scoped
   to single articles and to the content blocks named in each section.
   Off switch: add_filter( 'qbs_readable', '__return_false' );
   ========================================================================== */

:root {
  --qbr-text: 1.0625rem;          /* 17px body on phones */
  --qbr-text-lg: 1.125rem;        /* 18px body from 768px */
  --qbr-small: .9375rem;          /* 15px: notes, captions, sources */
  --qbr-label: .8125rem;          /* 13px: uppercase labels and chips */
  --qbr-lh: 1.72;
  --qbr-lh-tight: 1.3;
  --qbr-ink: var(--qk2-ink,#1E293B);
  --qbr-body: #2f3d37;            /* 11.2:1 on white */
  --qbr-muted: #4f5f58;           /* 6.6:1 on white (was var(--qk2-mute,#64748B), 5.6:1) */
  --qbr-line: #dfe7e2;
  --qbr-green: var(--qk2-pri,#4A7C59);
  --qbr-green-d: var(--qk2-pri-d,#3B6648);
  --qbr-measure: 70ch;
}
@media (min-width: 768px) {
  :root { --qbr-text: var(--qbr-text-lg); }
}

/* Single articles where the rules apply. */
/* (written out in each selector as body:is(...) so specificity beats Additional CSS) */

/* ---------- 1. Body text ---------- */
body:is(.single-post, .single-qcm_challenge, .single-qcm_solution, .single-qcm_book, .single-qsp_read, .page:not(.home)) .entry-content :is(p, li, dd, td, th, blockquote, figcaption):not([class*="qk-section"]) {
  overflow-wrap: break-word;
  hyphens: manual;
}
body:is(.single-post, .single-qcm_challenge, .single-qcm_solution, .single-qsp_read) .entry-content,
body:is(.single-qcm_challenge, .single-qcm_solution) .qk-note {
  font-size: var(--qbr-text);
  line-height: var(--qbr-lh);
  color: var(--qbr-body);
}
body:is(.single-post, .single-qcm_challenge, .single-qcm_solution, .single-qsp_read) .entry-content p:not([class]),
body:is(.single-qcm_challenge, .single-qcm_solution) .qk-note p:not([class]) {
  margin: 0 0 1.05em;
  font-size: inherit;
  line-height: var(--qbr-lh);
  text-wrap: pretty;
}
body:is(.single-post, .single-qcm_challenge, .single-qcm_solution, .single-qsp_read) .entry-content :is(p, li) > strong:first-child {
  color: var(--qbr-ink);
}
body:is(.single-post, .single-qcm_challenge, .single-qcm_solution, .single-qsp_read) .entry-content :is(strong, b) {
  font-weight: 700;
}
body:is(.single-post, .single-qcm_challenge, .single-qcm_solution, .single-qsp_read) .entry-content em {
  font-style: italic;
}
/* Comfortable line length on wide screens. Cards and tables keep their own width. */
@media (min-width: 1025px) {
  body:is(.single-post, .single-qcm_challenge, .single-qcm_solution, .single-qsp_read) .entry-content > :is(p, ul, ol, h2, h3, h4):not([class]),
  body:is(.single-qcm_challenge, .single-qcm_solution) .qbs-card__body > :is(p, ul, ol):not([class]) {
    max-width: var(--qbr-measure);
  }
}

/* ---------- 2. Headings: a clear ladder ---------- */
body:is(.single-post, .single-qcm_challenge, .single-qcm_solution, .single-qsp_read) .entry-content :is(h2, h3, h4):not([class]),
body:is(.single-qcm_challenge, .single-qcm_solution) .qk-note :is(h2, h3, h4) {
  color: var(--qbr-ink);
  line-height: var(--qbr-lh-tight);
  letter-spacing: -.01em;
  text-wrap: balance;
  scroll-margin-top: 110px;
}
body:is(.single-post, .single-qcm_challenge, .single-qcm_solution, .single-qsp_read) .entry-content h2:not([class]),
body:is(.single-qcm_challenge, .single-qcm_solution) .qk-note h2 {
  font-size: clamp(1.35rem, 1.1rem + 1.2vw, 1.65rem);
  margin: 2.1em 0 .65em;
}
body:is(.single-post, .single-qcm_challenge, .single-qcm_solution, .single-qsp_read) .entry-content h3:not([class]),
body:is(.single-qcm_challenge, .single-qcm_solution) .qk-note h3 {
  font-size: clamp(1.15rem, 1.02rem + .6vw, 1.3rem);
  font-weight: 700;
  color: var(--qbr-green-d);
  margin: 1.7em 0 .5em;
}
body:is(.single-post, .single-qcm_challenge, .single-qcm_solution, .single-qsp_read) .entry-content h4:not([class]),
body:is(.single-qcm_challenge, .single-qcm_solution) .qk-note h4:not([class]) {
  font-size: 1.08rem;
  font-weight: 700;
  margin: 1.4em 0 .4em;
}
/* A heading straight after a heading needs less space. */
body:is(.single-qcm_challenge, .single-qcm_solution) :is(.entry-content, .qk-note) :is(h2, h3) + :is(h3, h4) { margin-top: .6em; }
/* First heading in a card or note sits at the top. */
body:is(.single-qcm_challenge, .single-qcm_solution) :is(.qbs-card__body, .qk-note) > :is(h2, h3):first-child { margin-top: 0; }

/* ---------- 3. Links in running text ---------- */
body:is(.single-post, .single-qcm_challenge, .single-qcm_solution, .single-qsp_read) .entry-content :is(p, li, td, dd) a:not([class]) {
  color: var(--qbr-green);
  font-weight: 600;
  text-decoration: underline;
  text-decoration-thickness: 1.5px;
  text-decoration-color: rgba(74, 124, 89, .4);
  text-underline-offset: 3px;
  overflow-wrap: anywhere;            /* long portal addresses wrap instead of overflowing */
}
body:is(.single-post, .single-qcm_challenge, .single-qcm_solution, .single-qsp_read) .entry-content :is(p, li, td, dd) a:not([class]):hover {
  color: var(--qbr-green-d);
  text-decoration-color: currentColor;
}

/* ---------- 4. Plain lists ---------- */
body:is(.single-post, .single-qcm_challenge, .single-qcm_solution, .single-qsp_read) .entry-content :is(ul, ol):not([class]),
body:is(.single-qcm_challenge, .single-qcm_solution) .qk-note :is(ul, ol):not([class]) {
  margin: 0 0 1.2em;
}
body:is(.single-post, .single-qcm_challenge, .single-qcm_solution, .single-qsp_read) .entry-content :is(ul, ol):not([class]) > li,
body:is(.single-qcm_challenge, .single-qcm_solution) .qk-note :is(ul, ol):not([class]) > li {
  margin: 0 0 .55em;
  padding-inline-start: .25em;
  font-size: inherit;
  line-height: 1.65;
}
body:is(.single-post, .single-qcm_challenge, .single-qcm_solution, .single-qsp_read) .entry-content :is(ul, ol):not([class]) > li:last-child { margin-bottom: 0; }
body:is(.single-post, .single-qcm_challenge, .single-qcm_solution, .single-qsp_read) .entry-content ol:not([class]) > li::marker {
  font-variant-numeric: tabular-nums;
}
/* A list right after a lead-in sentence ("Stories that work well:") stays close to it. */
body:is(.single-qcm_challenge, .single-qcm_solution) :is(.entry-content, .qk-note) p:not([class]) + :is(ul, ol):not([class]) { margin-top: -.35em; }

/* ---------- 5. Tables (plain, Quick Notes, and the green "Take action now" box) ---------- */
body:is(.single-post, .single-qcm_challenge, .single-qcm_solution, .single-qsp_read, .single-qcm_book) .entry-content table:is(:not([class]), .qk-note-table) {
  font-size: var(--qbr-small);
  line-height: 1.55;
  font-variant-numeric: tabular-nums;
}
body:is(.single-post, .single-qcm_challenge, .single-qcm_solution, .single-qsp_read, .single-qcm_book) .entry-content table:is(:not([class]), .qk-note-table) :is(th, td) {
  padding: .75em .9em;
  vertical-align: top;
}
body:is(.single-post, .single-qcm_challenge, .single-qcm_solution, .single-qsp_read, .single-qcm_book) .entry-content table:is(:not([class]), .qk-note-table) td {
  color: var(--qbr-body);
}
body:is(.single-post, .single-qcm_challenge, .single-qcm_solution, .single-qsp_read, .single-qcm_book) .entry-content table:is(:not([class]), .qk-note-table) th {
  font-weight: 700;
  line-height: 1.35;
  letter-spacing: .01em;
}
/* First column names the row: make it stand out a little. */
body:is(.single-qcm_challenge, .single-qcm_solution) .entry-content table:is(:not([class]), .qk-note-table) tbody td:first-child {
  font-weight: 600;
  color: var(--qbr-ink);
}
/* Phones: the base layer already lets tables scroll sideways; give cells a readable minimum width. */
@media (max-width: 640px) {
  body:is(.single-post, .single-qcm_challenge, .single-qcm_solution, .single-qsp_read, .single-qcm_book) .entry-content table:is(:not([class]), .qk-note-table) :is(th, td) {
    min-width: 8.5rem;
    padding: .7em .8em;
  }
}

/* The green "Take action now" box at the top of roadmaps (.qk-action-box, inline styles). */
body:is(.single-qcm_challenge, .single-qcm_solution) .qk-action-box {
  font-size: var(--qbr-small);
  line-height: 1.6;
}
body:is(.single-qcm_challenge, .single-qcm_solution) .qk-action-box > p:first-child {
  font-size: var(--qbr-text);
  line-height: 1.45;
  color: var(--qbr-ink);
}
body:is(.single-qcm_challenge, .single-qcm_solution) .qk-action-box table {
  width: 100%;
  margin: .9em 0;
  border-collapse: collapse;
  background: #fff;
  border-radius: 10px;
}
body:is(.single-qcm_challenge, .single-qcm_solution) .qk-action-box :is(th, td) {
  padding: .65em .75em;
  border-top: 1px solid #d5e8dc;
  vertical-align: top;
}
body:is(.single-qcm_challenge, .single-qcm_solution) .qk-action-box tr:first-child :is(th, td) { border-top: 0; }
body:is(.single-qcm_challenge, .single-qcm_solution) .qk-action-box tbody tr td { background: transparent !important; }
body:is(.single-qcm_challenge, .single-qcm_solution) .qk-action-box table:not(:has(thead)) td:first-child { width: 32%; }
/* Phones: two-column "label | value" tables in the box stack, so the value gets the full width. */
@media (max-width: 600px) {
  body:is(.single-qcm_challenge, .single-qcm_solution) .qk-action-box table:not(:has(thead)) :is(tr, td) {
    display: block;
    width: auto;
  }
  body:is(.single-qcm_challenge, .single-qcm_solution) .qk-action-box table:not(:has(thead)) tr { padding: .55em .2em; border-top: 1px solid #d5e8dc; }
  body:is(.single-qcm_challenge, .single-qcm_solution) .qk-action-box table:not(:has(thead)) tr:first-child { border-top: 0; }
  body:is(.single-qcm_challenge, .single-qcm_solution) .qk-action-box table:not(:has(thead)) td { min-width: 0 !important; padding: .1em .55em !important; border: 0; }
  body:is(.single-qcm_challenge, .single-qcm_solution) .qk-action-box table:not(:has(thead)) td:first-child { width: auto; padding-top: .3em !important; color: var(--qbr-green-d); }
  body:is(.single-qcm_challenge, .single-qcm_solution) .qk-action-box table:has(thead) { display: block; overflow-x: auto; }
  body:is(.single-qcm_challenge, .single-qcm_solution) .qk-action-box table:has(thead) :is(th, td) { min-width: 8.5rem; }
}

/* ---------- 6. Quick Notes callouts (meta, goal, tip, avoid, done, byline) ---------- */
body:is(.single-qcm_challenge, .single-qcm_solution) :is(.qk-note-meta, .qk-note-goal, .qk-note-tip, .qk-note-mistake, .qk-note-done) {
  font-size: var(--qbr-small);
  line-height: 1.65;
  color: var(--qbr-body);
  padding: 1em 1.15em;
  margin: 0 0 1.5em;
  border-radius: 10px;
}
@media (min-width: 768px) {
  body:is(.single-qcm_challenge, .single-qcm_solution) :is(.qk-note-tip, .qk-note-mistake, .qk-note-goal) { font-size: 1rem; }
}
body:is(.single-qcm_challenge, .single-qcm_solution) .qk-note-meta p { margin: 0 0 .6em; }
body:is(.single-qcm_challenge, .single-qcm_solution) .qk-note-meta p:last-child { margin-bottom: 0; }
body:is(.single-qcm_challenge, .single-qcm_solution) .qk-note-meta a { overflow-wrap: anywhere; }
/* "On this page" jump links: one per line on phones, easy to tap. */
@media (max-width: 600px) {
  body:is(.single-qcm_challenge, .single-qcm_solution) .qk-note-meta p:last-child a {
    display: inline-flex;
    align-items: center;
    min-height: 40px;
  }
}
/* Goal and Done lines (older pages still have them): calm, not loud. */
body:is(.single-qcm_challenge, .single-qcm_solution) .qk-note-goal {
  background: #f3f8f5;
  border-inline-start: 4px solid var(--qbr-green);
}
body:is(.single-qcm_challenge, .single-qcm_solution) .qk-note-done {
  background: #fff;
  border: 1px dashed #b9d7c4;
  color: var(--qbr-muted);
}
body:is(.single-qcm_challenge, .single-qcm_solution) :is(.qk-note-tip, .qk-note-mistake, .qk-note-goal, .qk-note-done) > strong:first-child {
  margin-inline-end: .2em;
}
body:is(.single-qcm_challenge, .single-qcm_solution) .qk-note-mistake strong { color: #9b2419; }
body:is(.single-qcm_challenge, .single-qcm_solution) .qk-note-tip strong { color: #7a5212; }
body:is(.single-qcm_challenge, .single-qcm_solution) .qk-note-byline {
  font-size: var(--qbr-small);
  color: var(--qbr-muted);
  line-height: 1.6;
}

/* ---------- 7. Checklists ---------- */
body:is(.single-qcm_challenge, .single-qcm_solution) ul.qk-note-checklist > li {
  margin: 0 0 .7em;
  padding-inline-start: 2.1rem;
  line-height: 1.6;
}
body:is(.single-qcm_challenge, .single-qcm_solution) ul.qk-note-checklist > li::before {
  top: .2em;
  width: 1.2rem;
  height: 1.2rem;
}

/* ---------- 8. Fold-out sections (Evidence, Sources, How it changed) ---------- */
body:is(.single-qcm_challenge, .single-qcm_solution) details.qk-note-appendix {
  margin: 0 0 .9em;
  border: 1px solid var(--qbr-line);
  border-radius: 12px;
  background: #fff;
  overflow: hidden;
}
body:is(.single-qcm_challenge, .single-qcm_solution) details.qk-note-appendix > summary {
  display: flex;
  align-items: center;
  gap: .6em;
  min-height: 52px;
  padding: .8em 1.1em;
  cursor: pointer;
  font-weight: 700;
  font-size: 1rem;
  line-height: 1.35;
  color: var(--qbr-ink);
  list-style: none;
}
body:is(.single-qcm_challenge, .single-qcm_solution) details.qk-note-appendix > summary::-webkit-details-marker { display: none; }
body:is(.single-qcm_challenge, .single-qcm_solution) details.qk-note-appendix > summary::before {
  content: "+";
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--qk2-pri-l,#E7F0E9);
  color: var(--qbr-green);
  font-weight: 800;
}
body:is(.single-qcm_challenge, .single-qcm_solution) details.qk-note-appendix[open] > summary { border-bottom: 1px solid var(--qbr-line); }
body:is(.single-qcm_challenge, .single-qcm_solution) details.qk-note-appendix[open] > summary::before { content: "\2212"; background: var(--qbr-green); color: #fff; }
body:is(.single-qcm_challenge, .single-qcm_solution) details.qk-note-appendix > :not(summary) { margin-inline: 1.1em; }
body:is(.single-qcm_challenge, .single-qcm_solution) details.qk-note-appendix > :not(summary):first-of-type { margin-top: 1em; }
body:is(.single-qcm_challenge, .single-qcm_solution) details.qk-note-appendix > :last-child { margin-bottom: 1.1em; }

/* ---------- 9. Sources and references ---------- */
body:is(.single-post, .single-qcm_challenge, .single-qcm_solution, .single-qsp_read) ol.qk-note-sources {
  font-size: var(--qbr-small);
  line-height: 1.6;
  color: var(--qbr-muted);
}
body:is(.single-post, .single-qcm_challenge, .single-qcm_solution, .single-qsp_read) ol.qk-note-sources > li { margin: 0 0 .65em; }
body:is(.single-post, .single-qcm_challenge, .single-qcm_solution, .single-qsp_read) ol.qk-note-sources a { overflow-wrap: anywhere; font-weight: 600; }

/* ---------- 10. Description blocks (.qk-desc), moved here from Additional CSS ---------- */
.qk-desc { display: grid; gap: 14px; margin: 0 0 1.75rem; padding: 0; list-style: none; }
.qk-desc__item {
  background: #fff;
  border: 1px solid #e3e8e4;
  border-inline-start: 4px solid var(--qbr-green);
  border-radius: 10px;
  padding: 14px 16px;
}
.entry-content .qk-desc .qk-desc__title,
.qk-desc .qk-desc__title {
  margin: 0 0 6px !important;
  font-size: clamp(1.08rem, 1rem + .35vw, 1.2rem) !important;
  font-weight: 700;
  line-height: 1.35;
  color: var(--qbr-green-d);
  text-wrap: balance;
}
.qk-desc__item p { margin: 0; font-size: var(--qbr-text); line-height: 1.68; color: var(--qbr-body); }
.qk-desc__item p + p { margin-top: 8px; }
.entry-content .qk-desc .qk-desc__item > p { margin-top: 0 !important; margin-bottom: 0 !important; }
.entry-content .qk-desc .qk-desc__item > p + p { margin-top: 8px !important; }
@media (max-width: 600px) { .qk-desc__item { padding: 12px 14px; } }

/* ---------- 11. Section cards and their lists (Bookstore Styling cards) ---------- */
.qbs-card__body p { font-size: var(--qbr-text); line-height: var(--qbr-lh); color: var(--qbr-body); }
.qbs-card__body h3 { font-size: clamp(1.12rem, 1rem + .5vw, 1.25rem); line-height: var(--qbr-lh-tight); margin: 1.4em 0 .5em; }
.qbs-card li { line-height: 1.65; }
.qbs-steps > li { padding-top: 5px; line-height: 1.65; }
.qbs-dots > li { margin-bottom: .65em; line-height: 1.65; }
.qbs-checks > li { line-height: 1.6; }
.qbs-bubbles > li { line-height: 1.55; }
.qbs-refs > li { padding-top: 10px; padding-bottom: 10px; font-size: var(--qbr-small); line-height: 1.6; }
.qbs-refs > li a { overflow-wrap: anywhere; }
.qbs-facts__k { font-size: var(--qbr-label); letter-spacing: .06em; }
.qbs-facts__v { font-size: 1rem; line-height: 1.55; font-variant-numeric: tabular-nums; }
.qbs-links__desc { font-size: var(--qbr-small); line-height: 1.55; color: var(--qbr-muted); }
.qbs-note__k { font-size: var(--qbr-label); }
.qbs-note p { font-size: var(--qbr-text); line-height: 1.68; }

/* ---------- 12. FAQ accordions ---------- */
.qbs-faq__q { font-size: 1.03rem; line-height: 1.45; }
.qbs-faq__a { padding: 2px 18px 16px; }
.qbs-faq__a p { font-size: var(--qbr-text); line-height: 1.7; color: var(--qbr-body); }

/* ---------- 13. Key dates and resources (Qalam Solution Types) ---------- */
.qst-dates { font-variant-numeric: tabular-nums; }
.qst-date__when { letter-spacing: -.005em; }
.qst-res__by { font-size: .875rem; color: var(--qbr-muted); }
.qst-res__item a { overflow-wrap: anywhere; }

/* ---------- 14. Blockquotes, code, highlights ---------- */
body:is(.single-post, .single-qcm_challenge, .single-qcm_solution, .single-qsp_read) .entry-content blockquote:not([class]) p {
  font-size: var(--qbr-text);
  line-height: 1.7;
  margin-bottom: .6em;
}
body:is(.single-post, .single-qcm_challenge, .single-qcm_solution, .single-qsp_read) .entry-content :is(code, kbd):not([class]) {
  padding: .1em .35em;
  border-radius: 5px;
  background: #eef3f0;
  color: var(--qbr-ink);
  font-size: .9em;
  overflow-wrap: anywhere;
}
body:is(.single-post, .single-qcm_challenge, .single-qcm_solution, .single-qsp_read) .entry-content mark {
  padding: 0 .2em;
  border-radius: 3px;
  background: #fff1c7;
  color: var(--qbr-ink);
}

/* ---------- 15. Urdu text: Nastaliq needs room ---------- */
.entry-content :is([lang="ur"], [lang="ur-PK"], .qk-urdu, .urdu),
.entry-content [dir="rtl"] :is(p, li) {
  font-size: 1.12em;
  line-height: 2.15;
  word-spacing: .05em;
}
.entry-content :is([lang="ur"], [lang="ur-PK"]) :is(h2, h3) { line-height: 1.8; }

/* ---------- 16. Phones: a little more room, a little less clutter ---------- */
@media (max-width: 600px) {
  body:is(.single-qcm_challenge, .single-qcm_solution) .qbs-card { padding: 18px 16px; border-radius: 16px; }
  body:is(.single-qcm_challenge, .single-qcm_solution) .qk-note h2 { margin-top: 1.8em; }
  body:is(.single-post, .single-qcm_challenge, .single-qcm_solution, .single-qsp_read) .entry-content :is(ul, ol):not([class]) > li { margin-bottom: .6em; }
}

/* ---------- 17. Higher contrast when the device asks for it ---------- */
@media (prefers-contrast: more) {
  :root { --qbr-body: var(--qk2-ink,#1E293B); --qbr-muted: var(--qk2-body,#334155); --qbr-line: #9fb3a8; }
  .qk-desc__item, .qbs-card, .qst-dates, details.qk-note-appendix { border-color: #7d958a; }
}

/* ---------- 18. Print: black text, no tinted boxes ---------- */
@media print {
  body:is(.single-qcm_challenge, .single-qcm_solution) :is(.entry-content, .qk-note) { font-size: 11.5pt; line-height: 1.5; color: #000; }
  .qk-desc__item, .qk-note-goal, .qk-note-done, details.qk-note-appendix { background: #fff !important; border-color: #999 !important; break-inside: avoid; }
  details.qk-note-appendix > :not(summary) { display: block !important; }
}

/* ===== end readability layer ===== */
