/* ==========================================================================
   Design tokens — colors, spacing, typography, radii, shadows, motion
   ========================================================================== */

:root {
  /* Brand palette — Royal Gold / Matte Black / Pure White */
  --color-primary: #d4af37; /* Royal Gold */
  --color-primary-600: #c49a1a; /* Primary Hover */
  --color-secondary: #e5c76b; /* Secondary Gold */
  --color-accent: #e5c76b; /* Secondary Gold (used for success/copied states) */

  /* Accessible foreground variants — gold fails WCAG text/icon contrast on
     light backgrounds (~2.1:1), so text/icon usage on light surfaces reads
     this darker, same-hue gold instead. Backgrounds, gradients, borders, and
     dark-surface foregrounds keep the true brand gold above. */
  --color-primary-text: #8a6d23;
  --color-accent-text: #8a6d23;

  /* Text/icon color for content sitting ON TOP of a gold-colored background
     (buttons, "copied" pills, badges). Gold+black passes WCAG (~8.8:1) in
     both themes; gold+white fails (~2.1:1) in both — so this is intentionally
     NOT theme-dependent like --color-text is. */
  --color-on-primary: #121212;
  --color-on-accent: #121212;

  /* Brand RGB channels (for alpha compositing) */
  --primary-rgb: 212, 175, 55;
  --secondary-rgb: 229, 199, 107;

  --color-bg: #fafafa;
  --color-surface: #ffffff;
  --color-surface-2: #f2f2f2;
  --color-surface-3: #e8e8e8;
  --color-border: #e2e2e2;
  --color-border-strong: #cfcfcf;

  --color-text: #121212;
  --color-text-muted: #666666;
  --color-text-subtle: #7a7a7a;

  /* Gradients */
  --gradient-brand: linear-gradient(135deg, var(--color-primary) 0%, var(--color-secondary) 50%, var(--color-primary-600) 100%);
  --gradient-brand-soft: linear-gradient(135deg, rgba(var(--primary-rgb), 0.12), rgba(var(--secondary-rgb), 0.1), rgba(var(--primary-rgb), 0.12));
  --gradient-mesh: radial-gradient(60% 60% at 15% 10%, rgba(var(--primary-rgb), 0.16), transparent 60%),
    radial-gradient(50% 50% at 85% 0%, rgba(var(--secondary-rgb), 0.14), transparent 60%),
    radial-gradient(60% 60% at 50% 100%, rgba(var(--primary-rgb), 0.12), transparent 60%);

  /* Grid pattern (hero background) — neutral, restrained; gold stays reserved for deliberate accents */
  --grid-line: rgba(18, 18, 18, 0.06);
  --grid-size: 48px;

  /* Glassmorphism */
  --glass-bg: rgba(255, 255, 255, 0.68);
  --glass-border: rgba(255, 255, 255, 0.5);
  --glass-blur: 18px;
  --glass-shadow: 0 8px 32px rgba(18, 18, 18, 0.08);

  /* Typography */
  --font-sans: "Poppins", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --fs-xs: 0.8125rem;
  --fs-sm: 0.9375rem;
  --fs-base: 1rem;
  --fs-lg: 1.125rem;
  --fs-xl: 1.375rem;
  --fs-2xl: 1.75rem;
  --fs-3xl: 2.25rem;
  --fs-4xl: 3rem;
  --fs-5xl: 3.75rem;

  --lh-tight: 1.15;
  --lh-snug: 1.35;
  --lh-normal: 1.65;

  /* Spacing scale */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;
  --space-8: 4rem;
  --space-9: 6rem;
  --space-10: 8rem;

  /* Radii */
  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  --radius-2xl: 36px;
  --radius-full: 999px;

  /* Shadows — layered for realistic depth */
  --shadow-xs: 0 1px 2px rgba(18, 18, 18, 0.05);
  --shadow-sm: 0 2px 4px rgba(18, 18, 18, 0.05), 0 1px 2px rgba(18, 18, 18, 0.04);
  --shadow-md: 0 4px 12px rgba(18, 18, 18, 0.07), 0 2px 4px rgba(18, 18, 18, 0.05);
  --shadow-lg: 0 12px 28px rgba(18, 18, 18, 0.1), 0 6px 12px rgba(18, 18, 18, 0.06);
  --shadow-xl: 0 24px 56px rgba(18, 18, 18, 0.14), 0 10px 20px rgba(18, 18, 18, 0.08);
  --shadow-glow: 0 0 0 1px rgba(var(--primary-rgb), 0.18), 0 12px 32px rgba(var(--primary-rgb), 0.22);
  --shadow-glow-hover: 0 0 0 1px rgba(var(--primary-rgb), 0.24), 0 18px 44px rgba(var(--primary-rgb), 0.32);

  /* Focus — darker accessible gold so the ring itself meets 3:1 on light surfaces */
  --focus-ring: 0 0 0 3px rgba(138, 109, 35, 0.45);

  /* Motion */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --duration-fast: 150ms;
  --duration-base: 250ms;
  --duration-slow: 450ms;

  /* Layout */
  --container-max: 1280px;
  --header-height: 76px;

  color-scheme: light;
}

