/* =====================================================================
   theme-base.css  —  shared theme kit for Carey's sites (v0.1 draft)
   ---------------------------------------------------------------------
   Load order (all files local, no CDNs):
     1. theme-base.css        semantic tokens + light/dark + components
     2. brand-<site>.css      overrides brand tokens only
     3. themes/<fun>.css      optional fun themes (override tokens only)
     4. site.css              page-specific layout, using var(--…) only
   Theme switching: <html data-theme="light|dark|<fun>">, set by theme.js.
   Selector convention (keeps specificity predictable):
     :root                              light defaults        (0,1,0)
     :root[data-theme="dark"]           dark                  (0,2,0)
     @media dark  :root:not([data-theme])  no-JS dark fallback (0,2,0)
     :root[data-theme="<fun>"]          fun themes            (0,2,0)
   ===================================================================== */

/* ---------- 1. Light (default) -------------------------------------- */
:root {
  color-scheme: light;

  /* Surfaces */
  --color-bg:            #f8f8f6;  /* page background                   */
  --color-surface:       #ffffff;  /* cards, panels, inputs             */
  --color-surface-2:     #f0f0ec;  /* raised/alternate rows, sidebars   */
  --color-tint:          #e8eef5;  /* soft accent wash (highlights)     */
  --color-border:        #d6d6cf;  /* hairlines, dividers               */

  /* Text */
  --color-text:          #1d2433;  /* body copy                         */
  --color-text-muted:    #5a6273;  /* captions, meta (still AA)         */

  /* Brand / interactive */
  --color-accent:          #2f5d8a; /* primary buttons, active states   */
  --color-accent-contrast: #ffffff; /* text/icons placed ON accent      */
  --color-accent-2:        #a4552a; /* secondary brand colour           */
  --color-accent-2-contrast:#ffffff;
  --color-link:          #2f5d8a;
  --color-link-hover:    #1d4166;
  --color-focus:         #2563c9;  /* focus ring, >=3:1 against bg      */
  --brand-gradient:      linear-gradient(135deg, var(--color-accent), var(--color-accent-2));
  --brand-gradient-fg:   var(--color-accent-contrast); /* text on gradient */

  /* Status (usable as text on surface AND as fills with white text)   */
  --color-success:       #2e7d4f;
  --color-warning:       #8a5a00;
  --color-danger:        #b3261e;

  /* Code */
  --color-code-bg:       #18233a;
  --color-code-fg:       #e6edf7;

  /* Elevation */
  --shadow-sm: 0 1px 2px rgb(16 24 40 / .08);
  --shadow-md: 0 4px 12px rgb(16 24 40 / .10);

  /* Shape */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 14px;
  --radius-pill: 999px;

  /* Spacing scale (4px base) */
  --space-1: .25rem;  --space-2: .5rem;  --space-3: .75rem;
  --space-4: 1rem;    --space-5: 1.5rem; --space-6: 2rem;
  --space-7: 3rem;    --space-8: 4rem;

  /* Fonts — system stacks only. --font-display is the per-site hook
     (a brand layer may point it at a SELF-HOSTED @font-face).          */
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans",
               "Helvetica Neue", Arial, sans-serif;
  --font-display: var(--font-body);
  --font-mono: ui-monospace, "SFMono-Regular", Menlo, Consolas,
               "Liberation Mono", monospace;

  /* Type scale (~1.2 ratio) */
  --text-xs: .8rem;  --text-sm: .9rem;  --text-md: 1rem;
  --text-lg: 1.2rem; --text-xl: 1.44rem; --text-2xl: 1.73rem;
  --text-3xl: 2.07rem;
  --leading: 1.6;
  --leading-tight: 1.25;

  --measure: 70ch;   /* comfortable line length */
}

/* ---------- 2. Dark --------------------------------------------------- */
/* Keep these two blocks identical (check-contrast.py verifies it).      */
:root[data-theme="dark"] {
  color-scheme: dark;
  --color-bg: #12151c;  --color-surface: #1a1f29;  --color-surface-2: #232a36;
  --color-tint: #1d2b3d;  --color-border: #384152;
  --color-text: #e6e9ef;  --color-text-muted: #a6aebc;
  --color-accent: #7fb0e6;  --color-accent-contrast: #0e1420;
  --color-accent-2: #e39a68;  --color-accent-2-contrast: #1a1008;
  --color-link: #8dbcf0;  --color-link-hover: #b9d6f7;  --color-focus: #8dbcf0;
  --color-success: #6cc58f;  --color-warning: #e8b85a;  --color-danger: #f2867d;
  --color-code-bg: #0b0f17;  --color-code-fg: #e6edf7;
  --shadow-sm: 0 1px 2px rgb(0 0 0 / .4);
  --shadow-md: 0 4px 14px rgb(0 0 0 / .45);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --color-bg: #12151c;  --color-surface: #1a1f29;  --color-surface-2: #232a36;
    --color-tint: #1d2b3d;  --color-border: #384152;
    --color-text: #e6e9ef;  --color-text-muted: #a6aebc;
    --color-accent: #7fb0e6;  --color-accent-contrast: #0e1420;
    --color-accent-2: #e39a68;  --color-accent-2-contrast: #1a1008;
    --color-link: #8dbcf0;  --color-link-hover: #b9d6f7;  --color-focus: #8dbcf0;
    --color-success: #6cc58f;  --color-warning: #e8b85a;  --color-danger: #f2867d;
    --color-code-bg: #0b0f17;  --color-code-fg: #e6edf7;
    --shadow-sm: 0 1px 2px rgb(0 0 0 / .4);
    --shadow-md: 0 4px 14px rgb(0 0 0 / .45);
  }
}

