/**
 * ========================================
 * MAIN STYLES - BOOKSWIPE APPLICATION
 * ========================================
 *
 * Core styling with focus on:
 * - CSS custom properties for dynamic theming
 * - Hardware-accelerated transitions
 * - Touch-optimized responsive breakpoints
 * - Progressive enhancement patterns
 *
 * ARCHITECTURE:
 * - Mobile-first responsive strategy
 * - Component-scoped styling approach
 * - Performance-optimized animations
 * - Cross-browser gesture support
 */

/* ==========================================
   CSS RESET AND BASE STYLES
   ==========================================
   Normalize cross-browser differences */

* {
  margin: 0; /* Remove default margins */
  padding: 0; /* Remove default padding */
  box-sizing: border-box; /* Include padding/border in element width */
}

/* ==========================================
  CSS CUSTOM PROPERTIES (VARIABLES)
  ==========================================
  These variables make it easy to maintain consistent colors and spacing.
  Change a value here, and it updates throughout the entire app! */

:root {
  /* COLOR PALETTE - Light theme (default) */
  --primary-color: #6366f1; /* Main brand color (purple-blue) */
  --primary-hover: #5855eb; /* Darker shade for hover states */
  --success-color: #10b981; /* Green for positive actions */
  --danger-color: #ef4444; /* Red for negative actions */
  --warning-color: #f59e0b; /* Orange for warnings */

  /* TEXT COLORS - Light theme */
  --text-primary: #1f2937; /* Main text color (dark gray) */
  --text-secondary: #6b7280; /* Secondary text (medium gray) */
  --text-light: #9ca3af; /* Light text (light gray) */

  /* BACKGROUND COLORS - Light theme */
  --bg-primary: #ffffff; /* Main background (white) */
  --bg-secondary: #f9fafb; /* Secondary background (very light gray) */
  --bg-tertiary: #f3f4f6; /* Tertiary background (light gray) */
  --bg-card: #fefefe; /* Card background (very subtle off-white for contrast) */
  --border-color: #e5e7eb; /* Border color (light gray) */

  /* ACTION BUTTON BACKGROUNDS - Light theme */
  --btn-reject-bg: #fef2f2; /* Light red background for reject button */
  --btn-reject-border: #fecaca; /* Light red border for reject button */
  --btn-accept-bg: #f0fdf4; /* Light green background for accept button */
  --btn-accept-border: #bbf7d0; /* Light green border for accept button */

  /* GRADIENT ACCENT COLORS */
  --accent-purple: #8b5cf6; /* Purple accent for gradients */
  --gradient-start: #667eea; /* Gradient start color for body background */
  --gradient-end: #764ba2; /* Gradient end color for body background */

  /* SHADOWS - for depth and layering */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg:
    0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-xl:
    0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);

  /* BORDER RADIUS - for rounded corners */
  --radius-sm: 0.375rem; /* Small radius (6px) */
  --radius-md: 0.5rem; /* Medium radius (8px) */
  --radius-lg: 0.75rem; /* Large radius (12px) */
  --radius-xl: 1rem; /* Extra large radius (16px) */
}

/* ==========================================
   DARK THEME
   ==========================================
   Automatically applied when user prefers dark mode */
@media (prefers-color-scheme: dark) {
  :root {
    /* COLOR PALETTE - Dark theme overrides */
    --primary-color: #818cf8; /* Lighter purple for better contrast */
    --primary-hover: #6366f1; /* Original primary as hover */
    --success-color: #34d399; /* Lighter green for dark backgrounds */
    --danger-color: #f87171; /* Lighter red for dark backgrounds */
    --warning-color: #fbbf24; /* Lighter orange for dark backgrounds */

    /* TEXT COLORS - Dark theme */
    --text-primary: #f9fafb; /* Light text on dark background */
    --text-secondary: #d1d5db; /* Medium light gray */
    --text-light: #9ca3af; /* Gray for less important text */

    /* BACKGROUND COLORS - Dark theme */
    --bg-primary: #111827; /* Dark gray background */
    --bg-secondary: #1f2937; /* Slightly lighter dark gray */
    --bg-tertiary: #374151; /* Medium dark gray */
    --bg-card: #1a1f2e; /* Card background (slightly lighter than primary for contrast) */
    --border-color: #4b5563; /* Dark border color */

    /* ACTION BUTTON BACKGROUNDS - Dark theme */
    --btn-reject-bg: #374151; /* Dark background for reject button */
    --btn-reject-border: #6b7280; /* Dark border for reject button */
    --btn-accept-bg: #064e3b; /* Dark green background for accept button */
    --btn-accept-border: #065f46; /* Dark green border for accept button */

    /* GRADIENT ACCENT COLORS - Dark theme */
    --accent-purple: #a78bfa; /* Lighter purple accent for dark backgrounds */
    --gradient-start: #1e293b; /* Dark gradient start color for body background */
    --gradient-end: #334155; /* Dark gradient end color for body background */

    /* SHADOWS - Enhanced for dark theme */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.2);
    --shadow-md:
      0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.2);
    --shadow-lg:
      0 10px 15px -3px rgb(0 0 0 / 0.4), 0 4px 6px -4px rgb(0 0 0 / 0.3);
    --shadow-xl:
      0 20px 25px -5px rgb(0 0 0 / 0.5), 0 8px 10px -6px rgb(0 0 0 / 0.4);
  }

  /* Dark theme body background */
  body {
    background: linear-gradient(
      135deg,
      var(--gradient-start) 0%,
      var(--gradient-end) 100%
    );
  }
}

