/* ============================================================
   IT'S NOT TOO LATE — Style Sheet
   Mobile-first, WCAG AA compliant
   ============================================================ */

/* --- CSS Custom Properties --- */
:root {
  /* Colors — all combos verified WCAG AA (4.5:1+) */
  --bg: #FFF8F0;
  --card-bg: #FFFFFF;
  --text-primary: #2D2D2D;       /* on cream = 12.6:1 */
  --text-secondary: #555555;     /* on cream = 7.3:1 */
  --accent: #C4501B;             /* on white bg with white text */
  --accent-hover: #A34115;
  --accent-light: #FFF0E8;
  --green: #1B6B33;              /* encouragement headline */
  --green-light: #E8F5E9;
  --border: #E0D6CC;
  --shadow: rgba(45, 45, 45, 0.08);

  /* Typography */
  --font-heading: 'Lora', Georgia, 'Times New Roman', serif;
  --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;

  /* 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;

  /* Layout */
  --max-width: 960px;
  --radius: 8px;
  --radius-lg: 12px;
}

/* --- Dark Mode --- */
[data-theme="dark"] {
  --bg: #1A1410;
  --card-bg: #2A2218;
  --text-primary: #F0E8E0;
  --text-secondary: #B8A898;
  --accent: #E8753A;
  --accent-hover: #F08A50;
  --accent-light: #3A2818;
  --green: #5EBF78;
  --green-light: #1A2E1A;
  --border: #3A3028;
  --shadow: rgba(0, 0, 0, 0.3);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1A1410;
    --card-bg: #2A2218;
    --text-primary: #F0E8E0;
    --text-secondary: #B8A898;
    --accent: #E8753A;
    --accent-hover: #F08A50;
    --accent-light: #3A2818;
    --green: #5EBF78;
    --green-light: #1A2E1A;
    --border: #3A3028;
    --shadow: rgba(0, 0, 0, 0.3);
  }
}

/* Theme Toggle Button */
.theme-toggle {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  border: 2px solid var(--border);
  border-radius: 50%;
  background: var(--card-bg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.2s, background-color 0.2s;
}

.theme-toggle:hover {
  border-color: var(--accent);
}

.theme-toggle:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.theme-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}

.light-icon { color: #E8953A; }
.dark-icon { display: none; color: #B8A898; }

[data-theme="dark"] .light-icon { display: none; }
[data-theme="dark"] .dark-icon { display: flex; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .light-icon { display: none; }
  :root:not([data-theme="light"]) .dark-icon { display: flex; }
}

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

/* --- Base --- */
html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  color: var(--text-primary);
  background-color: var(--bg);
  line-height: 1.6;
  min-height: 100vh;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* --- Container --- */
.container {
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 var(--space-md);
}

/* --- Utility --- */
.hidden {
  display: none !important;
}

/* --- Site Header --- */
.site-header {
  text-align: center;
  padding: var(--space-3xl) var(--space-md) var(--space-lg);
  position: relative;
}

.site-title {
  font-family: var(--font-heading);
  font-size: clamp(2rem, 6vw, 3.5rem);
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
  margin-bottom: var(--space-sm);
}

.site-tagline {
  font-size: clamp(1rem, 2.5vw, 1.25rem);
  color: var(--text-secondary);
  max-width: 500px;
  margin: 0 auto;
}

/* --- Hero / Search --- */
.hero {
  padding: var(--space-md) var(--space-md) var(--space-xl);
}

.search-form {
  max-width: 600px;
  margin: 0 auto var(--space-lg);
}

.search-input-wrap {
  display: flex;
  gap: var(--space-sm);
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-xs);
  transition: border-color 0.2s;
}

.search-input-wrap:focus-within {
  border-color: var(--accent);
}

#search-input {
  flex: 1;
  border: none;
  outline: none;
  padding: var(--space-sm) var(--space-md);
  font-size: 1.1rem;
  font-family: var(--font-body);
  background: transparent;
  color: var(--text-primary);
  min-width: 0;
}

#search-input::placeholder {
  color: #767676;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-sm) var(--space-lg);
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
  transition: background-color 0.2s, transform 0.1s;
  white-space: nowrap;
}

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

.btn-primary {
  background-color: var(--accent);
  color: #FFFFFF;
}

