/* ============================================================
   DESIGN TOKENS
   ============================================================ */
:root {
    /* Colors */
    --color-ink:        #5a4530;
    --color-text:       #2c2418;
    --color-text-muted: #6b5a45;
    --color-text-light: #9a8a70;
    --color-blue:       #2a5090;
    --color-red:        #c85050;
    --color-green:      #2e7d32;
    --color-orange:     #b8600c;
    --color-purple:     #7b1fa2;
    --color-border:     #b0a48a;
    --color-border-light: rgba(168, 188, 208, 0.4);
    --color-bg-paper:   #faf5e8;
    --color-bg-warm:    #fdfaf0;
    --color-bg-card:    #fff;

    /* Typography */
    --font-hand: "Patrick Hand", cursive;

    /* Spacing */
    --space-xs:  0.25rem;
    --space-sm:  0.5rem;
    --space-md:  1rem;
    --space-lg:  1.5rem;
    --space-xl:  2rem;
    --space-2xl: 2.5rem;

    /* Borders & Shadows */
    --radius-sm: 2px;
    --radius-md: 4px;
    --shadow-sm: 1px 2px 4px rgba(0,0,0,0.05);
    --shadow-md: 2px 4px 10px rgba(0,0,0,0.08);
    --shadow-lg: 3px 4px 16px rgba(50,30,10,0.3);

    /* Transitions */
    --transition-fast: 0.15s ease;
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: var(--font-hand);
    color: var(--color-text);
    line-height: 1.55;
    min-height: 100vh;
    padding: 1.5rem;
    background:
        repeating-linear-gradient(
            87deg, transparent, transparent 2px,
            rgba(0,0,0,0.013) 2px, rgba(0,0,0,0.013) 4px
        ),
        linear-gradient(175deg, #c9a878, #b08a54, #c4a46c);
    perspective: 2000px;
}

/* ============================================================
   APP CONTAINER (notebook page)
   ============================================================ */
#app {
    max-width: 860px;
    margin: 0 auto;
    padding: var(--space-2xl) var(--space-2xl) var(--space-xl) 5rem;
    position: relative;
    min-height: auto;
    border-radius: var(--space-xs);
    transform-origin: left center;
    transform-style: preserve-3d;
    background:
        linear-gradient(to right, transparent 2.8rem, var(--color-red)80 2.8rem, var(--color-red)80 calc(2.8rem + 1.5px), transparent calc(2.8rem + 1.5px));
    background-color: var(--color-bg-paper);
    box-shadow: var(--shadow-lg), -1px 0 3px rgba(50,30,10,0.08), 0 0 0 1px rgba(0,0,0,0.04);
}

/* hole punches */
#app::before {
    content: '';
    position: absolute;
    left: 0.7rem;
    top: 5rem;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: #b8935c;
    box-shadow:
        0 0 0 1px rgba(0,0,0,0.12), 0 1px 3px rgba(0,0,0,0.2) inset,
        0 14rem 0 0 #b8935c, 0 14rem 0 1px rgba(0,0,0,0.12),
        0 28rem 0 0 #b8935c, 0 28rem 0 1px rgba(0,0,0,0.12);
}

/* dog-ear corner */
#app::after {
    content: '';
    position: absolute;
    bottom: 0; right: 0;
    width: 30px; height: 30px;
    background: linear-gradient(225deg, #c9a878 50%, #f0eadb 50%);
    border-radius: 0 0 2px 0;
}

/* Page turn animations */
@keyframes pageTurnOut {
    0%   { transform: translateX(0); opacity: 1; }
    100% { transform: translateX(-40px) scale(0.98); opacity: 0; }
}
@keyframes pageTurnIn {
    0%   { transform: translateX(40px) scale(0.98); opacity: 0; }
    100% { transform: translateX(0) scale(1); opacity: 1; }
}
#app.page-exit  { animation: pageTurnOut 0.2s ease-in both; }
#app.page-enter { animation: pageTurnIn 0.25s cubic-bezier(0.22, 0.61, 0.36, 1) both; }

