/* 
 * UCF Main Stylesheet - Global Design System
 * CSS Custom Properties theming with mobile-first responsive design
 * Four theme variants: Light (default), Dark, OLED, Retro
 * Accessibility-focused with reduced motion support
 */

/* ==========================================================================
   CSS Custom Properties (Design Tokens)
   Light theme serves as default when no data-theme attribute is present
   ========================================================================== */
:root{
  /* Core design tokens for light theme */
  --bg: #f7f7f2;              /* Page background color */
  --card-bg: #ffffff;         /* Card/surface background */
  --text: #0b1220;            /* Primary text color */
  --muted: #6b7280;           /* Secondary text color */
  --accent: #2563eb;          /* Primary brand color */
  --accent-contrast: #ffffff; /* Text color on accent backgrounds */
  --success: #16a34a;         /* Success state color */
  --danger: #dc2626;          /* Error/danger state color */
  --radius: 10px;             /* Border radius for rounded elements */
  --gap: 16px;                /* Standard spacing unit */
  --max-width: 980px;         /* Maximum content width */
  --font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --fs-base: 16px;            /* Base font size for rem calculations */
  --line-height: 1.5;         /* Base line height */
  --focus-ring: rgba(37,99,235,0.28); /* Focus indicator color */
  --elevation-1: 0 6px 22px rgba(2,6,23,0.06); /* Shadow for depth level 1 */
  --elevation-2: 0 10px 40px rgba(2,6,23,0.08); /* Shadow for depth level 2 */
  --image-overlay: rgba(0,0,0,0.35); /* Overlay for text on images */
  --transition-fast: 160ms;   /* Fast animation duration */
  --border-color: rgba(0, 0, 0, 0.08); /* Border color for separators */
  --input-bg: rgba(255, 255, 255, 0.02); /* Input field background */
  --hover-bg: rgba(0, 0, 0, 0.03); /* Hover state background */
  --accent-hover: #1e4bb6;    /* Accent color for hover states */
}

/* ==========================================================================
   Dark Theme Variables
   Uses gradient backgrounds and lighter text on dark backgrounds
   ========================================================================== */
html[data-theme="dark"] {
  --bg: linear-gradient(180deg,#071021,#0f1720); /* Dark gradient background */
  --card-bg: linear-gradient(180deg, rgba(255,255,255,0.03), rgba(255,255,255,0.015));
  --text: #e6eef8;           /* Light text for dark backgrounds */
  --muted: #94a3b8;          /* Muted light gray */
  --accent: #60a5fa;         /* Lighter blue for better contrast on dark */
  --accent-contrast: #07203a; /* Dark text on light accent */
  --focus-ring: rgba(96,165,250,0.22);
  --elevation-1: 0 8px 30px rgba(2,6,23,0.6); /* Stronger shadows for depth */
  --image-overlay: rgba(0,0,0,0.35);
  --border-color: rgba(255, 255, 255, 0.08); /* Light borders on dark */
  --input-bg: rgba(255, 255, 255, 0.03);
  --hover-bg: rgba(255, 255, 255, 0.05);
  --accent-hover: #93c5fd;
}

/* ==========================================================================
   OLED Theme Variables  
   True black backgrounds for OLED display efficiency
   ========================================================================== */
html[data-theme="oled"] {
  --bg: #000000;              /* Pure black for OLED power savings */
  --card-bg: #050505;         /* Near-black for card surfaces */
  --text: #e6eef8;
  --muted: #9aa6b8;
  --accent: #60a5fa;
  --accent-contrast: #041423;
  --focus-ring: rgba(96,165,250,0.22);
  --elevation-1: none;        /* Remove shadows in true black environment */
  --image-overlay: rgba(0,0,0,0.45);
  --border-color: rgba(255, 255, 255, 0.1);
  --input-bg: rgba(255, 255, 255, 0.02);
  --hover-bg: rgba(255, 255, 255, 0.03);
  --accent-hover: #93c5fd;
}

/* ==========================================================================
   Retro Theme Variables
   Warm, nostalgic color palette with exaggerated border radii
   ========================================================================== */
html[data-theme="retro"] {
  --bg: linear-gradient(180deg, #f6efe0 0%, #efe5d0 100%); /* Warm beige gradient */
  --card-bg: linear-gradient(180deg, #f5ebd8 0%, #f0e2c4 100%);
  --text: #3b2f2e;           /* Brown text for retro feel */
  --muted: #7a6b5b;
  --accent: #c47c2d;         /* Warm amber accent */
  --accent-contrast: #fffef9;
  --radius: 24px;            /* Large radius for bubbly appearance */
  --focus-ring: rgba(196, 124, 45, 0.25);
  --elevation-1: 0 8px 32px rgba(91, 71, 52, 0.12);
  --image-overlay: rgba(59, 47, 38, 0.25);
  
  /* Retro-specific design tokens */
  --retro-border: 2px solid rgba(123, 97, 74, 0.15);
  --retro-glow: 0 4px 20px rgba(196, 124, 45, 0.15);
  --retro-text-shadow: 0 1px 2px rgba(255, 255, 255, 0.5);

  --border-color: rgba(123, 97, 74, 0.15);
  --input-bg: rgba(255, 255, 255, 0.1);
  --hover-bg: rgba(181, 118, 45, 0.08);
  --accent-hover: #946023;
}

/* ==========================================================================
   Retro Theme Enhancements
   Additional styling to complete the retro aesthetic
   ========================================================================== */
html[data-theme="retro"] body {
  font-weight: 500; /* Bolder text for better readability with rounded fonts */
  text-shadow: var(--retro-text-shadow);
}

html[data-theme="retro"] .card {
  border: var(--retro-border);
  box-shadow: var(--elevation-1), inset 0 1px 0 rgba(255, 255, 255, 0.6);
  background: var(--card-bg);
  position: relative;
}

/* Retro card top highlight for 3D effect */
html[data-theme="retro"] .card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.8), transparent);
  border-radius: var(--radius) var(--radius) 0 0;
}

