@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@500;600;700&family=DM+Sans:ital,wght@0,400;0,500;0,700;1,400&display=swap');

:root {
  /* ---- Carnival-ticket palette: bright paper + confetti pink/gold/violet ---- */
  --ink: #2B0A3D;
  --ink-soft: #6B5C77;
  --bg: #FFFBF2;
  --surface: #FFFFFF;
  --surface-sunk: #FBF3FF;

  --primary: #FF2E86;
  --primary-ink: #FFFFFF;
  --primary-deep: #D4126A;

  --gold: #FFB703;
  --gold-ink: #3A2300;

  --violet: #5B2EFF;
  --violet-text: #4C1D95;
  --violet-ink: #FFFFFF;

  --success: #13A463;
  --success-ink: #FFFFFF;

  --danger: #E8406B;

  --border: #F0DCF0;
  --border-strong: #E3C6EC;

  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-pill: 999px;

  --shadow-pop: 0 2px 0 var(--border-strong), 0 14px 28px -14px rgba(43, 10, 61, 0.28);
  --shadow-pop-sm: 0 2px 0 var(--border-strong), 0 8px 16px -10px rgba(43, 10, 61, 0.22);

  --font-display: 'Fredoka', sans-serif;
  --font-body: 'DM Sans', sans-serif;

  font-family: var(--font-body);
  color-scheme: light;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 8px 8px, rgba(255, 46, 134, 0.07) 2px, transparent 2.5px),
    radial-gradient(circle at 46px 30px, rgba(91, 46, 255, 0.06) 2px, transparent 2.5px),
    radial-gradient(circle at 26px 54px, rgba(255, 183, 3, 0.09) 2.5px, transparent 3px),
    var(--bg);
  background-size: 64px 64px, 64px 64px, 64px 64px, auto;
  min-height: 100vh;
}

.hidden { display: none !important; }

#confettiCanvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 999;
}

.screen.centered {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

/* ---------------- Cards ---------------- */
.card {
  position: relative;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  margin: 20px auto;
  max-width: 820px;
  box-shadow: var(--shadow-pop);
}

h1 {
  font-family: var(--font-display);
  font-weight: 600;
  margin: 0 0 4px;
  font-size: 1.6rem;
  letter-spacing: -0.01em;
}
h2 {
  font-family: var(--font-display);
  font-weight: 600;
  margin-top: 0;
  font-size: 1.2rem;
  color: var(--ink);
}
h3 { font-family: var(--font-display); font-weight: 600; font-size: 1.05rem; }

.muted { color: var(--ink-soft); font-size: 0.9rem; }
.error { color: var(--danger); font-weight: 500; min-height: 1.2em; font-size: 0.9rem; }

label { font-size: 0.85rem; color: var(--ink-soft); display: flex; flex-direction: column; gap: 6px; font-weight: 500; }

input[type="text"], input[type="password"], input[type="number"], textarea {
  background: var(--surface-sunk);
  border: 2px solid var(--border);
  color: var(--ink);
  border-radius: var(--radius-md);
  padding: 11px 14px;
  font-size: 0.95rem;
  width: 100%;
  font-family: var(--font-body);
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
input:focus-visible, textarea:focus-visible {
  outline: none;
  border-color: var(--violet);
  box-shadow: 0 0 0 4px rgba(91, 46, 255, 0.15);
}
textarea { resize: vertical; }

/* ---------------- Buttons ---------------- */
.btn {
  border: none;
  border-radius: var(--radius-pill);
  padding: 11px 22px;
  font-size: 0.95rem;
  font-family: var(--font-body);
  cursor: pointer;
  margin-top: 10px;
  color: white;
  font-weight: 700;
  min-height: 44px;
  transition: transform 150ms ease, box-shadow 150ms ease, filter 150ms ease;
}
.btn:active:not(:disabled) { transform: translateY(1px) scale(0.99); }
.btn:focus-visible { outline: 3px solid var(--violet); outline-offset: 2px; }

.btn.primary { background: var(--primary); box-shadow: var(--shadow-pop-sm); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.05); box-shadow: 0 4px 0 var(--primary-deep); transform: translateY(-2px); }

.btn.ghost { background: var(--surface); border: 2px solid var(--border-strong); color: var(--ink); }
.btn.ghost:hover { background: var(--surface-sunk); }

.btn.danger { background: var(--danger); }

.btn.big {
  font-family: var(--font-display);
  font-size: 1.15rem;
  padding: 16px 28px;
  width: 100%;
  background: linear-gradient(135deg, var(--primary), var(--violet));
  box-shadow: var(--shadow-pop);
  animation: breathe 2.6s ease-in-out infinite;
}
.btn.big:hover:not(:disabled) { animation-play-state: paused; transform: translateY(-2px) scale(1.01); }
.btn.big:disabled { animation: none; }
@keyframes breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.015); }
}

.btn:disabled { opacity: 0.45; cursor: not-allowed; filter: none; transform: none; }

.btn .icon { vertical-align: -3px; margin-right: 6px; }

