:root {
    --paper: #F0F1E9;
    --paper-card: #FBFBF6;
    --ink: #1E2A22;
    --pine: #2F5D4E;
    --pine-dark: #234438;
    --mustard: #E3A73C;
    --mustard-dark: #A8792A;
    --line: #D3D6C6;
    --muted: #5B6459;
}

* { box-sizing: border-box; }

body {
    font-family: 'Work Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    margin: 0;
    color: var(--ink);
    background: var(--paper);
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    /* Safety net: a long unbroken token (pasted URL, code, etc.) anywhere on
       the site can otherwise force the whole page into horizontal scroll on
       a narrow phone screen. Only kicks in when a word truly has nowhere
       else to break — normal text wrapping is unaffected. */
    overflow-wrap: break-word;
}
.site-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    padding: 16px 32px;
    background: var(--paper-card);
    border-bottom: 1px solid var(--line);
}

.site-header .logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: 'Fraunces', serif;
    font-weight: 600;
    font-size: 1.25rem;
    color: var(--ink);
    text-decoration: none;
}

.logo-mark {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--paper);
    box-shadow: inset 0 0 0 2px var(--pine);
}

.site-nav {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

/* Hamburger button — hidden on desktop, shown below the breakpoint */
.nav-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 34px;
    height: 34px;
    background: none;
    border: 1px solid var(--line);
    border-radius: 6px;
    cursor: pointer;
    padding: 0;
}

