html {
  scroll-behavior: smooth;
}

body {
  background-color: #0a0a0f;
  background-image:
    radial-gradient(ellipse 80% 50% at 50% 0%, rgba(6, 182, 212, 0.25), transparent),
    radial-gradient(ellipse 60% 50% at 100% 50%, rgba(59, 130, 246, 0.2), transparent),
    radial-gradient(ellipse 60% 50% at 0% 100%, rgba(139, 92, 246, 0.2), transparent),
    radial-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px);
  background-size: 100%, 100%, 100%, 24px 24px;
  background-attachment: fixed;
  min-height: 100vh;
  color: #e5e7eb;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --text-primary: #e5e7eb;
  --text-secondary: #9ca3af;
  --text-link: #22d3ee;
  --bg-card: rgba(255, 255, 255, 0.05);
  --border-card: rgba(255, 255, 255, 0.1);
  --bg-header: rgba(10, 10, 15, 0.8);
  --border-header: rgba(255, 255, 255, 0.1);
}

.prose .callout {
  margin: 1.5em 0;
  padding: 1rem 1.125rem;
  border: 1px solid rgba(34, 211, 238, 0.24);
  border-left: 4px solid #22d3ee;
  border-radius: 0.5rem;
  background: rgba(6, 182, 212, 0.08);
  color: var(--text-primary, #e5e7eb);
}

.prose .callout.callout-example {
  border-color: rgba(122, 217, 185, 0.24);
  border-left-color: #7ad9b9;
  background: rgba(122, 217, 185, 0.08);
}

.prose .callout.callout-note .callout-title {
  color: #22d3ee !important;
}

.prose .callout.callout-info .callout-title {
  color: #67e8f9 !important;
}

.prose .callout.callout-performance {
  border-color: rgba(96, 165, 250, 0.28);
  border-left-color: #60a5fa;
  background: rgba(96, 165, 250, 0.08);
}

.prose .callout.callout-performance .callout-title {
  color: #93c5fd !important;
}

.prose .callout.callout-bestpractice {
  border-color: rgba(52, 211, 153, 0.28);
  border-left-color: #34d399;
  background: rgba(52, 211, 153, 0.08);
}

.prose .callout.callout-bestpractice .callout-title {
  color: #6ee7b7 !important;
}

.prose .callout.callout-troubleshooting {
  border-color: rgba(251, 191, 36, 0.28);
  border-left-color: #fbbf24;
  background: rgba(251, 191, 36, 0.08);
}

.prose .callout.callout-warning {
  border-color: rgba(248, 113, 113, 0.3);
  border-left-color: #f87171;
  background: rgba(248, 113, 113, 0.08);
}

.prose .callout .callout-title {
  margin: 0 0 0.35rem 0 !important;
  color: #7ad9b9 !important;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.3;
  text-transform: uppercase;
}

.prose .callout.callout-troubleshooting .callout-title {
  color: #fbbf24 !important;
}

.prose .callout.callout-warning .callout-title {
  color: #fca5a5 !important;
}

.prose .callout > :last-child {
  margin-bottom: 0 !important;
}

.prose .callout > p {
  margin-top: 0.5rem !important;
}

.prose .callout code {
  background-color: rgba(255, 255, 255, 0.12) !important;
}

.dl-card {
  display: block;
  padding: 1.5rem;
  border-radius: 0.75rem;
  transition: all 0.2s;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
}

.dl-card:hover {
  transform: translateY(-2px);
  border-color: rgba(6, 182, 212, 0.4);
  box-shadow: 0 0 24px rgba(6, 182, 212, 0.15), 0 4px 24px rgba(0, 0, 0, 0.3);
}

.dl-btn {
  display: inline-block;
  padding: 0.625rem 1.25rem;
  border-radius: 0.5rem;
  font-weight: 500;
  font-size: 0.875rem;
  text-decoration: none;
  transition: all 0.15s;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.7);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.dl-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.3);
  color: #fff;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

