/* ═══════════════════════════════════════════════════════════════════
   PHYS 172 Exam Prep: design system
   ═══════════════════════════════════════════════════════════════════ */
:root {
    --white: #ffffff;
    --grey-25: #fafafa;
    --grey-50: #f5f5f7;
    --grey-100: #e8e8ed;
    --grey-200: #d2d2d7;
    --grey-300: #b8b8bd;
    --grey-400: #86868b;
    --grey-600: #6e6e73;
    --grey-800: #1d1d1f;
    --black: #000000;

    --accent: #0071e3;
    --accent-hover: #0077ed;
    --accent-soft: rgba(0, 113, 227, 0.10);   /* focus rings only, never a surface */
    --success: #1a7f37;
    --warning: #b25e09;
    --danger: #d70015;
    --gold: #b8730a;

    /* Surfaces are solid, never alpha over content: alpha tints read as washed-out
       "glass" and shift with whatever sits behind them. Color carries meaning through
       icons and small marks; text stays near-black for legibility. */
    --green-tint: #f0f8f2;
    --green-line: #d3e7d9;
    --red-tint:   #fdf3f2;
    --red-line:   #f2dbd9;
    --blue-tint:  #f0f6fd;
    --blue-line:  #d9e6f7;
    --amber-tint: #fdf8ef;
    --amber-line: #efe1c8;

    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
    --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 22px;
    --radius-full: 980px;

    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04), 0 1px 6px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.04);
    --shadow-lg: 0 18px 50px rgba(0,0,0,0.16), 0 2px 8px rgba(0,0,0,0.06);

    --ease: cubic-bezier(0.4, 0, 0.2, 1);
    --t-fast: 150ms var(--ease);
    --t-med: 260ms var(--ease);

    --header-h: 56px;
    --panel-left-w: 400px;
    --panel-right-w: 380px;
    --touch: 36px;
    --safe-b: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
html { -webkit-text-size-adjust: 100%; overflow-anchor: none; }
body {
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.55;
    color: var(--grey-800);
    background: var(--grey-50);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    overscroll-behavior: none;
}
button, input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: not-allowed; }
svg { display: block; }
.hidden { display: none !important; }
strong, b { font-weight: 600; }
code { font-family: var(--mono); font-size: 0.92em; background: var(--grey-100); padding: 1px 5px; border-radius: 5px; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.14); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.28); background-clip: padding-box; }

/* icons in buttons */
button svg, .icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* ── Generic controls ─────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 20px; min-height: 40px;
    font-size: 14px; font-weight: 600; letter-spacing: -0.005em;
    border-radius: var(--radius-full);
    transition: background var(--t-fast), transform var(--t-fast), opacity var(--t-fast), box-shadow var(--t-fast);
    white-space: nowrap;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: var(--white); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { background: var(--grey-200); color: var(--grey-400); }
.btn-secondary { background: var(--grey-100); color: var(--grey-800); }
.btn-secondary:hover { background: var(--grey-200); }
.btn-dark { background: var(--black); color: var(--white); }
.btn-dark:hover { opacity: 0.85; }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 14px; min-height: 32px; font-size: 13px; }
.btn-link { background: none; color: var(--grey-600); font-size: 13px; font-weight: 500; padding: 8px 4px; }
.btn-link:hover { color: var(--black); }
.text-btn { font-size: 13px; font-weight: 500; color: var(--grey-800); padding: 7px 12px; border-radius: var(--radius-sm); border: 1px solid var(--grey-200); background: var(--white); transition: background var(--t-fast), border-color var(--t-fast); min-height: var(--touch); }
.text-btn:hover { background: var(--grey-50); border-color: var(--grey-300); }
.text-btn.subtle { border-color: transparent; background: transparent; color: var(--grey-600); }
.text-btn.subtle:hover { background: var(--grey-100); color: var(--grey-800); }
.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: var(--touch); height: var(--touch); border-radius: 9px;
    color: var(--grey-600); transition: background var(--t-fast), color var(--t-fast);
    flex-shrink: 0;
}
.icon-btn:hover { background: var(--grey-100); color: var(--black); }
.icon-btn:disabled { opacity: 0.4; }
.icon-btn.active { background: var(--grey-800); color: var(--white); }

.pill-btn {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 0 18px; height: 40px;
    font-size: 14px; font-weight: 600;
    border-radius: var(--radius-full);
    border: 1.5px solid var(--grey-200); background: var(--white); color: var(--grey-800);
    transition: border-color var(--t-fast), background var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast), opacity var(--t-fast);
    white-space: nowrap;
}
.pill-btn:hover { border-color: var(--grey-400); background: var(--grey-25); }
.pill-btn:active { transform: scale(0.98); }
.pill-btn.primary { background: var(--accent); border-color: var(--accent); color: var(--white); box-shadow: 0 6px 18px rgba(0,113,227,0.28); }
.pill-btn.primary:hover { background: var(--accent-hover); }
.pill-btn.primary:disabled { background: var(--grey-100); border-color: var(--grey-100); color: var(--grey-400); box-shadow: none; }
.pill-btn:disabled { border-color: var(--grey-100); color: var(--grey-400); background: var(--grey-50); }
.pill-btn svg { width: 18px; height: 18px; }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; min-height: 30px; border-radius: var(--radius-full); border: 1px solid var(--grey-200); background: var(--white); font-size: 12.5px; font-weight: 500; color: var(--grey-800); transition: background var(--t-fast), border-color var(--t-fast); white-space: nowrap; }
.chip:hover { background: var(--grey-50); border-color: var(--grey-300); }
.chip:disabled { opacity: 0.5; }

.segmented { display: inline-flex; padding: 3px; background: var(--grey-100); border-radius: 10px; gap: 2px; }
.seg-btn { display: inline-flex; align-items: center; gap: 7px; padding: 0 14px; height: 32px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--grey-600); transition: background var(--t-fast), color var(--t-fast), box-shadow var(--t-fast); }
.seg-btn svg { width: 15px; height: 15px; }
.seg-btn.active { background: var(--white); color: var(--black); box-shadow: var(--shadow-sm); }
.seg-btn:not(.active):hover { color: var(--grey-800); }

