/* ==========================================================================
   Portfolio 3.0: base: tokens, type, reset, global shell
   ========================================================================== */

@font-face {
  font-family: "Archivo";
  src: url("/fonts/archivo-latin-wdth-normal.woff2") format("woff2");
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Newsreader";
  src: url("/fonts/newsreader-latin-opsz-italic.woff2") format("woff2");
  font-weight: 200 800;
  font-style: italic;
  font-display: swap;
}

:root {
  /* Palette: warm paper, ink, neutral greys, a single Klein accent */
  --paper: #eeebe4;
  --paper-2: #e5e1d8;
  --paper-3: #d8d3c8;
  --ink: #131312;
  --ink-2: #3b3a36;
  --grey: #74716a;
  --line: rgb(19 19 18 / 0.16);
  --space: #0b0b0c;
  --klein: #0a33b8;
  --klein-bright: #4467ff;

  /* Surface-driven foreground (switched by [data-surface]) */
  --fg: var(--ink);
  --fg-muted: var(--grey);
  --fg-line: var(--line);

  --font-sans: "Archivo", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-serif: "Newsreader", Georgia, "Times New Roman", serif;

  /* Grid */
  --margin: clamp(20px, 3.4vw, 56px);
  --gutter: clamp(12px, 1.6vw, 24px);
  --cols: 12;
  --header-h: 64px;

  /* Type scale */
  --fs-label: 11px;
  --fs-small: 13px;
  --fs-body: clamp(16px, 1.08vw, 18px);
  --fs-lead: clamp(20px, 1.9vw, 30px);
  --fs-h3: clamp(40px, 5.4vw, 96px);
  --fs-h2: clamp(56px, 9vw, 168px);

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
}

:root[data-surface="dark"] {
  --fg: #f1eee8;
  --fg-muted: #9a978f;
  --fg-line: rgb(241 238 232 / 0.2);
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--paper);
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  font-stretch: 100%;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

