:root {
    --bg: #f6f7fb;
    --card: #ffffff;
    --text: #172033;
    --muted: #667085;
    --primary: #2454d6;
    --danger: #b42318;
    --border: #d0d5dd;
    --dark: #0b0f19;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--bg);
}
a { color: var(--primary); }
.topbar {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: center;
    padding: .9rem max(1rem, 4vw);
    background: #fff;
    border-bottom: 1px solid var(--border);
}
.brand { font-weight: 800; color: var(--text); text-decoration: none; }
.topbar nav { display: flex; gap: .8rem; flex-wrap: wrap; }
.container { width: min(1120px, calc(100% - 2rem)); margin: 2rem auto; }
.hero {
    padding: clamp(2rem, 8vw, 5rem);
    background: linear-gradient(135deg, #e7edff, #fff);
    border: 1px solid var(--border);
    border-radius: 24px;
}
.hero h1 { font-size: clamp(2rem, 7vw, 4rem); margin: 0 0 1rem; }
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 1.25rem;
    box-shadow: 0 10px 30px rgba(16,24,40,.06);
}
.narrow { max-width: 520px; margin-inline: auto; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 1rem; }
.page-title, .actions, .controls { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.page-title { justify-content: space-between; margin-bottom: 1rem; }
.button {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
    color: var(--text);
    padding: .72rem 1rem;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.button.ghost { background: transparent; }
.button:disabled { opacity: .5; cursor: not-allowed; }
label { display: grid; gap: .35rem; margin: .75rem 0; font-weight: 700; }
input, textarea, select {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: .75rem;
    font: inherit;
    background: #fff;
}
input:focus, textarea:focus, select:focus, button:focus, a:focus {
    outline: 3px solid rgba(36,84,214,.28);
    outline-offset: 2px;
}
.muted { color: var(--muted); }
.alert { background: #fef3f2; border: 1px solid #fecdca; padding: .75rem; border-radius: 10px; color: var(--danger); }
.alert.success { background: #ecfdf3; border-color: #abefc6; color: #067647; }
.field-error { color: var(--danger); font-weight: 700; min-height: 1.2em; }
.active-session { border: 1px solid #b2ddff; background: #eff8ff; border-radius: 12px; padding: .75rem; margin: .75rem 0; }
.active-session p { margin: 0 0 .5rem; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .75rem; }
.stats div { border: 1px solid var(--border); border-radius: 12px; padding: .8rem; background: #fff; }
.stats dt { color: var(--muted); font-weight: 700; }
.stats dd { margin: .2rem 0 0; font-size: 1.6rem; font-weight: 800; }
progress { width: 100%; height: 1rem; margin: .4rem 0; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: .75rem; margin-top: 1rem; }
.thumbs figure { margin: 0; border: 1px solid var(--border); border-radius: 12px; padding: .4rem; background: #fff; }
.thumbs img { width: 100%; display: block; border-radius: 8px; }
.thumbs figcaption { font-size: .85rem; color: var(--muted); margin-top: .25rem; }
.presenter-slide-map {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
    gap: .4rem;
    margin-top: 1rem;
    max-height: 24vh;
    overflow: auto;
    padding: .25rem;
}
.slide-map-button {
    border: 2px solid var(--border);
    border-radius: 10px;
    background: #fff;
    min-height: 42px;
    padding: .35rem;
    cursor: pointer;
    color: var(--text);
    font-weight: 800;
}
.slide-map-button.active { border-color: var(--primary); background: #e7edff; box-shadow: 0 0 0 3px rgba(36,84,214,.18); }

.presenter-shell {
    display: grid;
    grid-template-columns: minmax(260px, 340px) 1fr;
    gap: 1rem;
}
.panel, .stage-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 1rem;
}
.stage, .viewer-stage {
    position: relative;
    display: grid;
    place-items: center;
    background: var(--dark);
    border-radius: 16px;
    overflow: hidden;
    min-height: 55vh;
}
.stage img, .viewer-stage img {
    max-width: 100%;
    max-height: 78vh;
    object-fit: contain;
}
.blackout {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    background: #000;
    color: #fff;
    font-weight: 800;
    z-index: 3;
}
.hidden { display: none !important; }
.qrcode { width: 180px; height: 180px; margin: 1rem 0; background: #fff; display: grid; place-items: center; }
.qrcode canvas, .qrcode img { max-width: 100%; height: auto; }

.viewer-page { background: #05070d; color: #fff; overflow: hidden; }
.viewer { min-height: 100vh; display: grid; grid-template-rows: auto 1fr auto; }
.viewer header {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: .55rem .8rem;
    color: rgba(255,255,255,.78);
    font-size: .95rem;
}
.viewer-stage { border-radius: 0; min-height: 0; height: calc(100vh - 4.2rem); }
.viewer-credit { padding: .35rem .8rem; background: #0b0f19; color: rgba(255,255,255,.72); text-align: center; font-size: .85rem; }
.viewer-credit a { color: #b9c9ff; }
.viewer-message {
    position: absolute;
    bottom: 1rem;
    background: rgba(0,0,0,.6);
    padding: .65rem .9rem;
    border-radius: 999px;
}
.viewer-public-question { position: absolute; left: 1rem; right: 1rem; top: 1rem; z-index: 4; display: grid; gap: .25rem; padding: .8rem 1rem; background: rgba(255,255,255,.96); color: var(--text); border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.3); }
.viewer-question-panel { position: fixed; right: 1rem; bottom: 1rem; z-index: 10; width: min(360px, calc(100% - 2rem)); }
.question-form { margin-top: .6rem; padding: 1rem; background: rgba(255,255,255,.98); color: var(--text); border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 12px 30px rgba(0,0,0,.35); }
.question-form h2, .question-moderation h2 { margin-top: 0; }
.question-feedback { min-height: 1.2em; font-weight: 700; }
.question-feedback.success { color: #067647; }
.question-moderation { margin-top: 1.2rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.question-new-alert { margin: .5rem 0; padding: .55rem .7rem; border-radius: 10px; background: #fff4cc; color: #7a4d00; font-weight: 800; animation: question-pulse 1.1s ease-in-out infinite alternate; }
.question-clear-button { margin-bottom: .5rem; }
.question-badge { display: inline-grid; place-items: center; min-width: 1.6rem; padding: .1rem .35rem; border-radius: 999px; background: var(--primary); color: #fff; font-size: .8em; }
.question-item { border: 1px solid var(--border); border-radius: 10px; padding: .7rem; margin-top: .6rem; background: #f8faff; }
.question-item.displayed { border-color: #12b76a; background: #ecfdf3; box-shadow: 0 0 0 2px rgba(18,183,106,.16); }
.question-item p { margin: .35rem 0 .65rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.question-meta { color: var(--muted); font-size: .85rem; }
.question-item .actions { gap: .4rem; }
.question-item .button { padding: .45rem .6rem; font-size: .85rem; }
@keyframes question-pulse { from { opacity: .62; } to { opacity: 1; } }

@media (max-width: 760px) {
    .presenter-shell { grid-template-columns: 1fr; }
    .topbar { align-items: flex-start; flex-direction: column; }
    .container { margin: 1rem auto; }
    .stage, .viewer-stage { min-height: 48vh; }
    .viewer-question-panel { left: .5rem; right: .5rem; bottom: 2.6rem; width: auto; }
    .viewer-question-panel > .button { width: 100%; }
    .question-form { max-height: 72vh; overflow: auto; }
    .controls .button { min-height: 44px; }
}
