/* Global dark and light theme (Phase 3).

   One state on the root element, set before first paint by the inline
   script in partials/head.html:  <html data-theme="dark|light">
   Saved in localStorage under "joyjeet-theme"; otherwise the operating
   system preference; otherwise dark.

   Every colour on the site resolves to the semantic tokens below. The
   mirrored Lioré variables, the Dario and Allex section variables and the
   inner-page surfaces (pages.css) are all mapped onto them, so no component
   carries theme specific hex values.

   Surface roles (each keeps the dark / light rhythm in both themes):
     base     .surface, body, footer, page heroes      bg-secondary
     base     .hero, .section, In Numbers, .surface--black, Dario   bg-primary
     inverse  .surface--light                          surface-inverse
     muted    figure fills, card surfaces              surface-secondary / primary */

:root,
:root[data-theme="dark"] {
  color-scheme: dark;

  --bg-primary: #000;
  --bg-secondary: #121212;
  --bg-muted: #1a1a1a;

  --text-primary: #f5f4f0;
  --text-secondary: rgba(245, 244, 240, 0.72);
  --text-muted: rgba(245, 244, 240, 0.6);

  --surface-primary: #292929;
  --surface-secondary: #1c1c1c;
  --surface-inverse: #f5f4f0;
  --surface-inverse-fill: #e4e3de;
  --text-inverse: #121212;
  --text-inverse-secondary: rgba(18, 18, 18, 0.66);

  --border-primary: rgba(245, 244, 240, 0.2);
  --border-subtle: rgba(245, 244, 240, 0.1);
  --border-inverse: rgba(18, 18, 18, 0.16);

  --control-bg: #f5f4f0;
  --control-text: #0a0a0a;

  --haze-tint: rgba(0, 0, 0, 0.08);
  --menu-veil: rgba(17, 17, 17, 0.85);
  --cursor-bracket: #f5f4f0;
  --cursor-line: #9a9a9a;
  --ink-reveal-from: 125, 125, 125;
  --ink-reveal-to: 245, 244, 240;

  /* Header controls sit over whatever scrolls beneath them; these two are
     contrast colours, not theme colours (see data-contrast in site.js). */
  --on-dark: #f5f4f0;
  --on-light: #121212;
}

:root[data-theme="light"] {
  color-scheme: light;

  --bg-primary: #f5f4f0;
  --bg-secondary: #ecebe7;
  --bg-muted: #e3e2dd;

  --text-primary: #121212;
  --text-secondary: #4a4a48;
  --text-muted: #62625c;

  --surface-primary: #fbfaf7;
  --surface-secondary: #e3e2dd;
  --surface-inverse: #0a0a0a;
  --surface-inverse-fill: #1c1c1c;
  --text-inverse: #f5f4f0;
  --text-inverse-secondary: rgba(245, 244, 240, 0.7);

  --border-primary: rgba(18, 18, 18, 0.16);
  --border-subtle: rgba(18, 18, 18, 0.08);
  --border-inverse: rgba(245, 244, 240, 0.2);

  --control-bg: #121212;
  --control-text: #f5f4f0;

  --haze-tint: rgba(245, 244, 240, 0.1);
  --menu-veil: rgba(240, 239, 235, 0.9);
  --cursor-bracket: #121212;
  --cursor-line: #8c8c88;
  --ink-reveal-from: 150, 150, 147;
  --ink-reveal-to: 18, 18, 18;
}

/* ---------------------------------------------- mirrored Lioré variables */
/* The template redeclares these on body and .title-1 at each breakpoint
   (Webflow variable modes), so the mapping is set on those too. */
:root,
:root[data-theme="dark"],
:root[data-theme="light"],
:root[data-theme] body,
:root[data-theme] .title-1 {
  --color--second-color: var(--bg-secondary);   /* body and footer background */
  --colors--first-color: var(--bg-primary);      /* hero and .section background */
  --colors--fourth-color: var(--text-primary);   /* body text, hero intro overlays */
  --color--first-color: var(--text-primary);     /* menu links, underline */
  --colors--second-color: var(--text-primary);   /* links */
  --colors--third-color: var(--text-secondary);  /* menu numerals */
  --button--button-color: var(--text-primary);   /* footer link underline */
}

