:root {
    --bg: #f4f6fb;
    --card: #ffffff;
    --ink: #1f2430;
    --muted: #6b7280;
    --line: #e5e7eb;
    --brand: #5b5bd6;
    --brand-dark: #4848b8;
    --danger: #dc2626;
    --ok: #047857;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg);
    /* 1/8" (12px @ 96dpi) grid of light-gray squares behind the page */
    background-image:
        linear-gradient(to right, var(--line) 1px, transparent 1px),
        linear-gradient(to bottom, var(--line) 1px, transparent 1px);
    background-size: 12px 12px;
    color: var(--ink);
    line-height: 1.5;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 8px 20px;
    max-width: 880px;
    margin: 0 auto;
    background: var(--card);
    border-bottom: 1px solid var(--line);
}
.nav-left { justify-self: start; display: flex; align-items: center; gap: 16px; }
.brand-logo { justify-self: center; line-height: 0; }
.topbar .logo { height: 48px; width: auto; display: block; }
.nav-right { justify-self: end; display: flex; align-items: center; gap: 16px; }

.site-footer {
    max-width: 880px;
    margin: 0 auto;
    padding: 20px;
    background: var(--card);
    display: flex;
    justify-content: center;
}
.site-footer .powered {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}
.site-footer .powered span {
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    font-size: 13px;
}
.site-footer img { height: 30px; width: auto; display: block; }

/* Profile icon + popover */
.profile { position: relative; display: flex; }
.profile-btn {
    display: flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; padding: 0;
    border-radius: 50%; border: 1px solid var(--line);
    background: #fff; color: var(--brand); cursor: pointer;
}
.profile-btn:hover { background: #f3f4f6; }
.profile-btn svg { width: 22px; height: 22px; display: block; }
.profile-menu {
    position: absolute; right: 0; top: calc(100% + 8px);
    min-width: 180px; padding: 8px; z-index: 50;
    background: var(--card); border: 1px solid var(--line);
    border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, .12);
}
.profile-menu[hidden] { display: none; }
.profile-name {
    font-weight: 600; padding: 8px 10px;
    border-bottom: 1px solid var(--line); margin-bottom: 6px;
}
.profile-logout { display: block; padding: 8px 10px; border-radius: 8px; color: var(--ink); }
.profile-logout:hover { background: #f3f4f6; text-decoration: none; }

.container {
    max-width: 880px;
    margin: 18px auto;
    padding: 28px 20px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
}

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 22px;
    margin-bottom: 18px;
}

h1 { font-size: 26px; margin: 0 0 18px; }
h2 { font-size: 19px; margin: 0 0 14px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

label { display: block; font-size: 14px; font-weight: 600; margin: 14px 0 5px; }
input[type=text], input[type=email], input[type=password], input[type=number], select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 15px;
    background: #fff;
}
input:focus, select:focus { outline: 2px solid var(--brand); border-color: var(--brand); }

