/* Night-mode corrections. Loaded last so it wins over the sheets it repairs.
   Light mode is untouched by everything in this file. */

/* ── Bespoke session themes paint light surfaces with !important and have no
      night counterpart: the ink flips but the paper stays pastel (1.0:1).
      Night mode renders those cards on the shared night surfaces instead. ── */
:root[data-theme="dark"] body[class*="theme-"] .vocab-card,
:root[data-theme="dark"] body[class*="theme-"] .round-block,
:root[data-theme="dark"] body[class*="theme-"] .debate-duel-box,
:root[data-theme="dark"] body[class*="theme-"] .sensitive-box,
:root[data-theme="dark"] body[class*="theme-"] .ce-slide-item,
:root[data-theme="dark"] body[class*="theme-"] .science-journal-box,
:root[data-theme="dark"] body[class*="theme-"] .philosophers-ledger {
  background: #232c24 !important;
  border-color: rgba(255, 255, 255, 0.14) !important;
  color: #d6f7f5 !important;
}

:root[data-theme="dark"] body[class*="theme-"] .vocab-card *,
:root[data-theme="dark"] body[class*="theme-"] .round-block *,
:root[data-theme="dark"] body[class*="theme-"] .debate-duel-box *,
:root[data-theme="dark"] body[class*="theme-"] .ce-slide-item * {
  color: #d6f7f5 !important;
  border-color: rgba(255, 255, 255, 0.14) !important;
}

:root[data-theme="dark"] body[class*="theme-"] .vocab-card h4,
:root[data-theme="dark"] body[class*="theme-"] .round-header,
:root[data-theme="dark"] body[class*="theme-"] .round-header * {
  color: #9fd3aa !important;
}

