/* ==========================================================================
   Light / dark theme.

   Loaded LAST on every layout (main, event, admin), after the page stylesheets, so the dark
   overrides here win without having to touch the files they correct.

   How the mode is chosen:
    · A tiny inline script in the <head> sets <html data-theme="light|dark"> before first
      paint: the visitor's own pick from the header toggle (localStorage "theme") if they have
      made one, otherwise their device setting. assets/js/theme.js runs the toggle buttons and
      follows the device setting live until the visitor picks for themselves.
    · Without JavaScript there is no data-theme at all, and the media-query block below
      applies the dark palette from the device setting alone, so nobody is left on a white
      page their phone asked to be dark.

   Most of the site paints from the tokens in tokens.css, so the bulk of the work is the
   palette swap. Everything after it corrects a literal colour that was only ever tuned for a
   light page: a pastel wash, a frosted-white panel, white text on --ink. The brand colours
   themselves (--focus / --reset / --flow, the wordmark letters) are the same in both modes,
   so a pouch is the same purple at night as it is in the day.
   ========================================================================== */

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

/* ---- The dark palette (written twice: once for the toggle, once for no-JS) ---- */

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

  --bg:         #16120E;
  --bg-soft:    #1D1813;
  --surface:    #251F19;
  --ink:        #F3ECE2;
  --ink-soft:   #C8BDAD;
  --ink-faint:  #8F8472;
  --line:       #3D342A;

  --focus-tint: #2C2442;
  --focus-deep: #C9B8F2;
  --reset-tint: #1B2D22;
  --reset-deep: #92D6AC;
  --flow-tint:  #30270F;
  --flow-deep:  #F2CB66;

  --danger:     #FF8A7A;
  --success:    #92D6AC;
  --notice-bg:  #30270F;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.45);
  --shadow:    0 6px 20px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 16px 44px rgba(0, 0, 0, 0.55);

  /* The brand gradients wash towards white in light mode (components.css); here they wash
     towards the dark surface, or every gradient pill and hover would glow as a pastel slab. */
  --grad-brand-soft: linear-gradient(100deg in oklab,
    color-mix(in srgb, var(--flow)   22%, var(--surface)) 0%,
    color-mix(in srgb, var(--focus)  24%, var(--surface)) 50%,
    color-mix(in srgb, var(--reset)  22%, var(--surface)) 100%);
  --grad-brand-fallback: color-mix(in srgb, var(--focus) 20%, var(--surface));
  --grad-brand-border: linear-gradient(100deg in oklab,
    color-mix(in srgb, var(--flow)   70%, var(--surface)) 0%,
    color-mix(in srgb, var(--focus)  70%, var(--surface)) 50%,
    color-mix(in srgb, var(--reset)  70%, var(--surface)) 100%);

  /* Theme-only helpers used by the corrections below. */
  --notice-ink:  #F2CB66;
  --hairline:    rgba(255, 255, 255, 0.10);
  --pastel-wash: linear-gradient(160deg, #241D33 0%, #1A2820 52%, #2B2413 100%);
  --glass:       rgba(37, 31, 25, 0.72);
  --glass-edge:  rgba(255, 255, 255, 0.12);
  --on-ink:      #16120E;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg: #16120E; --bg-soft: #1D1813; --surface: #251F19;
    --ink: #F3ECE2; --ink-soft: #C8BDAD; --ink-faint: #8F8472; --line: #3D342A;
    --focus-tint: #2C2442; --focus-deep: #C9B8F2;
    --reset-tint: #1B2D22; --reset-deep: #92D6AC;
    --flow-tint: #30270F;  --flow-deep: #F2CB66;
    --danger: #FF8A7A; --success: #92D6AC; --notice-bg: #30270F;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.45);
    --shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 16px 44px rgba(0, 0, 0, 0.55);
    --grad-brand-soft: linear-gradient(100deg,
      color-mix(in srgb, var(--flow) 22%, var(--surface)) 0%,
      color-mix(in srgb, var(--focus) 24%, var(--surface)) 50%,
      color-mix(in srgb, var(--reset) 22%, var(--surface)) 100%);
    --grad-brand-fallback: color-mix(in srgb, var(--focus) 20%, var(--surface));
    --grad-brand-border: linear-gradient(100deg,
      color-mix(in srgb, var(--flow) 70%, var(--surface)) 0%,
      color-mix(in srgb, var(--focus) 70%, var(--surface)) 50%,
      color-mix(in srgb, var(--reset) 70%, var(--surface)) 100%);
  }
}

/* ---- Literal-colour corrections (dark only) ---------------------------------------- */

