*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0a0a12;
  --surface: #14141f;
  --text: #f5f5f7;
  --muted: #8b8b9e;
  --accent-a: #ff3b7a;
  --accent-b: #00e5ff;
  --glow-a: rgba(255, 59, 122, 0.55);
  --glow-b: rgba(0, 229, 255, 0.55);
  --success: #34d399;
  --error: #f87171;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --opt-fill: #ff3b7a;
  --opt-glow: rgba(255, 59, 122, 0.55);
  --opt-from: #c9185a;
}

html, body {
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}

body {
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(255, 59, 122, 0.18), transparent),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(0, 229, 255, 0.12), transparent),
    var(--bg);
  min-height: 100%;
}

.hidden { display: none !important; }

#loading-screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  background: var(--bg);
  z-index: 100;
}

.spinner {
  width: 2.5rem;
  height: 2.5rem;
  border: 3px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--accent-a);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.banner-error {
  position: fixed;
  top: calc(var(--safe-top) + 0.5rem);
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 2rem);
  padding: 0.6rem 1rem;
  background: rgba(248, 113, 113, 0.15);
  border: 1px solid var(--error);
  border-radius: 0.5rem;
  color: var(--error);
  font-size: 0.85rem;
  text-align: center;
  z-index: 90;
}

.local-banner {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 0.5rem);
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 2rem);
  padding: 0.4rem 0.75rem;
  background: rgba(251, 191, 36, 0.12);
  border: 1px solid rgba(251, 191, 36, 0.45);
  border-radius: 0.5rem;
  color: #fbbf24;
  font-size: 0.75rem;
  text-align: center;
  z-index: 80;
}

/* ── Audience ── */
#vote-view {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-top) + 2.5rem) 1.25rem calc(var(--safe-bottom) + 2rem);
  text-align: center;
}

.question {
  font-size: clamp(1.6rem, 6vw, 2.4rem);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.02em;
  margin-bottom: 2rem;
  max-width: 22ch;
}

.status-msg {
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.45;
  max-width: 28ch;
}

.status-msg strong {
  color: var(--text);
  display: block;
  font-size: 1.35rem;
  margin-bottom: 0.5rem;
}

.pulse-dot {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 50%;
  background: var(--accent-a);
  box-shadow: 0 0 12px var(--glow-a);
  animation: pulse-dot 1.4s ease-in-out infinite;
  margin: 0 auto 1.25rem;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

.vote-buttons {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: min(100%, 22rem);
}

.vote-btn {
  min-height: 4.5rem;
  padding: 1.1rem 1.5rem;
  font-size: clamp(1.15rem, 4.5vw, 1.45rem);
  font-weight: 700;
  border: none;
  border-radius: 1rem;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(135deg, var(--opt-from), var(--opt-fill));
  box-shadow: 0 6px 28px var(--opt-glow);
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.2s, outline-color 0.15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.vote-btn:active:not(:disabled) { transform: scale(0.97); }

.vote-btn.selected {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

.vote-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.thanks {
  margin-top: 1.75rem;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--success);
  animation: pop-in 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes pop-in {
  from { opacity: 0; transform: scale(0.85) translateY(0.5rem); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* ── Results bars (host + board) ── */
.results {
  width: min(100%, 52rem);
  margin-inline: auto;
}

.host-question,
.board-question {
  font-size: clamp(1.8rem, 5vw, 3rem);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  text-align: center;
  margin-bottom: 0.5rem;
  line-height: 1.1;
}

.host-total,
.board-total {
  text-align: center;
  font-size: clamp(0.95rem, 2.5vw, 1.2rem);
  color: var(--muted);
  margin-bottom: 2rem;
}

.host-total strong,
.board-total strong {
  color: var(--text);
  font-size: 1.35em;
}

.result-block {
  margin-bottom: 1.5rem;
}

.result-block.winner .result-label {
  text-shadow: 0 0 18px var(--opt-glow);
}

.result-block.winner .bar-track {
  box-shadow: 0 0 24px var(--opt-glow);
}

.result-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.6rem;
  gap: 1rem;
}

.result-label {
  font-size: clamp(1.1rem, 3.5vw, 1.6rem);
  font-weight: 800;
  color: var(--opt-fill);
}

.result-stats {
  font-size: clamp(1.4rem, 4vw, 2.2rem);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.result-stats.pulse {
  animation: stat-pulse 0.5s ease;
}

@keyframes stat-pulse {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.12); color: #fff; }
  100% { transform: scale(1); }
}

.bar-track {
  height: clamp(2.5rem, 8vw, 4rem);
  background: rgba(255, 255, 255, 0.06);
  border-radius: 0.75rem;
  overflow: hidden;
  position: relative;
}

.bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 0.75rem;
  background: linear-gradient(90deg, var(--opt-from), var(--opt-fill));
  box-shadow: 0 0 24px var(--opt-glow);
  transition: width 0.7s cubic-bezier(0.22, 1, 0.36, 1);
  position: relative;
}

.bar-fill::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 60%, rgba(255, 255, 255, 0.18));
  animation: shimmer 2.5s ease-in-out infinite;
}

@keyframes shimmer {
  0%, 100% { opacity: 0.3; }
  50%      { opacity: 0.8; }
}

/* ── Host ── */
#host-app {
  min-height: 100%;
  padding: calc(var(--safe-top) + 1.5rem) 1.25rem calc(var(--safe-bottom) + 2rem);
  max-width: 40rem;
  margin: 0 auto;
}

