/* Fonts: bundled locally, no third-party requests. */
@font-face { font-family: "Source Serif 4"; font-weight: 400; font-style: normal; font-display: swap; src: url("../fonts/source-serif-4-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Source Serif 4"; font-weight: 400; font-style: italic; font-display: swap; src: url("../fonts/source-serif-4-latin-400-italic.woff2") format("woff2"); }
@font-face { font-family: "Source Serif 4"; font-weight: 600; font-style: normal; font-display: swap; src: url("../fonts/source-serif-4-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-weight: 400; font-style: normal; font-display: swap; src: url("../fonts/ibm-plex-sans-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-weight: 600; font-style: normal; font-display: swap; src: url("../fonts/ibm-plex-sans-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans Arabic"; font-weight: 400; font-style: normal; font-display: swap; src: url("../fonts/ibm-plex-sans-arabic-arabic-400-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans Arabic"; font-weight: 600; font-style: normal; font-display: swap; src: url("../fonts/ibm-plex-sans-arabic-arabic-600-normal.woff2") format("woff2"); }

:root {
  --bg: #f6f8fa; --paper: #ffffff; --ink: #14202e; --muted: #4a5868; --rule: #d3dae3;
  --accent: #0b5c80; --accent-ink: #ffffff; --accent-soft: #e2eff5; --accent2: #8a4b00; --warn-bg: #fbf1e0;
  --focus: #b3500a;
  --ui: "IBM Plex Sans", "IBM Plex Sans Arabic", system-ui, sans-serif;
  --text: "Source Serif 4", "IBM Plex Sans Arabic", Georgia, serif;
  --r: 4px;
}
:root:not([data-theme="light"]) { color-scheme: light dark; }
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1620; --paper: #151f2b; --ink: #e6edf4; --muted: #a5b3c2; --rule: #2a3949;
    --accent: #6cc0e5; --accent-ink: #08202d; --accent-soft: #19303f; --accent2: #e5a45a; --warn-bg: #2b2418; --focus: #f0a560;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { font-size: 100%; -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--text); font-size: 1.0625rem; line-height: 1.6; }
html[lang="ar"] body { font-family: "IBM Plex Sans Arabic", var(--text); line-height: 1.85; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { font-family: var(--ui); line-height: 1.25; margin: 0; }
html[lang="ar"] h1, html[lang="ar"] h2, html[lang="ar"] h3, html[lang="ar"] h4 { font-family: "IBM Plex Sans Arabic", var(--ui); }
p { margin: 0 0 .75rem; max-width: 70ch; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.skip { position: absolute; inset-inline-start: 8px; top: -60px; background: var(--accent); color: var(--accent-ink); padding: .5rem .9rem; z-index: 20; font-family: var(--ui); }
.skip:focus { top: 8px; }
.noscript { padding: 1rem; }

/* Mathematics is always left-to-right and isolated from surrounding bidi text */
.math { direction: ltr; unicode-bidi: isolate; display: inline-block; }
.math.katex-display, div.math { display: block; }
.katex { font-size: 1.05em; }
html[lang="ar"] .katex { font-size: 1.02em; }

/* Header */
.site-header { background: var(--paper); border-block-end: 1px solid var(--rule); }
.bar { display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; justify-content: space-between; padding: 1rem clamp(1rem, 4vw, 2.5rem) .5rem; max-width: 80rem; margin-inline: auto; }
.brand h1 { font-size: clamp(1.35rem, 3vw, 1.9rem); font-weight: 600; }
.brand p { margin: .15rem 0 0; color: var(--muted); font-family: var(--ui); font-size: .95rem; }
html[lang="ar"] .brand p { font-family: "IBM Plex Sans Arabic", var(--ui); }
.langsw { display: inline-flex; border: 2px solid var(--accent); border-radius: var(--r); overflow: hidden; }
.langsw button { background: transparent; border: 0; padding: .55rem 1.1rem; cursor: pointer; font-family: var(--ui); font-weight: 600; min-width: 5.5rem; color: var(--accent); }
.langsw button[lang="ar"] { font-family: "IBM Plex Sans Arabic", var(--ui); }
.langsw button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.mainnav { max-width: 80rem; margin-inline: auto; padding-inline: clamp(1rem, 4vw, 2.5rem); }
.mainnav ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: .25rem 1.25rem; }
.mainnav button { background: none; border: 0; border-block-end: 3px solid transparent; padding: .6rem 0; cursor: pointer; font-family: var(--ui); color: var(--muted); font-weight: 600; font-size: .95rem; }
html[lang="ar"] .mainnav button { font-family: "IBM Plex Sans Arabic", var(--ui); }
.mainnav button:hover { color: var(--ink); }
.mainnav button[aria-current="page"] { color: var(--ink); border-block-end-color: var(--accent); }

main { max-width: 80rem; margin-inline: auto; padding: 1.25rem clamp(1rem, 4vw, 2.5rem) 3rem; outline: none; }
.site-footer { text-align: center; padding: 1.5rem; font-family: var(--ui); }
.site-footer a { color: var(--accent); }

/* Layout */
.layout { display: grid; grid-template-columns: 15rem minmax(0, 1fr); gap: 2rem; align-items: start; }
.side { position: sticky; top: 1rem; }
.topicbox summary { display: none; }
.topics { list-style: none; margin: 0; padding: 0; font-family: var(--ui); }
html[lang="ar"] .topics { font-family: "IBM Plex Sans Arabic", var(--ui); }
.topics button { width: 100%; display: flex; justify-content: space-between; gap: .5rem; text-align: start; background: none; border: 0; border-inline-start: 3px solid transparent; padding: .45rem .75rem; cursor: pointer; font-size: .95rem; color: var(--muted); }
.topics button:hover { background: var(--accent-soft); color: var(--ink); }
.topics button[aria-pressed="true"] { border-inline-start-color: var(--accent); color: var(--ink); font-weight: 600; background: var(--accent-soft); }
.topics .n { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 400; }

.toolbar { display: flex; flex-wrap: wrap; gap: .75rem 1rem; align-items: end; font-family: var(--ui); }
html[lang="ar"] .toolbar { font-family: "IBM Plex Sans Arabic", var(--ui); }
.field { display: flex; flex-direction: column; gap: .25rem; }
.field.grow { flex: 1 1 18rem; }
.field label { font-size: .85rem; color: var(--muted); font-weight: 600; }
.search, select, .fld { background: var(--paper); border: 1px solid var(--muted); border-radius: var(--r); padding: .55rem .7rem; min-height: 2.6rem; }
.search { width: 100%; }
.toolrow { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .5rem 1rem; margin: .9rem 0 .25rem; font-family: var(--ui); }
html[lang="ar"] .toolrow { font-family: "IBM Plex Sans Arabic", var(--ui); }
.count { margin: 0; color: var(--muted); font-size: .9rem; }
.btn { background: var(--paper); border: 1px solid var(--accent); color: var(--accent); border-radius: var(--r); padding: .4rem .85rem; cursor: pointer; font-family: var(--ui); font-size: .9rem; font-weight: 600; min-height: 2.4rem; }
html[lang="ar"] .btn { font-family: "IBM Plex Sans Arabic", var(--ui); }
.btn:hover { background: var(--accent-soft); }
.btnrow { display: flex; flex-wrap: wrap; gap: .5rem; margin: .5rem 0; }

/* Entries */
.cathead { font-size: 1.3rem; margin: 2rem 0 .5rem; padding-block-end: .4rem; border-block-end: 2px solid var(--ink); }
.entry { display: grid; grid-template-columns: 11rem minmax(0, 1fr); gap: 1.25rem; padding: 1rem 0; border-block-end: 1px solid var(--rule); scroll-margin-top: 1rem; }
.entry.flash { background: var(--accent-soft); }
.sym { font-size: 1.9rem; display: block; width: 100%; max-width: 100%; justify-self: center; min-height: 3rem; overflow-x: auto; overflow-y: auto; text-align: center; padding-block: .25rem; padding-inline: .25rem; }
.sym .katex { font-size: 1.3em; }
.body h3 { font-size: 1.15rem; }
.toggle { display: flex; width: 100%; justify-content: space-between; align-items: baseline; gap: 1rem; text-align: start; background: none; border: 0; padding: 0; cursor: pointer; font-family: inherit; font-size: inherit; font-weight: 600; color: var(--ink); }
.toggle .ename { text-decoration: underline; text-decoration-color: var(--rule); text-underline-offset: 4px; }
.toggle:hover .ename { text-decoration-color: var(--accent); }
.toggle .tlabel { font-size: .8rem; font-weight: 400; color: var(--accent); white-space: nowrap; font-family: var(--ui); }
html[lang="ar"] .toggle .tlabel { font-family: "IBM Plex Sans Arabic", var(--ui); }
.toggle::after { content: ""; }
.alt { margin: .1rem 0 .35rem; color: var(--muted); font-size: .95rem; }
.alt[lang="ar"] { font-family: "IBM Plex Sans Arabic", var(--ui); }
.read { margin: 0 0 .5rem; font-size: .98rem; }
.rlabel { color: var(--muted); font-family: var(--ui); font-size: .85rem; }
html[lang="ar"] .rlabel { font-family: "IBM Plex Sans Arabic", var(--ui); }
.badges { display: flex; flex-wrap: wrap; gap: .4rem; font-family: var(--ui); }
html[lang="ar"] .badges { font-family: "IBM Plex Sans Arabic", var(--ui); }
.badge { font-size: .78rem; border: 1px solid var(--rule); border-radius: 999px; padding: .05rem .6rem; color: var(--muted); background: var(--paper); }
.badge.conv-v { border-color: var(--accent2); color: var(--accent2); }
.badge.conv-u { border-color: var(--accent); color: var(--accent); }
.detail { margin-block-start: 1rem; padding: 1rem 1.25rem; background: var(--paper); border: 1px solid var(--rule); border-inline-start: 4px solid var(--accent); }
.detail[hidden] { display: none; }
.dsec { margin-block-end: 1.1rem; }
.dsec h4 { font-size: .95rem; color: var(--accent); margin-block-end: .3rem; }
.dsec p { margin-block-end: .4rem; }
.formula { overflow-x: auto; padding: .25rem 0; max-width: 100%; }
.formula .katex-display { margin: .5rem 0; }
.variant { background: var(--warn-bg); padding: .6rem .9rem; border-inline-start: 4px solid var(--accent2); }
.variant h4 { color: var(--accent2); }
.rel { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: .5rem; }
.xref { display: inline-flex; align-items: center; gap: .5rem; background: var(--accent-soft); border: 1px solid transparent; color: var(--ink); border-radius: var(--r); padding: .25rem .65rem; cursor: pointer; font-family: inherit; font-size: .92rem; }
.xref:hover { border-color: var(--accent); }
.xsym { font-size: .95em; }
.empty { padding: 2rem 0; }

/* Greek alphabet cross-links: inline prose names and standalone symbols. */
.greek-link { background: none; border: 0; padding: 0; margin: 0; cursor: pointer; font: inherit; color: var(--accent); text-decoration: underline; text-decoration-color: var(--rule); text-underline-offset: 3px; }
.greek-link:hover { text-decoration-color: var(--accent); background: var(--accent-soft); }
.greek-link.math-link { text-decoration: none; border-radius: var(--r); }
.greek-link.math-link:hover { text-decoration: underline; }
.tbl tr.flash th, .tbl tr.flash td { background: var(--accent-soft); }
.tbl tr[id^="greek-"] { scroll-margin-top: 1rem; }

/* Widgets */
.widgets { display: grid; gap: 1rem; }
.widget { border: 1px solid var(--rule); background: var(--bg); padding: .8rem 1rem; font-family: var(--ui); }
html[lang="ar"] .widget { font-family: "IBM Plex Sans Arabic", var(--ui); }
.wtitle { font-weight: 600; margin: 0 0 .5rem; font-size: .95rem; }
.wnote { font-size: .9rem; color: var(--muted); margin: .4rem 0 0; max-width: none; overflow-wrap: anywhere; direction: ltr; unicode-bidi: plaintext; }
html[lang="ar"] .wnote { direction: rtl; }
.ctl { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .75rem; margin: .3rem 0; font-size: .9rem; }
.ctl.col { flex-direction: column; align-items: stretch; }
.ctl label { min-width: 4rem; font-weight: 600; }
.ctl input[type=range] { flex: 1 1 10rem; max-width: 22rem; accent-color: var(--accent); min-height: 1.6rem; }
.sl-out { min-width: 3.5rem; font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; display: inline-block; }
.ctlrow { display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; }
.fld { width: auto; padding: .35rem .5rem; min-height: 2.2rem; direction: ltr; }
.fld.sm { width: 3.6rem; text-align: center; }
.fld.wide { width: 100%; resize: vertical; }
.mgrid { display: grid; grid-template-columns: repeat(2, auto); gap: .3rem; direction: ltr; }
.mgrid.row { grid-template-columns: repeat(3, auto); }
.mwrap { display: flex; align-items: center; gap: .5rem; direction: ltr; }
.mname { font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-block-end: .5rem; }
.chip { border: 1px solid var(--accent); background: var(--paper); color: var(--accent); padding: .3rem .8rem; border-radius: 999px; cursor: pointer; min-height: 2.2rem; }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.duo { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: .75rem; align-items: center; }

/* SVG plots */
.plot { width: 100%; max-width: 40rem; height: auto; display: block; background: var(--paper); border: 1px solid var(--rule); direction: ltr; }
.plot.short { max-height: 6rem; }
.ptext { font-family: var(--ui); font-size: 11px; fill: var(--muted); }
.ptext.big { font-size: 16px; fill: var(--ink); font-weight: 600; }
.pgrid line { stroke: var(--rule); stroke-width: 1; }
.paxis { stroke: var(--ink); stroke-width: 1.2; }
.pcurve { stroke: var(--accent); stroke-width: 2.4; fill: none; }
.pcurve2 { stroke: var(--accent2); stroke-width: 2; fill: none; }
.pdash { stroke: var(--muted); stroke-width: 1.8; stroke-dasharray: 6 4; fill: none; }
.pthick { stroke: var(--accent); stroke-width: 5; }
.pthick2 { stroke: var(--rule); stroke-width: 5; }
.pdot { fill: var(--paper); stroke: var(--accent); stroke-width: 2.5; }
.pcircle { fill: none; stroke: var(--ink); stroke-width: 1.5; }
.parea { fill: var(--accent); fill-opacity: .25; stroke: none; }
.ptri { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 2; }
.ptri2 { fill: none; stroke: var(--accent2); stroke-width: 2; stroke-dasharray: 6 4; }
.pset { fill: none; stroke: var(--muted); stroke-width: 1.5; }
.pset.on { fill: var(--accent-soft); stroke: var(--accent); }
.vfill { fill: var(--accent); fill-opacity: .45; }
.vhole { fill: var(--paper); }
.voutline { fill: none; stroke: var(--ink); stroke-width: 2; }

/* Tables and appendices */
.page h2 { font-size: 1.6rem; margin-block-end: 1rem; }
.page h3 { font-size: 1.2rem; margin: 1.75rem 0 .5rem; }
.lead { color: var(--muted); }
.tscroll { overflow-x: auto; max-width: 100%; }
.tbl, .truth { border-collapse: collapse; background: var(--paper); font-family: var(--ui); width: 100%; }
html[lang="ar"] .tbl, html[lang="ar"] .truth { font-family: "IBM Plex Sans Arabic", var(--ui); }
.tbl.narrow { max-width: 28rem; }
.tbl th, .tbl td, .truth th, .truth td { border: 1px solid var(--rule); padding: .5rem .8rem; text-align: start; vertical-align: top; }
.tbl thead th, .truth thead th { background: var(--accent-soft); }
.truth { width: auto; min-width: 12rem; margin-block-start: .5rem; }
.truth td, .truth th { text-align: center; }
.tv { font-weight: 600; color: var(--accent); }
.fv { color: var(--accent2); font-weight: 600; }
.gsym { font-size: 1.3rem; text-align: center !important; }
.arf { font-size: 1.2rem; }
.alt2 { color: var(--muted); }
.total th, .total td { font-weight: 600; }
.gloss { display: grid; grid-template-columns: minmax(12rem, 22rem) 1fr; gap: .2rem 1.5rem; max-width: 60rem; }
.gloss dt, .gloss dd { margin: 0; padding: .3rem 0; border-block-end: 1px solid var(--rule); }
.gloss .xref { background: none; padding: .1rem 0; font-weight: 600; color: var(--accent); text-align: start; }
.grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr)); gap: .6rem; }
.cell { width: 100%; flex-direction: column; align-items: center; justify-content: flex-start; gap: .3rem; padding: .7rem .5rem; background: var(--paper); border: 1px solid var(--rule); text-align: center; min-height: 6rem; }
.cell:hover { border-color: var(--accent); }
.csym { font-size: 1.15rem; max-width: 100%; overflow-x: auto; }
.cname { font-size: .78rem; color: var(--muted); font-family: var(--ui); line-height: 1.3; }
html[lang="ar"] .cname { font-family: "IBM Plex Sans Arabic", var(--ui); }
.varlist { list-style: none; padding: 0; margin: 0; max-width: 56rem; }
.varlist li { padding: .6rem 0; border-block-end: 1px solid var(--rule); }
.varlist .xref { background: none; padding: 0; font-weight: 600; color: var(--accent); }
.varlist p { margin: .2rem 0 0; font-size: .97rem; }

/* LaTeX commands page with interactive playground */
.latex-play { border-inline-start: 4px solid var(--accent); }
.latex-input { font-family: ui-monospace, Consolas, monospace; min-height: 4.2rem; }
.latex-out { background: var(--paper); border: 1px solid var(--rule); padding: .8rem 1rem; min-height: 3.2rem; }
.latex-err { color: var(--accent2); font-size: .9rem; margin: .4rem 0 0; font-family: var(--ui); }
html[lang="ar"] .latex-err { font-family: "IBM Plex Sans Arabic", var(--ui); }
.latex-code { font-family: ui-monospace, Consolas, monospace; font-size: .85rem; direction: ltr; unicode-bidi: isolate; display: inline-block; background: var(--accent-soft); padding: .1rem .45rem; border-radius: var(--r); overflow-wrap: anywhere; }
.latex-tbl td:nth-child(2), .latex-tbl td:nth-child(3) { direction: ltr; }
.latex-actions { white-space: nowrap; }
.btn.sm { padding: .25rem .6rem; min-height: 2rem; font-size: .82rem; }
.btn.ghost { border-color: var(--rule); color: var(--muted); }
.latexl-notes { color: var(--muted); font-size: .95rem; }
.latex-page h3[id^="latex-"] { scroll-margin-top: 1rem; }

/* Responsive */
@media (max-width: 879px) {
  .layout { grid-template-columns: 1fr; gap: 1rem; }
  .side { position: static; }
  .topicbox summary { display: block; cursor: pointer; font-family: var(--ui); font-weight: 600; padding: .6rem .8rem; border: 1px solid var(--muted); background: var(--paper); border-radius: var(--r); }
  html[lang="ar"] .topicbox summary { font-family: "IBM Plex Sans Arabic", var(--ui); }
  .entry { grid-template-columns: 1fr; gap: .4rem; }
  .sym { text-align: start; justify-self: start; min-height: 0; }
  .gloss { grid-template-columns: 1fr; }
  .gloss dt { border-block-end: 0; padding-block-end: 0; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; animation: none !important; } }
@media print { .side, .toolbar, .toolrow, .mainnav, .langsw, .btnrow { display: none; } .detail[hidden] { display: block; } }