.btn-primary:hover {
  background-color: var(--accent-hover);
  text-decoration: none;
}

.btn-secondary {
  background-color: var(--accent-light);
  color: var(--accent);
}

.btn-secondary:hover {
  background-color: #FFE4D6;
  text-decoration: none;
}

/* --- Suggestion Chips --- */
.suggestion-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-sm);
  max-width: 600px;
  margin: 0 auto;
}

.chip {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: var(--space-xs) var(--space-md);
  font-size: 0.9rem;
  font-family: var(--font-body);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

.chip:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}

/* --- Ad Slots (dev placeholders) --- */
.ad-slot {
  display: none; /* Hidden until AdSense is approved — remove this line when enabling ads */
  max-width: var(--max-width);
  margin: var(--space-lg) auto;
  padding: var(--space-lg) var(--space-md);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  text-align: center;
  background: var(--card-bg);
  position: relative;
}

.ad-label {
  font-size: 0.75rem;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.ad-slot--leaderboard {
  min-height: 90px;
}

.ad-slot--in-article {
  margin: var(--space-xl) 0;
  min-height: 100px;
}

/* --- Results Section --- */
.results-section {
  padding: var(--space-xl) 0;
}

.results-section.fade-in {
  animation: fadeSlideIn 0.4s ease-out;
}

@keyframes fadeSlideIn {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.result-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  box-shadow: 0 2px 12px var(--shadow);
}

.result-header {
  margin-bottom: var(--space-xl);
}

.result-headline {
  font-family: var(--font-heading);
  font-size: clamp(1.3rem, 3.5vw, 1.75rem);
  color: var(--green);
  line-height: 1.3;
  margin-bottom: var(--space-sm);
}

.result-blurb {
  font-size: 1.05rem;
  color: var(--text-secondary);
  line-height: 1.7;
}

/* --- Videos --- */
.videos-section,
.books-section {
  margin-top: var(--space-xl);
}

.videos-section h3,
.books-section h3 {
  font-family: var(--font-heading);
  font-size: 1.2rem;
  margin-bottom: var(--space-md);
  color: var(--text-primary);
}

.videos-grid {
  display: grid;
  gap: var(--space-md);
  grid-template-columns: 1fr;
}

.video-embed {
  position: relative;
  padding-bottom: 56.25%; /* 16:9 */
  height: 0;
  overflow: hidden;
  border-radius: var(--radius);
  background: #000;
}

.video-embed iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.video-title {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-top: var(--space-sm);
}

/* Thumbnail fallback (API results) */
.video-thumbnail-card {
  display: block;
  text-decoration: none;
  color: var(--text-primary);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform 0.2s;
}

.video-thumbnail-card:hover {
  transform: scale(1.02);
  text-decoration: none;
}

.video-thumbnail-wrap {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
}

.video-thumbnail-wrap img {
  width: 100%;
  aspect-ratio: 16/9;
  object-fit: cover;
}

.play-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 56px;
  height: 56px;
  background: rgba(0, 0, 0, 0.7);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.5rem;
  pointer-events: none;
}

/* --- Video Fallback Card (dead video replacement) --- */
.video-fallback-card {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: var(--text-primary);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform 0.2s;
}

.video-fallback-card:hover {
  transform: scale(1.02);
  text-decoration: none;
}

.video-fallback-wrap {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  aspect-ratio: 16/9;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.fallback-text {
  color: var(--text-secondary);
  font-size: 0.95rem;
  text-align: center;
  padding: var(--space-md);
}

/* --- Books --- */
.books-grid {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.book-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  background: var(--bg);
  border-radius: var(--radius);
  padding: var(--space-md) var(--space-lg);
}

.book-info {
  flex: 1;
  min-width: 0;
}

.book-title {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text-primary);
}

.book-author {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.book-link {
  display: inline-flex;
  align-items: center;
  padding: var(--space-sm) var(--space-md);
  background: var(--accent);
  color: #FFFFFF;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  transition: background-color 0.2s;
}

.book-link:hover {
  background: var(--accent-hover);
  text-decoration: none;
}

/* --- Result Actions --- */
.result-actions {
  margin-top: var(--space-xl);
  text-align: center;
}

/* --- Fallback Message --- */
.fallback-message {
  text-align: center;
  padding: var(--space-xl);
}

.fallback-message p {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: var(--space-md);
}

/* --- Loading --- */
.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: var(--space-xl) auto;
  animation: spin 0.8s linear infinite;
}

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