html[data-theme="retro"] .btn {
  border-radius: 20px; /* Extra rounded buttons */
  font-weight: 600;
  letter-spacing: 0.5px;
  border: var(--retro-border);
  box-shadow: 0 2px 8px rgba(123, 97, 74, 0.1);
  transition: all var(--transition-fast) ease;
}

html[data-theme="retro"] .btn-primary {
  background: linear-gradient(180deg, #d4893a 0%, #b5762d 100%);
  border: 2px solid #a36925;
  box-shadow: var(--retro-glow), 0 2px 4px rgba(91, 71, 52, 0.2);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

html[data-theme="retro"] .btn-primary:hover {
  transform: translateY(-2px); /* Lift effect on hover */
  box-shadow: 0 6px 20px rgba(196, 124, 45, 0.25), 0 2px 4px rgba(91, 71, 52, 0.2);
}

html[data-theme="retro"] .btn-ghost {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.6), rgba(255, 255, 255, 0.3));
  border: 2px solid rgba(123, 97, 74, 0.3);
}

html[data-theme="retro"] .logo {
  border-radius: 18px; /* Distinct from card radius for visual hierarchy */
  box-shadow: 0 4px 16px rgba(196, 124, 45, 0.2);
  border: 2px solid rgba(255, 255, 255, 0.8);
}

html[data-theme="retro"] .theme-option[aria-selected="true"] {
  box-shadow: var(--retro-glow);
  border: 2px solid rgba(196, 124, 45, 0.3);
}

html[data-theme="retro"] .carousel-dot {
  border-radius: 10px; /* Pill-shaped dots instead of circles */
  width: 24px;
  height: 8px;
  transition: all var(--transition-fast) ease;
}

html[data-theme="retro"] .carousel-dot.active {
  background: var(--accent);
  width: 32px; /* Animated width change for active state */
}

html[data-theme="retro"] .ucf-caption-inner {
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(91, 71, 52, 0.8), rgba(73, 57, 41, 0.7));
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

html[data-theme="retro"] .ucf-username {
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(91, 71, 52, 0.8), rgba(73, 57, 41, 0.7));
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Enhanced focus states for retro theme accessibility */
html[data-theme="retro"] .btn:focus-visible,
html[data-theme="retro"] .theme-option:focus-visible,
html[data-theme="retro"] .carousel-dot:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