:root[data-theme="dark"] {
  --color-bg: #121212; /* Matte Black */
  --color-surface: #1b1b1b; /* Dark Surface */
  --color-surface-2: #232323;
  --color-surface-3: #2b2b2b;
  --color-border: #333333;
  --color-border-strong: #3f3f3f;

  --color-text: #ffffff;
  --color-text-muted: #b3b3b3;
  --color-text-subtle: #8c8c8c;

  /* Gold reads with excellent contrast directly on matte black, so dark mode
     can use the true brand gold for text/icons too. */
  --color-primary-text: var(--color-primary);
  --color-accent-text: var(--color-accent);

  --grid-line: rgba(255, 255, 255, 0.07);

  --glass-bg: rgba(27, 27, 27, 0.65);
  --glass-border: rgba(255, 255, 255, 0.1);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);

  --gradient-mesh: radial-gradient(60% 60% at 15% 10%, rgba(var(--primary-rgb), 0.24), transparent 60%),
    radial-gradient(50% 50% at 85% 0%, rgba(var(--secondary-rgb), 0.2), transparent 60%),
    radial-gradient(60% 60% at 50% 100%, rgba(var(--primary-rgb), 0.18), transparent 60%);

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 6px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 14px 32px rgba(0, 0, 0, 0.45);
  --shadow-xl: 0 28px 60px rgba(0, 0, 0, 0.55);
  --shadow-glow: 0 0 0 1px rgba(var(--primary-rgb), 0.28), 0 12px 32px rgba(var(--primary-rgb), 0.35);
  --shadow-glow-hover: 0 0 0 1px rgba(var(--primary-rgb), 0.36), 0 18px 44px rgba(var(--primary-rgb), 0.48);

  --focus-ring: 0 0 0 3px rgba(212, 175, 55, 0.5);

  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --color-bg: #121212;
    --color-surface: #1b1b1b;
    --color-surface-2: #232323;
    --color-surface-3: #2b2b2b;
    --color-border: #333333;
    --color-border-strong: #3f3f3f;

    --color-text: #ffffff;
    --color-text-muted: #b3b3b3;
    --color-text-subtle: #8c8c8c;

    --color-primary-text: var(--color-primary);
    --color-accent-text: var(--color-accent);

    --grid-line: rgba(255, 255, 255, 0.07);

    --glass-bg: rgba(27, 27, 27, 0.65);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);

    --gradient-mesh: radial-gradient(60% 60% at 15% 10%, rgba(var(--primary-rgb), 0.24), transparent 60%),
      radial-gradient(50% 50% at 85% 0%, rgba(var(--secondary-rgb), 0.2), transparent 60%),
      radial-gradient(60% 60% at 50% 100%, rgba(var(--primary-rgb), 0.18), transparent 60%);

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 6px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 14px 32px rgba(0, 0, 0, 0.45);
    --shadow-xl: 0 28px 60px rgba(0, 0, 0, 0.55);
    --shadow-glow: 0 0 0 1px rgba(var(--primary-rgb), 0.28), 0 12px 32px rgba(var(--primary-rgb), 0.35);
    --shadow-glow-hover: 0 0 0 1px rgba(var(--primary-rgb), 0.36), 0 18px 44px rgba(var(--primary-rgb), 0.48);

    --focus-ring: 0 0 0 3px rgba(212, 175, 55, 0.5);

    color-scheme: dark;
  }
}

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

