/* ============================================================================
   Core: reset, base typography, the application shell and the shared
   components every screen composes from. Loaded on every page.
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  /* clip, not hidden: it stops an off-screen drawer from widening the page
     without turning html into a scroll container, which would break sticky */
  overflow-x: clip;
  /* the sticky header must never cover the element a deep link or a keyboard
     focus lands on — WCAG 2.2 "focus not obscured" */
  scroll-padding-top: calc(var(--header-h) + var(--s-4));
}
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--fs-md);
  line-height: var(--lh-ui);
  font-synthesis-weight: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

[hidden] { display: none !important; }

img, svg, video { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; }

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-read);
  font-weight: 700;
  line-height: var(--lh-head);
  text-wrap: balance;
}

::selection { background: var(--accent-weak); color: var(--ink); }

/* One focus ring, everywhere: 2px at 3:1 against both grounds, offset so it
   reads against dense text as clearly as against a button. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}
:focus:not(:focus-visible) { outline: none; }

.skip-link {
  position: fixed; inset-block-start: var(--s-2); inset-inline-start: var(--s-2);
  z-index: 200; padding: var(--s-2) var(--s-4);
  background: var(--accent); color: var(--ink-on-accent);
  border-radius: var(--r-sm); font-weight: 600;
  transform: translateY(-160%); transition: transform var(--dur-2) var(--ease);
}
.skip-link:focus { transform: none; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}

/* ---------------------------------------------------------------- icons */
/* One family: Phosphor-style outline, 1.75 stroke, 24 box, sized by token. */
.ico {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.75;
  stroke-linecap: round; stroke-linejoin: round;
}
.ico-sm { width: 16px; height: 16px; stroke-width: 2; }
.ico-lg { width: 24px; height: 24px; }

/* ============================================================ app shell */
.shell {
  max-width: var(--shell-max);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

/* ---------------------------------------------------------------- header */
.hdr {
  position: sticky; inset-block-start: 0; z-index: var(--z-header);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(14px) saturate(1.3);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  border-block-end: 1px solid var(--line-soft);
  transition: box-shadow var(--dur-3) var(--ease),
              background var(--dur-3) var(--ease);
}
/* after the first scroll the header gives its weight back to the text */
body.is-scrolled .hdr {
  box-shadow: var(--sh-2);
  background: color-mix(in srgb, var(--surface) 95%, transparent);
}

.hdr-row {
  display: flex; align-items: center; gap: var(--s-3);
  height: var(--header-h);
  max-width: var(--shell-max); margin-inline: auto;
  padding-inline: clamp(var(--s-3), 3vw, var(--s-8));
}

/* ---- wordmark: typographic, with one hairline rule as the only mark ---- */
.brand { display: flex; align-items: center; gap: var(--s-3); text-decoration: none; flex: none; }
.brand-mark { width: 26px; height: 26px; color: var(--accent); flex: none; }
.brand-txt { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name {
  font-family: var(--font-read); font-weight: 700;
  font-size: 1.12rem; letter-spacing: -.01em; color: var(--ink);
}
.brand-sub {
  font-size: var(--fs-2xs); color: var(--ink-3); font-weight: 400;
  letter-spacing: .01em;
}
@media (max-width: 900px) { .brand-sub { display: none; } }

/* ---- primary navigation ------------------------------------------------ */
.nav { display: flex; align-items: center; gap: var(--s-1); }
.nav a {
  display: inline-flex; align-items: center; gap: var(--s-2);
  padding: var(--s-2) var(--s-3);
  font-size: var(--fs-sm); font-weight: 500;
  color: var(--ink-2); text-decoration: none;
  border-radius: var(--r-sm);
  white-space: nowrap;
  transition: color var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
}
.nav a:hover { color: var(--ink); background: var(--surface-3); }
.nav a[aria-current="page"] { color: var(--accent); font-weight: 600; }
/* the current item carries a rule as well as a colour, so the state does not
   depend on hue alone */
.nav a[aria-current="page"]::after {
  content: ""; position: absolute; inset-inline: var(--s-3);
  inset-block-end: -1px; height: 2px; background: var(--accent);
  border-radius: var(--r-pill);
}
.nav a { position: relative; }

.hdr-spacer { flex: 1 1 auto; }
.hdr-tools { display: flex; align-items: center; gap: var(--s-1); }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--s-2);
  min-height: 40px; padding: 0 var(--s-4);
  font-size: var(--fs-sm); font-weight: 500; font-family: var(--font-ui);
  color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-sm);
  text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background var(--dur-1) var(--ease),
              border-color var(--dur-1) var(--ease),
              color var(--dur-1) var(--ease);
}
.btn:hover { background: var(--surface-3); border-color: var(--line-strong); }
.btn:active { background: var(--surface-3); }

