/* elOS shared foundation: tokens, fonts, base, buttons, header, footer and
   notices dialog, display preferences. Ported by hand from the prototype's
   design system (elos-design-system/styles/). templates/DESIGN.md documents
   every token; scripts/check_site.py lints this folder against it. */

/* --- Tokens ---------------------------------------------------------------
   The only place for colour literals and raw sizes. Everything below uses
   var(--…). Breakpoints can't be custom properties in @media, so they are
   listed in DESIGN.md and in check_site.py (BREAKPOINTS). */

:root {
  /* Palette (prototype tokens.css) */
  --pine: #244236;
  --purple: #55417f;
  --purple-bright: #7943d5;
  --lime: #b6d34c;
  --lime-hover: #c5df6e;
  --lime-soft: #e2ecb3;   /* lime 40 % on cream: the current nav item */
  --cream: #fffdf7;
  --ink: #18382e;
  --muted: #4b6054;
  --line: #dce1d5;
  --branch: #9887ad;

  /* Dark surfaces: footer and notices dialog */
  --night: #101e19;
  --night-text: #becdbf;
  --night-link: #c7d0c4;
  --night-body: #e3ebdf;
  --night-line: #fffdf755;
  --dialog-line: #aaba9b77;
  --backdrop: #0a1713b3;

  /* Translucent pine and cream (borders, hover fills, the header glass) */
  --pine-a7: #24423612;
  --pine-a20: #24423633;
  --glass-start: #fffdf79e;
  --glass-end: #d3dba38a;
  --glass-solid: #fffdf7df;
  --glass-highlight: #ffffff44;

  /* Focus */
  --focus-ring: var(--purple);
  --focus-ring-on-dark: var(--lime);
  --focus-width: 3px;
  --focus-offset: 4px;

  /* Spacing scale, 4 px base */
  --space-1: 0.25rem;  /*  4px */
  --space-2: 0.5rem;   /*  8px */
  --space-3: 0.75rem;  /* 12px */
  --space-4: 1rem;     /* 16px */
  --space-5: 1.5rem;   /* 24px */
  --space-6: 2rem;     /* 32px */
  --space-7: 3rem;     /* 48px */
  --space-8: 4rem;     /* 64px */
  --space-9: 6rem;     /* 96px */
  --space-10: 8rem;    /* 128px */

  /* Section rhythm */
  --section-space: clamp(var(--space-8), 4rem + 3vw, var(--space-9));

  /* Type */
  --font-body: 'Avenir Next', Avenir, Inter, 'Inter fallback', Arial, sans-serif;
  --font-heading: var(--font-body);
  --text-xs: 0.75rem;     /* 12px: footer small print */
  --text-sm: 0.8125rem;   /* 13px: header links, footer links */
  --text-md: 0.875rem;    /* 14px: menus, captions, meta */
  --text-base: 1rem;      /* 16px: minimum for body text */
  --text-body: clamp(1rem, 0.96rem + 0.18vw, 1.0625rem);    /* 16 → 17 */
  --text-prose: clamp(1rem, 0.93rem + 0.36vw, 1.125rem);    /* 16 → 18 */
  --text-lead: clamp(1.125rem, 1.05rem + 0.36vw, 1.25rem);  /* 18 → 20 */
  --text-icon: 1.375rem;  /* 22px: button arrows */
  --text-h4: 1.1875rem;   /* 19px: panel titles */
  --text-h3: clamp(1.25rem, 1.1rem + 0.7vw, 1.625rem);      /* 20 → 26 */
  --text-h2-prose: clamp(1.5rem, 1.3rem + 0.9vw, 2rem);     /* 24 → 32 */
  --text-dialog-title: clamp(1.5625rem, 1.45rem + 0.5vw, 1.8125rem); /* 25 → 29 */
  --text-h2: clamp(2rem, 1.4rem + 2.2vw, 2.875rem);         /* 32 → 46 */
  --text-h1: clamp(2.25rem, 1.4rem + 3.6vw, 4rem);          /* 36 → 64 */
  --leading-tight: 1.1;
  --leading-heading: 1.16;
  --leading-body: 1.6;
  --leading-prose: 1.75;
  --tracking-body: 0.012em;
  --tracking-ui: 0.025em;
  --tracking-display: -0.03em;
  --measure: 66ch;

  /* Layout */
  --page-max-width: 1280px;
  --gutter: var(--space-4);
  --header-max-width: 880px;
  --header-height: 54px;
  --header-offset: var(--space-3);
  --header-clearance: calc(var(--header-offset) + var(--header-height) + var(--space-8));
  --control-min-height: 52px;
  --target-min: 44px;
  --panel-width: 285px;
  --language-panel-width: 225px;
  --dialog-width: 640px;
  --logo-width: 82px;
  --logo-width-compact: 64px;

  /* Radii, borders, shadows */
  --radius-sm: 9px;
  --radius-md: 12px;
  --radius-button: 14px;
  --radius-lg: 18px;
  --radius-xl: 22px;
  --radius-dialog: 24px;
  --radius-pill: 999px;
  --border-hairline: 1px solid var(--pine-a20);
  --border-strong: 2px solid var(--pine);
  --shadow-button: 0 3px 14px #0b291b14;
  --shadow-header: inset 0 1px 0 var(--glass-highlight), 0 8px 24px #10261f14;
  --shadow-header-scrolled: 0 10px 35px #10261f1a, inset 0 1px 0 #ffffff66;
  --shadow-panel: 0 15px 35px #18382e24;
  --shadow-dialog: 0 25px 80px #00000055;

  /* Motion */
  --duration-fast: 150ms;
  --duration-base: 200ms;
  --duration-slow: 300ms;
  --ease: ease;

  /* Recolours the white logo SVG to pine. */
  --logo-filter: brightness(0) saturate(100%) invert(21%) sepia(14%) saturate(1086%)
    hue-rotate(104deg) brightness(91%) contrast(88%);
}

