/* 
  ========================================================================
  PEACE WORLD - DARK MODE (dark-mode.css)
  ========================================================================

  HOW THIS WORKS
  A `dark` class is toggled on <html> by theme-toggle.js (saved to
  localStorage so it persists across visits). Everything in this file is
  scoped under `.dark` and only applies once that class is present.

  There are two layers here:

  1. CSS custom properties (--color-*) — these are already used throughout
     base.css, navigation.css, cards.css, auth.css, admin.css, poems.css,
     footer.css (e.g. `.card-parchment { background-color:
     var(--color-white); }`). Redefining them under `.dark` automatically
     re-themes every custom component class in this project for free,
     without touching any of those files.

  2. Tailwind utility class overrides — most of the actual page markup uses
     Tailwind's CDN-generated utility classes directly in the EJS views
     (bg-white, text-slate-800, border-peace-100, etc.), with literal color
     values baked in via the tailwind.config in head.ejs, NOT CSS variables.
     Those classes can't be re-themed by changing a variable, so this file
     overrides the specific utility classes actually used across the site
     (found by scanning every view) with !important, scoped under `.dark`.
     This avoids having to add `dark:` variants to hundreds of individual
     elements across every EJS template.

  DARK PALETTE RATIONALE
  Rather than a generic gray dark mode, this stays on-brand: a deep,
  warm charcoal-teal background (evoking a "reading by lamplight" feel)
  paired with a brightened version of the same teal/olive/clay accents
  used in light mode, adjusted so they carry enough contrast against a
  dark background (the light-mode accent colors, e.g. teal #427c73,
  read as slightly muted on very dark backgrounds, so their dark-mode
  counterparts are a few steps lighter).
*/

html.dark {
  color-scheme: dark;
}

/* ------------------------------------------------------------------ */
/* 1. CSS custom property overrides (re-themes base.css, cards.css,   */
/*    navigation.css, auth.css, admin.css, poems.css, footer.css        */
/*    automatically since they already read these vars)                */
/* ------------------------------------------------------------------ */
html.dark {
  --color-sand: #101715;        /* page background */
  --color-sand-dark: #263a34;   /* borders / thumbnail placeholders */
  --color-teal: #6fb3a6;        /* brightened for contrast on dark bg */
  --color-teal-dark: #8fcabe;   /* used as a "hover / stronger" tone */
  --color-teal-light: rgba(111, 179, 166, 0.14); /* soft accent bg */
  --color-olive: #a3b17e;
  --color-clay: #e2916a;
  --color-slate: #dce7e2;       /* body text */
  --color-white: #17231f;       /* "surface" color: cards, inputs, modals */
}

/* Extra tokens used only within this file */
html.dark {
  --dark-text-1: #f2f6f4;  /* headings / high-emphasis text */
  --dark-text-2: #c3d1cb;  /* body copy */
  --dark-text-3: #93a29c;  /* meta / muted text */
  --dark-surface: #17231f; /* same as --color-white above, named for clarity */
  --dark-surface-alt: #1d2b27; /* slightly raised surface, e.g. badges */
  --dark-surface-alt-2: #223530; /* hover backgrounds */
}

/* ------------------------------------------------------------------ */
/* Page base                                                          */
/* ------------------------------------------------------------------ */
html.dark body {
  background-color: var(--color-sand);
}

html.dark ::selection {
  background-color: rgba(111, 179, 166, 0.35) !important;
  color: var(--dark-text-1) !important;
}

/* Scrollbar (WebKit) so it doesn't stay light-themed */
html.dark ::-webkit-scrollbar-track {
  background: var(--color-sand);
}
html.dark ::-webkit-scrollbar-thumb {
  background: var(--color-sand-dark);
  border-radius: 9999px;
}

/* ------------------------------------------------------------------ */
/* 2. Tailwind utility class overrides                                */
/*    Grouped by what they were doing in light mode.                  */
/* ------------------------------------------------------------------ */