.btn-primary {
  background: var(--accent); color: var(--ink-on-accent);
  border-color: var(--accent); font-weight: 600;
}
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }

.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-3); color: var(--ink); }

.btn-lg { min-height: 48px; padding: 0 var(--s-6); font-size: var(--fs-lg); }
.btn-sm { min-height: 32px; padding: 0 var(--s-3); font-size: var(--fs-xs); }

.btn[disabled], .btn[aria-disabled="true"] {
  opacity: .45; cursor: not-allowed; pointer-events: none;
}

/* icon-only control: 40px box keeps the pointer target at 24px+ (WCAG 2.2)
   and comfortably past 44px on touch via the media query below */
.ibtn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; flex: none;
  color: var(--ink-2); border-radius: var(--r-sm);
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
}
.ibtn:hover { background: var(--surface-3); color: var(--ink); }
.ibtn[aria-pressed="true"] { color: var(--accent); background: var(--accent-weak); }
.ibtn-sm { width: 32px; height: 32px; }
@media (pointer: coarse) {
  .ibtn { width: 44px; height: 44px; }
  .ibtn-sm { width: 40px; height: 40px; }
}

/* ------------------------------------------------------ segmented control */
.seg {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--surface-3); border-radius: var(--r-md);
  border: 1px solid var(--line-soft);
}
.seg button, .seg a {
  display: inline-flex; align-items: center; gap: var(--s-2);
  min-height: 32px; padding: 0 var(--s-3);
  font-size: var(--fs-xs); font-weight: 500; color: var(--ink-2);
  border-radius: var(--r-sm); text-decoration: none; white-space: nowrap;
  transition: background var(--dur-2) var(--ease), color var(--dur-2) var(--ease),
              box-shadow var(--dur-2) var(--ease);
}
.seg button:hover, .seg a:hover { color: var(--ink); }
.seg .is-on, .seg [aria-pressed="true"], .seg [aria-current="page"] {
  background: var(--surface); color: var(--ink); font-weight: 600;
  box-shadow: var(--sh-1);
}

/* ------------------------------------------------------------------ chips */
.chip {
  display: inline-flex; align-items: center; gap: var(--s-2);
  padding: var(--s-1) var(--s-3);
  font-size: var(--fs-2xs); font-weight: 500; color: var(--ink-2);
  background: var(--surface-3); border: 1px solid var(--line-soft);
  border-radius: var(--r-pill); white-space: nowrap;
}
.chip-accent { color: var(--accent); background: var(--accent-weak); border-color: var(--accent-line); }

/* ------------------------------------------------------------------ cards */
.card {
  background: var(--surface); border: 1px solid var(--line-soft);
  border-radius: var(--r-lg); padding: var(--s-6);
  transition: border-color var(--dur-2) var(--ease), box-shadow var(--dur-2) var(--ease);
}
a.card:hover, .card-link:hover { border-color: var(--accent-line); box-shadow: var(--sh-2); }

/* ------------------------------------------------------------------ forms */
.field {
  width: 100%; min-height: 40px; padding: 0 var(--s-3);
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--r-sm);
  font-size: var(--fs-sm);
  transition: border-color var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease);
}
.field:hover { border-color: var(--line-strong); }
.field:focus-visible {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-weak);
}
select.field { padding-inline-end: var(--s-8); cursor: pointer; }

.switch {
  display: inline-flex; align-items: center; gap: var(--s-2);
  font-size: var(--fs-xs); color: var(--ink-2); cursor: pointer;
  user-select: none;
}
.switch input { accent-color: var(--accent); width: 16px; height: 16px; cursor: pointer; }