/* --- Browse Topics Directory --- */
.topics-directory {
  padding: var(--space-2xl) 0 var(--space-md);
}

.directory-title {
  font-family: var(--font-heading);
  font-size: clamp(1.5rem, 4vw, 2rem);
  text-align: center;
  margin-bottom: var(--space-sm);
}

.directory-subtitle {
  text-align: center;
  color: var(--text-secondary);
  margin-bottom: var(--space-2xl);
  font-size: 1.05rem;
}

/* Category sections */
.category-section {
  margin-bottom: var(--space-xl);
}

.category-section:last-child {
  margin-bottom: 0;
}

.category-heading {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-xs);
  border-bottom: 1px solid var(--border);
}

.category-grid {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
}

/* Topic pills in directory */
.topic-pill {
  display: inline-flex;
  align-items: center;
  padding: var(--space-sm) var(--space-md);
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font-body);
}

.topic-pill:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px var(--shadow);
}

.topic-pill.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #FFFFFF;
}

/* --- Footer --- */
.site-footer {
  text-align: center;
  padding: var(--space-md) var(--space-md);
  border-top: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.site-footer p {
  margin: 0 0 0.25rem 0;
}

.site-footer p:last-child {
  margin-bottom: 0;
}

.site-footer a {
  color: var(--accent);
  text-decoration: none;
}

.site-footer a:hover {
  text-decoration: underline;
}

/* --- Dark mode overrides for specific elements --- */
[data-theme="dark"] .search-input-wrap {
  background: var(--card-bg);
}

[data-theme="dark"] #search-input {
  color: var(--text-primary);
}

[data-theme="dark"] .video-embed {
  background: #111;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .search-input-wrap {
    background: var(--card-bg);
  }
  :root:not([data-theme="light"]) #search-input {
    color: var(--text-primary);
  }
}

/* ============================================================
   RESPONSIVE: Tablet+ (600px)
   ============================================================ */
@media (min-width: 600px) {
  .videos-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .book-card {
    padding: var(--space-md) var(--space-xl);
  }
}

/* ============================================================
   RESPONSIVE: Desktop (768px+)
   ============================================================ */
@media (min-width: 768px) {
  .site-header {
    padding: var(--space-3xl) var(--space-md) var(--space-xl);
  }

  .result-card {
    padding: var(--space-2xl) var(--space-3xl);
  }
}

/* ============================================================
   SCROLL NAVIGATION BUTTONS (Floating Nav)
   ============================================================ */
.scroll-nav {
  position: fixed;
  bottom: 30px;
  right: 30px;
  z-index: 99;
  display: none;
  flex-direction: column;
  gap: 10px;
}

.scroll-nav.visible {
  display: flex;
}

.scroll-btn {
  width: 50px;
  height: 50px;
  border: none;
  outline: none;
  border-radius: 50%;
  background-color: var(--accent);
  color: #FFFFFF;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px var(--shadow);
  transition: background-color 0.2s, transform 0.2s, box-shadow 0.2s;
}

.scroll-btn:hover {
  background-color: var(--accent-hover);
  transform: translateY(-3px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.scroll-btn:active {
  transform: translateY(-1px);
}

.scroll-btn:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.scroll-bottom {
  background-color: var(--text-secondary);
}

.scroll-bottom:hover {
  background-color: var(--text-primary);
}

[data-theme="dark"] .scroll-btn {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .scroll-bottom {
  background-color: #555;
}

[data-theme="dark"] .scroll-bottom:hover {
  background-color: #777;
}

@media (max-width: 768px) {
  .scroll-nav {
    bottom: 20px;
    right: 20px;
  }

  .scroll-btn {
    width: 44px;
    height: 44px;
  }
}

/* ============================================================
   FOCUS STYLES (WCAG AA keyboard navigation)
   ============================================================ */
.btn:focus-visible,
.chip:focus-visible,
.topic-pill:focus-visible,
.book-link:focus-visible,
.video-thumbnail-card:focus-visible,
.video-fallback-card:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ============================================================
   REDUCED MOTION (WCAG 2.1 — vestibular disorders)
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  html {
    scroll-behavior: auto;
  }
}
