/* Bayt Al-Fuad · Semester 1 study library — one consolidated stylesheet.
   Academic reading style: warm near-white page, white reading surfaces, navy actions,
   modest subject accents, serif headings, sans-serif body, Cambria Math for notation.
   Sizes are in rem so they follow the reader's browser text size and zoom. */

:root {
  --page: #f7f7f3; --surface: #ffffff; --ink: #172b3a; --muted: #4d5d69; --line: #d8dee3;
  --action: #203e56; --action-hover: #2c5170; --focus: #203e56;
  --accent: #203e56; --tint: #edf1f4;
  --serif: Georgia, 'Times New Roman', serif; --sans: 'Segoe UI', Arial, sans-serif; --math: 'Cambria Math', Georgia, serif;
  --s1: .25rem; --s2: .5rem; --s3: .75rem; --s4: 1rem; --s5: 1.5rem; --s6: 2rem; --s7: 3rem; --s8: 4rem;
  --radius: 10px; --radius-s: 8px;
  --prose: 1.125rem;
  color-scheme: light;
}
body.math { --accent: #1f655c; --tint: #e8f1ef; }
body.physics { --accent: #365a7d; --tint: #eaf0f5; }
body.chemistry { --accent: #7a552f; --tint: #f5eee6; }
body.english { --accent: #67436c; --tint: #f3edf3; }
.subject-card.math { --accent: #1f655c; --tint: #e8f1ef; }
.subject-card.physics { --accent: #365a7d; --tint: #eaf0f5; }
.subject-card.chemistry { --accent: #7a552f; --tint: #f5eee6; }
.subject-card.english { --accent: #67436c; --tint: #f3edf3; }

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { font-family: var(--sans); color: var(--ink); background: var(--page); -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--page); font-size: 1rem; line-height: 1.65; font-synthesis: none; }
h1, h2, h3, h4 { font-family: var(--serif); font-weight: 700; line-height: 1.25; letter-spacing: 0; color: var(--ink); margin: 0 0 var(--s3); }
h1 { font-size: 2.625rem; }
h2 { font-size: 1.625rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.0625rem; }
p { margin: 0 0 var(--s4); }
li { line-height: 1.7; }
a { color: inherit; text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { color: var(--accent); text-decoration-thickness: 2px; }
a:focus-visible, button:focus-visible, summary:focus-visible, [tabindex]:focus-visible, textarea:focus-visible, select:focus-visible, input:focus-visible {
  outline: 3px solid var(--focus); outline-offset: 3px; border-radius: 2px;
}
img, svg { max-width: 100%; height: auto; }
figure { margin: var(--s5) 0; }
figcaption { font-size: .9375rem; color: var(--muted); line-height: 1.6; margin-top: var(--s3); }
section, article, [id] { scroll-margin-top: var(--s5); }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: fixed; left: var(--s4); top: -6rem; z-index: 20; padding: var(--s3) var(--s4); background: var(--surface); border: 1px solid var(--line); }
.skip:focus { top: var(--s4); }
.muted { color: var(--muted); }
.eyebrow { font-family: var(--sans); font-size: .875rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); margin: 0 0 var(--s2); }
.lead { font-size: 1.1875rem; line-height: 1.7; color: var(--muted); max-width: 44rem; }

/* ---------- mathematics ---------- */
.formula { font-family: var(--math); font-size: 1.1875rem; line-height: 1.8; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-s); padding: var(--s3) var(--s4); overflow-x: auto; overflow-wrap: anywhere; }
.frac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; margin: 0 .15em; font-size: .92em; line-height: 1.25; }
.frac > .num { border-bottom: 1px solid currentColor; padding: 0 .2em; }
.frac > .den { padding: 0 .2em; }
.rad { border-top: 1px solid currentColor; padding-top: .05em; }
sup, sub { line-height: 0; font-size: .75em; }

/* ---------- buttons ---------- */
.button { display: inline-block; background: var(--action); color: #fff; border: 1px solid var(--action); border-radius: var(--radius-s);
  padding: var(--s3) var(--s5); font-family: var(--sans); font-size: 1rem; font-weight: 600; line-height: 1.4; text-decoration: none; text-align: center; }
.button:hover { background: var(--action-hover); border-color: var(--action-hover); color: #fff; text-decoration: none; }
.button:focus-visible { outline-color: var(--action); }

/* ---------- header, footer, page frame ---------- */
.site-header { max-width: 1440px; margin: 0 auto; display: flex; justify-content: space-between; align-items: center; gap: var(--s5); padding: var(--s5) 4%; border-bottom: 1px solid var(--line); }
.brand { font-family: var(--serif); font-size: 1.25rem; font-weight: 700; color: var(--ink); text-decoration: none; }
.brand span { display: block; font-family: var(--sans); font-size: .875rem; font-weight: 400; color: var(--muted); margin-top: var(--s1); }
.brand:hover { color: var(--ink); }
.site-header nav { display: flex; flex-wrap: wrap; gap: var(--s1); }
.site-header nav a { font-size: 1rem; padding: var(--s2) var(--s4); border-radius: var(--radius-s); text-decoration: none; color: var(--ink); }
.site-header nav a:hover { background: var(--tint); color: var(--ink); }
.site-header nav a[aria-current] { background: var(--tint); color: var(--accent); font-weight: 600; box-shadow: inset 0 -2px 0 var(--accent); }
.site-footer { max-width: 1440px; margin: var(--s7) auto 0; display: flex; justify-content: space-between; gap: var(--s5); padding: var(--s5) 4%; border-top: 1px solid var(--line); font-size: .9375rem; color: var(--muted); }
.page { max-width: 1440px; margin: 0 auto; padding: 0 4% var(--s7); }
.reader { max-width: 1440px; margin: 0 auto; padding: 0 4% var(--s7); }
.breadcrumbs { display: flex; flex-wrap: wrap; gap: var(--s2); font-size: .9375rem; color: var(--muted); padding: var(--s5) 0 var(--s4); }
.breadcrumbs a { color: var(--muted); }

/* ---------- entrance ---------- */
.home-hero { padding: var(--s7) 0 var(--s6); max-width: 48rem; }
.home-hero h1 { font-size: 2.75rem; margin-bottom: var(--s4); }
.subject-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s5); align-items: stretch; }
.subject-card { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; transition: border-color .15s; }
.subject-card:hover { border-color: var(--accent); }
.subject-card:focus-within { border-color: var(--accent); }
.subject-art { height: 6rem; display: flex; align-items: center; padding: 0 var(--s5); background: var(--tint); color: var(--accent); font-family: var(--math); font-size: 2.75rem; line-height: 1; border-bottom: 1px solid var(--line); }
.subject-body { display: flex; flex-direction: column; flex: 1; padding: var(--s5); }
.subject-body .eyebrow { margin-bottom: var(--s2); }
.subject-body h2 { font-size: 1.625rem; margin-bottom: var(--s3); }
.subject-body > p:not(.eyebrow) { font-size: 1.0625rem; line-height: 1.6; color: var(--muted); margin: 0 0 var(--s5); }
.subject-body > .button { margin-top: auto; display: block; }
.home-footnote { text-align: center; color: var(--muted); margin: var(--s6) 0 0; }

/* ---------- subject contents ---------- */
.subject-heading { display: flex; justify-content: space-between; align-items: center; gap: var(--s6); padding: var(--s4) 0 var(--s6); }
.subject-heading h1 { margin-bottom: var(--s4); }
.subject-symbol { flex: none; display: flex; align-items: center; justify-content: center; width: 8rem; height: 8rem; border-radius: 50%; background: var(--tint); color: var(--accent); font-family: var(--math); font-size: 2.5rem; white-space: nowrap; }
.topic-section { margin-top: var(--s4); }
.group-title { font-size: 1.25rem; color: var(--accent); margin: var(--s6) 0 var(--s3); }
.topic-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.topic-row { display: grid; grid-template-columns: 2.5rem minmax(0, 1fr); gap: var(--s4); align-items: start; padding: var(--s4) var(--s5); border-bottom: 1px solid var(--line); }
.topic-row:last-child { border-bottom: 0; }
.topic-row:hover { background: var(--tint); }
.topic-row > span { font-family: var(--serif); font-size: 1.125rem; color: var(--accent); padding-top: .1rem; }
.topic-row h3 { font-size: 1.1875rem; margin: 0 0 var(--s1); }
.topic-row h3 a { text-decoration: none; }
.topic-row h3 a:hover { text-decoration: underline; }
.topic-row p { font-size: 1rem; color: var(--muted); margin: 0; max-width: 72ch; }
.tag { display: inline-block; font-style: normal; font-size: .875rem; color: var(--accent); background: var(--tint); border-radius: 4px; padding: 0 var(--s2); margin-left: var(--s1); }
.scope-footer { font-size: 1rem; color: var(--muted); max-width: 72ch; margin-top: var(--s6); }

/* ---------- lesson layout ---------- */
.reader-layout { display: grid; grid-template-columns: 16.5rem minmax(0, 1fr); gap: var(--s7); padding-top: var(--s4); }
.contents { align-self: start; position: sticky; top: var(--s4); max-height: calc(100vh - 2rem); overflow: auto; padding-right: var(--s4); border-right: 1px solid var(--line); }
.contents summary { font-weight: 600; padding: var(--s2) 0; cursor: pointer; }
.contents nav > a, .toc-group > a { display: block; padding: var(--s1) var(--s2); font-size: .9375rem; line-height: 1.5; color: var(--muted); text-decoration: none; border-radius: 6px; }
.contents a:hover { background: var(--tint); color: var(--ink); }
.contents a[aria-current] { background: var(--tint); color: var(--accent); font-weight: 600; }
.toc-group { margin: var(--s5) 0 var(--s4); }
.toc-group .eyebrow { display: block; padding-left: var(--s2); }
.reading-body { min-width: 0; max-width: 54rem; }
.reading-heading { padding: var(--s2) 0 var(--s5); }
.reading-heading h1 { font-size: 2.375rem; margin-bottom: var(--s4); }
.lesson-nav { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s5); font-size: 1rem; }
.reading-section { border-top: 1px solid var(--line); padding: var(--s6) 0 var(--s3); }
.reading-section > h2 { font-size: 1.625rem; margin-bottom: var(--s4); }
.reading-body p, .reading-body li, .reading-body dd { font-size: var(--prose); line-height: 1.75; }
.reading-body p, .reading-body ul, .reading-body ol, .reading-body dl { max-width: 72ch; }
.reading-body .formula, .reading-body figure, .reading-body .table-wrap { max-width: none; }
.reading-body ul, .reading-body ol { padding-left: 1.4rem; }
.background-item { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s4) var(--s5); margin: var(--s4) 0; }
.background-item h3 { font-size: 1.125rem; margin-bottom: var(--s2); }
.background-item p:last-child { margin-bottom: 0; }

/* figures and tables */
.concept-figure { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s4); }
.concept-figure svg { display: block; width: 100%; height: auto; }
.table-wrap { overflow-x: auto; margin: var(--s5) 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-s); }
table { border-collapse: collapse; width: 100%; font-size: 1rem; line-height: 1.6; }
caption { text-align: left; padding: var(--s3) var(--s4); font-weight: 600; font-family: var(--serif); }
th, td { padding: var(--s3) var(--s4); border-top: 1px solid var(--line); text-align: left; vertical-align: top; }
thead th { background: var(--tint); }
.table-note { font-size: .9375rem !important; color: var(--muted); }