.dl-btn-primary {
  display: inline-block;
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 0.5rem;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.15s;
  cursor: pointer;
  background: linear-gradient(135deg, #06b6d4, #3b82f6);
  border: none;
}

.dl-btn-primary:hover {
  box-shadow: 0 0 24px rgba(6, 182, 212, 0.4), 0 4px 12px rgba(59, 130, 246, 0.3);
}

.search-hit {
  background: rgba(6, 182, 212, 0.25);
  color: #22d3ee;
  border-radius: 2px;
  padding: 0 2px;
}

.search-result-card:hover {
  border-color: rgba(6, 182, 212, 0.4) !important;
  box-shadow: 0 0 16px rgba(6, 182, 212, 0.12);
}

/* Theme toggle icons: sun shown in dark theme, moon shown in light */
#theme-toggle .theme-icon-moon {
  display: none;
}

html.light #theme-toggle .theme-icon-moon {
  display: block;
}

html.light #theme-toggle .theme-icon-sun {
  display: none;
}

/* Book page layout: cover + details, single column on small screens */
.book-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 3rem;
  align-items: start;
}

@media (min-width: 768px) {
  .book-grid {
    grid-template-columns: minmax(220px, 360px) minmax(0, 1fr);
  }
}

html.light body {
  background-color: #f8fafc;
  background-image:
    radial-gradient(ellipse 80% 50% at 50% 0%, rgba(6, 182, 212, 0.15), transparent),
    radial-gradient(ellipse 60% 50% at 100% 50%, rgba(59, 130, 246, 0.1), transparent),
    radial-gradient(ellipse 60% 50% at 0% 100%, rgba(139, 92, 246, 0.1), transparent),
    radial-gradient(rgba(0, 0, 0, 0.05) 1px, transparent 1px);
  background-size: 100%, 100%, 100%, 24px 24px;
  background-attachment: fixed;
  min-height: 100vh;
  color: #1f2937;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --text-primary: #1f2937;
  --text-secondary: #475569;
  --text-link: #0891b2;
  --bg-card: rgba(255, 255, 255, 0.8);
  --border-card: rgba(0, 0, 0, 0.1);
  --bg-header: rgba(248, 250, 252, 0.9);
  --border-header: rgba(0, 0, 0, 0.1);
  --input-bg: #f1f5f9;
  --input-border: #94a3b8;
}

/* Re-map gray-on-dark text utilities that are illegible on the light
   background. :where() keeps specificity at one class, so hover utilities
   still win, while these rules beat the originals by source order. */
:where(html.light) h1.text-white,
:where(html.light) h2.text-white,
:where(html.light) h3.text-white {
  color: #1f2937;
}

:where(html.light) .text-gray-100,
:where(html.light) .text-gray-200,
:where(html.light) .text-gray-300 {
  color: #374151;
}

:where(html.light) .text-gray-400 {
  color: #4b5563;
}

/* The remaps above are unlayered, so they beat the (layered) Tailwind hover
   utilities on the same elements; restore hover colors for the combinations
   used in the app (chapter nav, admin filter chips). */
:where(html.light) .hover\:text-cyan-400:hover,
:where(html.light) .group:hover .group-hover\:text-cyan-400 {
  color: #0891b2;
}

:where(html.light) .hover\:text-white:hover {
  color: #111827;
}

/* Code blocks keep their dark background in light theme */
:where(html.light) pre.text-gray-100,
:where(html.light) pre .text-gray-100,
:where(html.light) pre code {
  color: #e5e7eb;
}

html.light .dl-card {
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid rgba(0, 0, 0, 0.1);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
  color: #1f2937;
}

html.light .dl-card h2,
html.light .dl-card h3,
html.light .dl-card h4 {
  color: #1f2937 !important;
}

html.light .dl-card:hover {
  border-color: rgba(6, 182, 212, 0.5);
  box-shadow: 0 0 24px rgba(6, 182, 212, 0.15), 0 4px 24px rgba(0, 0, 0, 0.12);
}

html.light .dl-btn {
  color: rgba(0, 0, 0, 0.7);
  background: rgba(0, 0, 0, 0.06);
  border: 1px solid rgba(0, 0, 0, 0.15);
}

