/* Slide Studio — application styles.
   White working chrome over a dark stage, indigo for the active tool. */

:root {
    --ink: #1f2330;
    --ink-2: #4b5263;
    --ink-3: #7a8193;
    --surface: #ffffff;
    --surface-2: #f5f6f9;
    --surface-3: #eceef3;
    --line: #dfe2e9;
    --line-2: #c9cdd8;
    --accent: #4f46e5;
    --accent-2: #4338ca;
    --accent-soft: #eef0ff;
    --red: #dc2626;
    --red-soft: #fdf0f0;
    --amber: #b45309;
    --purple: #7c3aed;
    --blue: #2563eb;
    --green: #15803d;
    --stage: #2a2c33;
    --stage-deep: #16171d;
    --radius: 6px;
    --radius-lg: 12px;
    --shadow-pop: 0 10px 30px rgba(15, 18, 30, 0.2), 0 2px 6px rgba(15, 18, 30, 0.08);
    --font-ui: 'Segoe UI', system-ui, -apple-system, Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-mono: ui-monospace, 'Cascadia Code', 'SF Mono', Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
    margin: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--stage-deep);
    color: var(--ink);
    font: 14px/1.45 var(--font-ui);
    -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
code, kbd { font-family: var(--font-mono); font-size: 0.92em; }

.noscript { padding: 24px; color: #fff; }

/* ---------------------------------------------------------------- Toolbar */
/* One row that scrolls sideways on narrow screens, so the slide keeps its space. */
.toolbar {
    position: relative;
    z-index: 50;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    min-height: 44px;
    padding: 4px 6px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}
.toolbar.hidden-bar { display: none; }

.tool-group {
    position: relative;
    display: flex;
    flex-shrink: 0;
    align-items: center;
    gap: 1px;
    padding: 0 5px;
    border-right: 1px solid var(--surface-3);
}
.tool-group:last-child { border-right: 0; }
.tool-group-end { margin-left: auto; }

.tool-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: transparent;
    color: var(--ink-2);
    font-size: 14px;
    transition: background-color 0.1s, border-color 0.1s, color 0.1s;
}
.tool-btn:hover { background: var(--surface-2); border-color: var(--line); color: var(--ink); }
.tool-btn.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.tone-red { color: var(--red); }
.tone-amber { color: var(--amber); }
.tone-purple { color: var(--purple); }
/* An on/off switch rather than a tool: coloured with a dot while on, so it
   never reads as a second selected tool next to the pen. */
.tool-toggle { position: relative; opacity: .55; }
.tool-toggle.is-on { opacity: 1; color: var(--purple); }
.tool-toggle.is-on::after { content: ''; position: absolute; right: 4px; bottom: 4px; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.tone-blue { color: var(--blue); }
.tone-indigo { color: var(--accent); }

.tool-divider { width: 1px; height: 22px; margin: 0 6px; background: var(--line); }

.slide-indicator, .zoom-display {
    min-width: 52px;
    text-align: center;
    font: 600 12px/1 var(--font-mono);
    font-variant-numeric: tabular-nums;
    color: var(--ink-2);
}
.zoom-display { min-width: 42px; font-size: 11px; }

.color-swatch {
    width: 26px;
    height: 26px;
    margin: 0 2px;
    border: 2px solid var(--line-2);
    border-radius: var(--radius);
    background: #000;
    box-shadow: inset 0 0 0 2px #fff;
}

.thickness { display: flex; flex-direction: column; gap: 1px; width: 104px; }
.thickness-label { font-size: 10px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-3); }
.thickness input { width: 100%; height: 16px; margin: 0; accent-color: var(--accent); }

.rec-group { gap: 4px; }
.rec-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line-2); }
.rec-active .rec-dot { background: var(--red); animation: pulse 1.4s ease-in-out infinite; }

.show-toolbar {
    position: fixed;
    top: 10px;
    right: 10px;
    z-index: 60;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 50%;
    background: var(--surface);
    color: var(--ink-2);
    box-shadow: var(--shadow-pop);
}

