/* CSS Reset and Base Styles */
*,
*::before,
*::after {
  box-sizing: border-box;
}

* {
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  line-height: 1.6;
  color: var(--text-primary);
  background-color: var(--bg-primary);
  transition: color 0.2s ease, background-color 0.2s ease;
  /* Prevent Safari blue overscroll bounce */
  overscroll-behavior-y: none;
  -webkit-overscroll-behavior-y: none;
  /* Prevent browser blue highlights/lines */
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* CSS Custom Properties */
:root {
  /* Colors - Light Theme */
  --text-primary: #1f2937;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --bg-primary: #ffffff;
  --bg-secondary: #f9fafb;
  --bg-tertiary: #f3f4f6;
  --border-color: #e5e7eb;
  --accent-color: #2563eb;
  --accent-hover: #1d4ed8;
  --success-color: #10b981;
  --warning-color: #f59e0b;
  --error-color: #ef4444;
  
  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
  --space-3xl: 4rem;
  
  /* Typography */
  --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;
  
  /* Line Heights */
  --line-height-tight: 1.25;
  --line-height-normal: 1.5;
  --line-height-relaxed: 1.625;
  --line-height-loose: 2;
  
  /* Borders and Radius */
  --border-radius-sm: 0.25rem;
  --border-radius-md: 0.5rem;
  --border-radius-lg: 0.75rem;
  --border-radius-xl: 1rem;
  
  /* Shadows */
  --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);
  
  /* Layout */
  --max-width-prose: 65ch;
  --max-width-wide: 80rem;
  --header-height: 4rem;
}

/* Layout Components */
.site-wrapper {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.main-content {
  flex: 1;
  padding: var(--space-lg) var(--space-md);
}

/* Skip Navigation */
.skip-nav {
  position: absolute;
  top: -100px;
  left: var(--space-md);
  background: var(--accent-color);
  color: white;
  padding: var(--space-sm) var(--space-md);
  text-decoration: none;
  border-radius: var(--border-radius-md);
  z-index: 1000;
  transition: top 0.3s;
  opacity: 0;
  transform: translateY(-100%);
}

.skip-nav:focus {
  top: var(--space-md);
  opacity: 1;
  transform: translateY(0);
}

/* Header */
.site-header {
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  /* Prevent Safari pull-to-refresh blue line */
  overscroll-behavior-y: none;
  -webkit-overscroll-behavior-y: none;
  /* Remove any focus outlines */
  outline: none !important;
}

/* Remove focus outlines from all header elements */
.site-header *:focus,
.site-header *:active,
.site-header button:focus,
.site-header a:focus {
  outline: none !important;
  box-shadow: none !important;
}

.header-container {
  max-width: var(--max-width-wide);
  margin: 0 auto;
  padding: 0 var(--space-md);
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
}

.brand-link {
  text-decoration: none;
  color: inherit;
}

.brand-title {
  font-size: var(--font-size-xl);
  font-weight: 700;
  line-height: var(--line-height-tight);
  margin-bottom: var(--space-xs);
}

.brand-subtitle {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  line-height: var(--line-height-normal);
}

.header-nav .nav-list {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
  list-style: none;
}

.header-nav a {
  text-decoration: none;
  color: var(--text-secondary);
  font-weight: 500;
  transition: color 0.2s ease;
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.nav-icon {
  font-size: 1.2em;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-icon svg,
.nav-icon img {
  width: 16px;
  height: 16px;
}

.nav-text {
  white-space: nowrap;
}

.header-nav a:hover,
.header-nav a[aria-current="page"] {
  color: var(--accent-color);
}


/* Theme Toggle */
.theme-toggle {
  background: none;
  border: none;
  padding: var(--space-sm);
  cursor: pointer;
  border-radius: var(--border-radius-md);
  transition: background-color 0.2s ease;
}

.theme-toggle:hover {
  background-color: var(--bg-secondary);
}

.theme-toggle-icon {
  display: block;
  width: 1.25rem;
  height: 1.25rem;
  background: var(--text-secondary);
  mask: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z" /></svg>') no-repeat center;
  mask-size: contain;
  -webkit-mask: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z" /></svg>') no-repeat center;
  -webkit-mask-size: contain;
}

/* Footer */
.site-footer {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  padding: var(--space-xl) var(--space-md);
  margin-top: var(--space-3xl);
}

.footer-container {
  max-width: var(--max-width-wide);
  margin: 0 auto;
}

.footer-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-md);
}

.footer-links {
  display: flex;
  gap: var(--space-lg);
}

.footer-links a {
  color: var(--text-secondary);
  text-decoration: none;
  transition: color 0.2s ease;
}

.footer-links a:hover {
  color: var(--accent-color);
}

.footer-meta {
  text-align: center;
  padding-top: var(--space-md);
  border-top: 1px solid var(--border-color);
}

.generated-by {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
}

.generated-by a {
  color: var(--text-secondary);
  text-decoration: none;
}

.generated-by a:hover {
  color: var(--accent-color);
}

/* Buttons and Interactive Elements */
.action-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-md) var(--space-xl);
  background: var(--accent-color);
  color: white;
  text-decoration: none;
  border-radius: var(--border-radius-lg);
  font-weight: 600;
  font-size: var(--font-size-base);
  transition: all 0.2s ease;
  border: 2px solid var(--accent-color);
}

.action-button:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.action-button.secondary {
  background: transparent;
  color: var(--accent-color);
  border: 2px solid var(--accent-color);
}

.action-button.secondary:hover {
  background: var(--accent-color);
  color: white;
}

/* Random chapter button styling */
.random-chapter-btn {
  background: var(--success-color) !important;
  color: white !important;
  border: 2px solid var(--success-color) !important;
}

.random-chapter-btn:hover {
  background: #059669 !important;
  border-color: #059669 !important;
  color: white !important;
}

/* Responsive Design */
@media (max-width: 768px) {
  .header-container {
    padding: 0 var(--space-sm);
  }
  
  .header-nav .nav-list {
    gap: var(--space-md);
  }
  
  .brand-title {
    font-size: var(--font-size-lg);
  }
  
  .footer-content {
    flex-direction: column;
    gap: var(--space-md);
    text-align: center;
  }
  
  .footer-links {
    justify-content: center;
  }
  
  .main-content {
    padding: var(--space-md) var(--space-sm);
  }
}

@media (max-width: 480px) {
  .header-nav .nav-list {
    gap: var(--space-sm);
  }
  
  .header-nav a {
    font-size: var(--font-size-sm);
    min-width: 44px;
    min-height: 44px;
    justify-content: center;
    padding: var(--space-sm);
    border-radius: var(--border-radius-md);
    position: relative;
  }
  
  .nav-text {
    display: none;
  }
  
  .nav-icon {
    font-size: 1.4em;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 1.4em;
  }
  
  .nav-icon svg,
  .nav-icon img {
    width: 20px;
    height: 20px;
  }
  
  /* Tooltip for mobile icons */
  .header-nav a::after {
    content: attr(aria-label);
    position: absolute;
    bottom: -2.5rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--border-radius-sm);
    font-size: var(--font-size-xs);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 1000;
    box-shadow: var(--shadow-md);
  }
  
  .header-nav a:hover::after,
  .header-nav a:focus::after {
    opacity: 1;
  }
  
  .brand-subtitle {
    display: none;
  }
}