/* ============================================================
   SHARED COMPONENTS
   ============================================================ */

/* --- Links --- */
a { color: var(--color-blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- Section divider --- */
.divider {
    border: none;
    border-top: 2px solid var(--color-ink);
    margin: var(--space-xl) 0;
}

/* --- Details / Summary (collapsible folder tab) --- */
details {
    border: 1px dashed #b8935c;
    border-radius: var(--space-md);
    overflow: hidden;
    background: rgba(255,255,255,0.5);
    transition: box-shadow 0.2s ease;
}
details:hover { box-shadow: 2px 3px 8px rgba(0,0,0,0.06); }

details summary {
    padding: var(--space-sm) var(--space-md);
    cursor: pointer;
    font-family: var(--font-hand);
    font-size: 1.1rem;
    color: var(--color-blue);
    background: rgba(42, 80, 144, 0.05);
    user-select: none;
    outline: none;
    list-style: none;
    transition: background var(--transition-fast);
}
details summary::-webkit-details-marker { display: none; }
details summary:hover { background: rgba(42, 80, 144, 0.1); }

/* --- Badge (small colored label) --- */
.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
    font-size: 0.78rem;
    font-weight: bold;
}
.badge-warning {
    color: #e65100;
    background: #fff3e0;
    border: 1.2px solid #ffe0b2;
}

/* --- Footer text --- */
.footer-text {
    text-align: center;
    font-size: 0.85rem;
    color: var(--color-text-light);
    font-style: italic;
    padding-top: var(--space-md);
    border-top: 1px dashed var(--color-border);
}

/* ============================================================
   INDEX VIEW
   ============================================================ */

.index-title-block {
    text-align: center;
    margin-bottom: var(--space-sm);
}

.index-title {
    font-size: 2.2rem;
    font-weight: 400;
    color: var(--color-blue);
    letter-spacing: 0.02em;
    line-height: 1.25;
    position: relative;
    display: inline-block;
    transition: transform 0.15s ease;
    cursor: pointer;
}
.index-title a {
    color: inherit;
    text-decoration: none;
}
.index-title a:hover {
    text-decoration: none;
}
.index-title:hover {
    transform: rotate(-0.3deg) scale(1.01);
}

.index-subtitle {
    margin-top: 0.6rem;
    font-size: 1.05rem;
    color: var(--color-text-muted);
    font-style: italic;
}
.index-subtitle a {
    color: inherit;
    text-decoration: none;
}
.index-subtitle a:hover {
    text-decoration: underline;
}
.info-link-container {
    margin: 1.5rem 0 0.5rem;
}

/* Gradebook table — pen-drawn notebook grid */
.report-card-container {
    margin: var(--space-xl) 0 var(--space-xl);
    overflow-x: auto;
    padding-bottom: var(--space-md);
}

.report-card {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-hand);
    border: 2px solid var(--color-ink);
    box-shadow: 2px 3px 0 rgba(0,0,0,0.1);
}

.report-card th,
.report-card td {
    padding: 0.8rem 1rem;
    text-align: center;
    border: 1px solid var(--color-border-light);
    position: relative;
}

.report-card .col-margin,
.report-card .cell-margin {
    text-align: left;
    padding-left: 1.2rem;
    border-right: 2px solid var(--color-red)80;
    min-width: 140px;
    background: rgba(200, 189, 165, 0.05);
}
.report-card .cell-margin a { color: var(--color-ink); text-decoration: none; }

.report-card thead th {
    background: rgba(250, 245, 232, 0.8);
    color: var(--color-blue);
    font-size: 1.15rem;
    font-weight: 700;
    border-bottom: 2px solid var(--color-ink);
}

/* hand-drawn underline for model name links */
.report-card thead th a {
    color: inherit;
    text-decoration: none;
    position: relative;
}
.report-card thead th a::after {
    content: '';
    position: absolute;
    bottom: -2px; left: 0;
    width: 100%; height: 1px;
    background: currentColor;
    opacity: 0.4;
    transform: rotate(0.5deg);
}