img, video, canvas, svg { display: block; max-width: 100%; }
img, video { height: auto; }
figure, p, h1, h2, h3, h4, dl, dd, ol, ul { margin: 0; }
ol, ul { padding: 0; list-style: none; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
em, i { font-family: var(--font-serif); font-style: italic; font-weight: 350; }

::selection { background: var(--klein); color: #fff; }

:focus-visible {
  outline: 2px solid var(--klein-bright);
  outline-offset: 4px;
  border-radius: 1px;
}

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

/* --- Type primitives -------------------------------------------------- */

.label {
  font-size: var(--fs-label);
  line-height: 1.35;
  font-weight: 500;
  font-stretch: 100%;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.serif { font-family: var(--font-serif); font-style: italic; font-weight: 350; }

.grid {
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  column-gap: var(--gutter);
  padding-inline: var(--margin);
}

/* --- Skip link --------------------------------------------------------- */

.skip-link {
  position: fixed;
  top: 12px; left: 12px;
  z-index: 100;
  padding: 12px 16px;
  background: var(--ink);
  color: var(--paper);
  font-size: var(--fs-small);
  transform: translateY(-160%);
  transition: transform 0.2s var(--ease-out);
}
.skip-link:focus { transform: none; }

/* --- Header ------------------------------------------------------------ */

.site-header {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 50;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: var(--gutter);
  padding-inline: var(--margin);
  color: var(--fg);
  transition: color 0.5s var(--ease-out), transform 0.5s var(--ease-out), background-color 0.3s linear;
  pointer-events: none;
}
.site-header > * { pointer-events: auto; }

/* Past the prologue the header becomes a quiet paper bar and steps aside while reading. */
.site-header.is-solid {
  background: var(--paper);
  box-shadow: 0 1px 0 var(--line);
  pointer-events: auto;
}
:root[data-surface="dark"] .site-header.is-solid { background: transparent; box-shadow: none; }
.site-header.is-hidden { transform: translateY(-100%); }
.site-header:focus-within { transform: none; }

.wordmark {
  font-size: var(--fs-small);
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.header-chapter {
  margin-left: clamp(16px, 6vw, 120px);
  color: var(--fg-muted);
  transition: color 0.5s var(--ease-out);
  white-space: nowrap;
}
.header-chapter b { font-weight: 500; color: var(--fg); }

.primary-nav {
  margin-left: auto;
  display: flex;
  gap: clamp(14px, 2.2vw, 36px);
}

.primary-nav a,
.lang-switch button,
.menu-toggle {
  position: relative;
  padding-block: 8px;
}

.primary-nav a::after,
.lang-switch button::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 3px;
  height: 1px;
  background: currentColor;
  transform: scaleX(0);
  transform-origin: right;
  transition: transform 0.45s var(--ease-out);
}
.primary-nav a:hover::after,
.primary-nav a[aria-current="true"]::after,
.lang-switch button[aria-pressed="true"]::after {
  transform: scaleX(1);
  transform-origin: left;
}

.lang-switch {
  display: flex;
  gap: 10px;
  padding-left: clamp(14px, 2vw, 28px);
  border-left: 1px solid var(--fg-line);
}
.lang-switch button { color: var(--fg-muted); }
.lang-switch button[aria-pressed="true"] { color: var(--fg); }

.menu-toggle { display: none; margin-left: auto; }

/* --- Mobile menu ------------------------------------------------------- */

.menu {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 32px;
  padding: calc(var(--header-h) + 24px) var(--margin) 32px;
  background: var(--paper);
  color: var(--ink);
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.35s var(--ease-out), visibility 0s linear 0.35s;
}
.menu.is-open {
  visibility: visible;
  opacity: 1;
  transition: opacity 0.35s var(--ease-out);
}
.menu__universes li { border-top: 1px solid var(--line); }
.menu__universes a,
.menu__universes span {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding-block: 12px;
  font-size: clamp(24px, 7vw, 40px);
  font-stretch: 75%;
  font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1;
}
.menu__universes span { color: var(--grey); }
.menu__universes small { font-size: var(--fs-label); font-stretch: 100%; letter-spacing: 0.08em; text-transform: uppercase; color: var(--grey); }
.menu__links { display: flex; gap: 24px; font-size: var(--fs-small); }

/* --- Journey map ------------------------------------------------------- */

.journey-map {
  position: fixed;
  right: var(--margin);
  top: 50%;
  z-index: 40;
  transform: translateY(-50%);
  color: var(--fg);
  transition: color 0.5s var(--ease-out), opacity 0.4s var(--ease-out);
}
.is-reading .journey-map { opacity: 0.18; }
.is-reading .journey-map:hover,
.is-reading .journey-map:focus-within { opacity: 1; }
.journey-map ol { display: grid; gap: 7px; }
.journey-map li { display: block; }
.journey-map a,
.journey-map span[aria-disabled] {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fg-muted);
  transition: color 0.3s var(--ease-out);
}
.journey-map span[aria-disabled] { opacity: 0.55; cursor: default; }
.journey-map a:hover,
.journey-map a[aria-current="step"] { color: var(--fg); }
.journey-map .jm-label {
  opacity: 0;
  transform: translateX(6px);
  transition: opacity 0.3s var(--ease-out), transform 0.3s var(--ease-out);
}
.journey-map:hover .jm-label,
.journey-map:focus-within .jm-label,
.journey-map [aria-current="step"] .jm-label { opacity: 1; transform: none; }
.jm-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  border: 1px solid currentColor;
  flex: none;
  transition: background-color 0.3s var(--ease-out), transform 0.3s var(--ease-out);
}
.journey-map [aria-current="step"] .jm-dot { background: currentColor; transform: scale(1.15); }

/* --- Small screens ----------------------------------------------------- */

@media (max-width: 900px) {
  :root { --header-h: 56px; }
  .primary-nav, .lang-switch.in-header { display: none; }
  .menu-toggle { display: block; }
  .header-chapter { margin-left: auto; }
  .header-chapter + .menu-toggle { margin-left: 18px; }
  .journey-map { display: none; }
}

@media (min-width: 901px) {
  .menu { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
