:root {
  --color-primary: #0052cc;
  --color-primary-hover: #003fa3;
  --color-secondary: #0088ff;
  --color-gold: #fbbf24;
  --color-gold-dark: #f59e0b;
  --color-accent: #059669;
  --color-danger: #dc2626;
  --color-surface: rgba(255, 255, 255, 0.94);
  --color-surface-glass: rgba(255, 255, 255, 0.88);
  --color-text: #0f172a;
  --color-text-muted: #475569;
  --color-border: rgba(15, 23, 42, 0.12);
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --shadow-lg: 0 20px 50px rgba(0, 38, 102, 0.25);
  --shadow-md: 0 10px 28px rgba(0, 38, 102, 0.18);
  --transition: 200ms cubic-bezier(0.22, 1, 0.36, 1);
}

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

html,
body {
  width: 100%;
  height: 100%;
  font-family: "Be Vietnam Pro", system-ui, -apple-system, sans-serif;
  color: var(--color-text);
  background: #0284c7;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.hidden {
  display: none !important;
}

/* Confetti Canvas */
#confettiCanvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 60;
}

/* Full-bleed Stage with QTOO Background */
.stage {
  position: relative;
  width: 100vw;
  height: 100vh;
  background-image: url("assets/bg.jpg?v=2");
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
  overflow: hidden;
}

/* Top-Right Floating Toolbar */
.top-toolbar {
  position: fixed;
  top: 18px;
  right: 22px;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.75);
  box-shadow: 0 8px 24px rgba(0, 56, 148, 0.16);
}

.toolbar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 44px;
  min-height: 44px;
  padding: 0 12px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--color-text);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color var(--transition), color var(--transition), transform var(--transition);
}

.toolbar-btn:hover {
  background: rgba(0, 82, 204, 0.1);
  color: var(--color-primary);
}

.toolbar-btn:active {
  transform: scale(0.96);
}

.toolbar-btn:focus-visible,
.spin-hub:focus-visible,
.chip-btn:focus-visible,
.tab-btn:focus-visible,
.btn:focus-visible,
.icon-close-btn:focus-visible,
.text-btn:focus-visible {
  outline: 3px solid var(--color-gold);
  outline-offset: 2px;
}

.toolbar-btn--primary {
  background: var(--color-primary);
  color: #ffffff;
  padding: 0 16px;
}

.toolbar-btn--primary:hover {
  background: var(--color-primary-hover);
  color: #ffffff;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--color-gold);
  color: #0f172a;
  font-size: 0.78rem;
  font-weight: 800;
}

.icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.icon-sm {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* Main 2-Zone Layout: Left preserves QTOO artwork, Right hosts the Wheel */
.main-layout {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 64px 3.5vw 24px;
}

.left-brand-space {
  flex: 1 1 44%;
  height: 100%;
  pointer-events: none;
}

.wheel-stage {
  flex: 0 0 54%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  position: relative;
}

.wheel-container {
  position: relative;
  width: min(76vh, 47vw, 660px);
  height: min(76vh, 47vw, 660px);
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}

.wheel-glow {
  position: absolute;
  inset: -4%;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(255, 255, 255, 0.65) 0%,
    rgba(56, 189, 248, 0.25) 55%,
    transparent 74%
  );
  pointer-events: none;
  z-index: 0;
}

#wheelCanvas {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100%;
  cursor: pointer;
  border-radius: 50%;
  filter: drop-shadow(0 20px 36px rgba(0, 44, 118, 0.34));
  transition: transform 220ms ease;
}

#wheelCanvas:hover {
  transform: scale(1.008);
}

/* 3 o'clock Pointer */
.wheel-pointer {
  position: absolute;
  right: -22px;
  top: 50%;
  width: 62px;
  height: 46px;
  transform: translateY(-50%);
  transform-origin: 82% 50%;
  z-index: 10;
  pointer-events: none;
  transition: transform 65ms ease-out;
}

