/* Exercices, éditeur, clavier, figures et catalogues. */

.statement {
    font-size: 22px;
    line-height: 1.65
}

@media(max-width:760px) {
    .statement {
        font-size: 19px;
    }
}

.hole {
    display: inline-flex;
    background: #f3e7d8;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0 8px;
    font-weight: 900;
    color: var(--primary-dark)
}

.question {
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 18px;
    background: #fffdf8;
    margin: 16px 0
}

.question.done {
    background: #f0fdf4;
    border-color: #bbf7d0
}

.builder label {
    font-weight: 750
}

.builder-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 12px
}

.stack {
    display: grid;
    gap: 12px
}

.builder-box {
    border: 1px solid var(--border);
    background: #fffdf8;
    border-radius: 18px;
    padding: 16px
}

.box-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px
}

.code-inline {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    background: #f4eadf;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1px 6px
}

details {
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px;
    background: #fff
}

summary {
    cursor: pointer;
    font-weight: 800
}

.script-section {
    border: 1px solid var(--border);
    border-radius: 16px;
    background: #fff;
    padding: 14px;
    margin-top: 12px
}

.script-section h4 {
    margin: 0 0 6px
}

.script-editor {
    min-height: 150px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 14px;
    line-height: 1.45;
    background: #0f172a;
    color: #e5e7eb;
    border-color: #1e293b
}

.script-editor::placeholder {
    color: #94a3b8
}

.script-editor:focus {
    background: #0f172a;
    color: #e5e7eb;
    border-color: var(--accent);
}

.answer-review {
    margin-top: 12px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: #fff;
    padding: 12px 14px
}

.answer-review p {
    margin: 6px 0
}

.answer-review b {
    font-weight: 900
}

.answer-math {
    display: inline-flex;
    max-width: 100%;
    overflow-x: auto;
    vertical-align: middle;
    font-size: 1.05em;
}

.btn.danger {
    background: #b42318;
    color: #fff;
}

.btn.danger:hover {
    filter: brightness(0.95);
}

.time-remaining {
    font-size: 20px;
    color: #b42318
}

.time-remaining span {
    font-variant-numeric: tabular-nums;
    font-size: 24px;
    font-weight: 900
}

.exercise-workbar {
    position: sticky;
    top: 66px;
    z-index: 4;
    margin-bottom: 18px;
    padding: 14px;
    background: rgba(255, 255, 255, .96);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: 0 10px 28px rgba(31, 41, 55, .10);
    backdrop-filter: blur(10px)
}

.workbar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px
}

.work-timer {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 12px;
    background: #fff4ed;
    color: #b42318;
    font-size: 14px
}

.work-timer b {
    font-size: 18px;
    font-variant-numeric: tabular-nums
}

.exercise-switcher {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 2px 2px 6px;
    scrollbar-width: thin
}

.exercise-tab {
    min-width: 150px;
    max-width: 220px;
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 9px 11px;
    border: 1px solid var(--border);
    border-radius: 13px;
    background: #fff;
    color: var(--text);
    text-decoration: none
}

.exercise-tab span {
    flex: 0 0 28px;
    height: 28px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: #f3e7d8;
    color: var(--primary-dark);
    font-weight: 900
}

.exercise-tab small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 750
}

.exercise-tab:hover {
    border-color: var(--light-brown);
    background: #fffaf2
}

.exercise-tab.current {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--focus)
}

.exercise-tab.completed span {
    background: #dcfae6;
    color: #067647
}

.exercise-tab.completed small {
    color: #067647
}

.auto-next-notice {
    position: sticky;
    top: 190px;
    z-index: 3;
    text-align: center;
    font-weight: 850
}

@media(max-width:760px) {
    .exercise-workbar {
        top: 92px;
        margin-left: -8px;
        margin-right: -8px
    }

    .exercise-tab {
        min-width: 118px
    }

    .exercise-tab small {
        max-width: 70px
    }

    .workbar-head {
        align-items: stretch
    }

    .work-timer {
        justify-content: center
    }
}


.math-keyboard {
    display: block;
    padding: .85rem;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--card);
    box-shadow: 0 14px 34px rgba(72, 57, 46, .12);
}

.math-answer-composer {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 52px;
    border: 2px solid var(--border);
    border-radius: 12px;
    background: var(--card);
    overflow: hidden;
    transition: border-color .15s ease, box-shadow .15s ease;
}

.math-answer-composer:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--focus);
}

.math-answer-field {
    display: block;
    width: 100%;
    min-height: 58px;
    padding: .75rem 1rem;
    border: 0;
    border-radius: 0;
    background: var(--card);
    color: var(--text);
    font-size: 1.25rem;
    outline: 0;
    --selection-background-color: #d8bf9f;
    --selection-color: #48392e;
    --contains-highlight-background-color: #ebded4;
    --contains-highlight-color: #48392e;
    --placeholder-color: #ab875f;
    --placeholder-opacity: .65;
}

.math-keyboard-trigger {
    display: grid;
    place-items: center;
    min-width: 52px;
    min-height: 58px;
    padding: 0;
    border: 0;
    border-left: 1px solid var(--border);
    border-radius: 0;
    background: var(--card-soft);
    color: var(--text);
    font-size: 1.1rem;
    cursor: pointer;
}

.math-keyboard-trigger:hover {
    background: var(--beige);
}

.math-answer-field::part(virtual-keyboard-toggle),
.math-answer-field::part(menu-toggle) {
    display: none !important;
}

.rich-math-editor {
    min-height: 110px;
    padding: .8rem .9rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--card);
    color: var(--text);
    line-height: 1.7;
    white-space: pre-wrap;
    cursor: text;
}

.rich-math-editor:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--focus);
    outline: 0;
}

.rich-math-editor:empty::before {
    content: attr(data-placeholder);
    color: var(--muted);
    pointer-events: none;
}

.rich-math-editor math-field[data-inline-math] {
    display: inline-block;
    min-width: 2.4rem;
    margin: 0 .16rem;
    padding: .08rem .28rem;
    border: 1px solid color-mix(in srgb, var(--brown) 45%, var(--border));
    border-radius: 6px;
    background: color-mix(in srgb, var(--light-brown) 24%, var(--card));
    color: var(--text);
    vertical-align: middle;
    --selection-background-color: #d8bf9f;
    --selection-color: #48392e;
    --contains-highlight-background-color: #ebded4;
    --contains-highlight-color: #48392e;
}

.rich-math-editor math-field[data-inline-math]::part(content),
.rich-math-editor math-field[data-inline-math]::part(container),
.rich-math-editor math-field[data-inline-math]::part(field) {
    background: transparent;
    color: var(--text);
}

.rich-math-editor math-field::part(virtual-keyboard-toggle),
.rich-math-editor math-field::part(menu-toggle) {
    display: none !important;
}

.inline-math-formula {
    display: inline-flex;
    max-width: 100%;
    overflow-x: auto;
    vertical-align: middle;
}

.field-label {
    margin: 0 0 .4rem;
    font-weight: 750;
    color: var(--text);
}

.math-answer-list {
    display: grid;
    gap: .55rem;
}

.math-answer-list-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: .45rem;
    align-items: stretch;
}

.math-answer-list-row math-field {
    display: block;
    width: 100%;
    min-height: 48px;
    padding: .55rem .7rem;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--card);
    color: var(--text);
    font-size: 1.08rem;
    --selection-background-color: #d8bf9f;
    --selection-color: #48392e;
    --contains-highlight-background-color: #ebded4;
    --contains-highlight-color: #48392e;
}

.math-answer-list-row math-field:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--focus);
    outline: 0;
}

.math-answer-list-row math-field::part(virtual-keyboard-toggle),
.math-answer-list-row math-field::part(menu-toggle) {
    display: none !important;
}

