:root {
  --bg-base: #0b0f19;
  --bg-surface: rgba(20, 27, 45, 0.78);
  --bg-surface-elevated: rgba(30, 41, 66, 0.85);
  --bg-glass: rgba(255, 255, 255, 0.05);
  --border-subtle: rgba(255, 255, 255, 0.09);
  --border-highlight: rgba(255, 255, 255, 0.18);

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent-primary: #f43f5e;
  --accent-primary-hover: #e11d48;
  --accent-secondary: #f59e0b;
  --accent-emerald: #10b981;
  --accent-indigo: #6366f1;

  --gradient-festive: linear-gradient(135deg, #f43f5e 0%, #e11d48 50%, #be123c 100%);
  --gradient-gold: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
  --gradient-emerald: linear-gradient(135deg, #34d399 0%, #059669 100%);
  --gradient-mystery: linear-gradient(135deg, #4f46e5 0%, #7c3aed 50%, #db2777 100%);

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --radius-xl: 28px;
  --radius-full: 9999px;

  --shadow-soft: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 8px 25px -4px rgba(244, 63, 94, 0.4);
  --shadow-gold: 0 8px 25px -4px rgba(245, 158, 11, 0.35);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  min-height: 100dvh;
  background-color: var(--bg-base);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Ambient Background Orbs */
.ambient-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.28;
  animation: floatOrb 18s ease-in-out infinite alternate;
}

.orb-1 {
  width: 340px;
  height: 340px;
  background: #f43f5e;
  top: -100px;
  right: -80px;
}

.orb-2 {
  width: 300px;
  height: 300px;
  background: #6366f1;
  bottom: 8%;
  left: -110px;
  animation-delay: -6s;
}

.orb-3 {
  width: 240px;
  height: 240px;
  background: #f59e0b;
  top: 42%;
  right: -90px;
  opacity: 0.16;
  animation-delay: -11s;
}

@keyframes floatOrb {
  0% { transform: translate(0, 0) scale(1); }
  100% { transform: translate(-25px, 35px) scale(1.1); }
}

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

/* Main App Container */
.app-shell {
  position: relative;
  z-index: 1;
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: calc(var(--safe-top) + 12px);
  padding-bottom: calc(var(--safe-bottom) + 96px);
  padding-left: 16px;
  padding-right: 16px;
}

/* Top Header */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 4px 18px;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  cursor: pointer;
  user-select: none;
}

.brand-icon {
  width: 40px;
  height: 40px;
  border-radius: 13px;
  background: var(--gradient-festive);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-glow);
  font-size: 20px;
  flex-shrink: 0;
}

.brand-text h1 {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.brand-text span {
  display: block;
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  padding: 5px 11px 5px 6px;
  border-radius: var(--radius-full);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.2s ease;
}

.user-pill:active {
  transform: scale(0.96);
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.78rem;
  color: #fff;
  flex-shrink: 0;
  text-transform: uppercase;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);
}

.avatar-lg {
  width: 48px;
  height: 48px;
  font-size: 1.15rem;
}

.avatar-xl {
  width: 68px;
  height: 68px;
  font-size: 1.65rem;
}

/* Cards & Surfaces */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow-soft);
  margin-bottom: 16px;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.card-interactive {
  cursor: pointer;
}

.card-interactive:hover {
  border-color: var(--border-highlight);
}

.card-interactive:active {
  transform: scale(0.985);
}

/* Auth Screen */
.auth-wrapper {
  margin: auto 0;
  padding: 16px 0;
}

.auth-hero {
  text-align: center;
  margin-bottom: 26px;
}

.auth-hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  background: rgba(244, 63, 94, 0.14);
  border: 1px solid rgba(244, 63, 94, 0.3);
  color: #fda4af;
  font-size: 0.78rem;
  font-weight: 600;
  margin-bottom: 14px;
}

.auth-hero h1 {
  font-size: 1.95rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 8px;
  background: linear-gradient(135deg, #ffffff 0%, #cbd5e1 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.auth-hero p {
  color: var(--text-secondary);
  font-size: 0.93rem;
  max-width: 360px;
  margin: 0 auto;
}

.segmented-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: rgba(15, 23, 42, 0.75);
  padding: 4px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  margin-bottom: 20px;
}

.segmented-tab {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.segmented-tab.active {
  background: var(--bg-surface-elevated);
  color: var(--text-primary);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}

/* Forms & Inputs */
.form-group {
  margin-bottom: 15px;
  min-width: 0;
  width: 100%;
}

.form-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  color: #cbd5e1;
  margin-bottom: 6px;
}

