:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --ink: #111111;
  --muted: #666666;
  --faint: #a3a3a3;
  --border: #e9e9e9;
  --border-strong: #d4d4d4;
  --soft: #f2f2f2;
  --trail: #e5484d;
  --level-lo: #2f9e6b;
  --level-hi: #e0605a;
  --done: #2f9e6b;
  --progress: #d9822b;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.06);
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Computer Modern Serif", "Computer Modern", "Latin Modern Roman", Georgia, serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --max: 1080px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0b0b;
    --surface: #141414;
    --ink: #ededed;
    --muted: #a1a1a1;
    --faint: #6b6b6b;
    --border: #232323;
    --border-strong: #333333;
    --soft: #1b1b1b;
    --trail: #ff5c61;
    --level-lo: #5ccf97;
    --level-hi: #ff8078;
    --done: #5ccf97;
    --progress: #f0a454;
    --shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0b0b0b;
  --surface: #141414;
  --ink: #ededed;
  --muted: #a1a1a1;
  --faint: #6b6b6b;
  --border: #232323;
  --border-strong: #333333;
  --soft: #1b1b1b;
  --trail: #ff5c61;
  --level-lo: #5ccf97;
  --level-hi: #ff8078;
  --done: #5ccf97;
  --progress: #f0a454;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

a { color: inherit; }

/* ---------- Hero ---------- */

.hero {
  position: relative;
  min-height: min(90vh, 780px);
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  cursor: crosshair;
}

.landscape {
  position: absolute;
  inset: 0;
}

.landscape canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* voile pour garder le texte lisible au-dessus du paysage */
.landscape::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(90deg, var(--bg) 0%, color-mix(in srgb, var(--bg) 85%, transparent) 32%, transparent 58%);
}

.hero-inner {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: var(--max);
  margin: 0 auto;
  padding: 6rem 1.5rem;
  pointer-events: none;
}

.hero-inner a { pointer-events: auto; }

.eyebrow {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 1.2rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.eyebrow::before {
  content: "";
  width: 1.6rem;
  height: 1px;
  background: currentColor;
}

.hero h1 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(2.8rem, 7.5vw, 4.8rem);
  letter-spacing: -0.02em;
  line-height: 1;
  margin: 0;
}

.hero .subtitle {
  font-size: 1rem;
  color: var(--muted);
  line-height: 1.7;
  max-width: 48ch;
  margin: 1.4rem 0 0;
}

.hero-links {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 2.2rem;
}

.social {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  color: var(--muted);
  text-decoration: none;
  transition: color 0.18s ease, background 0.18s ease;
}

.social svg { width: 1.1rem; height: 1.1rem; }

.social:hover {
  color: var(--ink);
  background: var(--soft);
}

.links-gap { width: 0.6rem; }

.cv {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  height: 2.2rem;
  padding: 0 0.95rem;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: var(--ink);
  text-decoration: none;
  font-size: 0.8rem;
  white-space: nowrap;
  transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}

.cv svg { width: 0.9rem; height: 0.9rem; flex-shrink: 0; }

.cv:hover {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}

/* Lecture en direct de f et ∇f */
.readout {
  position: absolute;
  right: max(1.5rem, calc((100vw - var(--max)) / 2 + 1.5rem));
  bottom: 1.5rem;
  z-index: 2;
  width: 16.5rem;
  padding: 0.8rem 1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface) 75%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  pointer-events: none;
}

.readout-row {
  display: flex;
  justify-content: space-between;
  line-height: 1.7;
}

.readout-label { font-family: var(--serif); font-style: italic; font-size: 0.9rem; }

.readout-value {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* Légende : la règle de mise à jour, sous les liens */
.legend {
  margin: 2.4rem 0 0;
  padding-left: 1rem;
  border-left: 1px solid var(--border-strong);
  max-width: 24rem;
}

.legend figcaption {
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 0.7rem;
}

.legend-note {
  margin: 0.6rem 0 0;
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--muted);
}

.eq {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.05rem;
  color: var(--ink);
}

