/* LibrePoll — clean, minimal, responsive design system. */

:root {
  --bg: #ffffff;
  --bg-subtle: #f6f7f9;
  --bg-raised: #ffffff;
  --border: #c7cdd6;
  --text: #16181d;
  --text-muted: #656d76;
  --brand: #4f46e5;
  --brand-dark: #3f37c9;
  --brand-contrast: #ffffff;
  --success: #12875a;
  --success-bg: #e7f7ef;
  --danger: #d1263f;
  --danger-bg: #fdecee;
  --warn: #b7791f;
  --warn-bg: #fdf3e0;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --max-width: 960px;
  font-size: 18px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101216;
    --bg-subtle: #17191f;
    --bg-raised: #1b1e25;
    --border: #2b2f38;
    --text: #eef0f3;
    --text-muted: #9aa2ad;
    --brand: #8b81f7;
    --brand-dark: #a89dfc;
    --brand-contrast: #10121a;
    --success: #3ecf8e;
    --success-bg: #0f2a20;
    --danger: #ff6b81;
    --danger-bg: #2c1216;
    --warn: #f0b94d;
    --warn-bg: #2c2210;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 2px 6px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Nunito', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1em; }
.muted { color: var(--text-muted); }
.small { font-size: 0.85rem; }

.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1.25rem;
}
.container--wide { max-width: 1200px; }
.container--narrow { max-width: 440px; }
@media (min-width: 641px) {
  .container--narrow { max-width: 800px; }
}

/* --- Nav --- */
.nav {
  border-bottom: 1px solid var(--border);
  background: var(--bg-raised);
}
.nav-inner {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.85rem 1.25rem;
  max-width: 1200px;
  margin: 0 auto;
}
.nav-brand { font-weight: 700; font-size: 1.1rem; color: var(--text); }
.nav-links { display: flex; gap: 1rem; flex: 1; flex-wrap: wrap; }
.nav-links a { color: var(--text-muted); font-size: 0.92rem; }
.nav-links a.active, .nav-links a:hover { color: var(--text); text-decoration: none; }
.nav-right { display: flex; align-items: center; gap: 0.9rem; }

.badge-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.4rem;
  height: 1.4rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  border: 1.5px solid var(--text-muted);
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 700;
}
.badge-count.has-pending {
  border-color: var(--danger);
  background: var(--danger);
  color: #fff;
  animation: shake 3.2s ease-in-out infinite;
}
@keyframes shake {
  0%, 92%, 100% { transform: translateX(0) rotate(0); }
  93% { transform: translateX(-2px) rotate(-8deg); }
  94% { transform: translateX(2px) rotate(8deg); }
  95% { transform: translateX(-2px) rotate(-6deg); }
  96% { transform: translateX(2px) rotate(6deg); }
  97% { transform: translateX(0) rotate(0); }
}

main { padding: 2rem 0 4rem; }

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text);
  padding: 0.55rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  line-height: 1.2;
}
.btn:hover { border-color: var(--text-muted); text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-contrast); }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.82rem; }
.btn-lg { padding: 0.85rem 1.4rem; font-size: 1.05rem; }
.btn-block { width: 100%; }
.btn-icon { padding: 0.45rem; width: 2.1rem; height: 2.1rem; }
.btn-icon.is-copied { color: var(--success); }

/* --- Forms --- */
label { display: block; font-weight: 600; font-size: 0.88rem; margin-bottom: 0.3rem; }
.field { margin-bottom: 1.1rem; }
.field-hint { color: var(--text-muted); font-size: 0.8rem; margin-top: 0.3rem; }
input[type="text"], input[type="email"], input[type="number"], input[type="password"],
input[type="search"], textarea, select {
  width: 100%;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-raised);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
}
textarea { min-height: 6rem; resize: vertical; }
input:focus, textarea:focus, select:focus, button:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}
.checkbox-row { display: flex; align-items: center; gap: 0.5rem; font-weight: 400; }
.checkbox-row label { font-weight: 400; margin: 0; }

.advanced { margin-bottom: 1.5rem; }
.advanced > summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.88rem;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  list-style: none;
}
.advanced > summary::-webkit-details-marker { display: none; }
.advanced > summary::before { content: "▸ "; color: var(--text-muted); }
.advanced[open] > summary::before { content: "▾ "; }
.advanced[open] > summary { border-radius: var(--radius-sm) var(--radius-sm) 0 0; }
.advanced-body {
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  padding: 1.1rem 0.9rem 0.1rem;
}

.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-track {
  position: absolute; inset: 0; background: var(--border); border-radius: 999px; transition: background 0.15s;
}
.switch-track::before {
  content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: transform 0.15s; box-shadow: var(--shadow);
}
.switch input:checked + .switch-track { background: var(--success); }
.switch input:checked + .switch-track::before { transform: translateX(18px); }

