/* Shared design system.
   Three axes: theme (dark/light), direction (rtl/ltr), motion (on/reduced).
   Charts carry the explanation — chrome stays out of the way. */

:root {
  --bg:        #0e1116;
  --bg-2:      #161b22;
  --bg-3:      #1c232c;
  --line:      #262d38;
  --line-2:    #333c4a;
  --ink:       #e8edf4;
  --ink-2:     #a9b4c4;
  --ink-3:     #6f7d90;
  --accent:    #4fa3ff;
  --accent-2:  #24d3a5;
  --warn:      #f5a524;
  --danger:    #f4694c;
  --sau:       #24d3a5;
  --grid:      #1e2530;
  --shadow:    rgba(0,0,0,.45);
  --radius:    12px;
  --maxw:      1180px;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --arabic: "SF Arabic", "Noto Sans Arabic", "IBM Plex Sans Arabic", "Segoe UI",
            Tahoma, "Geeza Pro", Arial, sans-serif;
  --dur: .5s;
}

/* Light palette: applied when the viewer picked light, or when they picked
   nothing and their system prefers it. */
:root[data-theme="light"] {
  --bg: #ffffff; --bg-2: #f7f9fc; --bg-3: #eef2f7;
  --line: #dfe5ee; --line-2: #c6d0de;
  --ink: #131820; --ink-2: #4a5668; --ink-3: #78859a;
  --grid: #e8edf4; --accent: #1668d4; --sau: #0f9c7c;
  --shadow: rgba(16,24,40,.13);
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #ffffff; --bg-2: #f7f9fc; --bg-3: #eef2f7;
    --line: #dfe5ee; --line-2: #c6d0de;
    --ink: #131820; --ink-2: #4a5668; --ink-3: #78859a;
    --grid: #e8edf4; --accent: #1668d4; --sau: #0f9c7c;
    --shadow: rgba(16,24,40,.13);
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  transition: background-color .3s ease, color .3s ease;
}
html[dir="rtl"] body { font-family: var(--arabic); line-height: 1.7; }

.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 20px; }

/* Figures stay latin and LTR even in Arabic — Saudi data publications do the
   same, and mirrored digits are unreadable in a chart. */
.num, .stat .v, td.num, .chart text { font-variant-numeric: tabular-nums; }
html[dir="rtl"] .lat { direction: ltr; display: inline-block; unicode-bidi: isolate; }

/* ---- masthead ---------------------------------------------------------- */
.masthead {
  border-bottom: 1px solid var(--line); background: var(--bg-2);
  position: sticky; top: 0; z-index: 20;
  backdrop-filter: saturate(150%) blur(8px);
}
.masthead .wrap { display: flex; align-items: center; justify-content: space-between; height: 56px; gap: 12px; }
.brand { font-weight: 650; letter-spacing: -.01em; color: var(--ink); text-decoration: none; font-size: 15px; white-space: nowrap; }
.brand span { color: var(--accent); }
.toolbar { display: flex; align-items: center; gap: 8px; }

/* segmented + icon toggles */
.seg { display: inline-flex; background: var(--bg-3); border: 1px solid var(--line-2); border-radius: 999px; padding: 2px; }
.seg button {
  border: 0; background: transparent; color: var(--ink-3); cursor: pointer;
  font: 600 12px/1 var(--sans); padding: 6px 12px; border-radius: 999px; transition: .18s;
}
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.icon-btn {
  width: 34px; height: 34px; display: grid; place-items: center; cursor: pointer;
  background: var(--bg-3); border: 1px solid var(--line-2); border-radius: 999px;
  color: var(--ink-2); transition: .18s; padding: 0;
}
.icon-btn:hover { color: var(--ink); border-color: var(--ink-3); }
.icon-btn svg { width: 16px; height: 16px; }