.row-total { border-top: 2px solid var(--color-ink); }
.row-total td { background: rgba(42, 80, 144, 0.03); }

.cell-acc { font-size: 1.4rem; }
.cell-acc span { display: inline-block; }

.empty-cell { color: var(--color-border); font-style: italic; font-size: 1.1rem; }

.cell-global { font-weight: 700; font-size: 1.55rem; background: rgba(42, 80, 144, 0.04); }

.report-card tbody tr:nth-child(even) { background: rgba(168, 188, 208, 0.04); }

/* Hover effect for clickable index cells (desktop only) */
@media (hover: hover) {
    .report-card tr.nivel-row-clickable td {
        cursor: pointer;
        transition: background 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
    }
    .report-card tr.nivel-row-clickable td:hover {
        background: rgba(232, 201, 122, 0.18);
        box-shadow: inset 0 0 0 1.5px rgba(232, 201, 122, 0.5);
    }
    .report-card tr.nivel-row-clickable td:active {
        transform: scale(1);
        box-shadow: inset 0 0 0 1px rgba(232, 201, 122, 0.3);
    }
}

/* Gradebook helpers */
.td-grade-container { display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.2; }
.teacher-note {
    color: var(--color-red);
    font-family: var(--font-hand);
    font-size: 0.9rem;
    font-weight: normal;
    margin-left: 6px;
    display: inline-block;
    transform: rotate(-3deg);
}
.teacher-note-sub {
    font-size: 0.75rem;
    color: #666;
    display: block;
    transform: rotate(1deg);
    margin-top: 2px;
}

/* Index footer — handwritten dashed line */
.index-footer {
    text-align: center;
    font-size: 0.85rem;
    color: var(--color-text-light);
    font-style: italic;
    padding-top: var(--space-md);
    border-top: 1px dashed var(--color-border);
}

/* Token receipt — looks like a thermal receipt strip taped to the page */
.token-receipt {
    margin: var(--space-xl) auto 0;
    max-width: 420px;
    background: #fffef5;
    border: 1px solid #e0d9c5;
    border-radius: 2px;
    padding: var(--space-md) var(--space-lg) var(--space-md);
    position: relative;
    box-shadow: 1px 2px 6px rgba(0,0,0,0.06);
    transform: rotate(-0.4deg);
    /* jagged bottom edge — torn receipt */
    background-image:
        linear-gradient(to bottom, #fffef5 0%, #fffef5 96%, transparent 96%);
    background-size: 100% 100%;
}
.token-receipt::before {
    content: '';
    position: absolute;
    top: -5px; left: 25%; right: 25%;
    height: 10px;
    background: rgba(220, 220, 180, 0.45);
    backdrop-filter: blur(1px);
    border-radius: 1px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
    transform: rotate(0.5deg);
    pointer-events: none;
}

.token-receipt-title {
    font-family: var(--font-hand);
    font-size: 1.15rem;
    font-weight: 400;
    color: var(--color-text-muted);
    text-align: center;
    margin-bottom: var(--space-sm);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding-bottom: var(--space-xs);
    border-bottom: 1px dashed var(--color-border);
}

.token-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-hand);
    font-size: 0.92rem;
}

.token-table th {
    text-align: center;
    color: var(--color-text-light);
    font-weight: 400;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding-bottom: var(--space-xs);
}

.token-table td {
    text-align: center;
    padding: 0.3rem 0.2rem;
    color: var(--color-text-muted);
}

.token-table .token-total {
    font-weight: 700;
    color: var(--color-text);
}

.token-table tr.token-grand {
    border-top: 1px dashed var(--color-border);
}

.token-table tr.token-grand td {
    padding-top: var(--space-xs);
    color: var(--color-text);
    font-weight: 700;
}

/* ============================================================
   EXAM VIEW
   ============================================================ */

