:root {
    --bg: #f5f6fb;
    --surface: #ffffff;
    --text: #111827;
    --muted: #6b7280;
    --border: #e5e7eb;
    --primary: #6366f1;
    --primary-ink: #ffffff;
    --danger: #ef4444;
    --success: #10b981;
    --radius: 16px;
    --shadow: 0 10px 30px rgba(17, 24, 39, .08);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f1220;
        --surface: #181c2e;
        --text: #f3f4f6;
        --muted: #9ca3af;
        --border: #2a2f45;
        --shadow: 0 10px 30px rgba(0, 0, 0, .35);
    }
}

* { box-sizing: border-box; }

/* Classes below set display:flex/grid, which would otherwise override the hidden attribute. */
[hidden] { display: none !important; }

html, body { margin: 0; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
}

h1, h2 { margin: 0 0 .5em; line-height: 1.2; }

.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center-text { text-align: center; }
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: .75rem; font-weight: 700; color: var(--primary); margin: 0 0 .5rem; }
.stack { display: flex; flex-direction: column; gap: .75rem; }
.error { color: var(--danger); font-size: .9rem; margin: 0; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
}

/* ---------- Buttons & inputs ---------- */

.btn {
    appearance: none;
    border: 1px solid transparent;
    border-radius: 12px;
    padding: .7rem 1.1rem;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    background: var(--surface);
    color: var(--text);
    transition: transform .05s, opacity .15s, background .15s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: default; }
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { border-color: var(--border); background: transparent; }
.btn-ghost:hover { background: var(--border); }
.btn-block { width: 100%; padding: .9rem; font-size: 1.05rem; }

.input, .select, .code-input {
    width: 100%;
    font: inherit;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: .8rem 1rem;
}
.input:focus, .code-input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.select { width: auto; max-width: 340px; padding: .6rem .8rem; }

/* ---------- Audience ---------- */

.audience-shell { max-width: 560px; margin: 0 auto; padding: 16px; min-height: 100vh; }
.audience-shell.center { display: flex; align-items: center; justify-content: center; }

.join-card { width: 100%; text-align: center; padding: 2rem 1.5rem; }
.brand { font-size: 1.8rem; font-weight: 800; }
.code-input { text-align: center; font-size: 2rem; font-weight: 700; letter-spacing: .2em; }

.audience-header { display: flex; align-items: center; justify-content: space-between; padding: .5rem 0 1rem; }
.brand-sm { font-weight: 700; }
.live-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.live-dot.on { background: var(--success); box-shadow: 0 0 0 4px rgba(16, 185, 129, .2); animation: pulse 2s infinite; }

.notice { background: rgba(99, 102, 241, .12); color: var(--primary); border-radius: 12px; padding: .7rem 1rem; margin-bottom: 1rem; font-weight: 500; }

.question { font-size: 1.4rem; font-weight: 700; }