/* Make the native "Choose file" button match our buttons: white, bold blue text. */
input[type=file] { border: 0; padding: 0; }
input[type=file]::file-selector-button,
input[type=file]::-webkit-file-upload-button {
    background: #fff;
    color: var(--brand);
    font-weight: 700;
    font-size: 15px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 16px;
    margin-right: 12px;
    cursor: pointer;
}
input[type=file]::file-selector-button:hover { background: #f3f4f6; }

.btn {
    display: inline-block;
    background: var(--brand);
    color: #fff;
    border: 0;
    border-radius: 8px;
    padding: 10px 16px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}
.btn:hover { background: var(--brand-dark); text-decoration: none; }
.btn-sm { padding: 6px 12px; font-size: 14px; }
.btn-ghost { background: transparent; color: var(--brand); border: 1px solid var(--line); }
.btn-ghost:hover { background: #f3f4f6; }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }
.btn-danger:hover { background: #fee2e2; }

.flash {
    background: #eef2ff;
    border: 1px solid #c7d2fe;
    color: var(--brand-dark);
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 16px;
}
.error { color: var(--danger); font-size: 14px; margin-top: 8px; }

.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.slide-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    margin-bottom: 10px;
    background: #fff;
}
.slide-row .pos { color: var(--muted); font-variant-numeric: tabular-nums; }
.badge {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .03em;
    padding: 3px 8px;
    border-radius: 999px;
    background: #eef2ff;
    color: var(--brand-dark);
}
.slide-row .grow { flex: 1; min-width: 0; }
.slide-row .grow .q { font-weight: 600; }
.slide-row form { display: inline; margin: 0; }

.type-grid { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 6px; }
.type-grid .btn.current { background: var(--brand); color: #fff; border-color: var(--brand); }

/* Type-picker modal */
.modal-backdrop {
    position: fixed; inset: 0; z-index: 100;
    background: rgba(17, 21, 34, .5);
    display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-backdrop[hidden] { display: none; }
.modal {
    background: var(--card); border-radius: 14px; padding: 24px;
    width: 100%; max-width: 480px; box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.modal h2 { margin-top: 0; }

.option-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.option-row input[type=text] { flex: 1; }
.option-row .correct { display: flex; align-items: center; gap: 6px; font-weight: 500; white-space: nowrap; font-size: 14px; }

.empty { text-align: center; color: var(--muted); padding: 30px 0; }
.actions { margin-top: 18px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 500; cursor: pointer; margin: 0; user-select: none; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle .switch {
    position: relative; flex: 0 0 auto;
    width: 40px; height: 22px;
    background: var(--line); border-radius: 999px;
    transition: background .2s;
}
.toggle .switch::after {
    content: ''; position: absolute; top: 2px; left: 2px;
    width: 18px; height: 18px;
    background: #fff; border-radius: 50%;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .3);
    transition: transform .2s;
}
.toggle input:checked + .switch { background: var(--brand); }
.toggle input:checked + .switch::after { transform: translateX(18px); }
.toggle input:focus-visible + .switch { outline: 2px solid var(--brand); outline-offset: 2px; }
.inline-actions { display: flex; gap: 6px; }

/* Dictation mic button next to a text input */
.with-mic { display: flex; gap: 8px; align-items: stretch; }
.with-mic input { flex: 1; }
.mic-btn {
    flex: 0 0 auto;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 8px;
    padding: 0 14px;
    font-size: 18px;
    cursor: pointer;
    line-height: 1;
}
.mic-btn:hover { background: #f3f4f6; }
.mic-btn.listening { background: #fee2e2; border-color: var(--danger); animation: micpulse 1s ease-in-out infinite; }
@keyframes micpulse { 50% { opacity: .55; } }
.auth-narrow { max-width: 420px; }

/* Login/auth: center the card in the middle of the page (header stays on top). */
.auth-screen {
    min-height: calc(100vh - 140px);
    display: flex;
    align-items: center;
    justify-content: center;
}
.auth-screen .card { width: 100%; margin-bottom: 0; }

/* ===== Presenter live view ===== */
.present-body { background: #111522; color: #f5f7ff; margin: 0; }
.present-wrap { display: flex; flex-direction: column; min-height: 100vh; }
.present-top {
    display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 24px;
    padding: 16px 28px; background: #1a1f33; border-bottom: 1px solid #2a3050;
}
.present-top .muted { color: #9aa3c7; }
.present-title { justify-self: center; text-align: center; font-size: 38px; font-weight: 800; color: #fff; }
.pt-right { justify-self: end; display: flex; align-items: center; gap: 24px; }
.join-code { font-size: 38px; font-weight: 800; letter-spacing: .12em; color: #fff; }
.qr { background: #fff; padding: 6px; border-radius: 8px; line-height: 0; }
.present-meta { text-align: right; }
.pcount { font-size: 22px; font-weight: 700; }
.conn { font-size: 13px; color: #9aa3c7; }

.stage { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 30px 8vw; }
.stage-empty { text-align: center; color: #9aa3c7; font-size: 20px; }
.stage-q { font-size: 40px; line-height: 1.15; margin: 0 0 30px; }

.bars { display: flex; flex-direction: column; gap: 16px; }
.bar-row { display: grid; grid-template-columns: 220px 1fr 60px; align-items: center; gap: 16px; }
.bar-label { font-size: 20px; font-weight: 600; }
.bar-track { background: #232a45; border-radius: 10px; height: 40px; overflow: hidden; }
.bar-fill { background: linear-gradient(90deg, #6d6df5, #a06df5); height: 100%; width: var(--pct, 0%); transition: width .35s ease, height .35s ease; border-radius: 10px; }
.bar-count { font-size: 22px; font-weight: 700; text-align: right; }

/* Vertical (column) chart mode — toggled by the presenter */
.bars.vertical { flex-direction: row; align-items: flex-end; justify-content: center; gap: 28px; min-height: 46vh; }
.bars.vertical .bar-row { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 46vh; flex: 0 1 170px; min-width: 0; }
.bars.vertical .bar-count { order: 1; text-align: center; margin-bottom: 8px; }
.bars.vertical .bar-track { order: 2; width: 96px; height: 100%; display: flex; align-items: flex-end; }
.bars.vertical .bar-fill { width: 100%; height: var(--pct, 0%); }
.bars.vertical .bar-label { order: 3; margin-top: 10px; text-align: center; max-width: 170px; }

.present-controls {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 28px; background: #1a1f33; border-top: 1px solid #2a3050;
}
.present-controls .spacer { flex: 1; }
.slidepos { color: #9aa3c7; font-variant-numeric: tabular-nums; }

/* ===== Audience (phone) view ===== */
.play-body { background: var(--brand); margin: 0; min-height: 100vh; }
.play-wrap { max-width: 440px; margin: 0 auto; padding: 28px 18px; }
.play-title { color: #fff; text-align: center; font-size: 30px; margin: 18px 0 24px; }
.play-body label { color: #e7e9ff; }
.code-input { text-transform: uppercase; letter-spacing: .15em; font-size: 22px; text-align: center; }
.btn-block { display: block; width: 100%; margin-top: 18px; padding: 14px; font-size: 17px; background: #fff; color: var(--brand-dark); }
.btn-block:hover { background: #f0f0ff; }

.play-status { color: #e7e9ff; text-align: center; margin: 10px 0 20px; font-size: 16px; }
.play-q { color: #fff; font-size: 24px; text-align: center; margin: 10px 0 22px; }
.play-options { display: flex; flex-direction: column; gap: 12px; }
.opt-btn {
    display: block; width: 100%; padding: 18px; font-size: 18px; font-weight: 600;
    background: #fff; color: var(--ink); border: 0; border-radius: 12px; cursor: pointer;
}
.opt-btn:active { transform: scale(.99); }
.opt-btn:disabled { opacity: .55; cursor: default; }
.play-thanks { color: #fff; text-align: center; font-size: 20px; font-weight: 700; margin-top: 22px; }

/* ===== Quiz: presenter ===== */
.quiz-hud { display: flex; gap: 20px; align-items: center; margin: -10px 0 22px; }
.quiz-hud .timer { font-size: 30px; font-weight: 800; color: #ffd166; min-width: 90px; }
.quiz-hud .answered { color: #9aa3c7; font-size: 18px; }
.bar-row.hide-count .bar-track, .bar-row.hide-count .bar-count { visibility: hidden; }
.bar-row.correct-opt .bar-label { color: #4ade80; }
.bar-row.correct-opt .bar-fill { background: linear-gradient(90deg, #22c55e, #4ade80); }
.bar-row.correct-opt .bar-label::after { content: ' ✓'; }

.board { margin-top: 26px; }
.board-title { font-size: 22px; margin: 0 0 12px; }
.board-list { list-style: none; margin: 0; padding: 0; max-width: 520px; }
.board-list li { display: flex; justify-content: space-between; padding: 10px 14px; background: #1f2540; border-radius: 8px; margin-bottom: 8px; font-size: 18px; counter-increment: rank; }
.board-list li::before { content: counter(rank) '. '; color: #9aa3c7; margin-right: 8px; }
.board-list { counter-reset: rank; }
.board-list .bs { font-weight: 800; color: #ffd166; }

/* ===== Quiz: audience ===== */
.play-timer { text-align: center; color: #fff; font-size: 34px; font-weight: 800; margin: 4px 0 14px; }
.opt-btn.picked { outline: 3px solid #ffd166; }
.opt-btn.correct { background: #22c55e; color: #fff; }
.opt-btn.wrong { background: #ef4444; color: #fff; }
.play-feedback { margin-top: 20px; text-align: center; color: #fff; font-size: 22px; font-weight: 700; padding: 18px; border-radius: 12px; background: rgba(255,255,255,.12); }
.play-feedback.good { background: rgba(34,197,94,.95); }
.play-feedback.bad { background: rgba(239,68,68,.95); }
.play-feedback.miss { background: rgba(255,255,255,.18); }
.play-feedback .fb-sub { font-size: 15px; font-weight: 500; margin-top: 8px; opacity: .95; }

/* ===== Open-ended: presenter text wall ===== */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.card-item { background: #1f2540; border: 1px solid #2a3050; border-radius: 12px; padding: 16px; animation: pop .25s ease; }
.card-item .ci-text { font-size: 19px; }
.card-item .ci-who { color: #9aa3c7; font-size: 13px; margin-top: 8px; }
@keyframes pop { from { transform: scale(.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ===== Q&A: presenter moderation ===== */
.qa-mod { display: flex; flex-direction: column; gap: 10px; max-width: 760px; }
.qa-item { display: flex; align-items: center; gap: 14px; background: #1f2540; border: 1px solid #2a3050; border-radius: 10px; padding: 12px 16px; }
.qa-item.status-pending { border-color: #b59412; background: #2a2616; }
.qa-item.status-answered { opacity: .55; }
.qa-item.status-dismissed { opacity: .4; }
.qa-up { font-weight: 800; color: #ffd166; min-width: 48px; }
.qa-body { flex: 1; }
.qa-text { font-size: 18px; }
.qa-meta { color: #9aa3c7; font-size: 13px; margin-top: 3px; }
.qa-status { text-transform: uppercase; letter-spacing: .04em; }
.qa-actions { display: flex; gap: 6px; white-space: nowrap; }

/* ===== Open-ended / Q&A: audience ===== */
.text-in { width: 100%; padding: 12px; border-radius: 10px; border: 0; font-size: 16px; font-family: inherit; }
.sent-note { color: #fff; text-align: center; margin-top: 10px; font-weight: 600; min-height: 20px; }
.qa-list { margin-top: 20px; display: flex; flex-direction: column; gap: 10px; }
.qa-empty { color: #e7e9ff; text-align: center; }
.qa-q { display: flex; align-items: stretch; gap: 10px; background: #fff; border-radius: 10px; overflow: hidden; }
.qa-q .qa-qtext { padding: 12px; flex: 1; color: var(--ink); }
.up-btn { border: 0; background: #eef0ff; color: var(--brand-dark); font-weight: 700; padding: 0 16px; cursor: pointer; font-size: 15px; }
.up-btn.voted { background: var(--brand); color: #fff; }

/* ===== Phase 5: surveys & analytics ===== */
.req { color: var(--danger); }
.share-box { display: flex; gap: 8px; margin-top: 12px; }
.share-box input { font-family: monospace; font-size: 13px; }

/* Survey builder/results shared bits */
.sq-title { font-weight: 600; font-size: 17px; margin-bottom: 12px; }
.sq-opt { display: flex; align-items: center; gap: 8px; font-weight: 400; margin: 8px 0; cursor: pointer; }
.sq-opt input { width: auto; }

.rating { display: flex; gap: 10px; }
.rating .rate { cursor: pointer; }
.rating .rate input { display: none; }
.rating .rate span { display: flex; align-items: center; justify-content: center; width: 48px; height: 48px; border: 2px solid var(--line); border-radius: 10px; font-size: 18px; font-weight: 700; }
.rating .rate input:checked + span { background: var(--brand); color: #fff; border-color: var(--brand); }

/* Results bar chart (light theme) */
.rbars { display: flex; flex-direction: column; gap: 10px; }
.rbar-row { display: grid; grid-template-columns: 200px 1fr 48px; align-items: center; gap: 12px; }
.rbar-label { font-weight: 500; }
.rbar-track { background: #eef0f6; border-radius: 8px; height: 28px; overflow: hidden; }
.rbar-fill { background: linear-gradient(90deg, #6d6df5, #a06df5); height: 100%; border-radius: 8px; }
.rbar-count { font-weight: 700; text-align: right; }

.rating-summary { display: flex; align-items: baseline; gap: 10px; }
.big-avg { font-size: 40px; font-weight: 800; color: var(--brand); }

.ans-list { display: flex; flex-direction: column; gap: 8px; }
.ans { background: #f6f7fb; border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; }

.rank-list { counter-reset: rank; list-style: none; margin: 0; padding: 0; }
.rank-list li { counter-increment: rank; display: flex; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.rank-list li::before { content: counter(rank) '. '; color: var(--muted); margin-right: 8px; }
.rank-list li span:first-of-type { flex: 1; }
.rank-score { font-weight: 800; color: var(--brand); }

/* Public survey page */
.survey-body { background: var(--bg); margin: 0; }
.survey-wrap { max-width: 620px; margin: 0 auto; padding: 28px 18px; }
.survey-done { text-align: center; padding: 48px 22px; }
.error-flash { background: #fee2e2; border: 1px solid #fecaca; color: #b91c1c; padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }
