@import url("https://cdn.jsdelivr.net/npm/computer-modern@0.1.3/cmu-serif.css");

/* Même interface que le site de maths ; seule la couleur de base change (vert pétrole au lieu de bleu nuit). */
:root {
    --bg: #101a1a;
    --panel: #162322;
    --hover: #1d2d2b;
    --field: #152120;
    --line: #2b403d;
    --track: #1f302e;
    --me: #26403c;
    --fg: #f3f6f5;
    --mute: #8fa4a0;
    --mute2: #6c807c;
    --ok: #6fd08c;
    --ko: #ff7b7b;
}

* { margin: 0; padding: 0; box-sizing: border-box; border-radius: 0; }

html, body { height: 100%; overflow: hidden; }
html { scrollbar-color: var(--line) var(--bg); }
body { font-family: "CMU Serif", serif; background: var(--bg); color: var(--fg); }
button, input, p, h1, select { font-family: "CMU Serif", serif; }
a { color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--mute); font-size: 14px; }

/* ---------- barre du haut ---------- */

.topbar {
    height: 52px; display: flex; align-items: center; justify-content: flex-start;
    padding: 0 20px; border-bottom: 1px solid var(--line);
    position: sticky; top: 0; background: var(--bg); z-index: 5;
}
.nav-links { display: flex; height: 100%; margin-left: auto; }
button.nav {
    background: transparent; color: #93a39f; border: none; border-bottom: 2px solid transparent;
    padding: 0 18px; font-size: 16px; font-weight: 400; height: 100%;
}
button.nav:hover { color: var(--fg); }
button.nav.on { color: var(--fg); border-bottom-color: var(--fg); }
button.home-link { height: 100%; padding: 0 18px 0 0; font-size: 18px; font-weight: 600; letter-spacing: 1px; color: var(--fg); flex: none; }
button.home-link:hover { color: #ffffff; }
body[data-page="lobby"] .nav-links { display: none; }

/* ---------- trois colonnes ---------- */

.container {
    height: calc(100dvh - 52px); overflow: hidden; display: grid;
    grid-template-columns: 250px minmax(0, 1fr) 300px; align-items: stretch;
}
.main-col {
    grid-column: 2; min-width: 0; min-height: 0; overflow-y: auto; overflow-x: hidden;
    display: flex; flex-direction: column; align-items: center; text-align: center;
    padding: 20px 16px; scrollbar-width: thin;
}
.side {
    min-height: 0; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 26px;
    scrollbar-width: thin; scrollbar-color: var(--line) transparent;
}
.side.left { grid-column: 1; border-right: 1px solid var(--line); gap: 14px; padding-bottom: 20px; }
.side.right { grid-column: 3; border-left: 1px solid var(--line); }
.side .panel { flex-shrink: 0; }

/* pages sans colonnes : accueil, profil, classement, entraînement */
body:not([data-page="play"]) #left, body:not([data-page="play"]) #right { display: none; }
body:not([data-page="play"]) .main-col { grid-column: 1 / -1; }
body[data-page="lobby"] .main-col { justify-content: center; }
body.with-bar #left, body.with-bar #right { display: none; }
body.with-bar .main-col { grid-column: 1 / -1; }

/* ---------- panneaux latéraux ---------- */

.side-title { font-size: 12px; font-weight: 400; color: #93a39f; letter-spacing: 2px; text-transform: uppercase; margin-bottom: 8px; }
.panel-body { display: flex; flex-direction: column; gap: 10px; }
.lv-cat { color: #93a39f; font-size: 12px; letter-spacing: 2px; text-transform: uppercase; }
.lv-num { font-size: 36px; line-height: 1.1; }
.lv-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.lv-xp, .lv-tier { color: var(--mute); font-size: 14px; }
.xpbar { display: flex; height: 6px; background: var(--track); }
.xpbar > div { height: 100%; flex: none; width: 0; background: var(--fg); transition: width 0.3s; }
.xp-ghost { background: var(--fg); opacity: 0.6; animation: xp-pulse 4s cubic-bezier(0.37, 0, 0.63, 1) infinite; }
.xp-gain { color: var(--fg); font-size: 13px; animation: xp-pulse 4s cubic-bezier(0.37, 0, 0.63, 1) infinite; }
@keyframes xp-pulse { 0%, 100% { opacity: 0.25; } 50% { opacity: 0.9; } }

.stat-row { display: flex; gap: 34px; }
.stat { display: flex; flex-direction: column; gap: 2px; font-size: 34px; }
.stat-label { color: #93a39f; font-size: 11px; letter-spacing: 2px; text-transform: uppercase; }
.steps-dots { display: flex; gap: 4px; }
.steps-dots span { flex: 1; height: 6px; background: var(--track); }
.steps-dots span.ok { background: var(--fg); }
.steps-dots span.rev { background: var(--mute2); }
.steps-dots span.cur { background: var(--fg); opacity: 0.35; }

.board-list { list-style: none; counter-reset: rank; font-size: 14px; }
.board-list li {
    counter-increment: rank; display: flex; justify-content: space-between;
    background: var(--panel); padding: 6px 10px; margin-bottom: 2px;
}
.board-list li::before { content: counter(rank) "."; color: var(--mute); width: 1.6em; }
.board-list li span:first-child { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-list li span + span { color: var(--mute); padding-left: 8px; white-space: nowrap; }
.board-list li:hover { background: var(--hover); }
.board-list li.me { background: var(--me); color: #ffffff; }
.board-list li.me::before, .board-list li.me span + span { color: var(--fg); }
.board-list li.empty { background: transparent; padding-left: 0; color: var(--mute); }
.board-list li.empty::before { content: ""; width: 0; }

/* ---------- boutons ---------- */

button {
    border: 1px solid var(--fg); padding: 10px 17px; font-size: 16px; font-weight: 600; cursor: pointer;
    background: var(--fg); color: var(--bg);
}
button.secondary { background: transparent; color: var(--fg); border-color: var(--line); }
button.secondary:hover { border-color: var(--fg); }
button:active { transform: scale(0.97); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.link { background: none; border: none; color: #93a39f; font-size: 15px; font-weight: 400; padding: 0; text-decoration: underline; cursor: pointer; }
button.link:hover { color: var(--fg); }

/* ---------- accueil ---------- */

.home { width: min(440px, 100%); display: flex; flex-direction: column; align-items: center; gap: 16px; }
.home-title { font-size: clamp(19px, 4.2vw, 36px); font-weight: 600; line-height: 1.1; text-align: center; width: min(94vw, 660px); text-wrap: balance; margin-bottom: 8px; }
.home-sub { color: var(--mute); font-size: 15px; margin-top: -14px; }
.home-modes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: 100%; }
.home-modes .wide { grid-column: 1 / -1; }
button.mode-btn {
    width: 100%; padding: 12px; font-size: 18px; font-weight: 400; letter-spacing: 1px;
    background: var(--panel); color: var(--fg); border: 1px solid var(--line);
    display: flex; flex-direction: column; align-items: center; gap: 2px;
}
button.mode-btn:hover { border-color: var(--fg); }
.home-rank { font-size: 13px; color: var(--mute); letter-spacing: 0; }
.home-ranking { background: var(--panel); border: none; padding: 8px 10px; width: 100%; color: inherit; font-weight: 400; text-align: left; cursor: pointer; }
.home-ranking:hover { background: var(--hover); }
.home-list { list-style: none; counter-reset: rank; font-size: 14px; color: var(--mute); }
.home-list li { counter-increment: rank; display: flex; justify-content: space-between; padding: 2px 4px; }
.home-list li::before { content: counter(rank) "."; width: 2em; color: var(--mute2); }
.home-list li span:first-child { flex: 1; }
.home-list li.me { color: var(--fg); }
.home-list li.empty::before { content: ""; width: 0; }
.home-ranking:hover .home-list { color: var(--fg); }

/* ---------- exercice ---------- */

.main-col { container-type: inline-size; }
.exo { width: min(1100px, 100%); display: flex; flex-direction: column; gap: 14px; text-align: left; }
.exo-top { display: flex; flex-direction: column; gap: 14px; }
.exo-text { display: flex; flex-direction: column; gap: 10px; }
/* colonne centrale large : schéma et énoncé côte à côte */
@container (min-width: 760px) {
    .exo-top { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 22px; align-items: start; }
    .exo-top .scene-box { width: 100%; }
    .exo-head { flex-direction: column; gap: 2px; }
}
.scene-box { background: var(--bg); align-self: center; width: min(640px, 100%); }
.scene-box svg { width: 100%; height: auto; max-height: 44vh; display: block; }
.label { color: #93a39f; font-size: 14px; }
.exo-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.exo-title { font-size: 24px; font-weight: 600; }
.statement { font-size: 17px; line-height: 1.55; color: #dfe6e4; }
.katex { font-size: 1.05em; }
.katex-display { margin: 0.5em 0; overflow-x: auto; overflow-y: hidden; }

#done { display: flex; flex-direction: column; gap: 6px; }
#done:empty { display: none; }
.done-step { background: var(--panel); padding: 10px 14px; font-size: 16px; }
.done-step .ds-q { color: #b9c6c3; }
.done-step .ds-a { color: var(--ok); margin-top: 2px; }
.done-step.rev .ds-a { color: var(--mute); }
.done-step .ds-sol { color: #c9d3d1; border-top: 1px solid var(--line); margin-top: 6px; padding-top: 6px; font-size: 15px; }

.answer-card { width: 100%; display: flex; flex-direction: column; gap: 10px; border-top: 1px solid var(--line); padding-top: 14px; }
.step-head { color: #93a39f; font-size: 12px; letter-spacing: 2px; text-transform: uppercase; }
.step-q { font-size: 18px; }
.answer-row { display: flex; align-items: center; gap: 10px; width: 100%; font-size: 20px; }
.answer-row input {
    flex: 1; min-width: 0; background: var(--field); color: var(--fg); border: 1px solid var(--line);
    padding: 10px 12px; font-size: 18px; outline: none;
}
.answer-row input:focus { border-color: var(--fg); }
.answer-row .unit, .answer-row .lhs { white-space: nowrap; }
.preview { min-height: 2em; font-size: 18px; overflow-x: auto; overflow-y: hidden; max-width: 100%; }
.toolbar { display: grid; grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); gap: 3px; width: 100%; }
button.key {
    padding: 6px 2px; min-width: 0; white-space: nowrap; overflow: hidden; font-size: 15px; font-weight: 400;
    background: var(--panel); color: var(--fg); border: 1px solid var(--line);
}
button.key.fn { background: #131e1d; color: #c3cfcc; font-size: 14px; }
button.key:hover { border-color: var(--fg); }
.choices { display: flex; flex-direction: column; gap: 6px; }
button.choice { background: var(--panel); color: var(--fg); border: 1px solid var(--line); text-align: left; font-weight: 400; font-size: 17px; }
button.choice:hover { border-color: var(--fg); }
button.choice.bad { border-color: var(--ko); color: var(--ko); }
.buttons { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.feedback { min-height: 1.4em; font-size: 16px; }
.feedback.ok { color: var(--ok); }
.feedback.ko { color: var(--ko); }
.hint { border-left: 2px solid var(--fg); padding: 4px 12px; color: #dfe6e4; font-size: 16px; }
.end-big { font-size: 44px; line-height: 1.1; }
.shake { animation: shake 0.28s; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

/* ---------- mode Entraînement ---------- */

.mode-bar { display: flex; align-items: center; gap: 12px; height: 34px; padding: 0 16px; border-bottom: 1px solid var(--line); font-size: 14px; color: #93a39f; white-space: nowrap; overflow: hidden; }
.mode-bar #mb-text { flex: 1; color: var(--fg); overflow: hidden; text-overflow: ellipsis; }
.mode-bar button { padding: 3px 10px; font-size: 13px; }
body.with-bar .container { height: calc(100dvh - 86px); }
.train { width: min(1100px, 100%); text-align: left; display: flex; flex-direction: column; gap: 18px; padding-bottom: 30px; }
.tier-pick { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.tier-pick button { padding: 5px 12px; font-size: 14px; font-weight: 400; background: transparent; color: var(--mute); border: 1px solid var(--line); }
.tier-pick button.on { color: var(--fg); border-color: var(--fg); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 8px; }
.card { background: var(--panel); text-decoration: none; display: flex; flex-direction: column; border: 1px solid transparent; }
.card:hover { border-color: var(--fg); }
.card.off { opacity: 0.4; pointer-events: none; }
.thumb { aspect-ratio: 3 / 2; overflow: hidden; background: var(--bg); }
.thumb svg { width: 100%; height: 100%; display: block; }
.card-body { padding: 10px 12px 12px; }
.card-title { font-size: 17px; }
.card-blurb { color: #aebcb9; font-size: 14px; margin-top: 3px; }
.card-tier { color: var(--mute); font-size: 13px; margin-top: 6px; }
.train h2, .narrow h2 { font-size: 13px; font-weight: 400; color: #93a39f; letter-spacing: 2px; text-transform: uppercase; margin-top: 8px; }

/* ---------- classement, profil ---------- */

.page-title { font-size: clamp(32px, 6vw, 46px); font-weight: 600; line-height: 1.1; margin-bottom: 8px; }
.narrow { width: min(560px, 100%); text-align: left; display: flex; flex-direction: column; gap: 12px; padding: 8px 0 30px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab { flex: 1; padding: 6px; font-size: 14px; font-weight: 400; background: transparent; color: #93a39f; border: 1px solid var(--line); white-space: nowrap; }
.tab.on { color: var(--fg); border-color: var(--fg); }
.form input {
    display: block; width: 100%; background: var(--field); color: var(--fg); border: 1px solid var(--line);
    padding: 9px 10px; font-size: 16px; outline: none;
}
.form input:focus { border-color: var(--fg); }
.acc-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.acc-msg { color: var(--ko); font-size: 14px; min-height: 1em; }
.cat-list { list-style: none; display: flex; flex-direction: column; gap: 2px; }
.cat-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; background: var(--panel); padding: 8px 12px; }
.cat-row:hover { background: var(--hover); }
.cat-lv { text-align: right; }
.cat-detail { grid-column: 1 / -1; color: #93a39f; font-size: 13px; }
.cat-row .xpbar { grid-column: 1 / -1; margin-top: 4px; }

/* ---------- bandeau de niveau (téléphone) ---------- */

.lv-strip { display: none; }

@media (max-width: 1000px) {
    .container { grid-template-columns: minmax(0, 1fr); }
    .main-col { grid-column: 1 !important; }
    #left, #right { display: none !important; }
    .topbar { padding: 0 10px; }
    .nav-links { flex: 1; min-width: 0; margin-left: 0; overflow-x: auto; scrollbar-width: none; justify-content: flex-start; }
    .nav-links::-webkit-scrollbar { display: none; }
    button.nav { white-space: nowrap; flex: 0 0 auto; padding: 0 10px; font-size: 15px; }
    button.home-link { padding-right: 12px; font-size: 16px; }
    body[data-page="play"]:not(.with-bar) .lv-strip {
        display: flex; align-items: center; gap: 8px; height: 30px; padding: 0 10px;
        border-bottom: 1px solid var(--line); font-size: 13px; color: #93a39f; white-space: nowrap;
    }
    .lv-strip #lvs-lv { color: var(--fg); }
    .lv-strip .xpbar { flex: 1; }
    body[data-page="play"]:not(.with-bar) .container { height: calc(100dvh - 82px); }
    .main-col { padding: 12px 10px 30px; }
    .scene-box svg { max-height: 34vh; }
    .exo-title { font-size: 20px; }
    .statement { font-size: 16px; }
}