/* --- Surfaces (cards, header, modals, inputs, dropdowns) --- */
html.dark .bg-white,
html.dark .bg-slate-50 {
  background-color: var(--dark-surface) !important;
}
html.dark .bg-white\/90,
html.dark .bg-white\/95 {
  background-color: rgba(23, 35, 31, 0.95) !important;
}
html.dark .bg-white\/40 {
  background-color: rgba(23, 35, 31, 0.4) !important;
}
html.dark .bg-slate-100 {
  background-color: var(--dark-surface-alt) !important;
}
html.dark .bg-peace-sand {
  background-color: var(--color-sand) !important;
}
html.dark .bg-peace-50,
html.dark .bg-peace-50\/50 {
  background-color: var(--dark-surface-alt) !important;
}
html.dark .bg-peace-50\/20 {
  background-color: rgba(29, 43, 39, 0.5) !important;
}
html.dark .bg-peace-100 {
  background-color: var(--dark-surface-alt-2) !important;
}
/* Hover states for the two classes above were missing: Tailwind generates
   `.hover\:bg-peace-50:hover` / `.hover\:bg-peace-100:hover` as separate
   rules from `.bg-peace-50` / `.bg-peace-100`, so overriding the base
   classes doesn't touch their hover variants. Without this, hovering any
   of the many light "ghost" buttons across the site (nav auth links,
   pagination, modal close buttons, filter chips, etc.) flashed the
   light-mode near-white/pale-teal color even in dark mode. Both share one
   "hover background" tone, consistent with --dark-surface-alt-2's purpose. */
html.dark .hover\:bg-peace-50:hover,
html.dark .hover\:bg-peace-100:hover {
  background-color: var(--dark-surface-alt-2) !important;
}
html.dark .bg-peace-200 {
  background-color: #2a4039 !important;
}
html.dark .bg-peace-300 {
  background-color: #325047 !important;
}

/* Dark backdrop overlays (modals) were already translucent dark — keep,
   just nudge slightly darker so they still read as an overlay on a
   now-dark page background. */
html.dark .bg-slate-900\/20,
html.dark .bg-slate-900\/30,
html.dark .bg-slate-900\/40 {
  background-color: rgba(0, 0, 0, 0.55) !important;
}

/* --- Body / heading / paragraph text --- */
html.dark .text-slate-950,
html.dark .text-slate-900,
html.dark .text-slate-800 {
  color: var(--dark-text-1) !important;
}
html.dark .text-slate-700,
html.dark .text-slate-600 {
  color: var(--dark-text-2) !important;
}
html.dark .text-slate-500,
html.dark .text-slate-400,
html.dark .text-slate-300 {
  color: var(--dark-text-3) !important;
}

/* --- Brand / accent text (links, icons, active nav, headings) --- */
html.dark .text-peace-400,
html.dark .text-peace-500,
html.dark .text-peace-600 {
  color: var(--color-teal) !important;
}
html.dark .text-peace-700,
html.dark .text-peace-850,
html.dark .hover\:text-peace-850:hover {
  color: var(--color-teal-dark) !important;
}
html.dark .text-peace-800,
html.dark .text-peace-900 {
  color: var(--dark-text-1) !important;
}
html.dark .text-peace-100,
html.dark .text-peace-200,
html.dark .text-peace-300 {
  color: var(--color-teal-dark) !important;
}
html.dark .text-peace-clay,
html.dark .text-clay-600 {
  color: var(--color-clay) !important;
}

/* --- Borders --- */
html.dark .border-peace-100,
html.dark .border-peace-100\/40,
html.dark .border-peace-200,
html.dark .border-peace-200\/80,
html.dark .border-slate-200 {
  border-color: var(--color-sand-dark) !important;
}
html.dark .border-peace-500,
html.dark .border-peace-600 {
  border-color: var(--color-teal) !important;
}

/* --- Status colors: success (green), and the soft category badges --- */
html.dark .bg-green-50 {
  background-color: #16281c !important;
}
html.dark .text-green-700 {
  color: #7fd99a !important;
}
html.dark .border-green-200 {
  border-color: #2f5c3f !important;
}

