:root {
  /* Colors */
  --color-bg: #4C1D95;
  --color-bg-light: #2d2457;
  --color-bg-dark: #150f36;
  --color-primary: #EC4899;
  --color-primary-hover: #DB2777;
  --color-secondary: #8B5CF6;
  --color-secondary-hover: #7C3AED;
  --color-accent: #F59E0B;
  --color-highlight: #F59E0B;
  --color-text: #ffffff;
  --color-text-muted: rgba(255, 255, 255, 0.7);
  --color-border: rgba(255, 255, 255, 0.15);
  --color-border-light: rgba(255, 255, 255, 0.1);
  --color-bg-card: rgba(255, 255, 255, 0.05);
  
  /* Semantic rating scale colors */
  --color-much-worse: #b91c1c;      /* Darker red */
  --color-worse: #fca5a5;           /* Lighter red */
  --color-better: #4ade80;         /* Medium green - darker than #86efac for legibility */
  --color-much-better: #16a34a;     /* Darker green */

  /* Typography */
  --font-family: 'Inter', sans-serif;
  --font-size-xs: 0.75rem;
  --font-size-sm: 0.875rem;
  --font-size-base: 1rem;
  --font-size-lg: 1.125rem;
  --font-size-xl: 1.25rem;
  --font-size-2xl: 1.5rem;
  --font-size-3xl: 1.875rem;
  --font-size-4xl: 2.25rem;
  
  --font-weight-normal: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;
  --font-weight-extrabold: 800;
  
  --line-height-tight: 1.25;
  --line-height-normal: 1.5;
  --line-height-relaxed: 1.625;

  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-12: 3rem;
  --space-16: 4rem;
  
  /* Border Radius */
  --radius-sm: 0.25rem;
  --radius-md: 0.5rem;
  --radius-lg: 1rem;
  --radius-full: 9999px;
  
  /* Layout Dimensions */
  --nav-height-top: 70px;
  --nav-height-bottom: 64px;
  
  /* Z-Indices */
  --z-nav: 1000;
  --z-modal: 2000;
  --z-toast: 3000;
  
  /* Animation */
  --transition-fast: 0.2s ease;
  --transition-normal: 0.3s ease;
  --transition-base: 0.2s ease;
  
  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
  
  /* ========================================
     GLASS DESIGN SYSTEM TOKENS
     ======================================== */
  
  /* Glass Blur Levels (3-tier elevation system) */
  --glass-blur-1: 12px;  /* Level 1: Cards, content surfaces */
  --glass-blur-2: 16px;  /* Level 2: Menus, overlays */
  --glass-blur-3: 20px;  /* Level 3: Modals, bottom sheets */
  
  /* Glass Background Opacity */
  --glass-bg-1: rgba(255, 255, 255, 0.15);
  --glass-bg-2: rgba(255, 255, 255, 0.2);
  --glass-bg-3: rgba(255, 255, 255, 0.25);
  
  /* Purple-tinted Glass for Modals (matches original #1f1748 but translucent for glass effect) */
  --glass-bg-modal: rgba(31, 23, 72, 0.4);  /* #1f1748 with 40% opacity - allows blur to show through */
  --glass-border-modal: rgba(255, 255, 255, 0.3);
  
  /* Glass Border Opacity */
  --glass-border-1: rgba(255, 255, 255, 0.3);
  --glass-border-2: rgba(255, 255, 255, 0.35);
  --glass-border-3: rgba(255, 255, 255, 0.4);
  
  /* Glass Elevation (Ambient Glow, not drop shadows) */
  --glass-elevation-1: 0 2px 8px rgba(0, 0, 0, 0.1), 
                       0 0 0 1px rgba(255, 255, 255, 0.1) inset;
  --glass-elevation-2: 0 4px 16px rgba(0, 0, 0, 0.12),
                       0 0 0 1px rgba(255, 255, 255, 0.15) inset;
  --glass-elevation-3: 0 8px 24px rgba(0, 0, 0, 0.15),
                       0 0 0 1px rgba(255, 255, 255, 0.2) inset;
  
  /* Background Layer (for glass to blur) */
  --app-bg-layer: linear-gradient(
    135deg,
    #4C1D95 0%,
    #5B21B6 50%,
    #6D28D9 100%
  );
  
  /* Typography on Glass */
  --font-weight-glass-min: 500;
  --text-on-glass: rgba(255, 255, 255, 0.9);
  --text-on-glass-muted: rgba(230, 230, 230, 0.85);
  --letter-spacing-glass: 0.01em;
  --text-shadow-glass: 0 1px 2px rgba(0, 0, 0, 0.1);
  
  /* Motion Tokens */
  --motion-fast: 150ms;
  --motion-default: 250ms;
  --motion-slow: 400ms;
  --ease-ios: cubic-bezier(0.4, 0.0, 0.2, 1);
  --ease-ios-out: cubic-bezier(0.0, 0.0, 0.2, 1);
  --ease-ios-in: cubic-bezier(0.4, 0.0, 1, 1);
  --ease-spring: cubic-bezier(0.68, -0.55, 0.265, 1.55);
  
  /* Touch Targets */
  --touch-target-min: 44px;
  --touch-target-comfort: 48px;
  
  /* Radius (iOS-style) */
  --radius-ios: 16px;
  --radius-ios-lg: 24px;
}