.form-label span.optional {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 0.75rem;
}

.form-input, .form-select, .form-textarea {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 13px 15px;
  color: var(--text-primary);
  color-scheme: dark;
  font-size: 16px; /* 16px prevents iOS Safari auto-zoom on focus! */
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input[type="date"].form-input {
  min-height: 50px;
  line-height: 1.4;
}

input[type="date"].form-input::-webkit-date-and-time-value {
  text-align: left;
  margin: 0;
}

.form-textarea {
  resize: vertical;
  min-height: 76px;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(244, 63, 94, 0.18);
}

.form-input::placeholder, .form-textarea::placeholder {
  color: var(--text-muted);
}

/* Buttons */
.btn {
  appearance: none;
  border: none;
  border-radius: var(--radius-md);
  padding: 13px 18px;
  font-size: 0.95rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.14s ease, opacity 0.2s ease, box-shadow 0.2s ease;
  user-select: none;
  text-decoration: none;
}

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

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--gradient-festive);
  color: #fff;
  box-shadow: var(--shadow-glow);
}

.btn-gold {
  background: var(--gradient-gold);
  color: #0f172a;
  box-shadow: var(--shadow-gold);
}

.btn-secondary {
  background: var(--bg-surface-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-highlight);
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.14);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-sm {
  padding: 8px 13px;
  font-size: 0.82rem;
  border-radius: 12px;
}

/* Quick Actions Row */
.quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 22px;
}

.action-tile {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  text-align: left;
  color: var(--text-primary);
  transition: transform 0.15s ease, border-color 0.2s ease;
}

.action-tile:active {
  transform: scale(0.97);
}

.action-tile-primary {
  background: linear-gradient(145deg, rgba(244, 63, 94, 0.2), rgba(20, 27, 45, 0.85));
  border-color: rgba(244, 63, 94, 0.35);
}

.action-tile-secondary {
  background: linear-gradient(145deg, rgba(99, 102, 241, 0.2), rgba(20, 27, 45, 0.85));
  border-color: rgba(99, 102, 241, 0.35);
}

.action-tile-icon {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  background: rgba(255, 255, 255, 0.08);
}

.action-tile h3 {
  font-size: 0.96rem;
  font-weight: 700;
  line-height: 1.2;
}

.action-tile p {
  font-size: 0.77rem;
  color: var(--text-secondary);
  line-height: 1.3;
}

/* Section Headers */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  padding: 0 2px;
}

.section-title {
  font-size: 0.98rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 7px;
  line-height: 1.25;
  min-width: 0;
}

/* Badges & Pills */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 5px 11px;
  border-radius: var(--radius-full);
  font-size: 0.73rem;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: 0.01em;
  white-space: nowrap;
  flex-shrink: 0;
  text-align: center;
}

.badge-open {
  background: rgba(245, 158, 11, 0.15);
  color: #fcd34d;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.badge-drawn {
  background: rgba(16, 185, 129, 0.16);
  color: #6ee7b7;
  border: 1px solid rgba(16, 185, 129, 0.32);
}

.badge-budget {
  background: rgba(99, 102, 241, 0.16);
  color: #a5b4fc;
  border: 1px solid rgba(99, 102, 241, 0.3);
}

.badge-owner {
  background: rgba(244, 63, 94, 0.16);
  color: #fda4af;
  border: 1px solid rgba(244, 63, 94, 0.3);
}

/* Group List Card */
.group-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.group-card-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 3px;
}

.group-card-sub {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.group-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
}

/* Invite Code Banner */
.invite-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(15, 23, 42, 0.65);
  border: 1px dashed rgba(255, 255, 255, 0.22);
  border-radius: var(--radius-md);
  padding: 12px 15px;
  margin-top: 14px;
}

.invite-code-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  display: block;
}

.invite-code-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: #fde047;
}

/* Secret Santa Reveal Box */
.reveal-card {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-xl);
  padding: 24px 20px;
  margin-bottom: 18px;
  text-align: center;
  background: var(--gradient-mystery);
  box-shadow: 0 14px 35px -8px rgba(124, 58, 237, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.22);
}