/* terms, formulas, derivations */
.definitions > div, .language-pattern > div { padding: var(--s3) 0; border-bottom: 1px solid var(--line); }
.definitions > div:last-child, .language-pattern > div:last-child { border-bottom: 0; }
dt { font-weight: 700; margin-bottom: var(--s1); }
dd { margin: 0; }
.formula-list > article { margin: var(--s4) 0 var(--s5); }
.formula-list h3 { font-size: 1.125rem; margin-bottom: var(--s2); }
.conditions { color: var(--muted); }
.derivation, .method { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s4) var(--s5); margin: var(--s5) 0; }
.derivation h3, .method h3 { font-size: 1.1875rem; }
.formula-compact { list-style: none; padding: 0 !important; }
.formula-compact li { margin: var(--s3) 0; }
.formula-compact .formula { display: block; }
.formula-compact .muted { display: block; font-size: .9375rem; margin-top: var(--s1); }

/* worked examples */
.worked-example { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s5); margin: var(--s5) 0; }
.worked-example h3 { font-size: 1.25rem; }
.worked-steps { padding-left: 1.4rem; }
.worked-steps li { padding: var(--s1) 0 var(--s2); }
.worked-steps p { margin: var(--s1) 0; }
.reason { color: var(--muted); font-size: 1rem !important; }
.result { border-top: 1px solid var(--line); padding-top: var(--s3); }
.meaning { color: var(--muted); }
.mistakes { list-style: none; padding: 0 !important; }
.mistakes > li { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s4) var(--s5); margin: var(--s3) 0; }
.mistakes .wrong { margin-bottom: var(--s2); }
.mistakes > li p:last-child { margin-bottom: 0; }
details.extra { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s3) var(--s5); margin: var(--s4) 0; }
details.extra summary { cursor: pointer; font-weight: 600; padding: var(--s2) 0; }
.lesson-sources { font-size: 1rem !important; color: var(--muted); margin-top: var(--s6); }
.moved-note { border-left: 3px solid var(--accent); padding-left: var(--s4); color: var(--muted); }
.next-topic { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s4) var(--s5); margin: var(--s6) 0; }