.wheel-pointer svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* Center Spin Hub Button */
.spin-hub {
  position: absolute;
  z-index: 8;
  width: 21%;
  height: 21%;
  min-width: 78px;
  min-height: 78px;
  border-radius: 50%;
  border: 5px solid #ffffff;
  background: linear-gradient(145deg, #0066ff 0%, #003ea8 100%);
  color: #ffffff;
  font-family: inherit;
  font-size: clamp(0.95rem, 1.55vw, 1.35rem);
  font-weight: 900;
  letter-spacing: 0.05em;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 10px 24px rgba(0, 35, 102, 0.45),
    inset 0 3px 6px rgba(255, 255, 255, 0.35),
    0 0 0 4px rgba(251, 191, 36, 0.9);
  transition: transform var(--transition), box-shadow var(--transition), filter var(--transition);
}

.spin-hub:hover:not(:disabled) {
  transform: scale(1.06);
  filter: brightness(1.08);
  box-shadow:
    0 14px 30px rgba(0, 35, 102, 0.5),
    inset 0 3px 8px rgba(255, 255, 255, 0.45),
    0 0 0 5px #fde047;
}

.spin-hub:active:not(:disabled) {
  transform: scale(0.96);
}

.spin-hub:disabled {
  cursor: not-allowed;
  opacity: 0.92;
}

.spin-hub__ring {
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.55);
  animation: hubPulse 2.2s infinite ease-out;
  pointer-events: none;
}

.is-spinning .spin-hub__ring {
  animation: none;
  opacity: 0;
}

@keyframes hubPulse {
  0% {
    transform: scale(0.96);
    opacity: 0.7;
  }
  70% {
    transform: scale(1.22);
    opacity: 0;
  }
  100% {
    transform: scale(1.22);
    opacity: 0;
  }
}

.spin-hint {
  padding: 7px 16px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.62);
  backdrop-filter: blur(8px);
  color: #ffffff;
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  transition: opacity var(--transition);
}

.spin-hint kbd {
  display: inline-block;
  padding: 1px 7px;
  margin: 0 2px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.35);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 700;
}

.is-spinning .spin-hint {
  opacity: 0;
}

/* Slide-over Drawer (Left) */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.28);
  backdrop-filter: blur(2px);
  z-index: 35;
}

.drawer {
  position: fixed;
  top: 16px;
  left: 16px;
  bottom: 16px;
  width: min(390px, calc(100vw - 32px));
  z-index: 40;
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid rgba(255, 255, 255, 0.85);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  transform: translateX(calc(-100% - 32px));
  transition: transform 280ms cubic-bezier(0.22, 1, 0.36, 1);
  overflow: hidden;
}

.drawer.open {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--color-border);
  background: rgba(248, 250, 252, 0.8);
}

.tabs {
  display: flex;
  gap: 6px;
  background: rgba(15, 23, 42, 0.06);
  padding: 4px;
  border-radius: 12px;
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 12px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--color-text-muted);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color var(--transition), color var(--transition);
}

.tab-btn.active {
  background: #ffffff;
  color: var(--color-primary);
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.08);
}

.tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: rgba(0, 82, 204, 0.12);
  color: var(--color-primary);
  font-size: 0.75rem;
  font-weight: 800;
}

.icon-close-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: background-color var(--transition), color var(--transition);
}

.icon-close-btn:hover {
  background: rgba(15, 23, 42, 0.08);
  color: var(--color-text);
}

.drawer-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 14px 16px 16px;
  gap: 12px;
  overflow: hidden;
}

.action-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 11px;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  background: #ffffff;
  color: var(--color-text);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

.chip-btn:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: #f0f6ff;
}

.chip-btn--danger:hover {
  border-color: var(--color-danger);
  color: var(--color-danger);
  background: #fef2f2;
}

.entries-textarea {
  flex: 1;
  width: 100%;
  resize: none;
  padding: 14px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  background: #ffffff;
  color: var(--color-text);
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.65;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.entries-textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(0, 82, 204, 0.16);
}

.drawer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 4px;
}

.text-btn {
  border: none;
  background: transparent;
  color: var(--color-primary);
  font-family: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color var(--transition);
}

.text-btn:hover {
  background: rgba(0, 82, 204, 0.08);
}

.text-btn--danger {
  color: var(--color-danger);
}

.text-btn--danger:hover {
  background: rgba(220, 38, 38, 0.08);
}

/* Results List */
.results-list {
  flex: 1;
  overflow-y: auto;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 4px;
}

.result-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 14px;
  border-radius: 12px;
  background: #ffffff;
  border: 1px solid var(--color-border);
}

.result-item__left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.result-rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 800;
  flex-shrink: 0;
}