html.dark .bg-amber-50 {
  background-color: #2a2013 !important;
}
html.dark .text-amber-600 {
  color: #fbbf24 !important;
}

html.dark .bg-rose-50 {
  background-color: #2a1720 !important;
}
html.dark .text-rose-600,
html.dark .hover\:text-rose-600:hover {
  color: #fb7185 !important;
}

html.dark .bg-emerald-50 {
  background-color: #142a1f !important;
}
html.dark .text-emerald-600 {
  color: #34d399 !important;
}

html.dark .bg-blue-50 {
  background-color: #142130 !important;
}
html.dark .text-blue-600 {
  color: #60a5fa !important;
}

/* Note: this is Tailwind's built-in "teal" palette (bg-teal-50/text-teal-600),
   distinct from this project's custom "peace" teal — used as one of the
   soft category-icon badge colors on the home page. */
html.dark .bg-teal-50 {
  background-color: #122522 !important;
}
html.dark .text-teal-600 {
  color: #5eead4 !important;
}

html.dark .bg-orange-50 {
  background-color: #2a1c10 !important;
}
html.dark .text-orange-600 {
  color: #fb923c !important;
}

html.dark .bg-clay-50 {
  background-color: #2a1c14 !important;
}

/* --- Auth error / success banners (auth.css hardcodes light-mode colors) --- */
html.dark .auth-error-container {
  background-color: #2a1414 !important;
  border-color: #b3452f !important;
}
html.dark .auth-error-icon {
  color: #f0917c !important;
}
html.dark .auth-error-text {
  color: #f0b3a5 !important;
}

/* ------------------------------------------------------------------ */
/* Component-specific touch-ups                                      */
/* ------------------------------------------------------------------ */

/* Header/nav sticky bar and mobile drawer use bg-white/95 (covered above)
   plus a light border — keep that legible on dark surfaces. */
html.dark header {
  border-color: var(--color-sand-dark);
}

/* Hero radial gradient (home.css) uses low-opacity teal/olive tints that
   read fine on a dark background as-is, no override needed. */

/* Toasts (toast.js) use fixed brand colors (teal/clay/olive-ish) chosen to
   read well on both light and dark surfaces already — no override needed. */

/* ------------------------------------------------------------------ */
/* PDF reader (views/Works/read-book.ejs)                             */
/* ------------------------------------------------------------------ */
/* pdf.js renders each page as pixels onto a <canvas> — that's actual
   rendered image data, not styleable text/backgrounds, so none of the
   CSS-variable or utility-class overrides above can touch it. The
   standard trick apps like ReadEra use for a PDF "night mode" is a CSS
   filter on the rendered page itself: inverting flips a white page to
   dark and black text to light, and hue-rotate(180deg) undoes the odd
   color-swap invert alone would cause on anything not pure black/white
   (a red heading would otherwise come out cyan). It's not a perfect
   re-color of the original PDF — colored images/diagrams will look
   inverted too — but it's the same trade-off every reader app using this
   technique accepts, and it's the only practical option without
   re-rendering the PDF's actual content differently server-side.

   invert(0.92) rather than a full 100% avoids pure black/white, which
   tends to feel harsher and cause more halation on OLED screens than a
   softer off-black/off-white does.

   pdf-reader.js (public/js/pdf-reader.js) recreates the <canvas> element
   inside #pdf-container on every page turn/zoom change — this is a
   descendant selector, so it applies automatically to whichever canvas
   exists at any given moment with no JS changes needed.
*/
html.dark #pdf-container {
  background-color: var(--color-sand);
}

html.dark #pdf-container canvas {
  filter: invert(0.92) hue-rotate(180deg);
}

/* The text layer sits on top of the canvas and holds the PDF's real,
   selectable text. Its glyphs are transparent (the canvas below is what
   you see), so the canvas filter above does not affect them. The selection
   highlight does need inverting though, otherwise a blue selection wash
   over an inverted page reads as a solid orange block. */
html.dark #pdf-container .textLayer ::selection,
html.dark #pdf-container .textLayer span::selection {
  background: rgba(147, 197, 253, 0.3);
}