/* Solutions aqueuses : même charte que le labo de dosage (brutaliste sobre, lisible au vidéoprojecteur) */
:root {
    --bg-color: #F4F4F0;
    --text-color: #000000;
    --border-color: #000000;
    --brand-blue: #003366;
    --bg-panel: #ffffff;
    --bg-elevated: #e6e6e1;
    --text-muted: #4b5563;
    --canvas-grid: #e2e2e2;
    --canvas-ink: #111111;
    --canvas-muted: #555555;
    --curve-color: #1d4ed8;
    --solute-color: #b45309;      /* m_soluté (orange) */
    --solution-color: #1d4ed8;    /* m_solution (bleu) */
    --accent-ok: #1d4ed8;         /* réponse juste : bleu + ✔ (jamais la seule couleur) */
    --warn-color: #c2410c;        /* avertissement : orange + ⚠ */
    --glass-fill: rgba(200, 222, 240, 0.28);
    --graph-font: 14;
    --curve-width: 2.5;
    --font-mono: 'Courier New', Courier, monospace;
    --font-sans: 'Helvetica Neue', Helvetica, Arial, sans-serif;
    --grid-line: 1px solid var(--border-color);
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
}

/* Thème sombre (contrat portail : data-theme + localStorage 'solutions-theme') */
:root[data-theme="dark"] {
    --bg-color: #12151c;
    --text-color: #e6e8eb;
    --border-color: #3d4654;
    --brand-blue: #1a4f8a;
    --bg-panel: #161a22;
    --bg-elevated: #1f2530;
    --text-muted: #a3acb8;
    --canvas-grid: #2a313d;
    --canvas-ink: #e6e8eb;
    --canvas-muted: #9aa3af;
    --curve-color: #7cb4ff;
    --solute-color: #fdba74;
    --solution-color: #93c5fd;
    --accent-ok: #93c5fd;
    --warn-color: #fdba74;
    --glass-fill: rgba(170, 200, 230, 0.10);
}

/* Mode projection : tout ce qui est en rem grossit, les canvas lisent --graph-font et --curve-width */
:root[data-projection="on"] {
    font-size: 20px;
    --graph-font: 18;
    --curve-width: 4;
}

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

body, .app-container, .canvas-container, .graph-container, button, input, select {
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-sans);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    border: 2px solid var(--border-color);
    margin: var(--spacing-xs);
    min-height: 0;
}

/* EN-TÊTE */
.main-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--spacing-sm);
    border-bottom: var(--grid-line);
    padding: var(--spacing-sm) var(--spacing-md) var(--spacing-sm) 90px;
    background: var(--bg-color);
}

.brand h1 {
    font-family: var(--font-mono);
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.author {
    font: 400 0.75rem var(--font-sans);
    color: var(--text-muted);
    letter-spacing: 0;
    margin-left: 6px;
}

.main-nav {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--spacing-sm);
}