/* --- Cards / tiles --- */
.card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
}
.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}
.poll-tile {
  display: block;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  color: var(--text);
  transition: box-shadow 0.15s, border-color 0.15s;
}
.poll-tile:hover { box-shadow: var(--shadow); border-color: var(--brand); text-decoration: none; }
.poll-tile-type {
  display: inline-flex; align-items: center; gap: 0.35rem;
  font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}
.poll-tile-name { font-weight: 600; margin-bottom: 0.3rem; }
.poll-tile-meta { color: var(--text-muted); font-size: 0.82rem; }

.poll-respond-qr { width: 100px; height: 100px; margin: 0 auto; }
.poll-respond-qr svg { width: 100%; height: 100%; display: block; }

.type-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.4rem; height: 1.4rem; border-radius: 5px;
  background: var(--bg-subtle); font-size: 0.8rem;
}

.badge {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.15rem 0.55rem; border-radius: 999px;
  font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em;
}
.badge-closed { background: var(--danger-bg); color: var(--danger); }
.badge-open { background: var(--success-bg); color: var(--success); }
.badge-pending { background: var(--warn-bg); color: var(--warn); }

/* --- Display tiles on the poll page --- */
.display-tile {
  position: relative;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  padding-bottom: 2.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.display-tile-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.5rem; }
.display-tile-name { font-weight: 600; }
.display-tile-type { color: var(--text-muted); font-size: 0.82rem; }
.display-url-row {
  display: flex; gap: 0.4rem; align-items: center;
  background: var(--bg-subtle); border-radius: var(--radius-sm); padding: 0.4rem 0.5rem;
}
.display-url-row input {
  border: none; background: transparent; font-size: 0.8rem; color: var(--text-muted); padding: 0.1rem;
  flex: 1; min-width: 0;
}
.display-tile-delete {
  position: absolute;
  bottom: 0.7rem;
  right: 0.7rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.9rem;
  height: 1.9rem;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--danger);
  cursor: pointer;
}
.display-tile-delete:hover { background: var(--danger-bg); }
.display-tile.is-revoked { opacity: 0.55; }

/* --- Modal --- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(10, 12, 16, 0.5);
  display: flex; align-items: center; justify-content: center; padding: 1rem; z-index: 50;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--bg-raised); border-radius: var(--radius); border: 1px solid var(--border);
  box-shadow: var(--shadow); width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto;
  padding: 1.5rem;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }

/* --- Tables --- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
th { color: var(--text-muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.02em; }
tr:last-child td { border-bottom: none; }

/* --- Flash / alerts --- */
.alert { border-radius: var(--radius-sm); padding: 0.75rem 1rem; margin-bottom: 1rem; font-size: 0.9rem; }
.alert-danger { background: var(--danger-bg); color: var(--danger); }
.alert-success { background: var(--success-bg); color: var(--success); }
.alert-warn { background: var(--warn-bg); color: var(--warn); }

/* --- Utility --- */
.stack { display: flex; flex-direction: column; gap: 0.75rem; }
.row { display: flex; align-items: center; gap: 0.75rem; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }
.wrap { flex-wrap: wrap; }
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; }
.text-center { text-align: center; }
.hidden { display: none !important; }

/* --- Responsive --- */
@media (max-width: 640px) {
  .nav-inner { flex-wrap: wrap; gap: 0.6rem; }
  .nav-links { order: 3; width: 100%; gap: 0.75rem; }
  main { padding: 1.25rem 0 3rem; }
  h1 { font-size: 1.35rem; }
}

/* =========================================================================
   Display renderer (served standalone or embedded in PowerPoint). Must
   scale typography/layout to its container at any size — thumbnail up to
   full-slide — so units below lean on cqw/vw rather than fixed px.
   ========================================================================= */