/* ---------------------------------------------------------------- Palette */
.palette-anchor { position: relative; }
.palette-popover {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    z-index: 100;
    width: 148px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    box-shadow: var(--shadow-pop);
}
.palette-popover-up { left: -52px; }
/* The toolbar scrolls, which would clip an absolutely positioned popover. */
#palette { position: fixed; top: 52px; left: 8px; }
.palette-label {
    margin: 0 0 4px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-3);
}
.palette-label:not(:first-child) { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--surface-3); }
.palette-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.p-color {
    width: 26px;
    height: 26px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 5px;
}
.p-color:hover { transform: scale(1.08); }
.palette-empty { grid-column: 1 / -1; margin: 2px 0; font-size: 11px; font-style: italic; color: var(--ink-3); }
.palette-custom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 10px;
    font-size: 12px;
    color: var(--ink-2);
}
.palette-custom input { width: 44px; height: 26px; padding: 0; border: 1px solid var(--line); border-radius: 5px; background: none; }

/* ---------------------------------------------------------------- Stage */
.stage-wrap {
    position: relative;
    flex: 1;
    display: flex;
    min-height: 0;
    padding: 20px;
    overflow: auto;
    background: var(--stage);
    overscroll-behavior: contain;
}
.stage-wrap.is-immersive { padding: 0; }
.stage-wrap.is-drop-target { box-shadow: inset 0 0 0 3px var(--accent); }

.slide-stage { position: relative; flex-shrink: 0; margin: auto; }

