/* ==========================================================================
   BRAND TOKENS — the only file you need to touch to change the look.
   --------------------------------------------------------------------------
   Every colour and typeface resolves through this file. Nothing in site.css
   hard-codes a colour.

   GTX colours:
       #89a540  green  accents and rules
       #636362  grey   secondary text
       #016bb7  blue   links and buttons

   Contrast is checked against WCAG 2.1 — read the note on each interactive
   colour before changing it.
   ========================================================================== */

:root {
  /* --- Core brand ------------------------------------------------------- */
  --brand-primary:      #016bb7;  /* GTX blue. 5.5:1 on white — AA          */
  --brand-primary-dark: #015a99;  /* hover / pressed. 7.2:1 on white         */
  --brand-deep:         #3b3b3a;  /* footer: GTX grey darkened. 11.2:1 w/ white */
  --brand-metal:        #89a540;  /* GTX green — accents and rules           */

  /* GTX green is 2.8:1 on white: fine for rules and borders, but it fails AA
     for text. Use --brand-accent-text where green has to carry text. */
  --brand-accent:      #89a540;
  --brand-accent-text: #566a24;   /* 6.0:1 on white — AA */

  /* --- Neutrals --------------------------------------------------------- */
  --ink:       #1a1a19;   /* 17.4:1 on white */
  --ink-soft:  #636362;   /* GTX grey. 6.0:1 on white — AA */
  --paper:     #ffffff;
  --paper-alt: #f2f4ee;
  --line:      #d9ddd2;

  /* --- Reversed (on --brand-deep) --------------------------------------- */
  --rev-text:  rgb(255 255 255 / .84);
  --rev-muted: rgb(255 255 255 / .60);
  --rev-line:  rgb(255 255 255 / .18);

  /* --- Feedback --------------------------------------------------------- */
  --ok:    #16653c;
  --error: #b3261e;

  /* --- Typography ------------------------------------------------------- */
  /* The manual's faces, kept from trb-website. */
  --display: "Barlow Condensed", "Arial Narrow", sans-serif;
  --body:    "Barlow", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono:    "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
}


/* ==========================================================================
   DARK MODE
   --------------------------------------------------------------------------
   On when the footer's theme switch says Dark (data-theme="dark" on <html>),
   or when it says System (no data-theme; also the case without JavaScript)
   and the system is dark. Light (data-theme="light") keeps the tokens above.

   CSS can't put an attribute and a media query in one selector, so the
   block is written twice: once under the media query, once for the
   attribute. Keep the two copies the same. light-dark() would hold each
   token once, but it can't carry the opacity and logo rules, and a browser
   without it (Safari before 17.5) would drop every token's colour.

   Component rules are scoped with :where() so they keep the specificity
   they had before the switch.

   GTX blue is too dark to read on a dark page, so it is lightened for links
   and buttons. GTX green is 6.5:1 on the dark page and is kept as it is.
   ========================================================================== */

/* Form controls and scrollbars follow a chosen theme too. */
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"]  { color-scheme: dark; }