#pin-gate {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.25rem;
  text-align: center;
  gap: 1rem;
}

#pin-gate h1 {
  font-size: 1.6rem;
  font-weight: 800;
}

#pin-gate p {
  color: var(--muted);
  font-size: 0.95rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1.1rem;
}

.field label {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

input[type="text"],
input[type="password"],
input[type="number"] {
  width: 100%;
  min-height: 3rem;
  padding: 0.75rem 1rem;
  font-size: 1.05rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 0.75rem;
}

input:focus-visible {
  outline: 2px solid var(--accent-b);
  outline-offset: 2px;
}

input:disabled {
  opacity: 0.5;
}

input[type="checkbox"] {
  width: 1.4rem;
  height: 1.4rem;
  accent-color: var(--accent-b);
  flex-shrink: 0;
}

.option-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.option-row input { flex: 1; }

.icon-btn,
.btn {
  min-height: 3rem;
  padding: 0.7rem 1.15rem;
  font-size: 0.95rem;
  font-weight: 700;
  border: none;
  border-radius: 0.75rem;
  cursor: pointer;
  color: #fff;
}

.icon-btn {
  min-width: 3rem;
  background: rgba(248, 113, 113, 0.15);
  color: var(--error);
  border: 1px solid rgba(248, 113, 113, 0.35);
}

.btn-primary {
  background: linear-gradient(135deg, #c9185a, var(--accent-a));
  box-shadow: 0 6px 24px var(--glow-a);
  width: 100%;
}

.btn-secondary {
  background: linear-gradient(135deg, #0099b8, var(--accent-b));
  box-shadow: 0 6px 24px var(--glow-b);
  width: 100%;
}

.btn-ghost {
  width: 100%;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--muted);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-row {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin: 1.25rem 0 2rem;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 0;
  margin-bottom: 0.5rem;
  cursor: pointer;
}

.toggle-row span {
  font-size: 0.95rem;
}

.host-status {
  display: inline-block;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 1.25rem;
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
}

.host-status.open {
  background: rgba(52, 211, 153, 0.18);
  color: var(--success);
}

.host-status.closed {
  background: rgba(251, 191, 36, 0.18);
  color: #fbbf24;
}

.host-preview {
  margin-top: 0.5rem;
}

.host-preview .result-stats {
  font-size: 1.2rem;
}

.host-preview .bar-track {
  height: 1.75rem;
}

.link-note {
  margin-top: 1.5rem;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}

.link-note code {
  color: var(--text);
  font-size: 0.85em;
}

/* ── Board ── */
#board-view {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-top) + 2rem) 2rem calc(var(--safe-bottom) + 2rem);
  text-align: center;
}

.board-kicker {
  font-size: clamp(0.9rem, 2vw, 1.2rem);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 0.75rem;
}

#qr-wrap {
  padding: 1rem;
  background: #fff;
  border-radius: 1.25rem;
  margin: 1.5rem auto;
  display: inline-block;
}

#qr-wrap canvas,
#qr-wrap img,
#qr-wrap table {
  display: block;
}

.board-hint {
  color: var(--muted);
  font-size: clamp(1rem, 2.5vw, 1.4rem);
  max-width: 28ch;
}

.board-live-tag {
  display: inline-block;
  margin-bottom: 1rem;
  padding: 0.3rem 0.8rem;
  border-radius: 999px;
  background: rgba(52, 211, 153, 0.18);
  color: var(--success);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.75rem;
}

.board-hidden-msg {
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  font-weight: 800;
  max-width: 18ch;
  line-height: 1.2;
}

.winner-banner {
  margin-top: 1.5rem;
  font-size: clamp(1.4rem, 3.5vw, 2rem);
  font-weight: 900;
  color: var(--success);
}

/* ── Always-on QR ── */
#qr-view {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-top) + 2rem) 2rem calc(var(--safe-bottom) + 2rem);
  text-align: center;
}

#qr-view #qr-wrap canvas {
  width: min(72vmin, 32rem);
  height: auto;
}