/* ==========================================
  BODY AND MAIN APP CONTAINER
  ==========================================
  Sets up the overall page layout and styling */

body {
  /* FONT STACK - Modern, readable fonts with fallbacks */
  font-family:
    "Inter",
    /* Primary font (loaded from Google Fonts) */ -apple-system,
    /* macOS system font */ BlinkMacSystemFont,
    /* macOS system font (older versions) */ sans-serif; /* Generic fallback */

  /* TYPOGRAPHY */
  line-height: 1.6; /* Comfortable line spacing for readability */
  color: var(--text-primary); /* Use our defined text color */

  /* BACKGROUND - Gradient for visual appeal */
  background: linear-gradient(
    135deg,
    var(--gradient-start) 0%,
    var(--gradient-end) 100%
  );
  min-height: 100vh; /* Full viewport height */
  overflow-x: hidden; /* Prevent horizontal scrolling */
}

#app {
  /* LAYOUT */
  position: relative;
  min-height: 100vh; /* Full height */
  max-width: min(
    600px,
    100vw
  ); /* Responsive width: 600px max, but never wider than viewport */
  margin: 0 auto; /* Center horizontally */

  /* STYLING */
  background: var(--bg-primary); /* White background */
  box-shadow: var(--shadow-xl); /* Drop shadow for depth */
}

/* ==========================================
  SCREEN MANAGEMENT SYSTEM
  ==========================================
  BookSwipe uses a single-page application pattern.
  Different "screens" are shown/hidden using CSS classes.

   SPA pattern: Multiple sections controlled via JavaScript visibility. */

.screen {
  /* POSITIONING */
  position: absolute; /* Stack screens on top of each other */
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh; /* Full viewport height */

  /* LAYOUT */
  display: flex; /* Use flexbox for internal layout */
  flex-direction: column; /* Stack children vertically */

  /* VISIBILITY CONTROL */
  opacity: 0; /* Hidden by default */
  visibility: hidden; /* Completely hidden (don't capture events) */

  /* SMOOTH TRANSITIONS */
  transition: all 0.3s ease; /* Animate when showing/hiding */
}

/* ACTIVE SCREEN - The currently visible screen */
.screen.active {
  opacity: 1; /* Fully visible */
  visibility: visible; /* Interactive */
}

/* Loading Screen */
#loading-screen {
  justify-content: center;
  align-items: center;
  background: linear-gradient(
    135deg,
    var(--primary-color) 0%,
    var(--accent-purple) 100%
  );
  color: white;
}

.loading-content {
  text-align: center;
  padding: 2rem;
}

.loading-content h1 {
  font-size: 2.5rem;
  font-weight: 700;
  margin-bottom: 2rem;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-top: 4px solid white;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 1.5rem;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* Welcome Screen */
#welcome-screen {
  justify-content: center;
  align-items: center;
  padding: 1.5rem;
  text-align: center;
}

.welcome-content h1 {
  font-size: 3rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  background: linear-gradient(
    135deg,
    var(--primary-color),
    var(--accent-purple)
  );
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.tagline {
  font-size: 1.25rem;
  color: var(--text-secondary);
  margin-bottom: 3rem;
}

.instructions {
  margin-bottom: 3rem;
}

.instruction-item {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 1rem;
  padding: 1rem;
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  font-size: 1.1rem;
}

.swipe-icon {
  font-size: 1.5rem;
}

/* Buttons */
.primary-btn,
.secondary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1rem 2rem;
  border: none;
  border-radius: var(--radius-lg);
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  min-width: 140px;
}

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