/* -------------------------------------------------------------------------- */
/* Auth-first-paint helpers                                                    */
/* -------------------------------------------------------------------------- */
/*
  SIMPLIFIED: Guest content has been moved to separate -guest.html pages.
  The route guard redirects unauthenticated users before any content renders.
  We only need to hide login CTAs in navigation when authenticated.
  
  `js/early-loading-screen.js` sets `html.htbx-auth-likely` when a prior session
  is very likely (cached profile or Supabase token present).
*/

/* Hide obvious login CTAs in navigation before auth resolves */
html.htbx-auth-likely .btn.btn-login {
  display: none !important;
}

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

html {
  height: 100%;
  overflow-x: hidden;
  /* Prevent horizontal scroll and ensure proper viewport height */
}

body {
  font-family: var(--font-family);
  /* Background gradient for glass effect */
  background: var(--app-bg-layer);
  background-attachment: fixed;
  min-height: 100vh;
  color: var(--color-text);
  line-height: var(--line-height-normal);
  -webkit-font-smoothing: antialiased;
  
  /* Fixed Nav Spacing */
  /* Default: Top nav spacing (works for both desktop nav and mobile header) */
  padding-top: var(--nav-height-top);
  padding-bottom: 0;
  
  /* Safe Area Insets (iOS) */
  padding-top: calc(var(--nav-height-top) + env(safe-area-inset-top, 0px));
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

@media (max-width: 768px) {
  body { 
    /* Mobile: Needs both top padding (mobile header) AND bottom padding (bottom nav) */
    padding-top: calc(var(--nav-height-top) + env(safe-area-inset-top, 0px));
    padding-bottom: calc(var(--nav-height-bottom) + var(--space-4) + env(safe-area-inset-bottom, 0px));
  }
}

/* Typography - Aligned with Design Language.md */
h1, h2, h3, h4, h5, h6 {
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height-tight);
  margin-bottom: var(--space-4);
  margin-top: 0; /* Ensure consistent top spacing - spacing comes from container padding */
}
/* H1: 3-4rem (hero) / 2rem (mobile) per Design Language */
h1 { 
  font-size: 2rem; /* Mobile default */
}
@media (min-width: 640px) {
  h1 { font-size: 3rem; } /* Desktop: 3-4rem range */
}
@media (min-width: 1024px) {
  h1 { font-size: 4rem; } /* Large desktop: 4rem */
}
/* H2: 2.5rem / 1.5rem per Design Language */
h2 { 
  font-size: 1.5rem; /* Mobile */
  color: var(--color-primary); 
}
@media (min-width: 640px) {
  h2 { font-size: 2.5rem; } /* Desktop */
}
h2.section-title { font-size: var(--font-size-xl); } /* Slightly smaller to prevent wrapping */
/* H3: 1.5rem per Design Language */
h3 { font-size: 1.5rem; }

/* Body: 1.1rem, line-height 1.6 per Design Language */
p { 
  margin-bottom: var(--space-4); 
  opacity: 0.9; 
  font-size: 1.1rem;
  line-height: 1.6;
}
a { color: inherit; text-decoration: none; transition: color var(--transition-fast); }
a:hover { color: var(--color-primary); }

/* Typography on Glass Surfaces */
.glass-card,
.glass-menu,
.glass-modal,
.card {
  /* Minimum weight for glass readability */
  font-weight: var(--font-weight-glass-min);
  color: var(--text-on-glass);
  letter-spacing: var(--letter-spacing-glass);
}

.glass-card p,
.glass-menu p,
.glass-modal p,
.card p {
  color: var(--text-on-glass);
  text-shadow: var(--text-shadow-glass);
}