/* ---- hero -------------------------------------------------------------- */
.hero { padding: 46px 0 26px; border-bottom: 1px solid var(--line); }
.eyebrow {
  font-family: var(--mono); font-size: 11.5px; letter-spacing: .09em;
  text-transform: uppercase; color: var(--accent); margin-bottom: 12px;
}
html[dir="rtl"] .eyebrow { font-family: var(--arabic); letter-spacing: 0; font-size: 12.5px; }
h1 { font-size: clamp(29px, 4.4vw, 44px); line-height: 1.14; margin: 0; letter-spacing: -.025em; font-weight: 680; }
html[dir="rtl"] h1 { letter-spacing: 0; line-height: 1.35; }

/* ---- stat tiles -------------------------------------------------------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); gap: 12px; margin: 26px 0 4px; }
.stat {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; transition: border-color .2s, transform .2s;
}
.stat:hover { border-color: var(--line-2); transform: translateY(-2px); }
.stat .v { font-size: 30px; font-weight: 660; letter-spacing: -.03em; line-height: 1.1; }
.stat .v.accent { color: var(--sau); }
.stat .l { font-size: 12.5px; color: var(--ink-3); margin-top: 5px; line-height: 1.45; }

/* ---- sections ---------------------------------------------------------- */
section { padding: 38px 0; border-bottom: 1px solid var(--line); }
section:last-of-type { border-bottom: 0; }
.sec-head { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
h2 { font-size: 21px; margin: 0; letter-spacing: -.02em; font-weight: 650; }
html[dir="rtl"] h2 { letter-spacing: 0; }

.card { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }

/* The only prose allowed on the page: one short line where omitting it would
   make a number misleading. Everything else belongs in the post. */
.fine { color: var(--ink-3); font-size: 12px; margin: 10px 2px 0; line-height: 1.5; }

/* ---- controls ---------------------------------------------------------- */
.controls { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; }
.chip {
  font: 500 12.5px/1 var(--sans); color: var(--ink-2); background: var(--bg-3);
  border: 1px solid var(--line-2); border-radius: 999px; padding: 7px 13px; cursor: pointer; transition: .15s;
}
html[dir="rtl"] .chip { font-family: var(--arabic); font-size: 13px; }
.chip:hover { color: var(--ink); border-color: var(--ink-3); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip.sau[aria-pressed="true"] { background: var(--sau); border-color: var(--sau); color: #04231c; }

/* ---- charts ------------------------------------------------------------ */
.chart-box { width: 100%; overflow-x: auto; }
svg.chart { display: block; width: 100%; height: auto; }
.chart text { font-family: var(--sans); fill: var(--ink-3); font-size: 11.5px; }
html[dir="rtl"] .chart text.lbl, html[dir="rtl"] .chart text.lbl-strong { font-family: var(--arabic); }
.chart .axis-line { stroke: var(--line-2); }
.chart .grid { stroke: var(--grid); }
.chart .lbl { fill: var(--ink-2); font-size: 12px; }
.chart .lbl-strong { fill: var(--ink); font-size: 12.5px; font-weight: 600; }

.legend { display: flex; flex-wrap: wrap; gap: 13px; margin-top: 12px; font-size: 12.5px; color: var(--ink-2); }
.legend i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; margin-inline-end: 6px; vertical-align: -1px; }

/* ---- tables ------------------------------------------------------------ */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: start; padding: 9px 10px; border-bottom: 1px solid var(--line); }
th { color: var(--ink-3); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; }
td.num, th.num { text-align: end; font-family: var(--mono); }
.tbl-scroll { overflow-x: auto; }

/* ---- disclosure -------------------------------------------------------- */
details { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); }
details + details { margin-top: 12px; }
summary {
  cursor: pointer; padding: 14px 18px; font-weight: 600; font-size: 14.5px;
  list-style: none; display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
summary::-webkit-details-marker { display: none; }
summary::after { content: "+"; color: var(--ink-3); font-family: var(--mono); font-size: 17px; }
details[open] summary::after { content: "−"; }
details[open] summary { border-bottom: 1px solid var(--line); }
.details-body { padding: 4px 18px 16px; }
.sum-meta { font-family: var(--mono); font-size: 11.5px; color: var(--ink-3); font-weight: 400; }

/* ---- badges ------------------------------------------------------------ */
.badge { font-family: var(--mono); font-size: 10.5px; padding: 2px 7px; border-radius: 5px; border: 1px solid; display: inline-block; }
.badge.pass { color: var(--accent-2); border-color: #1c6b57; background: #0d2b24; }
.badge.warn { color: var(--warn);     border-color: #6d4d13; background: #2b2110; }
.badge.fail { color: var(--danger);   border-color: #7a3327; background: #2d1512; }
:root[data-theme="light"] .badge.pass, html:not([data-theme="dark"]) .badge.pass { }
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .badge.pass { background: #e6f7f1; border-color: #9cd9c5; color: #0a6b52; }
  :root:not([data-theme="dark"]) .badge.warn { background: #fdf3e0; border-color: #e6c68a; color: #8a5b06; }
  :root:not([data-theme="dark"]) .badge.fail { background: #fdeceb; border-color: #f0b3ab; color: #a83224; }
}
:root[data-theme="light"] .badge.pass { background: #e6f7f1; border-color: #9cd9c5; color: #0a6b52; }
:root[data-theme="light"] .badge.warn { background: #fdf3e0; border-color: #e6c68a; color: #8a5b06; }
:root[data-theme="light"] .badge.fail { background: #fdeceb; border-color: #f0b3ab; color: #a83224; }

.prov { font-family: var(--mono); font-size: 11.5px; color: var(--ink-3); direction: ltr; }
.prov a { color: var(--accent); text-decoration: none; word-break: break-all; }

footer { padding: 30px 0 56px; color: var(--ink-3); font-size: 12.5px; }
footer a { color: var(--accent); text-decoration: none; }

.tooltip {
  position: fixed; pointer-events: none; z-index: 50; opacity: 0;
  background: var(--bg-3); border: 1px solid var(--line-2); border-radius: 8px;
  padding: 8px 11px; font-size: 12.5px; color: var(--ink); transition: opacity .12s;
  box-shadow: 0 8px 26px var(--shadow); max-width: 270px; line-height: 1.45;
}
html[dir="rtl"] .tooltip { font-family: var(--arabic); text-align: right; }
.tooltip .t-row { color: var(--ink-2); }

/* ---- animation --------------------------------------------------------- */
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.reveal { opacity: 0; }
.reveal.in { animation: rise var(--dur) cubic-bezier(.22,.68,.36,1) forwards; }
.stats .stat.reveal.in { animation-delay: calc(var(--i, 0) * 55ms); }

/* Charts animate from inside base.js (path draw / bar grow); these cover the
   surrounding furniture. */
.chart .drawable { stroke-dasharray: var(--len); stroke-dashoffset: var(--len); }
.chart .drawable.go { transition: stroke-dashoffset 1.1s cubic-bezier(.32,.72,.3,1); stroke-dashoffset: 0; }
.chart .growable { transform: scaleX(0); transform-origin: var(--origin, left); }
.chart .growable.go { transition: transform .75s cubic-bezier(.32,.72,.3,1); transform: scaleX(1); }
.chart .fadeable { opacity: 0; }
.chart .fadeable.go { transition: opacity .7s ease; opacity: var(--target-op, .88); }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .reveal, .reveal.in { opacity: 1; animation: none !important; }
  .chart .drawable { stroke-dasharray: none; stroke-dashoffset: 0; }
  .chart .growable { transform: none; }
  .chart .fadeable { opacity: var(--target-op, .88); }
  .stat:hover, .proj:hover { transform: none; }
  * { transition-duration: .001ms !important; }
}

@media (max-width: 640px) {
  .hero { padding: 30px 0 22px; }
  section { padding: 28px 0; }
  .stats { grid-template-columns: repeat(2, 1fr); gap: 9px; }
  .stat { padding: 13px 14px; }
  .stat .v { font-size: 23px; }
  .stat .l { font-size: 11.5px; }
  .masthead .wrap { height: 52px; }
  .brand { font-size: 14px; }
  .seg button { padding: 6px 10px; font-size: 11.5px; }
}