.slide-viewport {
    position: absolute;
    top: 0;
    left: 0;
    width: 1280px;
    height: 720px;
    background: #fff;
    transform-origin: 0 0;
    box-shadow: 0 4px 28px rgba(0, 0, 0, 0.45);
}
.slide-background { position: absolute; inset: 0; z-index: 1; overflow: hidden; background: #fff; }
.slide-background iframe { display: block; width: 100%; height: 100%; border: 0; pointer-events: none; background: #fff; }
.slide-image, .slide-pdf-canvas { display: block; width: 100%; height: auto; }
.slide-pdf { width: 100%; min-height: 100%; background: #f3f4f6; }
.slide-pdf.is-loading {
    background: linear-gradient(100deg, #f3f4f6 30%, #e8eaef 50%, #f3f4f6 70%) 0 0 / 300% 100%;
    animation: shimmer 1.4s linear infinite;
}
.slide-error { display: flex; align-items: center; justify-content: center; color: var(--ink-3); font-size: 18px; }
.smart-dark-mode { filter: invert(1) hue-rotate(180deg); }

#drawing-canvas {
    position: absolute;
    inset: 0;
    z-index: 10;
    width: 100%;
    height: 100%;
    touch-action: none;
}

.text-editor {
    position: absolute;
    z-index: 100;
    min-width: 30px;
    min-height: 30px;
    margin: 0;
    padding: 2px;
    border: 1px dashed var(--accent);
    background: transparent;
    color: #000;
    font: 16px/1.2 Arial, Helvetica, sans-serif;
    white-space: pre-wrap;
    overflow-wrap: break-word;
    overflow: hidden;
    outline: none;
    transform-origin: center;
    cursor: text;
}
.text-editor:empty::before { content: attr(data-placeholder); color: #9ca3af; pointer-events: none; }

.cursor-visual {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 9999;
    pointer-events: none;
    will-change: transform;
}

/* ---------------------------------------------------------------- Text toolbar */
.text-toolbar {
    position: fixed;
    z-index: 9998;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 5px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow-pop);
}
.tt-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: var(--surface-2);
    color: var(--ink-2);
}
.tt-btn:hover { background: var(--surface-3); }
.tt-btn.active { background: var(--accent-soft); border-color: #c7cbfb; color: var(--accent); }
.tt-divider { width: 1px; height: 18px; margin: 0 2px; background: var(--line); }
.tt-color { position: relative; }
.tt-swatch { width: 16px; height: 16px; border: 1px solid var(--line-2); border-radius: 3px; background: #000; }
.tt-select { height: 30px; padding: 0 6px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface); font-size: 12px; }
.tt-select-wide { width: 124px; }

/* ---------------------------------------------------------------- Buttons & fields */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 36px;
    padding: 0 16px;
    border: 1px solid transparent;
    border-radius: 8px;
    font-weight: 600;
    white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-2); }
.btn-primary:disabled { background: #a5a8e6; }
.btn-quiet { background: transparent; color: var(--ink-2); }
.btn-quiet:hover { background: var(--surface-2); color: var(--ink); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-danger-quiet { background: transparent; color: var(--red); }
.btn-danger-quiet:hover { background: var(--red-soft); }
.btn-block { width: 100%; }
.btn-small { min-height: 28px; padding: 0 10px; font-size: 12px; }

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--ink-3);
    font-size: 16px;
}
.icon-btn:hover { background: var(--surface-3); color: var(--ink); }

.link-btn {
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 0;
    border: 0;
    background: none;
    color: var(--accent);
    font-size: 12px;
    font-weight: 700;
}
.link-btn:hover { color: var(--accent-2); }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field-label { font-size: 12px; font-weight: 700; color: var(--ink-2); }
.field input, .eqn-line input[type="text"] {
    width: 100%;
    height: 36px;
    padding: 0 10px;
    border: 1px solid var(--line-2);
    border-radius: 6px;
    background: var(--surface);
}
.field input:focus, .eqn-line input[type="text"]:focus { border-color: var(--accent); outline: 2px solid var(--accent-soft); outline-offset: 0; }
input.is-invalid { border-color: var(--red) !important; background: var(--red-soft); }
.field-error { min-height: 0; margin: 2px 0 0; font-size: 12px; color: var(--red); }
.field-error:empty { display: none; }
.form-status { margin: 4px 0 0; min-height: 18px; font-size: 13px; font-weight: 600; color: var(--red); }
.hint { margin: 0; font-size: 12px; line-height: 1.55; color: var(--ink-3); }
.hint code { padding: 0 3px; border-radius: 3px; background: var(--surface-2); color: var(--ink-2); }
.section-label {
    margin: 4px 0 6px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-3);
}
.muted-note { margin: 4px; font-size: 12px; font-style: italic; color: var(--ink-3); }
.note { margin: 10px 0 0; padding: 8px 10px; border-radius: 6px; background: #fff7e8; color: #8a4b05; font-size: 12px; }

.switch { width: 38px; height: 22px; accent-color: var(--green); }

/* ---------------------------------------------------------------- Modals */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(12, 14, 22, 0.58);
}
.modal {
    display: flex;
    flex-direction: column;
    width: min(520px, 100%);
    max-height: calc(100vh - 32px);
    overflow: hidden;
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
    animation: modal-in 0.16s ease-out;
}
.modal-narrow { width: min(400px, 100%); }
.modal-wide { width: min(780px, 100%); }
.modal-full { width: 92vw; height: 90vh; max-height: 90vh; }
.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px 14px 22px;
    border-bottom: 1px solid var(--surface-3);
}
.modal-title { display: flex; align-items: center; gap: 10px; margin: 0; font-size: 18px; font-weight: 700; text-wrap: balance; }
.modal-body { display: flex; flex-direction: column; gap: 10px; padding: 20px 22px; overflow-y: auto; }
.modal-text { margin: 0; color: var(--ink-2); }
.modal-meta { margin: 0; font-size: 13px; font-weight: 600; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.modal-foot {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--surface-3);
    background: var(--surface-2);
}

