/* ==========================================================================
   base.css — tokens, reset, typography
   Simon Cambier — « L'architecte des systèmes »
   ========================================================================== */

/* ---------- Tokens ---------- */
:root {
  color-scheme: dark;

  --bg: #0c0d0f;
  --surface: #141519;
  --surface-2: #1a1b20;
  --line: #24262c;
  --line-strong: #34363d;
  --text: #ece9e2;
  --text-2: #9a9890;
  --text-3: #6b6a64;
  --accent: #ff4d1f;
  --accent-soft: rgba(255, 77, 31, 0.12);
  --accent-ink: #0c0d0f;
  --ok: #4ad38a;
  --error: #ff6b6b;

  --font-display: "Inter Tight", "Inter", system-ui, sans-serif;
  --font-serif: "Instrument Serif", Georgia, serif;
  --font-body: "Inter", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

  /* Modular scale, ratio 1.25, base 17px */
  --fs--2: 0.6875rem;  /* ~11px */
  --fs--1: 0.8125rem;  /* 13px */
  --fs-0: 1.0625rem;   /* 17px */
  --fs-1: 1.328rem;    /* 21px */
  --fs-2: 1.66rem;     /* 27px */
  --fs-3: 2.075rem;    /* 33px */
  --fs-4: 2.594rem;    /* 41px */
  --fs-5: 3.242rem;    /* 52px */
  --fs-6: 4.053rem;    /* 65px */
  --fs-hero: clamp(2.6rem, 7.6vw, 9.5rem);
  --fs-title: clamp(2rem, 5.2vw, 5.5rem);
  --fs-section: clamp(1.6rem, 3.4vw, 3.4rem);

  --lh-tight: 0.95;
  --lh-snug: 1.15;
  --lh-body: 1.6;

  --track-tight: -0.035em;
  --track-mono: 0.08em;

  /* 8px spacing system */
  --s-1: 0.5rem;
  --s-2: 1rem;
  --s-3: 1.5rem;
  --s-4: 2rem;
  --s-5: 3rem;
  --s-6: 4rem;
  --s-7: 6rem;
  --s-8: 8rem;
  --s-9: 12rem;

  --gutter: clamp(1.25rem, 3.5vw, 4rem);
  --section-y: clamp(4rem, 9vw, 10rem);

  --radius: 4px;
  --ease: cubic-bezier(0.2, 0.7, 0, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --dur: 600ms;
  --dur-fast: 220ms;

  --header-h: 4.5rem;
  --focus: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f3ef;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --line: #dedcd5;
  --line-strong: #c8c6be;
  --text: #121316;
  --text-2: #5e5d58;
  --text-3: #8a8983;
  --accent-ink: #ffffff;
  --accent-soft: rgba(255, 77, 31, 0.1);
}

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

* {
  margin: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h) + 1rem);
  background: var(--bg);
}

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

body {
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--fs-0);
  line-height: var(--lh-body);
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: clip;
  transition: background-color 300ms var(--ease), color 300ms var(--ease);
}

img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
}

img {
  height: auto;
}

input,
button,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

ul,
ol {
  list-style: none;
  padding: 0;
}

address {
  font-style: normal;
}

hr {
  border: 0;
  border-top: 1px solid var(--line);
}

p,
h1,
h2,
h3,
h4,
h5,
h6 {
  overflow-wrap: break-word;
}

h1,
h2,
h3,
h4 {
  text-wrap: balance;
}

p,
li,
blockquote {
  text-wrap: pretty;
}

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

:focus {
  outline: none;
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus);
  border-radius: var(--radius);
}

/* ---------- Typography ---------- */
.display,
h1,
h2,
h3 {
  font-family: var(--font-display);
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: var(--lh-snug);
}

h1 {
  font-size: var(--fs-title);
  letter-spacing: var(--track-tight);
  line-height: var(--lh-tight);
  font-weight: 500;
}

h2 {
  font-size: var(--fs-section);
  letter-spacing: -0.03em;
  line-height: 1.05;
}

h3 {
  font-size: var(--fs-1);
  font-weight: 500;
}

.serif {
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 400;
  letter-spacing: -0.01em;
}

.serif.accent,
.word-accent {
  color: var(--accent);
}