input[type="text"], textarea, select {
    width: 100%; padding: 11px 14px;
    border: 1.5px solid var(--grey-200); border-radius: var(--radius-md);
    background: var(--white); outline: none; font-size: 15px; line-height: 1.4;
    transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
input[type="text"]:focus, textarea:focus, select:focus { border-color: var(--grey-800); }
textarea { resize: vertical; }
select { appearance: none; -webkit-appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236e6e73' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; background-size: 16px; padding-right: 36px; }
.field-error { min-height: 18px; font-size: 12.5px; color: var(--danger); font-weight: 500; margin: 6px 0 4px; }

.spinner { width: 18px; height: 18px; border: 2px solid var(--grey-200); border-top-color: var(--grey-800); border-radius: 50%; animation: spin 0.8s linear infinite; display: inline-block; flex-shrink: 0; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes pop { 0% { transform: scale(0.96); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }

/* ── KaTeX + markdown inside content areas ────────────────────────── */
.katex { font-size: 1.05em; }
.katex-display { margin: 10px 0; overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.md p { margin: 0 0 10px; }
.md p:last-child { margin-bottom: 0; }
.md ul, .md ol { padding-left: 20px; margin: 0 0 10px; }
.md li { margin-bottom: 4px; }
.md h1, .md h2, .md h3, .md h4 { font-size: 14px; font-weight: 700; margin: 12px 0 6px; letter-spacing: -0.01em; }
.md h1:first-child, .md h2:first-child, .md h3:first-child { margin-top: 0; }
.md blockquote { border-left: 3px solid var(--grey-200); padding-left: 12px; color: var(--grey-600); margin: 8px 0; }
.md code { font-size: 0.9em; }
.md pre { background: var(--grey-50); border-radius: var(--radius-sm); padding: 10px 12px; overflow-x: auto; margin: 8px 0; }
.md pre code { background: none; padding: 0; }
.md table { border-collapse: collapse; margin: 8px 0; font-size: 13.5px; }
.md th, .md td { border: 1px solid var(--grey-200); padding: 5px 9px; }

/* ═══════════════════════════════════════════════════════════════════
   Start screen
   ═══════════════════════════════════════════════════════════════════ */
/* Centred content on a plain ground, not a heavy card floating on grey. The container is
   a hairline and a whisper of shadow; the type and the spacing do the work. */
.screen { position: fixed; inset: 0; z-index: 800; display: flex; align-items: center; justify-content: center; padding: 24px; background: var(--white); overflow-y: auto; }
.start-card { width: 100%; max-width: 396px; background: var(--white); border: 1px solid var(--grey-100); border-radius: 20px; box-shadow: 0 1px 2px rgba(0,0,0,0.03), 0 8px 28px rgba(0,0,0,0.05); padding: 34px 32px 28px; animation: pop 320ms var(--ease); }
.start-card h1 { font-size: 31px; font-weight: 600; letter-spacing: -0.033em; line-height: 1.1; margin-bottom: 10px; }
.start-sub { font-size: 15px; line-height: 1.5; color: var(--grey-600); margin-bottom: 28px; }
.start-loading { display: flex; align-items: center; gap: 10px; color: var(--grey-600); font-size: 13.5px; padding: 12px 0; }
.start-resume { display: flex; flex-direction: column; gap: 4px; }
.resume-line { font-size: 14px; color: var(--grey-600); margin-bottom: 10px; }
.resume-line strong { color: var(--grey-800); font-weight: 600; }
.login-form label { display: block; font-size: 12.5px; font-weight: 600; color: var(--grey-600); margin-bottom: 6px; }
.login-hint { font-size: 12px; color: var(--grey-400); margin-top: 14px; line-height: 1.5; }
.start-error { padding: 14px; border-radius: var(--radius-md); background: var(--red-tint); border: 1px solid var(--red-line); color: var(--danger); font-size: 13.5px; display: flex; flex-direction: column; gap: 10px; }

/* ═══════════════════════════════════════════════════════════════════
   Header
   ═══════════════════════════════════════════════════════════════════ */
.app-header {
    height: var(--header-h); flex-shrink: 0;
    display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
    padding: 0 12px 0 8px; gap: 12px;
    background: rgba(255,255,255,0.92); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 1px solid var(--grey-100);
    position: relative; z-index: 40;
}
.header-left { display: flex; align-items: center; gap: 6px; min-width: 0; }
.header-q { font-size: 15px; font-weight: 600; color: var(--black); letter-spacing: -0.015em; white-space: nowrap; padding-left: 2px; font-variant-numeric: tabular-nums; }
.header-center { display: flex; justify-content: center; }
.mode-pill { display: inline-flex; align-items: center; gap: 8px; padding: 6px 14px; border-radius: var(--radius-full); background: var(--grey-100); font-size: 13px; font-weight: 600; color: var(--grey-800); white-space: nowrap; transition: background var(--t-med), color var(--t-med); }
.mode-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--grey-800); }
.mode-pill.friendly { background: var(--blue-tint); color: var(--accent); }
.mode-pill.friendly .mode-dot { background: var(--accent); }
.mode-pill.locked { background: var(--grey-100); color: var(--grey-600); }
.header-right { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }

/* Sync is ambient: a quiet grey mark that only takes on color when something is wrong. */
.sync-status { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: var(--radius-full); font-size: 12px; font-weight: 500; color: var(--grey-400); background: transparent; border: 1px solid transparent; white-space: nowrap; transition: color var(--t-med), background var(--t-med), border-color var(--t-med); cursor: default; }
.sync-icon { width: 14px; height: 14px; display: inline-flex; }
.sync-icon svg { width: 14px; height: 14px; }
.sync-status.saving { color: var(--grey-600); }
.sync-status.saved { color: var(--grey-400); }
.sync-status.error { color: var(--danger); background: var(--red-tint); border-color: var(--red-line); cursor: pointer; }
.sync-status.offline { color: var(--warning); background: var(--amber-tint); border-color: var(--amber-line); }
.sync-status.quiet .sync-text { display: none; }

.stars-chip { display: inline-flex; align-items: center; gap: 5px; padding: 5px 11px; border-radius: var(--radius-full); background: var(--grey-50); border: 1px solid var(--grey-100); font-size: 13px; font-weight: 600; color: var(--grey-800); white-space: nowrap; font-variant-numeric: tabular-nums; }
.stars-chip .star { color: var(--gold); font-size: 12px; }
.stars-chip.bump { animation: starBump 600ms var(--ease); }
@keyframes starBump { 0% { transform: scale(1); } 30% { transform: scale(1.14); } 100% { transform: scale(1); } }
.stars-mult { font-size: 11px; font-weight: 600; background: var(--amber-tint); border: 1px solid var(--amber-line); color: #8a5000; border-radius: 6px; padding: 0 6px; margin-left: 2px; }

.user-menu { position: relative; }
.user-btn { width: 34px; height: 34px; border-radius: 50%; background: var(--grey-800); color: var(--white); font-size: 12.5px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; letter-spacing: 0.02em; transition: transform var(--t-fast), box-shadow var(--t-fast); }
.user-btn:hover { box-shadow: 0 0 0 3px var(--grey-200); }
.dropdown { position: absolute; top: calc(100% + 8px); right: 0; min-width: 220px; background: var(--white); border: 1px solid var(--grey-100); border-radius: var(--radius-md); box-shadow: var(--shadow-lg); padding: 6px; z-index: 60; animation: fadeUp 160ms var(--ease); }
.dropdown-name { font-size: 12px; color: var(--grey-400); padding: 8px 10px 6px; font-weight: 600; letter-spacing: 0.02em; }
.dropdown-item { display: block; width: 100%; text-align: left; padding: 9px 10px; border-radius: 8px; font-size: 13.5px; font-weight: 500; color: var(--grey-800); }
.dropdown-item:hover { background: var(--grey-50); }

/* ═══════════════════════════════════════════════════════════════════
   Main three-column layout
   ═══════════════════════════════════════════════════════════════════ */
.app-main { flex: 1; display: flex; min-height: 0; position: relative; background: var(--grey-50); }

.side-panel {
    display: flex; flex-direction: column;
    background: var(--white); min-height: 0;
    flex: 0 0 auto; overflow: hidden;
    transition: width var(--t-med), min-width var(--t-med), opacity var(--t-med), transform var(--t-med);
}
.side-panel.left { width: var(--panel-left-w); border-right: 1px solid var(--grey-100); }
.side-panel.right { width: var(--panel-right-w); border-left: 1px solid var(--grey-100); }
.side-panel.collapsed { width: 0 !important; min-width: 0; border-width: 0; opacity: 0; pointer-events: none; }
.side-panel.no-anim { transition: none; }

.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 10px 12px 18px; border-bottom: 1px solid var(--grey-100); flex-shrink: 0; min-height: 54px; }
.panel-head-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.panel-head h2 { font-size: 15px; font-weight: 700; letter-spacing: -0.01em; white-space: nowrap; }
.difficulty-badge { font-size: 11px; font-weight: 600; color: var(--grey-600); background: var(--grey-100); padding: 2px 8px; border-radius: 6px; white-space: nowrap; }
@keyframes pulse { 50% { opacity: 0.4; } }

.panel-body { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 16px 18px 28px; display: flex; flex-direction: column; gap: 14px; -webkit-overflow-scrolling: touch; }
.card-section { animation: fadeUp 220ms var(--ease); }

.resizer { width: 6px; flex: 0 0 6px; cursor: col-resize; background: transparent; position: relative; z-index: 5; transition: background var(--t-fast); margin: 0 -3px; }
.resizer:hover, .resizer.dragging { background: var(--blue-tint); }
.resizer.hidden { display: none; }

/* Attempts */
.attempts-bar { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.attempt-chip { padding: 5px 11px; border-radius: var(--radius-full); border: 1px solid var(--grey-200); background: var(--white); font-size: 12px; font-weight: 600; color: var(--grey-600); display: inline-flex; align-items: center; gap: 6px; transition: all var(--t-fast); }
.attempt-chip:hover { border-color: var(--grey-400); }
.attempt-chip.active { background: var(--grey-800); border-color: var(--grey-800); color: var(--white); }
.attempt-chip .st { font-size: 10px; }

/* Problem text */
.problem-text { font-size: 14.5px; line-height: 1.65; color: var(--grey-800); }
.problem-text p { margin: 0 0 10px; }
.problem-text p:last-child { margin-bottom: 0; }
/* Every reviewer tried to click these. Bordered, tinted cards with a filled circular badge
   are button styling, and no amount of explaining fixes an affordance. The options are a
   list you answer FROM, not a control, so they are drawn as a list: no box, no fill, the
   letter as a plain label. The hanging indent keeps wrapped lines under the text. */
.problem-text ol.mc { list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-direction: column; gap: 3px; }
.problem-text ol.mc li { display: flex; align-items: baseline; gap: 9px; padding: 3px 2px; }
.problem-text .mc-letter { flex: 0 0 auto; min-width: 15px; color: var(--grey-600); font-size: 13.5px; font-weight: 700; font-variant-numeric: tabular-nums; }
.problem-text .mc-letter::after { content: "."; }
.problem-text .mc-body { flex: 1; min-width: 0; }
.problem-text ol.statements { padding-left: 0; list-style: none; margin: 8px 0 12px; display: flex; flex-direction: column; gap: 6px; }
.problem-text ol.statements li { padding: 8px 10px; border-left: 3px solid var(--grey-200); background: var(--grey-25); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; font-size: 13.5px; }
.problem-diagram { margin-top: 14px; border: 1px solid var(--grey-100); border-radius: var(--radius-md); background: var(--white); padding: 12px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.problem-diagram img, .problem-diagram svg { max-width: 100%; height: auto; display: block; }
.problem-diagram .diagram-caption { font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--grey-400); }
.problem-diagram .diagram-note { font-size: 11.5px; line-height: 1.45; color: var(--grey-600); text-align: center; max-width: 42ch; border-top: 1px dashed var(--grey-200); padding-top: 6px; }
.problem-diagram.zoomable { cursor: zoom-in; }

/* Results */
/* Verdict: the icon carries the colour, the type stays near-black and readable. */
.verdict-banner { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: var(--radius-md); background: var(--grey-50); border: 1px solid var(--grey-100); margin-bottom: 12px; }
.verdict-banner h3 { font-size: 15px; font-weight: 600; letter-spacing: -0.015em; margin-bottom: 2px; color: var(--black); }
.verdict-banner p { font-size: 13px; color: var(--grey-600); }
.verdict-icon { width: 26px; height: 26px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: 14px; line-height: 1; flex-shrink: 0; margin-top: 1px; background: var(--grey-300); color: var(--white); }
.verdict-banner.correct { background: var(--green-tint); border-color: var(--green-line); }
.verdict-banner.correct .verdict-icon { background: #34c759; }
.verdict-banner.incorrect { background: var(--red-tint); border-color: var(--red-line); }
.verdict-banner.incorrect .verdict-icon { background: #ff3b30; }
.verdict-banner.check { background: var(--blue-tint); border-color: var(--blue-line); }
.verdict-banner.check .verdict-icon { background: var(--accent); }
.verdict-banner.error { background: var(--amber-tint); border-color: var(--amber-line); }
.verdict-banner.error .verdict-icon { background: #ff9f0a; }
.feedback-body { font-size: 14px; line-height: 1.6; color: var(--grey-800); margin-bottom: 12px; }

/* ── Results in the centre pane ───────────────────────────────────── */
/* The annotated submission needs room: at side-panel width the grader's boxes are
   too small to read, so the panel keeps the verdict and this opens the full view. */
.see-results-btn { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px; margin-bottom: 14px; border-radius: var(--radius-md); border: 1px solid var(--grey-200); background: var(--white); text-align: left; transition: border-color var(--t-fast), background var(--t-fast); }
.see-results-btn:hover { border-color: var(--grey-400); background: var(--grey-25); }
.see-results-btn svg { width: 16px; height: 16px; color: var(--grey-400); flex-shrink: 0; }
.srb-thumb { flex: 0 0 52px; height: 52px; border-radius: 8px; overflow: hidden; background: var(--grey-50); border: 1px solid var(--grey-100); display: flex; align-items: center; justify-content: center; }
.srb-thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top center; }
.srb-body { flex: 1; min-width: 0; }
.srb-title { display: block; font-size: 13.5px; font-weight: 600; color: var(--black); }
.srb-sub { display: block; font-size: 12px; color: var(--grey-600); margin-top: 1px; }

.results-scroll { position: absolute; inset: 0; overflow-y: auto; padding: 22px 20px 40px; -webkit-overflow-scrolling: touch; }
.results-stage { max-width: 900px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }
.results-stage-head h3 { font-size: 16px; font-weight: 600; letter-spacing: -0.015em; }
.results-stage-head p { font-size: 13px; color: var(--grey-600); margin-top: 2px; }
.results-notes { display: flex; flex-direction: column; gap: 6px; }
.result-note { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: var(--radius-md); border: 1px solid var(--grey-100); background: var(--white); text-align: left; width: 100%; transition: border-color var(--t-fast), background var(--t-fast); }
.result-note:hover, .result-note.active { border-color: var(--grey-300); background: var(--grey-25); }
.result-note .rn-num { flex: 0 0 20px; height: 20px; border-radius: 50%; color: var(--white); font-size: 11px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; margin-top: 1px; }
.result-note.green .rn-num { background: #34c759; }
.result-note.orange .rn-num { background: #ff9f0a; }
.result-note.red .rn-num { background: #ff3b30; }
.result-note .rn-body { flex: 1; min-width: 0; font-size: 13.5px; line-height: 1.5; color: var(--grey-800); }
.results-empty { font-size: 13px; color: var(--grey-400); padding: 6px 2px; }

.graded-image-wrap { position: relative; width: 100%; border: 1px solid var(--grey-200); border-radius: var(--radius-md); overflow: hidden; background: var(--white); touch-action: manipulation; }
.graded-image-wrap img { display: block; width: 100%; height: auto; }
.bbox { position: absolute; border: 2.5px solid; border-radius: 5px; cursor: pointer; background: rgba(255,255,255,0.04); transition: background var(--t-fast); }
.bbox.green { border-color: #34c759; }
.bbox.orange { border-color: #ff9f0a; }
.bbox.red { border-color: #ff3b30; }
.bbox:hover, .bbox.active { background: rgba(0,0,0,0.06); }
.bbox-num { position: absolute; top: -10px; left: -10px; width: 20px; height: 20px; border-radius: 50%; color: var(--white); font-size: 11px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.bbox.green .bbox-num { background: #34c759; }
.bbox.orange .bbox-num { background: #ff9f0a; }
.bbox.red .bbox-num { background: #ff3b30; }
.bbox-tooltip { position: absolute; z-index: 5; max-width: 280px; background: var(--black); color: var(--white); border-radius: var(--radius-sm); padding: 9px 12px; font-size: 12.5px; line-height: 1.45; box-shadow: var(--shadow-md); pointer-events: none; }
.bbox-tooltip * { color: var(--white) !important; }
.bbox-hint { font-size: 11.5px; color: var(--grey-400); margin-bottom: 12px; }

.next-actions { display: flex; flex-direction: column; gap: 10px; }
.next-title { font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--grey-400); margin-bottom: 2px; }
.action-row { display: grid; grid-template-columns: 1fr; gap: 8px; }
.action-btn { display: flex; align-items: center; gap: 12px; text-align: left; padding: 12px 14px; border-radius: var(--radius-md); border: 1.5px solid var(--grey-200); background: var(--white); transition: border-color var(--t-fast), background var(--t-fast), transform var(--t-fast); }
.action-btn:hover { border-color: var(--grey-400); background: var(--grey-25); }
.action-btn:active { transform: scale(0.99); }
.action-btn svg { width: 20px; height: 20px; flex-shrink: 0; color: var(--grey-600); }
.action-btn .a-title { font-size: 13.5px; font-weight: 600; color: var(--black); display: block; }
.action-btn .a-sub { font-size: 12px; color: var(--grey-600); display: block; margin-top: 1px; }
.action-btn.primary { background: var(--accent); border-color: var(--accent); }
.action-btn.primary svg, .action-btn.primary .a-title { color: var(--white); }
.action-btn.primary .a-sub { color: rgba(255,255,255,0.8); }
.action-btn.primary:hover { background: var(--accent-hover); }
.action-btn.warm { background: var(--amber-tint); border-color: var(--amber-line); }
.action-btn.warm svg { color: var(--warning); }
.action-btn:disabled { opacity: 0.55; }
.reward { color: var(--gold); font-weight: 700; letter-spacing: 1px; }

.changed-note { margin-top: 12px; }
.solution-body { font-size: 13.5px; line-height: 1.6; padding: 10px 0 0; }
details { border: 1px solid var(--grey-100); border-radius: var(--radius-md); padding: 10px 14px; background: var(--grey-25); }
summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--grey-800); list-style: none; display: flex; align-items: center; gap: 8px; }
summary::-webkit-details-marker { display: none; }
summary::before { content: ""; width: 7px; height: 7px; border-right: 2px solid var(--grey-400); border-bottom: 2px solid var(--grey-400); transform: rotate(-45deg); transition: transform var(--t-fast); margin-left: 2px; }
details[open] summary::before { transform: rotate(45deg); }

/* ═══════════════════════════════════════════════════════════════════
   Workspace
   ═══════════════════════════════════════════════════════════════════ */
.workspace { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--grey-50); position: relative; }
/* Three columns so the Notebook/Whiteboard switch sits centred in the workspace,
   with the utility buttons pinned right. */
.ws-toolbar { height: 50px; flex-shrink: 0; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 0 14px; gap: 10px; border-bottom: 1px solid var(--grey-100); background: rgba(255,255,255,0.8); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.ws-toolbar-right { display: flex; align-items: center; gap: 6px; justify-self: end; }
.ws-body { flex: 1; position: relative; min-height: 0; }
.ws-view { position: absolute; inset: 0; }

/* Notebook */
.notebook-scroll { position: absolute; inset: 0; overflow-y: auto; padding: 22px 20px 120px; -webkit-overflow-scrolling: touch; }
.notebook-page { max-width: 860px; margin: 0 auto; background: var(--white); border: 1px solid var(--grey-100); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); padding: 22px 22px 18px; min-height: 420px; }
.nb-block { position: relative; display: flex; gap: 8px; margin: 0 0 6px; border-radius: var(--radius-md); transition: background var(--t-fast); }
.nb-block:hover, .nb-block.focus { background: var(--grey-25); }
.nb-gutter { flex: 0 0 26px; display: flex; flex-direction: column; align-items: center; padding-top: 6px; gap: 2px; opacity: 0; transition: opacity var(--t-fast); }
.nb-block:hover .nb-gutter, .nb-block.focus .nb-gutter { opacity: 1; }
.nb-gutter button { width: 24px; height: 24px; border-radius: 6px; color: var(--grey-400); display: inline-flex; align-items: center; justify-content: center; }
.nb-gutter button:hover { background: var(--grey-100); color: var(--grey-800); }
.nb-gutter button svg { width: 14px; height: 14px; }
.nb-gutter .nb-index { font-size: 10px; color: var(--grey-300); font-weight: 600; margin-bottom: 2px; }
.nb-main { flex: 1; min-width: 0; padding: 4px 6px 4px 0; }
.nb-input { width: 100%; border: none; background: transparent; padding: 6px 8px; font-size: 15px; line-height: 1.6; resize: none; overflow: hidden; min-height: 40px; outline: none; border-radius: 8px; font-family: var(--font); color: var(--grey-800); }
.nb-input:focus { background: var(--white); box-shadow: inset 0 0 0 1.5px var(--accent); }
/* At grey-300 the prompt to start writing was read as disabled text, and reviewers went
   looking for somewhere else to type. It has to look like an invitation. */
.nb-input::placeholder { color: var(--grey-600); opacity: 1; font-weight: 500; }
.nb-preview { padding: 6px 8px; font-size: 15px; line-height: 1.6; min-height: 40px; cursor: text; border-radius: 8px; word-wrap: break-word; }
.nb-preview.empty { color: var(--grey-300); }
.nb-preview .katex-display { margin: 6px 0; }
.nb-drawing .nb-main { padding-right: 0; }
.nb-canvas-wrap { position: relative; border: 1.5px solid var(--grey-200); border-radius: var(--radius-md); overflow: hidden; background: var(--white); }
.nb-canvas-wrap.editing { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.nb-canvas { width: 100%; height: 340px; position: relative; }
.nb-snapshot { display: block; width: 100%; max-height: 520px; object-fit: contain; background: var(--white); cursor: pointer; }
.nb-snapshot-empty { display: flex; align-items: center; justify-content: center; height: 140px; color: var(--grey-400); font-size: 13px; cursor: pointer; gap: 8px; }
.nb-drawing-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 8px; background: var(--grey-25); border-top: 1px solid var(--grey-100); }
.nb-drawing-bar .lbl { font-size: 11.5px; font-weight: 600; color: var(--grey-400); letter-spacing: 0.04em; text-transform: uppercase; padding-left: 4px; }
.nb-drawing-bar .actions { display: flex; gap: 6px; }
.nb-drawing-bar .btn-sm { min-height: 30px; padding: 5px 12px; }
.nb-resize { height: 8px; cursor: ns-resize; background: linear-gradient(to right, transparent 45%, var(--grey-200) 45%, var(--grey-200) 55%, transparent 55%); background-size: 40px 2px; background-repeat: no-repeat; background-position: center; }
.add-block-bar { display: flex; align-items: center; gap: 8px; padding: 10px 6px 0 34px; flex-wrap: wrap; }
.add-block-btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: var(--radius-full); border: 1px dashed var(--grey-300); font-size: 12.5px; font-weight: 600; color: var(--grey-600); transition: all var(--t-fast); min-height: 32px; }
.add-block-btn svg { width: 14px; height: 14px; }
.add-block-btn:hover { border-style: solid; border-color: var(--grey-800); color: var(--black); background: var(--white); }
.add-block-hint { font-size: 12px; color: var(--grey-400); }

/* Whiteboard */
.whiteboard-canvas { position: absolute; inset: 0; }
.excalidraw .sidebar-trigger, .excalidraw .footer-center, .excalidraw .HelpDialog-btn, .excalidraw .encrypted-icon, .excalidraw .main-menu-trigger, .excalidraw .welcome-screen-center, .excalidraw .welcome-screen-decor, .excalidraw .layer-ui__wrapper__footer-right { display: none !important; }
.excalidraw .dropdown-menu-group:has([data-testid*="mermaid"]), .excalidraw [data-testid*="mermaid"], .excalidraw [data-testid="image-to-diagram"] { display: none !important; }
.excalidraw .App-menu__left { top: 70px !important; }
.nb-canvas .excalidraw .App-menu__left { top: 56px !important; max-height: calc(100% - 70px); }
.excalidraw--view-mode .App-toolbar { display: none !important; }

/* Locked overlay */
/* A slim, non-blocking strip: the workspace is already read-only when locked, so a
   full-screen scrim was covering work the student may want to re-read. */
.ws-locked { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 8; display: flex; align-items: center; gap: 10px; padding: 7px 8px 7px 14px; border-radius: var(--radius-full); background: rgba(255,255,255,0.94); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border: 1px solid var(--grey-200); box-shadow: var(--shadow-md); font-size: 13px; font-weight: 500; color: var(--grey-800); white-space: nowrap; animation: fadeUp 220ms var(--ease); max-width: calc(100% - 24px); }
.ws-locked .text-btn { padding: 5px 11px; font-size: 12.5px; }
.lock-dot { width: 8px; height: 8px; border-radius: 50%; background: #34c759; flex-shrink: 0; }
.lock-dot.fail { background: #ff3b30; }

/* Grading overlay */
.grading-overlay { position: absolute; inset: 0; z-index: 9; display: flex; align-items: center; justify-content: center; background: rgba(255,255,255,0.72); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); opacity: 0; pointer-events: none; transition: opacity var(--t-med); }
.grading-overlay.active { opacity: 1; pointer-events: auto; }
.grading-card { display: flex; flex-direction: column; gap: 12px; padding: 22px 24px; background: var(--white); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); border: 1px solid var(--grey-100); width: min(440px, 92%); }
.grading-head { display: flex; align-items: center; gap: 14px; }
.grading-head > div:nth-child(2) { flex: 1; min-width: 0; }
.grading-card h3 { font-size: 16px; font-weight: 700; }
.grading-card p { font-size: 13px; color: var(--grey-600); min-height: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* A heads-up for waits that are long by nature (harder problems), so a two-minute spinner
   does not read as a hang. Wraps, unlike the one-line status above it. */
.grading-card p.grading-note { white-space: normal; font-size: 12.5px; line-height: 1.45; color: var(--grey-600); background: var(--grey-50); border-radius: 8px; padding: 8px 10px; min-height: 0; }
.grading-timer { font-family: var(--mono); font-size: 12px; color: var(--grey-400); font-variant-numeric: tabular-nums; flex-shrink: 0; }
.grading-spinner { width: 36px; height: 36px; flex-shrink: 0; animation: grading-rotate 2s linear infinite; }
.grading-feed { display: flex; flex-direction: column; gap: 5px; max-height: 148px; overflow: hidden; border-top: 1px solid var(--grey-100); padding-top: 10px; }
.grading-feed:empty { display: none; }
.feed-item { display: flex; align-items: flex-start; gap: 8px; font-size: 12.5px; line-height: 1.4; color: var(--grey-600); animation: fadeUp 200ms var(--ease); }
.feed-item .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--grey-300); margin-top: 6px; flex-shrink: 0; }
.feed-item.live { color: var(--grey-800); font-weight: 500; }
.feed-item.live .dot { background: var(--accent); animation: dotPulse 1.5s ease-in-out infinite; }
.feed-item.code { color: var(--grey-600); }
.feed-item.code .dot { background: #34c759; }
/* Code-execution steps show a calculator instead of a dot. The code itself stays hidden;
   students only need to know the grader or tutor is checking the numbers. */
:root { --calc-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Crect x='3' y='1.75' width='10' height='12.5' rx='1.8' fill='none' stroke='black' stroke-width='1.5'/%3E%3Crect x='5.25' y='4' width='5.5' height='2.4' rx='.5'/%3E%3Ccircle cx='5.9' cy='9.1' r='.85'/%3E%3Ccircle cx='8' cy='9.1' r='.85'/%3E%3Ccircle cx='10.1' cy='9.1' r='.85'/%3E%3Ccircle cx='5.9' cy='11.6' r='.85'/%3E%3Ccircle cx='8' cy='11.6' r='.85'/%3E%3Ccircle cx='10.1' cy='11.6' r='.85'/%3E%3C/svg%3E"); }
.feed-item.code .dot, .chat-activity .row.code .dot { width: 14px; height: 14px; border-radius: 0; -webkit-mask: var(--calc-icon) center / contain no-repeat; mask: var(--calc-icon) center / contain no-repeat; }
.feed-item.code .dot { margin-top: 2px; background: var(--grey-400); }
.feed-item.code.live .dot, .chat-activity .row.code .dot { background: #34c759; animation: calcPulse 1.2s ease-in-out infinite; }
@keyframes calcPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
@keyframes dotPulse { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(0.6); opacity: 0.5; } }
.feed-item code { font-size: 11px; background: var(--grey-50); padding: 1px 5px; border-radius: 4px; color: var(--grey-600); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; display: inline-block; vertical-align: middle; }
.feed-item .ellipsis::after { content: "…"; animation: dots 1.4s steps(4) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }
.grading-spinner circle { stroke: var(--accent); stroke-linecap: round; animation: grading-dash 1.5s ease-in-out infinite; }
@keyframes grading-rotate { 100% { transform: rotate(360deg); } }
@keyframes grading-dash { 0% { stroke-dasharray: 1, 150; stroke-dashoffset: 0; } 50% { stroke-dasharray: 90, 150; stroke-dashoffset: -35; } 100% { stroke-dasharray: 90, 150; stroke-dashoffset: -124; } }

/* Action bar */
.ws-actionbar { flex-shrink: 0; display: flex; align-items: center; gap: 10px; padding: 10px 14px calc(10px + var(--safe-b)); background: rgba(255,255,255,0.88); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--grey-100); }
.ws-actionbar .spacer { flex: 1; }
.upload-chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 6px 4px 10px; border-radius: var(--radius-full); background: var(--blue-tint); border: 1px solid var(--blue-line); color: var(--accent); font-size: 12px; font-weight: 500; max-width: 220px; }
.upload-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-x { width: 20px; height: 20px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; color: var(--accent); font-size: 15px; line-height: 1; }
.chip-x:hover { background: rgba(0,113,227,0.2); }

/* ═══════════════════════════════════════════════════════════════════
   Tutor chat
   ═══════════════════════════════════════════════════════════════════ */
/* Only one side of this conversation is in a bubble. The tutor writes explanations with
   equations in them, and boxing that in grey at 88% width is what makes a chat read like
   a support widget: the text is the content, so it gets the full column and no container.
   The student's own lines stay contained, quiet grey rather than a brand colour, which is
   enough to tell the two voices apart. */
.chat-messages { flex: 1; overflow-y: auto; padding: 18px 22px 20px; display: flex; flex-direction: column; gap: 18px; -webkit-overflow-scrolling: touch; }
.chat-empty { margin: auto; text-align: center; color: var(--grey-400); font-size: 13px; max-width: 250px; line-height: 1.55; animation: fadeUp 240ms var(--ease); }
.chat-empty .ce-title { font-size: 15px; font-weight: 600; color: var(--grey-800); margin-bottom: 6px; letter-spacing: -0.01em; }
.msg { font-size: 14.5px; line-height: 1.62; word-wrap: break-word; animation: fadeUp 180ms var(--ease); }
.msg.tutor { align-self: stretch; color: var(--grey-800); }
.msg.student { align-self: flex-end; max-width: 85%; background: var(--grey-100); color: var(--grey-800); padding: 10px 16px; border-radius: 20px; }
.msg.system { align-self: center; background: transparent; color: var(--grey-400); font-size: 12px; text-align: center; padding: 2px 8px; }
.msg.error { align-self: stretch; background: var(--red-tint); border: 1px solid var(--red-line); color: var(--danger); padding: 10px 14px; border-radius: 14px; font-size: 13.5px; }
/* A caret while the reply streams, instead of three bouncing dots. */
.msg.streaming::after { content: ""; display: inline-block; width: 7px; height: 14px; background: var(--grey-800); margin-left: 3px; vertical-align: -2px; animation: caret 1.1s steps(2, start) infinite; }
@keyframes caret { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }
.msg-meta { align-self: flex-end; font-size: 11px; font-weight: 500; color: var(--grey-400); margin: -13px 6px 0; letter-spacing: -0.005em; animation: fadeUp 180ms var(--ease); }
.msg .md p { margin-bottom: 8px; }
.msg-thumb { display: block; max-width: 180px; max-height: 120px; border-radius: 12px; margin-bottom: 6px; }
.msg-status { font-size: 11.5px; color: var(--grey-400); display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; }
.chat-activity { align-self: stretch; display: flex; flex-direction: column; gap: 4px; padding: 0; font-size: 12.5px; color: var(--grey-400); animation: fadeUp 180ms var(--ease); }
.chat-activity .row { display: flex; align-items: center; gap: 7px; }
.chat-activity .row .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--grey-400); animation: dotPulse 1.5s ease-in-out infinite; flex-shrink: 0; }
.chat-activity .row.done .dot { background: var(--grey-300); animation: none; }
.chat-activity .t { font-family: var(--mono); font-size: 10.5px; color: var(--grey-400); margin-left: auto; padding-left: 8px; }
.typing { display: inline-flex; gap: 4px; padding: 12px 16px; align-self: flex-start; background: var(--grey-50); border-radius: 18px; border-bottom-left-radius: 6px; }
.typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--grey-400); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: 0.2s; } .typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }
/* Starters are for a thread that has not started. Leaving them parked above the composer
   for the whole conversation is the canned-reply look we are getting away from. */
.chat-quick { display: flex; gap: 6px; padding: 2px 18px 10px; flex-wrap: wrap; flex-shrink: 0; }

/* The composer is a field with its controls underneath, not a row of three widgets. */
.chat-composer { display: flex; align-items: flex-end; padding: 4px 12px calc(12px + var(--safe-b)); background: var(--white); flex-shrink: 0; }
.composer-bar { flex: 1; display: flex; flex-direction: column; align-items: stretch; min-width: 0; padding: 8px 10px; border: 1px solid var(--grey-200); border-radius: 26px; background: var(--white); box-shadow: 0 1px 2px rgba(0,0,0,0.04); transition: border-color var(--t-fast), box-shadow var(--t-fast); }
.composer-bar:focus-within { border-color: var(--grey-300); box-shadow: 0 2px 12px rgba(0,0,0,0.07); }
.chat-composer textarea { width: 100%; min-width: 0; border: none; background: transparent; box-shadow: none; border-radius: 0; padding: 3px 8px 0; max-height: 150px; line-height: 1.5; font-size: 14.5px; resize: none; min-height: 26px; }
.chat-composer textarea:focus { border: none; box-shadow: none; }
.composer-row { display: flex; align-items: center; gap: 4px; margin-top: 4px; }
.composer-row .spacer { flex: 1; }
.icon-btn.attach { width: 32px; height: 32px; border-radius: 50%; }
.icon-btn.attach svg { width: 17px; height: 17px; }
.send-btn { position: relative; width: 32px; height: 32px; border-radius: 50%; background: var(--black); color: var(--white); display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; transition: background var(--t-fast), color var(--t-fast), opacity var(--t-fast); }
.send-btn:hover { background: var(--grey-800); }
.send-btn:disabled { background: var(--grey-100); color: var(--grey-300); }
/* The mic holds the send button's slot while there is nothing to send. Idle it is a quiet
   ghost icon; listening it fills in and breathes, and the ring quickens while the student
   is actually producing words, so the button reads as hearing them rather than just on. */
.send-btn.mic { background: transparent; color: var(--grey-600); }
.send-btn.mic:hover { background: var(--grey-100); color: var(--grey-800); }
.send-btn.mic svg { width: 17px; height: 17px; }
.send-btn.mic.listening, .send-btn.mic.listening:hover { background: var(--black); color: var(--white); }
.send-btn.mic.listening::after { content: ""; position: absolute; inset: 0; border-radius: 50%; box-shadow: 0 0 0 0 rgba(0,0,0,0.30); animation: micPulse 1.8s var(--ease) infinite; }
.send-btn.mic.listening.speaking::after { animation-duration: 0.85s; }
@keyframes micPulse { from { box-shadow: 0 0 0 0 rgba(0,0,0,0.30); } to { box-shadow: 0 0 0 11px rgba(0,0,0,0); } }
@media (prefers-reduced-motion: reduce) { .send-btn.mic.listening::after { animation: none; } }
.send-btn svg { width: 18px; height: 18px; stroke-width: 2.2; }
.chat-attach-chip { font-size: 12px; color: var(--accent); padding: 0 16px 10px; display: flex; align-items: center; gap: 8px; }

/* Edge tabs */
.edge-tab { position: absolute; top: 50%; transform: translateY(-50%); z-index: 20; display: inline-flex; align-items: center; gap: 4px; padding: 10px 8px; background: var(--white); border: 1px solid var(--grey-200); box-shadow: var(--shadow-md); color: var(--grey-800); font-size: 11.5px; font-weight: 600; writing-mode: vertical-rl; text-orientation: mixed; letter-spacing: 0.03em; transition: background var(--t-fast); }
.edge-tab.left { left: 0; border-left: none; border-radius: 0 10px 10px 0; }
.edge-tab.right { right: 0; border-right: none; border-radius: 10px 0 0 10px; }
.edge-tab:hover { background: var(--grey-50); }
.edge-tab svg { width: 14px; height: 14px; }

/* ═══════════════════════════════════════════════════════════════════
   Drawer (questions)
   ═══════════════════════════════════════════════════════════════════ */
.drawer-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 500; opacity: 0; visibility: hidden; transition: opacity var(--t-med), visibility var(--t-med); }
.drawer-overlay.active { opacity: 1; visibility: visible; }
.drawer { position: fixed; top: 0; left: 0; bottom: 0; width: 340px; max-width: 88vw; background: var(--white); z-index: 501; box-shadow: var(--shadow-lg); transform: translateX(-100%); transition: transform var(--t-med); display: flex; flex-direction: column; }
.drawer.open { transform: translateX(0); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 10px 14px 20px; border-bottom: 1px solid var(--grey-100); }
.drawer-head h2 { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.drawer-exam { padding: 14px 20px 8px; display: flex; flex-direction: column; gap: 10px; }

/* Custom exam picker. A native <select> drops an OS-blue list that belongs to no design system. */
.exam-picker { position: relative; }
.exam-btn { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; min-height: var(--touch); padding: 9px 12px; border-radius: var(--radius-md); border: 1px solid var(--grey-200); background: var(--white); font-size: 14px; font-weight: 600; letter-spacing: -0.01em; color: var(--grey-800); text-align: left; transition: background var(--t-fast), border-color var(--t-fast); }
.exam-btn:hover { background: var(--grey-25); border-color: var(--grey-300); }
.exam-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.exam-btn svg { width: 16px; height: 16px; color: var(--grey-400); flex-shrink: 0; transition: transform var(--t-fast); }
.exam-picker.open .exam-btn { border-color: var(--grey-400); }
.exam-picker.open .exam-btn svg { transform: rotate(180deg); }
/* One exam: nothing to choose, so it reads as a heading rather than a control. */
.exam-picker.single .exam-btn { pointer-events: none; border-color: transparent; background: transparent; padding: 0 2px; min-height: 0; font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--grey-400); }
.exam-picker.single .exam-btn svg { display: none; }
.exam-menu { position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 30; background: var(--white); border: 1px solid var(--grey-100); border-radius: var(--radius-md); box-shadow: var(--shadow-lg); padding: 5px; animation: fadeUp 140ms var(--ease); max-height: 300px; overflow-y: auto; }
.exam-option { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border-radius: 8px; font-size: 13.5px; font-weight: 500; color: var(--grey-800); text-align: left; transition: background var(--t-fast); }
.exam-option:hover { background: var(--grey-50); }
.exam-option span:first-child { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.exam-option.active { font-weight: 600; }
.exam-option .tick { width: 15px; height: 15px; flex-shrink: 0; color: var(--accent); opacity: 0; }
.exam-option .tick svg { width: 15px; height: 15px; stroke-width: 2.4; }
.exam-option.active .tick { opacity: 1; }
.drawer-progress { font-size: 12px; color: var(--grey-600); display: flex; align-items: center; gap: 10px; font-variant-numeric: tabular-nums; flex-wrap: wrap; }
.drawer-progress .drawer-score-btn { flex: 0 0 auto; font-size: 12px; padding: 0; }
.drawer-progress .bar { flex: 1; height: 4px; background: var(--grey-100); border-radius: 2px; overflow: hidden; }
.drawer-progress .bar i { display: block; height: 100%; background: var(--success); border-radius: 2px; transition: width var(--t-med); }
.drawer-list { flex: 1; overflow-y: auto; padding: 8px 12px 20px; display: flex; flex-direction: column; gap: 2px; }
.q-item { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: var(--radius-md); text-align: left; transition: background var(--t-fast); width: 100%; }
.q-item:hover { background: var(--grey-50); }
.q-item.active { background: var(--grey-100); }
.q-num { flex: 0 0 30px; height: 30px; border-radius: 9px; background: var(--grey-100); font-size: 12px; font-weight: 600; color: var(--grey-600); display: inline-flex; align-items: center; justify-content: center; font-variant-numeric: tabular-nums; }
.q-item.active .q-num, .q-item:hover .q-num { background: var(--grey-800); color: var(--white); }
.q-body { flex: 1; min-width: 0; }
/* Titles wrap rather than truncate: an ellipsis on every row tells the student nothing. */
.q-title { font-size: 13.5px; font-weight: 500; color: var(--grey-800); line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.q-item.active .q-title { font-weight: 600; color: var(--black); }
.q-meta { font-size: 11.5px; color: var(--grey-400); margin-top: 2px; }
.q-status { font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: var(--radius-full); white-space: nowrap; }
.q-status.correct { background: var(--green-tint); color: var(--success); }
.q-status.corrected { background: var(--green-tint); color: var(--success); border: 1px solid var(--green-line); }
.q-status.failed { background: var(--red-tint); color: var(--danger); }
.q-status.progress { background: var(--blue-tint); color: var(--accent); }
.q-status.none { color: var(--grey-400); font-weight: 500; }

/* ═══════════════════════════════════════════════════════════════════
   Modals & sheets
   ═══════════════════════════════════════════════════════════════════ */
.modal-overlay { position: fixed; inset: 0; z-index: 900; background: rgba(0,0,0,0.42); display: flex; align-items: center; justify-content: center; padding: 20px; opacity: 0; visibility: hidden; transition: opacity var(--t-med), visibility var(--t-med); }
.modal-overlay.active { opacity: 1; visibility: visible; }
.modal { width: 100%; max-width: 420px; background: var(--white); border-radius: var(--radius-xl); box-shadow: var(--shadow-lg); padding: 28px 28px 22px; transform: translateY(8px) scale(0.98); transition: transform var(--t-med); max-height: calc(100vh - 40px); overflow-y: auto; }
.modal-overlay.active .modal { transform: none; }
.modal h3 { font-size: 19px; font-weight: 700; letter-spacing: -0.02em; margin-bottom: 8px; }
.modal > p { font-size: 14px; color: var(--grey-600); margin-bottom: 18px; line-height: 1.5; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
.modal-actions .btn { min-width: 110px; }
.modal .btn-link { display: block; margin: 12px auto 0; }
.slider-label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 14px; }
input[type="range"] { width: 100%; accent-color: var(--accent); cursor: pointer; }
.slider-scale { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--grey-400); margin-top: 6px; font-weight: 500; }
.slider-value { text-align: center; font-size: 30px; font-weight: 700; letter-spacing: -0.02em; margin: 14px 0 20px; }
.option-list { display: flex; flex-direction: column; gap: 10px; }
.option-btn { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-radius: var(--radius-md); border: 1.5px solid var(--grey-200); background: var(--white); text-align: left; transition: border-color var(--t-fast), background var(--t-fast); }
.option-btn:hover { border-color: var(--grey-400); background: var(--grey-25); }
.option-btn svg { width: 24px; height: 24px; color: var(--grey-600); flex-shrink: 0; }
.option-btn strong { display: block; font-size: 14.5px; }
.option-btn small { display: block; font-size: 12.5px; color: var(--grey-600); }
.qr-box { display: flex; justify-content: center; padding: 16px; background: var(--white); border: 1px dashed var(--grey-300); border-radius: var(--radius-md); margin: 6px 0 12px; }
#qr-code { width: 180px; height: 180px; }
.qr-status { font-size: 13px; color: var(--grey-600); text-align: center; }
.qr-status.ok { color: var(--success); font-weight: 600; }
.axis-list { display: flex; flex-direction: column; gap: 8px; }
.axis-card { display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; border: 1.5px solid var(--grey-200); border-radius: var(--radius-md); cursor: pointer; transition: border-color var(--t-fast), background var(--t-fast); }
.axis-card:hover { border-color: var(--grey-400); }
.axis-card:has(input:checked) { border-color: var(--accent); background: var(--blue-tint); }
.axis-card input { margin-top: 4px; accent-color: var(--accent); width: 16px; height: 16px; }
.axis-card strong { display: block; font-size: 14px; }
.axis-card small { display: block; font-size: 12.5px; color: var(--grey-600); }
.symbols-modal { max-width: 520px; }

/* Score card */
.score-modal { max-width: 440px; }
.score-hero { display: flex; align-items: baseline; justify-content: center; gap: 8px; margin: 4px 0 12px; }
.score-big { font-size: 46px; font-weight: 700; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.score-big-label { font-size: 13px; color: var(--grey-600); }
.score-bar { height: 8px; background: var(--grey-100); border-radius: 4px; overflow: hidden; }
.score-bar i { display: block; height: 100%; background: var(--success); border-radius: 4px; transition: width var(--t-med); }
.score-lines { list-style: none; margin: 16px 0 0; padding: 0; display: flex; flex-direction: column; }
.score-lines li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 9px 2px; font-size: 14px; color: var(--grey-600); border-bottom: 1px solid var(--grey-50); }
.score-lines li:last-child { border-bottom: none; }
.score-lines li b { color: var(--grey-800); font-variant-numeric: tabular-nums; }
.symbols-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); gap: 6px; }
.sym-btn { height: 44px; border-radius: 10px; border: 1px solid var(--grey-200); background: var(--white); font-size: 15px; display: inline-flex; align-items: center; justify-content: center; transition: background var(--t-fast), border-color var(--t-fast); }
.sym-btn:hover { background: var(--grey-50); border-color: var(--grey-400); }
.sym-btn .katex { font-size: 1em; }

.sheet-overlay { position: fixed; inset: 0; z-index: 950; background: rgba(0,0,0,0.3); opacity: 0; visibility: hidden; transition: opacity var(--t-med), visibility var(--t-med); }
.sheet-overlay.active { opacity: 1; visibility: visible; }
.sheet { position: fixed; top: 0; right: 0; bottom: 0; width: 380px; max-width: 92vw; background: var(--white); z-index: 951; box-shadow: var(--shadow-lg); transform: translateX(100%); transition: transform var(--t-med); display: flex; flex-direction: column; }
.sheet.open { transform: translateX(0); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 10px 14px 20px; border-bottom: 1px solid var(--grey-100); }
.sheet-head h3 { font-size: 16px; font-weight: 700; }
.sheet-body { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.sheet-body p { font-size: 13.5px; color: var(--grey-600); line-height: 1.5; }
.sheet-body textarea { min-height: 130px; font-size: 14px; }
.check-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--grey-800); cursor: pointer; }
.check-row input { accent-color: var(--accent); width: 16px; height: 16px; }
.shot-preview { border: 1px solid var(--grey-200); border-radius: var(--radius-md); overflow: hidden; background: var(--grey-50); min-height: 0; }
.shot-preview img { display: block; width: 100%; max-height: 200px; object-fit: contain; }
.shot-preview .loading { padding: 20px; text-align: center; font-size: 12.5px; color: var(--grey-600); display: flex; align-items: center; justify-content: center; gap: 8px; }

/* Toasts */
.toasts { position: fixed; bottom: calc(20px + var(--safe-b)); left: 50%; transform: translateX(-50%); z-index: 1200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { pointer-events: auto; background: var(--grey-800); color: var(--white); padding: 11px 18px; border-radius: var(--radius-full); font-size: 13.5px; font-weight: 500; box-shadow: var(--shadow-lg); animation: fadeUp 200ms var(--ease); max-width: min(520px, 90vw); text-align: center; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.warn { background: var(--warning); }

/* Tutorial */
.tutorial-backdrop { position: fixed; inset: 0; z-index: 1000; opacity: 0; visibility: hidden; transition: opacity var(--t-med), visibility var(--t-med); pointer-events: none; }
.tutorial-backdrop.active { opacity: 1; visibility: visible; pointer-events: auto; }
.tutorial-mask { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 1001; pointer-events: none; display: none; }
.tutorial-popover { position: fixed; z-index: 1005; width: 300px; background: var(--white); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 18px 18px 14px; display: none; flex-direction: column; gap: 8px; animation: pop 220ms var(--ease); }
.tutorial-step { font-size: 11px; font-weight: 700; color: var(--grey-400); letter-spacing: 0.08em; text-transform: uppercase; }
.tutorial-title { font-size: 15px; font-weight: 700; letter-spacing: -0.01em; }
.tutorial-desc { font-size: 13px; color: var(--grey-600); line-height: 1.5; }
.tutorial-buttons { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; }

/* Diagram lightbox */
.lightbox { position: fixed; inset: 0; z-index: 1100; background: rgba(0,0,0,0.75); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 30px; cursor: zoom-out; animation: fadeUp 150ms var(--ease); }
.lightbox img, .lightbox svg { max-width: 100%; max-height: 100%; background: var(--white); border-radius: var(--radius-md); padding: 16px; }
.lightbox .lightbox-note { color: rgba(255,255,255,0.82); font-size: 12.5px; text-align: center; }

/* ═══════════════════════════════════════════════════════════════════
   Responsive & touch
   ═══════════════════════════════════════════════════════════════════ */
/* One docked panel at a time (see isCompactLayout); cap it so the workspace keeps most of the width */
@media (min-width: 900px) and (max-width: 1279px) {
    .side-panel.left { width: min(var(--panel-left-w), 42vw); }
    .side-panel.right { width: min(var(--panel-right-w), 42vw); }
}

@media (max-width: 899px) {
    .side-panel { position: absolute; top: 0; bottom: 0; z-index: 30; box-shadow: var(--shadow-lg); width: min(440px, 88vw) !important; }
    .side-panel.left { left: 0; border-right: 1px solid var(--grey-100); }
    .side-panel.right { right: 0; border-left: 1px solid var(--grey-100); }
    .side-panel.left.collapsed { transform: translateX(-100%); width: min(440px, 88vw) !important; opacity: 1; }
    .side-panel.right.collapsed { transform: translateX(100%); width: min(440px, 88vw) !important; opacity: 1; }
    .resizer { display: none; }
}

@media (max-width: 900px) {
    :root { --header-h: 54px; }
    .app-header { grid-template-columns: auto 1fr auto; gap: 8px; padding: 0 8px; }
    .header-center { justify-content: flex-start; }
    .sync-text { display: none; }
    #btn-feedback { display: none; }
    .add-block-hint { display: none; }
    .notebook-scroll { padding: 12px 10px 110px; }
    .notebook-page { padding: 14px 12px; border-radius: var(--radius-md); }
    .pill-btn span { display: none; }
    .pill-btn { padding: 0 14px; }
    .pill-btn.primary span { display: inline; }
    .modal { padding: 22px 20px 18px; }
    .drawer { width: 320px; }
}

@media (max-width: 640px) {
    .mode-pill { padding: 5px 10px; font-size: 12px; }
    .stars-chip { padding: 4px 9px; }
    .segmented .seg-btn span { display: none; }
    .seg-btn { padding: 0 12px; }
    .side-panel { width: 100vw !important; }
    .side-panel.left.collapsed, .side-panel.right.collapsed { width: 100vw !important; }
}

/* Touch devices (iPad, tablets, phones): larger targets and roomier controls */
@media (pointer: coarse) {
    :root { --touch: 44px; }
    body { font-size: 16px; }
    .btn { min-height: 46px; padding: 12px 22px; font-size: 15px; }
    .pill-btn { height: 46px; padding: 0 20px; font-size: 15px; }
    .seg-btn { height: 38px; font-size: 14px; }
    .segmented { border-radius: 12px; }
    .chip { min-height: 38px; padding: 8px 14px; font-size: 13.5px; }
    .icon-btn svg { width: 20px; height: 20px; }
    .action-btn { padding: 14px 16px; }
    .q-item { padding: 13px 12px; }
    .nb-gutter { opacity: 1; }
    .nb-gutter button { width: 30px; height: 30px; }
    .nb-input, .nb-preview { font-size: 16px; }
    .chat-composer textarea { font-size: 16px; min-height: 44px; }
    .send-btn { width: 44px; height: 44px; }
    .nb-canvas { height: 400px; }
    .nb-resize { height: 14px; }
    .bbox { border-width: 3px; }
    .edge-tab { padding: 14px 10px; font-size: 12.5px; }
    .resizer { display: none; }
    .ws-actionbar { padding-top: 12px; }
    .excalidraw .App-toolbar { transform: scale(1.05); transform-origin: top center; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