/* The `hidden` attribute must always win, even against classes (e.g. .btn)
   that set an explicit `display` — author specificity ties default to
   showing the element otherwise, which defeats the attribute's purpose. */
[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: calc(var(--header-height) + var(--space-4));
}

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

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-normal);
  color: var(--color-text);
  background: var(--color-bg);
  transition: background-color var(--duration-base) var(--ease-out), color var(--duration-base) var(--ease-out);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

img,
svg {
  display: block;
  max-width: 100%;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
  cursor: pointer;
}

ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

h1,
h2,
h3,
h4 {
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: var(--lh-tight);
  color: var(--color-text);
}

/* Focus visibility for accessibility */
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

.btn:focus-visible,
.icon-btn:focus-visible,
.icon-action:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.skip-link {
  position: absolute;
  top: -48px;
  left: var(--space-4);
  background: var(--color-primary);
  color: var(--color-on-primary);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  z-index: 1000;
  transition: top var(--duration-fast) var(--ease-out);
}

.skip-link:focus {
  top: var(--space-3);
}

/* Layout helpers */
.container {
  width: 100%;
  max-width: var(--container-max);
  margin-inline: auto;
  padding-inline: var(--space-5);
}

@media (min-width: 640px) {
  .container {
    padding-inline: var(--space-6);
  }
}

.section {
  padding-block: var(--space-9);
}

@media (max-width: 640px) {
  .section {
    padding-block: var(--space-8);
  }
}

/* Alternating section background for rhythm */
.section-alt {
  background: var(--color-surface-2);
  border-block: 1px solid var(--color-border);
}

.section-head {
  max-width: 660px;
  margin-inline: auto;
  text-align: center;
  margin-bottom: var(--space-7);
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-primary-text);
  background: color-mix(in srgb, var(--color-primary) 10%, transparent);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-full);
  margin-bottom: var(--space-4);
  border: 1px solid color-mix(in srgb, var(--color-primary) 14%, transparent);
}

.eyebrow svg {
  width: 14px;
  height: 14px;
}

.section-title {
  font-size: clamp(1.85rem, 1.4rem + 1.8vw, var(--fs-3xl));
  margin-bottom: var(--space-3);
}

.section-subtitle {
  color: var(--color-text-muted);
  font-size: var(--fs-lg);
  line-height: var(--lh-snug);
}

/* Longer intro paragraph variant, for content-rich sections */
.section-intro {
  max-width: 760px;
  margin: 0 auto var(--space-7);
  text-align: center;
  color: var(--color-text-muted);
  font-size: var(--fs-lg);
  line-height: var(--lh-normal);
}

/* Long-form article prose within a section */
.prose-article {
  max-width: 820px;
  margin-inline: auto;
}

.prose-article h2 {
  font-size: clamp(1.6rem, 1.3rem + 1.2vw, var(--fs-2xl));
  margin-bottom: var(--space-4);
}

.prose-article h3 {
  font-size: var(--fs-xl);
  margin-top: var(--space-6);
  margin-bottom: var(--space-3);
}

.prose-article p {
  color: var(--color-text-muted);
  line-height: var(--lh-normal);
  margin-bottom: var(--space-4);
}

.prose-article p:last-child {
  margin-bottom: 0;
}

/* Gradient text */
.text-gradient {
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* Glass surface */
.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur)) saturate(160%);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(160%);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  font-weight: 600;
  font-size: var(--fs-sm);
  padding: 0.85rem 1.6rem;
  border-radius: var(--radius-full);
  border: 1px solid transparent;
  transition: transform var(--duration-fast) var(--ease-out), box-shadow var(--duration-base) var(--ease-out),
    background var(--duration-fast) var(--ease-out), border-color var(--duration-fast) var(--ease-out);
  white-space: nowrap;
}

.btn:active {
  transform: translateY(1px);
}

.btn-lg {
  font-size: var(--fs-base);
  padding: 1rem 2rem;
}