/* Mobile adjustments for retro theme */
@media (max-width: 420px) {
  html[data-theme="retro"] {
    --radius: 20px; /* Slightly smaller radius on mobile */
  }
  
  html[data-theme="retro"] .card {
    padding: 16px;
  }
}

/* ==========================================================================
   Base Reset and Global Styles
   Mobile-first approach with accessibility considerations
   ========================================================================== */

/* CSS Reset with border-box for predictable sizing */
* { box-sizing: border-box; }
html,body { height:100%; }

/* Base body styles with system font stack and smooth transitions */
body {
  margin:0;
  font-family:var(--font-family);
  font-size:var(--fs-base);
  line-height:var(--line-height);
  color:var(--text);
  background: var(--bg);
  -webkit-font-smoothing:antialiased;
  -moz-osx-font-smoothing:grayscale;
  -webkit-tap-highlight-color: transparent; /* Remove mobile tap highlight */
  transition: background var(--transition-fast) ease, color var(--transition-fast) ease;
}

/* Container for centered content with max-width constraint */
.container {
  width:100%;
  max-width:var(--max-width);
  margin:0 auto;
  padding:20px;
}

/* Card component - reusable surface with shadow and rounded corners */
.card {
  background: var(--card-bg);
  border-radius:var(--radius);
  padding:18px;
  border:1px solid rgba(0,0,0,0); /* Transparent border for consistent sizing */
  box-shadow: var(--elevation-1);
  color:var(--text);
  display:block;
  transition: box-shadow var(--transition-fast) ease, background var(--transition-fast) ease;
}

/* Typography scale with margin reset for consistency */
h1,h2,h3 { margin:0 0 10px 0; }
h1 { font-size:1.6rem; color:var(--text); }
h2 { font-size:1.15rem; color:var(--text); }

/* Text utility classes */
.lead { color:var(--muted); margin-top:6px; }
.muted { color:var(--muted); }

/* ==========================================================================
   Button System
   Multiple variants with consistent sizing and interaction states
   ========================================================================== */
.btn {
  display:inline-block;
  padding:10px 14px;
  border-radius:8px;
  text-decoration:none;
  font-weight:600;
  cursor:pointer;
  border:1px solid transparent;
  background:transparent;
  color:inherit;
  -webkit-appearance:none; /* Remove default button styling on iOS */
  transition: all var(--transition-fast) ease;
}

/* Remove default focus outline in favor of custom focus-visible */
.btn:focus { outline: none; }

/* Custom focus indicator for keyboard navigation only */
.btn:focus-visible, .theme-option:focus-visible, .carousel-dot:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 3px;
  border-radius:8px;
}

/* Primary button variant - high emphasis action */
.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
  box-shadow: 0 6px 18px rgba(0,0,0,0.06);
}

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

/* Ghost button variant - secondary action */
.btn-ghost {
  background:transparent;
  color:var(--text);
  border:1px solid rgba(0,0,0,0.06);
}

.btn-ghost:hover {
  background: var(--hover-bg);
  transform: translateY(-1px);
}

/* Danger button variant - destructive action */
.btn-danger {
  background: rgba(239, 68, 68, 0.1);
  color: #dc2626;
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.2);
  color: #b91c1c;
  transform: translateY(-1px);
}

/* Retro theme adjustments for danger button */
html[data-theme="retro"] .btn-danger {
  background: rgba(181, 118, 45, 0.1);
  color: #b5762d;
  border: 1px solid rgba(181, 118, 45, 0.3);
}

html[data-theme="retro"] .btn-danger:hover {
  background: rgba(181, 118, 45, 0.2);
  color: #946023;
}

/* Dark theme adjustments for danger button */
html[data-theme="dark"] .btn-danger,
html[data-theme="oled"] .btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

html[data-theme="dark"] .btn-danger:hover,
html[data-theme="oled"] .btn-danger:hover {
  background: rgba(239, 68, 68, 0.25);
  color: #fca5a5;
}

/* ==========================================================================
   Form Styling
   Accessible form controls with consistent styling
   ========================================================================== */