@media (min-width: 540px) {
  :root {
    --gutter: var(--space-5);
  }
}

@media (min-width: 1024px) {
  :root {
    --gutter: var(--space-7);
  }
}

/* "Stronger contrast" preference: muted greys become full ink. */
html.high-contrast {
  --muted: var(--ink);
  --night-text: var(--cream);
  --night-link: var(--cream);
  --night-body: var(--cream);
  --pine-a20: var(--pine);
}

/* --- Fonts ----------------------------------------------------------------
   Latin-subset variable fonts, self-hosted (OFL, see assets/fonts/). The
   "fallback" faces are Arial scaled to each font's metrics, so text doesn't
   jump when the web font swaps in. */

@font-face {
  font-family: Inter;
  src: url(/assets/fonts/inter-latin-wght-normal.woff2?v=1) format('woff2');
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
}

@font-face {
  font-family: 'Inter fallback';
  src: local('Arial'), local('ArialMT');
  size-adjust: 107%;
  ascent-override: 90.5%;
  descent-override: 22.5%;
  line-gap-override: 0%;
}

/* --- Base ------------------------------------------------------------------ */

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-offset) + var(--header-height) + var(--space-5));
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* The footer stays at the bottom of short pages. */
body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--cream);
  font-family: var(--font-body);
  font-size: var(--text-body);
  line-height: var(--leading-body);
  letter-spacing: var(--tracking-body);
}

figure,
h1,
h2,
h3,
h4,
p {
  margin: 0;
}

h1,
h2,
h3,
h4 {
  font-family: var(--font-heading);
  font-weight: 600;
  line-height: var(--leading-heading);
  letter-spacing: 0.005em;
  text-wrap: balance;
  hyphens: auto;
}

h1 {
  font-size: var(--text-h1);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-display);
}

h2 {
  font-size: var(--text-h2);
}

p {
  font-size: var(--text-body);
  text-wrap: pretty;
}

a,
button,
h1,
h2,
h3,
h4,
p,
li,
small {
  overflow-wrap: anywhere;
}

a,
button,
summary {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: inherit;
  text-underline-offset: 5px;
}

button {
  font: inherit;
}

img,
svg {
  max-width: 100%;
}

:is(a, button, summary, input, [tabindex]:not([tabindex='-1'])):focus-visible {
  outline: var(--focus-width) solid var(--focus-ring);
  outline-offset: var(--focus-offset);
}

#main {
  flex: 1 0 auto;
}

[tabindex='-1']:focus {
  outline: none;
}

[hidden] {
  display: none !important;
}

.container {
  width: min(100% - 2 * var(--gutter), var(--page-max-width));
  margin-inline: auto;
}

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