.choice-list { display: flex; flex-direction: column; gap: 10px; }
.choice {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    text-align: left;
}
.choice:hover { border-color: var(--accent); background: var(--accent-soft); }
.choice-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 17px;
}
.choice-title { display: block; font-weight: 700; }
.choice-note { display: block; font-size: 12px; color: var(--ink-3); }
.choice-danger:hover { border-color: var(--red); background: var(--red-soft); }
.choice-danger .choice-icon { background: var(--red-soft); color: var(--red); }

.card-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.select-card {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 14px;
    border: 2px solid var(--line);
    border-radius: 10px;
    cursor: pointer;
    user-select: none;
}
.select-card:hover { border-color: var(--line-2); background: var(--surface-2); }
.select-card.selected { border-color: var(--accent); background: var(--accent-soft); }
.select-card-icon { margin-bottom: 6px; font-size: 22px; color: var(--ink-3); }
.select-card.selected .select-card-icon { color: var(--accent); }
.select-card-title { font-weight: 700; }
.select-card-note { font-size: 12px; color: var(--ink-3); }
.cam-options { display: flex; flex-direction: column; gap: 12px; padding: 14px; border-radius: 10px; background: var(--surface-2); }
.option-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 13px; }
.segmented { display: inline-flex; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.segmented button { padding: 4px 12px; border: 0; border-radius: 6px; background: transparent; color: var(--ink-3); font-size: 12px; font-weight: 700; }
.segmented button.is-selected { background: var(--surface-3); color: var(--ink); }

.shape-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.shape-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px 6px 10px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
}
.shape-btn:hover { border-color: #38bdf8; background: #f0f9ff; }
.shape-btn i { font-size: 22px; color: var(--ink-2); }
.shape-btn span { font-size: 12px; font-weight: 600; color: var(--ink-2); }
.shape-btn kbd { padding: 0 5px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface-2); color: var(--ink-3); font-size: 10px; }