.exam-header {
    margin-bottom: var(--space-sm);
    position: relative;
}
.exam-header > div { display: flex; justify-content: space-between; align-items: center; }

.exam-title-hand {
    font-family: var(--font-hand);
    font-size: 2.1rem;
    font-weight: 400;
    color: var(--color-blue);
    margin: 0.5rem 0 0.2rem;
    line-height: 1.1;
    text-shadow: 1px 1px 0 rgba(0,0,0,0.05);
}

.exam-meta {
    color: var(--color-text-muted);
    font-size: 0.95rem;
    margin-top: 0.15rem;
    font-style: italic;
}

/* PDF Viewer — folder tab */
.pdf-details {
    margin: var(--space-md) 0 var(--space-xl);
    background: rgba(255, 255, 255, 0.5);
    border: 1px dashed #b8935c;
    border-radius: var(--space-md);
    overflow: hidden;
    transition: box-shadow 0.2s ease;
}
.pdf-details:hover { box-shadow: 2px 3px 10px rgba(0,0,0,0.08); }
.pdf-details summary { font-size: 1.1rem; }
.pdf-container { line-height: 0; background: #525659; }
.pdf-container iframe { border: none; display: block; }

/* Questions list */
.questions {
    display: flex;
    flex-direction: column;
    gap: var(--space-xl);
    margin-top: var(--space-xl);
    padding-bottom: var(--space-xl);
}

/* Question card — notebook paper scrap */
.question {
    background: #fff;
    border: 1px solid #d0d7de;
    border-radius: var(--space-xs);
    padding: 2rem 1.5rem 1.5rem;
    box-shadow: 1px 2px 4px rgba(0,0,0,0.05);
    position: relative;
    transition: box-shadow 0.2s;
}
.question:hover {
    box-shadow: 3px 6px 15px rgba(0,0,0,0.1);
}

.question .q-number {
    position: absolute;
    top: -11px; left: 14px;
    background: var(--color-red) !important;
    color: #fff !important;
    border: none;
    box-shadow: 1px 1px 3px rgba(0,0,0,0.2);
    font-weight: bold;
    z-index: 2;
    width: 1.7rem; height: 1.7rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 0.85rem;
    /* ink-stamp irregularity */
    border-radius: 52% 48% 50% 50% / 48% 52% 48% 52%;
}

.q-body { flex: 1; min-width: 0; }

.q-text {
    margin-bottom: 0.8rem;
    font-size: 1.08rem;
    line-height: 1.7;
}

/* Figure sticky note */
.q-figure {
    margin-bottom: 0.75rem;
    margin-left: 1.5rem;
    padding: 0.6rem 0.9rem;
    background: #fff9c4;
    border: 1px solid #fbc02d;
    font-size: 0.9rem;
    color: #5d4037;
    line-height: 1.5;
    transform: rotate(-0.5deg);
    box-shadow: 2px 3px 10px rgba(0,0,0,0.06);
    position: relative;
    border-radius: 2px 20px 2px 15px / 15px 2px 20px 2px;
}
.q-figure::before {
    content: "Nota: Descripción del gráfico";
    display: block;
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.75rem;
    color: #af8600;
    margin-bottom: 4px;
    padding-bottom: 2px;
    border-bottom: 1px solid #fbc02d80;
}

/* Options — cut-out paper labels */
.q-options {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: var(--space-md);
}

.option {
    padding: 0.25rem 0.6rem;
    font-size: 0.98rem;
    border-radius: var(--space-xs);
    border: 1px solid var(--color-border);
    line-height: 1.5;
    color: #3b2e1e;
    background: rgba(255,255,255,0.5);
    transition: box-shadow 0.15s ease;
}
.option:hover {
    box-shadow: 1px 1px 3px rgba(0,0,0,0.06);
}
.option.correct {
    color: #1a7a2e;
    font-weight: 700;
    border-color: #1a7a2e;
    border-width: 1.5px;
    text-decoration: underline;
    text-decoration-color: #1a7a2e;
    text-underline-offset: 3px;
    text-decoration-thickness: 1.5px;
}

/* AI Answers — inline expandable (taped memo strip) */
.ai-answers-inline {
    margin-top: var(--space-md);
    padding-top: var(--space-sm);
    border-top: 1px dashed rgba(0,0,0,0.12);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.ai-answer-expandable {
    border: 1px solid var(--color-border);
    border-radius: var(--space-md);
    background: rgba(255,255,255,0.6);
    overflow: hidden;
    position: relative;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.ai-answer-expandable:hover {
    transform: translateY(-1px) rotate(-0.2deg);
    box-shadow: 1px 2px 6px rgba(0,0,0,0.08);
}
.ai-answer-expandable.correct { border-left: 3px solid var(--color-green); }
.ai-answer-expandable.incorrect { border-left: 3px solid #c62828; }



.ai-answer-expandable summary {
    padding: var(--space-sm) var(--space-md);
    cursor: pointer;
    font-family: var(--font-hand);
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    user-select: none;
    list-style: none;
    background: transparent;
    color: var(--color-text);
}
.ai-answer-expandable summary::-webkit-details-marker { display: none; }
.ai-answer-expandable summary:hover { background: rgba(42, 80, 144, 0.04); }

.ai-toggle-label { font-weight: bold; color: var(--color-ink); flex: 1; }

.ai-toggle-status { font-weight: bold; font-size: 1rem; }
.ai-toggle-status.correct   { color: var(--color-green); }
.ai-toggle-status.incorrect  { color: #c62828; }

.ai-toggle-time { font-size: 0.8rem; color: #888; font-style: italic; }

.ai-answer-body {
    padding: 0.8rem 1rem var(--space-md);
    border-top: 1px solid rgba(0,0,0,0.06);
    background: rgba(255,255,255,0.4);
}

.ai-answer-body .reasoning-text {
    font-size: 0.95rem;
    line-height: 1.6;
    color: #3b2e1e;
    margin-bottom: var(--space-sm);
}

.ai-answer-expandable .ai-footer {
    margin-top: var(--space-sm);
    padding-top: var(--space-sm);
    border-top: 1px dotted rgba(0,0,0,0.1);
    font-size: 0.9rem;
    color: var(--color-text-muted);
}
.ai-answer-expandable .ai-footer strong { color: var(--color-blue); }

/* ============================================================
   INFO VIEW
   ============================================================ */
.info-paper { margin-top: 0; padding-bottom: var(--space-xl); }
.readme-rendered { font-size: 1.15rem; }

.lang-switch {
    background: rgba(42, 80, 144, 0.05);
    padding: 0.2rem 0.6rem;
    border-radius: var(--space-md);
    border: 1px dashed rgba(42, 80, 144, 0.3);
    font-weight: bold;
    transition: all 0.2s ease;
    cursor: pointer;
    position: relative;
}
.lang-switch::before {
    content: '';
    position: absolute;
    inset: 0;
    border: 1px solid transparent;
    border-radius: inherit;
    background: linear-gradient(135deg, rgba(42,80,144,0.08) 0%, transparent 50%);
    pointer-events: none;
}
.lang-switch:hover {
    background: rgba(42, 80, 144, 0.1);
    transform: scale(1.05) rotate(-1deg);
    text-decoration: none !important;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
    margin: 1.5rem 0 var(--space-md);
    color: var(--color-red);
    border-bottom: 1.5px solid #a8bcd060;
}
.markdown-body h1:first-child,
.markdown-body h2:first-child,
.markdown-body h3:first-child {
    margin-top: 0;
}
.markdown-body p { margin-bottom: var(--space-md); }
.markdown-body ul,
.markdown-body ol { margin-bottom: var(--space-md); padding-left: 2rem; }
.markdown-body blockquote {
    border-left: 4px solid var(--color-red);
    padding-left: var(--space-md);
    margin: var(--space-md) 0;
    font-style: italic;
    color: #555;
}
.markdown-body code {
    background: var(--color-bg-warm);
    padding: 2px 4px;
    border-radius: 3px;
    font-family: monospace;
}
.markdown-body pre {
    background: var(--color-bg-warm);
    padding: var(--space-md);
    border-radius: var(--space-md);
    overflow-x: auto;
    margin-bottom: var(--space-md);
    border: 1px solid #a8bcd060;
}
.markdown-body hr { border: none; border-top: 2px dashed #a8bcd060; margin: var(--space-xl) 0; }
.markdown-body a { color: var(--color-red); text-decoration: underline; }

/* ============================================================
   KaTeX
   ============================================================ */
.katex-html { user-select: none; }

/* Next exam link — matches "back-link" style */
.btn-next-link {
    margin-left: var(--space-md);
}

/* ============================================================
   RESPONSIVE — Tablet (<=768px)
   ============================================================ */
@media (max-width: 768px) {
    body { padding: 0.75rem; }

    #app {
        padding: var(--space-lg) 1rem var(--space-xl) 3rem;
        background:
            linear-gradient(to right, transparent 2rem, var(--color-red)80 2rem, var(--color-red)80 calc(2rem + 1.5px), transparent calc(2rem + 1.5px));
        background-color: var(--color-bg-paper);
    }
    #app::before { left: 0.45rem; width: 11px; height: 11px; }

    .exam-header { margin-bottom: var(--space-md); }
    .info-link-container { margin-bottom: var(--space-lg); }
    .index-title { font-size: 1.8rem; }
    .exam-title-hand { font-size: 1.8rem; }

    /* Gradebook mobile: card layout */
    .report-card, .report-card thead, .report-card tbody, .report-card tr, .report-card td { display: block; }
    .report-card tbody { display: flex; flex-direction: column; }
    .report-card { border: none; box-shadow: none; width: 100%; border-collapse: separate; }
    .report-card thead { display: none; }
    .report-card tr {
        margin-bottom: var(--space-xl);
        border: 1.5px solid var(--color-ink);
        background: #fefcf4;
        box-shadow: 1px 2px 6px rgba(0,0,0,0.06);
        transform: none;
        position: relative;
        width: 100%;
        box-sizing: border-box;
        cursor: pointer;
        transition: transform 0.15s ease, box-shadow 0.15s ease;
    }
    .report-card tr.row-total {
        order: -1; /* Move Nota Final to first position on mobile */
        border-color: var(--color-blue) !important;
        background: #f4f8ff;
    }
    .report-card tr:active {
        transform: scale(0.98);
        box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    }
    /* tape strip on mobile card */
    .report-card tr::before {
        content: '';
        position: absolute;
        top: -5px; left: 30%; right: 30%;
        height: 10px;
        background: rgba(232, 201, 122, 0.5);
        border-radius: 1px;
        box-shadow: 0 1px 2px rgba(0,0,0,0.05);
        transform: none;
        pointer-events: none;
    }
    .report-card td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.7rem 1rem;
        border: none;
        word-break: break-word; /* Handle long names */
        text-align: right;
    }
    .report-card .cell-margin {
        background: rgba(42, 80, 144, 0.08);
        border-bottom: 2px solid var(--color-ink);
        color: var(--color-blue);
        font-size: 1.25rem;
        justify-content: center;
        border-right: none;
    }
    .nivel-label {
        position: relative;
        display: flex;
        align-items: center;
    }
    .nivel-label::after {
        content: '\203A';
        font-size: 1.5rem;
        color: var(--color-blue);
        margin-left: 0.4rem;
        opacity: 0.5;
        font-weight: 700;
    }
    .report-card td::before {
        content: attr(data-label);
        font-weight: 400;
        font-size: 0.9rem;
        color: var(--color-text-light);
        text-align: left;
        white-space: pre-wrap;
        line-height: 1.1;
        margin-right: 10px;
    }
    .report-card-container {
        margin: var(--space-md) 0 var(--space-sm) !important;
        padding-bottom: 0 !important;
    }
    .token-receipt { margin-top: var(--space-sm) !important; }
    .report-card .cell-global {
        background: rgba(42, 80, 144, 0.04);
        font-size: 1.5rem;
        border-bottom: none;
        padding: var(--space-md) 1.2rem;
    }

    .report-card td { min-height: 4.2rem; border-bottom: 1px dashed rgba(0,0,0,0.15) !important; }
    .report-card .cell-margin {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        text-align: center !important;
    }
    .report-card td::before { font-size: 0.95rem !important; color: #887a64 !important; }
    .report-card .td-grade-container { align-items: flex-end !important; text-align: right !important; }
    .teacher-note { font-size: 0.75rem !important; }
    .teacher-note-sub { font-size: 0.65rem !important; }
}

/* ============================================================
   RESPONSIVE — Phone (<=520px)
   ============================================================ */
@media (max-width: 520px) {
    body { padding: 0.35rem; }

    #app {
        padding: var(--space-md) 1rem var(--space-xl) 1rem;
        border-radius: 0;
        background-color: var(--color-bg-paper);
    }
    #app::before { display: none; }
    #app::after { width: 20px; height: 20px; }
    
    @keyframes mobileFadeOut {
        0%   { opacity: 1; transform: translateY(0); }
        100% { opacity: 0; transform: translateY(10px); }
    }
    @keyframes mobileFadeIn {
        0%   { opacity: 0; transform: translateY(-10px); }
        100% { opacity: 1; transform: translateY(0); }
    }
    #app.page-exit  { animation: mobileFadeOut 0.2s ease-in both; }
    #app.page-enter { animation: mobileFadeIn 0.25s ease-out both; }

    .index-title { font-size: 1.55rem; }
    .index-subtitle { font-size: 0.92rem; }
    .exam-title-hand { font-size: 1.5rem; }
    .exam-meta { font-size: 0.88rem; }

    .question { padding: 1.8rem 1rem 1.2rem; }
    .question .q-number { width: 1.5rem; height: 1.5rem; font-size: 0.8rem; }
    .q-text { font-size: 1rem; line-height: 1.6; }
    .q-figure { font-size: 0.84rem; padding: 0.35rem 0.55rem; margin-left: 0.8rem; }
    .q-options { flex-direction: column; gap: 0.3rem; }
    .option { font-size: 0.9rem; padding: 0.3rem 0.5rem; }

    .ai-answer-expandable summary { font-size: 0.88rem; padding: 0.4rem 0.6rem; }
    .ai-answer-body { padding: 0.6rem 0.7rem 0.8rem; }

    .readme-rendered { font-size: 1.05rem; }
    .report-card td::before { font-size: 0.85rem !important; }
    .token-receipt { max-width: 100%; transform: none; }
}

/* ============================================================
   RESPONSIVE — Small phone (<=360px)
   ============================================================ */
@media (max-width: 360px) {
    #app { padding: var(--space-md) 0.8rem var(--space-xl) 0.8rem; }
    .index-title { font-size: 1.35rem; }
    .q-text { font-size: 0.92rem; }
}

/* ============================================================
   DESKTOP — Next exam button matches PDF summary style
   ============================================================ */
@media (min-width: 769px) {
    .btn-next-exam {
        display: inline-block;
        width: auto;
        height: auto;
        padding: var(--space-sm) var(--space-md);
        margin-left: var(--space-md);
        font-size: 1.1rem;
        font-weight: 400;
        color: var(--color-blue);
        background: rgba(42, 80, 144, 0.05);
        border: 1px dashed #b8935c;
        border-radius: var(--space-md);
        line-height: normal;
    }
    .btn-next-exam:hover {
        background: rgba(42, 80, 144, 0.1);
        box-shadow: 2px 3px 10px rgba(0, 0, 0, 0.08);
        transform: none;
    }
    .btn-next-text { display: inline; }
    .btn-next-arrow { display: none; }
}