.waiting { padding: 3rem 1.5rem; }
.check { width: 64px; height: 64px; margin: 0 auto 1rem; border-radius: 50%; background: var(--success); color: #fff; display: grid; place-items: center; font-size: 2rem; }
.spinner { width: 44px; height: 44px; margin: 0 auto 1.25rem; border-radius: 50%; border: 4px solid var(--border); border-top-color: var(--primary); animation: spin 1s linear infinite; }

.choices { display: flex; flex-direction: column; gap: .6rem; }
.choice { display: flex; align-items: center; gap: .75rem; padding: .9rem 1rem; border: 2px solid var(--border); border-radius: 12px; cursor: pointer; font-weight: 500; }
.choice:has(input:checked) { border-color: var(--primary); background: rgba(99, 102, 241, .08); }
.choice input { width: 1.2rem; height: 1.2rem; accent-color: var(--primary); }
.choice.is-disabled { opacity: .45; cursor: not-allowed; }

.scale { display: grid; grid-template-columns: repeat(var(--steps), 1fr); gap: .4rem; }
.scale-step input { position: absolute; opacity: 0; pointer-events: none; }
.scale-step span { display: grid; place-items: center; aspect-ratio: 1; border: 2px solid var(--border); border-radius: 12px; font-weight: 700; cursor: pointer; }
.scale-step input:checked + span { background: var(--primary); border-color: var(--primary); color: #fff; }
.scale-step input:focus-visible + span { outline: 2px solid var(--primary); }
.scale-labels { display: flex; justify-content: space-between; gap: 1rem; }

/* ---------- Results ---------- */

.results { margin-top: 1rem; }
.empty { text-align: center; padding: 2rem 0; }
.charts { display: grid; gap: 1.5rem; }
.chart-box { position: relative; height: 300px; min-width: 0; }
.average { font-size: 1.1rem; margin-bottom: .75rem; }
.average strong { font-size: 2rem; margin: 0 .25rem; }

.word-cloud { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: .3em .8em; padding: 1rem 0; }
.word { font-weight: 700; line-height: 1.1; }

.entries { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .75rem; }
.entry { background: var(--bg); border: 1px solid var(--border); border-radius: 12px; padding: .9rem 1rem; overflow-wrap: anywhere; }

/* ---------- Presenter ---------- */

.presenter { overflow-x: hidden; }
.presenter-shell { min-height: 100vh; display: flex; flex-direction: column; }

.presenter-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; padding: 1rem 1.5rem; border-bottom: 1px solid var(--border); background: var(--surface); }
.join-hint { font-size: 1.2rem; }
.join-hint .code { letter-spacing: .08em; color: var(--primary); }
.join-hint .sep { color: var(--muted); margin: 0 .4rem; }
.header-actions { display: flex; align-items: center; gap: .6rem; }

.badge { font-size: .75rem; font-weight: 700; letter-spacing: .06em; padding: .35rem .7rem; border-radius: 999px; background: var(--border); color: var(--muted); }
.badge-live { background: var(--danger); color: #fff; animation: pulse 2s infinite; }

.presenter-main { flex: 1; display: grid; grid-template-columns: 1fr 340px; gap: 1.5rem; padding: 1.5rem; }
.stage { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem 2.5rem; display: flex; flex-direction: column; min-width: 0; }
.stage-meta { display: flex; align-items: center; gap: 1rem; }
.stage-meta .eyebrow { margin: 0; }
.status { font-size: .8rem; font-weight: 600; padding: .25rem .6rem; border-radius: 999px; }
.status.open { background: rgba(16, 185, 129, .15); color: var(--success); }
.status.closed { background: rgba(239, 68, 68, .15); color: var(--danger); }
.stage-question { font-size: clamp(1.8rem, 3.2vw, 3rem); font-weight: 800; margin: .75rem 0 1rem; }

.stage-results { flex: 1; display: flex; flex-direction: column; font-size: 1.25rem; }
.stage-results .charts { flex: 1; }
.stage-results .charts-2 { grid-template-columns: 3fr 2fr; }
.stage-results .chart-box { height: auto; min-height: 380px; }

.hidden-results { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.big-count { font-size: 7rem; font-weight: 800; color: var(--primary); line-height: 1; }

.qr-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; text-align: center; align-self: start; }
.qr { background: #fff; border-radius: 12px; padding: .75rem; }
.qr svg { display: block; width: 100%; height: auto; }
.qr-url { font-weight: 700; font-size: 1.1rem; margin: 1rem 0 .25rem; overflow-wrap: anywhere; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; padding: .9rem 1.5rem; border-top: 1px solid var(--border); background: var(--surface); }
.toolbar-group { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.segmented button { appearance: none; border: 0; background: transparent; color: var(--text); font: inherit; font-weight: 600; padding: .65rem .9rem; cursor: pointer; }
.segmented form + form button { border-left: 1px solid var(--border); }
.segmented button.active { background: var(--primary); color: #fff; }

@media (max-width: 900px) {
    .presenter-main { grid-template-columns: 1fr; }
    .qr-panel { max-width: 340px; margin: 0 auto; }
    .stage { padding: 1.25rem; }
    .stage-results .charts-2 { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
    .charts-2 .chart-box { height: 260px; }
}

/* ---------- Printable report ---------- */

/* Always light: it is meant for paper/PDF. */
.report-page {
    --bg: #f5f6fb; --surface: #ffffff; --text: #111827; --muted: #6b7280; --border: #e5e7eb;
    background: #e9ebf3; color: var(--text);
}

.report-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; max-width: 210mm; margin: 0 auto; padding: 16px; }
.report { background: #fff; max-width: 210mm; margin: 0 auto 32px; padding: 14mm 14mm 10mm; box-shadow: var(--shadow); }

.report-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; border-bottom: 3px solid var(--primary); padding-bottom: 1rem; }
.report-question { font-size: 1.6rem; font-weight: 800; margin: 0; }
.report-brand { font-weight: 800; color: var(--primary); white-space: nowrap; }

.report-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: .75rem; margin: 1.25rem 0; }
.report-stats > div { background: var(--bg); border-radius: 12px; padding: .75rem 1rem; display: flex; flex-direction: column; }
.stat-value { font-size: 1.6rem; font-weight: 800; color: var(--primary); }
.stat-value.small-value { font-size: 1rem; padding: .35rem 0; }
.stat-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }

.report-section { margin-top: 1.5rem; }
.report-section h2 { font-size: 1.05rem; margin-bottom: .75rem; }
.report-results .charts-2 { grid-template-columns: 3fr 2fr; }
.report-results .chart-box { height: 280px; }
.report-results .word-cloud { font-size: 1rem; }

.report-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.report-table th { text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); border-bottom: 2px solid var(--border); padding: .45rem .5rem; }
.report-table td { border-bottom: 1px solid var(--border); padding: .45rem .5rem; vertical-align: top; overflow-wrap: anywhere; }
.report-table .num { text-align: right; width: 1%; white-space: nowrap; }
.report-table .nowrap { white-space: nowrap; }
.report-table tr { break-inside: avoid; }
.tag { display: inline-block; margin-left: .4rem; font-size: .7rem; font-weight: 700; color: var(--success); border: 1px solid var(--success); border-radius: 999px; padding: 0 .4rem; }

.report-footer { margin-top: 2rem; padding-top: .75rem; border-top: 1px solid var(--border); text-align: center; }

@media (max-width: 640px) {
    .report { padding: 16px; }
    .report-results .charts-2 { grid-template-columns: 1fr; }
}

@page { size: A4; margin: 12mm; }

@media print {
    .no-print { display: none !important; }
    .report-page { background: #fff; }
    .report { box-shadow: none; margin: 0; padding: 0; max-width: none; }
    .report-results .charts-2 { grid-template-columns: 3fr 2fr; }
    .avoid-break, .report-results, .report-stats { break-inside: avoid; }
    .report-section h2 { break-after: avoid; }
    * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: .6; } }