.math-answer-list-row .danger {
    min-width: 44px;
    padding: .45rem;
}

.math-keyboard-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
    margin-bottom: .65rem;
}

.math-keyboard-tabs button {
    min-height: auto !important;
    min-width: auto !important;
    padding: .4rem .65rem;
    font-size: .78rem !important;
    background: var(--card);
    color: var(--muted);
}

.math-keyboard-tabs button.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.math-keyboard-panel {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 4.75rem), 1fr));
    gap: .4rem;
}

.math-keyboard-panel[data-math-category="Structures"],
.math-keyboard-panel[data-math-category="Matrices"] {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr));
}

.math-keyboard-panel[data-math-category="Analyse"] {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 8rem), 1fr));
}

.math-keyboard-panel[data-math-category="Fonctions"],
.math-keyboard-panel[data-math-category="Géométrie"] {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 7rem), 1fr));
}

.math-keyboard-panel[data-math-category="Statistiques"] {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 9rem), 1fr));
}

.math-keyboard[hidden] {
    display: none;
}

.math-keyboard button {
    min-width: 0;
    min-height: 2.5rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--card);
    color: var(--text);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 700;
    white-space: normal;
    overflow-wrap: anywhere;
    line-height: 1.2;
}

.math-keyboard-panel button>span {
    display: grid;
    place-items: center;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    padding: .1rem;
}

.exercise-visual {
    margin: 1rem 0;
}

.exercise-visual iframe {
    width: 100%;
    min-height: 420px;
    border: 1px solid var(--border);
    border-radius: 12px;
}

.exercise-visual img {
    display: block;
    max-width: 100%;
    height: auto;
    margin: auto;
    border-radius: 12px;
}

.exercise-instance-preview {
    display: block;
    margin-top: .6rem;
    padding: .65rem;
    border-radius: 9px;
    background: var(--bg);
    color: var(--text);
    font-size: .9rem;
    line-height: 1.45;
}

.generated-plot svg {
    width: 100%;
    height: auto;
    max-height: 520px;
    background: #fff;
    border-radius: 8px;
}

.plot-grid {
    stroke: #e2e8f0;
    stroke-width: 1;
}

.plot-axis {
    stroke: #334155;
    stroke-width: 2;
}

.generated-plot text {
    font: 600 18px system-ui, sans-serif;
}

.plot-legend {
    display: flex;
    flex-wrap: wrap;
    gap: .8rem;
    justify-content: center;
    margin: .5rem;
}

.plot-legend span {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
}

.plot-legend i {
    width: 1.5rem;
    height: .25rem;
    border-radius: 1rem;
}

.learning-table {
    border-collapse: collapse;
    margin: auto;
    min-width: min(100%, 420px);
}

.learning-table th,
.learning-table td {
    border: 2px solid var(--border);
    padding: .65rem 1rem;
    text-align: center;
}

.learning-table th {
    background: var(--bg);
}

.generated-plot figcaption,
.named-learning-table figcaption {
    text-align: center;
    margin-top: .65rem;
    font-weight: 850;
    color: var(--text);
}

.named-learning-table {
    margin: 1.2rem 0;
}

.content-block {
    transition: opacity .15s ease, transform .15s ease;
}

.content-block.dragging,
.level-sort-row.dragging {
    opacity: .45;
    transform: scale(.99);
}

.drag-handle {
    cursor: grab;
    color: var(--muted);
    user-select: none;
}

.plot-element-row {
    display: grid;
    grid-template-columns: minmax(180px, 2fr) 54px minmax(110px, 1fr) auto;
    gap: .55rem;
    align-items: center;
    margin: .55rem 0;
}

.plot-element-row input[type="color"] {
    min-height: 44px;
    padding: .25rem;
}

@media(max-width:650px) {
    .plot-element-row {
        grid-template-columns: 1fr 54px
    }

    .plot-element-row input:nth-child(3) {
        grid-column: 1/-1
    }

    .settings-nav {
        top: 120px
    }
}