.eq-line {
  display: flex;
  align-items: flex-start;
  gap: 0.3rem;
  line-height: 1.3;
  white-space: nowrap;
}

.eq-line + .eq-line { margin-top: 0.35rem; }

.eq-line sub { font-size: 0.68em; }

.term {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
}

.term-math {
  padding: 0 0.2rem;
  border-bottom: 1px solid var(--border-strong);
}

.term-inertia .term-math {
  color: var(--trail);
  border-bottom-color: var(--trail);
}

.term-label {
  margin-top: 0.15rem;
  font-family: var(--mono);
  font-style: normal;
  font-size: 0.6rem;
  letter-spacing: 0.04em;
  color: var(--faint);
}

.term-inertia .term-label { color: var(--trail); }

.eq-params {
  margin-top: 0.45rem;
  font-family: var(--mono);
  font-style: normal;
  font-size: 0.66rem;
  color: var(--faint);
}

.readout-hint {
  margin-top: 0.35rem;
  font-family: var(--sans);
  font-size: 0.72rem;
  line-height: 1.45;
  color: var(--faint);
}

/* ---------- Projets ---------- */

main {
  max-width: var(--max);
  margin: 0 auto;
  padding: 4.5rem 1.5rem 3rem;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.section-head h2 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 2rem;
  letter-spacing: -0.01em;
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
}

.count {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

.filters {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
}

.chip {
  font: inherit;
  font-size: 0.8rem;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 999px;
  padding: 0.4rem 0.9rem;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
}

.chip:hover { color: var(--ink); }

.chip.is-active {
  background: var(--ink);
  color: var(--bg);
}

.chip:focus-visible,
.card:focus-visible,
.cv:focus-visible,
.social:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 1rem;
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.2rem 1.3rem 1.3rem;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
  animation: rise 0.5s ease both;
}

.card[hidden] { display: none; }

.card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
  border-color: var(--border-strong);
}

.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.4rem;
}

.idx {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

.card h3 {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.15rem;
  line-height: 1.25;
  margin: 0 0 0.45rem;
  padding-right: 1.2rem;
}

.card p {
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.5;
  margin: 0;
}

.arrow {
  position: absolute;
  right: 1.2rem;
  bottom: 1.1rem;
  font-size: 1rem;
  color: var(--faint);
  opacity: 0;
  transform: translateX(-4px);
  transition: opacity 0.2s ease, transform 0.2s ease, color 0.2s ease;
}

.card:hover .arrow {
  opacity: 1;
  transform: none;
  color: var(--ink);
}

.status {
  flex-shrink: 0;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--muted);
  padding: 0.2rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.status-done::before { background: var(--done); }
.status-progress::before { background: var(--progress); animation: pulse 1.8s ease-in-out infinite; }

footer {
  max-width: var(--max);
  margin: 0 auto;
  padding: 2rem 1.5rem 3rem;
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--faint);
}

.foot-math { font-family: var(--serif); font-style: italic; font-size: 0.9rem; }

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@keyframes pulse {
  50% { opacity: 0.3; }
}

/* ---------- Mobile : le paysage passe sous le texte ---------- */

@media (max-width: 760px) {
  .hero {
    flex-direction: column;
    align-items: stretch;
    min-height: 0;
  }

  .hero-inner {
    order: 1;
    padding: 3.5rem 16px 1.5rem;
  }

  .landscape {
    order: 2;
    position: relative;
    margin: 0 16px 16px;
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
  }

  .landscape canvas { height: 340px; }

  .landscape::after { background: none; }

  /* sous le paysage plutôt que par-dessus */
  .readout {
    position: static;
    width: auto;
    border: 0;
    border-top: 1px solid var(--border);
    border-radius: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 1.2rem;
  }

  .readout-hint { grid-column: 1 / -1; }
  .legend { margin-top: 2rem; }

  main { padding: 3rem 16px 2rem; }
  footer { padding: 1.5rem 16px 2.5rem; }
  .grid { grid-template-columns: 1fr; }
  .arrow { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .card, .status-progress::before { animation: none; }
  * { transition: none !important; }
}