.btn-primary {
  position: relative;
  background: var(--gradient-brand);
  background-size: 140% 140%;
  background-position: 0% 50%;
  color: var(--color-on-primary);
  box-shadow: var(--shadow-glow);
  transition: transform var(--duration-fast) var(--ease-out), box-shadow var(--duration-base) var(--ease-out),
    background-position var(--duration-slow) var(--ease-out);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-glow-hover);
  background-position: 100% 50%;
}

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border-strong);
  box-shadow: var(--shadow-xs);
}

.btn-secondary:hover {
  border-color: var(--color-primary);
  color: var(--color-primary-text);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

/* Card base */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  transition: transform var(--duration-base) var(--ease-out), box-shadow var(--duration-base) var(--ease-out),
    border-color var(--duration-base) var(--ease-out);
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: color-mix(in srgb, var(--color-primary) 32%, var(--color-border));
}

/* Icon badge — shared square gradient icon container */
.icon-badge {
  display: inline-grid;
  place-items: center;
  border-radius: var(--radius-md);
  background: var(--gradient-brand-soft);
  color: var(--color-primary-text);
  flex-shrink: 0;
}

/* Recently copied — shared by any filterable-grid instance with
   [data-fg-recent]/[data-fg-recent-list] markup (see filterable-grid.js) */
.recent-copies {
  margin-bottom: var(--space-5);
}

.recent-copies-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-subtle);
  margin-bottom: var(--space-3);
}

.recent-copies-label svg {
  width: 14px;
  height: 14px;
}

.recent-copies-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.recent-copies-chip {
  font-size: var(--fs-sm);
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  padding: 6px 14px;
  border-radius: var(--radius-full);
  transition: border-color var(--duration-fast) var(--ease-out), transform var(--duration-fast) var(--ease-out);
}

.recent-copies-chip:hover {
  border-color: var(--color-primary);
  transform: translateY(-1px);
}

.recent-copies-chip.is-copied {
  background: var(--color-accent);
  color: var(--color-on-accent);
  border-color: var(--color-accent);
}

/* Scroll reveal */
[data-reveal] {
  opacity: 0;
  transform: translateY(24px);
  transition: opacity var(--duration-slow) var(--ease-out), transform var(--duration-slow) var(--ease-out);
  will-change: opacity, transform;
}

[data-reveal].is-visible {
  opacity: 1;
  transform: translateY(0);
  will-change: auto;
}

@media (prefers-reduced-motion: reduce) {
  [data-reveal] {
    opacity: 1;
    transform: none;
  }
}

/* Visually hidden but accessible */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Back to top */
.back-to-top {
  position: fixed;
  right: var(--space-5);
  bottom: var(--space-5);
  z-index: 80;
  display: inline-grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-muted);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  visibility: hidden;
  /* How far the button rides above its resting place, so the adhesion rule
     below can lift it without touching `bottom`. Moving it with `bottom` lays
     the button out again and the browser counts that against CLS — a measured
     0.0251 on the Astro half of the site every time the ad appeared, and this
     file carried the identical rule. A transform moves it without laying
     anything out, and the same transition still animates it. Keep in step with
     src/styles/global.css, which has the same block. */
  --lift: 0px;
  transform: translateY(calc(12px - var(--lift)));
  transition: opacity var(--duration-base) var(--ease-out), transform var(--duration-base) var(--ease-out),
    visibility var(--duration-base), color var(--duration-fast) var(--ease-out), border-color var(--duration-fast) var(--ease-out);
}

.back-to-top.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(calc(0px - var(--lift)));
}

/* Mediavine fixes its adhesion ad to the bottom of the viewport, above every
   z-index on the page, and marks the body while one is live. The button sat
   underneath it and could not be pressed. Lift it clear rather than over the
   top: covering an ad costs viewability, and there is room above it. The unit
   is 90px on desktop and shorter on phones, so one offset clears both. */
body.adhesion .back-to-top {
  /* 82px is the old `calc(90px + var(--space-4))` measured against the button's
     own `bottom: var(--space-5)`, so it clears the ad by exactly as much as
     before — the same position, reached without a relayout. */
  --lift: 82px;
}

.back-to-top:hover {
  color: var(--color-primary-text);
  border-color: var(--color-primary);
}

.back-to-top svg {
  width: 20px;
  height: 20px;
}