.skip-link {
  position: fixed;
  top: var(--space-3);
  left: var(--space-3);
  z-index: 20;
  padding: var(--space-3) var(--space-4);
  border: var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--cream);
  color: var(--pine);
  font-weight: 600;
  transform: translateY(-200%);
}

.skip-link:focus {
  transform: none;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  ::after,
  ::before {
    animation: none !important;
    transition: none !important;
  }
}

html.reduce-motion {
  scroll-behavior: auto;
}

html.reduce-motion *,
html.reduce-motion ::after,
html.reduce-motion ::before {
  animation: none !important;
  transition: none !important;
  scroll-behavior: auto !important;
}

/* --- Buttons --------------------------------------------------------------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-5);
  max-width: 100%;
  min-height: var(--control-min-height);
  padding: var(--space-3) var(--space-5);
  border: 0;
  border-radius: var(--radius-button);
  font-size: var(--text-md);
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: var(--tracking-ui);
  text-decoration: none;
  cursor: pointer;
  transition:
    background-color var(--duration-fast) var(--ease),
    color var(--duration-fast) var(--ease),
    transform var(--duration-fast) var(--ease);
}

.button > span {
  flex-shrink: 0;
  font-size: var(--text-icon);
  line-height: 1;
}

.button:hover {
  transform: translateY(-1px);
}

.button:active {
  transform: translateY(1px);
}

.button:disabled,
.button[aria-disabled='true'] {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.button-lime {
  background: var(--lime);
  color: var(--ink);
}

.button-lime:hover {
  background: var(--lime-hover);
}

.button-pine {
  background: var(--pine);
  color: var(--cream);
  box-shadow: var(--shadow-button);
}

.button-pine:hover {
  background: var(--purple-bright);
  color: var(--cream);
}

/* --- Header ----------------------------------------------------------------
   A fixed glass pill. Below 768 px the links move into the native <details>
   "Menu"; every control works without JavaScript. */

#site-header {
  position: fixed;
  top: var(--header-offset);
  left: 50%;
  z-index: 10;
  width: min(100% - 2 * var(--gutter), var(--header-max-width));
  padding-inline: var(--space-3);
  border: var(--border-hairline);
  border-radius: var(--radius-xl);
  background: linear-gradient(110deg, var(--glass-start), var(--glass-end));
  box-shadow: var(--shadow-header);
  color: var(--pine);
  transform: translateX(-50%);
  -webkit-backdrop-filter: blur(22px);
  backdrop-filter: blur(22px);
  transition:
    background-color var(--duration-base) var(--ease),
    box-shadow var(--duration-base) var(--ease);
}

#site-header.is-scrolled {
  background: var(--glass-solid);
  box-shadow: var(--shadow-header-scrolled);
}

html.high-contrast #site-header {
  border: var(--border-strong);
  background: var(--cream);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  min-height: var(--header-height);
}

.brand {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  min-height: var(--target-min);
  border-radius: var(--radius-sm);
}

.brand img {
  display: block;
  width: var(--logo-width-compact);
  height: auto;
  filter: var(--logo-filter);
}

#main-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-1);
  min-width: 0;
}

#main-nav > a {
  display: none;
}

#main-nav > a:not(.button) {
  align-items: center;
  min-height: var(--target-min);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-pill);
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: var(--tracking-ui);
  text-decoration: none;
  white-space: nowrap;
  transition:
    background-color var(--duration-base) var(--ease),
    color var(--duration-base) var(--ease);
}

#main-nav > a:not(.button):hover {
  background: var(--pine);
  color: var(--cream);
}

/* The current page or section (prototype): a light lime pill, bold, with a
   small dot after the word; hover turns it pine and the dot lime. Articles
   mark Blog with aria-current="true", the blog index with "page". */
#main-nav > a[aria-current] {
  font-weight: 700;
}

#main-nav > a[aria-current]:not(:hover) {
  background: var(--lime-soft);
}

#main-nav > a[aria-current]::after {
  content: '';
  width: 5px;
  height: 5px;
  margin-left: var(--space-2);
  border-radius: 50%;
  background: currentColor;
}

#main-nav > a[aria-current]:hover::after {
  background: var(--lime);
}

#main-nav > .button {
  min-height: var(--target-min);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-pill);
  font-size: var(--text-sm);
  font-weight: 650;
  white-space: nowrap;
}

#main-nav > a:active,
.compact-navigation summary:active,
.display-preferences summary:active,
.language-selector summary:active {
  transform: translateY(1px);
}