/* Graph dialog */
.graph-layout { display: grid; grid-template-columns: 210px 1fr; gap: 22px; }
.graph-presets-col { padding-right: 18px; border-right: 1px solid var(--surface-3); }
.graph-main-col { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.preset-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.func-btn {
    padding: 4px 8px;
    border: 1px solid #dbe4ff;
    border-radius: 5px;
    background: #f2f6ff;
    color: #1d4ed8;
    font: 12px var(--font-mono);
}
.func-btn:hover { background: #dbe7ff; }
.equation-list { display: flex; flex-direction: column; gap: 8px; max-height: 190px; overflow-y: auto; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); }
.eqn-line { display: flex; align-items: center; gap: 6px; }
.eqn-line input[type="text"] { flex: 1; font-family: var(--font-mono); }
.eqn-line input[type="color"] { flex-shrink: 0; width: 34px; height: 34px; padding: 0; border: 1px solid var(--line-2); border-radius: 6px; background: none; }
.eqn-remove { flex-shrink: 0; width: 34px; height: 34px; border: 1px solid #fbd5d5; border-radius: 6px; background: var(--red-soft); color: var(--red); }
.graph-history { display: flex; flex-direction: column; max-height: 90px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); }
.history-item { padding: 5px 8px; border: 0; border-bottom: 1px solid var(--surface-3); background: none; text-align: left; font: 12px var(--font-mono); color: var(--ink-2); }
.history-item:hover { background: var(--surface); color: var(--blue); }

/* Slide gallery */
.sorter-grid {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(auto-fill, 262px);
    justify-content: center;
    align-content: start;
    gap: 24px;
    padding: 24px;
    overflow-y: auto;
    background: var(--surface-2);
}
.thumb-card {
    position: relative;
    width: 262px;
    height: 150px;
    padding: 0;
    overflow: hidden;
    border: 3px solid transparent;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 2px 6px rgba(15, 18, 30, 0.12);
}
.thumb-card:hover { border-color: var(--line-2); transform: translateY(-2px); }
.thumb-card.is-active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.thumb-view { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.thumb-scaler { position: absolute; top: 0; left: 0; width: 1280px; background: #fff; transform: scale(0.2); transform-origin: 0 0; }
.thumb-scaler iframe { display: block; width: 1280px; height: 100%; border: 0; }
.thumb-scaler > img, .thumb-scaler > canvas { position: absolute; top: 0; left: 0; width: 100%; height: auto; }
.thumb-num {
    position: absolute;
    right: 6px;
    bottom: 6px;
    padding: 1px 7px;
    border-radius: 4px;
    background: rgba(31, 35, 48, 0.85);
    color: #fff;
    font: 600 11px/1.6 var(--font-mono);
}

/* ---------------------------------------------------------------- Live session */
.live-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #ef4444; animation: pulse 1.6s ease-in-out infinite; }
.live-pill {
    position: fixed;
    top: 14px;
    left: 50%;
    z-index: 9000;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border: 0;
    border-radius: 999px;
    background: rgba(20, 21, 28, 0.86);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.04em;
    transform: translateX(-50%);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}
.student-pill {
    position: fixed;
    top: 14px;
    left: 14px;
    z-index: 9000;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    max-width: calc(100vw - 28px);
    padding: 7px 14px;
    border-radius: 8px;
    background: rgba(21, 128, 61, 0.92);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}
.student-pill[data-state="warn"] { background: rgba(180, 83, 9, 0.94); }
.student-pill[data-state="error"] { background: rgba(185, 28, 28, 0.94); }

.audio-dock {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: var(--shadow-pop);
}
.audio-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 50%;
    background: var(--surface-3);
    color: var(--ink);
    font-size: 16px;
}
.audio-btn.is-off { background: var(--red-soft); color: var(--red); }
.audio-status { min-width: 70px; padding-right: 4px; font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-3); }
.audio-connect {
    position: fixed;
    top: 64px;
    left: 50%;
    z-index: 9500;
    padding: 12px 22px;
    border: 0;
    border-radius: 999px;
    background: var(--accent);
    color: #fff;
    font-weight: 700;
    transform: translateX(-50%);
    box-shadow: 0 6px 20px rgba(79, 70, 229, 0.45);
}

.link-box { display: flex; align-items: center; gap: 10px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); }
.link-text { flex: 1; min-width: 0; overflow-wrap: anywhere; font-size: 12px; color: var(--accent-2); user-select: all; }
.participants { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; list-style: none; }
.participant {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    background: var(--surface-2);
}
.participant.is-writer { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.participant-info { display: flex; flex-direction: column; min-width: 0; }
.participant-name { overflow: hidden; font-size: 13px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.participant-meta { font-size: 11px; color: var(--ink-3); }
.participant-actions { display: flex; flex-shrink: 0; gap: 4px; }
.participant-empty { font-size: 13px; color: var(--ink-3); }
.btn-outline { background: var(--surface); border-color: var(--accent); color: var(--accent); }
.btn-outline:hover { background: var(--accent-soft); }
.btn-quiet.is-danger { color: var(--red); }
.live-writers { color: #c7d2fe; }

/* Student writing on the board */
body.student-mode.can-write #drawing-canvas { pointer-events: auto; }
body.student-mode.can-write .cursor-visual:not([hidden]) { display: block !important; }
.guest-toolbar {
    position: fixed;
    left: 50%;
    bottom: 20px;
    z-index: 1100;
    display: flex;
    align-items: center;
    max-width: calc(100vw - 24px);
    padding: 8px;
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: var(--shadow-pop);
    transform: translateX(-50%);
}
.guest-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0 10px 0 6px;
    color: var(--accent);
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}
.guest-toolbar.is-collapsed > :not(#guest-tools-toggle) { display: none; }
.guest-toolbar.is-collapsed { padding: 4px; }
#guest-tools-toggle { flex-shrink: 0; }
.guest-group { display: flex; flex-shrink: 0; align-items: center; gap: 4px; padding: 0 8px; border-left: 1px solid var(--surface-3); }
.guest-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 12px;
    background: var(--surface-2);
    color: var(--ink-2);
    font-size: 16px;
}
.guest-btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.guest-swatch { width: 32px; height: 32px; padding: 0; border: 3px solid #fff; border-radius: 50%; box-shadow: 0 0 0 1px var(--line-2); }
.guest-swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--accent); }
.guest-size {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 10px;
    background: transparent;
}
.guest-size[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }
.guest-dot { display: block; border-radius: 50%; background: var(--ink); }
body.can-write #toast-region { bottom: 96px; } /* keep messages clear of the writing tools */
@media (max-width: 1100px) {
    .guest-toolbar { bottom: 86px; }   /* above the audio controls */
    body.can-write #toast-region { bottom: 162px; }
}
@media (max-width: 640px) {
    .guest-badge { display: none; }
}

.join-name { width: 100%; text-align: left; }
.field-optional { font-weight: 400; color: var(--ink-3); }

.join-overlay { z-index: 10000; background: rgba(12, 14, 22, 0.82); }
.join-card .modal-body { align-items: center; gap: 12px; padding: 28px 24px 24px; text-align: center; }
.join-status { margin: 0; font-size: 11px; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; color: var(--accent); }

.fab {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 5000;
    width: 48px;
    height: 48px;
    border: 0;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
}

/* Webcam overlay while recording */
#webcam-preview-container {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 9000;
    width: 200px;
    height: 150px;
    overflow: hidden;
    border: 3px solid #fff;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    cursor: move;
    touch-action: none;
}
#webcam-preview-container.circle { width: 180px; height: 180px; border-radius: 50%; }
#webcam-preview-container.rect { border-radius: 8px; }
#webcam-video, .webcam-chroma { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); background: #333; }