/* Section headings keep the accent but at a night-legible lightness */
:root[data-theme="dark"] body[class*="theme-"] .section-title { color: #b7dcc0 !important; }

/* ── Inks that never got a night value ── */
:root[data-theme="dark"] .error-links a,
body.theme-dark .error-links a { color: #9fd3aa !important; }

:root[data-theme="dark"] .debate-duel-item strong { color: #9fb3a2 !important; }
:root[data-theme="dark"] .debate-duel-item span { color: #dfe9e0 !important; }

/* ── Solid fills carrying white labels ── */
.join-btn,
.whatsapp-btn { background: #0f6b35 !important; color: #ffffff !important; }
/* Plain links keep the WhatsApp affordance; a designed CTA (.ev-btn, .btn)
   keeps its brand fill instead of being repainted by its href. */
a[href*="wa.me"]:not(footer a):not(.ev-btn):not(.btn),
a[href*="whatsapp"]:not(footer a):not(.ev-btn):not(.btn) { background: #0f6b35 !important; color: #ffffff !important; }
.mistake-mod-label,
[class*="mod-badge"] { background: #9a3412 !important; color: #ffffff !important; }

/* Tailwind-ish pastel panels pasted into the copy */
:root[data-theme="dark"] [class*="bg-violet-100"],
:root[data-theme="dark"] [class*="bg-pink-50"],
:root[data-theme="dark"] [class*="bg-orange-50"],
:root[data-theme="dark"] [class*="bg-stone-50"] { background: #232c24 !important; }

/* ── Footers of bespoke themes stay on the light surface ── */
:root[data-theme="dark"] footer,
:root[data-theme="dark"] .footer-inner { background: #1a1f1a !important; color: #c9e9e7; }
:root[data-theme="dark"] .footer-links-col h3,
:root[data-theme="dark"] .fb-name,
:root[data-theme="dark"] .footer-brand .fb-name { color: #d6f7f5 !important; }
:root[data-theme="dark"] .footer-links-col a,
:root[data-theme="dark"] .footer-brand p,
:root[data-theme="dark"] .footer-bottom { color: #a9bcac !important; }

/* ── Slide/overview blocks: pastel panels with flipped ink ── */
:root[data-theme="dark"] .ce-slide-item > div,
:root[data-theme="dark"] .round-header,
:root[data-theme="dark"] .ce-slide-item > div > div,
:root[data-theme="dark"] .parlor-ledger,
:root[data-theme="dark"] .ce-slide-overview-wrapper { background: #232c24 !important; }
:root[data-theme="dark"] .ce-slide-item > div,
:root[data-theme="dark"] .ce-slide-item > div > div,
:root[data-theme="dark"] .parlor-ledger,
:root[data-theme="dark"] .round-header { color: #d6f7f5 !important; border-color: rgba(255,255,255,.14) !important; }

/* ── Wonder voiceover widget is painted from JS with fixed pastels ── */
:root[data-theme="dark"] .wonder-voiceover-player,
:root[data-theme="dark"] .wonder-voiceover-player > div,
:root[data-theme="dark"] .wonder-voiceover-player > div > div { background: #232c24 !important; color: #d6f7f5 !important; }
:root[data-theme="dark"] .speech-mode-badge { background: #3b3550 !important; color: #e9e5ff !important; }
:root[data-theme="dark"] .clapper-meta-label { color: #F0B357 !important; }

/* ── Chips and small inks that keep their light values at night ── */
:root[data-theme="dark"] .vocab-pill,
:root[data-theme="dark"] .vocab-grid span { background: #2c352d !important; color: #dfe9e0 !important; border-color: rgba(255,255,255,.14) !important; }

:root[data-theme="dark"] .btn-trailer,
:root[data-theme="dark"] a.btn-trailer { color: #F0B357 !important; }

:root[data-theme="dark"] .sidebar-promo,
:root[data-theme="dark"] .sidebar-promo * { color: #F08968 !important; }

:root[data-theme="dark"] .error-container .error-code { color: #9fd3aa !important; }
:root[data-theme="dark"] .error-links { color: #9fd3aa !important; }

/* science-light keeps a white page under a dark palette */
:root[data-theme="dark"] body.theme-science-light,
:root[data-theme="dark"] body.theme-science-light main.content-container,
:root[data-theme="dark"] body.theme-science-light .content-container {
  background: #1a1f1a !important; color: #d6f7f5 !important;
}
:root[data-theme="dark"] body.theme-science-light h1,
:root[data-theme="dark"] body.theme-science-light h2,
:root[data-theme="dark"] body.theme-science-light h3,
:root[data-theme="dark"] body.theme-science-light h4,
:root[data-theme="dark"] body.theme-science-light p,
:root[data-theme="dark"] body.theme-science-light li,
:root[data-theme="dark"] body.theme-science-light span:not([class]) { color: #d6f7f5 !important; }

/* Quotes themes use a pastel accent as a button *fill* under white labels
   (2.1:1 in both modes). Keep the pastel for borders, darken the fill. */
body[class*="theme-quotes-"] .btn-primary,
body[class*="theme-quotes-"] #ledger-next-btn,
body[class*="theme-quotes-"] .ledger-next-btn {
  background-color: color-mix(in srgb, var(--quotes-theme-accent, #B45309) 45%, #000000) !important;
  color: #ffffff !important;
}

/* Footer brand text must follow the page ink, never a fixed light value */
.footer-brand .fb-name,
.footer-brand .fb-logo span,
.footer-links-col h3 {
  background: transparent !important;
  color: var(--ink, #28251d) !important;
}

/* Cinema slates are dark surfaces: their link accent must be light */
.cinema-slate-box .btn-trailer,
.cinema-slate-box .theme-video-link a { color: #F0B357 !important; }

/* ── Second wave: surfaces that kept light paper under the night palette ── */
:root[data-theme="dark"] .history-session,
:root[data-theme="dark"] .history-body,
:root[data-theme="dark"] .perspective-mirror-box,
:root[data-theme="dark"] .perspective-mirror-grid > div,
:root[data-theme="dark"] .calc-card,
:root[data-theme="dark"] #quiz-result,
:root[data-theme="dark"] .ev-card,
:root[data-theme="dark"] .event-card,
:root[data-theme="dark"] body[class*="theme-celebrate-"] main.content-container,
:root[data-theme="dark"] body[class*="theme-celebrate-"] .content-container {
  background: #232c24 !important;
  color: #d6f7f5 !important;
  border-color: rgba(255, 255, 255, 0.14) !important;
}
/* Pinned collection headings carry each club's accent as a hex; on night surfaces they vanish. */
:root[data-theme="dark"] .pinned-challenges-section > h3,
html[data-theme="dark"] .pinned-challenges-section > h3,
body.theme-dark .pinned-challenges-section > h3 { color: #d6f7f5 !important; }

:root[data-theme="dark"] .history-session h3,
:root[data-theme="dark"] .history-session h4,
:root[data-theme="dark"] .perspective-mirror-grid h3,
:root[data-theme="dark"] .perspective-mirror-grid h4,
:root[data-theme="dark"] .perspective-mirror-grid strong { color: #d6f7f5 !important; }
:root[data-theme="dark"] body[class*="theme-celebrate-"] h1,
:root[data-theme="dark"] body[class*="theme-celebrate-"] h2,
:root[data-theme="dark"] body[class*="theme-celebrate-"] h3,
:root[data-theme="dark"] body[class*="theme-celebrate-"] p,
:root[data-theme="dark"] body[class*="theme-celebrate-"] li { color: #d6f7f5 !important; }
:root[data-theme="dark"] .ev-card *,
:root[data-theme="dark"] .event-card * { color: #dfe9e0 !important; }

/* Quiz "correct" chip used the WhatsApp green under white text (1.98:1) */
#quiz-result,
.quiz-result,
.calc-card .correct { background: #0f6b35 !important; color: #ffffff !important; }
#quiz-result * { color: #ffffff !important; }
:root[data-theme="dark"] .ev-card,
:root[data-theme="dark"] .ev-card h3,
:root[data-theme="dark"] .ev-card h4,
:root[data-theme="dark"] .ev-card p { color: #dfe9e0 !important; }

/* Active filter pills keep their light-mode brown ink on a dark chip */
:root[data-theme="dark"] .sd-pill.sd-active,
:root[data-theme="dark"] .sd-pill[aria-pressed="true"],
:root[data-theme="dark"] .sd-pill.is-active { background: #4a3a20 !important; color: #F6C177 !important; }

/* Buttons that fill with --indigo need white ink, not a tinted one */
a.view-btn[style*="--indigo"],
a.view-btn[style*="--indigo"] * { color: #ffffff !important; }

/* Onboarding guide cards were hard-coded white */
:root[data-theme="dark"] #onboarding-guide div,
:root[data-theme="dark"] #onboarding-guide p,
:root[data-theme="dark"] #onboarding-guide strong {
  background-color: transparent !important;
  color: #dfe9e0 !important;
}
:root[data-theme="dark"] #onboarding-guide > div > div,
:root[data-theme="dark"] #onboarding-guide .onboarding-card {
  background: #232c24 !important;
  border-color: rgba(255,255,255,0.14) !important;
}

/* Footer links / ecosystem note keep light-mode accents on the night footer */
:root[data-theme="dark"] footer a,
:root[data-theme="dark"] footer p,
:root[data-theme="dark"] .cosy-gated-ecosystem-note a { color: #A9CFB3 !important; }
:root[data-theme="dark"] .cosy-gated-ecosystem-note a { color: #F08968 !important; }

/* Mind-deck CTA paints the theme accent under white text (2.6:1) */
:root[data-theme="dark"] body[class*="theme-mind"] #ledger-next-btn,
:root[data-theme="dark"] body[class*="theme-mind"] .philosophers-ledger .btn-primary {
  background: color-mix(in srgb, var(--mind-theme-accent, #5D4037) 55%, #000000) !important;
  color: #ffffff !important;
}

/* Wonder pages are dark by design: the perspective panel must not stay cream */
body[class*="theme-wonder-"] .cosy-perspective-panel,
body[class*="theme-wonder-"] .panel-perspective-mirror,
body[class*="theme-wonder-"] .wonder-column-item {
  background: #221a2d !important;
  color: #e8e4ef !important;
  border-color: #3a3245 !important;
}
body[class*="theme-wonder-"] .cosy-perspective-panel *,
body[class*="theme-wonder-"] .wonder-column-item * { color: #e8e4ef !important; }

/* Product identity: the card corner and lift come from the canonical product
   layer (vendored in shared/vendor/cosylanguages), not restated here. */
[data-product] .explore-card,
[data-product] .event-card {
  border-radius: var(--cosy-product-radius);
  box-shadow: var(--cosy-product-shadow);
}

/* Inline-styled club chips keep a light mint fill while dark mode re-inks the
   text light, so the label vanishes. Match the inline fills and darken them. */
html[data-theme="dark"] .club-tag[style*="E1F5EE" i],
body.theme-dark .club-tag[style*="E1F5EE" i],
html[data-theme="dark"] .club-tag[style*="EFFCFB" i],
body.theme-dark .club-tag[style*="EFFCFB" i] {
  background: rgba(111, 209, 180, 0.16) !important;
  border-color: rgba(111, 209, 180, 0.28) !important;
}

/* .cta-section paints an ink panel; --ink flips to a light ink in dark mode, so
   the panel became near-white with white text. Keep the panel a dark fill. */
html[data-theme="dark"] .cta-section,
body.theme-dark .cta-section {
  background: #0A3B3D;
}

/* ── Inline light card fills ───────────────────────────────────────────────
   1,544 pages declare `background:#FFFDF9` inline, and another 300 use a short
   `#fff`. A token cannot reach those, so the dark theme left a cream card under
   ink that had flipped to a light tint: 1.14:1 on the wonder vocabulary lists.
   Matching the six-digit creams by value (they cannot prefix-match another
   colour) and the short whites only at a declaration boundary keeps a peach
   chip such as `#fff0e0` out of the sweep. */
html[data-theme="dark"] :is(
  [style*="background:#FFFDF9" i], [style*="background: #FFFDF9" i],
  [style*="background:#FFFDF5" i], [style*="background: #FFFDF5" i],
  [style$="background:#fff" i], [style*="background:#fff;" i],
  [style$="background:#ffffff" i], [style*="background:#ffffff;" i],
  [style$="background:white" i], [style*="background:white;" i],
  [style$="background: white" i], [style*="background: white;" i]
) {
  background-color: var(--cosy-color-surface) !important;
}

/* ── Inline inks inside cards that are dark in both themes ────────────────
   These cards (club history rows, film slates, wonder panels, ledgers) hold
   inline colours picked for a white card. The card never turns light, so in
   dark mode the ink has to be re-pointed per container rather than globally:
   the same hex is correct on a white card elsewhere on the site. */
html[data-theme="dark"] .history-session [style*="color: #1A7A4A" i],
html[data-theme="dark"] .history-session [style*="color:#1A7A4A" i],
html[data-theme="dark"] .life-balance-card [style*="color: #1A7A4A" i],
html[data-theme="dark"] .life-balance-card [style*="color:#1A7A4A" i],
body.theme-dark .history-session [style*="color: #1A7A4A" i],
body.theme-dark .life-balance-card [style*="color: #1A7A4A" i] {
  color: #6FF0B6 !important; /* 5.1:1 on the mint chip over a dark card */
}

/* .club-tag chips in those rows keep their mint fill inline, which the rule
   above turns dark; the label keeps the level colour but lightened. */
html[data-theme="dark"] .history-session .club-tag[style*="color" i],
body.theme-dark .history-session .club-tag[style*="color" i] {
  border-color: currentColor !important;
}

html[data-theme="dark"] .history-session [style*="color: #C0392B" i],
html[data-theme="dark"] .history-session [style*="color:#C0392B" i],
html[data-theme="dark"] .life-balance-card [style*="color: #C0392B" i],
html[data-theme="dark"] .life-balance-card [style*="color:#C0392B" i],
body.theme-dark .history-session [style*="color: #C0392B" i],
body.theme-dark .life-balance-card [style*="color: #C0392B" i] {
  color: #E9A39C !important;
}

html[data-theme="dark"] .history-session [style*="color: #7A1C1C" i],
html[data-theme="dark"] .history-session [style*="color:#7A1C1C" i],
html[data-theme="dark"] .quotes-card [style*="color: #7A1C1C" i],
html[data-theme="dark"] .quotes-card [style*="color:#7A1C1C" i],
html[data-theme="dark"] .parlor-ledger [style*="color: #7A1C1C" i],
html[data-theme="dark"] .parlor-ledger [style*="color:#7A1C1C" i],
body.theme-dark .history-session [style*="color: #7A1C1C" i],
body.theme-dark .quotes-card [style*="color: #7A1C1C" i],
body.theme-dark .parlor-ledger [style*="color: #7A1C1C" i] {
  color: #E9A1A1 !important;
}

html[data-theme="dark"] .history-session [style*="color: #3F2B96" i],
html[data-theme="dark"] .history-session [style*="color:#3F2B96" i],
html[data-theme="dark"] .wonder-about-card [style*="color: #3F2B96" i],
html[data-theme="dark"] .wonder-about-card [style*="color:#3F2B96" i],
html[data-theme="dark"] .wonder-about-card [style*="color: #1F104D" i],
html[data-theme="dark"] .wonder-about-card [style*="color:#1F104D" i],
body.theme-dark .history-session [style*="color: #3F2B96" i],
body.theme-dark .wonder-about-card [style*="color: #3F2B96" i],
body.theme-dark .wonder-about-card [style*="color: #1F104D" i] {
  color: #B9AEE8 !important;
}

/* Wonder decks paint their indigo inline on the cream card, and the deck body
   is the only wrapper: the .wonder-about-card scope above never reaches it. */
html[data-theme="dark"] body[class*="theme-wonder-"] :is(
  [style^="color: #3F2B96"], [style^="color:#3F2B96"],
  [style*="; color: #3F2B96"], [style*=";color: #3F2B96"],
  [style*="; color:#3F2B96"], [style*=";color:#3F2B96"],
  [style^="color: #1F104D"], [style^="color:#1F104D"],
  [style*="; color: #1F104D"], [style*=";color: #1F104D"],
  [style*="; color:#1F104D"], [style*=";color:#1F104D"]
) {
  color: #B9AEE8 !important;
}

html[data-theme="dark"] .periodic-element [style*="color: #0F6E56" i],
html[data-theme="dark"] .periodic-element [style*="color:#0F6E56" i],
body.theme-dark .periodic-element [style*="color: #0F6E56" i],
body.theme-dark .periodic-element [style*="color:#0F6E56" i] {
  color: #1CCDA0 !important;
}

html[data-theme="dark"] .auth-card [style*="color: #3C6344" i],
html[data-theme="dark"] .auth-card [style*="color:#3C6344" i],
html[data-theme="dark"] .daily-spotlight-card [style*="color: #3C6344" i],
html[data-theme="dark"] .daily-spotlight-card [style*="color:#3C6344" i],
html[data-theme="dark"] .daily-spotlights-container [style*="color: #3C6344" i],
html[data-theme="dark"] .daily-spotlights-container [style*="color:#3C6344" i],
body.theme-dark .auth-card [style*="color: #3C6344" i],
body.theme-dark .daily-spotlight-card [style*="color: #3C6344" i],
body.theme-dark .daily-spotlights-container [style*="color: #3C6344" i] {
  color: #94BE9D !important;
}

html[data-theme="dark"] .life-balance-footer [style*="color: #4F46E5" i],
html[data-theme="dark"] .life-balance-card [style*="color: #4F46E5" i],
html[data-theme="dark"] .life-balance-view,
body.theme-dark .life-balance-footer [style*="color: #4F46E5" i],
body.theme-dark .life-balance-card [style*="color: #4F46E5" i],
body.theme-dark .life-balance-view {
  color: #B2AEF4 !important;
}

/* Muted body ink inside the dark history rows (the --muted token stays light-mode
   grey, which is unreadable on #2A322B). */
html[data-theme="dark"] .history-session,
body.theme-dark .history-session {
  --muted: rgba(232, 240, 233, 0.88);
}

/* Adjacent-month calendar dates: readable grey in light mode, too dark here. */
html[data-theme="dark"] .day-cell.other-month .day-number,
body.theme-dark .day-cell.other-month .day-number {
  color: #B6B4B1;
}

/* Studio's teal text and save button sit on dark surfaces in dark mode. */
html[data-theme="dark"] .sidebar-add-card-btn,
html[data-theme="dark"] .center-tab-btn.is-active,
body.theme-dark .sidebar-add-card-btn,
body.theme-dark .center-tab-btn.is-active {
  color: #6FD3D8;
}

/* Remaining links inside the dark club history rows and wonder cards. */
html[data-theme="dark"] .history-session [style*="color: #993556" i],
html[data-theme="dark"] .history-session [style*="color:#993556" i],
html[data-theme="dark"] .history-session [style*="color: #3B6D11" i],
html[data-theme="dark"] .history-session [style*="color:#3B6D11" i],
html[data-theme="dark"] .history-session [style*="color: #A5650F" i],
html[data-theme="dark"] .history-session [style*="color:#A5650F" i],
html[data-theme="dark"] .history-session [style*="color: #087A80" i],
html[data-theme="dark"] .history-session [style*="color:#087A80" i],
body.theme-dark .history-session [style*="color: #993556" i],
body.theme-dark .history-session [style*="color: #3B6D11" i],
body.theme-dark .history-session [style*="color: #A5650F" i],
body.theme-dark .history-session [style*="color: #087A80" i] {
  color: #E8F5F6 !important;
}

/* These inks come from CSS, not inline, so the containers are targeted. */
html[data-theme="dark"] .wonder-card-draft-tag,
body.theme-dark .wonder-card-draft-tag { color: #0CB3BC; }

html[data-theme="dark"] .elem-symbol,
body.theme-dark .elem-symbol { color: #19B990; }

html[data-theme="dark"] .explore-card-cta,
html[data-theme="dark"] .daily-spotlights-tag,
html[data-theme="dark"] .daily-spotlight-card span,
html[data-theme="dark"] .auth-btn-secondary,
html[data-theme="dark"] .auth-back-link,
body.theme-dark .explore-card-cta,
body.theme-dark .daily-spotlights-tag,
body.theme-dark .daily-spotlight-card span,
body.theme-dark .auth-btn-secondary,
body.theme-dark .auth-back-link { color: #7AAE84; }

html[data-theme="dark"] .parlor-ledger span,
body.theme-dark .parlor-ledger span { color: #E48A8A; }

/* Home footer link ink is a sage chosen for the light page. */
html[data-theme="dark"] .past-events-footer-link a,
body.theme-dark .past-events-footer-link a { color: #7AAE84; }

/* Celebration cards carry a gold link that also sits on the dark row. */
html[data-theme="dark"] .celebrate-card-view,
body.theme-dark .celebrate-card-view { color: #E88E15; }

/* The localized homepages put the card CTA in a footer span, not the anchor. */
html[data-theme="dark"] .explore-card-footer span,
body.theme-dark .explore-card-footer span { color: #7AAE84; }

/* session-directory.js writes these two chips with an inline palette, so their
   ink never followed the dark surface underneath: 2.1:1 and 2.2:1. */
html[data-theme="dark"] .sd-badge-theme,
body.theme-dark .sd-badge-theme {
  color: #6FE3D6 !important;
}

html[data-theme="dark"] .sd-pill-wishlist,
body.theme-dark .sd-pill-wishlist {
  color: #F0B860 !important;
}