.pill.orange {
    background: #fff4e5;
    color: #b54708
}

.question.feedback-orange {
    background: #fffaeb;
    border-color: #fedf89
}

.question.feedback-red {
    background: #fef3f2;
    border-color: #fecdca
}

.question.feedback-green {
    background: #f0fdf4;
    border-color: #bbf7d0
}

.exercise-picker-toolbar {
    display: grid;
    grid-template-columns: minmax(220px, 2fr) minmax(150px, 1fr) minmax(180px, 1fr);
    gap: 10px;
    align-items: center
}

.exercise-library {
    max-height: 620px;
    overflow: auto;
    padding: 4px
}

.exercise-chapter-group {
    margin: 10px 0 22px
}

.exercise-chapter-group h4,
.catalog-chapter>h2 {
    position: sticky;
    top: 0;
    margin: 0 0 10px;
    padding: 9px 12px;
    border-radius: 12px;
    background: #f3e7d8;
    color: var(--primary-dark);
    z-index: 1
}

.exercise-choice {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    height: 100%;
    cursor: pointer
}

.exercise-choice input {
    width: auto;
    margin-top: 4px
}

.exercise-choice:has(input:checked) {
    border-color: var(--primary);
    background: #faf3e9;
    box-shadow: 0 0 0 3px var(--focus)
}

.exercise-choice small {
    color: var(--muted)
}

.exercise-catalog-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start
}

.exercise-catalog-card .btn {
    margin-top: auto
}

@media(max-width:760px) {
    .exercise-picker-toolbar {
        grid-template-columns: 1fr
    }

    .exercise-library {
        max-height: none
    }
}

/* Catalogue, exercice en cours, clavier et éditeur. */
.section-exercises {
    --section-accent: var(--brown);
}

.section-exercises .question {
    border-top: 3px solid color-mix(in srgb, var(--section-accent) 24%, var(--border));
}

.section-exercises .math-keyboard-tabs button.active {
    background: var(--section-accent);
}

.section-exercises .exercise-tab.current {
    border-color: var(--section-accent);
}

.section-exercises .generated-plot {
    --plot-accent: var(--section-accent);
}

/* La construction d'exercices garde des états lisibles, dans la palette sable. */
.builder-section-title,
.variable-box,
.exercise-chapter-group h4,
.catalog-chapter>h2 {
    border-color: var(--border);
    background: #f3e7d8;
    color: var(--primary-dark);
}

.math-keyboard-panel button mjx-container {
    margin: 0 !important;
    pointer-events: none;
}

.builder-math-tools {
    position: sticky;
    bottom: 12px;
    z-index: 8;
    display: grid;
    gap: 8px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: color-mix(in srgb, var(--card) 94%, transparent);
    box-shadow: 0 14px 34px rgba(72, 57, 46, .14);
    backdrop-filter: blur(10px);
}

.builder-math-tools>p {
    margin: 0;
}

.exercise-choice:has(input:checked) {
    border-color: var(--brown);
    background: #faf3e9;
    box-shadow: 0 0 0 3px var(--focus);
}

.exercise-chapter-group .grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.exercise-chapter-group .exercise-choice,
.exercise-chapter-group .exercise-choice>span {
    min-width: 0;
}

.exercise-instance-preview {
    max-width: 100%;
    overflow-wrap: anywhere;
}

.exercise-library {
    overflow-x: hidden;
}

@media (max-width: 900px) {
    .exercise-chapter-group .grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 600px) {
    .exercise-chapter-group .grid {
        grid-template-columns: 1fr;
    }
}

html[data-theme="dark"] .builder-box,
html[data-theme="dark"] .script-section,
html[data-theme="dark"] .question,
html[data-theme="dark"] .exercise-choice,
html[data-theme="dark"] .math-keyboard,
html[data-theme="dark"] details,
html[data-theme="dark"] .answer-review,
html[data-theme="dark"] .exercise-tab {
    background: var(--card);
}