.result-name {
  font-weight: 700;
  font-size: 0.94rem;
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-time {
  font-size: 0.76rem;
  color: var(--color-text-muted);
  flex-shrink: 0;
}

.empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.92rem;
  padding: 24px;
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.52);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: fadeIn 180ms ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  width: 100%;
  background: #ffffff;
  border-radius: var(--radius-lg);
  box-shadow: 0 28px 70px rgba(0, 30, 84, 0.38);
  overflow: hidden;
  animation: popIn 240ms cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.92) translateY(12px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-card--winner {
  max-width: 520px;
  padding: 36px 28px 28px;
  text-align: center;
  border: 3px solid var(--color-gold);
  background: linear-gradient(180deg, #ffffff 0%, #f0f7ff 100%);
}

.winner-badge {
  width: 68px;
  height: 68px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: linear-gradient(135deg, #fde047 0%, #f59e0b 100%);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 24px rgba(245, 158, 11, 0.38);
}

.winner-badge svg {
  width: 34px;
  height: 34px;
}

.winner-eyebrow {
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--color-primary);
  margin-bottom: 10px;
}

.winner-name {
  font-size: clamp(1.8rem, 4vw, 2.75rem);
  font-weight: 900;
  color: #0f172a;
  line-height: 1.2;
  margin-bottom: 26px;
  word-break: break-word;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.modal-actions--end {
  justify-content: flex-end;
  padding: 16px 24px 20px;
  border-top: 1px solid var(--color-border);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 20px;
  border-radius: 12px;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: all var(--transition);
}

.btn--primary {
  background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
  color: #ffffff;
  box-shadow: 0 6px 18px rgba(0, 82, 204, 0.28);
}

.btn--primary:hover {
  filter: brightness(1.07);
  transform: translateY(-1px);
}

.btn--secondary {
  background: #f1f5f9;
  color: var(--color-text);
}

.btn--secondary:hover {
  background: #e2e8f0;
}

.btn--danger-outline {
  background: #ffffff;
  border-color: rgba(220, 38, 38, 0.35);
  color: var(--color-danger);
}

.btn--danger-outline:hover {
  background: #fef2f2;
  border-color: var(--color-danger);
}

/* Settings Modal */
.modal-card--settings {
  max-width: 440px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--color-border);
}

.modal-header h2 {
  font-size: 1.1rem;
  font-weight: 800;
}

.settings-body {
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.setting-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.setting-row label {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--color-text);
}

.setting-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.setting-value {
  font-size: 0.86rem;
  font-weight: 800;
  color: var(--color-primary);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--color-primary);
  cursor: pointer;
}

.select-input,
.text-input {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1.5px solid var(--color-border);
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.92rem;
  color: var(--color-text);
  background: #ffffff;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  min-height: 36px;
}

.toggle-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--color-primary);
  cursor: pointer;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 70;
  padding: 10px 18px;
  border-radius: 999px;
  background: #0f172a;
  color: #ffffff;
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.25);
}

/* Responsive Breakpoints */
@media (max-width: 960px) {
  .stage {
    background-position: left center;
  }

  .main-layout {
    flex-direction: column;
    justify-content: center;
    padding: 74px 16px 20px;
  }

  .left-brand-space {
    display: none;
  }

  .wheel-stage {
    flex: 1;
    width: 100%;
  }

  .wheel-container {
    width: min(74vw, 66vh, 520px);
    height: min(74vw, 66vh, 520px);
  }
}

@media (max-width: 520px) {
  .top-toolbar {
    top: 12px;
    right: 12px;
    gap: 4px;
    padding: 5px;
  }

  .toolbar-btn--primary span:not(.badge) {
    display: none;
  }

  .wheel-container {
    width: min(86vw, 62vh);
    height: min(86vw, 62vh);
  }

  .wheel-pointer {
    width: 48px;
    height: 36px;
    right: -16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .spin-hub__ring {
    animation: none;
  }
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }
}

/* Live Admin Sync Controls */
.toolbar-sync-label {
  font-size: 0.86rem;
  font-weight: 700;
}

@media (max-width: 640px) {
  .toolbar-sync-label {
    display: none;
  }
}

@keyframes spinIcon {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.is-spinning-icon {
  animation: spinIcon 0.8s linear infinite;
}

.sync-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border-radius: 14px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
}

.sync-modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.sync-mode-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.72);
  color: #334155;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 180ms ease, color 180ms ease, border-color 180ms ease;
}

.sync-mode-btn:hover {
  background: #ffffff;
  color: #0052cc;
}

.sync-mode-btn.active {
  background: #0052cc;
  color: #ffffff;
  box-shadow: 0 3px 10px rgba(0, 82, 204, 0.25);
}

.sync-mode-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 19px;
  padding: 0 6px;
  border-radius: 9999px;
  background: rgba(15, 23, 42, 0.1);
  font-size: 0.72rem;
  font-weight: 800;
}

.sync-mode-btn.active .sync-mode-count {
  background: rgba(255, 255, 255, 0.24);
  color: #ffffff;
}

.sync-status {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 600;
  color: #1e40af;
  text-align: center;
}