html .section.gray { background-color: var(--bg-primary); }
html .button-line-first { background-color: var(--border-primary); }
html .menu-circle { background-color: var(--menu-veil); }

/* Hero social icons and globe are white glyph images made for the dark hero. */
:root[data-theme="light"] .hero .globe { filter: none; }
:root[data-theme="light"] .hero .social-icon-main .animation-image { filter: invert(1); }
:root[data-theme="light"] .hero .social-circle { background-color: var(--bg-muted); }

/* ---------------------------------------------------- Allex (In Numbers) */
html .allex-sections {
  --white: var(--bg-primary);
  --black: var(--text-primary);
  --black-alt: var(--bg-primary);
  --dark: var(--text-secondary);
  --light: var(--text-secondary);
  background-color: var(--bg-primary);
}

/* ---------------------------------------------------------- Dario blocks */
/* "html" prefix: these must win over the template stylesheets whatever the
   load order, since theme.css now loads first from the identity partial. */
html .dario-sections {
  --_color---black: var(--bg-primary);
  --_color---white: var(--text-primary);
  --_color---bg-section: var(--bg-secondary);
  --_color---dark-gray: var(--surface-primary);
  --_color---gray: var(--text-muted);
  background-color: var(--bg-primary);
}

html .dario-sections .overlay-cta-circle {
  background-image:
    linear-gradient(0deg, var(--_color---black), transparent 20%),
    linear-gradient(180deg, var(--_color---black), transparent 20%),
    radial-gradient(circle farthest-corner at 50% 50%, transparent 62%, var(--_color---black));
}

html .dario-sections .line-reveal { background-image: linear-gradient(180deg, transparent, var(--_color---bg-section) 2%); }
html .dario-sections .career-deck-controls__button { border-color: var(--border-primary); }

/* ---------------------------------------------------------- portrait */
/* The home portrait has two versions: black and white for dark mode and
   the colour photograph for light mode. Only one is displayed, and the
   hidden one is not fetched (both are lazy). */
.portrait--light { display: none; }
:root[data-theme="light"] .portrait--dark { display: none; }
:root[data-theme="light"] .portrait--light { display: block; }


/* ------------------------------------------------------------- footer */
:root[data-theme="light"] .footer-main .footer-smiley { filter: invert(1); }

/* ------------------------------------------------------------ header */
.navigation-wrapper .sub-logo-text,
.navigation-wrapper .theme-toggle {
  color: var(--on-dark);
}

.navigation-wrapper[data-contrast="light"] .sub-logo-text,
.navigation-wrapper[data-contrast="light"] .theme-toggle {
  color: var(--on-light);
}

/* Theme toggle: a 40px control beside the menu icon, secondary to it. It
   shows the action available: the sun while dark (switch to light), the
   moon while light (switch to dark). */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  margin-right: 10px;
  padding: 0;
  background: none;
  border: 0;
  border-radius: 999px;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.theme-toggle svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-toggle .theme-toggle__moon { fill: currentColor; stroke: none; }
.theme-toggle .theme-toggle__moon { display: none; }
:root[data-theme="light"] .theme-toggle .theme-toggle__sun { display: none; }
:root[data-theme="light"] .theme-toggle .theme-toggle__moon { display: block; }

.theme-toggle:hover svg { opacity: 0.75; }
.theme-toggle:focus-visible {
  outline: 1px solid currentColor;
  outline-offset: 2px;
}

/* ------------------------------------------------------- form controls */
.form__input:-webkit-autofill,
.form__input:-webkit-autofill:hover,
.form__input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--ink);
  -webkit-box-shadow: 0 0 0 1000px var(--bg) inset;
  box-shadow: 0 0 0 1000px var(--bg) inset;
  caret-color: var(--ink);
}

.form__input::placeholder { color: var(--ink-muted); }

/* ---------------------------------------------------- theme transition */
/* site.js adds .theme-transition to <html> for 300ms around a switch. */
html.theme-transition,
html.theme-transition *,
html.theme-transition *::before,
html.theme-transition *::after {
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease, fill 0.2s ease, stroke 0.2s ease, filter 0.2s ease !important;
}

@media (prefers-reduced-motion: reduce) {
  html.theme-transition,
  html.theme-transition *,
  html.theme-transition *::before,
  html.theme-transition *::after {
    transition: none !important;
  }
}
