:root {
  --bg-0: #08070d;
  --bg-1: #131127;
  --bg-2: #1d1838;
  --fg: oklch(96% 0.01 280);
  --fg-dim: oklch(70% 0.02 280);
  --accent: oklch(72% 0.22 305);
  --accent-2: oklch(78% 0.18 200);
  --danger: oklch(70% 0.22 25);
  --surface: oklch(20% 0.03 285 / 0.55);
  --surface-strong: oklch(24% 0.04 285 / 0.85);
  --border: oklch(60% 0.05 285 / 0.18);
  --radius: 18px;
  --radius-sm: 12px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --shadow: 0 30px 60px -30px rgba(0,0,0,0.6), 0 0 0 1px var(--border);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 600px at 10% -10%, oklch(40% 0.18 305 / 0.45), transparent 60%),
    radial-gradient(900px 500px at 110% 10%, oklch(45% 0.15 200 / 0.35), transparent 60%),
    linear-gradient(180deg, var(--bg-0) 0%, var(--bg-1) 60%, var(--bg-0) 100%);
  background-attachment: fixed;
  color: var(--fg);
  font-family: ui-sans-serif, system-ui, -apple-system, "Inter", "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-feature-settings: "ss01", "cv11";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body { overflow-x: hidden; }
a { color: var(--accent); text-decoration: none; }
button { font-family: inherit; }

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 18px 80px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  letter-spacing: -0.01em;
  font-size: 22px;
}
.brand .dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 24px var(--accent);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  backdrop-filter: blur(24px) saturate(140%);
  -webkit-backdrop-filter: blur(24px) saturate(140%);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}

h1 {
  font-size: clamp(28px, 6vw, 42px);
  letter-spacing: -0.02em;
  margin: 18px 0 6px;
  line-height: 1.05;
}
h2 { font-size: 20px; margin: 0 0 12px; letter-spacing: -0.01em; }
.sub { color: var(--fg-dim); margin: 0 0 20px; line-height: 1.5; }

.field { display: flex; flex-direction: column; gap: 8px; margin: 14px 0; }
.field label { font-size: 13px; color: var(--fg-dim); }
.input, select, textarea {
  width: 100%;
  background: oklch(15% 0.02 285 / 0.7);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  font-size: 16px;
  outline: none;
  transition: border-color 160ms var(--ease), box-shadow 160ms var(--ease);
}
.input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 4px oklch(72% 0.22 305 / 0.15); }
.input.code { letter-spacing: 0.4em; text-align: center; font-weight: 700; text-transform: uppercase; font-size: 22px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 20px;
  font-size: 16px;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 120ms var(--ease), background 160ms var(--ease), opacity 160ms var(--ease);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0a0612;
}
.btn.ghost { background: transparent; border-color: var(--border); color: var(--fg); }
.btn.danger { background: oklch(35% 0.18 25 / 0.7); color: var(--fg); border: 1px solid oklch(60% 0.2 25 / 0.4); }
.btn.full { width: 100%; }

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

.hint { color: var(--fg-dim); font-size: 13px; }
.error { color: var(--danger); font-size: 14px; margin-top: 6px; min-height: 18px; }

