@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;0,9..40,800;1,9..40,400&family=Barlow+Condensed:wght@500;600;700&display=swap');

/* Favedom Design System -- compiled token stylesheet. All tokens inlined. */
/* Favedom Color Tokens */
:root {
  /* ── Base surfaces ── */
  --color-bg:           #0B0D18;
  --color-surface-1:    #13162A;
  --color-surface-2:    #1B1F35;
  --color-surface-3:    #252A45;
  --color-surface-4:    #2E3355;
  --color-border:       #2B2F4E;
  --color-border-muted: #1D2038;

  /* ── Purple / Brand ── */
  --color-purple-50:  #EDE8FF;
  --color-purple-100: #D5CCFF;
  --color-purple-200: #BAA8FF;
  --color-purple-300: #9D84FF;
  --color-purple-400: #8A6BFF;
  --color-purple-500: #765CF6;  /* primary — #765CF6 gives 4.54:1 with white (AA compliant) */
  --color-purple-600: #6847E0;
  --color-purple-700: #5233C2;
  --color-purple-800: #3A21A0;
  --color-purple-900: #231472;

  /* ── Text ── */
  --color-text-primary:   #FFFFFF;
  --color-text-secondary: #9CA5C2;
  --color-text-muted:     #9EA5BF;  /* lightened 25% from #7E87AA → 7.92:1 on bg, 5.74:1 on surface-3 (AA, all surfaces) */
  --color-text-disabled:  #3D4468;
  --color-text-accent:    #9D84FF;
  --color-text-inverse:   #0B0D18;

  /* ── Semantic status ── */
  --color-success:         #22C55E;
  --color-success-subtle:  rgba(34,197,94,0.12);
  --color-warning:         #F59E0B;
  --color-warning-subtle:  rgba(245,158,11,0.12);
  --color-error:           #EF4444;
  --color-error-subtle:    rgba(239,68,68,0.12);
  --color-info:            #3B82F6;
  --color-info-subtle:     rgba(59,130,246,0.12);

  /* ── Library Popularity ── */
  --color-pop-very-high: #22C55E;
  --color-pop-high:      #84CC16;
  --color-pop-moderate:  #F59E0B;
  --color-pop-low:       #6C7498;

  /* ── Overlays & scrims ── */
  --color-overlay-sm:    rgba(255,255,255,0.04);
  --color-overlay-md:    rgba(255,255,255,0.08);
  --color-overlay-hover: rgba(255,255,255,0.06);
  --color-scrim-dark:    rgba(11,13,24,0.82);
  --color-scrim-cover:   linear-gradient(to top, rgba(11,13,24,0.95) 0%, rgba(11,13,24,0.4) 60%, transparent 100%);
}

/* Favedom Typography Tokens */

/* Cascadia Code — upload CascadiaCode.woff2 to assets/fonts/ to activate */
@font-face {
  font-family: 'Cascadia Code';
  src: url('../assets/fonts/CascadiaCode.woff2') format('woff2');
  font-weight: 100 700;
  font-style: normal;
  font-display: swap;
}
/* NOTE: No official font files were provided. DM Sans is substituted as the nearest
   visual match to the bold sans-serif seen in the UI mockups. Supply .woff2 files to
   replace with the exact production typeface. */

/* Harben — brand wordmark typeface, licensed for "FAVEDOM" branding use only.
   Do not apply to body copy or UI text — brand wordmark contexts only. */
