:root {
  --red: #c0392b;
  --dark-red: #922b21;
  --green: #27ae60;
  --dark-green: #1e8449;
  --gold: #f39c12;
  --snow: #ecf0f1;
  --dark: #2c3e50;
  --white: #fff;
  --shadow: 0 4px 15px rgba(0,0,0,0.15);

  /* Light mode (default) */
  --bg-primary: linear-gradient(135deg, #fdfcfb 0%, #e2d1c3 100%);
  --bg-card: #fff;
  --bg-card-alt: #f8f9fa;
  --text-primary: #2c3e50;
  --text-secondary: #666;
  --border-color: #e0e0e0;
  --input-bg: #fff;
  --input-border: #ddd;
  --header-bg: linear-gradient(135deg, var(--red), var(--dark-red));
}

[data-theme="dark"] {
  --bg-primary: linear-gradient(135deg, #0f0c29 0%, #1a1a2e 50%, #16213e 100%);
  --bg-card: #1e293b;
  --bg-card-alt: #273449;
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --border-color: #334155;
  --input-bg: #273449;
  --input-border: #475569;
  --header-bg: linear-gradient(135deg, #7f1d1d, #991b1b);
  --snow: #334155;
}

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

body {
  font-family: 'Nunito', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  transition: background 0.4s, color 0.4s;
}

/* ==================== SNOWFLAKES ==================== */
.snowflakes { position: fixed; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 0; }
.snowflake {
  position: absolute; top: -10px; color: #fff; font-size: 1rem; opacity: 0.7;
  animation: fall linear infinite;
}
[data-theme="dark"] .snowflake { opacity: 0.3; }
[data-theme="light"] .snowflake { color: #95a5a6; opacity: 0.6; }
@keyframes fall { to { transform: translateY(100vh) rotate(360deg); opacity: 0; } }

/* ==================== REGISTRATION SCREEN ==================== */
.register-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: var(--bg-primary);
  z-index: 500; display: flex; align-items: center; justify-content: center;
  transition: opacity 0.5s, transform 0.5s;
}
.register-overlay.hidden { opacity: 0; pointer-events: none; transform: scale(1.05); }
.register-box {
  background: var(--bg-card); border-radius: 24px;
  padding: 3rem; max-width: 480px; width: 90%;
  text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  animation: modalIn 0.6s ease;
}
.register-box h1 {
  font-family: 'Mountains of Christmas', cursive;
  color: var(--red); font-size: 2.2rem; margin-bottom: 0.3rem;
}
.register-box .subtitle { color: var(--text-secondary); margin-bottom: 2rem; }
.register-box .event-name { color: var(--gold); font-weight: 700; font-size: 1.1rem; }

/* Avatar picker */
.avatar-picker { display: flex; flex-wrap: wrap; gap: 0.6rem; justify-content: center; margin: 1.5rem 0; }
.avatar-option {
  width: 60px; height: 60px; border-radius: 50%;
  border: 3px solid var(--border-color);
  cursor: pointer; transition: all 0.3s;
  overflow: hidden; padding: 2px;
  background: var(--bg-card-alt);
}
.avatar-option:hover { border-color: var(--gold); transform: scale(1.1); }
.avatar-option.selected { border-color: var(--green); box-shadow: 0 0 15px rgba(39,174,96,0.4); transform: scale(1.15); }
.avatar-option img { width: 100%; height: 100%; border-radius: 50%; }

/* ==================== HEADER ==================== */
header {
  position: relative; z-index: 10;
  background: var(--header-bg);
  padding: 1.2rem 2rem 0.8rem;
  box-shadow: var(--shadow);
  transition: background 0.4s;
}
.header-top {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 0.8rem;
}
.header-title {
  font-family: 'Mountains of Christmas', cursive;
  color: var(--white); font-size: 1.8rem;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}
.header-controls { display: flex; align-items: center; gap: 0.8rem; }

/* User badge */
.user-badge {
  display: flex; align-items: center; gap: 0.5rem;
  background: rgba(255,255,255,0.15);
  border-radius: 50px; padding: 0.3rem 1rem 0.3rem 0.3rem;
  backdrop-filter: blur(10px);
}
.user-badge img { width: 32px; height: 32px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.5); }
.user-badge span { color: var(--white); font-weight: 600; font-size: 0.85rem; }

/* Theme toggle */
.theme-toggle, .lang-toggle {
  background: rgba(255,255,255,0.15);
  border: 2px solid rgba(255,255,255,0.3);
  color: var(--white); width: 38px; height: 38px;
  border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; transition: all 0.3s;
}
.theme-toggle:hover, .lang-toggle:hover {
  background: rgba(255,255,255,0.3); transform: scale(1.1);
}
.lang-toggle { width: auto; padding: 0 0.8rem; border-radius: 20px; font-size: 0.8rem; font-weight: 700; }

nav { display: flex; gap: 0.4rem; justify-content: center; flex-wrap: wrap; }
.nav-btn {
  background: rgba(255,255,255,0.1);
  border: 2px solid rgba(255,255,255,0.2);
  color: var(--white);
  padding: 0.5rem 1rem;
  border-radius: 25px; cursor: pointer;
  font-family: 'Nunito', sans-serif;
  font-weight: 600; font-size: 0.85rem;
  transition: all 0.3s;
}
.nav-btn:hover, .nav-btn.active {
  background: var(--white); color: var(--red); border-color: var(--white);
}

/* ==================== MAIN ==================== */
main {
  position: relative; z-index: 1;
  max-width: 900px; margin: 2rem auto; padding: 0 1rem;
}

.section { display: none; }
.section.active { display: block; animation: fadeIn 0.4s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(15px); } to { opacity: 1; transform: translateY(0); } }
@keyframes modalIn { from { transform: scale(0.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ==================== CARDS ==================== */
.card {
  background: var(--bg-card);
  border-radius: 16px; padding: 2rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
  transition: background 0.4s;
}
.card h2 {
  font-family: 'Mountains of Christmas', cursive;
  color: var(--red); font-size: 1.6rem;
  margin-bottom: 1.5rem;
  border-bottom: 2px solid var(--border-color);
  padding-bottom: 0.5rem;
}
.card h3 { color: var(--green); margin: 1rem 0 0.5rem; }

/* ==================== FORMS ==================== */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 600; margin-bottom: 0.3rem; color: var(--text-primary); }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 0.7rem 1rem;
  border: 2px solid var(--input-border);
  border-radius: 10px; font-family: 'Nunito', sans-serif;
  font-size: 0.95rem; transition: border-color 0.3s;
  background: var(--input-bg); color: var(--text-primary);
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none; border-color: var(--green);
}
.form-group textarea { resize: vertical; min-height: 60px; }
.form-row { display: flex; gap: 1rem; align-items: flex-end; }
.form-row .form-group { flex: 1; }

/* ==================== BUTTONS ==================== */
.btn {
  padding: 0.7rem 1.5rem; border: none; border-radius: 10px;
  font-family: 'Nunito', sans-serif; font-weight: 700; font-size: 0.95rem;
  cursor: pointer; transition: all 0.3s;
  display: inline-flex; align-items: center; gap: 0.5rem;
}
.btn-primary { background: var(--green); color: var(--white); }
.btn-primary:hover { background: var(--dark-green); transform: translateY(-2px); }
.btn-secondary { background: var(--bg-card-alt); color: var(--text-primary); }
.btn-secondary:hover { opacity: 0.8; }
.btn-danger { background: var(--red); color: var(--white); font-size: 0.8rem; padding: 0.4rem 0.8rem; }
.btn-danger:hover { background: var(--dark-red); }
.btn-christmas {
  background: linear-gradient(135deg, var(--red), var(--dark-red));
  color: var(--white); font-size: 1.2rem; padding: 1rem 2.5rem;
  display: block; margin: 1.5rem auto; border-radius: 50px;
  box-shadow: 0 5px 20px rgba(192,57,43,0.4);
}
.btn-christmas:hover { transform: translateY(-3px) scale(1.05); }
.btn-christmas:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-gold { background: var(--gold); color: var(--white); }
.btn-gold:hover { opacity: 0.9; transform: translateY(-2px); }
.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.8rem; }

/* ==================== FAMILY CARDS ==================== */
.family-card {
  background: var(--bg-card); border-radius: 16px;
  padding: 1.5rem; margin-bottom: 1rem;
  box-shadow: var(--shadow); border-left: 5px solid var(--green);
  transition: background 0.4s;
}
.family-card h3 { color: var(--green); margin-bottom: 1rem; display: flex; justify-content: space-between; align-items: center; }
.member-row {
  display: flex; gap: 0.5rem; align-items: center;
  padding: 0.5rem 0; border-bottom: 1px solid var(--border-color);
}
.member-row input {
  flex: 1; padding: 0.5rem;
  border: 1px solid var(--input-border); border-radius: 8px;
  font-family: 'Nunito', sans-serif;
  background: var(--input-bg); color: var(--text-primary);
}
.member-row .btn-danger { flex-shrink: 0; }

/* ==================== WISHLIST ==================== */
.wish-item {
  background: var(--bg-card-alt); border-radius: 12px;
  padding: 1rem; margin-bottom: 1rem;
  border: 2px solid var(--border-color);
}
.wish-item h4 { color: var(--red); margin-bottom: 0.8rem; display: flex; justify-content: space-between; }
.wish-item .form-group { margin-bottom: 0.6rem; }
.wish-item .preview-img {
  max-width: 120px; max-height: 120px;
  border-radius: 8px; margin-top: 0.5rem;
  object-fit: cover; border: 2px solid var(--border-color);
}

/* URL cards */
.url-row {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.6rem; margin-bottom: 0.5rem;
  background: var(--bg-card-alt); border-radius: 10px;
  border: 1px solid var(--border-color);
}
.url-row img { width: 32px; height: 32px; border-radius: 50%; }
.url-row .name { font-weight: 700; flex-shrink: 0; }
.url-row input {
  flex: 1; padding: 0.4rem; font-size: 0.75rem;
  border: 1px solid var(--input-border); border-radius: 6px;
  background: var(--input-bg); color: var(--text-primary);
}
.url-row .btn-sm { flex-shrink: 0; }

/* ==================== ROULETTE ==================== */
.roulette-container {
  position: relative; width: 300px; height: 300px;
  margin: 2rem auto; display: none;
}
.roulette-container.active { display: block; }
.roulette-wheel {
  width: 100%; height: 100%; border-radius: 50%;
  border: 8px solid var(--gold);
  position: relative;
  box-shadow: 0 0 30px rgba(243,156,18,0.4);
}
.roulette-center {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 60px; height: 60px; background: var(--gold);
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; color: var(--white); z-index: 2;
}
.roulette-segment {
  position: absolute; width: 50%; height: 50%; top: 0; right: 0;
  transform-origin: bottom left;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.65rem; font-weight: 700; color: var(--white);
  text-shadow: 1px 1px 2px rgba(0,0,0,0.5); overflow: hidden;
}
.roulette-segment span {
  display: block; transform: rotate(calc(var(--half-angle)));
  position: absolute; top: 25%; left: 55%;
  white-space: nowrap; font-size: 0.6rem;
}
.roulette-pointer {
  position: absolute; top: -15px; left: 50%; transform: translateX(-50%);
  width: 0; height: 0;
  border-left: 15px solid transparent; border-right: 15px solid transparent;
  border-top: 30px solid var(--red); z-index: 3;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

/* ==================== RESULTS ==================== */
#sorteoResults .result-pair {
  background: var(--bg-card-alt); border-radius: 12px;
  padding: 1rem 1.5rem; margin: 0.8rem 0;
  display: flex; align-items: center; gap: 1rem;
  animation: fadeIn 0.5s ease;
  border-left: 4px solid var(--green);
}
#sorteoResults .result-pair .arrow { color: var(--red); font-size: 1.5rem; }
#sorteoResults .result-pair .person { font-weight: 700; font-size: 1.1rem; }

/* ==================== MODAL ==================== */
.modal-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.6); z-index: 100;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(4px);
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--bg-card); border-radius: 20px;
  padding: 2.5rem; max-width: 450px; width: 90%;
  text-align: center; animation: modalIn 0.4s ease;
}
.modal-icon { font-size: 4rem; color: var(--green); margin-bottom: 1rem; }
.modal h2 { font-family: 'Mountains of Christmas', cursive; color: var(--red); margin-bottom: 0.5rem; }
.modal p { color: var(--text-secondary); margin-bottom: 1.5rem; }
.modal-actions { display: flex; gap: 1rem; justify-content: center; }