.theme-toggle {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    background: var(--bg-panel);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    padding: 6px 12px;
    min-height: 44px;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.theme-toggle:hover { background: var(--text-color); color: var(--bg-color); }
.theme-toggle[aria-pressed="true"] { background: var(--brand-blue); color: #fff; }

/* Boutons segmentés */
.seg-group { display: flex; gap: 2px; flex-wrap: wrap; }

.seg {
    font: 600 0.85rem/1.2 var(--font-sans);
    padding: 6px 12px;
    min-height: 36px;
    border: 1px solid rgba(255, 255, 255, 0.6);
    background: transparent;
    color: #fff;
    cursor: pointer;
}

.seg:hover { background: rgba(255, 255, 255, 0.15); }
.seg.active { background: #fff; color: var(--brand-blue); }
:root[data-theme="dark"] .seg.active { color: #0b1a2e; }

/* Variante sur fond clair (en-tête de page, panneau des réglages) */
.nav-seg .seg, .seg-light .seg {
    border: 1px solid var(--border-color);
    color: var(--text-color);
    background: var(--bg-panel);
    min-height: 44px;
}

.nav-seg .seg { font-size: 0.95rem; padding: 6px 14px; }
.nav-seg .seg:hover, .seg-light .seg:hover { background: var(--bg-elevated); }
.nav-seg .seg.active, .seg-light .seg.active { background: var(--brand-blue); color: #fff; border-color: var(--brand-blue); }

/* ONGLET UNIQUE : grille réglages | bandeau | expérience | résultats */
.tab-content { display: none; flex: 1; overflow: hidden; min-height: 0; }

#simulation.tab-content.active {
    display: grid;
    grid-template-columns: 300px minmax(0, 1.45fr) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
}

#simulation .control-panel { grid-column: 1; grid-row: 1 / 3; }
#simulation .protocol-banner { grid-column: 2 / 4; grid-row: 1; }
#simulation .visualization-panel { grid-column: 2; grid-row: 2; min-height: 0; }
#simulation .results-panel { grid-column: 3; grid-row: 2; min-height: 0; border-right: none; }

.panel {
    display: flex;
    flex-direction: column;
    border-right: var(--grid-line);
    min-width: 0;
    min-height: 0;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--spacing-sm);
    flex-wrap: wrap;
    padding: var(--spacing-sm);
    border-bottom: var(--grid-line);
    background: var(--brand-blue);
    color: #fff;
}

.panel-header h2 {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    font-weight: bold;
    text-transform: uppercase;
}

/* Panneau des réglages repliable */
.collapse-btn {
    flex: none;
    width: 1.9rem;
    height: 1.9rem;
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font: 700 1.3rem/1 var(--font-sans);
    color: #fff;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    cursor: pointer;
}

.collapse-btn:hover { background: rgba(255, 255, 255, 0.18); }

#simulation.tab-content.active.config-hidden { grid-template-columns: 56px minmax(0, 1.45fr) minmax(0, 1fr); }
#simulation.config-hidden .controls-grid { display: none; }
#simulation.config-hidden .control-panel .panel-header {
    flex: 1;
    flex-direction: column;
    justify-content: flex-start;
    flex-wrap: nowrap;
    padding: var(--spacing-sm) 0;
    cursor: pointer;
    border-bottom: none;
}
#simulation.config-hidden .control-panel .panel-header h2 {
    order: 2;
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    margin-top: var(--spacing-sm);
}

.controls-grid {
    display: flex;
    flex: 1;
    flex-direction: column;
    padding: var(--spacing-md);
    gap: var(--spacing-md);
    overflow-y: auto;
}

.poste-ctrl, .sub-ctrl { display: flex; flex-direction: column; gap: 10px; }
.poste-ctrl[hidden], .sub-ctrl[hidden], [hidden] { display: none !important; }

.input-group { display: flex; flex-direction: column; gap: 4px; }

.input-group label, .group-label {
    font-size: 0.8rem;
    font-weight: 700;
}

select, input[type="number"] {
    border: var(--grid-line);
    background: var(--bg-panel);
    color: var(--text-color);
    padding: 8px;
    min-height: 44px;
    font-family: var(--font-sans);
    font-size: 1rem;
    border-radius: 0;
    width: 100%;
}

.num-range { display: flex; gap: 8px; align-items: center; }
.num-range input[type="number"] { width: 6.5em; flex: none; font-family: var(--font-mono); font-weight: 700; }

input[type=range] {
    -webkit-appearance: none;
    appearance: none;
    flex: 1;
    min-width: 0;
    height: 44px;
    background: transparent;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 22px;
    width: 22px;
    background: var(--brand-blue);
    border: 2px solid var(--bg-panel);
    cursor: pointer;
    margin-top: -9px;
}

input[type=range]::-webkit-slider-runnable-track {
    height: 4px;
    background: var(--text-muted);
    border: 1px solid var(--border-color);
}

input[type=range]::-moz-range-thumb { height: 20px; width: 20px; background: var(--brand-blue); border-radius: 0; }

.btn-small {
    font: 600 0.85rem/1.2 var(--font-sans);
    padding: 8px 12px;
    min-height: 44px;
    background: var(--bg-panel);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    cursor: pointer;
}

.btn-small:hover { background: var(--bg-elevated); }
.btn-small:disabled { opacity: 0.45; cursor: default; }
.btn-wide { width: 100%; text-align: left; }

.btn-primary {
    font: 700 1rem/1.2 var(--font-sans);
    padding: 8px 16px;
    min-height: 44px;
    background: var(--brand-blue);
    color: #fff;
    border: 1px solid var(--brand-blue);
    cursor: pointer;
}

.btn-primary:disabled { opacity: 0.45; cursor: default; }

.check { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; min-height: 44px; cursor: pointer; }
.check input { width: 22px; height: 22px; }

.hint { font-size: 0.82rem; color: var(--text-muted); line-height: 1.4; }

.sub-box {
    border: 1px solid var(--border-color);
    padding: 8px 10px;
    background: var(--bg-panel);
}

.sub-box summary { font-weight: 700; font-size: 0.85rem; cursor: pointer; min-height: 32px; display: flex; align-items: center; }
.sub-box[open] summary { margin-bottom: 8px; }
.sub-box .btn-small { margin-top: 8px; }
.calc-line { margin-top: 8px; font-weight: 700; font-size: 1rem; }

/* Poste 2 : réglages numérotés dans l'ordre du raisonnement */
.step-title { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 0.95rem; margin-top: 4px; }
.step-title .num {
    display: inline-flex; align-items: center; justify-content: center;
    width: 1.6em; height: 1.6em; border-radius: 50%;
    background: var(--brand-blue); color: #fff; font-size: 0.85rem; flex: none;
}
.calc-box {
    border-left: 4px solid var(--brand-blue);
    background: var(--bg-panel);
    padding: 6px 10px;
    font-weight: 700; font-size: 1.02rem; line-height: 1.45;
}
.calc-box:empty { display: none; }
.calc-box .muted { font-weight: 400; font-size: 0.85rem; color: var(--text-muted); }
.calc-box.ok { border-left-color: var(--accent-ok); }
.calc-box.warn { border-left-color: var(--warn-color); }
.calc-box.warn b { color: var(--warn-color); }
.seg-wrap { flex-wrap: wrap; }
.seg-wrap .seg { flex: 0 0 auto; }

.preset-list, .etalon-list { display: flex; flex-direction: column; gap: 6px; }
.preset-list button, .etalon-list button { text-align: left; }
.etalon-list button.done { background: var(--bg-elevated); }

/* BANDEAU DU PROTOCOLE */
.protocol-banner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px var(--spacing-md);
    padding: 10px var(--spacing-md);
    background: var(--bg-panel);
    border-bottom: var(--grid-line);
    border-left: 8px solid var(--brand-blue);
    min-width: 0;
}

