/* ==========================================================
   Portfolio v2 — Tristan Carretey
   Le contenu défile normalement par-dessus un canvas 3D fixe.
   ========================================================== */

:root {
    --font: "IBM Plex Sans", system-ui, sans-serif;
    --panel-w: 36rem;
    --radius: 6px;
    --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

[data-theme="dark"] {
    color-scheme: dark;
    --bg: #07090d;
    --fg: #e9ebee;
    --muted: #a0a8b3;
    --line: #262c35;
    --panel: rgb(10 13 18 / 0.82);
    --card: #0e1218;
    --accent: #f5a524;
    --accent-ink: #1a1203;
    /* Couleurs lues par la scène 3D */
    --net-line: #3d5876;
    --net-node: #9cc0e6;
    --net-dust: #46505e;
}

[data-theme="light"] {
    color-scheme: light;
    --bg: #f3f1ec;
    --fg: #16181c;
    --muted: #535a63;
    --line: #d6d2c8;
    --panel: rgb(243 241 236 / 0.86);
    --card: #fbfaf7;
    --accent: #b45309;
    --accent-ink: #fff7ed;
    --net-line: #8797aa;
    --net-node: #2f4a6b;
    --net-dust: #b3ada2;
}

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

html {
    scroll-snap-type: y mandatory;
    scroll-behavior: smooth;
    background: var(--bg);
}

body {
    margin: 0;
    font-family: var(--font);
    font-size: 1rem;
    line-height: 1.6;
    color: var(--fg);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
    margin: 0;
    line-height: 1.1;
    font-weight: 600;
    text-wrap: balance;
}

p { margin: 0; }

a {
    color: inherit;
    text-decoration-color: var(--accent);
    text-underline-offset: 0.2em;
}

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

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

.icon {
    width: 1.1em;
    height: 1.1em;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    vertical-align: -0.15em;
    flex: none;
}

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

.skip-link {
    position: fixed;
    top: 0.75rem;
    left: 0.75rem;
    z-index: 100;
    padding: 0.5rem 0.875rem;
    background: var(--accent);
    color: var(--accent-ink);
    font-weight: 600;
    border-radius: var(--radius);
    transform: translateY(-200%);
}
.skip-link:focus { transform: none; }

/* ---------- Fond 3D ---------- */

#network {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    z-index: 0;
}

.no-webgl #network { display: none; }
.no-webgl body {
    background:
        radial-gradient(circle at 75% 30%, color-mix(in srgb, var(--accent) 12%, transparent), transparent 40%),
        var(--bg);
    background-attachment: fixed;
}

/* ---------- Barre du haut ---------- */

.topbar {
    position: fixed;
    inset: 0 0 auto 0;
    z-index: 20;
    display: flex;
    justify-content: flex-end; /* boutons langue et thème à droite */
    align-items: center;
    padding: 1rem clamp(1rem, 3vw, 2rem);
    pointer-events: none;
}
.topbar > * { pointer-events: auto; }

.controls {
    display: flex;
    gap: 0.5rem;
}

.control {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.75rem;
    height: 2.75rem;
    padding: 0 0.75rem;
    font: 500 0.875rem var(--font);
    color: var(--fg);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
}
.control:hover { border-color: var(--accent); color: var(--accent); }

[data-theme="dark"] .icon-moon,
[data-theme="light"] .icon-sun { display: none; }

/* ---------- Plan du réseau (navigation latérale) ---------- */

.route {
    position: fixed;
    right: clamp(1rem, 3vw, 2rem);
    top: 50%;
    transform: translateY(-50%);
    z-index: 20;
}

.route ol {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.5rem 0 0.5rem 0.75rem;
    background: var(--panel);
    border-right: 1px solid var(--line);
}

.route a {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.75rem;
    min-height: 2rem;
    padding-right: 0.875rem;
    margin-right: -1px;
    font-size: 0.875rem;
    color: var(--muted);
    text-decoration: none;
    border-right: 2px solid transparent;
    transition: color 0.2s, border-color 0.2s;
}
.route a:hover { color: var(--fg); }
.route a[aria-current="step"] {
    color: var(--fg);
    border-right-color: var(--accent);
}

/* ---------- Stations (sections) ---------- */

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

.station {
    min-height: 100vh;
    min-height: 100svh;
    display: flex;
    align-items: center;
    padding: 5.5rem clamp(1rem, 6vw, 6rem) 3rem;
    scroll-snap-align: start;
}

