/*
 * Site customisations, loaded after main.css and theme.css so it wins the
 * cascade. One file, two sections:
 *
 *   1. THEME TOKENS -- the only thing that differs between light and dark.
 *      Colours only. Nothing else belongs here.
 *   2. COMMON STYLES -- fonts, sizing and layout fixes. Written once and
 *      shared by both themes, so typography cannot drift between them.
 *
 * If a font ever needs changing, there is exactly one place to change it.
 */


/* =========================================================================
   1. THEME TOKENS (colour only)

   Three states: no data-theme = follow the OS; data-theme="light"/"dark" =
   an explicit user choice, which must win over the OS in both directions.
   ========================================================================= */

:root {
  color-scheme: light;
  --bg:         #ffffff;
  --bg-surface: #ffffff;   /* same tone: surfaces must not read as boxes */
  --bg-sunken:  #ffffff;
  --text:       #212529;
  --text-muted: #6c757d;
  --border:     #e9ecef;
  --link:       #2E7D32;
  --accent:     #2E7D32;
  --on-accent:  #ffffff;
  --accent-rgb: 46 125 50;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg:         #14171a;
    --bg-surface: #14171a;   /* same tone: surfaces must not read as boxes */
    --bg-sunken:  #14171a;
    --text:       #e6e8ea;
    --text-muted: #9aa4ad;
    --border:     #2e353b;
    --link:       #66BB6A;
    --accent:     #66BB6A;
    --on-accent:  #14171a;
    --accent-rgb: 102 187 106;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg:         #14171a;
  --bg-surface: #14171a;   /* same tone: surfaces must not read as boxes */
  --bg-sunken:  #14171a;
  --text:       #e6e8ea;
  --text-muted: #9aa4ad;
  --border:     #2e353b;
  --link:       #66BB6A;
  --accent:     #66BB6A;
  --on-accent:  #14171a;
  --accent-rgb: 102 187 106;
}


/* =========================================================================
   2. COMMON STYLES -- identical in both themes
   ========================================================================= */

/* ---- fonts: STIX Two Text everywhere, declared exactly once ----
   The base theme mixes Lora, Georgia and Arial across a handful of selectors,
   and Bootstrap sets a sans stack on body. All are re-pointed here.
   Code is the one exception: STIX is proportional and would break alignment. */

