/* Daybreak Sobriety Tracker: the Theme color on every page.
 *
 * The Theme pop-up on the home page sets data-color on <html> (Teal, the default, has
 * no attribute and is defined by each page's own styles, unchanged). A small script at
 * the top of each page puts it on before the page is drawn, so the color never flashes,
 * and js/auth.js keeps it in step with the account.
 *
 * How it works:
 *   1. Each color defines eight roles (--t-bg, --t-surface, --t-line, --t-ink,
 *      --t-ink-soft, --t-accent, --t-accent-2, --t-tint) plus --t-on-accent, once for
 *      light and once for dark. Light mode keeps a white page and the page's own ink.
 *   2. One shared block maps those roles onto the names each page already uses
 *      (--teal, --blue-deep, --bg-soft, --card-top, --nf-accent, ...), so every page,
 *      pop-up, button, chip and the confetti re-tint together and no teal is left over.
 * `html[data-color]` outranks the pages' own `:root` rules, so load order doesn't matter.
 */

/* ======================================================================
   1. The colors
   ====================================================================== */

/* ---------- Light: white page, the page's own ink, tinted accents ---------- */
html[data-color="dusk"] {
  --t-surface: #f6f4fc; --t-line: #e2ddf3; --t-tint: #ebe6fa;
  --t-accent: #6a52d6; --t-accent-2: #9a4fb8;
}
html[data-color="sage"] {
  --t-surface: #f2f8f4; --t-line: #d8e8de; --t-tint: #e3f1e8;
  --t-accent: #2b7a4b; --t-accent-2: #587519;
}
html[data-color="sunrise"] {
  --t-surface: #fdf6f0; --t-line: #f0dccd; --t-tint: #fbe9d9;
  --t-accent: #ad4f0c; --t-accent-2: #b8432f;
}
html[data-color="blush"] {
  --t-surface: #fcf3f6; --t-line: #f1d9e2; --t-tint: #f9e4ec;
  --t-accent: #b8325f; --t-accent-2: #b0532f;
}
html[data-color="graphite"] {
  --t-surface: #f4f5f7; --t-line: #e0e3e7; --t-tint: #e8ebef;
  --t-accent: #3d6483; --t-accent-2: #566574;
}

/* ---------- Dark: the whole page re-tints ---------- */
@media (prefers-color-scheme: dark) {
  html[data-color="dusk"] {
    --t-bg: #15141f; --t-surface: #1e1c2d; --t-line: #34314a;
    --t-ink: #ece9f6; --t-ink-soft: #aaa6c4; --t-accent: #a89cf0; --t-accent-2: #d0a6e6;
  }
  html[data-color="sage"] {
    --t-bg: #0f1b16; --t-surface: #16281f; --t-line: #28443a;
    --t-ink: #e6f1ea; --t-ink-soft: #9fb8aa; --t-accent: #7fcf9a; --t-accent-2: #b6d98a;
  }
  html[data-color="sunrise"] {
    --t-bg: #1d1511; --t-surface: #2a1e18; --t-line: #4a362b;
    --t-ink: #f6ebe3; --t-ink-soft: #c2aa9b; --t-accent: #f0a35e; --t-accent-2: #e8836f;
  }
  html[data-color="blush"] {
    --t-bg: #1c1319; --t-surface: #2a1c25; --t-line: #4a3040;
    --t-ink: #f6e9ef; --t-ink-soft: #c4a5b4; --t-accent: #ee8fb0; --t-accent-2: #f2b5a0;
  }
  html[data-color="graphite"] {
    --t-bg: #14161a; --t-surface: #1d2025; --t-line: #333840;
    --t-ink: #eceef1; --t-ink-soft: #a3a9b3; --t-accent: #9ab8d4; --t-accent-2: #b9c4d0;
  }
}

/* ======================================================================
   2. Roles -> the names each page uses (light first, dark overrides below)
   ====================================================================== */

/* Light defaults. :where() keeps these weaker than each color's own dark values above. */
:where(html[data-color]) {
  --t-bg: #ffffff;
  --t-on-accent: #ffffff;
}