.panel {
    position: relative;
    width: 100%;
    max-width: var(--panel-w);
    padding: clamp(1.25rem, 3vw, 2.25rem);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}
.panel-wide { max-width: 64rem; }

/* L'accueil n'a pas de cadre : le nom est posé sur le réseau */
.station-intro .panel {
    background: none;
    border: 0;
    padding-left: 0;
}

/* ---------- Entrée d'une station ----------
   À l'arrivée de la caméra, le neurone se décharge : un signal parcourt le bord haut du panneau,
   le cadre se matérialise derrière lui, puis le contenu arrive en cascade (--i = rang de l'élément). */

.station:not(.is-visible) .panel {
    background-color: transparent;
    border-color: transparent;
}
.station.is-visible .panel {
    transition: background-color 0.6s var(--ease) 0.2s, border-color 0.6s var(--ease) 0.2s;
}

.panel::before {
    content: "";
    position: absolute;
    top: -1px;
    left: -1px;
    right: -1px;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent) 35%, var(--accent));
    transform: scaleX(0);
    transform-origin: left;
    opacity: 0;
    pointer-events: none;
}
.station-intro .panel::before { display: none; }
.station.is-visible .panel::before { animation: signal 1s var(--ease) both; }

@keyframes signal {
    0% { transform: scaleX(0); opacity: 1; }
    55% { transform: scaleX(1); opacity: 1; }
    100% { transform: scaleX(1); opacity: 0; }
}

.rv { opacity: 0; }
.station.is-visible .rv {
    animation: rise 0.8s var(--ease) both;
    animation-delay: calc(0.25s + var(--i, 0) * 55ms);
}
/* Titres : montent à travers un masque */
.station.is-visible .rv-mask { animation-name: unmask; animation-duration: 0.9s; }

@keyframes rise {
    from { opacity: 0; transform: translateY(1.25rem); }
    to { opacity: 1; transform: none; }
}
@keyframes unmask {
    from { opacity: 1; clip-path: inset(0 0 100% 0); transform: translateY(0.6em); }
    to { opacity: 1; clip-path: inset(-0.15em -0.1em -0.25em -0.1em); transform: none; }
}

/* Accueil : le nom apparaît ligne par ligne pendant que le cerveau émerge */
.name .line { display: block; }
.station-intro.is-visible .rv { animation-delay: calc(0.6s + var(--i, 0) * 120ms); }

/* Contenu re-rendu pendant qu'on le regarde (langue, filtres) : pas de nouvelle cascade */
.station.is-visible.instant .rv { animation: none; opacity: 1; }

.topbar,
.route { animation: fade 1s var(--ease) 1.1s both; }
@keyframes fade { from { opacity: 0; } }

.name {
    font-size: clamp(3.25rem, 10vw, 8rem);
    letter-spacing: -0.035em;
    line-height: 0.92;
}

.role {
    margin-top: 1.5rem;
    font-size: clamp(1.15rem, 2vw, 1.4rem);
    font-weight: 500;
}

.lead {
    margin-top: 1rem;
    max-width: 38rem;
    font-size: 1.125rem;
    color: var(--muted);
}

h2 {
    font-size: clamp(2rem, 4.5vw, 3rem);
    letter-spacing: -0.02em;
    margin-bottom: 1.25rem;
}

h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

.prose { max-width: 38rem; }
.prose p + p { margin-top: 1rem; }

/* ---------- Parcours ---------- */

.columns {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr));
    gap: 2rem 3rem;
}

.timeline li + li {
    margin-top: 1.25rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--line);
}
.timeline .when { display: block; font-size: 0.9rem; }
.timeline .title { font-weight: 600; }
.timeline .org { color: var(--muted); }
.timeline .text { margin-top: 0.375rem; font-size: 0.95rem; }

/* ---------- Compétences ---------- */

/* Une ligne par domaine : nom, outils, niveau. Les filets appartiennent aux lignes
   (pas au conteneur) pour que rien ne s'affiche avant leur entrée en scène. */
.skill-list li {
    display: grid;
    grid-template-columns: minmax(9rem, 15rem) 1fr auto;
    gap: 0.375rem 2rem;
    align-items: baseline;
    padding: 1.125rem 0;
    border-bottom: 1px solid var(--line);
}
.skill-list li:first-child { border-top: 1px solid var(--line); }
.skill-list h3 {
    margin: 0;
    font-size: 1.05rem;
}
.skill-list .tools { color: var(--fg); }
.skill-list .level {
    font-size: 0.9rem;
    color: var(--muted);
    white-space: nowrap;
    text-align: right;
}

