/* Tokens : light-dark() suit color-scheme, que le bouton de thème force via data-theme */
:root {
  color-scheme: light dark;
  --bg: light-dark(#ffffff, #0d1117);
  --surface: light-dark(#f6f8fa, #161b22);
  --text: light-dark(#1f2328, #e6edf3);
  --muted: light-dark(#59636e, #9198a1);
  --border: light-dark(#d1d9e0, #30363d);
  --accent: light-dark(#016fb9, #5cb3f0);
  --accent-soft: light-dark(#e6f1fa, #10283b);
  --on-accent: light-dark(#ffffff, #0d1117);

  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --step-0: clamp(1rem, 0.96rem + 0.2vw, 1.125rem);
  --step-1: clamp(1.25rem, 1.15rem + 0.5vw, 1.5rem);
  --step-2: clamp(1.6rem, 1.4rem + 1vw, 2.2rem);
  --step-3: clamp(2.5rem, 1.9rem + 3vw, 4.5rem);
  --space: clamp(1rem, 0.8rem + 1vw, 1.5rem);
  --radius: 12px;
  --max: 64rem;
}

:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

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

html {
  scroll-padding-top: 5rem;
  -webkit-text-size-adjust: 100%;
}

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: var(--step-0) / 1.6 var(--font);
  text-rendering: optimizeLegibility;
}

h1, h2, h3 { line-height: 1.15; margin: 0; text-wrap: balance; }
p { margin: 0; text-wrap: pretty; }
ul, ol, dl, dd { margin: 0; padding: 0; }
ul, ol { list-style: none; }

a {
  color: var(--accent);
  text-underline-offset: 0.2em;
  &:hover { text-decoration-thickness: 2px; }
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}

.wrap {
  width: min(100% - 2rem, var(--max));
  margin-inline: auto;
}

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

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

.skip {
  position: absolute;
  left: 1rem;
  top: -3rem;
  z-index: 10;
  padding: 0.5rem 1rem;
  background: var(--accent);
  color: var(--on-accent);
  border-radius: var(--radius);
  &:focus { top: 1rem; }
}

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  gap: var(--space);
  min-height: 3.5rem;
}

.logo {
  font: 700 1.1rem var(--mono);
  color: var(--text);
  text-decoration: none;
  margin-right: auto;
}

nav ul {
  display: flex;
  gap: clamp(0.75rem, 2vw, 1.5rem);
}

nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.95rem;
  &:hover { color: var(--text); }
}

.theme-toggle {
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  &[hidden] { display: none; }
  &:hover { border-color: var(--accent); color: var(--accent); }
}

/* Hero */
.hero {
  display: grid;
  align-items: center;
  gap: 2rem 3rem;
  padding-block: clamp(4rem, 10vw, 8rem) clamp(3rem, 6vw, 5rem);
}

.eyebrow {
  font: 600 0.9rem var(--mono);
  color: var(--accent);
  letter-spacing: 0.02em;
}

h1 {
  font-size: var(--step-3);
  letter-spacing: -0.03em;
  margin-block: 0.5rem;
}

.stack-line {
  font: var(--step-1) var(--mono);
  color: var(--muted);
}

.lead {
  max-width: 38rem;
  margin-top: 1.5rem;
  font-size: var(--step-1);
  line-height: 1.5;
}

.cta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 2rem;
}

.btn {
  display: inline-block;
  padding: 0.65rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
  transition: border-color 0.2s, background-color 0.2s, translate 0.2s;
  &:hover { border-color: var(--accent); translate: 0 -2px; }
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  &:hover { background: color-mix(in srgb, var(--accent) 88%, var(--text)); }
}

/* Sections */
.section {
  padding-block: clamp(3rem, 6vw, 5rem);
  border-top: 1px solid var(--border);
}

h2 {
  font-size: var(--step-2);
  letter-spacing: -0.02em;
  margin-bottom: 2rem;
}

/* Projets : liste dépliable (details natif), une ligne compacte par projet, le détail s'ouvre au clic */
.project-list {
  display: grid;
  gap: 0.75rem;
}

.project {
  --thumb: 5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.2s;
  &:hover, &[open] { border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }

  @media (width >= 40rem) { --thumb: 10rem; }
  @media (width >= 56rem) { --thumb: 12rem; }
}

/* Mobile : vignette et titre sur une ligne, phrase et stack dessous.
   Desktop : vignette à gauche, titre, phrase et stack empilés à droite. */
.project summary {
  display: grid;
  grid-template-columns: var(--thumb) 1fr auto;
  grid-template-areas:
    "thumb title toggle"
    "pitch pitch pitch"
    "tags  tags  tags";
  align-items: center;
  gap: 0.6rem 1rem;
  padding: 1rem;
  border-radius: var(--radius);
  list-style: none;
  cursor: pointer;
  &::-webkit-details-marker { display: none; }

  @media (width >= 40rem) {
    grid-template-rows: 1fr auto auto auto 1fr;
    grid-template-areas:
      "thumb .     toggle"
      "thumb title toggle"
      "thumb pitch toggle"
      "thumb tags  toggle"
      "thumb .     toggle";
    gap: 0.4rem 1.25rem;
  }

  h3 {
    grid-area: title;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem 0.75rem;
    font-size: var(--step-1);
  }

  /* Chevron : pointe vers le bas, se retourne quand le projet est ouvert */
  &::after {
    content: "";
    grid-area: toggle;
    width: 0.6rem;
    height: 0.6rem;
    margin-inline: 0.4rem;
    border-right: 2px solid var(--muted);
    border-bottom: 2px solid var(--muted);
    rotate: 45deg;
    translate: 0 -25%;
  }
}

.project[open] summary::after { rotate: 225deg; translate: 0 25%; }

@media (prefers-reduced-motion: no-preference) {
  .project summary::after { transition: rotate 0.25s ease, translate 0.25s ease; }

  /* Ouverture animée là où le navigateur sait interpoler vers height: auto, instantanée ailleurs */
  @supports (interpolate-size: allow-keywords) {
    .project {
      interpolate-size: allow-keywords;
      &::details-content {
        block-size: 0;
        overflow-y: clip;
        transition: block-size 0.3s ease, content-visibility 0.3s allow-discrete;
      }
      &[open]::details-content { block-size: auto; }
    }
  }
}

.project-thumb {
  grid-area: thumb;
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
}

.project-pitch {
  grid-area: pitch;
  color: var(--muted);
}

.project summary .tags { grid-area: tags; }

/* Le détail s'aligne sous le texte en desktop */
.project-body {
  display: grid;
  gap: 1rem;
  padding: 0 1rem 1.25rem;

  @media (width >= 40rem) { padding-left: calc(1rem + var(--thumb) + 1.25rem); }
}

.badge {
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font: 600 0.8rem var(--mono);
}

.points {
  display: grid;
  gap: 0.4rem;
  color: var(--muted);

  li {
    padding-left: 1.2rem;
    position: relative;
    &::before {
      content: "→";
      position: absolute;
      left: 0;
      color: var(--accent);
    }
  }
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;

  > * {
    padding: 0.15rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font: 0.8rem var(--mono);
    color: var(--muted);
  }
}

.links {
  display: flex;
  gap: 1.25rem;
  font-weight: 600;
  &.muted { font-weight: 400; font-size: 0.9rem; }
}

/* Cas concrets : une carte par incident, toujours dans le même ordre (symptôme, diagnostic, résolution, prévention) */
.cases {
  display: grid;
  gap: var(--space);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr));
}

.case {
  display: grid;
  align-content: start;
  gap: 1rem;
  padding: 1.5rem;
  border: 1px solid var(--border);
  border-radius: 12px;

  h3 { font-size: var(--step-1); }

  dl { display: grid; gap: 0.75rem; }
  dt {
    font: 600 0.8rem var(--mono);
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }
  dd { color: var(--muted); }
}

/* Emplacement à remplir avant la mise en ligne */
.todo {
  border-style: dashed;
  .muted { font-style: italic; }
}

/* Parcours */
.timeline {
  display: grid;
  gap: 1.75rem;
  border-left: 2px solid var(--border);
  padding-left: 1.5rem;

  li {
    position: relative;
    display: grid;
    gap: 0.25rem;
    &::before {
      content: "";
      position: absolute;
      left: calc(-1.5rem - 6px);
      top: 0.45rem;
      width: 10px;
      height: 10px;
      border-radius: 50%;
      background: var(--bg);
      border: 2px solid var(--accent);
    }
  }

  h3 { font-size: var(--step-0); }
  p:not(.when) { color: var(--muted); }

  @media (width >= 48rem) {
    li { grid-template-columns: 12rem 1fr; gap: 1.5rem; }
  }
}

.when {
  font: 0.9rem var(--mono);
  color: var(--accent);
  padding-top: 0.15rem;
}

/* Compétences */
.skills {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr));
  gap: 1.5rem var(--space);

  dt {
    font-weight: 600;
    margin-bottom: 0.6rem;
  }
}

/* Footer */
.site-footer {
  border-top: 1px solid var(--border);
  padding-block: 2rem;
  font-size: 0.9rem;
}

.footer-inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
}

/* Apparition au scroll, CSS seul, ignorée si non supportée ou si l'utilisateur réduit les animations */
@media (prefers-reduced-motion: no-preference) {
  @supports (animation-timeline: view()) {
    .timeline li, .skills > div, .case {
      animation: reveal linear both;
      animation-timeline: view();
      animation-range: entry 0% entry 40%;
    }
  }

  @keyframes reveal {
    from { opacity: 0; translate: 0 1.5rem; }
  }
}