/* English language lessons */
.model-text { margin: var(--s4) 0; }
.model-text figcaption { font-size: .875rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); margin: 0 0 var(--s2); }
.model-text blockquote { margin: 0; padding: var(--s4) var(--s5); background: var(--tint); border-left: 4px solid var(--accent); border-radius: 0 var(--radius-s) var(--radius-s) 0; font-family: var(--serif); overflow-wrap: anywhere; }
.model-text blockquote p { margin: 0 0 var(--s3); }
.model-text blockquote p:last-child { margin-bottom: 0; }
.language-example h4 { font-size: 1.0625rem; margin: var(--s4) 0 var(--s1); }
.annotations li { margin: var(--s1) 0; }
.language-pattern { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s2) var(--s5); }
.draft-text { background: #fbeeea; border-bottom: 2px dotted #a13b2a; padding: 0 .2em; }
.media-note { border-left: 3px solid var(--accent); background: var(--tint); padding: var(--s3) var(--s4); border-radius: 0 var(--radius-s) var(--radius-s) 0; }

/* sources and old-link pages */
.source-list, .compat-list { list-style: none; padding: 0 !important; }
.source-item { border-top: 1px solid var(--line); padding: var(--s4) 0; }
.source-item h3 { font-size: 1.125rem; margin-bottom: var(--s1); }
.compat-list li { padding: var(--s2) 0; border-bottom: 1px solid var(--line); }
.compat-list li:target { background: var(--tint); }

/* ---------- feedback (optional, after each lesson) ---------- */
.feedback { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin: var(--s6) 0; padding: 0 var(--s5); }
.feedback > summary { cursor: pointer; font-weight: 600; font-size: 1.0625rem; padding: var(--s4) 0; }
.feedback-form { padding-bottom: var(--s5); max-width: 40rem; }
.feedback-form fieldset { border: 0; padding: 0; margin: 0 0 var(--s4); }
.feedback-form legend, .feedback-form label.field { display: block; font-weight: 600; margin-bottom: var(--s2); }
.feedback-form .choice { display: flex; gap: var(--s2); align-items: center; font-size: 1rem; padding: var(--s1) 0; }
.feedback-form input[type="radio"] { width: 1.1rem; height: 1.1rem; accent-color: var(--action); }
.feedback-form select, .feedback-form textarea { display: block; width: 100%; font: inherit; font-size: 1rem; color: var(--ink); background: var(--surface); border: 1px solid #8a969f; border-radius: var(--radius-s); padding: var(--s2) var(--s3); }
.feedback-form textarea { min-height: 8rem; resize: vertical; line-height: 1.6; }
.feedback-form .field-group { margin-bottom: var(--s4); }
.feedback-form .hint { font-size: .9375rem; color: var(--muted); margin: var(--s1) 0 0; }
.feedback-form button { cursor: pointer; }
.feedback-form button[disabled] { opacity: .75; cursor: progress; }
.feedback-status { margin-top: var(--s3); font-weight: 600; }
.feedback-status.ok { color: #1f5b33; }
.feedback-status.error { color: #9a2c1e; }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .subject-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .reader-layout { grid-template-columns: 14rem minmax(0, 1fr); gap: var(--s6); }
}
@media (max-width: 760px) {
  :root { --prose: 1.0625rem; }
  h1, .home-hero h1 { font-size: 2rem; }
  .reading-heading h1 { font-size: 1.875rem; }
  h2, .reading-section > h2 { font-size: 1.5rem; }
  .lead { font-size: 1.0625rem; }
  .site-header { flex-direction: column; align-items: flex-start; gap: var(--s3); padding: var(--s4) 5%; }
  .page, .reader { padding-left: 5%; padding-right: 5%; }
  .home-hero { padding: var(--s5) 0 var(--s4); }
  .subject-grid { grid-template-columns: 1fr; gap: var(--s4); }
  .subject-art { height: 4.5rem; font-size: 2.25rem; }
  .subject-heading { padding: var(--s2) 0 var(--s4); }
  .subject-symbol { display: none; }
  .reader-layout { display: block; }
  .contents { position: static; max-height: 16rem; border: 1px solid var(--line); border-radius: var(--radius-s); padding: var(--s2) var(--s4); margin-bottom: var(--s5); background: var(--surface); }
  .worked-example, .derivation, .method, .background-item, .mistakes > li, .feedback { padding-left: var(--s4); padding-right: var(--s4); }
  .topic-row { grid-template-columns: 2rem minmax(0, 1fr); padding: var(--s4); gap: var(--s3); }
  .site-footer { flex-direction: column; gap: var(--s2); padding: var(--s5) 5%; }
  .formula { font-size: 1.0625rem; }
}
@media print {
  .site-header, .site-footer, .contents, .reader-top, .next-topic, .skip, .feedback { display: none; }
  .reader-layout { display: block; }
  .worked-example, figure { break-inside: avoid; }
  body { background: #fff; }
}