/* camera */
.camera-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 24px;
  overflow: hidden;
  background: oklch(12% 0.02 285);
  border: 1px solid var(--border);
}
.camera-stage video, .camera-stage canvas, .camera-stage img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}
.camera-ring {
  position: absolute; inset: 8px;
  border: 2px dashed oklch(75% 0.15 305 / 0.6);
  border-radius: 22px;
  pointer-events: none;
  animation: pulse 2.4s var(--ease) infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

/* participant grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 14px;
  margin-top: 14px;
}
.tile {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  aspect-ratio: 3 / 4;
  cursor: pointer;
  transition: transform 220ms var(--ease), border-color 160ms var(--ease);
  isolation: isolate;
}
.tile:active { transform: scale(0.97); }
.tile.self { outline: 2px solid var(--accent); outline-offset: -2px; }
.tile img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  z-index: 0;
}
.tile .overlay {
  position: absolute; inset: 0;
  background: linear-gradient(180deg, transparent 40%, rgba(0,0,0,0.78) 100%);
  z-index: 1;
}
.tile .meta {
  position: absolute; left: 12px; right: 12px; bottom: 10px;
  z-index: 2;
  display: flex; align-items: end; justify-content: space-between; gap: 8px;
}
.tile .name {
  font-weight: 700;
  font-size: 14px;
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-shadow: 0 2px 8px rgba(0,0,0,0.7);
}
.tile .votes {
  background: oklch(72% 0.22 305 / 0.95);
  color: #16001e;
  font-weight: 800;
  font-size: 13px;
  padding: 2px 8px;
  border-radius: 999px;
  min-width: 28px;
  text-align: center;
}
.tile .vote-burst {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 56px;
  pointer-events: none;
  opacity: 0;
  z-index: 3;
}
.tile.flash .vote-burst { animation: burst 700ms var(--ease); }
@keyframes burst {
  0% { opacity: 0; transform: scale(0.4); }
  30% { opacity: 1; transform: scale(1.2); }
  100% { opacity: 0; transform: scale(1.6); }
}
.tile.flash { border-color: var(--accent); }

.toolbar {
  position: sticky; top: 10px;
  z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 999px;
  background: var(--surface-strong);
  border: 1px solid var(--border);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  margin-bottom: 14px;
}
.toolbar .code-pill {
  font-weight: 800;
  letter-spacing: 0.3em;
  padding: 6px 12px;
  border-radius: 999px;
  background: oklch(28% 0.04 285 / 0.8);
}

/* status banner */
.banner {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: oklch(40% 0.15 30 / 0.25);
  border: 1px solid oklch(70% 0.18 30 / 0.3);
  color: oklch(95% 0.05 30);
  font-size: 14px;
  margin: 12px 0;
}
.banner.info { background: oklch(40% 0.12 200 / 0.25); border-color: oklch(70% 0.15 200 / 0.3); color: oklch(95% 0.05 200); }
.banner.ok { background: oklch(40% 0.15 145 / 0.25); border-color: oklch(70% 0.18 145 / 0.3); color: oklch(95% 0.06 145); }

/* admin table */
.admin-table { width: 100%; border-collapse: collapse; }
.admin-table th, .admin-table td {
  padding: 10px 8px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.admin-table th { color: var(--fg-dim); font-weight: 500; }
.admin-table tr:hover td { background: oklch(25% 0.03 285 / 0.4); }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.badge.on { background: oklch(40% 0.15 145 / 0.5); color: oklch(95% 0.08 145); }
.badge.off { background: oklch(30% 0.02 285 / 0.6); color: var(--fg-dim); }

.spinner {
  width: 18px; height: 18px;
  border: 2px solid oklch(70% 0.05 285 / 0.4);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 480px) {
  .container { padding: 14px 12px 80px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
  h1 { font-size: 28px; }
}

/* Vote toast */
.toast-host {
  position: fixed;
  inset: 0 0 auto 0;
  top: max(14px, env(safe-area-inset-top));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  pointer-events: none;
  z-index: 9999;
}
.vote-toast {
  --bg: oklch(20% 0.04 280 / 0.85);
  --bd: oklch(70% 0.18 320 / 0.55);
  position: relative;
  pointer-events: auto;
  min-width: min(86vw, 380px);
  max-width: min(92vw, 480px);
  padding: 12px 14px;
  border-radius: 18px;
  background: var(--bg);
  border: 1px solid var(--bd);
  color: #fff;
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  box-shadow: 0 18px 50px -10px rgba(0,0,0,0.55), 0 0 0 1px rgba(255,255,255,0.04) inset;
  transform: translateY(-30px) scale(0.92);
  opacity: 0;
  transition: transform .42s cubic-bezier(.16,1,.3,1), opacity .3s ease;
  overflow: hidden;
  isolation: isolate;
}
.vote-toast.in {
  transform: translateY(0) scale(1);
  opacity: 1;
  animation: toastWiggle 1.6s cubic-bezier(.36,.07,.19,.97) .3s both;
}
.vote-toast.out {
  transform: translateY(-20px) scale(0.96);
  opacity: 0;
}
.vote-toast.me {
  --bd: oklch(78% 0.22 90 / 0.8);
  box-shadow: 0 18px 50px -10px rgba(0,0,0,0.6), 0 0 24px oklch(78% 0.22 90 / 0.45);
}
.vote-toast-glow {
  position: absolute;
  inset: -40%;
  background: conic-gradient(from 0deg,
    oklch(75% 0.22 320),
    oklch(75% 0.22 30),
    oklch(75% 0.22 90),
    oklch(75% 0.22 200),
    oklch(75% 0.22 320));
  filter: blur(40px);
  opacity: 0.45;
  z-index: -1;
  animation: glowSpin 4s linear infinite;
}
.vote-toast-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.vote-toast-avatar {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  object-fit: cover;
  border: 2px solid rgba(255,255,255,0.6);
  flex-shrink: 0;
}
.vote-toast-text {
  flex: 1;
  min-width: 0;
}
.vote-toast-title {
  font-weight: 700;
  font-size: 15px;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.vote-toast-sub {
  margin-top: 2px;
  font-size: 12px;
  opacity: 0.75;
}
.vote-toast-badge {
  font-weight: 800;
  font-size: 18px;
  padding: 6px 12px;
  border-radius: 999px;
  background: linear-gradient(135deg, oklch(80% 0.2 30), oklch(75% 0.22 350));
  color: #1a0a1a;
  box-shadow: 0 6px 18px -4px oklch(70% 0.22 350 / 0.7);
  animation: badgePop .6s cubic-bezier(.34,1.56,.64,1) both;
}
.confetti {
  position: absolute;
  top: 30%;
  width: 8px;
  height: 14px;
  border-radius: 2px;
  pointer-events: none;
  z-index: 2;
  animation: confettiFly 1.2s cubic-bezier(.2,.7,.3,1) forwards;
}
@keyframes toastWiggle {
  0%, 100% { transform: translateY(0) rotate(0); }
  20% { transform: translateY(0) rotate(-1.2deg); }
  40% { transform: translateY(0) rotate(1.2deg); }
  60% { transform: translateY(0) rotate(-0.6deg); }
  80% { transform: translateY(0) rotate(0.6deg); }
}
@keyframes glowSpin {
  to { transform: rotate(1turn); }
}
@keyframes badgePop {
  0% { transform: scale(0.4); opacity: 0; }
  60% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); }
}
@keyframes confettiFly {
  0% { transform: translate(0, 0) rotate(0); opacity: 1; }
  100% { transform: translate(var(--tx), var(--ty)) rotate(var(--rot)); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .vote-toast, .vote-toast.in, .vote-toast-glow, .vote-toast-badge, .confetti {
    animation: none !important;
    transition: opacity .2s ease;
  }
}

/* Profile breakdown modal */
.tile { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.profile-overlay {
  position: fixed;
  inset: 0;
  background: oklch(8% 0.02 280 / 0.6);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s ease;
  z-index: 10000;
}
.profile-overlay.open {
  opacity: 1;
  pointer-events: auto;
}
.profile-card {
  position: relative;
  width: min(96vw, 460px);
  max-height: 84vh;
  overflow: auto;
  background: oklch(18% 0.03 280 / 0.92);
  border: 1px solid oklch(70% 0.18 320 / 0.35);
  border-radius: 22px;
  padding: 18px 18px 22px;
  color: #fff;
  box-shadow: 0 30px 80px -20px rgba(0,0,0,0.6);
  transform: scale(0.95) translateY(8px);
  transition: transform .25s cubic-bezier(.16,1,.3,1);
}
.profile-overlay.open .profile-card {
  transform: scale(1) translateY(0);
}
.profile-close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.08);
  color: #fff;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.profile-close:hover { background: rgba(255,255,255,0.16); }
.profile-head {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 14px;
}
.profile-avatar {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  object-fit: cover;
  border: 2px solid rgba(255,255,255,0.4);
}
.profile-name {
  font-size: 20px;
  font-weight: 700;
}
.profile-total {
  margin-top: 2px;
  font-size: 13px;
  opacity: 0.75;
}
.profile-list-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.65;
  margin: 6px 0 8px;
}
.profile-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.profile-voter {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.06);
}
.profile-voter-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  object-fit: cover;
}
.profile-voter-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.profile-voter-count {
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  background: linear-gradient(135deg, oklch(80% 0.2 30), oklch(75% 0.22 350));
  color: #1a0a1a;
  font-size: 14px;
}
.profile-empty,
.profile-loading {
  padding: 18px 4px;
  text-align: center;
  opacity: 0.7;
  font-size: 14px;
}