@font-face {
  font-family: 'Harben';
  src: url('/assets/fonts/Harben.woff') format('woff'),
       url('/assets/fonts/Harben.otf') format('opentype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --font-sans: 'DM Sans', system-ui, -apple-system, sans-serif;
  --font-condensed: 'Barlow Condensed', 'DM Sans', sans-serif;
  --font-mono: ui-monospace, 'Cascadia Code', monospace;
  --font-brand: 'Harben', 'Barlow Condensed', sans-serif;

  /* Scale */
  --text-xs:   0.6875rem;   /* 11px */
  --text-sm:   0.75rem;     /* 12px */
  --text-base: 0.875rem;    /* 14px */
  --text-md:   1rem;        /* 16px */
  --text-lg:   1.125rem;    /* 18px */
  --text-xl:   1.25rem;     /* 20px */
  --text-2xl:  1.5rem;      /* 24px */
  --text-3xl:  1.875rem;    /* 30px */
  --text-4xl:  2.25rem;     /* 36px */
  --text-5xl:  3rem;        /* 48px */
  --text-6xl:  3.75rem;     /* 60px */

  /* Weight */
  --font-light:     300;
  --font-regular:   400;
  --font-medium:    500;
  --font-semibold:  600;
  --font-bold:      700;
  --font-extrabold: 800;

  /* Line heights */
  --leading-none:    1;
  --leading-tight:   1.15;
  --leading-snug:    1.3;
  --leading-normal:  1.5;
  --leading-relaxed: 1.65;

  /* Letter spacing */
  --tracking-tight:   -0.03em;
  --tracking-snug:    -0.02em;
  --tracking-normal:  0em;
  --tracking-wide:    0.04em;
  --tracking-wider:   0.08em;
  --tracking-widest:  0.14em;
}

/* Favedom Spacing & Layout Tokens */
:root {
  /* 4px base grid */
  --space-0:  0;
  --space-1:  0.25rem;   /* 4px */
  --space-2:  0.5rem;    /* 8px */
  --space-3:  0.75rem;   /* 12px */
  --space-4:  1rem;      /* 16px */
  --space-5:  1.25rem;   /* 20px */
  --space-6:  1.5rem;    /* 24px */
  --space-8:  2rem;      /* 32px */
  --space-10: 2.5rem;    /* 40px */
  --space-12: 3rem;      /* 48px */
  --space-16: 4rem;      /* 64px */
  --space-20: 5rem;      /* 80px */
  --space-24: 6rem;      /* 96px */

  /* Border radii */
  --radius-sm:   4px;
  --radius-md:   8px;
  --radius-lg:   12px;
  --radius-xl:   16px;
  --radius-2xl:  24px;
  --radius-full: 9999px;

  /* Layout */
  --max-width-content: 1200px;
  --max-width-wide:    1440px;
  --nav-height:        60px;
  --mobile-nav-height: 56px;
  --sidebar-width:     280px;
  --cover-ratio:       1.5; /* @kind other */
}

/* Favedom Effects Tokens — shadow, blur, animation */
:root {
  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(0,0,0,0.45);
  --shadow-sm: 0 2px 6px rgba(0,0,0,0.5);
  --shadow-md: 0 4px 14px rgba(0,0,0,0.55);
  --shadow-lg: 0 8px 28px rgba(0,0,0,0.65);
  --shadow-xl: 0 16px 48px rgba(0,0,0,0.75);

  /* Purple glow — buttons, focused elements */
  --shadow-purple-sm: 0 2px 12px rgba(123,92,246,0.22);
  --shadow-purple-md: 0 4px 24px rgba(123,92,246,0.32);
  --shadow-purple-lg: 0 8px 40px rgba(123,92,246,0.42);

  /* Cover card glow — book covers on hover */
  --shadow-cover: 0 12px 40px rgba(0,0,0,0.7);

  /* Blur */
  --blur-sm:  blur(4px);  /* @kind other */
  --blur-md:  blur(8px);  /* @kind other */
  --blur-lg:  blur(16px); /* @kind other */
  --blur-xl:  blur(24px); /* @kind other */

  /* Transitions */
  --ease-out:    cubic-bezier(0.16,1,0.3,1);   /* @kind other */
  --ease-bounce: cubic-bezier(0.34,1.56,0.64,1); /* @kind other */

  --duration-fast:   100ms; /* @kind other */
  --duration-base:   180ms; /* @kind other */
  --duration-slow:   300ms; /* @kind other */
  --duration-slower: 480ms; /* @kind other */

  --transition-fast:   var(--duration-fast)   var(--ease-out); /* @kind other */
  --transition-base:   var(--duration-base)   var(--ease-out); /* @kind other */
  --transition-slow:   var(--duration-slow)   var(--ease-out); /* @kind other */
}

/* ── Global interactive states — ADA / WCAG 2.1 AA ─────────────────────────
   Applies to all <a>, <button>, and interactive elements site-wide.
   Components using inline styles will layer on top of these globals.
   ─────────────────────────────────────────────────────────────────────────── */

/* Remove browser default outline — we supply our own via :focus-visible */
*:focus {
  outline: none;
}

/* Keyboard focus indicator — visible ring using brand purple.
   3px solid + 2px offset gives strong 3:1+ contrast on all surfaces.
   :focus-visible targets keyboard navigation only, not mouse clicks. */
*:focus-visible {
  outline: 3px solid var(--color-purple-400);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ── Links — base transition only, no opacity hack ──
   Hover states are handled per-context via .nav-link, .text-link, etc.
   The old opacity:0.82 global hover is removed — it fought class-based states. */
a {
  transition: color var(--transition-base);
}

/* Unclassed links that aren't in a known context — conservative fallback */
a:not([class]):hover {
  opacity: 0.85;
}

/* ── Links — shared class system ───────────────────────────────────────── */
/* Internal navigation: white bold, no underline                          */
.link_internal {
  color: var(--color-text-primary);
  font-weight: var(--font-semibold);
  text-decoration: none;
  transition: color var(--transition-base);
}
.link_internal:hover, .link_internal:focus-visible {
  color: var(--color-text-secondary);
}

/* External/source references: white bold, no underline                   */
.link_external {
  color: var(--color-text-primary);
  font-weight: var(--font-semibold);
  text-decoration: none;
  transition: color var(--transition-base);
}
.link_external:hover, .link_external:focus-visible {
  color: var(--color-text-secondary);
}

/* ── Buttons — shared class system ─────────────────────────────────────── */
/* Single source of truth for CTAs. All templates use these classes       */
/* instead of inline styles or scoped redefinitions.                      */

/* Base — shared structure for all button variants */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: var(--font-sans);
  font-weight: var(--font-semibold);
  font-size: 14px;
  padding: 10px 24px;
  height: 44px;
  border-radius: var(--radius-md);
  text-decoration: none;
  white-space: nowrap;
  border: none;
  cursor: pointer;
  transition: background var(--transition-base), box-shadow var(--transition-base), color var(--transition-base);
}

/* Primary — purple filled, white text */
.btn_primary {
  background: var(--color-purple-500);
  color: #fff;
  box-shadow: var(--shadow-purple-sm);
}
.btn_primary:hover, .btn_primary:focus-visible {
  background: var(--color-purple-600);
}

/* Secondary — surface background, border outline */
.btn_secondary {
  background: var(--color-surface-2);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border);
}
.btn_secondary:hover, .btn_secondary:focus-visible {
  background: var(--color-surface-3);
}