@media (max-width: 640px) {
    .skill-list li { grid-template-columns: 1fr auto; }
    .skill-list .tools { grid-column: 1 / -1; grid-row: 2; color: var(--muted); }
}

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

.project-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 2.25rem 2rem;
    margin-top: 2rem;
}

/* Projets courants : pas de cadre, un filet au-dessus qui s'allume au survol */
.project {
    position: relative;
    display: flex;
    padding-top: 1.25rem;
    border-top: 1px solid var(--line);
    transition: border-color 0.25s;
}
.project:hover,
.project:focus-within { border-top-color: var(--accent); }
.project-body {
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
}
.project h3 { margin: 0; font-size: 1.1rem; }
.project .desc { font-size: 0.95rem; color: var(--muted); }
.project .tags {
    margin-top: auto;
    padding-top: 0.25rem;
    font-size: 0.85rem;
    color: var(--muted);
}
.project .open {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    /* Les boutons n'héritent pas de la police : on la force pour que lien et bouton soient identiques */
    font: 500 0.95rem var(--font);
    color: var(--fg);
    text-decoration: none;
    background: none;
    border: 0;
    padding: 0;
    cursor: pointer;
    align-self: flex-start;
}
.project .open:hover { color: var(--accent); }
/* Toute la carte est cliquable via son lien ou bouton */
.project .open::after {
    content: "";
    position: absolute;
    inset: 0;
}

/* Projet mis en avant (étude de cas) : une seule carte, texte à gauche, captures à droite */
.project.feature {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
    gap: 2rem;
    align-items: center;
    padding: clamp(1.25rem, 3vw, 2rem);
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    transition: border-color 0.25s;
}
.project.feature:hover,
.project.feature:focus-within { border-color: var(--accent); }
.project.feature h3 { font-size: clamp(1.4rem, 2.5vw, 1.8rem); }
.project.feature .desc { font-size: 1rem; }

.preview {
    position: relative;
    height: 17rem;
}
.preview img {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 8rem;
    height: auto;
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: 0 18px 40px -18px rgb(0 0 0 / 0.6);
    transition: transform 0.5s var(--ease);
}
.preview img:nth-child(1) { transform: translate(-125%, -46%) rotate(-7deg); }
.preview img:nth-child(2) { transform: translate(-50%, -54%); z-index: 1; }
.preview img:nth-child(3) { transform: translate(25%, -46%) rotate(7deg); }
.project.feature:hover .preview img:nth-child(1) { transform: translate(-135%, -48%) rotate(-10deg); }
.project.feature:hover .preview img:nth-child(3) { transform: translate(35%, -48%) rotate(10deg); }

/* Dépôts de cours : repliés sous une ligne qu'on peut déplier */
.more {
    margin-top: 2.5rem;
    border-top: 1px solid var(--line);
}
.more summary {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 3rem;
    font-weight: 500;
    color: var(--muted);
    cursor: pointer;
    list-style: none;
}
.more summary::-webkit-details-marker { display: none; }
.more summary::after {
    content: "+";
    margin-left: auto;
    font-size: 1.25rem;
    line-height: 1;
}
.more[open] summary::after { content: "−"; }
.more summary:hover { color: var(--fg); }

/* Une ligne par dépôt : nom, description, langage */
.repo-list li {
    display: grid;
    grid-template-columns: minmax(8rem, 11rem) 1fr auto;
    gap: 0.25rem 1.5rem;
    align-items: baseline;
    padding: 0.875rem 0;
    border-top: 1px solid var(--line);
}
.repo-list a {
    font-weight: 600;
    text-decoration: none;
}
.repo-list a:hover { color: var(--accent); }
.repo-list p { font-size: 0.95rem; color: var(--muted); }
.repo-list .lang { font-size: 0.85rem; color: var(--muted); white-space: nowrap; }

.status {
    margin-top: 1rem;
    font-size: 0.9rem;
    color: var(--accent);
}
.status:empty { display: none; }