.bn-hint { flex: 1 1 320px; min-width: 0; font-size: 1.15rem; font-weight: 700; line-height: 1.3; }

/* Grandeurs clés en gros (comme les lectures de la réfraction) */
.readouts { display: flex; flex-wrap: wrap; gap: 6px 22px; flex: 0 1 auto; }
.readout { display: flex; flex-direction: column; min-width: 0; }
.readout .label { font-size: 0.8rem; color: var(--text-muted); }
.readout .value {
    font-size: 1.55rem; font-weight: 800; line-height: 1.15;
    font-variant-numeric: tabular-nums; white-space: nowrap;
}
.readout.pending .value { color: var(--text-muted); }

.bn-steps { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; flex: 1 1 100%; }

.step-btn {
    font: 600 0.85rem/1.2 var(--font-sans);
    padding: 6px 8px;
    min-height: 44px;
    border: 2px solid var(--border-color);
    background: var(--bg-color);
    color: var(--text-color);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.step-btn .num {
    display: inline-flex; align-items: center; justify-content: center;
    width: 1.5em; height: 1.5em; border-radius: 50%;
    border: 2px solid currentColor; font-size: 0.8rem;
}

.step-btn.done { opacity: 0.7; }
.step-btn.done .num { background: var(--text-color); color: var(--bg-color); border-color: var(--text-color); }
.step-btn.next { background: var(--brand-blue); color: #fff; border-color: var(--brand-blue); }
.step-btn.running { background: var(--brand-blue); color: #fff; border-style: dashed; }
.step-btn:disabled { cursor: default; }
.step-btn.todo:disabled { opacity: 0.5; }

.bn-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-left: auto; }

/* EXPÉRIENCE */
.view-options {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px var(--spacing-md);
    padding: 6px var(--spacing-md);
    border-bottom: var(--grid-line);
    font-size: 0.85rem;
    background: var(--bg-color);
}

.view-options .btn-small { min-height: 36px; padding: 4px 10px; }
.view-options .btn-small[aria-pressed="true"] { background: var(--brand-blue); color: #fff; }
.view-note { color: var(--text-muted); font-size: 0.85rem; }

.canvas-container {
    background: var(--bg-panel);
    position: relative;
    flex: 1 1 auto;
    min-height: 200px;
}

canvas { width: 100%; height: 100%; display: block; touch-action: manipulation; }
#sceneCanvas.draggable { touch-action: none; }

/* RÉSULTATS */
.results-body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: var(--spacing-sm) var(--spacing-md) var(--spacing-md);
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
}

/* Carte d'abord (sans défilement), le graphe prend la place restante */
.results-panel.with-graph .results-body { flex: 0 0 auto; max-height: 62%; }

.graph-container {
    flex: 1 1 auto;
    background: var(--bg-panel);
    margin: 0 var(--spacing-md) var(--spacing-md);
    border: var(--grid-line);
    position: relative;
    min-height: 200px;
}

.card {
    border-left: 6px solid var(--brand-blue);
    background: var(--bg-panel);
    padding: 8px 12px;
    border-top: 1px solid var(--canvas-grid);
    border-right: 1px solid var(--canvas-grid);
    border-bottom: 1px solid var(--canvas-grid);
}

/* Titres de carte sans majuscules forcées : « ρ = m / V » et « mL » restent justes */
.card h3 {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.card p { font-size: 0.95rem; line-height: 1.45; }
.card p + p { margin-top: 4px; }

.formula {
    font-size: 1.3rem;
    font-weight: 700;
    line-height: 1.55;
}

.formula .res { white-space: nowrap; }
.big { font-size: 1.5rem; font-weight: 800; }
.muted { color: var(--text-muted); }
.prev { font-size: 0.8rem; font-weight: 600; color: var(--text-muted); font-style: italic; }

/* Distinction ρ / c_m : couleur ET soulignement différent */
.q-solute { color: var(--solute-color); border-bottom: 3px solid var(--solute-color); }
.q-solution { color: var(--solution-color); border-bottom: 3px double var(--solution-color); }

.card.warn { border-left-color: var(--warn-color); }
.card.warn h3 { color: var(--warn-color); }
.card.ok { border-left-color: var(--accent-ok); }
.card.ok h3 { color: var(--accent-ok); }
.card.key { border-left-width: 10px; }

/* Une seule vue de résultats : une carte principale, lisible de loin */
.results-body > .card { font-size: 1.05rem; }
.card p { font-size: 1rem; }
.card .lead { font-size: 1.05rem; }
.card .note { font-size: 0.9rem; color: var(--text-muted); }

table.mesures { width: 100%; border-collapse: collapse; font-size: 0.95rem; text-align: center; }
table.mesures th, table.mesures td { border: 1px solid var(--border-color); padding: 2px 6px; }
table.mesures th { background: var(--bg-elevated); }
table.mesures .soda td { font-weight: 700; }

@media (max-width: 900px) {
    body { height: auto; overflow: auto; }
    .app-container { height: auto; }
    .main-header { padding-left: var(--spacing-md); padding-top: 36px; }

    #simulation.tab-content.active,
    #simulation.tab-content.active.config-hidden {
        display: flex;
        flex-direction: column;
        overflow: visible;
    }

    #simulation .panel { border-right: none; border-bottom: var(--grid-line); }
    /* Sur téléphone : la manipulation d'abord, les réglages ensuite */
    #simulation .protocol-banner { order: 1; }
    #simulation .visualization-panel { order: 2; }
    #simulation .control-panel { order: 3; }
    #simulation .results-panel { order: 4; }
    #simulation .visualization-panel { min-height: 460px; }
    #simulation .visualization-panel .canvas-container { min-height: 420px; }
    #simulation.config-hidden .control-panel .panel-header { flex-direction: row; }
    #simulation.config-hidden .control-panel .panel-header h2 { writing-mode: horizontal-tb; transform: none; margin: 0; }
    .results-panel.with-graph .results-body { max-height: none; }
    .graph-container { min-height: 320px; }
    .formula { font-size: 1.1rem; }
}

@media (max-width: 480px) {
    .nav-seg .seg { font-size: 0.85rem; padding: 6px 8px; }
    .brand h1 { font-size: 1rem; }
    .protocol-banner { padding: 8px; }
    .bn-hint { font-size: 1rem; }
}

/* Boutons segmentés sur fond de page : texte blanc sur l'accent, dans les deux thèmes */
:root[data-theme="dark"] .nav-seg .seg.active,
:root[data-theme="dark"] .seg-light .seg.active { color: #fff; }