/* ==================== TOAST ==================== */
.toast {
  position: fixed; bottom: 2rem; right: 2rem;
  padding: 1rem 1.5rem; border-radius: 12px;
  color: var(--white); font-weight: 600;
  z-index: 200; animation: slideIn 0.4s ease;
  max-width: 350px;
}
.toast.hidden { display: none; }
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }
.toast.info { background: #2980b9; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ==================== HELP BOX ==================== */
.help-box {
  background: var(--bg-card-alt); border: 2px solid var(--gold);
  border-radius: 12px; padding: 1.2rem; margin-top: 1.5rem;
}
.help-box h3 { color: var(--gold); font-size: 1rem; margin-bottom: 0.5rem; }
.help-box ol { padding-left: 1.2rem; font-size: 0.85rem; color: var(--text-secondary); }
.help-box li { margin-bottom: 0.3rem; }
.help-box code { background: var(--border-color); padding: 0.1rem 0.4rem; border-radius: 4px; font-size: 0.8rem; }
.help-box a { color: var(--green); }

.info-banner {
  background: linear-gradient(135deg, rgba(243,156,18,0.1), rgba(243,156,18,0.05));
  border: 2px solid var(--gold); border-radius: 10px;
  padding: 0.8rem 1.2rem; color: var(--gold); font-weight: 600;
  margin-bottom: 1rem;
}

.hidden { display: none !important; }

#sorteoStatus { text-align: center; margin-bottom: 1rem; color: var(--text-secondary); }
#sorteoStatus .warning { color: var(--red); font-weight: 600; }
#sorteoStatus .ready { color: var(--green); font-weight: 600; }

/* ==================== RESPONSIVE ==================== */
@media (max-width: 600px) {
  .header-title { font-size: 1.3rem; }
  .header-top { flex-wrap: wrap; gap: 0.5rem; }
  .form-row { flex-direction: column; }
  .roulette-container { width: 250px; height: 250px; }
  .modal-actions { flex-direction: column; }
  .register-box { padding: 2rem 1.5rem; }
  .register-box h1 { font-size: 1.7rem; }
  .avatar-option { width: 48px; height: 48px; }
  nav { gap: 0.3rem; }
  .nav-btn { padding: 0.4rem 0.7rem; font-size: 0.78rem; }
  .url-row { flex-wrap: wrap; }
}
