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

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

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: "CMU Serif", serif;
    background: #151820;
    color: #f5f5f7;
}

button, input, p, h1 {
    font-family: "CMU Serif", serif;
}

[hidden] { display: none !important; }

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

.topbar {
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    border-bottom: 1px solid #343a4d;
    position: sticky;
    top: 0;
    background: #151820;
    z-index: 5;
}

.brand {
    font-size: 20px;
    font-weight: 600;
    letter-spacing: 1px;
}

.nav-links { display: flex; height: 100%; }

button.nav {
    background: transparent;
    color: #9299aa;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 0 18px;
    font-size: 16px;
    font-weight: 400;
    height: 100%;
}

button.nav:hover { color: #f5f5f7; }
button.nav.on { color: #f5f5f7; border-bottom-color: #f5f5f7; }

/* ---------- mise en page 3 colonnes ---------- */

.container {
    height: calc(100dvh - 52px);
    overflow: hidden;
    display: grid;
    grid-template-columns: 250px minmax(0, 1fr) 300px;
    align-items: stretch;
}

.main-col {
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 20px 16px;
}

.side {
    min-height: 0;
    overflow: hidden;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    align-self: stretch;
}

.side.left { border-right: 1px solid #343a4d; grid-column: 1; }
.side.right { border-left: 1px solid #343a4d; grid-column: 3; }
.main-col { grid-column: 2; }
#page-account { grid-column: 1 / -1; max-width: 420px; justify-self: center; width: 100%; }

.muted { color: #6d7487; font-size: 14px; }

/* ---------- panneaux repliables ---------- */

.panel { border: 1px solid #343a4d; }

.panel-head {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: transparent;
    color: #9099ac;
    border: none;
    padding: 10px 12px;
    font-size: 12px;
    font-weight: 400;
    letter-spacing: 2px;
    text-transform: uppercase;
}

#streak { font-size: 20px; line-height: 1.7; white-space: nowrap; }
.panel-head span:first-child { white-space: nowrap; }

.panel-head:hover { color: #f5f5f7; }
.chev { transition: transform 0.15s; }
.panel.collapsed .chev { transform: rotate(-90deg); }
.panel.collapsed .panel-body { display: none; }
.panel-body { padding: 0 12px 12px; display: flex; flex-direction: column; gap: 10px; }

.equation-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 25px;
    padding: 24px;
}

.label {
    color: #9099ac;
    font-size: 14px;
}

#equation, #p-equation {
    font-size: clamp(16px, 2.5vw, 25px);
    color: #ffffff;
    max-width: 100%;
    overflow-x: auto;
}

/* ---------- réponse ---------- */

.answer-card {
    width: min(640px, 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.answer-row {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    font-size: 20px;
}

#answer, #p-answer {
    flex: 1;
    min-width: 0;
    background: #1d2130;
    color: #f5f5f7;
    border: 1px solid #343a4d;
    padding: 10px 12px;
    font-size: 18px;
    outline: none;
}

#answer:focus, #p-answer:focus {
    border-color: #f5f5f7;
}

.preview {
    min-height: 2em;
    font-size: 18px;
    overflow-x: auto;
    max-width: 100%;
}

.toolbar {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
    width: 100%;
}

button.key {
    padding: 8px 4px;
    font-size: 15px;
    font-weight: 400;
    background: #1d2130;
    color: #f5f5f7;
    border: 1px solid #343a4d;
}

button.key:hover {
    border-color: #f5f5f7;
}

.buttons {
    display: flex;
    gap: 10px;
    margin-top: 6px;
}

button {
    border: 1px solid #f5f5f7;
    padding: 10px 17px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    background: #f5f5f7;
    color: #151820;
}

button.secondary {
    background: transparent;
    color: #f5f5f7;
    border-color: #343a4d;
}

button.secondary:hover {
    border-color: #f5f5f7;
}

button:active {
    transform: scale(0.97);
}

.feedback {
    min-height: 1.4em;
    font-size: 16px;
}

.feedback.ok { color: #6fd08c; }
.feedback.ko { color: #ff7b7b; }

.solution {
    border-top: 1px solid #343a4d;
    padding-top: 10px;
    width: 100%;
    font-size: 18px;
    overflow-x: auto;
}

.sol-title {
    color: #9099ac;
    font-size: 12px;
    letter-spacing: 2px;
    text-transform: uppercase;
}

.sol-regime {
    color: #9299aa;
    font-size: 15px;
    margin: 4px 0;
}

/* ---------- panneau latéral ---------- */

.stat-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1px;
    background: #343a4d;
    border: 1px solid #343a4d;
}

.stat {
    background: #151820;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 26px;
}

.stat-label {
    color: #9099ac;
    font-size: 11px;
    letter-spacing: 2px;
    text-transform: uppercase;
}



/* ---------- compte + classement ---------- */

.account {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    text-align: left;
}

.board { display: flex; flex-direction: column; gap: 8px; }
.acc-sep { margin-top: 14px; }
.acc-total { font-size: 28px; }
.account button { padding: 10px; }

.account input {
    background: #1d2130;
    color: #f5f5f7;
    border: 1px solid #343a4d;
    padding: 8px 10px;
    font-size: 15px;
    outline: none;
}

.account input:focus { border-color: #f5f5f7; }
.acc-buttons { display: flex; gap: 6px; }
.acc-buttons button { flex: 1; padding: 8px; font-size: 15px; }
.acc-name { font-size: 18px; }
.acc-msg { color: #ff7b7b; font-size: 13px; min-height: 1em; }

.board-tabs { display: flex; gap: 4px; }

.tab {
    flex: 1;
    padding: 6px;
    font-size: 14px;
    font-weight: 400;
    background: transparent;
    color: #9299aa;
    border: 1px solid #343a4d;
}

.tab.on { color: #f5f5f7; border-color: #f5f5f7; }

.board-list {
    list-style: none;
    counter-reset: rank;
    font-size: 15px;
}

.board-list li {
    counter-increment: rank;
    display: flex;
    justify-content: space-between;
    padding: 5px 8px;
    border: 1px solid #343a4d;
    margin-top: -1px;
}

.board-list li::before {
    content: counter(rank) ".";
    color: #6d7487;
    width: 2em;
}

.board-list li span:first-child { flex: 1; }
.board-list li.me { border-color: #f5f5f7; }
.board-list li.empty { color: #6d7487; }
.board-list li.empty::before { content: ""; width: 0; }

/* pas de barre de défilement verticale dans les blocs de la colonne centrale :
   ils gardent leur taille naturelle au lieu de se comprimer */
#equation, #p-equation, .solution, .preview, .equation-card, .answer-card {
    flex-shrink: 0;
    overflow-y: hidden;
}

/* ---------- pages : tout se pilote avec body[data-page] ---------- */

.mobile-only { display: none; }

.page { display: none; }

body[data-page="ed"] #page-ed,
body[data-page="board"] #page-ed,
body[data-page="prim"] #page-prim,
body[data-page="account"] #page-account { display: flex; }

/* la page Connexion n'a pas les colonnes classement / session */
body[data-page="account"] #left,
body[data-page="account"] #right { display: none; }


/* ---------- solution affichée : le reste monte ou disparaît ---------- */

.solved .toolbar,
.solved .preview { display: none; }
.solved .equation-card { padding: 8px; gap: 8px; }
.solved .answer-card { gap: 6px; }
.solved .solution { font-size: 16px; padding-top: 6px; }
.solved .katex-display { margin: 0.3em 0; }
.solved .sol-title { display: none; }

.board-list li { padding: 4px 8px; }
.panel-body .muted { font-size: 13px; }

/* écrans peu hauts */
@media (max-height: 700px) {
    .side { padding: 10px; gap: 8px; }
    .stat { padding: 6px 10px; font-size: 22px; }
        .panel-head { padding: 7px 10px; }
    .panel-body { padding: 0 10px 8px; gap: 6px; }
    .equation-card { padding: 10px; gap: 10px; }
    #equation { font-size: clamp(15px, 2.2vw, 22px); }
    .preview { min-height: 1.4em; }
    button.key { padding: 5px 4px; }
    button { padding: 8px 14px; }
}

/* ---------- petits écrans : une page à la fois, sans défilement ---------- */

@media (max-width: 1000px) {
    .container { grid-template-columns: minmax(0, 1fr); }
    .main-col, #page-account, .side { grid-column: 1; grid-row: 1; }
    .side.left, .side.right { border: none; width: 100%; }
    .mobile-only { display: block; }
    .topbar { padding: 0 10px; }
    .brand { display: none; }
    .nav-links { width: 100%; justify-content: space-around; }
    button.nav { padding: 0 8px; font-size: 15px; }

    body[data-page="ed"] #left,
    body[data-page="ed"] #right,
    body[data-page="prim"] #left,
    body[data-page="prim"] #right { display: none; }

    body[data-page="board"] #right,
    body[data-page="board"] #page-ed,
    body[data-page="board"] #page-prim { display: none; }
}