/* Scoreboard */
.board-page { padding-top: 22px; }
.board-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.board-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  opacity: 0.85;
}
.board-pill {
  letter-spacing: 0.18em;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.1);
}
.board-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: oklch(70% 0 0 / 0.5);
  display: inline-block;
}
.board-dot.on {
  background: oklch(78% 0.22 145);
  box-shadow: 0 0 0 0 oklch(78% 0.22 145 / 0.7);
  animation: liveDot 1.6s ease-out infinite;
}
@keyframes liveDot {
  0%   { box-shadow: 0 0 0 0 oklch(78% 0.22 145 / 0.6); }
  70%  { box-shadow: 0 0 0 10px oklch(78% 0.22 145 / 0); }
  100% { box-shadow: 0 0 0 0 oklch(78% 0.22 145 / 0); }
}
.board-readonly { opacity: 0.7; margin-top: 0; }
.board-list {
  list-style: none;
  margin: 18px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.board-row {
  display: grid;
  grid-template-columns: 52px 56px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 16px;
  transition: transform .35s cubic-bezier(.16,1,.3,1), background .25s ease, border-color .25s ease;
}
.board-row.pulse {
  animation: rowPulse .9s cubic-bezier(.16,1,.3,1);
}
@keyframes rowPulse {
  0%   { transform: scale(1);    background: rgba(255,255,255,0.04); }
  20%  { transform: scale(1.015); background: oklch(75% 0.18 320 / 0.18); border-color: oklch(75% 0.18 320 / 0.55); }
  100% { transform: scale(1);    background: rgba(255,255,255,0.04); }
}
.board-rank {
  font-weight: 800;
  font-size: 18px;
  text-align: center;
  letter-spacing: 0.02em;
  opacity: 0.8;
}
.board-rank.gold   { color: oklch(85% 0.18 90);  opacity: 1; text-shadow: 0 0 12px oklch(80% 0.2 90 / 0.5); }
.board-rank.silver { color: oklch(85% 0.02 250); opacity: 1; }
.board-rank.bronze { color: oklch(72% 0.13 50);  opacity: 1; }
.board-avatar {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  object-fit: cover;
  border: 1px solid rgba(255,255,255,0.15);
}
.board-info { min-width: 0; }
.board-name {
  font-weight: 700;
  font-size: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.board-bar {
  margin-top: 6px;
  height: 6px;
  background: rgba(255,255,255,0.07);
  border-radius: 999px;
  overflow: hidden;
}
.board-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, oklch(72% 0.22 320), oklch(78% 0.2 30));
  border-radius: 999px;
  transition: width .5s cubic-bezier(.16,1,.3,1);
}
.board-votes {
  font-weight: 800;
  font-size: 22px;
  min-width: 48px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.board-empty {
  padding: 30px 12px;
  text-align: center;
  opacity: 0.7;
  border: 1px dashed rgba(255,255,255,0.12);
  border-radius: 16px;
}
@media (max-width: 480px) {
  .board-row { grid-template-columns: 40px 48px 1fr auto; padding: 10px; gap: 10px; }
  .board-avatar { width: 48px; height: 48px; border-radius: 12px; }
  .board-votes { font-size: 18px; min-width: 36px; }
}

/* Moments gallery */
.profile-moments-btn {
  margin-top: 14px;
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid oklch(70% 0.18 320 / 0.35);
  background: linear-gradient(135deg, oklch(28% 0.06 320 / 0.6), oklch(22% 0.04 280 / 0.6));
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: transform .15s ease, background .2s ease, border-color .2s ease;
}
.profile-moments-btn::before {
  content: '📸  ';
}
.profile-moments-btn::after {
  content: '▾';
  float: right;
  opacity: 0.7;
  transition: transform .2s ease;
}
.profile-moments-btn.open::after {
  transform: rotate(180deg);
}
.profile-moments-btn:hover {
  background: linear-gradient(135deg, oklch(34% 0.08 320 / 0.7), oklch(26% 0.05 280 / 0.7));
}
.profile-moments-btn:disabled {
  opacity: 0.6;
  cursor: wait;
}
.profile-moments {
  margin-top: 12px;
}
.moments-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.moment {
  margin: 0;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.moment img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  cursor: zoom-in;
  display: block;
}
.moment figcaption {
  padding: 6px 8px 8px;
  font-size: 11px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.moment-voter {
  font-weight: 700;
}
.moment-when {
  opacity: 0.6;
}
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 11000;
  padding: 20px;
  animation: lbFade .2s ease;
}
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 12px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.7);
}
@keyframes lbFade {
  from { opacity: 0; }
  to   { opacity: 1; }
}