/* The header logo: the dark version is hidden until dark mode is on. */
.brand .brand__dark { display: none; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand-primary:      #5aa9e6;  /* lightened GTX blue. 7.1:1 on page — AAA */
    --brand-primary-dark: #8cc4ef;  /* hover: lighter, not darker, on a dark page */
    --brand-deep:         #08111a;  /* footer                                     */
    --brand-metal:        #89a540;  /* GTX green. 6.5:1 on page                   */

    --brand-accent:      #89a540;
    --brand-accent-text: #a3c25a;   /* 9.0:1 on page */

    --ink:       #e8eef3;   /* 15.5:1 on page — AAA */
    --ink-soft:  #a9a9a8;   /* lightened GTX grey. 7.7:1 on page — AAA */
    --paper:     #0e1720;
    --paper-alt: #16222d;
    --line:      #27384a;

    --rev-text:  rgb(255 255 255 / .84);
    --rev-muted: rgb(255 255 255 / .60);
    --rev-line:  rgb(255 255 255 / .16);

    --ok:    #6ee7a8;
    --error: #ff8f88;
  }

  /* Buttons take dark text on the lightened blue, not white. */
  :where(:root:not([data-theme="light"])) .btn { color: var(--brand-deep); }
  :where(:root:not([data-theme="light"])) .btn:hover { color: var(--brand-deep); }
  :where(:root:not([data-theme="light"])) .btn--ghost { color: var(--brand-primary); }
  :where(:root:not([data-theme="light"])) .btn--ghost:hover { color: var(--brand-deep); }
  :where(:root:not([data-theme="light"])) .btn--light { background: var(--brand-primary); border-color: var(--brand-primary); color: var(--brand-deep); }
  :where(:root:not([data-theme="light"])) .btn--light:hover { background: transparent; color: var(--brand-primary); border-color: var(--brand-primary); }

  :where(:root:not([data-theme="light"])) .hero { background-image: linear-gradient(160deg, rgb(8 17 26 / .90), rgb(8 17 26 / .97)); }

  :where(:root:not([data-theme="light"])) [aria-invalid="true"] { background: #2a1a1c; }

  :where(:root:not([data-theme="light"])) img { opacity: .92; }          /* take the glare off photographs */
  :where(:root:not([data-theme="light"])) :is(.brand img, .footer__mark img, .social svg) { opacity: 1; }

  /* The header logo's dark version. */
  :where(:root:not([data-theme="light"])) .brand .brand__light { display: none; }
  :where(:root:not([data-theme="light"])) .brand .brand__dark { display: block; }
}

:root[data-theme="dark"] {
  --brand-primary:      #5aa9e6;  /* lightened GTX blue. 7.1:1 on page — AAA */
  --brand-primary-dark: #8cc4ef;  /* hover: lighter, not darker, on a dark page */
  --brand-deep:         #08111a;  /* footer                                     */
  --brand-metal:        #89a540;  /* GTX green. 6.5:1 on page                   */

  --brand-accent:      #89a540;
  --brand-accent-text: #a3c25a;   /* 9.0:1 on page */

  --ink:       #e8eef3;   /* 15.5:1 on page — AAA */
  --ink-soft:  #a9a9a8;   /* lightened GTX grey. 7.7:1 on page — AAA */
  --paper:     #0e1720;
  --paper-alt: #16222d;
  --line:      #27384a;

  --rev-text:  rgb(255 255 255 / .84);
  --rev-muted: rgb(255 255 255 / .60);
  --rev-line:  rgb(255 255 255 / .16);

  --ok:    #6ee7a8;
  --error: #ff8f88;
}

/* Buttons take dark text on the lightened blue, not white. */
:where(:root[data-theme="dark"]) .btn { color: var(--brand-deep); }
:where(:root[data-theme="dark"]) .btn:hover { color: var(--brand-deep); }
:where(:root[data-theme="dark"]) .btn--ghost { color: var(--brand-primary); }
:where(:root[data-theme="dark"]) .btn--ghost:hover { color: var(--brand-deep); }
:where(:root[data-theme="dark"]) .btn--light { background: var(--brand-primary); border-color: var(--brand-primary); color: var(--brand-deep); }
:where(:root[data-theme="dark"]) .btn--light:hover { background: transparent; color: var(--brand-primary); border-color: var(--brand-primary); }

:where(:root[data-theme="dark"]) .hero { background-image: linear-gradient(160deg, rgb(8 17 26 / .90), rgb(8 17 26 / .97)); }

:where(:root[data-theme="dark"]) [aria-invalid="true"] { background: #2a1a1c; }

:where(:root[data-theme="dark"]) img { opacity: .92; }          /* take the glare off photographs */
:where(:root[data-theme="dark"]) :is(.brand img, .footer__mark img, .social svg) { opacity: 1; }

/* The header logo's dark version. */
:where(:root[data-theme="dark"]) .brand .brand__light { display: none; }
:where(:root[data-theme="dark"]) .brand .brand__dark { display: block; }

@media (prefers-color-scheme: dark) and (prefers-contrast: more) {
  :root:not([data-theme="light"]) { --ink: #ffffff; --ink-soft: #c4d3df; --line: #3d5568; }
}
@media (prefers-contrast: more) {
  :root[data-theme="dark"] { --ink: #ffffff; --ink-soft: #c4d3df; --line: #3d5568; }
}
