html, body {
    font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

a, .btn-link {
    color: #006bb7;
}

.btn-primary {
    color: #fff;
    background-color: #1b6ec2;
    border-color: #1861ac;
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
  box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
}

.content {
    padding-top: 1.1rem;
}

h1:focus {
    outline: none;
}

.valid.modified:not([type=checkbox]) {
    outline: 1px solid #26b050;
}

.invalid {
    outline: 1px solid #e50000;
}

.validation-message {
    color: #e50000;
}

/* Error pop-up (Blazor shows it with display:block when something breaks). Themed in the chalk section below. */
#blazor-error-ui {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    padding: 1rem;
    background: rgba(20, 26, 22, 0.6);
}

.blazor-error-boundary {
    background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2My41MDYgNTFDMjY0LjcxNyA1MSAyNjUuODEzIDUxLjQ4MzcgMjY2LjYwNiA1Mi4yNjU4TDI2Ny4wNTIgNTIuNzk4NyAyNjcuNTM5IDUzLjYyODMgMjkwLjE4NSA5Mi4xODMxIDI5MC41NDUgOTIuNzk1IDI5MC42NTYgOTIuOTk2QzI5MC44NzcgOTMuNTEzIDI5MSA5NC4wODE1IDI5MSA5NC42NzgyIDI5MSA5Ny4wNjUxIDI4OS4wMzggOTkgMjg2LjYxNyA5OUwyNDAuMzgzIDk5QzIzNy45NjMgOTkgMjM2IDk3LjA2NTEgMjM2IDk0LjY3ODIgMjM2IDk0LjM3OTkgMjM2LjAzMSA5NC4wODg2IDIzNi4wODkgOTMuODA3MkwyMzYuMzM4IDkzLjAxNjIgMjM2Ljg1OCA5Mi4xMzE0IDI1OS40NzMgNTMuNjI5NCAyNTkuOTYxIDUyLjc5ODUgMjYwLjQwNyA1Mi4yNjU4QzI2MS4yIDUxLjQ4MzcgMjYyLjI5NiA1MSAyNjMuNTA2IDUxWk0yNjMuNTg2IDY2LjAxODNDMjYwLjczNyA2Ni4wMTgzIDI1OS4zMTMgNjcuMTI0NSAyNTkuMzEzIDY5LjMzNyAyNTkuMzEzIDY5LjYxMDIgMjU5LjMzMiA2OS44NjA4IDI1OS4zNzEgNzAuMDg4N0wyNjEuNzk1IDg0LjAxNjEgMjY1LjM4IDg0LjAxNjEgMjY3LjgyMSA2OS43NDc1QzI2Ny44NiA2OS43MzA5IDI2Ny44NzkgNjkuNTg3NyAyNjcuODc5IDY5LjMxNzkgMjY3Ljg3OSA2Ny4xMTgyIDI2Ni40NDggNjYuMDE4MyAyNjMuNTg2IDY2LjAxODNaTTI2My41NzYgODYuMDU0N0MyNjEuMDQ5IDg2LjA1NDcgMjU5Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121;
    padding: 1rem 1rem 1rem 3.7rem;
    color: white;
}

    .blazor-error-boundary::after {
        content: "An error has occurred."
    }

.darker-border-checkbox.form-check-input {
    border-color: #929292;
}

.form-floating > .form-control-plaintext::placeholder, .form-floating > .form-control::placeholder {
    color: var(--bs-secondary-color);
    text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder, .form-floating > .form-control:focus::placeholder {
    text-align: start;
}

.status-bar-safe-area {
    display: none;
}

@supports (-webkit-touch-callout: none) {
    .status-bar-safe-area {
        display: flex;
        position: sticky;
        top: 0;
        height: env(safe-area-inset-top);
        background-color: #f7f7f7;
        width: 100%;
        z-index: 1;
    }

    .flex-column, .navbar-brand {
        padding-left: env(safe-area-inset-left);
    }
}

/* ============ Practice section ============ */

.practice-heading {
    color: #800080;
}

.chapter-heading {
    margin-top: 1.5rem;
    font-size: 1.25rem;
}

.chapter-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin: 1rem 0 1.5rem;
    max-width: 520px;
}

.chapter-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    width: 100%;
    padding: 1rem 1.25rem;
    font-size: 1.1rem;
    color: #fff;
    background: linear-gradient(135deg, #800080, #4a1a6e);
    border: none;
    border-radius: 14px;
    cursor: pointer;
    text-align: left;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

    .chapter-card:hover {
        transform: translateY(-2px);
        box-shadow: 0 6px 16px rgba(128, 0, 128, 0.35);
    }

.chapter-order {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2rem;
    height: 2rem;
    padding: 0 0.5rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.22);
    font-weight: 700;
}

.practice-session {
    max-width: 640px;
}

.practice-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.practice-progress {
    font-weight: 600;
}

.practice-streak, .practice-score {
    margin-left: auto;
    font-weight: 700;
    color: #800080;
}

.practice-title {
    margin-bottom: 0.25rem;
}