html.light .dl-btn:hover {
  background: rgba(0, 0, 0, 0.1);
  border-color: rgba(0, 0, 0, 0.3);
  color: #000;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

html.light header {
  background: var(--bg-header, rgba(248, 250, 252, 0.9)) !important;
  border-color: var(--border-header, rgba(0, 0, 0, 0.1)) !important;
}

html.light header a,
html.light header span {
  color: var(--text-secondary, #475569) !important;
}

html.light header .text-white {
  color: var(--text-primary, #1f2937) !important;
}

html.light #theme-toggle {
  background: rgba(0, 0, 0, 0.05) !important;
  border-color: rgba(0, 0, 0, 0.15) !important;
  color: #475569 !important;
}

html.light .prose h1,
html.light .prose h2,
html.light .prose h3,
html.light .prose h4 {
  color: #1f2937 !important;
}

html.light .prose p,
html.light .prose li,
html.light .prose td {
  color: #374151 !important;
}

html.light .prose strong {
  color: #1f2937 !important;
}

html.light .prose blockquote {
  color: #374151 !important;
  border-left-color: #0891b2 !important;
  background-color: rgba(0, 0, 0, 0.03) !important;
}

html.light .prose .callout {
  color: #374151 !important;
  border-color: rgba(8, 145, 178, 0.24) !important;
  border-left-color: #0891b2 !important;
  background: #eef8fb !important;
}

html.light .prose .callout.callout-example {
  border-color: rgba(22, 163, 116, 0.25) !important;
  border-left-color: #16a374 !important;
  background: #eefbf6 !important;
}

html.light .prose .callout.callout-note .callout-title {
  color: #0891b2 !important;
}

html.light .prose .callout.callout-info .callout-title {
  color: #0e7490 !important;
}

html.light .prose .callout.callout-performance {
  border-color: rgba(37, 99, 235, 0.25) !important;
  border-left-color: #2563eb !important;
  background: #eff6ff !important;
}

html.light .prose .callout.callout-performance .callout-title {
  color: #1d4ed8 !important;
}

html.light .prose .callout.callout-bestpractice {
  border-color: rgba(5, 150, 105, 0.25) !important;
  border-left-color: #059669 !important;
  background: #ecfdf5 !important;
}

html.light .prose .callout.callout-bestpractice .callout-title {
  color: #047857 !important;
}

html.light .prose .callout.callout-troubleshooting {
  border-color: rgba(217, 119, 6, 0.28) !important;
  border-left-color: #d97706 !important;
  background: #fff8e6 !important;
}

html.light .prose .callout.callout-warning {
  border-color: rgba(220, 38, 38, 0.28) !important;
  border-left-color: #dc2626 !important;
  background: #fff1f2 !important;
}

html.light .prose .callout .callout-title {
  color: #047857 !important;
}

html.light .prose .callout.callout-troubleshooting .callout-title {
  color: #b45309 !important;
}

html.light .prose .callout.callout-warning .callout-title {
  color: #b91c1c !important;
}

html.light .prose code {
  color: #1f2937 !important;
  background-color: rgba(0, 0, 0, 0.08) !important;
}

html.light .prose pre {
  background-color: #1f2937 !important;
}

html.light .prose pre code {
  color: #e5e7eb !important;
  background-color: transparent !important;
}

html.light h2.section-title {
  color: #1f2937 !important;
}

html.light .auth-card {
  background: rgba(255, 255, 255, 0.85) !important;
  border-color: rgba(0, 0, 0, 0.1) !important;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1) !important;
}

html.light .auth-card h2 {
  color: #1f2937 !important;
}

html.light .auth-card label {
  color: #374151 !important;
}

html.light .auth-card input[type="email"],
html.light .auth-card input[type="password"],
html.light .auth-card input[type="text"] {
  background: var(--input-bg) !important;
  border: 1px solid var(--input-border) !important;
  color: var(--text-primary) !important;
}

html.light .auth-card .auth-text {
  color: #4b5563 !important;
}

html.light .auth-card .auth-link {
  color: #0891b2 !important;
}

html.light .auth-card .auth-link:hover {
  color: #0e7490 !important;
}

html.light .auth-card .auth-github {
  background: rgba(0, 0, 0, 0.06) !important;
  border-color: rgba(0, 0, 0, 0.15) !important;
  color: #1f2937 !important;
}

html.light .auth-card .auth-divider {
  border-color: rgba(0, 0, 0, 0.1) !important;
}

html.light .auth-card .auth-divider span {
  color: #6b7280 !important;
}

html.light .search-hit {
  background: rgba(6, 182, 212, 0.15);
  color: #0e7490;
}