@media (max-width: 900px) {
    .project-grid { grid-template-columns: 1fr; }
    .project.feature { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
    .preview { height: 13rem; }
    .preview img { width: 6.25rem; }
    .repo-list li { grid-template-columns: 1fr auto; }
    .repo-list p { grid-column: 1 / -1; grid-row: 2; }
}

/* ---------- Contact ---------- */

.email {
    display: inline-block;
    margin-top: 1.75rem;
    font-size: clamp(1.25rem, 3.5vw, 2rem);
    font-weight: 500;
    word-break: break-word;
}

.links {
    display: flex;
    gap: 1.5rem;
    margin-top: 1.5rem;
}
.links a {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    min-height: 2.75rem;
}

.footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 0.5rem 1.5rem;
    margin-top: 3rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--line);
    font-size: 0.85rem;
    color: var(--muted);
}

/* ---------- Étude de cas (dialog) ---------- */

.case-study {
    width: min(100% - 2rem, 68rem);
    max-height: calc(100dvh - 2rem);
    padding: 0;
    color: var(--fg);
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}
.case-study[open] { animation: case-in 0.45s var(--ease); }
.case-study[open]::backdrop { animation: fade 0.45s var(--ease); }
.case-study::backdrop { background: rgb(0 0 0 / 0.6); }
@keyframes case-in {
    from { opacity: 0; transform: translateY(1rem) scale(0.985); }
}

.case-inner {
    position: relative;
    padding: clamp(1.25rem, 4vw, 3rem);
}
.case-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
}
.case-head { padding-right: 3.5rem; }
.case-tags {
    font-size: 0.9rem;
    color: var(--muted);
    margin-bottom: 0.5rem;
}
.case-study h2 { margin-bottom: 1rem; }
.case-study .lead { max-width: 46rem; }

/* Distinction : sur la carte projet et en tête de l'étude de cas */
.award {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    color: var(--accent);
}
.award .icon { width: 1.2em; height: 1.2em; }
.case-award {
    padding: 0.5rem 0.875rem;
    border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
    border-radius: var(--radius);
    background: color-mix(in srgb, var(--accent) 8%, transparent);
}
.project .award { font-size: 0.9rem; color: var(--accent); }

.case-points {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr));
    gap: 1.25rem 2rem;
    margin: 2rem 0 2.25rem;
}
.case-points div {
    padding-top: 1rem;
    border-top: 1px solid var(--line);
}
.case-points dt { font-weight: 600; margin-bottom: 0.375rem; }
.case-points dd { margin: 0; color: var(--muted); font-size: 0.95rem; }

/* Captures : toutes visibles d'un coup, sans défilement horizontal */
.shots {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 10rem), 1fr));
    gap: 1.25rem;
}
@media (max-width: 640px) {
    .shots { grid-template-columns: repeat(2, 1fr); gap: 0.875rem; }
}
.shots figure { margin: 0; }
.shots img {
    display: block;
    width: 100%;
    height: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius);
}
.shots figcaption {
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: var(--muted);
}

.noscript {
    position: relative;
    z-index: 30;
    padding: 2rem;
}

/* ---------- Responsive ---------- */

@media (min-width: 1024px) {
    /* Laisse la place au plan du réseau à droite */
    .station { padding-right: max(6vw, 9rem); }
}

@media (max-width: 1023px) {
    .route { display: none; }
}

/* Portrait : le neurone occupe le haut de l'écran, le texte d'accueil passe en bas */
@media (orientation: portrait) and (max-width: 1023px) {
    .station-intro { align-items: flex-end; }
}

@media (max-width: 640px) {
    .station { padding-inline: 1rem; }
    .lead { font-size: 1rem; }
}

/* ---------- Changement de thème ---------- */

/* Pendant la bascule, aucune transition : tout change au même instant */
.theme-switching *,
.theme-switching *::before,
.theme-switching *::after {
    transition: none !important;
}

/* L'onde est animée en JS (clip-path circulaire depuis le bouton) : pas de fondu par défaut */
::view-transition-old(root),
::view-transition-new(root) {
    animation: none;
    mix-blend-mode: normal;
}

.theme-wave {
    position: fixed;
    z-index: 50;
    border: 2px solid var(--accent);
    border-radius: 50%;
    box-shadow: 0 0 40px color-mix(in srgb, var(--accent) 35%, transparent);
    pointer-events: none;
    transform: translate(-50%, -50%) scale(0);
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    .rv { opacity: 1; }
    .station:not(.is-visible) .panel { background-color: var(--panel); border-color: var(--line); }
    .station.is-visible .rv,
    .panel::before,
    .topbar,
    .route,
    .case-study[open],
    .case-study[open]::backdrop { animation: none !important; }
}