.primary-btn:hover {
  background: var(--primary-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.secondary-btn {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 2px solid var(--border-color);
}

.secondary-btn:hover {
  background: var(--bg-secondary);
  transform: translateY(-2px);
}

/* Header */
.app-header {
  padding: 0.75rem 1rem 0.5rem;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  text-align: center;
  position: relative;
  z-index: 20;
}

.app-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: var(--primary-color);
}

.progress-container {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.progress-bar {
  flex: 1;
  height: 8px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(
    90deg,
    var(--primary-color),
    var(--accent-purple)
  );
  border-radius: var(--radius-sm);
  transition: width 0.3s ease;
  width: 0%;
}

.progress-text {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* Main Voting Area */
.voting-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0.75rem;
  padding-bottom: 0.5rem;
  position: relative; /* Enable absolute positioning for children */
}

/* Action Buttons */
.action-buttons {
  position: absolute; /* Float over content instead of taking layout space */
  bottom: 1rem; /* Position from bottom */
  left: 50%;
  transform: translateX(-50%); /* Center horizontally */
  display: flex;
  justify-content: center;
  gap: 2rem;
  background: transparent; /* Transparent container to prevent visual "box" effect */
  z-index: 15; /* Ensure buttons stay above cards */
  pointer-events: none; /* Allow pointer events to pass through container */
}

.action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1.25rem;
  border: none;
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 600;
  font-size: 0.9rem;
  pointer-events: auto; /* Re-enable pointer events for actual buttons */
}

.reject-btn {
  background: var(--btn-reject-bg);
  color: var(--danger-color);
  border: 2px solid var(--btn-reject-border);
}

.reject-btn:hover {
  background: var(--danger-color);
  color: white;
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.accept-btn {
  background: var(--btn-accept-bg);
  color: var(--success-color);
  border: 2px solid var(--btn-accept-border);
}

.accept-btn:hover {
  background: var(--success-color);
  color: white;
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.btn-icon {
  font-size: 1.1rem;
}

.btn-text {
  font-size: 0.85rem;
}

/* Results Screen */
#results-screen {
  justify-content: center;
  align-items: center;
  padding: 2rem;
  text-align: center;
}

.results-content h1 {
  font-size: 2.5rem;
  margin-bottom: 1rem;
}

.results-summary {
  font-size: 1.25rem;
  color: var(--text-secondary);
  margin-bottom: 2rem;
}

.results-stats {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin-bottom: 2rem;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1.5rem;
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  min-width: 100px;
}

.stat-number {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary-color);
}

.stat-label {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-top: 0.5rem;
}

.user-input-section {
  margin-bottom: 2rem;
}

.user-input-section label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  color: var(--text-primary);
}

.user-input-section input {
  width: 100%;
  max-width: 300px;
  padding: 0.75rem;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 1rem;
  transition: border-color 0.2s ease;
}

.user-input-section input:focus {
  outline: none;
  border-color: var(--primary-color);
}

/* Authenticated User Display */
.authenticated-user-info {
  margin-bottom: 2rem;
  padding: 1rem 1.5rem;
  background: var(--bg-secondary);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-lg);
  text-align: center;
  max-width: 300px;
  margin-left: auto;
  margin-right: auto;
}

.authenticated-user-info .user-label {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
  font-weight: 500;
}

.authenticated-user-info .user-display-name {
  font-size: 1rem;
  color: var(--text-primary);
  font-weight: 600;
  word-break: break-word;
}

.results-actions {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: center;
}

/* Success Screen */
#success-screen {
  justify-content: center;
  align-items: center;
  padding: 2rem;
  text-align: center;
}

.success-content h1 {
  font-size: 2.5rem;
  margin-bottom: 1rem;
}

.success-content p {
  font-size: 1.25rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.success-subtitle {
  font-size: 1rem !important;
  margin-bottom: 2rem !important;
}

/* ==========================================
  SMOOTH THEME TRANSITIONS
  ==========================================
  Adds smooth transitions when switching themes */
*:not(.book-card):not(.swipe-indicator):not(.loading-spinner),
*:not(.book-card):not(.swipe-indicator):not(.loading-spinner)::before,
*:not(.book-card):not(.swipe-indicator):not(.loading-spinner)::after {
  transition:
    background-color 0.3s ease,
    border-color 0.3s ease,
    color 0.3s ease,
    box-shadow 0.3s ease;
}

/* Responsive Design */
@media (max-width: 480px) {
  #app {
    max-width: 100%;
    box-shadow: none;
  }

  .welcome-content h1 {
    font-size: 2.5rem;
  }

  .action-buttons {
    gap: 1.5rem;
    bottom: 0.5rem; /* Closer to bottom on mobile */
  }

  .action-btn {
    width: 60px;
    height: 60px;
    font-size: 1rem;
    padding: 0.5rem;
    flex-direction: column;
    gap: 0.25rem;
  }

  .btn-icon {
    font-size: 1rem;
  }

  .btn-text {
    font-size: 0.7rem;
  }

  .results-stats {
    gap: 1rem;
  }

  .results-actions {
    width: 100%;
  }

  .primary-btn,
  .secondary-btn {
    width: 100%;
    max-width: 320px;
    padding: 1.25rem 2rem;
    font-size: 1.1rem;
  }

  /* Remove padding-bottom since buttons now float */
}

/* Tablet responsive */
@media (min-width: 481px) and (max-width: 768px) {
  #app {
    max-width: 100%;
    box-shadow: var(--shadow-xl);
  }

  .action-buttons {
    gap: 2.5rem;
    bottom: 1.5rem; /* More space from bottom on tablet */
  }

  .action-btn {
    width: 90px;
    height: 90px;
    font-size: 1.2rem;
  }

  .primary-btn,
  .secondary-btn {
    max-width: 400px;
    padding: 1.25rem 2.5rem;
    font-size: 1.1rem;
  }
}

@media (max-height: 600px) {
  .welcome-content h1 {
    font-size: 2rem;
  }

  .instructions {
    margin-bottom: 2rem;
  }

  .tagline {
    margin-bottom: 2rem;
  }
}