.glass-card h1,
.glass-card h2,
.glass-card h3,
.glass-menu h1,
.glass-menu h2,
.glass-menu h3,
.glass-modal h1,
.glass-modal h2,
.glass-modal h3,
.card h1,
.card h2,
.card h3 {
  color: var(--text-on-glass);
  font-weight: var(--font-weight-semibold);
  text-shadow: var(--text-shadow-glass);
}

/* Muted text on glass */
.glass-card .text-muted,
.glass-menu .text-muted,
.glass-modal .text-muted,
.card .text-muted {
  color: var(--text-on-glass-muted);
}

/* Components */
.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--space-4);
}

/* Standardize h1 spacing from mobile header across all pages */
.content-wrapper > .container:first-child,
.content-wrapper > .container:first-of-type,
.content-area:first-child,
.content:first-child,
.hero:first-child,
.profile-container:first-child {
  padding-top: var(--space-4) !important; /* Consistent 16px spacing from header */
}

/* Ensure nested containers don't add extra top spacing */
.page-header,
.profile-header,
.hero > h1:first-child {
  margin-top: 0 !important; /* Remove any default margin that would push h1 down */
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 0.75rem; /* Reduced from 1rem to fit better */
  border-radius: 0.5rem;
  font-weight: var(--font-weight-medium);
  cursor: pointer;
  transition: var(--transition-fast);
  border: none;
  font-family: inherit;
  text-align: center;
  text-decoration: none;
  white-space: nowrap; /* Prevent text wrapping */
  font-size: var(--font-size-sm); /* Slightly smaller font */
}

.btn-primary {
  background-color: var(--color-primary);
  color: white;
}
.btn-primary:hover { background-color: var(--color-primary-hover); }

.btn-secondary {
  background-color: transparent;
  border: 1px solid var(--color-primary);
  color: var(--color-primary);
}
.btn-secondary:hover {
  background-color: var(--color-primary);
  color: white;
}

.btn-icon { padding: 0.5rem; background: transparent; color: white; }
.btn-icon:hover { color: var(--color-primary); background: rgba(255,255,255,0.1); }

.btn-sm {
  padding: 0.25rem 0.75rem;
  font-size: var(--font-size-sm);
}

.btn-lg {
  padding: 0.75rem 2rem;
  font-size: var(--font-size-lg);
}

/* ========================================
   GLASS COMPONENT CLASSES
   ======================================== */

/* Level 1: Cards & Content Surfaces */
.glass-card {
  background: var(--glass-bg-1);
  backdrop-filter: blur(var(--glass-blur-1));
  -webkit-backdrop-filter: blur(var(--glass-blur-1));
  border: 1px solid var(--glass-border-1);
  border-radius: var(--radius-ios);
  box-shadow: var(--glass-elevation-1);
  padding: var(--space-6);
  transition: all var(--motion-default) var(--ease-ios);
}

/* Fallback for no backdrop-filter support */
@supports not (backdrop-filter: blur(1px)) {
  .glass-card {
    background: rgba(255, 255, 255, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.4);
  }
}

.no-glass .glass-card {
  background: rgba(255, 255, 255, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.5);
}

/* Level 2: Menus & Overlays */
.glass-menu {
  background: var(--glass-bg-2);
  backdrop-filter: blur(var(--glass-blur-2));
  -webkit-backdrop-filter: blur(var(--glass-blur-2));
  border: 1px solid var(--glass-border-2);
  border-radius: 20px;
  box-shadow: var(--glass-elevation-2);
  padding: var(--space-4);
}

@supports not (backdrop-filter: blur(1px)) {
  .glass-menu {
    background: rgba(255, 255, 255, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.5);
  }
}

.no-glass .glass-menu {
  background: rgba(255, 255, 255, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.6);
}

/* Level 3: Modals & Bottom Sheets */
.glass-modal {
  /* Purple-tinted glass to match original #1f1748 but with glass effect */
  background: var(--glass-bg-modal);
  backdrop-filter: blur(var(--glass-blur-3));
  -webkit-backdrop-filter: blur(var(--glass-blur-3));
  border: 1px solid var(--glass-border-modal);
  border-radius: var(--radius-ios-lg);
  box-shadow: var(--glass-elevation-3);
  padding: var(--space-6);
  /* Ensure glass effect is visible */
  color: var(--text-on-glass);
  font-weight: var(--font-weight-glass-min);
}

@supports not (backdrop-filter: blur(1px)) {
  .glass-modal {
    background: rgba(31, 23, 72, 0.85);  /* #1f1748 with higher opacity fallback */
    border: 1px solid rgba(255, 255, 255, 0.3);
  }
}

