/*
 * UCCS — Unde Cuvintele Capătă Sens
 * base.css — v6
 *
 * Sections:
 *   1.  Design tokens  (light + dark in one place)
 *   2.  Base reset
 *   3.  Accessibility utilities
 *   4.  Layout
 *   5.  Selection
 *
 * GROUND RULES enforced here:
 *   • No raw hex/rgba/hsl for colour — tokens only.
 *   • Dark overrides live ONCE, inside [data-theme="dark"].
 *   • The @media (prefers-color-scheme: dark) block is an exact
 *     mirror of [data-theme="dark"]. Both are marked /* MIRROR *\/
 *     to signal they must change together.
 *   • Spacing via --space-* only. Font sizes via --text-* only.
 *   • --color-surface-dynamic removed (was alias of surface-offset).
 *   • --content-medium / --content-small removed (unused).
 *   • --nav-height added; scroll-padding-top uses it.
 *   • --space-14 added to fill the gap between 12 and 16.
 *   • Blockquote token --color-blockquote-bg added here so
 *     prose.css can reference it without any raw hex.
 */

/* ============================================================
 *  1. DESIGN TOKENS
 * ============================================================ */

/*
 * Breakpoints — consumed by all other stylesheets via comments.
 * Cannot be used directly in @media queries; reference their
 * pixel values and annotate with the token name.
 *
 * --bp-sm:  480px   (large phones, landscape)
 * --bp-md:  640px   (small tablets / large phones)
 * --bp-lg:  768px   (tablets)
 * --bp-xl: 1024px   (small desktops)
 */

:root {
  --bp-sm:  480px;
  --bp-md:  640px;
  --bp-lg:  768px;
  --bp-xl: 1024px;
}

/* ── Light theme (default) ─────────────────────────────────── */