/* Compact menu (below 768 px) */
.compact-navigation {
  position: static;
  color: var(--pine);
}

.compact-navigation summary,
.display-preferences summary,
.language-selector summary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  min-width: var(--target-min);
  min-height: var(--target-min);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: 650;
  white-space: nowrap;
  list-style: none;
  cursor: pointer;
  transition:
    background-color var(--duration-base) var(--ease),
    color var(--duration-base) var(--ease);
}

.compact-navigation summary {
  font-size: var(--text-sm);
}

.compact-navigation summary::-webkit-details-marker,
.display-preferences summary::-webkit-details-marker,
.language-selector summary::-webkit-details-marker {
  display: none;
}

.compact-navigation summary svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.compact-navigation summary:hover,
.compact-navigation[open] summary,
.display-preferences summary:hover,
.language-selector summary:hover {
  background: var(--pine);
  color: var(--cream);
}

.display-preferences[open] summary,
.language-selector[open] summary {
  background: var(--pine-a7);
  color: var(--pine);
}

.compact-navigation-panel {
  position: absolute;
  top: calc(100% + var(--space-3));
  right: 0;
  display: grid;
  gap: var(--space-1);
  width: max-content;
  max-width: 100%;
  padding: var(--space-3);
  border: var(--border-hairline);
  border-radius: var(--radius-lg);
  background: var(--cream);
  box-shadow: var(--shadow-panel);
}

.compact-navigation-panel > a {
  display: flex;
  align-items: center;
  min-height: var(--target-min);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  color: var(--pine);
  font-size: var(--text-md);
  font-weight: 600;
  text-decoration: none;
}

.compact-navigation-panel > a:not(.button):hover,
.compact-navigation-panel > a[aria-current] {
  background: var(--pine-a7);
}

.compact-navigation-panel > .button {
  justify-content: flex-start;
  color: var(--cream);
}

@media (max-width: 379px) {
  .compact-navigation summary > span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}

@media (min-width: 768px) {
  #site-header {
    padding-inline: var(--space-4);
    border-radius: var(--radius-pill);
  }

  .header-inner {
    gap: var(--space-6);
  }

  .brand img {
    width: var(--logo-width);
  }

  #main-nav > a {
    display: inline-flex;
  }

  .compact-navigation {
    display: none;
  }
}

/* --- Footer and notices dialog -------------------------------------------- */

#site-footer {
  padding-block: var(--space-6);
  background: var(--night);
  color: var(--night-text);
  font-size: var(--text-xs);
}

#site-footer :is(a, button):focus-visible,
.notice-dialog :is(a, button):focus-visible {
  outline-color: var(--focus-ring-on-dark);
}

.footer-bottom {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* Copyright and the company, one under the other (prototype). */
.footer-company {
  display: grid;
  gap: var(--space-1);
}

.footer-company small {
  font-size: var(--text-xs);
  line-height: 1.6;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-5);
}

.footer-links :is(a, button) {
  display: inline-flex;
  align-items: center;
  min-height: var(--target-min);
  padding: 0;
  border: 0;
  background: none;
  color: var(--night-link);
  font: inherit;
  font-size: var(--text-sm);
  text-decoration: none;
  cursor: pointer;
  transition: color var(--duration-fast) var(--ease);
}

.footer-links :is(a, button):hover,
.footer-links a[aria-current='page'] {
  color: var(--lime);
}

.footer-links a[aria-current='page'] {
  text-decoration: underline;
}

.footer-social {
  display: flex;
  gap: var(--space-2);
}

.footer-social a {
  display: grid;
  place-items: center;
  width: var(--target-min);
  height: var(--target-min);
  border: 1px solid var(--night-line);
  border-radius: var(--radius-md);
  color: var(--night-link);
  transition:
    color var(--duration-fast) var(--ease),
    border-color var(--duration-fast) var(--ease);
}

.footer-social a:hover {
  border-color: var(--lime);
  color: var(--lime);
}

.footer-social svg {
  width: 20px;
  height: 20px;
}

@media (min-width: 768px) {
  .footer-bottom {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4) var(--space-6);
  }

  .footer-nav {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-4) var(--space-6);
  }
}