.nav-toggle span {
    display: block;
    width: 18px;
    height: 2px;
    margin: 0 auto;
    background: var(--ink);
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.nav-toggle.is-active span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-toggle.is-active span:nth-child(2) { opacity: 0; }
.nav-toggle.is-active span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

@media (max-width: 640px) {
    .site-header { padding: 14px 20px; }

    .nav-toggle { display: flex; }

    .site-nav {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        flex-direction: column;
        align-items: stretch;
        gap: 4px;
        background: var(--paper-card);
        border-bottom: 1px solid var(--line);
        padding: 12px 20px 16px;
        box-shadow: 0 8px 16px -12px rgba(30, 42, 34, 0.25);
        z-index: 20;
    }

    .site-nav.is-open { display: flex; }

    .nav-tab, .nav-link {
        margin-left: 0;
        padding: 10px 4px;
        border-bottom: 1px solid var(--line);
        border-radius: 0;
    }

    .nav-tab:last-of-type, .nav-link:last-child { border-bottom: none; }
}

.nav-tab {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.78rem;
    letter-spacing: 0.02em;
    text-decoration: none;
    padding: 6px 12px;
    border-radius: 4px;
    border: 1px solid transparent;
    transition: border-color 0.15s, background 0.15s;
}

.nav-tab--notes { color: var(--pine-dark); }
.nav-tab--notes:hover { border-color: var(--pine); background: rgba(47, 93, 78, 0.08); }

.nav-tab--blog { color: var(--mustard-dark); }
.nav-tab--blog:hover { border-color: var(--mustard); background: rgba(227, 167, 60, 0.14); }

.nav-tab--quiz { color: #9C3D8B; }
.nav-tab--quiz:hover { border-color: #9C3D8B; background: rgba(156, 61, 139, 0.1); }

.nav-link {
    font-family: 'Work Sans', sans-serif;
    font-size: 0.88rem;
    text-decoration: none;
    color: var(--muted);
    margin-left: 6px;
}

.nav-link:hover { color: var(--ink); }

/* Logout is a POST form (CSRF-protected) but should look identical to the
   other plain <a class="nav-link"> items sitting next to it */
.nav-logout-form {
    display: contents;
}

button.nav-link {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
}

.site-main {
    max-width: 900px;
    margin: 0 auto;
    padding: 40px 20px;
    min-height: 60vh;
    flex: 1;
    width: 100%;
}

.site-main--full {
    max-width: none;
    margin: 0;
    padding: 0;
    flex: 1;
}

.site-main--wide {
    max-width: 1400px;
    width: 80%;
    margin: 0 auto;
    padding: 40px 20px;
    flex: 1;
}

.site-footer {
    position: relative;
    text-align: center;
    padding: 32px 24px 26px;
    background: var(--pine-dark);
    color: #DDE6DF;
    font-family: 'Work Sans', sans-serif;
    font-size: 0.85rem;
    margin-top: 40px;
}
.footer-links {
    margin-bottom: 8px !important;
}

.footer-links a {
    color: #DDE6DF;
    text-decoration: none;
    font-size: 0.82rem;
    margin: 0 8px;
}

.footer-links a:hover {
    text-decoration: underline;
}

.site-footer p { margin: 0; }
.site-footer .footer-meta {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.72rem;
    color: rgba(221, 230, 223, 0.6);
    margin-top: 6px;
}

.footer-holes {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 14px;
}

.footer-holes::before,
.footer-holes::after {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--paper);
    opacity: 0.9;
}

.post-list { display: flex; flex-direction: column; gap: 24px; }

.post-card {
    padding: 20px;
    background: #fff;
    border: 1px solid #eee;
    border-radius: 8px;
}

.post-card h2, .post-card h3 { margin: 8px 0 4px; }
.post-card h2 a, .post-card h3 a { text-decoration: none; color: #111; }
.post-card time { color: #999; font-size: 0.85rem; }

.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-note { background: #e0f2fe; color: #0369a1; }
.badge-blog { background: #dcfce7; color: #15803d; }
.badge-solution { background: #fef3c7; color: #b45309; }

.post-full h1 { margin-top: 8px; }
.post-content { margin-top: 24px; font-size: 1.05rem; }
.post-content img { max-width: 100%; border-radius: 6px; }

.admin-form { display: flex; flex-direction: column; gap: 16px; max-width: 100%; }
.admin-form label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 0.9rem; }
.admin-form input, .admin-form select, .admin-form textarea {
    padding: 10px; font-size: 1rem; border: 1px solid #ccc; border-radius: 6px; font-family: inherit;
}
.admin-form button {
    padding: 12px; background: #111; color: #fff; border: none; border-radius: 6px;
    font-size: 1rem; cursor: pointer; width: fit-content;
}
.admin-form button:hover { background: #333; }

.form-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

.button-secondary {
    padding: 12px 18px;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--muted);
    text-decoration: none;
    font-family: 'Work Sans', sans-serif;
    font-size: 1rem;
}

.button-secondary:hover {
    border-color: var(--muted);
    color: var(--ink);
}

#semester-subject-fields { display: flex; flex-direction: column; gap: 16px; }

.admin-table { width: 100%; border-collapse: collapse; margin-top: 16px; }
.admin-table th, .admin-table td { text-align: left; padding: 10px; border-bottom: 1px solid #eee; }

.link-button {
    background: none; border: none; padding: 0; margin-left: 10px;
    color: #dc2626; text-decoration: underline; cursor: pointer; font-size: inherit; font-family: inherit;
}

.button {
    display: inline-block; padding: 10px 16px; background: #111; color: #fff;
    text-decoration: none; border-radius: 6px; font-size: 0.9rem;
    border: none; cursor: pointer; font-family: inherit;
}

.home-links { display: flex; gap: 16px; margin-top: 24px; }
.success { color: #15803d; font-weight: 600; }
.error { color: #dc2626; font-weight: 600; }

.breadcrumb { font-size: 0.85rem; color: #888; margin-bottom: 16px; }
.breadcrumb a { color: #666; text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }


.subject-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 20px;
    margin-top: 24px;
}

.subject-card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
    padding: 24px 22px 20px;
    background: var(--paper-card);
    border: 1px solid var(--line);
    border-radius: 10px;
    text-decoration: none;
    color: var(--ink);
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.subject-card:hover {
    transform: translateY(-4px);
    border-color: var(--pine);
    box-shadow: 0 14px 28px -16px rgba(30, 42, 34, 0.35);
}

.subject-card-title {
    font-family: 'Fraunces', serif;
    font-weight: 600;
    font-size: 1.15rem;
    margin-bottom: 14px;
    line-height: 1.3;
}

.subject-card-breakdown {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 18px;
}

.mini-badge {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.7rem;
    padding: 3px 9px;
    border-radius: 10px;
    white-space: nowrap;
}

.mini-badge-note { background: #E0F2FE; color: #0369A1; }
.mini-badge-solution { background: #FEF3C7; color: #B45309; }
.mini-badge-question { background: #F3E1EE; color: #9C3D8B; }

.subject-card-browse {
    margin-top: auto;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.78rem;
    color: var(--pine);
    border: 1px solid var(--line);
    padding: 6px 16px;
    border-radius: 20px;
    transition: background 0.15s, border-color 0.15s;
}

.subject-card:hover .subject-card-browse {
    background: var(--pine);
    border-color: var(--pine);
    color: #fff;
}

.semester-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 20px;
    margin-top: 24px;
}

.semester-card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 32px 20px 24px;
    background: var(--paper-card);
    border: 1px solid var(--line);
    border-radius: 10px;
    text-decoration: none;
    color: var(--ink);
    overflow: hidden;
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.semester-card::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 4px;
    background: var(--pine);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.25s ease;
}

.semester-card:hover {
    transform: translateY(-4px);
    border-color: var(--pine);
    box-shadow: 0 14px 28px -16px rgba(30, 42, 34, 0.35);
}

.semester-card:hover::before {
    transform: scaleX(1);
}

.semester-card-num {
    font-family: 'Fraunces', serif;
    font-weight: 700;
    font-size: 2.4rem;
    color: var(--pine);
    line-height: 1;
    margin-bottom: 10px;
}

.semester-card-title {
    font-family: 'Work Sans', sans-serif;
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 4px;
}

.semester-card .post-count {
    margin-top: 0;
    margin-bottom: 18px;
}

.semester-card-browse {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.78rem;
    color: var(--pine);
    border: 1px solid var(--line);
    padding: 6px 16px;
    border-radius: 20px;
    transition: background 0.15s, border-color 0.15s;
}

.semester-card:hover .semester-card-browse {
    background: var(--pine);
    border-color: var(--pine);
    color: #fff;
}   

.post-count {
    display: block;
    font-size: 0.8rem;
    font-weight: 400;
    color: #888;
    margin-top: 4px;
}

.subject-meta { color: #888; margin-top: -8px; }
.empty-state { color: #999; font-style: italic; }

.tab-toggle {
    display: flex;
    gap: 8px;
    border-bottom: 1px solid var(--line);
    margin: 24px 0 20px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
}

.tab-btn {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.85rem;
    background: none;
    border: none;
    padding: 10px 4px;
    margin-bottom: -1px;
    border-bottom: 2px solid transparent;
    color: var(--muted);
    cursor: pointer;
    flex-shrink: 0;
    white-space: nowrap;

}

.tab-btn.is-active {
    color: var(--pine-dark);
    border-bottom-color: var(--pine);
    font-weight: 600;
}

.tab-count {
    display: inline-block;
    background: var(--line);
    color: var(--ink);
    font-size: 0.72rem;
    padding: 1px 7px;
    border-radius: 10px;
    margin-left: 4px;
}

.tab-btn.is-active .tab-count {
    background: var(--pine);
    color: #fff;
}


.post-layout {
    display: flex;
    gap: 48px;
    align-items: flex-start;
    max-width: 1400px;
    margin: 0 auto;
}

.post-full { flex: 1; min-width: 0; }

.toc {
    width: 220px;
    flex-shrink: 0;
    position: sticky;
    top: 24px;
    padding: 16px;
    border-left: 2px solid var(--line);
}

.toc-label {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    margin: 0 0 12px;
}

.toc nav { display: flex; flex-direction: column; gap: 8px; }

.toc nav a {
    font-size: 0.88rem;
    color: var(--muted);
    text-decoration: none;
    line-height: 1.4;
}

.toc nav a:hover { color: var(--pine); }

html { scroll-behavior: smooth; }

@media (max-width: 900px) {
    .post-layout { flex-direction: column; }
    .toc {
        position: static;
        width: 100%;
        border-left: none;
        border-top: 1px solid var(--line);
        order: -1;
    }
}

.ql-snow .ql-picker.ql-size .ql-picker-label::before,
.ql-snow .ql-picker.ql-size .ql-picker-item::before {
    content: attr(data-value) !important;
}

.badge-question { background: #F3E1EE; color: #9C3D8B; }


/*dashboard filter*/
.filter-bar {
    display: flex;
    gap: 10px;
    align-items: center;
    margin: 16px 0 20px;
    flex-wrap: wrap;
}

.filter-bar select {
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    font-family: 'Work Sans', sans-serif;
    /* iOS Safari auto-zooms the page when a tapped form field is under
       16px — 1rem here (not the old 0.9rem) avoids that on the dashboard. */
    font-size: 1rem;
    background: var(--paper-card);
}

/*dashboard search bar*/

.filter-search {
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    font-family: 'Work Sans', sans-serif;
    font-size: 1rem;
    background: var(--paper-card);
    min-width: 200px;
}

/*make quill toolbar sticky*/

.ql-toolbar.ql-snow {
    position: sticky;
    top: 0;
    z-index: 10;
    background: #fff;
}

/*slug*/
.field-hint {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.75rem;
    color: var(--muted);
    font-weight: 400;
}

/*related posts*/

.related-posts {
    margin-top: 56px;
    padding-top: 32px;
    border-top: 1px solid var(--line);
}

.related-posts-label {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    margin-bottom: 18px;
}

.related-posts-viewall {
    display: inline-block;
    margin-top: 20px;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.85rem;
    color: var(--pine);
    text-decoration: none;
}

.related-posts-viewall:hover {
    text-decoration: underline;
}


.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-top: 16px;
}
.table-scroll .admin-table { margin-top: 0; min-width: 640px; }

@media (max-width: 640px) {
    .post-full h1 {
        font-size: 1.5rem;
        line-height: 1.3;
    }

    .post-full .badge {
        display: inline-block;
        margin-bottom: 8px;
    }

    .post-full time {
        display: block;
        margin-top: 4px;
    }

    .subject-meta {
        font-size: 0.85rem;
    }

    .breadcrumb {
        font-size: 0.78rem;
        line-height: 1.6;
        word-break: break-word;
    }

    .post-content {
        font-size: 1rem;
    }

    .toc {
        padding: 12px 0;
        margin-bottom: 8px;
    }

    .related-posts-label {
        font-size: 0.72rem;
    }
}


.post-content table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    max-width: 100%;
    border-collapse: collapse;
}

.post-content table td,
.post-content table th {
    border: 1px solid var(--line);
    padding: 8px 12px;
    white-space: normal;
}

.post-content table th {
    background: var(--paper-card);
    font-weight: 600;
    text-align: left;
}

.post-content pre {
    overflow-x: auto;
    max-width: 100%;
}

@media (max-width: 640px) {
    .site-main {
        padding: 24px 14px;
    }

    .site-main--wide {
        width: 100%;
        padding: 24px 14px;
    }

    .post-layout {
        gap: 20px;
    }
}

/* ---- Quiz feature ---- */

.quiz-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 28px;
    margin-top: 24px;
}

.quiz-card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
    padding: 44px 36px 32px;
    background: var(--paper-card);
    border: 1px solid var(--line);
    border-radius: 10px;
    text-decoration: none;
    color: var(--ink);
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.quiz-card:hover {
    transform: translateY(-4px);
    border-color: #9C3D8B;
    box-shadow: 0 14px 28px -16px rgba(30, 42, 34, 0.35);
}

.quiz-card-title {
    font-family: 'Fraunces', serif;
    font-weight: 600;
    font-size: 1.15rem;
    margin-bottom: 8px;
    line-height: 1.3;
}

.quiz-card-desc {
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.5;
    margin: 0 0 18px;
}

.quiz-card-meta {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.75rem;
    color: var(--muted);
    margin-bottom: 0;
}

.quiz-card-link {
    display: flex;
    flex-direction: column;
    flex: 1;
    width: 100%;
    text-decoration: none;
    color: inherit;
}

.quiz-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    margin-top: 22px;
}

.quiz-card-start {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.78rem;
    color: #9C3D8B;
    border: 1px solid var(--line);
    padding: 6px 16px;
    border-radius: 20px;
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s;
}

.quiz-card:hover .quiz-card-start {
    background: #9C3D8B;
    border-color: #9C3D8B;
    color: #fff;
}

.quiz-card-leaderboard {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.75rem;
    color: var(--muted);
    text-decoration: none;
}

.quiz-card-leaderboard:hover {
    color: #9C3D8B;
    text-decoration: underline;
}

.quiz-question {
    background: var(--paper-card);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 22px 24px;
    margin-bottom: 20px;
}

.quiz-question-num {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    margin-bottom: 8px;
}

.quiz-question-text {
    font-weight: 600;
    margin: 0 0 16px;
    line-height: 1.5;
}

.quiz-question-text .katex,
.quiz-option .katex,
.math-preview .katex {
    /* Matrices/fractions render as INLINE katex (single $...$), which has no
       built-in wrapping — without this, a wide matrix pushes its flex/block
       parent wider than the viewport and the whole page scrolls sideways
       on narrow screens. display:inline-block + max-width:100% lets the
       formula itself scroll instead of the page. */
    display: inline-block;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    vertical-align: middle;
}

.quiz-option span {
    /* Flex items default to min-width:auto, which ignores the sibling's
       max-width rule above and lets a wide formula overflow anyway —
       min-width:0 lets this shrink to the available row width. */
    min-width: 0;
    flex: 1;
}

.quiz-question-image {
    display: block;
    max-width: 100%;
    max-height: 360px;
    border-radius: 8px;
    margin: 0 0 16px;
}

.quiz-options { display: flex; flex-direction: column; gap: 10px; }

.quiz-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: 6px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.quiz-option:hover { border-color: #9C3D8B; }

.quiz-option input[type="radio"] { accent-color: #9C3D8B; }

.quiz-option-correct {
    border-color: #15803d;
    background: rgba(21, 128, 61, 0.08);
}

.quiz-option-incorrect {
    border-color: #dc2626;
    background: rgba(220, 38, 38, 0.08);
}

.quiz-result-summary {
    background: var(--paper-card);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 28px 24px;
    text-align: center;
    margin-bottom: 32px;
}

.quiz-result-score {
    font-family: 'Fraunces', serif;
    font-weight: 700;
    font-size: 2.6rem;
    color: #9C3D8B;
    line-height: 1;
    margin-bottom: 8px;
}

.quiz-result-label {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.8rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 20px;
}

.quiz-result-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

.quiz-nickname-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 20px;
    max-width: 320px;
}

.quiz-nickname-field input {
    padding: 10px 12px;
    font-size: 1rem;
    font-weight: 400;
    border: 1px solid var(--line);
    border-radius: 6px;
    font-family: inherit;
}

.leaderboard-table th:first-child,
.leaderboard-table td:first-child {
    width: 48px;
    text-align: center;
    font-size: 1.05rem;
}

.table-scroll .leaderboard-table {
    /* .table-scroll .admin-table sets min-width:640px for the wide 6-column
       admin tables — this only has 4 narrow columns and fits a phone screen
       fine on its own, so undo that and let it size naturally instead of
       forcing a horizontal scrollbar that isn't actually needed. */
    min-width: 0;
}

.leaderboard-row-you {
    background: rgba(156, 61, 139, 0.08);
}

.leaderboard-you-tag {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 8px;
    border-radius: 10px;
    background: #9C3D8B;
    color: #fff;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.68rem;
    vertical-align: middle;
}

.math-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    margin-bottom: 12px;
    background: var(--paper-card);
    border: 1px solid var(--line);
    border-radius: 8px;
    position: sticky;
    top: 0;
    z-index: 10;
    box-shadow: 0 2px 6px -2px rgba(30, 42, 34, 0.15);
}

.math-toolbar-label {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.72rem;
    color: var(--muted);
    width: 100%;
    margin-bottom: 2px;
}

.math-btn {
    font-family: 'Work Sans', sans-serif;
    font-size: 0.82rem;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 6px 10px;
    cursor: pointer;
    color: var(--ink);
}

.math-btn:hover {
    border-color: #9C3D8B;
    color: #9C3D8B;
}

.math-select {
    font-family: 'Work Sans', sans-serif;
    font-size: 0.82rem;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 6px 10px;
    cursor: pointer;
    color: var(--ink);
}

.math-select:hover {
    border-color: #9C3D8B;
    color: #9C3D8B;
}

.math-preview {
    min-height: 1.2em;
    padding: 8px 12px;
    margin-bottom: 12px;
    background: #fff;
    border: 1px dashed var(--line);
    border-radius: 6px;
    font-size: 0.92rem;
    color: var(--muted);
}

.math-preview:empty {
    display: none;
}

.math-preview-line {
    padding: 2px 0;
}

.quiz-question-builder {
    background: var(--paper-card);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 16px;
    position: relative;
}

.quiz-question-builder-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.quiz-question-builder-header span {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}

.quiz-image-field {
    margin-bottom: 12px;
}

.quiz-image-preview {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.quiz-image-preview img {
    max-width: 160px;
    max-height: 120px;
    border-radius: 6px;
    border: 1px solid var(--line);
    display: block;
}

.quiz-option-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.quiz-option-row input[type="radio"] { accent-color: #9C3D8B; flex-shrink: 0; }

.quiz-option-row input[type="text"] { flex: 1; }

.quiz-option-row-label {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.8rem;
    color: var(--muted);
    width: 16px;
    flex-shrink: 0;
}

@media (max-width: 640px) {
    .quiz-question { padding: 18px 16px; }
    .quiz-result-score { font-size: 2.1rem; }

    /* iOS Safari auto-zooms on a tapped <select>/<input> under 16px — only
       need this override on phones, so the compact toolbar look stays on desktop. */
    .math-select { font-size: 1rem; }
}

/* ---- Quiz results: Print / Save as PDF ---- */
.scroll-top-btn {
    position: fixed;
    bottom: 20%;
    right: 10%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: var(--pine);
    color: #fff;
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 8px 20px -8px rgba(30, 42, 34, 0.45);
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
    z-index: 40;
}

.scroll-top-btn.is-visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.scroll-top-btn:hover {
    background: var(--pine-dark);
}

@media (max-width: 640px) {
    .scroll-top-btn {
        bottom: 16px;
        right: 16px;
        width: 40px;
        height: 40px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .scroll-top-btn {
        transition: none;
    }
}

@media print {
    .site-header,
    .site-footer,
    .nav-toggle,
    .breadcrumb,
    .no-print {
        display: none !important;
    }

    .site-main, .site-main--wide, .site-main--full {
        max-width: 100%;
        width: 100%;
        padding: 0;
        margin: 0;
    }

    .quiz-question {
        break-inside: avoid;
        page-break-inside: avoid;
    }

    /* Browsers drop background colors by default when printing —
       these are what show which option was correct/incorrect */
    .quiz-option-correct,
    .quiz-option-incorrect,
    .quiz-result-summary {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}