:root,
[data-theme="light"] {

  /* Surfaces */
  --color-bg:             #f8f5ef;
  --color-surface:        #faf8f3;
  --color-surface-2:      #fcfbf8;
  --color-surface-offset: #f2ede4;
  --color-divider:        #ddd6ca;
  --color-border:         #d4ccc0;

  /* Text */
  --color-text:         #1c1a14;
  --color-text-muted:   #6b6459;
  --color-text-faint:   #b3a99a;
  --color-text-inverse: #f8f5ef;

  /* Brand */
  --color-primary:           #5a3e2b;
  --color-primary-hover:     #432d1c;
  --color-primary-active:    #2e1d10;
  --color-primary-highlight: #e0d4c8;

  --color-gold:       #b07d3a;
  --color-gold-hover: #9a6b2a;

  --color-accent:       #b23080;
  --color-accent-hover: #961f6a;
  --color-accent-light: #f5e0ee;

  /* Semantic */
  --color-error:   #9b2c2c;
  --color-success: #3a6b20;

  /* Canonical Color Extensions */

  /* Core hues */
  --color-red:        #9b2c2c;
  --color-green:      #3a6b20;
  --color-blue:       #305c8c;
  --color-yellow:     #b07d3a;
  --color-orange:     #c46a27;
  --color-purple:     #5d4a82;
  --color-teal:       #3e6f71;
  --color-pink:       #9b3a58;

  /* Hover accents (slightly darker tones) */
  --color-red-hover:    #822525;
  --color-green-hover:  #335b1c;
  --color-blue-hover:   #284b73;
  --color-yellow-hover: #9a6b2a;
  --color-orange-hover: #a8561f;
  --color-purple-hover: #4e3e6b;
  --color-teal-hover:   #335e5e;
  --color-pink-hover:   #82304b;

  /* Highlights / light tints */
  --color-red-light:    #e6b4b4;
  --color-green-light:  #bcd1b0;
  --color-blue-light:   #b8c6da;
  --color-yellow-light: #e0c89a;
  --color-orange-light: #e6b892;
  --color-purple-light: #cac0db;
  --color-teal-light:   #b6cccb;
  --color-pink-light:   #e3c0c9;

  /* Component-level semantic tokens */
  --color-code-border:     rgba(28, 26, 20, 0.08);  /* inline code + pre borders */
  --color-th-border:       rgba(28, 26, 20, 0.18);  /* table <th> bottom rule   */

  /* Prose-specific tokens */
  --color-blockquote-bg:   var(--color-surface-offset);   /* blockquote background    */
  --color-blockquote-mark: var(--color-primary-highlight); /* decorative opening mark  */

  /* Radii */
  --radius-sm:   0.25rem;
  --radius-md:   0.375rem;
  --radius-lg:   0.5rem;
  --radius-xl:   0.75rem;
  --radius-full: 9999px;

  /* Transitions */
  --transition-fast:        120ms cubic-bezier(0.16, 1, 0.3, 1);
  --transition-interactive: 180ms cubic-bezier(0.16, 1, 0.3, 1);

  /* Shadows */
  --shadow-sm: 0 1px 2px  rgba(30, 20, 10, 0.06);
  --shadow-md: 0 4px 14px rgba(30, 20, 10, 0.08);
  --shadow-lg: 0 12px 36px rgba(30, 20, 10, 0.11);

  /* ── Site geometry ──────────────────────────────────────────
   * --site-max-w resizes the whole layout in one go.
   * --nav-height drives scroll-padding-top and mobile drawer. */
  --site-max-w: 1120px;
  --nav-height: 4rem;

  --content-article: 780px;
  --content-narrow:  640px;
  --content-default: 1120px;
  --content-wide:    var(--site-max-w);
  --content-full:    100%;

  /* ── Fluid type scale ───────────────────────────────────────
   * Each step clamps between a minimum (mobile) and maximum
   * (desktop) value, scaling linearly with the viewport. */
  --text-xs:   clamp(0.75rem,   0.7rem   + 0.25vw, 0.8125rem);
  --text-sm:   clamp(0.8125rem, 0.78rem  + 0.25vw, 0.9375rem);
  --text-base: clamp(1rem,      0.96rem  + 0.2vw,  1.125rem);
  --text-lg:   clamp(1.125rem,  1rem     + 0.6vw,  1.375rem);
  --text-xl:   clamp(1.375rem,  1.1rem   + 1.1vw,  2rem);
  --text-2xl:  clamp(1.75rem,   1.2rem   + 2vw,    3rem);
  --text-3xl:  clamp(2.25rem,   1rem     + 3.8vw,  4.5rem);

  /* ── Spacing scale (4 px base) ─────────────────────────────
   * Named by multiplier: --space-4 = 1rem = 16 px. */
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-5:  1.25rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-14: 3.5rem;
  --space-16: 4rem;
  --space-20: 5rem;
  --space-24: 6rem;

  /* ── Typography ─────────────────────────────────────────────
   * --font-ui inherits --font-body; override if a dedicated
   * sans-serif is added later. */
  --font-display: 'Cormorant Garamond', 'Georgia', serif;
  --font-body:    'Source Serif 4', 'Georgia', serif;
  --font-ui:       var(--font-body);
  --font-mono: 'IBM Plex Mono', 'Consolas', monospace;
}

/* ── Dark theme token overrides ────────────────────────────── */
/* MIRROR: every property here must also appear in the
   @media block below. Change both or change neither.        */

[data-theme="dark"] {
  --color-bg:             #17140d;
  --color-surface:        #1c1912;
  --color-surface-2:      #211e16;
  --color-surface-offset: #2a261c;
  --color-divider:        #2e2a20;
  --color-border:         #3d3829;

  --color-text:         #e0d8cb;
  --color-text-muted:   #9a9183;
  --color-text-faint:   #5e5749;
  --color-text-inverse: #17140d;

  --color-primary:           #c4956a;
  --color-primary-hover:     #d4a87e;
  --color-primary-active:    #e0bc96;
  --color-primary-highlight: #2e2318;

  --color-gold:       #c9973f;
  --color-gold-hover: #d9a84e;

    --color-accent:       #cc5599;
    --color-accent-hover: #d96aaa;
    --color-accent-light: #3a1828;

  --color-error:   #e07070;
  --color-success: #7ab856;

  --color-code-border: rgba(224, 216, 203, 0.10);
  --color-th-border:   rgba(224, 216, 203, 0.20);

  /* Prose tokens — darker surface, muted gold mark */
  --color-blockquote-bg:   var(--color-surface-offset);
  --color-blockquote-mark: var(--color-primary-highlight);

  --shadow-sm: 0 1px 2px  rgba(0, 0, 0, 0.25);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 36px rgba(0, 0, 0, 0.45);
}