.no-glass .glass-modal {
  background: rgba(31, 23, 72, 0.9);  /* #1f1748 with near-opaque fallback */
  border: 1px solid rgba(255, 255, 255, 0.4);
}

/* Reduced Motion Support */
.reduced-motion .glass-card,
.reduced-motion .glass-menu,
.reduced-motion .glass-modal,
.reduced-motion .card,
.reduced-motion .entry-card {
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: none;
  animation: none;
}

/* High Contrast Mode */
.high-contrast .glass-card,
.high-contrast .glass-menu,
.high-contrast .glass-modal,
.high-contrast .card,
.high-contrast .entry-card {
  background: rgba(255, 255, 255, 0.35);
  border: 2px solid rgba(255, 255, 255, 0.6);
}

.high-contrast .glass-card,
.high-contrast .glass-menu,
.high-contrast .glass-modal,
.high-contrast .card {
  color: #ffffff;
  font-weight: 600;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* Bottom Sheet Variant */
.glass-modal.bottom-sheet {
  border-radius: var(--radius-ios-lg) var(--radius-ios-lg) 0 0;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 90vh;
  padding-bottom: calc(var(--space-6) + env(safe-area-inset-bottom, 0px));
  animation: glassSlideUp var(--motion-default) var(--ease-ios-out);
}

@keyframes glassSlideUp {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Scrim behind modal */
.glass-scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: calc(var(--z-modal) - 1);
}

@supports not (backdrop-filter: blur(1px)) {
  .glass-scrim {
    background: rgba(0, 0, 0, 0.5);
  }
}

/* Legacy card class - now uses glass */
.card {
  background: var(--glass-bg-1);
  backdrop-filter: blur(var(--glass-blur-1));
  -webkit-backdrop-filter: blur(var(--glass-blur-1));
  border: 1px solid var(--glass-border-1);
  border-radius: var(--radius-ios);
  box-shadow: var(--glass-elevation-1);
  padding: var(--space-6);
}

@supports not (backdrop-filter: blur(1px)) {
  .card {
    background: rgba(255, 255, 255, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.4);
  }
}

.no-glass .card {
  background: rgba(255, 255, 255, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.5);
}

/* Utilities */
.mb-1 { margin-bottom: var(--space-1); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.mb-8 { margin-bottom: var(--space-8); }
.mb-16 { margin-bottom: var(--space-16); }

.text-center { text-align: center; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--space-2); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }

.hidden { display: none; }

/* Grid Utilities */
.grid { display: grid; }
.grid-gap-4 { gap: var(--space-4); }
.grid-gap-6 { gap: var(--space-6); }
.grid-cols-1 { grid-template-columns: repeat(1, 1fr); }
@media (min-width: 640px) { .grid-cols-2 { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1024px) { .grid-cols-3 { grid-template-columns: repeat(3, 1fr); } }

/* ========================================
   LOADING SCREEN
   ======================================== */

#loading-screen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--color-bg);
  z-index: 99999; /* Very high z-index to ensure it's on top */
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  /* Prevent white flash by ensuring background covers everything */
  will-change: opacity;
}

#loading-screen.visible {
  opacity: 1;
  visibility: visible;
}

#loading-screen.hiding {
  opacity: 0;
  visibility: hidden;
}

.loading-screen-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-6);
}

.loading-logo {
  font-size: 2rem;
  font-weight: var(--font-weight-bold);
  color: var(--color-text);
  letter-spacing: 0.05em;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ========================================
   OFFLINE STATUS INDICATOR
   ======================================== */

.offline-status-indicator {
  position: absolute;
  top: 0;
  left: 0;
  padding: var(--space-2) var(--space-3);
  background: rgba(239, 68, 68, 0.9);
  color: var(--color-text);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  border-radius: 0 0 var(--radius-sm) 0;
  z-index: 1999;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-100%);
  transition: all 0.3s ease;
  white-space: nowrap;
}

.offline-status-indicator.visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.offline-status-text {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.offline-status-text::before {
  content: '📴';
  font-size: 0.875rem;
}

/* Mobile header positioning */
.mobile-header .offline-status-indicator {
  position: relative;
  top: auto;
  left: auto;
  transform: none;
  border-radius: var(--radius-sm);
  margin-right: var(--space-2);
  flex-shrink: 0;
}

/* Desktop nav positioning */
.nav-top-container .offline-status-indicator {
  position: absolute;
  top: 100%;
  left: 0;
  border-radius: 0 0 var(--radius-sm) 0;
  transform: translateY(0);
}