:root {
  --font-serif: "STIX Two Text", "STIX Two Math", "Times New Roman", Times, Georgia, serif;
  --font-mono: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

body,
article,
.article-post,
.page-content,
.excerpt,
.btn,
.form-control,
.navbar-brand,
.navbar-light .navbar-nav .nav-link,
.jumbotron-home h1,
.article-headline,
.spanborder span,
ol.list-featured li,
ol.list-featured li:before,
article blockquote,
article blockquote:before,
h1, h2, h3, h4, h5, h6,
.h1, .h2, .h3, .h4, .h5, .h6,
small, .small, input, select, textarea, button {
  font-family: var(--font-serif);
}

code, pre, kbd, samp, .highlight, .highlight * {
  font-family: var(--font-mono) !important;
}

/* ---- titles bold ----
   The theme sets .article-headline to 400 and article headings to 600;
   Bootstrap sets headings to 500. All are overridden here. */
h1, h2, h3, h4, h5, h6,
.h1, .h2, .h3, .h4, .h5, .h6,
article h1, article h2, article h3, article h4, article h5, article h6,
article .h1, article .h2, article .h3, article .h4, article .h5, article .h6,
.article-headline,
.jumbotron-home h1,
.navbar-brand,
.spanborder span {
  font-weight: 700;
}

/* STIX has a modest x-height, so the theme's default body size reads small. */
body { font-size: 1.0625rem; line-height: 1.7; }
.article-post, .page-content { font-size: 1.125rem; line-height: 1.75; }

/* theme.css renders the article's first letter as a floated 5em drop cap.
   Disabled here: it fought with headings and images, and reset the properties
   rather than editing theme.css so the vendor file stays untouched. */
article:first-letter,
article::first-letter {
  float: none;
  font-size: inherit;
  line-height: inherit;
  margin: 0;
  vertical-align: baseline;
}

/* ---- base colours ---- */
body { background-color: var(--bg); color: var(--text); }
.site-content { background-color: transparent; }
a { color: var(--link); }
hr { border-top-color: var(--border); }

/* ---- Bootstrap utilities used in the markup ---- */
.bg-white      { background-color: var(--bg-surface) !important; }
.text-dark     { color: var(--text) !important; }
.text-muted    { color: var(--text-muted) !important; }
.border,
.border-top    { border-color: var(--border) !important; }
.bg-lightblue  { background-color: var(--bg-sunken) !important; }

/* ---- headings / titles ----
   The theme hardcodes these, so they stay near-black in dark mode unless they
   are re-pointed. Selector specificity is matched to the theme's own rules
   (e.g. .navbar-light .navbar-brand is 0,2,0) -- a bare .navbar-brand loses. */
h1, h2, h3, h4, h5, h6,
.h1, .h2, .h3, .h4, .h5, .h6 { color: var(--text); }
.article-headline            { color: var(--text); }

/* .spanborder stacks two rules: a faint one across the full width, and a
   strong accent under the heading text, overlapped via margin-bottom:-1px. */
.spanborder      { border-bottom-color: var(--border); }
.spanborder span { border-bottom-color: var(--text); background-color: transparent; }

/* ---- navbar + footer ---- */
.topnav.bg-white { background-color: var(--bg-surface) !important;
                   border-bottom: 1px solid var(--border); }
.navbar-light .navbar-brand,
.navbar-light .navbar-brand:hover,
.navbar-light .navbar-brand:focus { color: var(--text); }
.navbar-light .navbar-nav .nav-link { color: var(--text-muted); }
.navbar-light .navbar-nav .nav-link:hover { color: var(--link); }
footer.bg-white { background-color: var(--bg-surface) !important;
                  border-top-color: var(--border) !important; }

/* ---- theme components ---- */
.excerpt  { color: var(--text-muted); }
.alertbar { background-color: var(--bg-surface); border-top: 1px solid var(--border); }
.card     { background-color: var(--bg-surface); border: 1px solid var(--border); }

/* ---- article body + code ---- */
.article-post, .page-content { color: var(--text); }
.article-post pre, .page-content pre,
.highlight, code {
  background-color: var(--bg-sunken) !important;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
}
/* inline code sits in a line of prose, so keep its box tight */
code { padding: .1em .35em; }
.article-post pre, .page-content pre, .highlight { padding: .75rem 1rem; }
blockquote { border-left-color: var(--border); color: var(--text-muted); }

/* ---- forms + search modal ---- */
.form-control {
  background-color: var(--bg-sunken);
  border-color: var(--border);
  color: var(--text);
}
.form-control:focus {
  background-color: var(--bg-sunken);
  color: var(--text);
  border-color: var(--accent);
}
.form-control::placeholder { color: var(--text-muted); }
.modal-content { background-color: var(--bg-surface); color: var(--text); border: 1px solid var(--border); }
.modal-header, .modal-footer { border-color: var(--border); }
#lunrsearchresults .lunrsearchresult a { color: var(--text-muted); }

/* ---- accent colour: one colour for the whole site ----
   Bootstrap ships six semantic colours (primary/secondary/success/info/
   warning/danger) and theme.css hardcodes its own green on top. Every one of
   them is aliased to --accent here, so the palette is closed: whichever
   variant class gets used, now or later, it comes out the same green.
   Neutral greys (surfaces, borders, muted text) are deliberately left alone --
   they are not a competing accent. */

/* links */
a { color: var(--link); }
a:hover, a:focus { color: var(--accent); }
/* theme.css sets a.text-dark:hover with !important, so this must match it */
a.text-dark:hover, a.text-dark:focus { color: var(--accent) !important; }
.card a:hover { color: var(--accent); }

/* coloured text */
.text-primary, .text-secondary, .text-success,
.text-info, .text-warning, .text-danger { color: var(--accent) !important; }

/* solid buttons -- --on-accent flips with the theme so the label stays legible
   on the fill (dark green + white in light mode, light green + dark in dark) */
.btn-primary, .btn-success, .btn-info, .btn-warning, .btn-danger, .btn-dark {
  background-color: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
.btn-primary:hover, .btn-success:hover, .btn-info:hover,
.btn-warning:hover, .btn-danger:hover, .btn-dark:hover,
.btn-primary:focus, .btn-success:focus, .btn-info:focus,
.btn-warning:focus, .btn-danger:focus, .btn-dark:focus {
  background-color: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  filter: brightness(1.12);
}

/* outline buttons */
.btn-outline-primary, .btn-outline-secondary, .btn-outline-success,
.btn-outline-info, .btn-outline-warning, .btn-outline-danger,
.btn-outline-dark, .btn-outline-light {
  color: var(--accent);
  border-color: var(--accent);
  background-color: transparent;
}
.btn-outline-primary:hover, .btn-outline-secondary:hover, .btn-outline-success:hover,
.btn-outline-info:hover, .btn-outline-warning:hover, .btn-outline-danger:hover,
.btn-outline-dark:hover, .btn-outline-light:hover,
.btn-outline-primary:focus, .btn-outline-secondary:focus, .btn-outline-success:focus,
.btn-outline-info:focus, .btn-outline-warning:focus, .btn-outline-danger:focus,
.btn-outline-dark:focus, .btn-outline-light:focus {
  background-color: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

/* neutral utility buttons: grey surface, accent label -- no third colour */
.btn-light, .btn-secondary {
  background-color: var(--bg-sunken);
  border-color: var(--border);
  color: var(--accent);
}
.btn-light:hover, .btn-secondary:hover,
.btn-light:focus, .btn-secondary:focus {
  background-color: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

/* coloured fills / borders / badges */
.bg-primary, .bg-success, .bg-info, .bg-warning, .bg-danger {
  background-color: var(--accent) !important;
  fill: var(--accent) !important;
}
.badge-primary, .badge-success, .badge-info, .badge-warning, .badge-danger {
  background-color: var(--accent);
  color: var(--on-accent);
}
.border-primary, .border-success, .border-info,
.border-warning, .border-danger { border-color: var(--accent) !important; }

/* focus rings */
.btn:focus, .btn.focus, .form-control:focus {
  box-shadow: 0 0 0 .2rem rgb(var(--accent-rgb) / .35);
}

/* Footer note: sits under the footer's main row, separated by a hairline.
   Kept narrow so it reads as a statement rather than a block of small print. */
.footer-note {
  max-width: 46rem;
  line-height: 1.6;
}

/* Mobile hamburger.
   Bootstrap bakes stroke='rgba(0,0,0,0.5)' into a data-URI background-image,
   and a CSS variable cannot be interpolated into url() -- so the icon stayed
   black in dark mode. Using the SVG as a mask instead means the shape comes
   from the data URI and the colour from background-color, which follows the
   theme. (Alpha is what a mask reads, so the stroke colour below is irrelevant
   as long as it is opaque.) */
.navbar-light .navbar-toggler-icon {
  background-image: none;
  background-color: var(--text);
  -webkit-mask: url("data:image/svg+xml;charset=utf8,%3Csvg viewBox='0 0 30 30' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 7h22M4 15h22M4 23h22'/%3E%3C/svg%3E") no-repeat center;
          mask: url("data:image/svg+xml;charset=utf8,%3Csvg viewBox='0 0 30 30' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 7h22M4 15h22M4 23h22'/%3E%3C/svg%3E") no-repeat center;
  -webkit-mask-size: 100% 100%;
          mask-size: 100% 100%;
}
.navbar-light .navbar-toggler {
  color: var(--text);
  border-color: var(--border);
}

/* ---- the theme toggle ---- */
#theme-toggle {
  background: none; border: 0; cursor: pointer; line-height: 1;
  padding: .25rem .5rem; color: var(--text-muted); font-size: 1rem;
}
#theme-toggle:hover { color: var(--link); }
/* Show the icon for the theme you would switch *to*. */
#theme-toggle .icon-dark  { display: none; }
:root[data-theme="dark"] #theme-toggle .icon-dark  { display: inline; }
:root[data-theme="dark"] #theme-toggle .icon-light { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #theme-toggle .icon-dark  { display: inline; }
  :root:not([data-theme="light"]) #theme-toggle .icon-light { display: none; }
}