/* ---------------- Login: the ticket ---------------- */
.login-card {
  display: flex;
  width: 460px;
  max-width: 100%;
  padding: 0;
  overflow: hidden;
  animation: ticket-in 480ms cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes ticket-in {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.ticket-stub {
  position: relative;
  width: 108px;
  flex-shrink: 0;
  background: linear-gradient(165deg, var(--violet), var(--primary));
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 0;
}
.ticket-stub-label {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-family: var(--font-display);
  font-weight: 600;
  color: white;
  letter-spacing: 0.08em;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 10px;
}

.perforation {
  position: relative;
  width: 0;
  border-left: 3px dashed rgba(255, 255, 255, 0.65);
}
.perforation::before, .perforation::after {
  content: "";
  position: absolute;
  left: -10px;
  width: 20px;
  height: 20px;
  background: var(--bg);
  border-radius: 50%;
}
.perforation::before { top: -10px; }
.perforation::after { bottom: -10px; }

.login-main { flex: 1; padding: 32px 28px; text-align: left; }
.login-main .brand-row { display: flex; align-items: center; gap: 10px; margin-bottom: 2px; }
.login-main label { margin: 14px 0; }

/* ---------------- Topbar ---------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  border-bottom: 3px solid var(--border);
  background: var(--surface);
}
.brand-row { display: flex; align-items: center; gap: 10px; }
.topbar nav { display: flex; gap: 8px; align-items: center; }

.tab-btn {
  background: transparent;
  border: none;
  color: var(--ink-soft);
  padding: 9px 16px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  font-weight: 700;
  font-family: var(--font-body);
  min-height: 40px;
  transition: background 150ms ease, color 150ms ease;
}
.tab-btn:hover { background: var(--surface-sunk); }
.tab-btn.active { background: var(--ink); color: white; }

.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.checkbox-row { flex-direction: row; align-items: center; gap: 10px; margin-top: 14px; }
input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--violet); cursor: pointer; }

/* ---------------- Step badge (numbered, since this IS a sequence) ---------------- */
.card > h2 { display: flex; align-items: center; gap: 12px; }
.step-no {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--gold);
  color: var(--gold-ink);
  font-family: var(--font-display);
  font-size: 0.95rem;
  flex-shrink: 0;
}

/* ---------------- Links list ---------------- */
.links-list { margin-top: 14px; display: flex; flex-direction: column; gap: 10px; }

.link-chip {
  background: var(--surface-sunk);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  animation: pop-in 260ms ease both;
}

@keyframes pop-in {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.link-chip .platform-badge {
  font-family: var(--font-display);
  font-size: 0.72rem;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: var(--violet);
  color: white;
  font-weight: 600;
}

.link-chip .url-text {
  font-size: 0.8rem;
  color: var(--ink-soft);
  word-break: break-all;
  flex: 1;
  min-width: 200px;
}

.remove-link {
  background: transparent;
  border: none;
  color: var(--danger);
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 150ms ease;
}
.remove-link:hover { background: rgba(232, 64, 107, 0.12); }

#sourcesConfig .source-row {
  background: var(--surface-sunk);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 10px;
}

.source-row .toggles { display: flex; gap: 20px; margin-top: 10px; flex-wrap: wrap; }
.source-row label.checkbox-inline { flex-direction: row; align-items: center; gap: 8px; font-size: 0.88rem; }

.status-log {
  margin-top: 12px;
  font-size: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.status-log .ok { color: var(--success); font-weight: 600; }
.status-log .err { color: var(--danger); font-weight: 600; }

.participants-preview {
  margin: 16px 0;
  font-size: 0.95rem;
  color: var(--ink-soft);
}
.participants-preview strong { color: var(--ink); font-family: var(--font-display); }

/* ---------------- Winner ticket stubs ---------------- */
#resultsContent { display: flex; flex-direction: column; gap: 10px; margin: 14px 0; }

.winner-card, .sub-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 2px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-pop-sm);
  opacity: 0;
  animation: ticket-pop 520ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes ticket-pop {
  from { opacity: 0; transform: translateX(-10px) scale(0.96); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}

.ticket-chip {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.1rem;
  min-width: 44px;
  height: 44px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: white;
}
.ticket-chip.rank-1 { background: linear-gradient(145deg, #FFD85C, var(--gold)); color: var(--gold-ink); }
.ticket-chip.rank-2 { background: linear-gradient(145deg, #CFE3FF, #93A9C9); color: #1A2A3D; }
.ticket-chip.rank-3 { background: linear-gradient(145deg, #F3C9A0, #C98A54); color: #3A2200; }
.ticket-chip.rank-other { background: linear-gradient(145deg, var(--violet), var(--primary)); }
.ticket-chip.sub { background: var(--surface-sunk); color: var(--violet-text); border: 2px dashed var(--border-strong); }

.winner-name { font-family: var(--font-display); font-weight: 600; font-size: 1.02rem; }

/* ---------------- Modal ---------------- */
.modal {
  position: fixed; inset: 0;
  background: rgba(43, 10, 61, 0.45);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  animation: fade-in 180ms ease;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal-box {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 26px;
  width: 480px;
  max-width: 90vw;
  box-shadow: var(--shadow-pop);
  animation: ticket-in 220ms cubic-bezier(0.22, 1, 0.36, 1);
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

.history-item {
  background: var(--surface-sunk);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 10px;
}

code {
  background: var(--surface-sunk);
  padding: 1px 6px;
  border-radius: 6px;
  font-size: 0.85em;
}

@media (max-width: 640px) {
  .card { padding: 20px; margin: 14px 12px; }
  .grid2 { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; gap: 10px; align-items: flex-start; }
  .login-card { flex-direction: column; width: 100%; }
  .ticket-stub { width: 100%; flex-direction: row; padding: 14px; }
  .ticket-stub-label { writing-mode: horizontal-tb; transform: none; }
  .perforation { width: 100%; height: 0; border-left: none; border-top: 3px dashed rgba(255,255,255,0.65); }
  .perforation::before, .perforation::after { top: -10px; }
  .perforation::before { left: -10px; }
  .perforation::after { left: auto; right: -10px; }
}