/* Small variant — compact for card-level CTAs */
.btn_sm {
  font-size: 11px;
  padding: 6px 12px;
  height: auto;
}

/* Large variant — prominent page-level CTAs */
.btn_lg {
  font-size: var(--text-md);
  padding: 10px 28px;
  height: 48px;
}

/* ── Legacy attribute-selector hover rules ─────────────────────────────── */
/* Retained for inline-styled buttons not yet migrated to .btn classes.  */
/* Remove these once all inline button styles are replaced.              */
a[style*="background:var(--color-purple-500)"],
a[style*="background: var(--color-purple-500)"],
button[style*="background:var(--color-purple-500)"] {
  transition: background var(--transition-base), box-shadow var(--transition-base);
}
a[style*="background:var(--color-purple-500)"]:hover,
a[style*="background: var(--color-purple-500)"]:hover,
button[style*="background:var(--color-purple-500)"]:hover {
  background: var(--color-purple-600) !important;
  box-shadow: var(--shadow-purple-sm);
}
a[style*="border:1px solid var(--color-border)"],
a[style*="border: 1px solid var(--color-border)"] {
  transition: background var(--transition-base), color var(--transition-base);
}
a[style*="border:1px solid var(--color-border)"]:hover,
a[style*="border: 1px solid var(--color-border)"]:hover {
  background: var(--color-overlay-hover) !important;
}