/* Base */
[data-theme="dark"] a:hover { color: #FFFFFF; }
[data-theme="dark"] .skip-link,
[data-theme="dark"] .icon-tip { color: var(--on-ink); }

/* Notices and flashes */
[data-theme="dark"] .badge-notice,
[data-theme="dark"] .placeholder-flag,
[data-theme="dark"] .survey-admin-warn { color: var(--notice-ink); }
[data-theme="dark"] .flash-error { background: #3A1E19; }

/* Announcement marquee: the same tri-hue band, sunk into the dark instead of lifted to white. */
[data-theme="dark"] .announce {
  background: linear-gradient(100deg,
    color-mix(in srgb, var(--flow)  34%, var(--bg)) 0%,
    color-mix(in srgb, var(--focus) 34%, var(--bg)) 50%,
    color-mix(in srgb, var(--reset) 34%, var(--bg)) 100%);
}

/* Footer: the light build sets a fixed sand colour; here it is one step off the page. */
[data-theme="dark"] .site-footer { background: var(--bg-soft); border-top: 1px solid var(--line); }
[data-theme="dark"] .footer-band,
[data-theme="dark"] .footer-disclaimer,
[data-theme="dark"] .footer-legal { border-top-color: var(--hairline); }
[data-theme="dark"] .footer-capture .input { background: var(--surface); border-color: var(--line); }

/* Pastel bands on the home page — the same three-hue wash, deepened. */
[data-theme="dark"] .starter-band,
[data-theme="dark"] .quiz-cta,
[data-theme="dark"] .jiggle-section { background: var(--pastel-wash); }
[data-theme="dark"] .rituals-band .k-dot { color: #8F7A45; }

/* Frosted-glass panels (the waitlist veil on the home page and the PDP). White glass under
   light ink would be unreadable, so the glass goes smoked instead. */
[data-theme="dark"] .claim-veil-panel,
[data-theme="dark"] .pdp-veil-panel { background: var(--glass); border-color: var(--glass-edge); }
[data-theme="dark"] .claim-veil-panel::after {
  background: linear-gradient(148deg, rgb(255 255 255 / 0.08) 0%, rgb(255 255 255 / 0) 46%);
}

/* Bundle band (shop + bundles): the same mesh of the three ritual hues plus pink, mixed into
   the dark page instead of into white, with light ink on it. Its plum --bundle-ink is derived
   from --focus-deep, which is light in this mode, so it is reset to the page ink here. */
[data-theme="dark"] .bundle-band {
  --bundle-ink: var(--ink);
  color: var(--ink);
  background-color: color-mix(in srgb, var(--focus) 30%, var(--bg));
  background-image:
    radial-gradient(90% 120% at 4% 88%,  color-mix(in srgb, var(--reset) 34%, var(--bg)) 0%, transparent 62%),
    radial-gradient(80% 115% at 96% 10%, color-mix(in srgb, var(--flow) 30%, var(--bg)) 0%, transparent 60%),
    radial-gradient(70% 100% at 68% 96%, color-mix(in srgb, var(--neon-pink) 26%, var(--bg)) 0%, transparent 64%),
    linear-gradient(104deg,
      color-mix(in srgb, var(--reset)     30%, var(--bg)) 0%,
      color-mix(in srgb, var(--focus)     30%, var(--bg)) 42%,
      color-mix(in srgb, var(--neon-pink) 24%, var(--bg)) 72%,
      color-mix(in srgb, var(--flow)      28%, var(--bg)) 100%);
}
[data-theme="dark"] .bundle-band .trust-row .tick { background: rgba(22, 18, 14, 0.72); }

/* Admin */
[data-theme="dark"] .chip.is-active { color: var(--on-ink); }

/* Wavy section edges. In light mode they are SVGs painted in the cream page colour; here the
   same wave shapes are used as a mask over a block of the dark page colour, so the edge always
   matches whatever --bg is rather than a colour baked into an image. */
[data-theme="dark"] .wave-band::before,
[data-theme="dark"] .wave-band::after {
  background: var(--bg);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1200 46' preserveAspectRatio='none'%3E%3Cpath d='M0,0 H1200 V22 C1010,42 900,8 700,24 C505,40 335,8 150,25 C95,30 46,29 0,22 Z' fill='%23FAF7F2'/%3E%3C/svg%3E") no-repeat center / 100% 101%;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1200 46' preserveAspectRatio='none'%3E%3Cpath d='M0,0 H1200 V22 C1010,42 900,8 700,24 C505,40 335,8 150,25 C95,30 46,29 0,22 Z' fill='%23FAF7F2'/%3E%3C/svg%3E") no-repeat center / 100% 101%;
}
[data-theme="dark"] .jiggle-section::before,
[data-theme="dark"] .jiggle-section::after {
  background: var(--bg);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1200 52' preserveAspectRatio='none'%3E%3Cpath d='M0,0 H1200 V24 C1010,50 905,6 700,28 C500,49 335,6 150,29 C92,35 44,33 0,25 Z' fill='%23FAF7F2'/%3E%3C/svg%3E") no-repeat center / 100% 101%;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1200 52' preserveAspectRatio='none'%3E%3Cpath d='M0,0 H1200 V24 C1010,50 905,6 700,28 C500,49 335,6 150,29 C92,35 44,33 0,25 Z' fill='%23FAF7F2'/%3E%3C/svg%3E") no-repeat center / 100% 101%;
}

/* Reviews-page select chevron: drawn in the deep purple, which vanishes on dark. */
[data-theme="dark"] .review-form-col .select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23C9B8F2' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
}

/* ---- The toggle itself ---------------------------------------------------------------- */

/* Sun in dark mode (tap for light), moon in light mode (tap for dark): the icon shows where
   you are going, the way most sites and phones do it. Both icons are in the markup so the
   right one shows on first paint, before any script has run. */
.theme-toggle .icon-sun  { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun  { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .theme-toggle .icon-sun  { display: block; }
  :root:not([data-theme]) .theme-toggle .icon-moon { display: none; }
}

/* On the stripped event pages and in the admin there is no header, so the toggle sits on its
   own in the top-right corner of the window. */
.theme-toggle-corner {
  position: fixed; top: 12px; right: 12px; z-index: 300;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-sm);
}
.theme-toggle-corner:hover { background: var(--bg-soft); }