.mono,
.label,
.tag,
.pill,
.eyebrow {
  font-family: var(--font-mono);
  font-weight: 400;
  font-size: var(--fs--1);
  letter-spacing: var(--track-mono);
  text-transform: uppercase;
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
}

.mono-num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.lead {
  font-size: var(--fs-1);
  line-height: 1.5;
  color: var(--text-2);
  max-width: 60ch;
}

.muted {
  color: var(--text-2);
}

.prose {
  max-width: 68ch;
}

.prose p + p {
  margin-top: var(--s-2);
}

.prose h3 {
  margin-top: var(--s-4);
  margin-bottom: var(--s-1);
}

.text-link {
  position: relative;
  text-decoration: none;
  background-image: linear-gradient(currentColor, currentColor);
  background-size: 100% 1px;
  background-repeat: no-repeat;
  background-position: 0 100%;
  transition: background-size var(--dur-fast) var(--ease), color var(--dur-fast);
}

.text-link:hover {
  background-size: 0 1px;
  background-position: 100% 100%;
  color: var(--accent);
}

/* ---------- Grid & layout ---------- */
.grid-12 {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  column-gap: var(--s-3);
  row-gap: var(--s-4);
}

.section {
  position: relative;
  padding-inline: var(--gutter);
  padding-block: var(--section-y);
}

.section--tight {
  padding-block: var(--s-6);
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s-3);
  padding-bottom: var(--s-2);
  border-bottom: 1px solid var(--line);
  margin-bottom: clamp(2rem, 5vw, 4rem);
}

.section-head .index {
  color: var(--text-2);
}

.section-head .index b {
  color: var(--text);
  font-weight: 500;
}

.section-head .coord {
  color: var(--text-3);
}

.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Fine background grid */
.page-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    linear-gradient(to right, var(--line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--line) 1px, transparent 1px);
  background-size: calc(100% / 12) 100%, 100% 160px;
  opacity: 0.35;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.9), rgba(0, 0, 0, 0.2) 60%, transparent);
  -webkit-mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.9), rgba(0, 0, 0, 0.2) 60%, transparent);
}

main {
  position: relative;
  z-index: 1;
}

/* Grain overlay for images */
.grain {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
}

.grain::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.18;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/><feColorMatrix type='saturate' values='0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

.grain img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ---------- Motion utilities ---------- */
.reveal {
  opacity: 0;
  transform: translateY(24px);
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
  transition-delay: var(--delay, 0ms);
}

.reveal.is-visible {
  opacity: 1;
  transform: none;
}

@supports (animation-timeline: view()) {
  .reveal {
    opacity: 1;
    transform: none;
    transition: none;
    animation: reveal-in linear both;
    animation-timeline: view();
    animation-range: entry 0% entry 35%;
  }

  @keyframes reveal-in {
    from {
      opacity: 0;
      transform: translateY(24px);
    }
    to {
      opacity: 1;
      transform: none;
    }
  }
}

/* Mask reveal for hero words */
.mask-word {
  display: inline-block;
  overflow: hidden;
  vertical-align: bottom;
  padding: 0.06em 0.04em 0.18em;
  margin: -0.06em -0.04em -0.18em;
}

.mask-word > span {
  display: inline-block;
  transform: translateY(110%);
  animation: rise var(--dur) var(--ease) forwards;
  animation-delay: calc(var(--i, 0) * 70ms + 120ms);
}

@keyframes rise {
  to {
    transform: translateY(0);
  }
}

.page-enter {
  animation: page-in 500ms var(--ease) both;
}

.page-leave {
  animation: page-out 320ms var(--ease) forwards;
}

@keyframes page-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes page-out {
  to {
    opacity: 0;
    transform: translateY(-10px);
  }
}

@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;
  }

  .reveal {
    opacity: 1;
    transform: none;
  }

  .mask-word > span {
    transform: none;
    animation: none;
  }
}

/* View transition circular theme reveal */
::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
  mix-blend-mode: normal;
}

::view-transition-new(root) {
  animation: theme-reveal 600ms var(--ease);
}

@keyframes theme-reveal {
  from {
    clip-path: circle(0% at var(--vt-x, 50%) var(--vt-y, 50%));
  }
  to {
    clip-path: circle(150% at var(--vt-x, 50%) var(--vt-y, 50%));
  }
}