/* ----------------------------------------------------------- page heading */
/* A document page. It carries its own gutter and stops well short of the
   window's edge: prose that runs the full width of a 1440px display is not a
   page, it is a banner. */
.page {
  max-width: var(--doc-max);
  margin-inline: auto;
  padding-inline: var(--gutter);
  padding-block: var(--s-10) var(--s-24);
}
.page-head { margin-block-end: var(--s-10); }
.page-head h1 {
  font-size: var(--fs-title); color: var(--ink);
  letter-spacing: -.015em; margin-block-end: var(--s-3);
}
.lede {
  color: var(--ink-2); font-size: var(--fs-lg); line-height: 1.8;
  max-width: 68ch;
}
.crumb {
  display: flex; align-items: center; gap: var(--s-2);
  font-size: var(--fs-xs); color: var(--ink-3);
  margin-block-end: var(--s-3);
}
.crumb a { color: var(--ink-3); text-decoration: none; }
.crumb a:hover { color: var(--accent); text-decoration: underline; }
/* the separator points the way the script runs, so it is mirrored by RTL */
.crumb .sep { color: var(--line-strong); }

/* --------------------------------------------------------------- eyebrow */
.eyebrow {
  font-size: var(--fs-2xs); font-weight: 600; letter-spacing: .09em;
  color: var(--accent); text-transform: none;
  display: flex; align-items: center; gap: var(--s-3);
  margin-block-end: var(--s-3);
}
.eyebrow::after {
  content: ""; height: 1px; flex: 1 1 auto;
  background: linear-gradient(to left, var(--line), transparent);
}

/* ------------------------------------------------------------------ toast */
.toast {
  position: fixed; inset-block-end: var(--s-6);
  inset-inline-start: 50%; transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex; align-items: center; gap: var(--s-2);
  padding: var(--s-3) var(--s-5);
  background: var(--navy); color: var(--on-navy);
  border-radius: var(--r-pill); box-shadow: var(--sh-3);
  font-size: var(--fs-sm); font-weight: 500;
  animation: toast-in var(--dur-3) var(--ease-soft);
}
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
}

/* ------------------------------------------- loading / empty / error states */
.spinner {
  width: 15px; height: 15px; flex: none;
  border: 2px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2s; }
}

.state {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: var(--s-3); padding: var(--s-16) var(--s-6);
  color: var(--ink-3);
}
.state .ico { width: 30px; height: 30px; color: var(--line-strong); stroke-width: 1.5; }
.state h2 { font-size: var(--fs-h3); color: var(--ink-2); font-family: var(--font-ui); font-weight: 600; }
.state p { max-width: 46ch; font-size: var(--fs-sm); }
.state .btn { margin-block-start: var(--s-2); }

.state-error {
  border: 1px solid var(--danger); border-radius: var(--r-md);
  background: var(--danger-weak); color: var(--ink-2);
  padding: var(--s-5); text-align: start; align-items: stretch;
}
.state-error h2 { color: var(--danger); }