/* ---------- 3. Base elements ----------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font: var(--text-md)/var(--leading) var(--font-body);
  overflow-wrap: break-word;   /* 7 languages: long words must wrap   */
  hyphens: auto;               /* needs <html lang="…"> per language   */
}
h1, h2, h3, h4 {
  font-family: var(--font-display);
  line-height: var(--leading-tight);
  margin: var(--space-5) 0 var(--space-3);
  text-wrap: balance;
}
h1 { font-size: var(--text-3xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
p  { max-width: var(--measure); }
small, .muted { color: var(--color-text-muted); }

a { color: var(--color-link); text-underline-offset: .15em; }
a:hover { color: var(--color-link-hover); }

:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
}

code, pre, kbd { font-family: var(--font-mono); font-size: .92em; }
pre {
  background: var(--color-code-bg);
  color: var(--color-code-fg);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  overflow-x: auto;
}
:not(pre) > code {
  background: var(--color-surface-2);
  padding: .1em .35em;
  border-radius: var(--radius-sm);
}
hr { border: 0; border-top: 1px solid var(--color-border); }

/* SVG icons follow the text colour automatically */
svg.icon { width: 1.25em; height: 1.25em; fill: none; stroke: currentColor;
           stroke-width: 2; vertical-align: -.2em; flex-shrink: 0; }

/* ---------- 4. Components -------------------------------------------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-5);
  min-width: 0;                 /* lets long strings wrap inside grids */
}
/* Long words (pl/ru/pt…) must never overflow a component. "anywhere" also
   shrinks min-content size, so flex/grid children can actually narrow. */
.card, .btn, .tag, .alert, .alert > *, th, td { overflow-wrap: anywhere; min-width: 0; }

.btn {
  display: inline-flex; align-items: center; gap: var(--space-2);
  max-width: 100%;
  padding: var(--space-2) var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: var(--color-accent);
  color: var(--color-accent-contrast);
  font: inherit; font-weight: 600; line-height: var(--leading-tight);
  text-align: center; text-decoration: none; white-space: normal;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.08); color: var(--color-accent-contrast); }
.btn--secondary { background: var(--color-accent-2); color: var(--color-accent-2-contrast); }
.btn--secondary:hover { color: var(--color-accent-2-contrast); }
.btn--ghost {
  background: transparent; color: var(--color-link);
  border-color: var(--color-border);
}
.btn--ghost:hover { background: var(--color-tint); color: var(--color-link); }

.tag {
  display: inline-block; max-width: 100%;
  padding: .1em .6em;
  border-radius: var(--radius-pill);
  background: var(--tag-bg, var(--color-tint));
  color: var(--tag-fg, var(--color-text));
  font-size: var(--text-sm); font-weight: 600;
}

.alert {
  display: flex; gap: var(--space-3); align-items: flex-start;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-border);
  border-left: 4px solid var(--alert-color, var(--color-accent));
  border-radius: var(--radius-md);
  background: var(--color-surface);
}
.alert > svg { color: var(--alert-color, var(--color-accent)); }
.alert--success { --alert-color: var(--color-success); }
.alert--warning { --alert-color: var(--color-warning); }
.alert--danger  { --alert-color: var(--color-danger); }

input, select, textarea {
  font: inherit; color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  max-width: 100%;
}

table { border-collapse: collapse; width: 100%; }
th, td { text-align: start; padding: var(--space-2) var(--space-3);
         border-bottom: 1px solid var(--color-border); }
thead th { background: var(--color-surface-2); }

.site-header {
  background: var(--brand-gradient);
  color: var(--brand-gradient-fg);
  padding: var(--space-5) var(--space-4);
  /* Text on the gradient is checked at WCAG "large text" (3:1), so keep
     everything in the header >= 18.66px bold. Put small print elsewhere. */
  font-size: var(--text-lg);
  font-weight: 700;
}
.site-header a { color: inherit; }

.nav { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4);
       list-style: none; margin: 0; padding: 0; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* Visually hidden but available to screen readers / SVG sprite holders */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden;
           clip: rect(0 0 0 0); white-space: nowrap; }