.field { margin-bottom:12px; }
.field label { display:block; margin-bottom:6px; font-weight:700; color:var(--text); }
.field input, .field textarea, .field select {
  display:block;
  width:100%;
  padding:10px 12px;
  border-radius:8px;
  border:1px solid rgba(0,0,0,0.06);
  background: rgba(255,255,255,0.02);
  color:var(--text);
  font-size:1rem;
  transition: box-shadow .12s, border-color .12s;
}

/* Enhanced focus states for form controls */
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none;
  box-shadow: 0 0 0 3px var(--focus-ring);
  border-color: rgba(96,165,250,0.35);
}

/* Error message styling for form validation */
.errlist {
  color:var(--danger);
  background:rgba(239,68,68,0.06);
  padding:10px;
  border-radius:8px;
  border:1px solid rgba(239,68,68,0.12);
}
.errlist li { margin:6px 0; }

/* Image handling - responsive by default */
img, picture, figure { max-width:100%; height:auto; display:block; }

/* Utility classes for layout and typography */
.center { display:flex; align-items:center; justify-content:center; }
.small { font-size:.9rem; }

/* Screen reader only content for accessibility */
.sr-only {
  position:absolute!important;
  width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0;
}

/* Reduced motion support for users with vestibular disorders */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ==========================================================================
   Responsive Design
   Mobile-first breakpoints for larger screens
   ========================================================================== */
@media(min-width:720px){
  .grid-2 { display:grid; grid-template-columns:1fr 1fr; gap:18px; }
}

/* ==========================================================================
   Theme Selector Component Styling
   Visual representation of available themes
   ========================================================================== */
#theme-selector { display:flex; flex-direction:column; gap:8px; }
#theme-options { list-style:none; padding:0; margin:0; display:flex; gap:8px; flex-wrap:wrap; }
.theme-option {
  padding:8px 10px;
  border-radius:8px;
  background:transparent;
  border:1px solid rgba(0,0,0,0.06);
  cursor:pointer;
  font-weight:600;
  user-select:none; /* Prevent text selection during clicking */
}
.theme-option[aria-selected="true"] {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: transparent;
}
.theme-option:focus { outline: none; }
.theme-option:hover { transform: translateY(-1px); transition: transform var(--transition-fast) ease; }

/* Carousel dot indicators for slide navigation */
.carousel-dot {
  display:inline-block;
  width:12px;
  height:12px;
  border-radius:50%;
  background:rgba(0,0,0,0.12);
  margin:0 6px;
  cursor:pointer;
}
.carousel-dot.active {
  background: var(--muted);
}

/* Overlay utilities for text on images with contrast ensuring */
.ucf-overlay {
  position: absolute;
  left: 12px;
  right: 12px;
  color: var(--text);
  text-shadow: 0 1px 3px rgba(0,0,0,0.35);
  pointer-events: none; /* Allow clicks to pass through to underlying content */
}

.ucf-caption {
  bottom: 12px;
  font-size: .95rem;
  display:inline-block;
  background: rgba(0,0,0,0.35);
  padding: 6px 8px;
  border-radius: 6px;
  pointer-events: none;
}
.ucf-username { top:12px; font-weight:700; font-size:1rem; }

/* Image responsiveness */
.ucf-slide img { width:100%; height:auto; display:block; }

/* Elevation utility classes for consistent shadows */
.elev-1 { box-shadow: var(--elevation-1); }
.elev-2 { box-shadow: var(--elevation-2); }

/* ==========================================================================
   Theme Option Visual Styling
   Each theme button shows a preview of its color scheme
   ========================================================================== */
.theme-option[data-theme="light"] {
  background: #f7f7f2;
  color: #0b1220;
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.theme-option[data-theme="dark"] {
  background: #071021;
  color: #e6eef8;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.theme-option[data-theme="oled"] {
  background: #000000;
  color: #e6eef8;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.theme-option[data-theme="retro"] {
  background: #f6efe0;
  color: #3b2f2e;
  border: 1px solid rgba(123, 97, 74, 0.2);
}

/* Interactive states for theme buttons */
.theme-option:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: all var(--transition-fast) ease;
}