.lp-display {
  width: 100%;
  height: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: transparent;
  color: #1c1e24;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  position: relative;
  /* Promotes this to its own GPU compositing layer. Content add-in webview
     hosts (PowerPoint on Mac, worse in slideshow mode) have a documented
     tendency not to repaint a same-size content update, leaving stale
     pixels ("ghosting") on screen — an already-isolated layer is less
     likely to get skipped. Paired with a per-render nudge in display.js. */
  transform: translateZ(0);
}
.lp-display[data-theme="dark"] { color: #f2f4f7; }
.lp-display[data-theme="light"] { color: #1c1e24; background: #ffffff; }
.lp-display[data-theme="dark"] { background: #14161c; }

.lp-display-inner { flex: 1; display: flex; flex-direction: column; padding: 4%; min-height: 0; }
.lp-prompt { margin: auto; text-align: center; max-width: 90%; }
.lp-prompt-text { font-size: clamp(1.1rem, 4vw, 2.6rem); font-weight: 700; margin-bottom: 1em; }
.lp-prompt-qr { display: flex; flex-direction: column; align-items: center; gap: 0.6em; }
.lp-prompt-qr canvas, .lp-prompt-qr svg { width: min(40vh, 40vw, 260px); height: auto; background: #fff; padding: 6px; border-radius: 8px; }
.lp-prompt-link { font-size: clamp(0.9rem, 2vw, 1.3rem); font-weight: 600; letter-spacing: 0.02em; }
.lp-prompt-code { font-family: ui-monospace, SFMono-Regular, monospace; font-size: clamp(1rem, 2.4vw, 1.6rem); }

.lp-reconnecting {
  position: absolute; bottom: 3%; right: 3%;
  font-size: 0.72rem; padding: 0.3em 0.7em; border-radius: 999px;
  background: rgba(120, 90, 0, 0.85); color: #fff; opacity: 0.9;
}
.lp-blank { position: absolute; inset: 0; background: #000; z-index: 40; }
.lp-blank[hidden] { display: none; }

.lp-toggle-hint { position: absolute; top: 3%; right: 3%; font-size: 0.7rem; opacity: 0.5; }

.lp-moderation-note { position: absolute; bottom: 3%; left: 3%; font-size: 0.72rem; opacity: 0.6; }
.lp-moderation-note[hidden] { display: none; }

/* Bar graph */
.lp-bars { display: flex; flex-direction: column; gap: 0.6em; flex: 1; justify-content: center; }
.lp-bars.horizontal .lp-bar-row { display: flex; align-items: center; gap: 0.6em; }
.lp-bar-label { flex: 0 0 28%; font-size: clamp(0.75rem, 1.6vw, 1.1rem); text-align: right; }
.lp-bar-track { flex: 1; background: rgba(120,120,130,0.18); border-radius: 6px; height: clamp(1em, 4vw, 2em); overflow: hidden; }
.lp-bar-fill { height: 100%; background: var(--brand); border-radius: 6px; transition: width 0.4s ease; }
.lp-bar-fill.correct { background: var(--success); }
.lp-bar-value { flex: 0 0 auto; font-size: clamp(0.7rem, 1.4vw, 1rem); min-width: 2.5em; }

/* Tables */
.lp-table { width: 100%; border-collapse: collapse; font-size: clamp(0.75rem, 2vw, 1.2rem); }
.lp-table td, .lp-table th { padding: 0.4em 0.6em; border-bottom: 1px solid rgba(120,120,130,0.25); }

/* Word cloud / note grid */
.lp-cloud { position: relative; flex: 1; }
.lp-cloud span { position: absolute; white-space: nowrap; font-weight: 700; }
.lp-notegrid { position: relative; flex: 1; }
.lp-note {
  position: absolute; background: var(--bg-raised, #fff); color: #1c1e24; border-radius: 8px;
  padding: 0.5em 0.7em; font-size: clamp(0.55rem, 1.4vw, 0.95rem); box-shadow: 0 1px 4px rgba(0,0,0,0.15);
  max-width: 14em; transition: left 0.6s ease, top 0.6s ease;
}

/* Movie credits */
.lp-credits { flex: 1; overflow: hidden; position: relative; }
.lp-credits-track { position: absolute; left: 0; right: 0; display: flex; flex-direction: column; gap: 1.2em; text-align: center; }
.lp-credits-track div { font-size: clamp(0.9rem, 2.6vw, 1.6rem); }

/* Upvote list */
.lp-upvote-list { display: flex; flex-direction: column; gap: 0.5em; flex: 1; overflow: hidden; }
.lp-upvote-row { display: flex; justify-content: space-between; gap: 0.6em; background: rgba(120,120,130,0.1); border-radius: 8px; padding: 0.5em 0.8em; }
.lp-upvote-text { font-size: clamp(0.75rem, 2vw, 1.15rem); }
.lp-upvote-count { font-weight: 700; font-variant-numeric: tabular-nums; }

/* Continuum / scatter */
.lp-continuum { flex: 1; position: relative; display: flex; align-items: center; }
.lp-continuum-line { position: relative; width: 100%; height: 3px; background: rgba(120,120,130,0.35); border-radius: 3px; }
.lp-continuum-label { position: absolute; top: -2.2em; font-size: clamp(0.7rem, 1.6vw, 1.05rem); font-weight: 600; }
.lp-continuum-label.left { left: 0; }
.lp-continuum-label.right { right: 0; text-align: right; }
.lp-dot { position: absolute; top: 50%; width: 0.9em; height: 0.9em; border-radius: 50%; background: var(--brand); opacity: 0.55; transform: translate(-50%, -50%); }
.lp-dot.mean { width: 1.6em; height: 1.6em; opacity: 1; background: var(--danger); z-index: 2; }
.lp-marker { position: absolute; font-size: clamp(1em, 2.4vw, 1.8em); transform: translate(-50%, -50%); }

.lp-scatter { flex: 1; position: relative; border: 1px solid rgba(120,120,130,0.3); }
.lp-scatter-crosshair { position: absolute; background: rgba(120,120,130,0.25); }
.lp-scatter-axis-label { position: absolute; font-size: clamp(0.65rem, 1.4vw, 1rem); font-weight: 600; }

/* Leaderboard */
.lp-leaderboard { flex: 1; display: flex; flex-direction: column; gap: 0.45em; justify-content: center; }
.lp-leaderboard-row { display: flex; align-items: center; gap: 0.7em; font-size: clamp(0.75rem, 2vw, 1.2rem); }
.lp-leaderboard-rank { font-weight: 800; opacity: 0.6; width: 1.6em; }
.lp-leaderboard-name { flex: 1; }
.lp-leaderboard-score { font-weight: 700; font-variant-numeric: tabular-nums; }

/* Carousel */
.lp-carousel { flex: 1; display: flex; align-items: center; justify-content: center; position: relative; }
.lp-carousel-item { max-width: 100%; max-height: 100%; display: flex; align-items: center; justify-content: center; }
.lp-carousel-item img, .lp-carousel-item svg { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; }

/* Masonry */
.lp-masonry { columns: 3 160px; column-gap: 0.6em; flex: 1; overflow: auto; }
.lp-masonry-item { break-inside: avoid; margin-bottom: 0.6em; border-radius: 8px; overflow: hidden; background: rgba(120,120,130,0.08); }
.lp-masonry-item img, .lp-masonry-item svg { width: 100%; display: block; }
.lp-masonry-item.text-tile { padding: 0.6em 0.8em; font-size: clamp(0.7rem, 1.6vw, 1rem); }
.lp-masonry-item.fade-in { animation: fadein 0.4s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* --- Present view: large touch targets, high contrast --- */
.present-poll-select { font-size: 1.1rem; padding: 0.8rem; }
.present-display {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem;
  background: var(--bg-raised);
}
.present-controls { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 0.6rem; margin-top: 0.75rem; }
.present-controls .btn { padding: 1.1rem 0.5rem; font-size: 1rem; }
.present-panic {
  width: 100%; padding: 1.4rem; font-size: 1.2rem; font-weight: 800; letter-spacing: 0.02em;
  background: var(--danger); color: #fff; border: none; border-radius: var(--radius);
  margin: 1.5rem 0;
}
.present-panic.is-active { background: #7a0f22; }

/* --- Moderation queue --- */
.moderate-card { max-width: 520px; margin: 0 auto; text-align: center; }
.moderate-media { max-width: 100%; max-height: 50vh; border-radius: var(--radius); margin-bottom: 1rem; }
.moderate-actions { display: flex; gap: 1rem; justify-content: center; margin-top: 1.5rem; }
.moderate-actions .btn { width: 5.5rem; height: 5.5rem; border-radius: 50%; font-size: 1.8rem; }

/* --- Respond forms --- */
.respond-container { max-width: 480px; margin: 0 auto; }
.option-list { display: flex; flex-direction: column; gap: 0.5rem; }
.option-item {
  display: flex; align-items: center; gap: 0.6rem; padding: 0.7rem 0.9rem;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; font-weight: 500;
}
.option-item:hover { border-color: var(--brand); }
.option-item.selected { border-color: var(--brand); background: rgba(79, 70, 229, 0.08); }
.slider-input { width: 100%; }
.marker-palette { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.marker-choice { font-size: 1.6rem; padding: 0.3rem 0.5rem; border-radius: var(--radius-sm); border: 2px solid transparent; cursor: pointer; }
.marker-choice.selected { border-color: var(--brand); background: rgba(79, 70, 229, 0.08); }
.whiteboard-canvas { width: 100%; aspect-ratio: 4 / 3; border: 1px solid var(--border); border-radius: var(--radius); touch-action: none; background: #fff; }
.whiteboard-toolbar { display: flex; gap: 0.5rem; margin: 0.6rem 0; flex-wrap: wrap; }
.point2d-plane { width: 100%; aspect-ratio: 1 / 1; border: 1px solid var(--border); border-radius: var(--radius); position: relative; touch-action: none; }