.notice-dialog {
  width: min(100% - 2 * var(--gutter), var(--dialog-width));
  max-height: 80vh;
  overflow: auto;
  padding: var(--space-5);
  border: 1px solid var(--dialog-line);
  border-radius: var(--radius-dialog);
  background: var(--pine);
  color: var(--cream);
  box-shadow: var(--shadow-dialog);
}

.notice-dialog::backdrop {
  background: var(--backdrop);
  -webkit-backdrop-filter: blur(5px);
  backdrop-filter: blur(5px);
}

.notice-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-5);
  margin-bottom: var(--space-5);
}

.notice-head h2 {
  font-size: var(--text-dialog-title);
}

.notice-close {
  flex-shrink: 0;
  width: var(--target-min);
  height: var(--target-min);
  border: 1px solid var(--night-line);
  border-radius: var(--radius-button);
  background: none;
  color: var(--cream);
  font-size: var(--text-icon);
  line-height: 1;
  cursor: pointer;
  transition: border-color var(--duration-fast) var(--ease);
}

.notice-close:hover {
  border-color: var(--lime);
}

.notice-body {
  color: var(--night-body);
  font-size: var(--text-base);
  line-height: var(--leading-prose);
}

.notice-body p + p {
  margin-top: var(--space-3);
}

.notice-links {
  display: grid;
  gap: var(--space-3);
  margin: var(--space-5) 0 0;
  padding: 0;
  list-style: none;
}

.notice-links a {
  color: var(--lime);
  line-height: 1.5;
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}

.notice-links a:hover {
  text-decoration-thickness: 2px;
}

.notice-contact {
  margin-top: var(--space-5);
  font-size: var(--text-base);
}

.notice-contact a {
  color: var(--lime);
}

@media (min-width: 540px) {
  .notice-dialog {
    padding: var(--space-6);
  }
}

/* --- Display preferences and language selector --------------------------- */

.display-preferences,
.language-selector {
  position: static;
  flex-shrink: 0;
  color: var(--pine);
}

.display-preferences summary svg {
  width: 23px;
  height: 23px;
  flex-shrink: 0;
}

.language-selector summary > svg {
  display: none;
}

.language-flag {
  font-size: var(--text-h4);
  line-height: 1;
}

.preferences-summary-label {
  display: none;
}

.preferences-panel {
  position: absolute;
  top: calc(100% + var(--space-3));
  right: 0;
  width: min(100%, var(--panel-width));
  max-height: calc(100dvh - var(--header-clearance));
  overflow: auto;
  padding: var(--space-5);
  border: var(--border-hairline);
  border-radius: var(--radius-xl);
  background: var(--cream);
  box-shadow: var(--shadow-panel);
  color: var(--ink);
  text-align: left;
}

html.high-contrast .preferences-panel,
html.high-contrast .compact-navigation-panel {
  border: var(--border-strong);
}

.preferences-panel h2 {
  margin-bottom: var(--space-3);
  font-size: var(--text-h4);
  letter-spacing: 0;
}

.preferences-panel > label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  min-height: var(--target-min);
  font-size: var(--text-md);
  cursor: pointer;
}

.preferences-panel input {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  margin: 0;
  accent-color: var(--pine);
}

.preferences-reset {
  min-height: var(--target-min);
  margin-top: var(--space-2);
  padding: 0;
  border: 0;
  background: none;
  color: var(--pine);
  font-size: var(--text-md);
  text-decoration: underline;
  text-underline-offset: 4px;
  cursor: pointer;
}

.preferences-reset:hover {
  color: var(--purple-bright);
}

.language-panel {
  width: min(100%, var(--language-panel-width));
}

.language-options {
  display: grid;
  gap: var(--space-1);
}

.language-options a {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--target-min);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-md);
  text-decoration: none;
  transition:
    background-color var(--duration-base) var(--ease),
    color var(--duration-base) var(--ease);
}

.language-options a[aria-current='page'] {
  background: var(--lime);
  font-weight: 650;
}

.language-options a:hover {
  background: var(--pine);
  color: var(--cream);
}

@media (min-width: 1024px) {
  .display-preferences,
  .language-selector {
    position: relative;
  }

  .preferences-panel,
  .language-panel {
    width: var(--panel-width);
  }

  .language-panel {
    width: var(--language-panel-width);
  }

  .preferences-summary-label {
    display: inline;
  }
}

/* "Larger text" preference: site.js stores each element's enlarged size. */
html.larger-text [style*='--readable-font-size'] {
  font-size: var(--readable-font-size) !important;
}
