/*
 * Teaching Pace — one hand-written stylesheet, no framework.
 *
 * Dark by default: the instructor view spends its life on a projector next to slides, and a white
 * page is a lamp pointed at the room. Every state is carried by text as well as colour, because a
 * projector washes out hue long before it washes out words.
 */

:root {
    --bg: #0b1220;
    --bg-raised: #141d31;
    --bg-sunken: #080e19;
    --border: #253149;
    --text: #eef2f9;
    --text-muted: #9aa7bf;

    --slow: #4b9cf5;
    --ok: #37c98b;
    --fast: #f7a23b;
    --danger: #f4635f;

    --radius: 14px;
    --radius-sm: 9px;
    --shadow: 0 18px 40px rgb(0 0 0 / 45%);

    --font: 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    min-height: 100%;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
}

.page {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

.body-centred .page { justify-content: center; }

a { color: var(--slow); }

/* ---------- Shared bits ---------- */

.btn {
    appearance: none;
    border: 1px solid var(--border);
    background: var(--bg-raised);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    padding: 0.7rem 1.1rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background-color 120ms ease, border-color 120ms ease, transform 60ms ease;
}

.btn:hover { border-color: #35476a; background: #1b2740; }
.btn:active { transform: translateY(1px); }

.btn:focus-visible {
    outline: 3px solid var(--slow);
    outline-offset: 2px;
}

.btn--primary { background: var(--ok); border-color: var(--ok); color: #04231a; }
.btn--primary:hover { background: #2fb87d; border-color: #2fb87d; }

.btn--danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn--danger:hover { background: rgb(244 99 95 / 14%); border-color: var(--danger); }

.btn--ghost { background: transparent; }
.btn--small { padding: 0.35rem 0.7rem; font-size: 0.85rem; }

.stack { display: flex; flex-direction: column; gap: 0.9rem; }

/* Off-screen but still announced: lets the strip show "3 · 8 · 1" while a screen reader hears
 * "3 too slow, 8 just right, 1 too fast". */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field--disabled { opacity: 0.45; }

.field__label { font-size: 0.85rem; font-weight: 600; color: var(--text-muted); }
.field__hint { font-weight: 400; color: var(--text-muted); font-size: 0.8rem; display: block; }

.field__input {
    font: inherit;
    color: var(--text);
    background: var(--bg-sunken);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.65rem 0.75rem;
    width: 100%;
}

.field__input:focus-visible { outline: 3px solid var(--slow); outline-offset: 1px; }

.field__input--code {
    text-transform: uppercase;
    letter-spacing: 0.4em;
    font-size: 1.4rem;
    text-align: center;
    font-weight: 700;
}

.field__range { width: 100%; accent-color: var(--slow); }

.checkbox { display: flex; gap: 0.6rem; align-items: flex-start; font-size: 0.9rem; }
.checkbox input { margin-top: 0.3rem; accent-color: var(--ok); flex: none; }

.alert { border-radius: var(--radius-sm); padding: 0.6rem 0.8rem; margin: 0; font-size: 0.9rem; }
.alert--error { background: rgb(244 99 95 / 14%); border: 1px solid var(--danger); color: #ffd9d8; }

.pill {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.15rem 0.6rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    color: var(--text-muted);
}

.pill[data-state="connected"] { color: var(--ok); border-color: rgb(55 201 139 / 45%); }
.pill[data-state="reconnecting"] { color: var(--fast); border-color: rgb(247 162 59 / 45%); }
.pill[data-state="closed"] { color: var(--danger); border-color: rgb(244 99 95 / 45%); }

.code-inline {
    font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace;
    letter-spacing: 0.16em;
    background: var(--bg-sunken);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.05em 0.4em;
}

.code-inline--large { font-size: 1.5rem; letter-spacing: 0.22em; }

.card {
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.4rem;
}

.card--narrow { max-width: 34rem; margin: 0 auto; }
.card__title { margin: 0 0 0.5rem; font-size: 1.1rem; }
.card__body { margin: 0 0 1rem; color: var(--text-muted); font-size: 0.92rem; }
.card__body--muted { margin-top: 1rem; margin-bottom: 0; font-size: 0.85rem; }

/* ---------- Landing ---------- */

.landing { width: min(58rem, 100%); margin: 0 auto; padding: 2rem 1.25rem 3rem; }
.landing__header { text-align: center; margin-bottom: 2rem; }
.landing__eyebrow { margin: 0; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.24em; font-size: 0.75rem; }
.landing__title { margin: 0.2rem 0 0.6rem; font-size: clamp(2.2rem, 7vw, 3.4rem); letter-spacing: -0.02em; }
.landing__lede { margin: 0 auto; max-width: 34rem; color: var(--text-muted); }
.landing__cards { display: grid; gap: 1.25rem; grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr)); }

/* ---------- Gauge ---------- */

.gauge { display: flex; flex-direction: column; align-items: center; gap: 0.6rem; width: 100%; }

.gauge__dial { width: 100%; max-width: 30rem; height: auto; display: block; }

.gauge__band { opacity: 0.22; transition: opacity 200ms ease; }
.gauge__band--slow { fill: var(--slow); }
.gauge__band--ok { fill: var(--ok); }
.gauge__band--fast { fill: var(--fast); }

/* The live band lights up, so the reading survives a washed-out projector. */
.gauge[data-label="too-slow"] .gauge__band--slow,
.gauge[data-label="just-right"] .gauge__band--ok,
.gauge[data-label="too-fast"] .gauge__band--fast { opacity: 1; }

.gauge__needle { fill: var(--text); transition: transform 500ms cubic-bezier(0.22, 1, 0.36, 1); }
.gauge__hub { fill: var(--text); }

.gauge__readout { text-align: center; }

.gauge__label {
    margin: 0;
    font-size: clamp(1.6rem, 5vw, 2.6rem);
    font-weight: 700;
    letter-spacing: -0.01em;
    line-height: 1.1;
}

.gauge[data-label="too-slow"] .gauge__label { color: var(--slow); }
.gauge[data-label="just-right"] .gauge__label { color: var(--ok); }
.gauge[data-label="too-fast"] .gauge__label { color: var(--fast); }
.gauge[data-label="no-data"] .gauge__label { color: var(--text-muted); }

.gauge__meta { margin: 0.25rem 0 0; color: var(--text-muted); font-size: 0.95rem; }

.gauge__bar {
    display: flex;
    width: 100%;
    max-width: 30rem;
    height: 0.7rem;
    border-radius: 999px;
    overflow: hidden;
    background: var(--bg-sunken);
    border: 1px solid var(--border);
}

.gauge__seg { flex-grow: 0; flex-basis: 0; transition: flex-grow 400ms ease; }
.gauge__seg--slow { background: var(--slow); }
.gauge__seg--ok { background: var(--ok); }
.gauge__seg--fast { background: var(--fast); }

.gauge__counts {
    display: flex;
    gap: 1.5rem;
    list-style: none;
    margin: 0;
    padding: 0;
    justify-content: center;
    text-align: center;
}

.count { display: flex; flex-direction: column; }
.count__value { font-size: clamp(1.3rem, 3.5vw, 2rem); font-weight: 700; line-height: 1; }
.count__label { font-size: 0.78rem; color: var(--text-muted); }
.count--slow .count__value { color: var(--slow); }
.count--ok .count__value { color: var(--ok); }
.count--fast .count__value { color: var(--fast); }

/* ---------- Instructor ---------- */

.instructor { width: min(78rem, 100%); margin: 0 auto; padding: 1.5rem 1.25rem 2.5rem; flex: 1; }

.instructor__header {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.instructor__title { margin: 0; font-size: 1.6rem; }
.instructor__sub { margin: 0.35rem 0 0; }
.instructor__actions { display: flex; flex-wrap: wrap; gap: 0.6rem; }

.instructor__body { display: grid; gap: 1.5rem; grid-template-columns: minmax(0, 1.6fr) minmax(18rem, 1fr); align-items: start; }

@media (max-width: 62rem) {
    .instructor__body { grid-template-columns: 1fr; }
}

.display {
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

/*
 * Fullscreen. The whole view goes fullscreen rather than just the dial, so Reset and Exit stay
 * clickable — an instructor who has to hunt for the Escape key mid-lecture will simply not use it.
 * `.is-fullscreen` is the fallback for browsers that refuse the Fullscreen API.
 */
.instructor:fullscreen,
.instructor.is-fullscreen {
    background: var(--bg);
    width: 100%;
    max-width: none;
    display: flex;
    flex-direction: column;
    padding: 1.25rem 2vw 2vh;
}

.instructor:fullscreen .sidebar,
.instructor.is-fullscreen .sidebar { display: none; }

.instructor:fullscreen .instructor__header,
.instructor.is-fullscreen .instructor__header { margin-bottom: 0.75rem; align-items: center; }

.instructor:fullscreen .instructor__title,
.instructor.is-fullscreen .instructor__title { font-size: 1.15rem; font-weight: 600; color: var(--text-muted); }

.instructor:fullscreen .instructor__body,
.instructor.is-fullscreen .instructor__body { grid-template-columns: 1fr; flex: 1; min-height: 0; }

.instructor:fullscreen .display,
.instructor.is-fullscreen .display {
    height: 100%;
    justify-content: center;
    border: 0;
    background: transparent;
    gap: 1.5vh;
}

.instructor:fullscreen .gauge__dial,
.instructor.is-fullscreen .gauge__dial { max-width: min(64vw, 78vh); }

.instructor:fullscreen .gauge__label,
.instructor.is-fullscreen .gauge__label { font-size: clamp(3rem, 8vw, 7rem); }

.instructor:fullscreen .gauge__meta,
.instructor.is-fullscreen .gauge__meta { font-size: clamp(1.1rem, 2.2vw, 2rem); }

.instructor:fullscreen .gauge__bar,
.instructor.is-fullscreen .gauge__bar { max-width: 60vw; height: 1.1rem; }

.instructor:fullscreen .gauge__counts,
.instructor.is-fullscreen .gauge__counts { gap: clamp(2rem, 6vw, 6rem); }

.instructor:fullscreen .count__value,
.instructor.is-fullscreen .count__value { font-size: clamp(2rem, 4.5vw, 4rem); }

.instructor:fullscreen .count__label,
.instructor.is-fullscreen .count__label { font-size: clamp(0.9rem, 1.5vw, 1.3rem); }

.sidebar { display: flex; flex-direction: column; gap: 1.25rem; }

.card--join { text-align: center; }

.qr {
    width: min(100%, 15rem);
    height: auto;
    background: #fff;
    border-radius: var(--radius-sm);
    padding: 0.6rem;
    display: block;
    margin: 0 auto 0.9rem;
}

.join-url {
    font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace;
    font-size: 0.9rem;
    word-break: break-all;
    margin: 0 0 0.5rem;
    color: var(--text);
}

.join-code { margin: 0 0 0.9rem; color: var(--text-muted); font-size: 0.85rem; }

/* ---------- Compact pop-out ---------- */

.body-compact { background: var(--bg); }
.body-compact .page { min-height: 100vh; }

/*
 * Everything here is sized to fit inside the pop-out window instructor.js asks for, with room to
 * spare for browser chrome — a Reset button clipped off the bottom edge is worse than no button.
 */
.instructor--compact { padding: 0.4rem; width: 100%; display: flex; }
.instructor--compact .instructor__body { grid-template-columns: 1fr; gap: 0; flex: 1; }
.instructor--compact .display { padding: 0.3rem; border: 0; background: transparent; gap: 0.3rem; }
.instructor--compact .gauge { gap: 0.3rem; }
.instructor--compact .gauge__dial { max-width: 9.5rem; }
.instructor--compact .gauge__label { font-size: 1.35rem; }
.instructor--compact .gauge__meta { font-size: 0.75rem; }
.instructor--compact .gauge__bar { height: 0.45rem; max-width: 16rem; }
.instructor--compact .gauge__counts { gap: 1rem; }
.instructor--compact .count__value { font-size: 1rem; }
.instructor--compact .count__label { font-size: 0.65rem; }
.compact__reset { margin-top: 0.1rem; padding: 0.25rem 0.7rem; font-size: 0.78rem; }

.compact__controls { display: flex; align-items: center; gap: 0.4rem; flex: none; }

.variant { display: flex; gap: 0.15rem; }

.variant__btn {
    appearance: none;
    border: 1px solid var(--border);
    background: var(--bg-raised);
    color: var(--text-muted);
    font: inherit;
    font-size: 0.8rem;
    line-height: 1;
    padding: 0.3rem 0.5rem;
    border-radius: 6px;
    cursor: pointer;
}

.variant__btn:hover { color: var(--text); border-color: #35476a; }
.variant__btn:focus-visible { outline: 2px solid var(--slow); outline-offset: 1px; }

.variant__btn[aria-pressed="true"] {
    color: var(--text);
    border-color: var(--slow);
    background: color-mix(in srgb, var(--slow) 22%, var(--bg-raised));
}

/* ---------- Compact: bar strip variant ----------
 *
 * One wide row instead of the dial block, so the pop-out can sit along the top or bottom edge of a
 * screen without covering slides. Roughly a quarter the height of the dial layout.
 *
 * Scoped to [data-variant="bar"] so these beat the generic .instructor--compact sizing above,
 * which is tuned for the dial and would otherwise cap the bar's width.
 */

.instructor--compact[data-variant="bar"] { padding: 0.35rem 0.6rem; }

/* minmax(0, 1fr), not 1fr: a bare 1fr track has an automatic min-content floor, so the grid would
 * refuse to shrink below the strip's natural width and push the controls off the right edge. */
.instructor--compact[data-variant="bar"] .instructor__body { grid-template-columns: minmax(0, 1fr); }

.instructor--compact[data-variant="bar"] .display {
    flex-direction: row;
    align-items: center;
    gap: 0.75rem;
    padding: 0.2rem;
    min-width: 0;
}

/* width:auto overrides .gauge's width:100% — as a flex row item that 100% would overflow .display,
 * and the resulting shrink lands entirely on the label, ellipsising it even in a wide window. */
.strip {
    flex: 1 1 auto;
    width: auto;
    flex-direction: row;
    align-items: center;
    gap: 0.7rem;
    min-width: 0;
}

.strip__dot {
    width: 0.65rem;
    height: 0.65rem;
    border-radius: 50%;
    flex: none;
    background: var(--text-muted);
    transition: background-color 200ms ease;
}

/* Shrinkable with an ellipsis: the pop-out can be dragged narrow, and truncating the one piece of
 * prose beats forcing a horizontal scrollbar on everything else. */
.strip__label {
    font-size: 1.05rem;
    font-weight: 700;
    white-space: nowrap;
    flex: 0 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.strip[data-label="too-slow"] .strip__dot { background: var(--slow); }
.strip[data-label="just-right"] .strip__dot { background: var(--ok); }
.strip[data-label="too-fast"] .strip__dot { background: var(--fast); }

.strip[data-label="too-slow"] .strip__label { color: var(--slow); }
.strip[data-label="just-right"] .strip__label { color: var(--ok); }
.strip[data-label="too-fast"] .strip__label { color: var(--fast); }
.strip[data-label="no-data"] .strip__label { color: var(--text-muted); }

/* The bar is the only thing that absorbs spare width; min-width stops it collapsing to nothing or
 * forcing a horizontal scrollbar when the window is dragged narrow. */
/* flex-basis 0 (and width:auto, overriding .gauge__bar's width:100%) so the bar asks for nothing up
 * front and simply grows into what is left. With an auto basis it would claim the whole row, and
 * the label — the only other shrinkable item — would ellipsise even in a wide window. */
.instructor--compact[data-variant="bar"] .strip__bar {
    flex: 1 1 0;
    width: auto;
    min-width: 2.5rem;
    max-width: none;
    height: 0.7rem;
}

.instructor--compact[data-variant="bar"] .strip__counts { gap: 0.5rem; flex: none; }
.instructor--compact[data-variant="bar"] .strip__counts .count__value { font-size: 1rem; }

.strip__counts .count { flex-direction: row; align-items: baseline; }

/* line-height must match .count__value's 1. Inheriting the body's 1.5 makes the separator taller
 * above the shared baseline, which shoves its sibling number down — and since the last count has
 * no separator, that number alone would sit 4px higher than the other two. */
.strip__counts .count::after {
    content: '·';
    color: var(--text-muted);
    line-height: 1;
    margin-left: 0.5rem;
}

.strip__counts .count:last-child::after { content: none; }

.strip__tally {
    font-size: 0.85rem;
    color: var(--text-muted);
    white-space: nowrap;
    flex: none;
    font-variant-numeric: tabular-nums;
    /* Extra breathing room: the tally is digits sitting next to more digits. */
    padding-left: 0.35rem;
}

/* Dragged really narrow, drop the per-option numbers first: the bar still shows the proportions,
 * and the label, tally and Reset are what you cannot do without. */
@media (max-width: 27rem) {
    .instructor--compact[data-variant="bar"] .strip__counts { display: none; }
}

/* ---------- Student ---------- */

.body-student .page { justify-content: flex-start; }

.student {
    width: min(30rem, 100%);
    margin: 0 auto;
    padding: 1.5rem 1.1rem calc(2rem + env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    gap: 1rem;
    flex: 1;
}

.student__header { text-align: center; }
.student__title { margin: 0; font-size: 1.25rem; }
.student__sub { margin: 0.4rem 0 0; }
.student__prompt { margin: 0.5rem 0 0; text-align: center; font-size: 1.05rem; color: var(--text-muted); }

.votes { display: flex; flex-direction: column; gap: 0.85rem; }

.vote {
    position: relative;
    appearance: none;
    display: grid;
    grid-template-columns: 2.5rem 1fr 2rem;
    align-items: center;
    gap: 0.35rem 0.9rem;
    text-align: left;
    font: inherit;
    color: var(--text);
    background: var(--bg-raised);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    /* Big enough to hit without looking, from a lecture-hall seat. */
    padding: 1.15rem 1rem;
    cursor: pointer;
    transition: border-color 120ms ease, background-color 120ms ease, transform 60ms ease;
}

.vote:active { transform: scale(0.99); }
.vote:focus-visible { outline: 3px solid var(--text); outline-offset: 2px; }

.vote__glyph { grid-row: span 2; font-size: 1.6rem; text-align: center; }
.vote__label { font-size: 1.15rem; font-weight: 700; }
.vote__note { grid-column: 2; font-size: 0.82rem; color: var(--text-muted); }
.vote__check { grid-row: span 2; font-size: 1.4rem; opacity: 0; text-align: center; }

.vote--slow { --accent: var(--slow); }
.vote--ok { --accent: var(--ok); }
.vote--fast { --accent: var(--fast); }

.vote .vote__glyph { color: var(--accent); }
.vote:hover { border-color: var(--accent); }

/* Selection is marked by the tick and the border, not colour alone. */
.vote--selected { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 18%, var(--bg-raised)); }
.vote--selected .vote__check { opacity: 1; color: var(--accent); }

.student__status { margin: 0; text-align: center; min-height: 1.5rem; color: var(--text-muted); font-size: 0.9rem; }

.student__results { border-top: 1px solid var(--border); padding-top: 1rem; }
.student__results-title { margin: 0 0 0.75rem; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--text-muted); text-align: center; }
.gauge--small .gauge__dial { max-width: 16rem; }
.gauge--small .gauge__label { font-size: 1.3rem; }

.student__footer { margin-top: auto; padding-top: 1.5rem; text-align: center; color: var(--text-muted); font-size: 0.85rem; }
.student__footer p { margin: 0.25rem 0; }
.student__privacy { font-size: 0.78rem; }

/* ---------- Motion ---------- */

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