/* ── System dark mode (no explicit data-theme) — MIRROR ────── */

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --color-bg:             #17140d;
    --color-surface:        #1c1912;
    --color-surface-2:      #211e16;
    --color-surface-offset: #2a261c;
    --color-divider:        #2e2a20;
    --color-border:         #3d3829;

    --color-text:         #e0d8cb;
    --color-text-muted:   #9a9183;
    --color-text-faint:   #5e5749;
    --color-text-inverse: #17140d;

    --color-primary:           #c4956a;
    --color-primary-hover:     #d4a87e;
    --color-primary-active:    #e0bc96;
    --color-primary-highlight: #2e2318;

    --color-gold:       #c9973f;
    --color-gold-hover: #d9a84e;

    --color-accent:       #cc5599;
    --color-accent-hover: #d96aaa;
    --color-accent-light: #3a1828;

    --color-error:   #e07070;
    --color-success: #7ab856;

    --color-code-border: rgba(224, 216, 203, 0.10);
    --color-th-border:   rgba(224, 216, 203, 0.20);

    --color-blockquote-bg:   var(--color-surface-offset);
    --color-blockquote-mark: var(--color-primary-highlight);

    --shadow-sm: 0 1px 2px  rgba(0, 0, 0, 0.25);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 12px 36px rgba(0, 0, 0, 0.45);
  }
}

/* ============================================================
 *  2. BASE RESET
 * ============================================================ */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
  scroll-padding-top: var(--nav-height);
  hanging-punctuation: first last;
}

body {
  min-height: 100dvh;
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.72;
  color: var(--color-text);
  background-color: var(--color-bg);
  transition:
    background-color var(--transition-interactive),
    color            var(--transition-interactive);
}

img, picture, video, canvas, svg {
  display: block;
  max-width: 100%;
  height: auto;
}

img { background: var(--color-surface-offset); }

ul[role="list"],
ol[role="list"] { list-style: none; }

input, button, textarea, select { font: inherit; color: inherit; }

h1, h2, h3, h4, h5, h6 {
  text-wrap: balance;
  line-height: 1.2;
  font-family: var(--font-display);
  font-weight: 500;
}

p, li, figcaption { text-wrap: pretty; }

button { cursor: pointer; background: none; border: none; }

table { border-collapse: collapse; width: 100%; }

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

a {
  color: var(--color-primary);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition:
    color   var(--transition-fast),
    opacity var(--transition-fast);
}

a:hover { color: var(--color-primary-hover); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration:  0.01ms !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ============================================================
 *  3. ACCESSIBILITY UTILITIES
 * ============================================================ */

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

.skip-link {
  position: absolute;
  top: var(--space-3);
  left: var(--space-3);
  padding: var(--space-2) var(--space-4);
  background: var(--color-primary);
  color: var(--color-text-inverse);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 600;
  border-radius: var(--radius-md);
  text-decoration: none;
  z-index: 999;
  transform: translateY(-120%);
  transition: transform var(--transition-fast);
}

.skip-link:focus { transform: translateY(0); }

/* ============================================================
 *  4. LAYOUT
 * ============================================================ */

/*
 * --side-pad: minimum var(--space-4) = 1rem so narrow phones
 * (360 px) still get comfortable edge breathing room.
 */
:root { --side-pad: clamp(var(--space-4), 4vw, var(--space-10)); }

main {
  flex: 1;
  width: 100%;
  max-width: var(--site-max-w);
  margin-inline: auto;
  padding-inline: var(--side-pad);
  padding-block: var(--space-8) var(--space-20);
}

.container-wide {
  max-width: var(--site-max-w);
  margin-inline: auto;
  padding-inline: var(--side-pad);
}

/* ============================================================
 *  5. SELECTION
 * ============================================================ */

/*
 * Light: highlighted in warm primary tint.
 * Dark: inverted — primary colour on dark text.
 * Explicit [data-theme] wins over @media because it comes
 * later in the cascade.
 */

::selection      { background: var(--color-primary-highlight); color: var(--color-text); }
::-moz-selection { background: var(--color-primary-highlight); color: var(--color-text); }

[data-theme="dark"] ::selection      { background: var(--color-primary); color: var(--color-text-inverse); }
[data-theme="dark"] ::-moz-selection { background: var(--color-primary); color: var(--color-text-inverse); }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) ::selection      { background: var(--color-primary); color: var(--color-text-inverse); }
  :root:not([data-theme]) ::-moz-selection { background: var(--color-primary); color: var(--color-text-inverse); }
}