html[data-color] {
  /* Every page */
  --bg: var(--t-bg);
  --line: var(--t-line);
  --teal: var(--t-accent);
  --dialog-bg: var(--t-bg);
  --field-border: color-mix(in srgb, var(--t-accent) 45%, var(--t-bg));
  --shadow: color-mix(in srgb, color-mix(in srgb, var(--t-accent) 30%, #000) 22%, transparent);
  --backdrop: color-mix(in srgb, color-mix(in srgb, var(--t-accent) 30%, #000) 35%, transparent);

  /* Resources, Shop, Account, Log in / Sign up, Privacy, Texting, Unsubscribe */
  --bg-soft: var(--t-surface);
  --bg-teal: var(--t-tint);
  --blue: var(--t-accent);
  --blue-deep: var(--t-accent);
  --urgent-border: var(--t-line);
  --bg-item: var(--t-bg);
  --tag-bg: var(--t-tint);
  --note-bg: var(--t-bg);
  --field: var(--t-bg);
  --btn-bg: var(--t-accent);
  --btn-bg-hover: color-mix(in srgb, var(--t-accent) 85%, #000);
  --btn-ink: var(--t-on-accent);

  /* Home page */
  --teal-deep: var(--t-accent);
  --teal-soft: var(--t-tint);
  --blue-soft: var(--t-tint);
  --field-bg: var(--t-bg);
  --placeholder: color-mix(in srgb, var(--ink-soft) 85%, var(--t-bg));
  --focus-outline: color-mix(in srgb, var(--t-accent) 45%, transparent);
  --focus-ring: color-mix(in srgb, var(--t-accent) 20%, transparent);
  --card-top: var(--t-surface);
  --card-bottom: color-mix(in srgb, var(--t-tint) 65%, var(--t-surface));
  --divider: color-mix(in srgb, var(--t-line) 85%, var(--t-accent));
  --milestone-border: color-mix(in srgb, var(--t-accent-2) 35%, var(--t-line));
  --milestone-top: color-mix(in srgb, var(--t-accent-2) 3%, var(--t-bg));
  --milestone-bottom: color-mix(in srgb, var(--t-accent-2) 10%, var(--t-bg));
  --milestone-eyebrow: var(--t-accent-2);
  --footer-bg: var(--t-surface);
  --on-accent: var(--t-on-accent);
  --btn-top: var(--t-accent);
  --btn-bottom: color-mix(in srgb, var(--t-accent) 92%, #000);
  --btn-hover: color-mix(in srgb, var(--t-accent) 82%, #000);
  --bar1: color-mix(in srgb, var(--t-accent) 70%, #000);
  --bar2: color-mix(in srgb, var(--t-accent) 80%, #000);
  --bar3: color-mix(in srgb, var(--t-accent) 90%, #000);
  --bar4: var(--t-accent);
  --bar-text: var(--t-on-accent);
  /* Milestone sun icon and confetti: accent and accent-2 */
  --sun-ray: var(--t-accent-2);
  --sun: color-mix(in srgb, var(--t-accent-2) 70%, var(--t-bg));
  --sun-base: var(--t-accent);
  --confetti-1: var(--t-accent);
  --confetti-2: var(--t-accent-2);
  --confetti-3: color-mix(in srgb, var(--t-accent) 55%, #fff);
  --confetti-4: color-mix(in srgb, var(--t-accent-2) 55%, #fff);
  --confetti-5: color-mix(in srgb, var(--t-accent) 50%, var(--t-accent-2));
  --confetti-6: color-mix(in srgb, var(--t-accent-2) 35%, #fff);
}

/* Notifications pop-up (css/notifications.css) */
html[data-color] .nf-dialog {
  --nf-bg: var(--t-bg);
  --nf-line: var(--t-line);
  --nf-tint: var(--t-tint);
  --nf-accent: var(--t-accent);
  --nf-accent-hover: color-mix(in srgb, var(--t-accent) 85%, #000);
  --nf-on-accent: var(--t-on-accent);
  --nf-focus: var(--t-accent);
  --nf-shadow: var(--shadow);
  --nf-backdrop: var(--backdrop);
}

/* Invite someone button and pop-up (css/invite.css) */
html[data-color] :is(.iv-dialog, .iv-cta) {
  --iv-bg: var(--t-bg);
  --iv-line: var(--t-line);
  --iv-tint: var(--t-tint);
  --iv-field: var(--t-surface);
  --iv-accent: var(--t-accent);
  --iv-accent-hover: color-mix(in srgb, var(--t-accent) 85%, #000);
  --iv-on-accent: var(--t-on-accent);
  --iv-focus: var(--t-accent);
  --iv-shadow: var(--shadow);
  --iv-backdrop: var(--backdrop);
}

/* ---------- Dark (follows the device setting, like the rest of the site) ---------- */
@media (prefers-color-scheme: dark) {
  html[data-color] {
    --t-tint: color-mix(in srgb, var(--t-accent) 16%, var(--t-surface));
    --t-on-accent: var(--t-bg);

    --ink: var(--t-ink);
    --ink-soft: var(--t-ink-soft);
    --dialog-bg: var(--t-surface);
    --field-border: color-mix(in srgb, var(--t-line) 55%, var(--t-ink-soft));
    --shadow: rgba(0, 0, 0, .55);
    --backdrop: color-mix(in srgb, color-mix(in srgb, var(--t-bg) 70%, #000) 65%, transparent);

    --bg-item: color-mix(in srgb, var(--t-surface) 75%, var(--t-line));
    --note-bg: color-mix(in srgb, var(--t-surface) 60%, var(--t-bg));
    --field: color-mix(in srgb, var(--t-surface) 55%, var(--t-bg));
    --btn-bg-hover: color-mix(in srgb, var(--t-accent) 75%, #fff);

    --field-bg: color-mix(in srgb, var(--t-surface) 55%, var(--t-bg));
    --focus-outline: color-mix(in srgb, var(--t-accent) 65%, transparent);
    --focus-ring: color-mix(in srgb, var(--t-accent) 30%, transparent);
    --card-bottom: color-mix(in srgb, var(--t-surface) 70%, var(--t-bg));
    --milestone-top: var(--t-surface);
    --milestone-bottom: color-mix(in srgb, var(--t-accent-2) 10%, var(--t-surface));
    --footer-bg: color-mix(in srgb, var(--t-surface) 55%, var(--t-bg));
    --btn-top: color-mix(in srgb, var(--t-accent) 85%, #fff);
    --btn-bottom: var(--t-accent);
    --btn-hover: color-mix(in srgb, var(--t-accent) 70%, #fff);
    --bar1: color-mix(in srgb, var(--t-accent) 55%, var(--t-ink));
    --bar2: color-mix(in srgb, var(--t-accent) 70%, var(--t-ink));
    --bar3: color-mix(in srgb, var(--t-accent) 85%, var(--t-ink));
    --sun: color-mix(in srgb, var(--t-accent-2) 80%, var(--t-ink));
    --confetti-3: color-mix(in srgb, var(--t-accent) 60%, var(--t-ink));
    --confetti-4: color-mix(in srgb, var(--t-accent-2) 60%, var(--t-ink));
    --confetti-6: color-mix(in srgb, var(--t-accent-2) 45%, var(--t-ink));
  }

  html[data-color] .nf-dialog {
    --nf-bg: var(--t-surface);
    --nf-ink: var(--t-ink);
    --nf-soft: var(--t-ink-soft);
    --nf-accent-hover: color-mix(in srgb, var(--t-accent) 75%, #fff);
  }

  html[data-color] :is(.iv-dialog, .iv-cta) {
    --iv-bg: var(--t-surface);
    --iv-ink: var(--t-ink);
    --iv-soft: var(--t-ink-soft);
    --iv-field: color-mix(in srgb, var(--t-surface) 55%, var(--t-bg));
    --iv-accent-hover: color-mix(in srgb, var(--t-accent) 75%, #fff);
  }
}