/* ---------------------------------------------------------------- Loading & toasts */
.loading-screen {
    position: fixed;
    inset: 0;
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(245, 246, 249, 0.82);
    backdrop-filter: blur(2px);
}
.loading-card { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.loading-card p { margin: 0; font-size: 16px; font-weight: 700; color: var(--ink-2); }
.spinner {
    display: inline-block;
    width: 32px;
    height: 32px;
    border: 3px solid var(--accent-soft);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

#toast-region {
    position: fixed;
    bottom: 24px;
    left: 50%;
    z-index: 10001;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: min(520px, calc(100vw - 32px));
    transform: translateX(-50%);
    pointer-events: none;
}
.toast {
    max-width: 100%;
    padding: 10px 16px;
    border-radius: 8px;
    background: rgba(24, 26, 34, 0.94);
    color: #fff;
    font-size: 13px;
    font-weight: 500;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.2s, transform 0.2s;
}
.toast.is-visible { opacity: 1; transform: none; }
.toast-error { background: rgba(153, 27, 27, 0.96); }

/* ---------------------------------------------------------------- Modes */
body.broadcast-mode .stage-wrap { background: var(--stage-deep); }
body.broadcast-mode .slide-viewport { box-shadow: none; }

body.student-mode { background: #000; }
body.student-mode .toolbar,
body.student-mode .show-toolbar,
body.student-mode .text-toolbar,
body.student-mode .cursor-visual { display: none !important; }
body.student-mode .stage-wrap { background: #000; }
body.student-mode #drawing-canvas { pointer-events: none; }

/* ---------------------------------------------------------------- Small screens */
@media (max-width: 720px) {
    .graph-layout { grid-template-columns: 1fr; }
    .graph-presets-col { padding: 0 0 12px; border-right: 0; border-bottom: 1px solid var(--surface-3); }
    .shape-grid { grid-template-columns: repeat(3, 1fr); }
    .card-grid, .field-row { grid-template-columns: 1fr; }
    .tool-group-end { margin-left: 0; }
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Small-group teaching: readable work cards, private feedback, persistent call access. */
.classroom-dock { position: fixed; left: 16px; bottom: 16px; z-index: 2100; display: flex; gap: 8px; }
.classroom-dock .btn { min-height: 42px; box-shadow: 0 3px 16px #0002; }
.classroom-modal { width: min(1180px, calc(100vw - 32px)); max-width: 1180px; max-height: calc(100dvh - 112px); }
.classroom-body { overflow-y: auto; overscroll-behavior: contain; padding: 20px; }
.classroom-modal .modal-head { flex-shrink: 0; }
.classroom-modal .hint { margin: 4px 0; }
.class-actions, .class-activity-heading, .board-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 10px 0; }
.class-actions h3 { margin: 0; margin-right: auto; }
.classroom-modal button, .board-tools input[type=color] { min-height: 40px; }
.classroom-modal textarea, .classroom-modal input:not([type=checkbox]):not([type=color]), .classroom-modal select { border: 1px solid #cbd5e1; border-radius: 7px; padding: 9px 11px; background: white; max-width: 100%; }
.classroom-modal textarea { resize: vertical; width: 100%; }
.classroom-modal details { border: 1px solid #e2e8f0; padding: 12px; border-radius: 9px; margin: 12px 0; }
.classroom-modal summary { font-weight: 600; cursor: pointer; padding: 4px; }
.activity-form { display: grid; gap: 12px; padding: 12px 4px 4px; }
.class-checkbox { display: flex; align-items: center; gap: 8px; }
.class-prompt { white-space: pre-wrap; font-size: 17px; line-height: 1.55; font-weight: 600; background: #eff6ff; border-left: 3px solid #2563eb; border-radius: 5px; padding: 14px 16px; }
.class-timer { background: #f1f5f9; color: #334155; font-variant-numeric: tabular-nums; border-radius: 20px; padding: 5px 12px; }
.class-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(245px, 1fr)); gap: 14px; }
.student-card { text-align: left; border: 1px solid #cbd5e1; background: #fff; border-radius: 12px; overflow: hidden; padding: 0; box-shadow: 0 2px 5px #0f172a08; }
.student-card:hover, .student-card:focus-visible { border-color: #2563eb; }
.student-card.needs-help { border: 2px solid #d97706; }
.student-card-head { display: flex; justify-content: space-between; gap: 8px; padding: 12px; }
.student-state { font-size: 12px; color: #475569; background: #f1f5f9; border-radius: 20px; padding: 3px 8px; white-space: nowrap; }
.needs-help .student-state { background: #fef3c7; color: #92400e; }
.student-card canvas { display: block; width: 100%; height: auto; border-top: 1px solid #f1f5f9; border-bottom: 1px solid #f1f5f9; }
.student-card-note, .student-card-foot { display: block; padding: 7px 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.student-card-foot { font-size: 12px; color: #64748b; padding-top: 0; }
.student-detail { border: 1px solid #cbd5e1; border-radius: 12px; background: #f8fafc; padding: 18px; margin-top: 20px; }
.student-thinking { white-space: pre-wrap; padding: 12px; background: white; border-radius: 6px; }
.private-canvas { display: block; width: 100%; height: auto; aspect-ratio: 16 / 9; background: white; border: 1px solid #cbd5e1; border-radius: 6px; touch-action: none; cursor: crosshair; }
.board-tools button { background: white; border: 1px solid #cbd5e1; border-radius: 6px; padding: 6px 12px; }
.board-tools button[aria-pressed=true], #work-choices button[aria-pressed=true], #work-status-buttons button[aria-pressed=true] { box-shadow: inset 0 0 0 2px #2563eb; background: #eff6ff; color: #1e40af; }
.board-tools input[type=color] { padding: 2px; width: 42px; border: 1px solid #cbd5e1; border-radius: 6px; }
.work-feedback { padding: 14px; margin-top: 16px; border-radius: 8px; background: #f1f5f9; color: #475569; white-space: pre-wrap; }
.work-feedback.has-feedback { background: #fff7ed; color: #9a3412; border-left: 3px solid #ea580c; }
.class-empty { text-align: center; padding: 35px; color: #64748b; }
.call-panel { position: fixed; right: 16px; bottom: 76px; width: min(380px, calc(100vw - 32px)); max-height: 68dvh; overflow: auto; z-index: 2200; background: #fff; border: 1px solid #cbd5e1; border-radius: 12px; padding: 14px; box-shadow: 0 10px 35px #0004; }
.call-heading { display: flex; align-items: center; justify-content: space-between; }
.camera-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.camera-tile { margin: 0; background: #0f172a; color: white; border-radius: 8px; overflow: hidden; }
.camera-tile video { width: 100%; aspect-ratio: 16/9; display: block; object-fit: contain; }
.camera-tile figcaption { padding: 4px 8px; font-size: 12px; }
.teacher-video-bubble { position: fixed; top: 142px; right: 18px; width: 136px; height: 136px; z-index: 1150; }
.teacher-video-bubble.on-left { right: auto; left: 18px; }
.teacher-video-bubble video { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; background: #0f172a; border: 3px solid #fff; box-shadow: 0 3px 14px #0004; }
.bubble-controls { position: absolute; bottom: -12px; left: 50%; transform: translateX(-50%); display: flex; gap: 4px; }
.bubble-controls button { width: 36px; height: 36px; border-radius: 50%; border: 1px solid #cbd5e1; background: #fff; color: #111827; font-size: 22px; }
.teacher-video-restore { position: fixed; right: 12px; top: 142px; z-index: 1150; }
#shared-screen-video { display: block; width: 100%; max-height: 70dvh; object-fit: contain; background: #0f172a; }
#student-cameras-modal .camera-grid { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
@media (max-width: 640px), (max-height: 540px) {
    .teacher-video-bubble { top: 90px; width: 96px; height: 96px; right: 12px; }
    .teacher-video-restore { top: 90px; font-size: 12px; }
    .classroom-dock { max-width: calc(100vw - 24px); flex-wrap: wrap; gap: 4px; }
    .classroom-dock .btn { padding: 8px; font-size: 12px; }
}
.save-status { white-space: nowrap; font-size: 11px; padding: 0 10px; color: #64748b; }
.save-status.save-error { color: #b91c1c; font-weight: 600; }
.library-row { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid #e2e8f0; padding: 12px 0; }
.library-row > div { flex: 1; min-width: 0; overflow-wrap: anywhere; }
#library-save { margin-top: 12px; }
.audio-dock { z-index: 2201; }
@media (max-width: 720px) {
    .classroom-modal { width: calc(100vw - 12px); max-height: calc(100dvh - 130px); }
    .classroom-body { padding: 12px; }
    .class-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
    .student-card-head { flex-direction: column; padding: 8px; }
    .classroom-dock { bottom: 12px; left: 8px; }
    .classroom-dock .btn { padding: 8px; }
    .audio-dock .audio-status { display: none; }
    .audio-dock { right: 8px; bottom: 12px; gap: 4px; padding: 4px; }
    .classroom-dock { max-width: calc(100vw - 116px); flex-wrap: wrap; }
    .student-detail { padding: 8px; }
}
@keyframes pulse { 50% { opacity: 0.45; } }
@keyframes shimmer { to { background-position: -300% 0; } }
@keyframes modal-in { from { opacity: 0; transform: scale(0.97); } }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Device check (P07) sits above the student join screen. */
#device-check-modal { z-index: 10001; }
.device-check select { width: 100%; }
.device-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.device-row meter { flex: 1; min-width: 140px; height: 18px; }
.device-preview { display: block; width: 100%; max-height: 240px; margin: 10px 0; background: #111; border-radius: 8px; object-fit: contain; }
.device-error { color: #a52536; }
#btn-join-device-check { margin-top: 10px; }

.connection-quality { margin-left: 8px; padding: 1px 8px; border-radius: 10px; font-size: 12px; background: rgba(255,255,255,.18); }
.connection-quality[data-level="fair"] { background: #8a6d1a; }
.connection-quality[data-level="poor"] { background: #9b2c2c; }