/* Active theme selection override */
.theme-option[aria-selected="true"] {
  background: var(--accent) !important;
  color: var(--accent-contrast) !important;
  border-color: transparent !important;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

/* Enhanced focus states for keyboard navigation */
.theme-option:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
  z-index: 1; /* Ensure focus ring appears above adjacent elements */
}

/* Theme selector layout optimization */
#theme-options {
  gap: 6px;
}

.theme-option {
  padding: 8px 12px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  min-width: 60px;
  text-align: center;
  transition: all var(--transition-fast) ease;
  flex: 1;
  max-width: 80px;
}

/* Mobile optimization for theme selector */
@media (max-width: 720px) {
  #theme-options {
    flex-wrap: wrap;
  }
  
  .theme-option {
    min-width: 70px;
    font-size: 0.85rem;
    padding: 6px 10px;
  }
}

/* ==========================================================================
   Footer Styling
   Consistent footer across all pages with theme adaptation
   ========================================================================== */
footer {
  margin-top: auto; /* Push footer to bottom in flex layouts */
  color: var(--muted);
  font-size: 0.9rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 20px;
  text-align: center;
  border-top: 1px solid var(--border-color);
  background: var(--card-bg);
}

/* Footer content container for proper alignment */
.footer-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  max-width: var(--max-width);
  gap: 12px;
  flex-wrap: wrap;
}

/* Ensure footer positioning in logged-in layouts */
.logged-in-main + footer {
  margin-top: auto;
  padding: 20px;
}

/* Mobile footer adjustments */
@media (max-width: 720px) {
  .footer-content {
    flex-direction: column;
    gap: 8px;
  }
  
  footer {
    padding: 16px 12px;
  }
}

/* Theme-specific footer enhancements */
html[data-theme="retro"] footer {
  border-top: 2px solid var(--border-color);
  background: linear-gradient(180deg, var(--card-bg), rgba(245, 235, 216, 0.95));
}

html[data-theme="dark"] footer,
html[data-theme="oled"] footer {
  background: rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(10px);
}

/* ==========================================================================
   Modal Component Styles
   Global modal dialog system with backdrop and accessibility features
   ========================================================================== */

/* 
 * Fixed position modal covering entire viewport
 * High z-index ensures proper layering above other content
 */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal.open {
  display: flex;
}

/* 
 * Modal backdrop with blur effect for visual depth
 * Semi-transparent overlay provides focus isolation
 */
.modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}

/* 
 * Modal content container with constrained dimensions
 * Scrollable content area for overflow management
 */
.modal-content {
  background: var(--card-bg);
  border-radius: var(--radius);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  z-index: 1;
  box-shadow: var(--elevation-2);
  border: 1px solid var(--border-color);
}

/* 
 * Modal header with flexible space distribution
 * Padding management for consistent internal spacing
 */
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 20px 0 20px;
  margin-bottom: 20px;
}

.modal-header h2 {
  margin: 0;
  color: var(--text);
}

/* 
 * Modal close button with hover states
 * Padding and border-radius for adequate touch target size
 */
.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: color var(--transition-fast) ease;
}

.modal-close:hover {
  color: var(--text);
}

.modal-body {
  padding: 0 20px;
}

/* 
 * Modal actions container with right-aligned buttons
 * Top border creates visual separation from form content
 */
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 20px;
  border-top: 1px solid var(--border-color);
  margin-top: 20px;
}

.error-container {
  margin-top: 16px;
}

/* Retro theme modal enhancements */
html[data-theme="retro"] .modal-content {
  border: var(--retro-border);
  background: linear-gradient(180deg, var(--card-bg), rgba(245, 235, 216, 0.95));
}

html[data-theme="retro"] .modal-backdrop {
  background: rgba(91, 71, 52, 0.4);
}

/* Dark and OLED theme backdrop enhancements */
html[data-theme="dark"] .modal-backdrop,
html[data-theme="oled"] .modal-backdrop {
  background: rgba(0, 0, 0, 0.8);
}

/* Mobile modal adjustments */
@media (max-width: 480px) {
  .modal {
    padding: 10px;
  }
  
  .modal-content {
    max-height: 95vh;
  }
  
  .modal-actions {
    flex-direction: column-reverse;
  }
}