/* ── Form controls — shared select/input styling ───────────────────────── */
.form_select {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--color-text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}
.form_select:focus-visible {
  border-color: var(--color-purple-500);
  box-shadow: 0 0 0 2px rgba(118, 92, 246, 0.25);
}

/* ── Surface / card links ── */
a[style*="background:var(--color-surface-2)"]:hover,
a[style*="background: var(--color-surface-2)"]:hover {
  background: var(--color-surface-3) !important;
}

/* ── Link state system — WCAG 2.1 AA, dark theme ─────────────────────────────
   Three contexts: nav links, text links (inline), footer links.
   All states maintain ≥ 4.5:1 contrast on --color-bg (#0B0D18).
   Token contrast ratios (verified):
     --color-text-primary   #FFF       21:1   ✓ AAA
     --color-text-secondary #9CA5C2   8.4:1   ✓ AAA
     --color-text-muted     #7E87AA   5.8:1   ✓ AA
     --color-text-accent    #9D84FF   7.0:1   ✓ AAA
     --color-purple-300     #9D84FF   7.0:1   ✓ AAA
     --color-purple-200     #BAA8FF  10.2:1   ✓ AAA
   ────────────────────────────────────────────────────────────────────────── */

/* Nav links — grouped context, color-only distinction acceptable (WCAG 1.4.1 §3) */
.nav-link {
  color: var(--color-text-primary);
  text-decoration: none;
  font-weight: var(--font-semibold);
  transition: color var(--transition-base), border-color var(--transition-base);
}
.nav-link:visited { color: var(--color-text-primary); }
.nav-link:hover   { color: var(--color-text-secondary); }
.nav-link:active  { color: var(--color-purple-300); }
.nav-link[aria-current="page"],
.nav-link.active  { color: var(--color-text-primary); font-weight: var(--font-semibold); }

/* Text links — inline with body text, require underline for WCAG 1.4.1 */
.text-link {
  color: var(--color-text-primary);
  font-weight: var(--font-semibold);
  text-decoration: none;
  transition: color var(--transition-base);
}
.text-link:visited {
  color: var(--color-text-primary);
}
.text-link:hover {
  color: var(--color-text-secondary);
}
.text-link:active { color: var(--color-text-secondary); }

/* Breadcrumb links */
.breadcrumb-link {
  color: var(--color-text-muted);
  text-decoration: none;
  transition: color var(--transition-base);
}
.breadcrumb-link:visited { color: var(--color-text-muted); }
.breadcrumb-link:hover   { color: var(--color-text-primary); }
.breadcrumb-link:active  { color: var(--color-purple-300); }

/* Inline text links inside paragraphs (<p a>, prose contexts) —
   catches links not explicitly classed, e.g. editorial content, disclaimers.
   Underline required: they appear mid-sentence alongside non-link text. */
p a:not([class]),
li a:not([class]) {
  color: var(--color-text-primary);
  font-weight: var(--font-semibold);
  text-decoration: none;
  transition: color var(--transition-base);
}
p a:not([class]):visited,
li a:not([class]):visited {
  color: var(--color-text-primary);
}
p a:not([class]):hover,
li a:not([class]):hover {
  color: var(--color-text-secondary);
}
p a:not([class]):active,
li a:not([class]):active { color: var(--color-text-secondary); }

/* ── Skip-to-content link — screen reader / keyboard users ──
   Visually hidden until focused; satisfies WCAG 2.4.1 Bypass Blocks. */
.skip-to-content {
  position: absolute;
  top: -100%;
  left: var(--space-4);
  z-index: 9999;
  background: var(--color-purple-500);
  color: #fff;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  font-weight: var(--font-semibold);
  text-decoration: none;
  transition: top var(--transition-fast);
}
.skip-to-content:focus-visible {
  top: var(--space-4);
  outline: 3px solid var(--color-purple-200);
  outline-offset: 2px;
}