.reveal-card.revealed {
  background: linear-gradient(145deg, #1e1b4b 0%, #31102f 60%, #0f172a 100%);
  border-color: rgba(251, 191, 36, 0.45);
}

.reveal-mystery-icon {
  width: 68px;
  height: 68px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.1rem;
  margin: 0 auto 14px;
  animation: pulseGift 2.2s infinite ease-in-out;
}

@keyframes pulseGift {
  0%, 100% { transform: scale(1) rotate(0deg); }
  25% { transform: scale(1.06) rotate(-4deg); }
  75% { transform: scale(1.06) rotate(4deg); }
}

.reveal-peer-name {
  font-size: 1.65rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  color: #fde047;
  margin: 8px 0 4px;
}

.reveal-peer-username {
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.75);
  margin-bottom: 16px;
}

/* Member List Item */
.member-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.member-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(15, 23, 42, 0.55);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px 14px;
}

.member-info {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.member-name {
  font-weight: 700;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  line-height: 1.25;
}

.member-sub {
  font-size: 0.76rem;
  color: var(--text-secondary);
}

/* Wishlist Items */
.wishlist-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.wish-item {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.wish-content {
  flex: 1;
  min-width: 0;
}

.wish-title {
  font-weight: 700;
  font-size: 0.96rem;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.wish-note {
  font-size: 0.83rem;
  color: var(--text-secondary);
  margin-top: 4px;
  word-break: break-word;
}

.wish-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 7px;
  font-size: 0.78rem;
  font-weight: 600;
  color: #38bdf8;
  text-decoration: none;
}

.wish-link:hover {
  text-decoration: underline;
}

.priority-dot {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-weight: 700;
}

.prio-3 {
  background: rgba(244, 63, 94, 0.18);
  color: #fda4af;
}

.prio-2 {
  background: rgba(245, 158, 11, 0.16);
  color: #fcd34d;
}

.prio-1 {
  background: rgba(148, 163, 184, 0.15);
  color: #cbd5e1;
}

/* Bottom Mobile Navigation Bar */
.bottom-nav {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 12px);
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 32px);
  max-width: 460px;
  background: rgba(15, 23, 42, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 24px;
  padding: 6px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.6);
  z-index: 40;
}

.bottom-nav.has-admin {
  grid-template-columns: repeat(4, 1fr);
}

.nav-item {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  padding: 8px 6px;
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.nav-item svg {
  width: 21px;
  height: 21px;
  stroke-width: 2.1;
}

.nav-item.active {
  background: rgba(244, 63, 94, 0.16);
  color: #fda4af;
}

/* Modal Bottom Sheet (Mobile Friendly) */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 7, 18, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 80;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 1;
  transition: opacity 0.2s ease;
}

.modal-backdrop.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal-sheet {
  width: 100%;
  max-width: 540px;
  max-height: 90dvh;
  overflow-x: hidden;
  overflow-y: auto;
  background: #131c31;
  border-top: 1px solid var(--border-highlight);
  border-radius: 28px 28px 0 0;
  padding: 22px 20px calc(var(--safe-bottom) + 24px);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.6);
  transform: translateY(0);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-backdrop.hidden .modal-sheet {
  transform: translateY(100%);
}

@media (min-width: 600px) {
  .modal-backdrop {
    align-items: center;
    padding: 20px;
  }
  .modal-sheet {
    border-radius: 26px;
    border: 1px solid var(--border-highlight);
    padding: 24px;
  }
}

.sheet-handle {
  width: 42px;
  height: 5px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 99px;
  margin: 0 auto 16px;
}

/* Toast Notification */
.toast-container {
  position: fixed;
  top: calc(var(--safe-top) + 14px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: calc(100% - 32px);
  max-width: 420px;
  pointer-events: none;
}

.toast {
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--border-highlight);
  color: var(--text-primary);
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 0.86rem;
  font-weight: 600;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toastIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.toast-error {
  border-color: rgba(244, 63, 94, 0.55);
  color: #fecdd3;
}

.toast-success {
  border-color: rgba(16, 185, 129, 0.55);
  color: #a7f3d0;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-14px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.empty-state {
  text-align: center;
  padding: 28px 16px;
  color: var(--text-secondary);
}

.empty-state-icon {
  font-size: 2.3rem;
  margin-bottom: 10px;
}

.rules-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 12px;
}

.rule-chip {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 13px;
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid var(--border-subtle);
  font-size: 0.81rem;
  color: var(--text-secondary);
}

.rule-chip strong {
  color: var(--text-primary);
  display: block;
  margin-bottom: 1px;
}