html[data-theme="dark"] .rich-math-editor math-field[data-inline-math],
html[data-theme="dark"] .math-answer-list-row math-field,
html[data-theme="dark"] .math-answer-field {
    background: #2b231e;
    color: #f3e8dc;
    border-color: #5d4a3c;
    --selection-background-color: #c5943f;
    --selection-color: #1d1713;
    --contains-highlight-background-color: #8f6d4a;
    --contains-highlight-color: #1d1713;
    --_selection-background-color: #c5943f;
    --_selection-color: #1d1713;
    --_contains-highlight-background-color: #8f6d4a;
    --_contains-highlight-color: #1d1713;
    --caret-color: #f8d991;
    --_caret-color: #f8d991;
}

html[data-theme="dark"] .math-answer-composer {
    background: #2b231e;
    border-color: #5d4a3c;
}

html[data-theme="dark"] .rich-math-editor math-field[data-inline-math]::part(content),
html[data-theme="dark"] .rich-math-editor math-field[data-inline-math]::part(container),
html[data-theme="dark"] .rich-math-editor math-field[data-inline-math]::part(field),
html[data-theme="dark"] .math-answer-list-row math-field::part(content),
html[data-theme="dark"] .math-answer-list-row math-field::part(container),
html[data-theme="dark"] .math-answer-list-row math-field::part(field),
html[data-theme="dark"] .math-answer-field::part(content),
html[data-theme="dark"] .math-answer-field::part(container),
html[data-theme="dark"] .math-answer-field::part(field) {
    background: transparent;
    color: #f3e8dc;
}

html[data-theme="dark"] .rich-math-editor math-field[data-inline-math]::part(selection),
html[data-theme="dark"] .rich-math-editor math-field[data-inline-math]::part(contains-highlight),
html[data-theme="dark"] .math-answer-list-row math-field::part(selection),
html[data-theme="dark"] .math-answer-list-row math-field::part(contains-highlight),
html[data-theme="dark"] .math-answer-field::part(selection),
html[data-theme="dark"] .math-answer-field::part(contains-highlight) {
    background: #c5943f;
    color: #1d1713;
}

html[data-theme="dark"] .builder-section-title,
html[data-theme="dark"] .variable-box,
html[data-theme="dark"] .exercise-chapter-group h4,
html[data-theme="dark"] .catalog-chapter>h2 {
    background: #342a23;
    color: var(--primary-dark);
}

html[data-theme="dark"] .exercise-choice:has(input:checked) {
    background: #382e25;
}

html[data-theme="dark"] .generated-plot svg {
    background: #f8f3eb;
}

html[data-theme="dark"] .script-editor,
html[data-theme="dark"] .script-editor:focus {
    background: #111827;
    color: #e5e7eb;
}

html[data-theme="dark"] .question.done,
html[data-theme="dark"] .question.feedback-green {
    background: #202a22;
    border-color: #465b49;
}

html[data-theme="dark"] .question.feedback-orange {
    background: #32291b;
    border-color: #6e582d;
}

html[data-theme="dark"] .question.feedback-red {
    background: #30201d;
    border-color: #6b4039;
}

html[data-theme="dark"] .work-timer,
html[data-theme="dark"] .pill.orange {
    background: #352a1c;
    color: #e3b965;
}

html[data-theme="dark"] .exercise-tab:hover {
    background: var(--card-soft);
}

.classification-choices {
    display: flex;
    flex-wrap: wrap;
    gap: 8px
}

.classification-choices .choice {
    margin: 0;
    padding: 9px 12px
}

.classification-choices .choice input {
    margin-top: 2px
}

.formula-round-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(135px, 210px);
    gap: .65rem;
    align-items: end;
}

.formula-round-row>p {
    grid-column: 1/-1;
    margin: 0;
}

@media(max-width:650px) {
    .formula-round-row {
        grid-template-columns: 1fr
    }
}

.math-keyboard button:hover {
    background: var(--card-soft);
    color: var(--text);
}