.question-meta {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.badge {
    display: inline-block;
    padding: 0.3rem 0.75rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 700;
    color: #fff;
}

.badge-difficulty {
    background: #3497db;
}

.badge-marks {
    background: #e67e22;
}

.question-prompt {
    font-size: 1.15rem;
    line-height: 1.5;
}

.hint-button {
    margin: 0.25rem 0 0.5rem;
}

.hint-list {
    margin: 0.5rem 0 1rem;
}

.hint-item {
    margin-bottom: 0.35rem;
    padding: 0.6rem 0.9rem;
    background: #fff8e1;
    border-left: 4px solid #f5b301;
    border-radius: 8px;
}

.question-content {
    margin-top: 1rem;
}

/* ---- number entry ---- */

.num-field {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.num-label {
    min-width: 6rem;
    font-weight: 600;
}

.num-input {
    flex: 0 0 auto;
    width: 9rem;
    padding: 0.6rem 0.9rem;
    font-size: 1.35rem;
    text-align: center;
    border: 2px solid #b6c2d2;
    border-radius: 10px;
    outline: none;
}

    .num-input:focus {
        border-color: #800080;
        box-shadow: 0 0 0 3px rgba(128, 0, 128, 0.2);
    }

.num-correct .num-input {
    border-color: #28a745;
    background: #e8f8ee;
}

.num-wrong .num-input {
    border-color: #dc3545;
    background: #fdecec;
}

.field-glyph {
    font-size: 1.3rem;
    font-weight: 700;
}

.field-expected {
    margin: -0.5rem 0 1rem 6.75rem;
    font-size: 0.9rem;
    color: #dc3545;
}

/* ---- math keypad ---- */

.math-keypad {
    max-width: 300px;
    margin: 0.75rem auto 1.25rem;
    padding: 0.75rem;
    background: linear-gradient(to bottom, #2d2d3a, #1b1b26);
    border-radius: 16px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
}

.keypad-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
}

.keypad-key {
    padding: 0.9rem 0;
    font-size: 1.4rem;
    font-weight: 600;
    color: #fff;
    background: #44445a;
    border: none;
    border-radius: 10px;
    cursor: pointer;
}

    .keypad-key:hover {
        background: #585873;
    }

    .keypad-key:active {
        background: #800080;
    }

.keypad-done {
    width: 100%;
    margin-top: 0.5rem;
    font-size: 1.1rem;
    background: #28a745;
}

    .keypad-done:hover {
        background: #1f8b38;
    }

/* ---- equation choice ---- */

.eq-option {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    margin-bottom: 0.6rem;
    padding: 0.85rem 1rem;
    font-size: 1.05rem;
    text-align: left;
    background: #f4f6fa;
    border: 2px solid #d5dce8;
    border-radius: 12px;
    cursor: pointer;
}

.eq-letter {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.8rem;
    height: 1.8rem;
    border-radius: 50%;
    background: #800080;
    color: #fff;
    font-weight: 700;
}

.eq-display {
    font-family: 'Cambria', Georgia, serif;
    font-size: 1.15rem;
}

.eq-check {
    margin-left: auto;
    font-weight: 700;
    color: #28a745;
    font-size: 1.3rem;
}

.eq-option.selected {
    border-color: #800080;
    background: #f3e8f7;
}

.eq-option.correct-option {
    border-color: #28a745;
    background: #e8f8ee;
}

.eq-option.wrong-option {
    border-color: #dc3545;
    background: #fdecec;
}

/* ---- routes ---- */

.route-picker {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 0.9rem;
}

.route-card {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    padding: 1.1rem;
    text-align: left;
    background: linear-gradient(135deg, #800080, #5a1a86);
    color: #fff;
    border: none;
    border-radius: 16px;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

    .route-card:hover {
        transform: translateY(-3px);
        box-shadow: 0 8px 18px rgba(128, 0, 128, 0.4);
    }

.route-icon {
    font-size: 1.8rem;
}

.route-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.route-step {
    margin-bottom: 1rem;
    padding: 0.9rem;
    border: 2px solid #e2e6ee;
    border-radius: 12px;
}

.route-step.step-correct {
    border-color: #28a745;
    background: #f2fbf5;
}

.route-step.step-wrong {
    border-color: #dc3545;
    background: #fdf4f4;
}

.route-step-prompt {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
}

.step-glyph {
    font-size: 1.2rem;
    font-weight: 700;
}

.hint-toggle {
    margin-left: auto;
    font-size: 0.85rem;
    padding: 0.25rem 0.6rem;
    border: 1px solid #800080;
    border-radius: 999px;
    color: #800080;
    background: transparent;
    cursor: pointer;
}

.step-hint {
    margin: 0.5rem 0;
    padding: 0.55rem 0.8rem;
    background: #fff8e1;
    border-left: 4px solid #f5b301;
    border-radius: 8px;
    font-size: 0.95rem;
}

.route-step .num-field {
    margin-top: 0.9rem;
}

/* ---- submit & feedback ---- */

.submit-btn {
    margin-top: 0.5rem;
    min-width: 180px;
}

.feedback {
    margin-top: 1rem;
    padding: 0.9rem 1.1rem;
    border-radius: 12px;
    font-weight: 600;
}

.feedback-correct {
    background: #e8f8ee;
    border: 2px solid #28a745;
    color: #155724;
}

.feedback-wrong {
    background: #fdecec;
    border: 2px solid #dc3545;
    color: #721c24;
}

.feedback-marks {
    font-weight: 700;
    margin-top: 0.2rem;
}

.explanation-block {
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    background: #f4f6fa;
    border-radius: 10px;
}

    .explanation-block summary {
        cursor: pointer;
        font-weight: 600;
        color: #800080;
    }

    .explanation-block pre {
        white-space: pre-wrap;
        margin-top: 0.5rem;
        font-family: 'Segoe UI', sans-serif;
        font-size: 1rem;
        line-height: 1.5;
    }

.explanation-block p {
    margin-top: 0.5rem;
}

.practice-footer {
    margin-top: 1.5rem;
    text-align: center;
}

.practice-loading, .practice-empty {
    margin-top: 3rem;
    text-align: center;
}

/* ---- school test paper (step-by-step working) ---- */

.test-paper {
    margin-top: 1rem;
    padding: 1.25rem 1.25rem 1rem;
    background: #fff;
    border: 1px solid #e2e2e6;
    border-radius: 14px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
}

    .test-paper .question-content {
        margin-top: 0;
    }

.work-step {
    margin-bottom: 1.1rem;
    padding-bottom: 0.8rem;
    border-bottom: 1px dashed #d7dbe3;
}

    .work-step:last-child {
        border-bottom: none;
        margin-bottom: 0;
        padding-bottom: 0;
    }

.work-step.step-correct {
    background: #f2fbf5;
    border-radius: 10px;
    padding: 0.5rem 0.75rem 0.75rem;
}

.work-step.step-wrong {
    background: #fdf4f4;
    border-radius: 10px;
    padding: 0.5rem 0.75rem 0.75rem;
}

.work-step-head {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
}

.work-prompt {
    line-height: 1.5;
}

.work-expr {
    font-family: 'Cambria', Georgia, serif;
    font-size: 1.2rem;
}

.work-line {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

    .work-line .num-field {
        margin-bottom: 0;
    }

    .work-line .num-input {
        width: 6.5rem;
        border: none;
        border-bottom: 2px dotted #8a93a3;
        border-radius: 0;
        background: transparent;
        padding: 0.3rem 0.5rem;
        font-size: 1.2rem;
    }

    .work-line .num-input:focus {
        border-color: #800080;
        box-shadow: none;
        border-bottom-style: solid;
    }

    .work-line .num-correct .num-input {
        border-bottom-color: #28a745;
        background: transparent;
    }

    .work-line .num-wrong .num-input {
        border-bottom-color: #dc3545;
        background: transparent;
    }

    .work-line .field-expected {
        margin: 0.1rem 0 0;
    }

.work-line-hint {
    margin-top: 0.4rem;
}

.step-marks {
    margin-left: auto;
    min-width: 1.5rem;
    padding: 0.15rem 0.5rem;
    text-align: center;
    font-size: 0.8rem;
    font-weight: 700;
    color: #800080;
    background: #f3e8f7;
    border-radius: 999px;
}

.num-prefix {
    font-weight: 600;
}

/* ---- free-form expression entry ---- */

.expr-input {
    width: 15rem;
    text-align: left;
    font-family: 'Cambria', Georgia, serif;
}

.work-line .expr-input {
    width: 12rem;
}

.expr-field .field-expected {
    margin-left: 0;
}

.work-line .step-marks {
    flex: 0 0 auto;
}

.work-step .eq-option {
    margin: 0.6rem 0 0;
}

/* ---- Home & about ---- */
.home {
    display: flex;
    flex-direction: column;
    min-height: 70vh;
    justify-content: space-between;
    text-align: center;
}

.home-hero {
    padding: 2.5rem 1rem 1rem;
}

.home-title {
    font-size: 2.4rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.home-tagline {
    font-size: 1.25rem;
    font-style: italic;
    color: #512BD4;
    margin-bottom: 1.25rem;
}

.home-intro {
    max-width: 32rem;
    margin: 0 auto 1.75rem;
}

.home-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.home-footer {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 1.5rem 1rem;
    font-size: 0.9rem;
    color: #666;
}

/* Studio logo: small, above the "Be Different" line. */
.home-footer-logo {
    width: 64px;
    height: auto;
    margin: 0 auto 0.5rem;
}

/* App logo in place of the hero title text. */
.home-logo {
    display: block;
    width: min(75%, 280px);
    height: auto;
    margin: 0 auto;
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.45);
}

.about {
    max-width: 40rem;
    margin: 0 auto;
    padding: 1.5rem 1rem;
}

.about h2 {
    margin-top: 1.5rem;
    font-size: 1.25rem;
}

.about-small {
    font-size: 0.85rem;
    color: #666;
}

/* ---- Lessons ---- */
.lesson-page {
    max-width: 46rem;
    margin: 0 auto;
    padding: 1rem 0 2rem;
}

.lesson-chapter-title {
    margin: 1rem 0 0.5rem;
}

.lesson-section {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 2px solid #e5e0f5;
}

.lesson-section-title {
    font-size: 1.4rem;
    color: #512BD4;
}

.lesson-theory h3 {
    font-size: 1.1rem;
    margin-top: 1.25rem;
}

.lesson-theory p,
.lesson-example p,
.lesson-tip p,
.lesson-formula-note p {
    line-height: 1.6;
    margin-bottom: 0.75rem;
}

.lesson-list {
    padding-left: 1.25rem;
    line-height: 1.6;
}

.lesson-formula {
    margin: 1rem 0;
    padding: 0.9rem 1rem;
    border-left: 4px solid #512BD4;
    background: #f4f1fd;
    border-radius: 6px;
}

.lesson-formula-name {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #512BD4;
}

.lesson-formula-body {
    font-family: 'Cambria', Georgia, serif;
    font-size: 1.25rem;
    margin: 0.35rem 0;
    overflow-wrap: anywhere;
}

.lesson-example {
    margin: 1rem 0;
    padding: 0.9rem 1rem;
    border: 1px solid #d9d4ea;
    border-radius: 6px;
}

.lesson-example-label {
    font-weight: 600;
    margin-bottom: 0.4rem;
}

.lesson-example summary {
    cursor: pointer;
    color: #512BD4;
}

.lesson-example-solution {
    font-family: 'Cambria', Georgia, serif;
    font-size: 1.05rem;
    white-space: pre-wrap;
    background: #fafafa;
    padding: 0.75rem;
    border-radius: 4px;
    margin: 0.5rem 0;
}

.lesson-tip {
    display: flex;
    gap: 0.5rem;
    margin: 1rem 0;
    padding: 0.75rem 1rem;
    background: #fff8e1;
    border-radius: 6px;
}

.lesson-image-placeholder {
    margin: 1rem 0;
    padding: 1.25rem;
    border: 2px dashed #b9b2d6;
    border-radius: 8px;
    text-align: center;
    color: #666;
    background: #fbfaff;
}

.lesson-image-icon {
    font-size: 2rem;
}

.lesson-image img {
    max-width: 100%;
}

.lesson-practice-note {
    font-size: 0.9rem;
    color: #666;
    margin-top: 0.75rem;
}

.lesson-footer {
    margin-top: 2rem;
    text-align: center;
}

/* =====================================================================
   Chalk theme
   Square corners everywhere, borders in the grade colour, a chalk font
   for headings and a dusty chalkboard / paper feel.
   Grade colours: 8 blue, 9 purple, 10 green, 11 red, 12 black.
   ===================================================================== */

@font-face {
    font-family: 'Patrick Hand';
    src: url('fonts/PatrickHand-Regular.ttf') format('truetype');
    font-display: swap;
}

:root {
    --grade: #33413b;                     /* no grade chosen: chalkboard slate */
    --grade-tint: rgba(51, 65, 59, 0.07);
    --board: #2f3a34;
    --chalk: #f7f5ee;
    --chalk-yellow: #f3e08a;
    --tray: #8a6a47;
    --paper: #f3f1ea;
    --card: #fffdf8;
    --ink: #2b2b2b;
    --smudge: 4px 4px 0 rgba(0, 0, 0, 0.1);
    --chalk-font: 'Patrick Hand', 'Comic Sans MS', cursive;
}

.grade-1  { --grade: #e65100; --grade-tint: rgba(230, 81, 0, 0.08); }
.grade-2  { --grade: #c2185b; --grade-tint: rgba(194, 24, 91, 0.08); }
.grade-3  { --grade: #00838f; --grade-tint: rgba(0, 131, 143, 0.08); }
.grade-4  { --grade: #8d6e00; --grade-tint: rgba(141, 110, 0, 0.09); }
.grade-5  { --grade: #5d4037; --grade-tint: rgba(93, 64, 55, 0.08); }
.grade-6  { --grade: #3949ab; --grade-tint: rgba(57, 73, 171, 0.08); }
.grade-7  { --grade: #00695c; --grade-tint: rgba(0, 105, 92, 0.08); }
.grade-8  { --grade: #1f5fbf; --grade-tint: rgba(31, 95, 191, 0.08); }
.grade-9  { --grade: #6a3fa0; --grade-tint: rgba(106, 63, 160, 0.08); }
.grade-10 { --grade: #2e7d32; --grade-tint: rgba(46, 125, 50, 0.08); }
.grade-11 { --grade: #c62828; --grade-tint: rgba(198, 40, 40, 0.08); }
.grade-12 { --grade: #1b1b1b; --grade-tint: rgba(27, 27, 27, 0.07); }

/* Square corners, everywhere. */
*, *::before, *::after {
    border-radius: 0 !important;
}

html, body {
    color: var(--ink);
    background-color: var(--paper);
    /* Faint chalk dust on paper. */
    background-image:
        radial-gradient(rgba(0, 0, 0, 0.035) 1px, transparent 1px),
        radial-gradient(rgba(0, 0, 0, 0.025) 1px, transparent 1px);
    background-size: 7px 7px, 11px 11px;
    background-position: 0 0, 3px 5px;
}

h1, h2, h3,
.practice-heading, .chapter-heading, .chapter-title, .practice-title,
.lesson-section-title, .lesson-example-label, .route-card strong,
.btn, .badge, .practice-progress, .practice-streak, .practice-score {
    font-family: var(--chalk-font);
    letter-spacing: 0.02em;
}

h1, .practice-heading {
    font-size: 2.1rem;
}

/* ---- Buttons ---- */
.btn {
    font-size: 1.15rem;
    border-width: 2px;
}

.btn-primary,
.btn-primary:hover,
.btn-primary:focus {
    color: #fff;
    background-color: var(--grade);
    border-color: var(--grade);
}

.btn-primary:hover {
    filter: brightness(1.15);
}

.btn-secondary {
    color: var(--ink);
    background-color: var(--card);
    border-color: var(--grade);
}

.btn-secondary:hover {
    color: var(--ink);
    background-color: var(--grade-tint);
    border-color: var(--grade);
}

/* ---- Grade picker ---- */
/* ---- Grade picker: one chalkboard tile per grade, in its colour ---- */
/* Three across the top (8, 9, 10) and two centred below (11, 12): six columns, each tile spans two. */
.grade-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 0.75rem;
    max-width: 560px;
    margin: 1.25rem auto;
}

    .grade-grid > .grade-tile {
        grid-column: span 2;
    }

        /* With exactly five grades, the last two sit between the three above. */
        .grade-grid > .grade-tile:nth-child(4):nth-last-child(2) {
            grid-column: 2 / span 2;
        }

        .grade-grid > .grade-tile:nth-child(5):last-child {
            grid-column: 4 / span 2;
        }

.grade-tile {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1;
    padding: 0.5rem;
    color: var(--chalk);
    background-color: var(--board);
    background-image:
        radial-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px),
        radial-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px);
    background-size: 6px 6px, 13px 13px;
    border: 5px solid var(--tray);
    border-top: 12px solid var(--grade);
    box-shadow: var(--smudge);
    font-family: var(--chalk-font);
    cursor: pointer;
    transition: transform 0.12s ease;
}

    .grade-tile:active {
        transform: scale(0.96);
    }

.grade-tile-label {
    font-size: clamp(0.8rem, 3.2vw, 1.15rem);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    opacity: 0.85;
}

.grade-tile-number {
    font-size: clamp(2.4rem, 11vw, 4rem);
    line-height: 1;
    text-shadow: 0 0 3px rgba(255, 255, 255, 0.4);
}

/* Grade 12's colour is black: give its band a chalk edge so it still reads on the dark tile. */
.grade-tile.grade-12 {
    border-top-color: #111;
    box-shadow: var(--smudge), inset 0 3px 0 rgba(247, 245, 238, 0.35);
}

/* ---- Can't connect ---- */
.offline-card {
    max-width: 420px;
    margin: 1.5rem auto;
    padding: 1.5rem 1.25rem;
    text-align: center;
    background: var(--card);
    border: 3px solid var(--grade);
    box-shadow: var(--smudge);
}

    .offline-card h2 {
        font-family: var(--chalk-font);
        color: var(--grade);
    }

.offline-icon {
    font-size: 2.5rem;
}

/* ---- Chapter cards ---- */
.practice-heading,
.chapter-heading {
    color: var(--grade);
}

.chapter-card {
    color: var(--ink);
    background: var(--card);
    border: 3px solid var(--grade);
    box-shadow: var(--smudge);
}

.chapter-card:hover {
    background: var(--grade-tint);
    box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.12);
}

.chapter-order {
    color: #fff;
    background: var(--grade);
}

.chapter-title {
    font-size: 1.3rem;
}

/* ---- Practice ---- */
.practice-streak,
.practice-score,
.practice-progress {
    color: var(--grade);
    font-size: 1.15rem;
}

.badge-difficulty {
    background: var(--grade);
}

.badge-marks {
    background: var(--ink);
}

.test-paper {
    background: var(--card);
    border: 3px solid var(--grade);
    box-shadow: var(--smudge);
}

.num-input,
.expr-input {
    background: #fff;
    border: 2px solid rgba(0, 0, 0, 0.3);
}

.num-input:focus,
.expr-input:focus {
    outline: none;
    border-color: var(--grade);
    box-shadow: 0 0 0 3px var(--grade-tint);
}

.work-line .num-input:focus {
    border-color: var(--grade);
}

.work-step {
    border-bottom: 2px dashed rgba(0, 0, 0, 0.15);
}

.step-marks {
    color: var(--grade);
    background: var(--grade-tint);
    border: 1px solid var(--grade);
}

.eq-option {
    background: var(--card);
    border: 2px solid rgba(0, 0, 0, 0.25);
}

.eq-option.selected {
    border-color: var(--grade);
    background: var(--grade-tint);
}

.eq-letter {
    background: var(--grade);
    font-family: var(--chalk-font);
}

.route-card {
    color: var(--ink);
    background: var(--card);
    border: 3px solid var(--grade);
    box-shadow: var(--smudge);
}

.route-step {
    background: var(--card);
    border: 2px solid var(--grade);
}

.hint-toggle,
.hint-button {
    color: var(--grade);
    border: 2px solid var(--grade);
    background: transparent;
}

.hint-item,
.step-hint {
    background: #fff8e1;
    border-left: 4px solid var(--chalk-yellow);
}

.explanation-block {
    background: var(--card);
    border: 2px solid var(--grade);
}

.explanation-block summary {
    color: var(--grade);
}

.feedback {
    border-width: 2px;
    border-style: solid;
    font-family: var(--chalk-font);
    font-size: 1.2rem;
}

/* The keypad is a little chalkboard. */
.math-keypad {
    background: var(--board);
    border-top: 6px solid var(--tray);
}

.keypad-key {
    color: var(--chalk);
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(247, 245, 238, 0.35);
    font-family: var(--chalk-font);
    font-size: 1.3rem;
}

.keypad-key:hover {
    background: rgba(255, 255, 255, 0.14);
}

.keypad-key:active {
    background: var(--grade);
}

/* ---- Lessons ---- */
.lesson-chapter-title,
.lesson-section-title {
    color: var(--grade);
}

.lesson-section {
    border-top: 3px solid var(--grade);
}

.lesson-formula {
    background: var(--grade-tint);
    border: 2px solid var(--grade);
    border-left-width: 8px;
}

.lesson-formula-name {
    color: var(--grade);
}

.lesson-example {
    background: var(--card);
    border: 2px solid var(--grade);
    box-shadow: var(--smudge);
}

.lesson-example summary {
    color: var(--grade);
}

.lesson-example-solution {
    background: var(--paper);
    border-left: 4px solid var(--grade);
}

.lesson-tip {
    background: #fff8e1;
    border-left: 4px solid var(--chalk-yellow);
}

.lesson-image-placeholder {
    background: var(--grade-tint);
    border: 2px dashed var(--grade);
}

/* ---- Home: a framed chalkboard ---- */
.home-hero {
    color: var(--chalk);
    background-color: var(--board);
    background-image:
        radial-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px),
        radial-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px);
    background-size: 6px 6px, 13px 13px;
    border: 10px solid var(--tray);
    box-shadow: var(--smudge);
    margin-top: 1.5rem;
}

.home-title {
    font-family: var(--chalk-font);
    font-weight: normal;
    font-size: 3rem;
    color: var(--chalk);
    text-shadow: 0 0 3px rgba(255, 255, 255, 0.4);
}

.home-tagline {
    font-family: var(--chalk-font);
    font-size: 1.6rem;
    font-style: normal;
    color: var(--chalk-yellow);
}

.home-intro {
    color: rgba(247, 245, 238, 0.9);
}

.home-actions .btn {
    color: var(--chalk);
    background: transparent;
    border: 2px solid var(--chalk);
    padding: 0.5rem 2rem;
}

.home-actions .btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Compact keypad: four columns, a basic page and an extras page swapped by the toggle key. */
.keypad-grid {
    grid-template-columns: repeat(4, 1fr);
}

.keypad-key.keypad-toggle {
    font-size: 1rem;
    background: rgba(255, 255, 255, 0.16);
}

.keypad-key.keypad-done {
    width: auto;
    margin-top: 0;
    font-size: 1rem;
    background: var(--grade, #28a745);
}

.keypad-key.keypad-wide {
    grid-column: span 2;
}

/* Live preview of a typed expression with real powers. */
.expr-preview {
    margin: 0.25rem 0 0.5rem;
    font-family: "Cambria", Georgia, serif;
    font-size: 1.2rem;
    color: var(--grade);
}

/* ---- Report a problem ---- */
.flag-row {
    display: flex;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0.5rem 0;
}

.flag-button,
.learn-button {
    font-family: var(--chalk-font);
    font-size: 1rem;
    color: #666;
    background: transparent;
    border: 1px dashed rgba(0, 0, 0, 0.3);
    padding: 0.25rem 0.75rem;
    cursor: pointer;
}

.flag-button:hover,
.learn-button:hover {
    color: var(--ink);
    border-color: var(--grade);
}

.flag-button-compact {
    font-size: 0.9rem;
    padding: 0.15rem 0.5rem;
}

.flag-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(20, 26, 23, 0.6);
}

.flag-dialog {
    width: 100%;
    max-width: 28rem;
    max-height: 90vh;
    overflow-y: auto;
    padding: 1.25rem;
    background: var(--card);
    border: 3px solid var(--grade);
    box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.2);
}

.flag-dialog h3 {
    margin-top: 0;
    color: var(--grade);
}

.flag-reasons {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin: 0.75rem 0;
}

.flag-reason {
    display: flex;
    gap: 0.6rem;
    align-items: center;
    padding: 0.5rem 0.6rem;
    border: 2px solid rgba(0, 0, 0, 0.15);
    cursor: pointer;
}

.flag-reason.selected {
    border-color: var(--grade);
    background: var(--grade-tint);
}

.flag-comment {
    width: 100%;
    padding: 0.5rem;
    border: 2px solid rgba(0, 0, 0, 0.25);
    font: inherit;
}

.flag-comment:focus {
    outline: none;
    border-color: var(--grade);
}

.flag-error {
    margin-top: 0.5rem;
    color: #b32121;
}

.flag-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1rem;
}

/* ---- Rounds: progress dots ---- */
.round-dots {
    display: flex;
    gap: 0.3rem;
    align-items: center;
}

.round-dots .dot {
    width: 0.8rem;
    height: 0.8rem;
    border: 2px solid var(--grade);
    background: transparent;
}

.round-dots .dot-current {
    background: var(--grade-tint);
    outline: 2px solid var(--grade);
    outline-offset: 1px;
}

.round-dots .dot-right {
    background: var(--grade);
}

.round-dots .dot-wrong {
    background: repeating-linear-gradient(45deg, var(--grade) 0 2px, transparent 2px 5px);
}

.badge-comeback {
    background: #8a6a47;
}

/* ---- Chalk dust celebration ---- */
.chalk-celebration {
    position: relative;
    height: 3rem;
    margin: 0.5rem 0;
    text-align: center;
    pointer-events: none;
}

.chalk-celebration.chalk-big {
    height: 6rem;
}

.chalk-message {
    display: inline-block;
    font-family: var(--chalk-font);
    font-size: 1.8rem;
    color: var(--grade);
    text-shadow: 0 0 2px rgba(0, 0, 0, 0.12);
    animation: chalk-pop 0.45s ease-out both;
}

.chalk-big .chalk-message {
    font-size: 3rem;
}

.chalk-puff {
    position: absolute;
    left: 50%;
    top: 50%;
}

.chalk-puff i {
    position: absolute;
    width: var(--size);
    height: var(--size);
    background: var(--colour);
    opacity: 0;
    filter: blur(0.6px);
    animation: chalk-dust 0.9s ease-out var(--delay) both;
}

.chalk-big .chalk-puff i {
    animation-duration: 1.6s;
}

@keyframes chalk-pop {
    0% { transform: scale(0.6) rotate(-4deg); opacity: 0; }
    60% { transform: scale(1.12) rotate(2deg); opacity: 1; }
    100% { transform: scale(1) rotate(0); opacity: 1; }
}

@keyframes chalk-dust {
    0% { transform: translate(0, 0) scale(1); opacity: 0.85; }
    100% { transform: translate(var(--dx), var(--dy)) scale(0.3); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
    .chalk-message,
    .chalk-puff i {
        animation: none;
    }

    .chalk-puff {
        display: none;
    }
}

/* ---- Round results ---- */
.practice-results {
    max-width: 32rem;
    margin: 1rem auto;
    text-align: center;
}

.results-card {
    padding: 1.25rem;
    background: var(--card);
    border: 3px solid var(--grade);
    box-shadow: var(--smudge);
}

.results-score {
    font-family: var(--chalk-font);
    font-size: 2.4rem;
    color: var(--grade);
}

.results-detail {
    color: #555;
}

.results-section {
    margin-top: 0.9rem;
    padding-top: 0.9rem;
    border-top: 2px dashed rgba(0, 0, 0, 0.12);
}

.results-mastered {
    font-family: var(--chalk-font);
    font-size: 1.25rem;
}

.results-soft {
    color: #555;
    font-size: 0.95rem;
}

.results-streak {
    font-family: var(--chalk-font);
    font-size: 1.2rem;
}

.results-actions {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    align-items: center;
    margin-top: 1.25rem;
}

/* ---- Mastery tally ---- */
.chapter-body {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.mastery-tally {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    justify-content: center;
}

.chapter-body .mastery-tally {
    justify-content: flex-start;
}

.mastery-squares {
    display: flex;
    gap: 3px;
    flex-wrap: wrap;
}

.mastery-squares span {
    width: 0.75rem;
    height: 0.75rem;
    border: 2px solid var(--grade);
}

.mastery-squares span.filled {
    background: var(--grade);
}

.mastery-label {
    font-family: var(--chalk-font);
    font-size: 1rem;
    color: #555;
}

/* ---- Home: today panel on the chalkboard ---- */
.home-today {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.home-continue {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    width: 100%;
    max-width: 26rem;
    padding: 1rem 1.25rem;
    text-align: left;
    color: var(--ink);
    background: var(--card);
    border: 4px solid var(--grade);
    box-shadow: 5px 5px 0 rgba(0, 0, 0, 0.35);
    cursor: pointer;
}

.home-continue:hover {
    transform: translate(-1px, -1px);
}

.home-continue-label {
    font-family: var(--chalk-font);
    font-size: 1rem;
    color: var(--grade);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.home-continue-title {
    font-family: var(--chalk-font);
    font-size: 1.8rem;
}

.home-continue-meta {
    color: #666;
}

.home-note,
.home-streak {
    margin: 0;
    color: rgba(247, 245, 238, 0.9);
}

.home-streak {
    font-family: var(--chalk-font);
    font-size: 1.3rem;
}

.home-links {
    display: flex;
    gap: 1.5rem;
    justify-content: center;
    margin-top: 1rem;
    font-family: var(--chalk-font);
    font-size: 1.2rem;
}

/* ---- Settings ---- */
.nav-bar {
    position: relative;
}

.settings-button {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1.6rem;
    line-height: 1;
    color: var(--chalk);
    background: transparent;
    border: none;
    cursor: pointer;
}

.settings-dialog {
    max-width: 32rem;
    text-align: left;
}

.settings-section {
    padding: 0.75rem 0;
    border-top: 2px dashed rgba(0, 0, 0, 0.12);
}

.settings-section h4 {
    font-family: var(--chalk-font);
    font-size: 1.25rem;
    margin: 0 0 0.4rem;
}

.settings-label {
    display: block;
    margin: 0.5rem 0;
}

.settings-small {
    font-size: 0.85rem;
    color: #666;
}

.settings-warning {
    padding: 0.5rem 0.75rem;
    background: #fff8e1;
    border-left: 4px solid var(--chalk-yellow);
}

.settings-message {
    margin-top: 0.5rem;
    font-weight: 600;
}

.settings-gap {
    margin-top: 0.5rem;
}

.recovery-code {
    margin: 0.5rem 0;
    padding: 0.75rem;
    font-family: Consolas, "Courier New", monospace;
    font-size: 1.35rem;
    letter-spacing: 0.08em;
    text-align: center;
    color: var(--chalk);
    background: var(--board);
    border: 4px solid var(--tray);
    user-select: all;
}

/* ---- Error pop-up, on theme ---- */
.error-card {
    max-width: 380px;
    margin: 28vh auto 0;
    padding: 1.5rem 1.25rem 1.25rem;
    text-align: center;
    color: var(--chalk);
    background-color: var(--board);
    background-image:
        radial-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px),
        radial-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px);
    background-size: 6px 6px, 13px 13px;
    border: 8px solid var(--tray);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
    animation: error-in 0.2s ease-out both;
}

    .error-card h2 {
        font-family: var(--chalk-font);
        font-size: 1.7rem;
        color: var(--chalk-yellow);
    }

    .error-card p {
        margin-bottom: 1.1rem;
    }

.error-chalk {
    font-size: 2rem;
}

.error-actions {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
}

    .error-actions .reload,
    .error-actions .dismiss {
        padding: 0.5rem 1rem;
        font-family: var(--chalk-font);
        font-size: 1.15rem;
        text-decoration: none;
        cursor: pointer;
    }

    .error-actions .reload {
        color: var(--board);
        background: var(--chalk);
        border: 2px solid var(--chalk);
    }

    .error-actions .dismiss {
        color: var(--chalk);
        background: transparent;
        border: 2px solid rgba(247, 245, 238, 0.6);
    }

@keyframes error-in {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: none; }
}

/* ---- Question diagrams (SVG, drawn inline so these styles apply) ----
   Class names used by the Studio's diagram builder and the starter drawings:
   qfig-shape (filled outline), qfig-line, qfig-dashed, qfig-mark (angle arcs, right-angle boxes,
   ticks, arrows), qfig-point, qfig-label (point names) and qfig-value (numbers, e.g. {h} cm). */
.question-figure {
    margin: 0.5rem auto 1rem;
    max-width: 360px;
    text-align: center;
}

    .question-figure svg {
        width: 100%;
        height: auto;
        overflow: visible;
    }

.question-figure-missing {
    padding: 1rem;
    border: 2px dashed var(--grade);
    color: #666;
}

.qfig-shape {
    fill: var(--grade-tint);
    stroke: var(--ink);
    stroke-width: 2;
    stroke-linejoin: round;
}

.qfig-line {
    fill: none;
    stroke: var(--ink);
    stroke-width: 2;
    stroke-linecap: round;
}

.qfig-dashed {
    fill: none;
    stroke: var(--ink);
    stroke-width: 1.5;
    stroke-dasharray: 6 5;
}

.qfig-mark {
    fill: none;
    stroke: var(--grade);
    stroke-width: 1.8;
}

.qfig-point {
    fill: var(--ink);
}

.qfig-label {
    font-family: var(--chalk-font);
    font-size: 17px;
    fill: var(--ink);
}

.qfig-value {
    font-family: var(--chalk-font);
    font-size: 15px;
    fill: var(--grade);
}

/* ---- Back button and coming-soon pages ---- */
.back-button {
    margin: 0.25rem 0 0.75rem;
}

.coming-soon {
    max-width: 440px;
    margin: 2rem auto;
    padding: 1.75rem 1.25rem;
    text-align: center;
    background: var(--card);
    border: 3px dashed var(--grade);
    box-shadow: var(--smudge);
}

    .coming-soon h1 {
        font-family: var(--chalk-font);
        color: var(--grade);
    }

.coming-soon-icon {
    font-size: 2.5rem;
}

/* ---- Classes in Settings ---- */
.class-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0;
    border-bottom: 1px dashed rgba(0, 0, 0, 0.2);
}


/* Calculator sheet: the question stays visible above it. */
.badge-no-calc {
    background: var(--board);
    color: var(--chalk);
}

.calc-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1200;
    max-height: 72vh;
    overflow-y: auto;
    max-width: 560px;
    margin: 0 auto;
    padding: 0.6rem 0.75rem calc(0.75rem + env(safe-area-inset-bottom));
    background: var(--board);
    color: var(--chalk);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.3);
}

.calc-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.4rem;
}

.calc-tabs {
    display: flex;
    gap: 0.35rem;
}

.calc-tab {
    border: 1px solid var(--chalk);
    border-radius: 8px;
    background: none;
    color: var(--chalk);
    padding: 0.2rem 0.7rem;
}

.calc-tab.active {
    background: var(--chalk);
    color: var(--board);
}

.calc-close {
    border: none;
    background: none;
    color: var(--chalk);
    font-size: 1.1rem;
    min-width: 44px;
    min-height: 36px;
}

.calc-equation {
    margin: 0 0 0.3rem;
    text-align: center;
    color: var(--chalk-yellow);
    font-size: 1.05rem;
}

.calc-formula {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    font-size: 1rem;
    overflow-x: auto;
}

.calc-filled {
    margin-top: 0.3rem;
    color: var(--chalk-yellow);
    font-size: 0.9rem;
}

.calc-fraction {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    white-space: nowrap;
}

.calc-over {
    padding: 0 0.3rem;
    border-bottom: 1px solid currentColor;
}

.calc-boxes {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.4rem;
    margin: 0.5rem 0 0.3rem;
}

.calc-box {
    min-height: 44px;
    border: 2px solid transparent;
    border-radius: 8px;
    background: var(--card);
    color: var(--ink);
}

.calc-box.active {
    border-color: var(--chalk-yellow);
}

.calc-box.wrong {
    border-color: #e57373;
    background: #fdecea;
}

.calc-flag {
    margin: 0 0 0.3rem;
    color: #ffb4a9;
    font-size: 0.9rem;
    text-align: center;
}

.calc-result {
    margin-bottom: 0.4rem;
    padding: 0.35rem;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.1);
    text-align: center;
}

.calc-screen {
    min-height: 3.4rem;
    margin-bottom: 0.4rem;
    padding: 0.3rem 0.5rem;
    border-radius: 8px;
    background: var(--card);
    color: var(--ink);
    text-align: right;
    overflow-wrap: anywhere;
}

.calc-entry {
    font-size: 0.9rem;
}

.calc-answer {
    font-size: 1.25rem;
    font-weight: 600;
}

.calc-keys {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.3rem;
}

.calc-keys-small {
    grid-template-columns: repeat(4, 1fr);
}

.calc-key {
    min-height: 40px;
    padding: 0;
    border: none;
    border-radius: 8px;
    background: var(--card);
    color: var(--ink);
    font-size: 1rem;
}

.calc-key.calc-science {
    background: var(--tray);
    color: var(--chalk);
    font-size: 0.85rem;
}

.calc-key.calc-equals {
    background: var(--chalk-yellow);
    font-weight: 700;
}

.calc-wide {
    grid-column: span 2;
}

.calc-tall {
    grid-row: span 2;
}

/* Reminder pop-ups. The daily one is a chalkboard; the Friday one is a sticky note. */
.nudge-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1300;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(0, 0, 0, 0.5);
}

.nudge-board,
.nudge-sticky {
    position: relative;
    width: 100%;
    max-width: 340px;
    padding: 1.25rem;
    text-align: center;
}

.nudge-board {
    border: 6px solid var(--tray);
    border-radius: 8px;
    background: var(--board);
    color: var(--chalk);
    font-family: var(--chalk-font);
}

.nudge-sticky {
    background: #fbe36f;
    color: #3a3216;
    transform: rotate(-2deg);
    box-shadow: 6px 8px 0 rgba(0, 0, 0, 0.25);
}

.nudge-pin {
    position: absolute;
    top: -14px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1.5rem;
}

.nudge-go {
    display: block;
    width: 100%;
    min-height: 44px;
    margin-top: 0.5rem;
    background: var(--chalk-yellow);
    color: var(--ink);
    font-weight: 700;
}

.nudge-sticky .nudge-go {
    background: #3a3216;
    color: #fbe36f;
}

.nudge-later {
    min-height: 44px;
    border: none;
    background: none;
    color: inherit;
    text-decoration: underline;
}

/* Jotter: an old exercise book that slides up over the lower part of the screen. */
.lesson-jotter {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 0.4rem;
}

.jotter-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1150;
    display: flex;
    flex-direction: column;
    height: 62vh;
    max-width: 560px;
    margin: 0 auto;
    padding: 0.4rem 0.5rem calc(0.4rem + env(safe-area-inset-bottom));
    border-radius: 14px 14px 0 0;
    background: #7a5a3a;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.35);
    animation: jotter-up 0.2s ease-out;
}

@keyframes jotter-up {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.jotter-bar,
.jotter-tools,
.jotter-pages {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.jotter-bar {
    justify-content: space-between;
    margin-bottom: 0.3rem;
}

.jotter-tool,
.jotter-page,
.jotter-erase {
    min-width: 40px;
    min-height: 38px;
    border: 1px solid #b39a63;
    border-radius: 6px;
    background: #efe2c2;
    color: #4a3a1c;
}

.jotter-tool.active,
.jotter-page.active {
    background: #4a3a1c;
    color: #efe2c2;
}

.jotter-close {
    min-width: 44px;
    min-height: 38px;
    border: none;
    background: none;
    color: #fff;
    font-size: 1.1rem;
}

.jotter-paper {
    position: relative;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    border-radius: 3px;
    background-color: #ecdfbd;
    background-image:
        radial-gradient(ellipse at 12% 18%, rgba(133, 94, 38, 0.2), transparent 32%),
        radial-gradient(ellipse at 88% 80%, rgba(133, 94, 38, 0.24), transparent 38%),
        radial-gradient(ellipse at 70% 12%, rgba(133, 94, 38, 0.1), transparent 24%),
        linear-gradient(to right, transparent 34px, rgba(160, 60, 50, 0.3) 34px, rgba(160, 60, 50, 0.3) 35px, transparent 35px),
        repeating-linear-gradient(to bottom, transparent 0, transparent 27px, rgba(70, 90, 120, 0.2) 27px, rgba(70, 90, 120, 0.2) 28px);
    box-shadow: inset 0 0 28px rgba(96, 66, 24, 0.4);
}

.jotter-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    touch-action: none;
}

.jotter-canvas.typing {
    cursor: text;
}

.jotter-note {
    position: absolute;
    z-index: 1;
    min-height: 28px;
    padding: 0;
    overflow: hidden;
    border: none;
    outline: none;
    resize: none;
    background: transparent;
    color: #27303f;
    font-family: var(--chalk-font);
    font-size: 1.05rem;
    line-height: 28px;
    field-sizing: content;
}

.jotter-symbols {
    display: flex;
    gap: 0.25rem;
    margin-top: 0.3rem;
    overflow-x: auto;
}

.jotter-symbol {
    flex: 0 0 auto;
    min-width: 38px;
    min-height: 38px;
    border: none;
    border-radius: 6px;
    background: #efe2c2;
    color: #27303f;
}

.jotter-pages {
    margin-top: 0.3rem;
}

.jotter-erase {
    margin-left: auto;
    padding: 0 0.5rem;
}

.jotter-erase + .jotter-erase {
    margin-left: 0;
}

.jotter-erase.confirm {
    background: #a33a2c;
    color: #fff;
}

/* The keypad sits where a phone keyboard does, with the question scrolled into view above it. */
.math-keypad {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1100;
    max-width: 560px;
    margin: 0 auto;
    padding: 0.4rem 0.4rem calc(0.4rem + env(safe-area-inset-bottom));
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -4px 14px rgba(0, 0, 0, 0.3);
}

.math-keypad .keypad-grid {
    gap: 0.3rem;
}

.math-keypad .keypad-key {
    min-height: 46px;
    padding: 0.45rem 0;
}

html:has(.math-keypad) {
    scroll-padding-top: 4rem;
    scroll-padding-bottom: calc(var(--keypad-height, 280px) + 0.75rem);
}

body:has(.math-keypad) {
    padding-bottom: calc(var(--keypad-height, 280px) + 1rem);
}

/* Worked lines: a long equation takes its own row with the answer under it; a short one stays beside its box. */
.work-line {
    flex-wrap: wrap;
}

.work-line .work-expr {
    flex: 1 1 auto;
    min-width: 0;
    overflow-wrap: anywhere;
}

.work-line .num-field {
    flex: 1 1 8rem;
    min-width: 0;
}

.work-line .num-input,
.work-line .expr-input {
    width: 100%;
    min-width: 0;
}

/* Hint and jotter side by side; the tools under the question in one straight, even row. */
.question-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.question-actions:empty {
    display: none;
}

.question-tools {
    flex-wrap: nowrap;
    justify-content: stretch;
    align-items: stretch;
    margin-top: 1rem;
}

.question-tools .learn-button,
.question-tools .flag-button {
    flex: 1 1 0;
    min-width: 0;
    min-height: 44px;
    padding: 0.25rem;
    font-size: 0.9rem;
    line-height: 1.15;
    text-align: center;
}

.practice-footer {
    margin-top: 1rem;
}

/* ---- Menu (replaces the settings cog) ---- */
.menu-open { display: inline-flex; align-items: center; gap: 0.2rem; }

.star-badge {
    display: inline-block;
    min-width: 1.4rem;
    padding: 0.05rem 0.35rem;
    border-radius: 999px;
    background: var(--chalk-yellow);
    color: var(--ink);
    font: 700 0.8rem/1.2 var(--chalk-font);
    text-align: center;
    box-shadow: 0 0 0 2px var(--board);
}

.menu-list { display: grid; gap: 0.5rem; margin: 0.5rem 0 1rem; }

.menu-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 52px;
    padding: 0.6rem 0.9rem;
    border: 2px solid var(--grade, #33413b);
    border-radius: 8px;
    background: var(--card);
    color: var(--ink);
    font: 1.15rem var(--chalk-font);
    text-align: left;
}

.menu-back {
    border: none;
    background: none;
    color: var(--grade, #33413b);
    font: 1rem var(--chalk-font);
    padding: 0;
    min-height: 36px;
}

.settings-check { display: flex; gap: 0.5rem; align-items: flex-start; margin: 0.6rem 0; }
.settings-check input { margin-top: 0.3rem; min-width: 18px; min-height: 18px; }

/* ---- Fire around the score: orange from 3 in a row, blue from 5 ---- */
.practice-score { position: relative; padding: 0.1rem 0.5rem; border-radius: 10px; }

.practice-score.on-fire {
    --flame: #ff8a1f;
    --flame-core: #ffd23f;
    color: #b44d00;
    box-shadow: 0 0 0 2px var(--flame), 0 0 14px 2px var(--flame);
    animation: flicker 0.9s ease-in-out infinite alternate;
}

.practice-score.fire-blue {
    --flame: #2f8cff;
    --flame-core: #a8e1ff;
    color: #0d4fa8;
}

.fire-count { margin-right: 0.35rem; font-weight: 700; }

.fire-flames { position: absolute; left: 0; right: 0; top: -14px; height: 16px; display: flex; justify-content: space-around; pointer-events: none; }

.fire-flames i {
    width: 12px;
    height: 16px;
    border-radius: 50% 50% 35% 35%;
    background: radial-gradient(circle at 50% 70%, var(--flame-core), var(--flame) 70%, transparent 72%);
    transform-origin: bottom center;
    animation: flame 0.6s ease-in-out infinite alternate;
}

.fire-flames i:nth-child(2) { animation-delay: 0.2s; height: 20px; margin-top: -4px; }
.fire-flames i:nth-child(3) { animation-delay: 0.4s; }

@keyframes flame { from { transform: scaleY(0.8) rotate(-4deg); } to { transform: scaleY(1.15) rotate(4deg); } }
@keyframes flicker { from { box-shadow: 0 0 0 2px var(--flame), 0 0 10px 1px var(--flame); } to { box-shadow: 0 0 0 2px var(--flame), 0 0 18px 4px var(--flame); } }

/* ---- Mastery shapes, drawn in chalk ---- */
.mastery-shapes { display: flex; gap: 4px; flex-wrap: wrap; }

.mastery-shapes .shape { width: 1.05rem; height: 1.05rem; overflow: visible; }

.mastery-shapes .shape * {
    fill: none;
    stroke: var(--grade);
    stroke-width: 2;
    stroke-linejoin: round;
    stroke-linecap: round;
    stroke-dasharray: 3 0.6;
}

.mastery-shapes .shape-1 * { fill: var(--grade-tint); }
.mastery-shapes .shape-2 * { fill: color-mix(in srgb, var(--grade) 35%, transparent); }
.mastery-shapes .shape-3 * { fill: var(--grade); stroke-dasharray: none; }

/* ---- Achievements ---- */
.achievements-page h1 { margin-bottom: 0.25rem; }

.achievement-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.75rem; margin: 1rem 0 1.5rem; }

.achievement-card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
    padding: 0.8rem 0.5rem;
    border: 2px solid var(--grade, #33413b);
    border-radius: 10px;
    background: var(--card);
    color: var(--ink);
    font-family: var(--chalk-font);
    text-align: center;
}

.achievement-card.unseen { box-shadow: 0 0 0 3px var(--chalk-yellow); }
.achievement-star { position: absolute; top: -8px; right: -8px; }
.achievement-icon { font-size: 2rem; line-height: 1; }
.achievement-title { font-size: 1.05rem; font-weight: 700; }
.achievement-progress { font-size: 0.85rem; color: #555; }
.achievement-medals { display: flex; gap: 0.3rem; }

.medal {
    width: 1.7rem;
    height: 1.7rem;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font: 700 0.8rem var(--chalk-font);
    color: #999;
    border: 2px dashed #bbb;
}

.medal.earned { color: #fff; border-style: solid; }
.medal-1.earned { background: #b06a2c; border-color: #8a4f1c; }
.medal-2.earned { background: #9aa4ad; border-color: #6d7780; }
.medal-3.earned { background: #d4a514; border-color: #a17c07; }

.certificate-row { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; padding: 0.5rem 0; border-bottom: 1px dashed #ccc; }

/* ---- Badge heads-up ---- */
.achievement-toast {
    position: fixed;
    left: 50%;
    top: 70px;
    z-index: 1400;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    max-width: calc(100vw - 32px);
    padding: 0.6rem 1rem;
    border: 3px solid var(--chalk-yellow);
    border-radius: 12px;
    background: var(--board);
    color: var(--chalk);
    font: 1rem var(--chalk-font);
    text-align: left;
    transform: translateX(-50%);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
    animation: toast-in 0.35s ease-out, toast-out 0.4s ease-in 3.1s forwards;
}

.toast-icon { font-size: 1.8rem; }
.medal-tier-1 { border-color: #b06a2c; }
.medal-tier-2 { border-color: #c7cfd6; }
.medal-tier-3 { border-color: #d4a514; }

@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -20px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes toast-out { to { opacity: 0; transform: translate(-50%, -12px); } }

/* ---- Formulas and the jotter ---- */
.formula-card {
    margin: 0.4rem 0;
    padding: 0.6rem 0.8rem;
    border: 2px solid var(--grade, #33413b);
    border-radius: 8px;
    background: var(--card);
    user-select: none;
}

.formula-name { font: 700 0.95rem var(--chalk-font); }
.formula-text { font-family: 'Cambria', Georgia, serif; font-size: 1.15rem; }

.figure-hint { margin: 0.2rem 0 0.6rem; color: #666; font-size: 0.85rem; text-align: center; }

.jotter-send-pages { display: flex; gap: 0.4rem; margin: 0.6rem 0 1rem; }

.jotter-colour {
    width: 30px;
    height: 30px;
    border: 2px solid #b39a63;
    border-radius: 50%;
    background: var(--pen);
}

.jotter-colour.active { box-shadow: 0 0 0 3px #4a3a1c; }

.jotter-image { position: absolute; z-index: 0; pointer-events: none; opacity: 0.9; }
.jotter-image svg, .jotter-image img { width: 100%; height: auto; }

@media (prefers-reduced-motion: reduce) {
    .practice-score.on-fire, .fire-flames i, .achievement-toast { animation: none; }
}

/* ---- Save a grade for offline use ---- */
.offline-save {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin: 0.6rem 0;
    font-size: 0.9rem;
    color: #555;
}

/* ---- Build-up round for learners who are battling ---- */
.build-up-note {
    margin: 0.4rem 0 0.6rem;
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    background: var(--grade-tint);
    color: var(--ink);
    font-size: 0.95rem;
}

/* ---- Play ---- */
.play-grades { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.5rem 0 1rem; }
.play-modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0.75rem; }
.play-card {
    display: flex; flex-direction: column; align-items: flex-start; gap: 0.25rem;
    padding: 0.9rem 1rem; border: 2px solid var(--grade); border-radius: 12px;
    background: var(--grade-tint); color: var(--ink); text-align: left;
}
.play-card:disabled { opacity: 0.6; }
.play-card-title { font-size: 1.15rem; font-weight: 600; }
.play-card-detail { font-size: 0.9rem; color: #555; }
.play-note { font-size: 0.9rem; color: #555; margin: 0.5rem 0; }
.play-clock { font-weight: 700; }
.play-clock-low { color: #c62828; }
.play-lives { letter-spacing: 0.15rem; }
.results-record { font-size: 1.2rem; font-weight: 700; }

.leaderboard-heading { margin-top: 1.5rem; }
.leaderboard { margin: 0.75rem 0 1.25rem; padding: 0.75rem 1rem; border-radius: 12px; background: #fffdf7; border: 1px solid #e4e0d4; }
.leaderboard h3 { font-size: 1.05rem; margin: 0 0 0.5rem; }
.leaderboard-rows { list-style: none; margin: 0; padding: 0; }
.leaderboard-rows li { display: flex; gap: 0.75rem; align-items: center; padding: 0.3rem 0; border-bottom: 1px dashed #e4e0d4; }
.leaderboard-rank { width: 2.2rem; text-align: center; font-weight: 600; }
.leaderboard-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leaderboard-points { font-weight: 700; }
.leaderboard-me { background: var(--grade-tint); border-radius: 6px; }
.leaderboard-mine { margin-top: 0.4rem; border-top: 2px solid var(--grade); }
.leaderboard-big { border: 2px solid var(--grade); padding: 1rem 1.25rem; }
.leaderboard-big h3 { font-size: 1.4rem; }
.leaderboard-big .leaderboard-rows li { padding: 0.5rem 0; font-size: 1.1rem; }


/* ---- Young learners (Grades 1-3): bigger, calmer, no pressure ---- */
.grade-1, .grade-2, .grade-3 { font-size: 1.12rem; }
.grade-1 .btn, .grade-2 .btn, .grade-3 .btn { padding: 0.7rem 1.2rem; font-size: 1.1rem; }
.grade-1 .question-prompt, .grade-2 .question-prompt, .grade-3 .question-prompt { font-size: 1.35rem; line-height: 1.5; }
.grade-1 .fire-flames, .grade-2 .fire-flames, .grade-3 .fire-flames,
.grade-1 .fire-count, .grade-2 .fire-count, .grade-3 .fire-count { display: none; }
.young-stars { font-size: 2rem; letter-spacing: 0.2rem; }

/* ---- Put in order / number line / picture options ---- */
.order-label { margin: 0.4rem 0; color: #555; }
.order-chosen, .order-pool { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.6rem 0; min-height: 3rem; }
.order-chosen { padding: 0.5rem; border: 2px dashed var(--grade); background: var(--grade-tint); }
.order-item { min-width: 3.2rem; padding: 0.6rem 0.9rem; font-size: 1.2rem; border: 2px solid var(--ink); background: var(--card); }
.order-item.chosen { border-color: var(--grade); }
.order-slot { min-width: 3.2rem; padding: 0.6rem 0.9rem; text-align: center; color: #aaa; border: 2px dotted #ccc; }
.order-answer { font-weight: 600; }
.numberline-svg { width: 100%; max-width: 560px; display: block; touch-action: manipulation; }
.numberline-zone { cursor: pointer; }
.numberline-zone:hover { fill: rgba(0, 0, 0, 0.04); }
.eq-picture svg { max-width: 150px; max-height: 120px; width: auto; height: auto; display: block; }