/* skeleton: reserves the space its content will take, so nothing jumps */
.skel {
  background: linear-gradient(90deg, var(--surface-3) 25%,
              var(--surface-2) 37%, var(--surface-3) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
  border-radius: var(--r-sm);
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
@media (prefers-reduced-motion: reduce) { .skel { animation: none; } }

/* --------------------------------------------------------------- scrollbar */
@supports (scrollbar-width: thin) {
  * { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
}

/* ------------------------------------------------------- reveal on scroll */
/* opt-in, one property, and inert the moment a reader asks for less motion */
.reveal { opacity: 0; transform: translateY(10px); }
.reveal.is-in {
  opacity: 1; transform: none;
  transition: opacity var(--dur-4) var(--ease), transform var(--dur-4) var(--ease);
}
@media (prefers-reduced-motion: reduce) {
  .reveal, .reveal.is-in { opacity: 1; transform: none; transition: none; }
}

/* ------------------------------------------------------------------ print */
@media print {
  .no-print, .hdr, .skip-link, .toast, .mobile-nav { display: none !important; }
  body { background: #fff; }
}

/* ===================================================== responsive shell */
/* Two visibilities, one breakpoint, used by the header and by pages alike. */
.only-mobile { display: none; }
@media (max-width: 860px) {
  .only-desk   { display: none !important; }
  .only-mobile { display: inline-flex; }
}

/* ------------------------------------------------ mobile navigation sheet */
/* One pattern, not two: the header's menu button is the only navigation
   affordance on small screens. No bottom bar competes with it. */
.navsheet { position: fixed; inset: 0; z-index: var(--z-panel); }
.navsheet-scrim {
  position: absolute; inset: 0;
  background: color-mix(in srgb, var(--navy) 55%, transparent);
  backdrop-filter: blur(2px);
  animation: fade-in var(--dur-2) var(--ease);
}
@keyframes fade-in { from { opacity: 0; } }

.navsheet-panel {
  position: absolute; inset-block: 0; inset-inline-start: 0;
  width: min(84vw, 320px);
  background: var(--surface); border-inline-end: 1px solid var(--line);
  box-shadow: var(--sh-4);
  display: flex; flex-direction: column;
  animation: navsheet-in var(--dur-3) var(--ease-soft);
}
/* RTL: the panel enters from the same edge the script starts on */
@keyframes navsheet-in { from { transform: translateX(-100%); } }
/* the drawer opens from the side the menu button sits on; in RTL that is the
   right, which inset-inline-start already resolves to */
html[dir="rtl"] .navsheet-panel {
  border-inline-end: 0; border-inline-start: 1px solid var(--line);
  animation-name: navsheet-in-rtl;
}
@keyframes navsheet-in-rtl { from { transform: translateX(100%); } }
@media (prefers-reduced-motion: reduce) {
  .navsheet-panel, .navsheet-scrim { animation: none; }
}

.navsheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s-3) var(--s-3) var(--s-3) var(--s-5);
  border-block-end: 1px solid var(--line-soft);
  font-size: var(--fs-xs); font-weight: 600; color: var(--ink-3);
}
.navsheet-nav { list-style: none; margin: 0; padding: var(--s-3); display: grid; gap: 2px; }
.navsheet-nav a {
  display: flex; align-items: center; gap: var(--s-3);
  min-height: 48px; padding: 0 var(--s-3);
  border-radius: var(--r-sm); text-decoration: none;
  color: var(--ink-2); font-size: var(--fs-md); font-weight: 500;
}
.navsheet-nav a:hover { background: var(--surface-3); color: var(--ink); }
.navsheet-nav a[aria-current="page"] {
  background: var(--accent-weak); color: var(--accent); font-weight: 600;
}
.navsheet-nav .ico { color: var(--ink-3); }
.navsheet-nav a[aria-current="page"] .ico { color: var(--accent); }
.navsheet-go { margin-inline-start: auto; width: 16px; height: 16px; color: var(--line-strong); }
html[dir="rtl"] .navsheet-go { transform: scaleX(-1); }

body.navsheet-open { overflow: hidden; }

/* ----------------------------------------------------------------- toasts */
.toast-error { background: var(--danger); color: #fff; }

/* --------------------------------------------------- RTL directional icons */
/* Arrows follow the reading direction; a check or a gear never mirrors. */
html[dir="rtl"] .ico-flip { transform: scaleX(-1); }

/* ========================================================= search overlay */
.so { position: fixed; inset: 0; z-index: var(--z-panel); }
.so-scrim {
  position: absolute; inset: 0;
  background: color-mix(in srgb, var(--navy) 58%, transparent);
  backdrop-filter: blur(3px);
  animation: fade-in var(--dur-2) var(--ease);
}
.so-panel {
  position: relative;
  width: min(760px, calc(100vw - var(--s-8)));
  max-height: min(78vh, 720px);
  margin: clamp(var(--s-8), 9vh, var(--s-20)) auto 0;
  display: flex; flex-direction: column;
  background: var(--surface-over);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-4);
  overflow: hidden;
  animation: so-in var(--dur-3) var(--ease-soft);
}
@keyframes so-in { from { opacity: 0; transform: translateY(-10px) scale(.99); } }
@media (prefers-reduced-motion: reduce) {
  .so-panel, .so-scrim { animation: none; }
}

.so-bar {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  border-block-end: 1px solid var(--line-soft);
}
.so-icon { color: var(--ink-3); flex: none; }
.so-bar input {
  flex: 1 1 auto; min-width: 0;
  border: 0; background: none; outline: none;
  font-size: 1.05rem; color: var(--ink);
}
.so-bar input::placeholder { color: var(--ink-3); }
.so-bar input::-webkit-search-cancel-button { display: none; }

.so-filters {
  display: flex; align-items: center; gap: var(--s-4);
  padding: var(--s-3) var(--s-4);
  border-block-end: 1px solid var(--line-soft);
  background: var(--surface-2);
}
.so-status {
  font-size: var(--fs-xs); color: var(--ink-3);
  display: flex; align-items: center; gap: var(--s-2);
  margin-inline-start: auto;
}
.so-status b { color: var(--accent); font-weight: 600; }

.so-results { flex: 1 1 auto; overflow-y: auto; padding: var(--s-3) var(--s-3) var(--s-4); }
.so-results:focus-visible { outline: none; }

.so-label {
  display: flex; align-items: center; gap: var(--s-2);
  font-size: var(--fs-2xs); font-weight: 600; color: var(--ink-3);
  padding: var(--s-4) var(--s-3) var(--s-2);
}
.so-label .ico { color: var(--accent); }

.so-list, .so-recent { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.so-list a, .so-recent button {
  display: block; width: 100%; text-align: start;
  padding: var(--s-3); border-radius: var(--r-sm);
  text-decoration: none; color: inherit;
  transition: background var(--dur-1) var(--ease);
}
.so-list a:hover, .so-list a:focus-visible,
.so-recent button:hover, .so-recent button:focus-visible {
  background: var(--surface-3);
}
.so-recent button { display: flex; align-items: center; gap: var(--s-2); font-size: var(--fs-sm); color: var(--ink-2); }
.so-recent .ico { color: var(--ink-3); }

.so-ctx {
  display: flex; align-items: baseline; gap: var(--s-2);
  font-size: var(--fs-2xs); color: var(--ink-3); margin-block-end: var(--s-1);
}
.so-tag {
  color: var(--accent); font-weight: 600; white-space: nowrap;
  padding-inline-end: var(--s-2);
  border-inline-end: 1px solid var(--line);
}
.so-snip {
  display: block; font-family: var(--font-read);
  font-size: 1.02rem; line-height: 1.85; color: var(--ink-2);
}
.so-snip mark {
  background: var(--mark); color: var(--mark-ink);
  padding: 0 .15em; border-radius: 2px; font-weight: 700;
}
.so-more { padding: var(--s-3); font-size: var(--fs-xs); color: var(--ink-3); }

.so-hint {
  display: flex; flex-direction: column; align-items: center; gap: var(--s-2);
  padding: var(--s-12) var(--s-6); text-align: center; color: var(--ink-3);
}
.so-hint .ico { width: 28px; height: 28px; color: var(--line-strong); stroke-width: 1.5; }
.so-hint p { font-size: var(--fs-sm); max-width: 44ch; }
.so-hint-sm { font-size: var(--fs-xs) !important; color: var(--ink-3); }

.so-foot {
  display: flex; gap: var(--s-4); flex-wrap: wrap;
  padding: var(--s-2) var(--s-4);
  border-block-start: 1px solid var(--line-soft);
  background: var(--surface-2);
  font-size: var(--fs-2xs); color: var(--ink-3);
}
.so-foot span { display: inline-flex; align-items: center; gap: var(--s-1); }
kbd {
  font-family: var(--font-ui); font-size: .7rem; line-height: 1;
  padding: 3px 5px; border: 1px solid var(--line);
  border-block-end-width: 2px; border-radius: var(--r-xs);
  background: var(--surface); color: var(--ink-2);
}
body.so-open { overflow: hidden; }

@media (max-width: 640px) {
  .so-panel {
    width: 100vw; max-height: 100dvh; height: 100dvh;
    margin: 0; border-radius: 0; border: 0;
  }
  .so-foot { display: none; }
}