/* ── Hamburger / mobile nav ───────────────────────────────────────────────── */
.nav-hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 40px;
  height: 40px;
  padding: 8px;
  background: none;
  border: none;
  cursor: pointer;
  border-radius: var(--radius-sm);
  -webkit-tap-highlight-color: transparent;
}
.nav-hamburger span {
  display: block;
  height: 2px;
  background: var(--color-text-primary);
  border-radius: 2px;
  transition: transform var(--transition-base), opacity var(--transition-base);
}
.nav-hamburger[aria-expanded="true"] span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
.nav-hamburger[aria-expanded="true"] span:nth-child(2) {
  opacity: 0;
}
.nav-hamburger[aria-expanded="true"] span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* Mobile drawer */
.nav-drawer {
  display: none;
  position: fixed;
  inset: 56px 0 0 0;
  z-index: 99;
  background: var(--color-surface-1);
  border-top: 1px solid var(--color-border-muted);
  padding: 24px 24px 40px;
  overflow-y: auto;
}
.nav-drawer.open { display: block; }
.nav-drawer ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.nav-drawer .nav-link {
  display: block;
  font-size: 18px;
  font-weight: 500;
  padding: 12px 0;
  border-bottom: 1px solid var(--color-border-muted);
}

@media (max-width: 640px) {
  .nav-hamburger { display: flex; }
  .nav-links-desktop { display: none !important; }
}
@media (min-width: 641px) {
  .nav-drawer { display: none !important; }
}

/* ── Loading skeletons — cover-card grid + search row list ──
   Static HTML shown before JS runs; render() overwrites innerHTML once data is ready.
   No new color tokens — reuses surface-2/surface-3/surface-4 shimmer sweep. */
@keyframes fvd-skeleton-shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.skeleton-card {
  aspect-ratio: 2/3;
  border-radius: 6px;
  border: 1px solid var(--color-border-muted);
  background: linear-gradient(90deg, var(--color-surface-2) 25%, var(--color-surface-3) 50%, var(--color-surface-2) 75%);
  background-size: 200% 100%;
  animation: fvd-skeleton-shimmer 1.4s ease-in-out infinite;
  margin-bottom: 10px;
}
.skeleton-line {
  height: 10px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--color-surface-2) 25%, var(--color-surface-3) 50%, var(--color-surface-2) 75%);
  background-size: 200% 100%;
  animation: fvd-skeleton-shimmer 1.4s ease-in-out infinite;
  margin-bottom: 6px;
}
.skeleton-line.short  { width: 60%; }
.skeleton-line.medium { width: 80%; }

.skeleton-row {
  display: flex;
  gap: 12px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 12px;
}
.skeleton-row-cover {
  flex-shrink: 0;
  width: 52px;
  height: 78px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--color-surface-3) 25%, var(--color-surface-4) 50%, var(--color-surface-3) 75%);
  background-size: 200% 100%;
  animation: fvd-skeleton-shimmer 1.4s ease-in-out infinite;
}
.skeleton-row-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
}
.skeleton-row-line {
  height: 10px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--color-surface-3) 25%, var(--color-surface-4) 50%, var(--color-surface-3) 75%);
  background-size: 200% 100%;
  animation: fvd-skeleton-shimmer 1.4s ease-in-out infinite;
}

/* ── Cover Pending placeholder ────────────────────────────────────────────── */
/* Single source of truth for the branded "COVER PENDING" card.              */
/* Used by CoverImage.jsx (React) inline styles AND cover_utils.js (vanilla) */
/* via class names. Matches CoverImage.jsx reference dimensions.             */
.cover-pending {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--color-surface-2);
  gap: 8px;
}
.cover-pending-icon {
  opacity: 0.25;
}
.cover-pending-label {
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: rgba(255, 255, 255, 0.3);
  text-transform: uppercase;
  line-height: 1.4;
  text-align: center;
  font-family: var(--font-condensed, sans-serif);
}
