/* Keep the single-problem workspace narrower than the worksheet grid. */
.guided-workspace {
    max-width: 960px;
}

/* Explicitly hide inactive panels and development-only controls. */
.guided-workspace [hidden] {
    display: none;
}

.student-header {
    position: static;
    align-items: center;
}

#worksheetTitle {
    margin: 8px 0 0;
    font-size: 2.5rem;
    font-weight: 400;
}

/* Header controls use the shared studentControls.css styles. */
.practice-footer {
    margin-top: 24px;
}

/* Allow the restart control and save status to wrap on smaller screens. */
.practice-session-controls {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 12px;
}

#saveStatus {
    flex: 1;
}

#saveStatus[data-error="true"] {
    padding: 10px;
    border: 2px solid #e25b8d;
    background: var(--surface);
}

/* The native details element keeps development guidance collapsible. */
.development-notice {
    padding: 16px;
    margin-bottom: 20px;
    border: 2px solid var(--focus);
    border-radius: 8px;
    background: var(--surface);
    line-height: 1.5;
}

.development-notice summary {
    font-weight: 700;
    cursor: pointer;
}

/* Submission results override the page background selected by the theme. */
body[data-practice-result="incorrect"] {
    --page-background: #e88787;
}

body[data-practice-result="first-correct"] {
    --page-background: #8cdaa5;
}

body[data-practice-result="retry-correct"] {
    --page-background: #8fbdea;
}

/* Darker result backgrounds preserve readability in dark mode. */
body[data-theme="dark"][data-practice-result="incorrect"] {
    --page-background: #702b32;
}

body[data-theme="dark"][data-practice-result="first-correct"] {
    --page-background: #225b3b;
}

body[data-theme="dark"][data-practice-result="retry-correct"] {
    --page-background: #234e7b;
}

progress {
    width: 100%;
    height: 18px;
    accent-color: var(--focus);
}

/* Scale math with the size control and scroll long expressions locally. */
.guided-problem {
    padding: 8px 8px 12px;
    overflow-x: auto;
    font-size: calc(1.8rem * var(--problem-scale));
}

/* Use panel padding instead of MathJax margins around the displayed problem. */
#problemText mjx-container[display="true"] {
    margin: 0;
}

/* Empty rendering notices should not push the answer controls down. */
#mathStatus:empty {
    display: none;
}

#answerHelp {
    margin: 16px 0 0;
}

/* Keep the label above the input and Check Answer beside the input.
   Development controls occupy the third row, with Next below Check. */
#answerForm {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px 12px;
}

#answerForm label {
    grid-column: 1;
    grid-row: 1;
    align-self: end;
    font-weight: 700;
}

#nextProblemButton {
    grid-column: 2;
    grid-row: 3;
}

#checkAnswerButton {
    grid-column: 2;
    grid-row: 2;
}

#generateProblemButton {
    grid-column: 1;
    grid-row: 3;
    justify-self: start;
}

#answerInput {
    grid-column: 1;
    grid-row: 2;
    min-width: 0;
    width: 100%;
    padding: 12px;
    font: 1.1rem Arial, sans-serif;
    border: 2px solid var(--border);
    border-radius: 6px;
    color: var(--page-text);
    background: var(--surface-soft);
}

#answerForm button,
.practice-session-controls button {
    padding: 12px 18px;
    border: 2px solid var(--border);
    border-radius: 6px;
    font: 1rem Arial, sans-serif;
    color: var(--page-text);
    background: var(--surface);
    cursor: pointer;
}

button:disabled {
    opacity: 0.55;
    cursor: default;
}

/* Visible keyboard focus includes collapsible guidance and scrollable history. */
button:focus-visible,
input:focus-visible,
summary:focus-visible,
#completionPanel:focus-visible,
#answerHistory:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 3px;
}

/* Reserve feedback space and add a surface only when a message is present. */
#feedback {
    min-height: 1.5em;
    font-weight: 700;
}

#feedback:not(:empty) {
    padding: 12px;
    border-radius: 6px;
    background: var(--surface);
}

#feedback[data-status="correct"] {
    color: var(--answer-text);
}

#feedback[data-status="incorrect"],
#feedback[data-status="invalid"],
#loadStatus[data-error="true"] {
    border-left: 4px solid #e25b8d;
    padding-left: 10px;
}

#historyTitle {
    margin-top: 0;
    margin-bottom: 0;
    padding-top: 0;
    padding-bottom: 0;
}

/* Limit history height so new attempts do not continually lengthen the page.
   Contained scrolling prevents wheel gestures from spilling into page scrolling. */
#answerHistory {
    max-height: min(320px, 35vh);
    padding-left: 36px;
    overflow-y: scroll;
    overscroll-behavior-y: contain;
    scrollbar-gutter: stable;
}

.history-entry {
    padding: 10px 4px;
    border-bottom: 1px solid var(--border);
    overflow-wrap: anywhere;
    font-size: 1.25rem;
}

/* Each entry retains its own result color independently of the current problem. */
.history-entry[data-practice-result="incorrect"] {
    color: #b42323;
}

.history-entry[data-practice-result="first-correct"] {
    color: #18733a;
}

.history-entry[data-practice-result="retry-correct"] {
    color: #245ea5;
}

body[data-theme="dark"] .history-entry[data-practice-result="incorrect"] {
    color: #ff9b9b;
}

body[data-theme="dark"] .history-entry[data-practice-result="first-correct"] {
    color: #8cdaa5;
}

body[data-theme="dark"] .history-entry[data-practice-result="retry-correct"] {
    color: #8fbdea;
}

.history-entry:last-child {
    border-bottom: 0;
}

.history-entry p {
    margin: 8px 0;
}

/* Size the problem and answer columns to their contents rather than spreading
   them across the full row; keep the attempt count in the final column. */
.history-row {
    display: grid;
    grid-template-columns: minmax(0, max-content) minmax(0, max-content) max-content;
    justify-content: start;
    align-items: center;
    gap: 24px;
}

.history-problem {
    min-width: 0;
    overflow-x: auto;
    text-align: left;
}

.history-attempts {
    text-align: right;
}

.history-row .history-submitted {
    min-width: 0;
    margin: 0;
}

/* Reduce history gaps and stack header sections on narrow screens. */
@media (max-width: 600px) {
    .history-row {
        gap: 16px;
    }

    .student-header {
        flex-direction: column;
        align-items: stretch;
        padding: 16px;
    }

    #answerForm button {
        width: 100%;
    }
}
