/* XY — repris du style de theo.delemazure.fr */

/* Polices hébergées sur le site (aucun appel à Google) — licence SIL OFL, voir fonts/ */
@font-face {
    font-family: 'Montserrat';
    src: url("fonts/Montserrat-Variable.woff2") format("woff2");
    font-weight: 100 900;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'Montserrat';
    src: url("fonts/Montserrat-Variable-Italic.woff2") format("woff2");
    font-weight: 100 900;
    font-style: italic;
    font-display: swap;
}
@font-face {
    font-family: 'Anonymous Pro';
    src: url("fonts/AnonymousPro-Regular.woff2") format("woff2");
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

:root {
    --ink: #222;
    --soft: #404040;
    --link: #0f346b;
    --hover: #15156e;
    --panel: #f2f2f2;
    --tok: 48px;          /* recalculé en JS selon le nombre de candidats */
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
}

body {
    font-family: 'Montserrat', sans-serif;
    color: var(--soft);
    background: #fff;
    overflow: hidden;
}

.app {
    display: grid;
    grid-template-columns: minmax(230px, 24%) 1fr;
    gap: 3.5vw;
    height: 100vh;
    height: 100dvh;
    padding: 3vh 3vw 2.5vh 3vw;
}

/* ---------- colonne gauche ---------- */

.left {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.brand {
    color: var(--ink);
    line-height: 0.88;
    margin: 2vh 0 5vh 0;
}
.brand .l1 {
    font-size: clamp(28px, 4.1vw, 66px);
    letter-spacing: -0.01em;
}
.brand .l2 {
    font-weight: 900;
    font-size: clamp(80px, 13vw, 210px);
    letter-spacing: -0.03em;
    margin: 0 0 0 -0.04em;   /* c'est un h1 : pas de marges par défaut */
    line-height: inherit;
}
.noscript { position: fixed; inset: auto 0 0 0; margin: 0; padding: 14px 20px; background: #222; color: #fff; text-align: center; }

.daymeta {
    font-family: 'Anonymous Pro', monospace;
    font-size: clamp(15px, 1.55vw, 24px);
    color: var(--ink);
}
.daytitle {
    font-size: clamp(18px, 1.9vw, 30px);
    color: var(--ink);
    font-weight: 700;
    margin-top: 0.25em;
}

.prev-link { display: none; }

.prev-h {
    margin: 5vh 0 1.4vh 0;
    font-size: clamp(15px, 1.4vw, 21px);
    color: var(--ink);
}

.days {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    background: var(--panel);
    padding: 14px 16px;
    font-size: clamp(13px, 1.05vw, 16px);
}
.days a {
    display: flex;
    gap: 0.6em;
    color: #333;
    text-decoration: none;
    padding: 4px 0;
    cursor: pointer;
    transition: color 0.2s;
}
.days a:hover {
    font-style: italic;
    color: var(--hover);
}
.days a.active {
    color: var(--link);
    font-weight: 700;
}
.days a .d-title { flex: 1; }
.days a .d-done { color: #999; }

/* ---------- colonne droite ---------- */

.right {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: 1fr auto;
    grid-template-areas: "plane tray" "bar credit";
    column-gap: 2vw;
    min-height: 0;
    min-width: 0;
}

.tray {
    grid-area: tray;
    background: var(--panel);
    display: grid;
    grid-template-columns: repeat(2, calc(var(--tok) * 2.1));
    grid-auto-rows: max-content;
    align-content: start;
    justify-items: center;
    padding: 18px 14px;
    row-gap: calc(var(--tok) * 0.3);
    column-gap: 8px;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;          /* beaucoup de candidats : la colonne défile */
    scrollbar-width: thin;
}

.plane {
    grid-area: plane;
    position: relative;
    min-height: 0;
    margin: 0 0 1vh 0;
    container-type: size;
}

/* zone de coordonnées : x, y dans [-1, 1], toujours carrée */
.field {
    /* marges autour de la grille : flèche (16px) + écart + une ligne de texte */
    --labfs: clamp(13px, 1.2vw, 18px);
    --gap: 24px;
    --px: calc(var(--gap) + var(--labfs) * 1.3);
    --py: calc(var(--gap) + var(--labfs) * 1.3);
    --s: min(100cqw - 2 * var(--px), 100cqh - 2 * var(--py));
    position: absolute;
    width: var(--s);
    height: var(--s);
    left: calc((100cqw - var(--s)) / 2 + var(--shift, 0px));   /* --shift : décalage pour équilibrer la place des libellés */
    top: calc((100cqh - var(--s)) / 2);
    /* grille fine : 20 x 20 cases (pas de 0,1) */
    --grid: #ececec;
    background-image:
        linear-gradient(to right, var(--grid) 1px, transparent 1px),
        linear-gradient(to bottom, var(--grid) 1px, transparent 1px);
    background-size: 5% 5%;
    box-shadow: inset -1px -1px 0 var(--grid);
}

#dens, #lines {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}
#dens  { z-index: 1; }
#lines { z-index: 2; overflow: visible; }

.axis-x, .axis-y {
    position: absolute;
    background: #111;
    z-index: 0;
}
.axis-x {
    left: 0; right: 0;
    top: 50%;
    height: 5px;
    margin-top: -2.5px;
}
.axis-y {
    top: 0; bottom: 0;
    left: 50%;
    width: 5px;
    margin-left: -2.5px;
}
.axis-x::before, .axis-x::after,
.axis-y::before, .axis-y::after {
    content: '';
    position: absolute;
    width: 0; height: 0;
    border: 0 solid transparent;
}
.axis-x::after  { right: -16px; top: 50%; transform: translateY(-50%); border-left: 18px solid #111; border-top-width: 10px; border-bottom-width: 10px; }
.axis-x::before { left: -16px;  top: 50%; transform: translateY(-50%); border-right: 18px solid #111; border-top-width: 10px; border-bottom-width: 10px; }
.axis-y::before { top: -16px;    left: 50%; transform: translateX(-50%); border-bottom: 18px solid #111; border-left-width: 10px; border-right-width: 10px; }
.axis-y::after  { bottom: -16px; left: 50%; transform: translateX(-50%); border-top: 18px solid #111; border-left-width: 10px; border-right-width: 10px; }

.lab {
    position: absolute;
    z-index: 0;
    color: var(--ink);
    font-size: var(--labfs);
    line-height: 1.15;
    pointer-events: none;
    /* passe à la ligne entre les mots seulement ; un mot trop long élargit le libellé */
    width: max-content;
    min-width: min-content;
    overflow-wrap: normal;
    hyphens: none;
    --off: calc(var(--gap) + var(--labfs) * 0.65);   /* distance du bord de la grille au milieu du texte */
}
.lab:empty { display: none; }

/* --- axes bidirectionnels : origine au centre --- */
/* axe vertical : au-dessus et au-dessous des flèches */
.lab-yp, .lab-yn { left: 50%; max-width: 90%; text-align: center; transform: translateX(-50%); }
.lab-yp { bottom: calc(100% + var(--gap)); }
.lab-yn { top: calc(100% + var(--gap)); }
/* axe horizontal : à l'horizontale, à l'extérieur de la grille, après les flèches.
   Le libellé est coupé en deux au milieu (entre deux mots) : une moitié au-dessus
   du niveau de l'axe, l'autre en dessous. La largeur disponible de chaque côté
   (--sideL, --sideR) est mesurée en JS dans l'espace libre autour de la grille. */
.field { --px: var(--gap); }
.lab-xn, .lab-xp { top: 50%; height: 0; min-width: 0; }
.lab-xn { right: calc(100% + var(--gap) + 4px); width: var(--sideL, 110px); text-align: right; }
.lab-xp { left: calc(100% + var(--gap) + 4px); width: var(--sideR, 110px); text-align: left; }
.lab .half { position: absolute; left: 0; right: 0; }
.lab .half.top { bottom: 2px; }
.lab .half.bot { top: 2px; }

/* --- axes unidirectionnels : origine en bas à gauche --- */
.plane.uni .axis-x { top: 100%; }
.plane.uni .axis-y { left: 0; }
.plane.uni .axis-x::before,
.plane.uni .axis-y::after { display: none; }
/* axe horizontal : libellés sous l'axe, au début et au bout */
.plane.uni .lab-xn, .plane.uni .lab-xp { top: calc(100% + 18px); height: auto; width: max-content; min-width: min-content; max-width: 48%; transform: none; }
.plane.uni .lab-xn { left: 0; right: auto; text-align: left; }
.plane.uni .lab-xp { left: auto; right: 0; text-align: right; }
/* axe vertical : à l'horizontale — le bout au-dessus de la flèche, le début à gauche de l'origine */
.plane.uni .lab-yp { left: 0; bottom: calc(100% + var(--gap)); max-width: 90%; text-align: left; transform: none; }
.plane.uni .lab-yn { left: auto; right: calc(100% + 14px); top: auto; bottom: -0.6em; width: var(--sideL, 110px); min-width: 0; max-width: none; text-align: right; transform: none; }

/* adresse du site, en tout petit, sous le coin bas droit de la grille */
.site-link {
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    z-index: 0;
    font-size: 10px;
    line-height: 1.2;
    color: #aaa;
    text-decoration: none;
    white-space: nowrap;
}
.site-link:hover { font-style: italic; color: var(--hover); }
.plane.uni .site-link { right: 22px; }   /* laisse la place à la pointe de la flèche */

/* consensus du candidat survolé, au-dessus du coin haut droit de la grille */
.consensus {
    position: absolute;
    right: 0;
    bottom: calc(100% + var(--gap));
    z-index: 5;
    font-size: var(--labfs);
    line-height: 1.15;
    color: var(--ink);
    white-space: nowrap;
    pointer-events: none;
}
.consensus[hidden] { display: none; }
.consensus b { color: var(--c, var(--ink)); }

/* ---------- candidats ---------- */

.tok {
    position: absolute;
    z-index: 4;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: max-content;
    transform: translate(-50%, calc(var(--tok) / -2));
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;   /* pas de menu « appui long » sur iPhone */
    cursor: grab;
    transition: opacity 0.2s;
}
.tray .tok {
    position: relative;
    transform: none;
    width: 100%;
    min-width: 0;
}
.tok.drag-src { opacity: 0.25; }
.tok.ghost { pointer-events: none; }
.tok.dragging {
    position: fixed;
    z-index: 50;
    cursor: grabbing;
    transform: translate(-50%, calc(var(--tok) / -2)) scale(1.08);
}
.locked .tok, .tok.legend { cursor: default; }

.disc {
    width: var(--tok);
    height: var(--tok);
    border-radius: 50%;
    background-color: var(--c);
    background-size: cover;
    background-position: center;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: calc(var(--tok) * 0.32);
    letter-spacing: 0.02em;
    border: 3px solid var(--c);
    transition: transform 0.15s;
}
/* candidat avec image : rond recadré (cover), liseré de sa couleur */
.tok.has-img .disc {
    color: transparent;
    border-width: 2px;
    background-color: #fff;
}

.tname {
    font-size: clamp(11px, 0.95vw, 14px);
    color: var(--ink);
    margin-top: 3px;
    padding: 0 3px;
    white-space: nowrap;
    background: rgba(255, 255, 255, 0.85);
}
.tray .tname {
    background: none;
    max-width: 100%;
    white-space: normal;      /* nom complet, sur plusieurs lignes si besoin — jamais de « … » */
    text-align: center;
    line-height: 1.2;
}

.tok:not(.legend):hover .disc { transform: scale(1.06); }
.tok.legend:hover .tname, .tok.hl .tname { font-style: italic; color: var(--hover); }

/* médianes (graphique collaboratif) */
.tok.med { z-index: 3; }
.tok.med .disc {
    background-color: #fff;
    color: var(--c);
    border-style: dashed;
    width: calc(var(--tok) * 0.8);
    height: calc(var(--tok) * 0.8);
    font-size: calc(var(--tok) * 0.26);
}
.tok.med { transform: translate(-50%, calc(var(--tok) * -0.4)); }
.plane[data-view="mine"] .tok.med .tname { display: none; }

/* Noms sur la grille : placés autour de la pastille (dessous, dessus, droite, gauche)
   par placeLabels() dans axes.js, pour éviter qu'ils se chevauchent. */
.field .tok .tname { position: absolute; left: 50%; top: calc(100% + 2px); margin-top: 0; transform: translateX(-50%); }
.field .tok.lbl-above .tname { top: auto; bottom: calc(100% + 2px); }
.field .tok.lbl-right .tname { left: calc(100% + 4px); top: 50%; transform: translateY(-50%); }
.field .tok.lbl-left  .tname { left: auto; right: calc(100% + 4px); top: 50%; transform: translateY(-50%); }
.field .tok.lbl-off .tname { display: none; }                 /* pas de place : visible au survol */
.field .tok.lbl-off.hl .tname { display: block; z-index: 6; }
.plane[data-view="mine"] .tok.med .disc { background-image: none !important; }
.plane[data-view="mine"] .tok.med.has-img .disc { color: var(--c); }

.plane[data-view="collab"] .tok.user,
.plane[data-view="collab"] #lines { display: none; }
.plane[data-view="collab"] .tok.med .disc {
    background-color: var(--c);
    color: #fff;
    border-style: solid;
    width: var(--tok);
    height: var(--tok);
    font-size: calc(var(--tok) * 0.32);
}
.plane[data-view="collab"] .tok.med { transform: translate(-50%, calc(var(--tok) / -2)); }
.plane[data-view="collab"] .tok.med.has-img .disc { color: transparent; }

/* survol : on éteint les autres */
.focus .tok:not(.hl) { opacity: 0.15; }
#lines line { transition: opacity 0.2s; }
.focus #lines line:not(.hl) { opacity: 0.1; }

/* ---------- barre du bas ---------- */

.bar {
    display: flex;
    align-items: center;
    gap: 2vw;
    grid-area: bar;
    height: 64px;
    position: relative;
    padding-left: 4.5%;
}
/* à droite du bouton : nombre de réponses, puis la case « Points médians » */
.bar .side { display: flex; flex-direction: column; gap: 4px; min-width: 0; }

.btn {
    font-family: 'Montserrat', sans-serif;
    font-size: clamp(16px, 1.5vw, 22px);
    background-color: #555;
    color: #fff;
    border: none;
    padding: 9px 30px;
    cursor: pointer;
    transition: background-color 0.5s;
    white-space: nowrap;
}
.btn:hover { background-color: #222; }
.btn:disabled { background-color: #c8c8c8; cursor: default; }

.medopt {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: clamp(13px, 1.1vw, 17px);
    color: var(--ink);
    cursor: pointer;
    user-select: none;
}
.medopt input {
    width: 16px;
    height: 16px;
    margin: 0;
    accent-color: #555;
    cursor: pointer;
}
.medopt:hover { font-style: italic; color: var(--hover); }
.medopt[hidden] { display: none; }

.plane.no-med[data-view="mine"] .tok.med,
.plane.no-med[data-view="mine"] #lines { display: none; }

.credit {
    grid-area: credit;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    width: 0;
    min-width: 100%;   /* n'élargit pas la colonne : s'adapte à la largeur des candidats */
    align-self: end;
    text-align: right;
    font-size: clamp(11px, 0.85vw, 13px);
    color: #888;
    line-height: 1.4;
    padding-bottom: 2px;
}
.credit a {
    color: var(--link);
    text-decoration: none;
    font-weight: 700;
}
.credit a { white-space: nowrap; }
.credit a:hover { font-style: italic; color: var(--hover); }
.credit a.legal-link { font-weight: 400; color: #666; }
.credit .nw { white-space: nowrap; }

/* ---------- page mentions légales ---------- */

body.page-legal { overflow: auto; }
.legal {
    max-width: 640px;
    margin: 0 auto;
    padding: 6vh 6vw 8vh 6vw;
    color: var(--soft);
    line-height: 1.6;
    font-size: 16px;
}
.legal .brand-small {
    display: inline-flex;
    align-items: baseline;
    gap: 8px;
    margin: 0 0 5vh 0;
    text-decoration: none;
    color: var(--ink);
}
.legal .brand-small .l1 { font-size: 26px; }
.legal .brand-small .l2 { font-size: 40px; }
.legal h1 { font-size: 30px; font-weight: 700; color: var(--ink); margin: 0 0 3vh 0; }
.legal h2 { font-size: 18px; font-weight: 700; color: var(--ink); margin: 4vh 0 0.6em 0; }
.legal p { margin: 0 0 0.8em 0; }
.legal a { color: var(--link); text-decoration: none; }
.legal a:hover { font-style: italic; color: var(--hover); }
.legal .back { margin-top: 5vh; }

.status {
    min-width: 0;             /* jusqu'à deux lignes, jamais de « … » */
    font-size: clamp(13px, 1.1vw, 17px);
    color: var(--soft);
    line-height: 1.35;
}
.status b { color: var(--ink); }

/* petite fenêtre de confirmation, au-dessus du bouton */
.pop {
    position: absolute;
    left: 4.5%;
    bottom: calc(100% + 10px);
    z-index: 70;
    background: #fff;
    border: 2px solid var(--ink);
    padding: 16px 18px 14px 18px;
    box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.08);
    max-width: min(420px, 92vw);
}
.pop[hidden] { display: none; }
.pop p { margin: 0 0 14px 0; color: var(--ink); font-size: 16px; }
.pop .pop-actions { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.pop .btn { font-size: 16px; padding: 8px 20px; }
.pop a { color: var(--link); text-decoration: none; font-size: 15px; }
.pop a:hover { font-style: italic; color: var(--hover); }

/* grands écrans : noms des candidats un peu plus grands */
@media only screen and (min-width: 1600px) and (min-height: 950px) {
    .tname { font-size: clamp(14px, 0.8vw, 18px); }
}

/* ---------- mobile ---------- */

@media only screen and (max-width: 800px) {
    .app {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
        gap: 1.2vh;
        padding: 2vh 3vw 1.5vh 3vw;
    }
    .left { position: relative; }
    .brand { display: flex; align-items: baseline; gap: 0.25em; margin: 0 0 0.6vh 0; }
    .brand .l1 { font-size: 22px; }
    .brand .l2 { font-size: 40px; }
    .daytitle { font-size: 17px; }
    /* « Jours précédents » : un lien à côté de la date, qui ouvre la liste par-dessus */
    .prev-h { display: none; }
    .metarow { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
    .metarow .daymeta { white-space: nowrap; }
    .prev-link {
        display: inline; flex: none;
        font-size: 13px; color: var(--link); text-decoration: none; cursor: pointer;
    }
    .prev-link:hover, .left.open .prev-link { font-style: italic; color: var(--hover); }
    .days {
        display: none;
        position: absolute; left: 0; right: 0; top: 100%; z-index: 60;
        max-height: 60vh; margin-top: 6px;
        box-shadow: 0 4px 0 #ddd;
    }
    .left.open .days { display: block; }
    .right { display: flex; flex-direction: column; }
    .plane { flex: 1; margin: 1.5vh 0 1vh 0; }
    .bar { flex: none; }
    .credit { flex: none; margin-top: 4px; }
    .field { --labfs: 13px; --gap: 22px; --py: calc(var(--gap) + var(--labfs) * 2.6); }
    /* candidats posés sur la grille : plus petits que dans la barre, noms plus fins */
    .field .tok { --tok: var(--tokg, 30px); }
    .field .tname { font-size: 10.5px; margin-top: 2px; padding: 0 2px; }
    /* téléphone : le consensus passe au-dessus du libellé du haut */
    .consensus { font-size: 11px; bottom: calc(100% + var(--gap) + var(--labfs) * 1.3 + 4px); }
    /* sur téléphone : libellés des côtés tournés à 90°, le long de l'axe, hors de la grille */
    .field { --px: calc(var(--gap) + var(--labfs) * 1.3); }
    .lab .half { position: static; }
    .plane:not(.uni) .lab-xn, .plane:not(.uni) .lab-xp { top: 50%; height: auto; width: 100%; text-align: center; }
    .plane:not(.uni) .lab-xn { left: 0; right: auto; transform: translate(calc(-50% - var(--off)), -50%) rotate(-90deg); }   /* se lit de bas en haut */
    .plane:not(.uni) .lab-xp { left: 100%; right: auto; transform: translate(calc(-50% + var(--off)), -50%) rotate(90deg); }  /* se lit de haut en bas */
    /* unidirectionnel : le début de l'axe vertical, tourné, à gauche de l'axe, près de l'origine */
    .plane.uni .lab-yn { left: 0; right: auto; top: 75%; bottom: auto; width: 48%; max-width: none; text-align: left;
                         transform: translate(calc(-50% - var(--off)), -50%) rotate(-90deg); }
    /* candidats : taille fixe, nom complet, barre qui défile horizontalement */
    .tray {
        display: flex;
        flex-wrap: nowrap;
        align-items: flex-start;
        gap: 12px;
        padding: 10px 10px 8px 10px;
        min-height: calc(var(--tok) + 40px);
        overflow-x: auto;
        overflow-y: hidden;
        overscroll-behavior-x: contain;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }
    .tray::-webkit-scrollbar { display: none; }
    /* fondu sur le bord quand des candidats sont cachés */
    .tray.fade-r { -webkit-mask-image: linear-gradient(to right, #000 82%, transparent); mask-image: linear-gradient(to right, #000 82%, transparent); }
    .tray.fade-l { -webkit-mask-image: linear-gradient(to left, #000 82%, transparent); mask-image: linear-gradient(to left, #000 82%, transparent); }
    .tray.fade-l.fade-r { -webkit-mask-image: linear-gradient(to right, transparent, #000 18%, #000 82%, transparent); mask-image: linear-gradient(to right, transparent, #000 18%, #000 82%, transparent); }
    .tray .tok {
        flex: none;
        width: calc(var(--tok) * 1.8);
        min-width: min-content;      /* un mot long élargit le candidat plutôt que d'être coupé */
        touch-action: pan-x;         /* glisser horizontalement = faire défiler la barre */
    }
    .tray .tname {
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
        text-align: center;
        line-height: 1.2;
        max-width: none;
    }
    .bar { padding-left: 0; }
    .pop { left: 0; }
    .btn { padding: 8px 18px; }
}
