/* ==========================================================================
   gbbns.co — design tokens
   Three tiers: primitive → semantic → component.
   Theming uses light-dark(): every semantic colour is declared once and
   resolves against the nearest `color-scheme`, so a nested
   [data-theme="dark"] region works without re-declaring a single token.
   ========================================================================== */

@layer reset, tokens, base, layout, components, utilities;

@layer tokens {

  /* ------------------------------------------------------------------------
     TIER 1 · PRIMITIVES — raw values, no intent. Never used in components.
     ------------------------------------------------------------------------ */
  :root {
    /* Colour · stone (neutral: warm limestone at the top, peat at the bottom) */
    --color-stone-0:   oklch(99.2% 0.004 100); /* #FDFCF9 */
    --color-stone-50:  oklch(97.8% 0.006 100); /* #F9F8F3 */
    --color-stone-100: oklch(95.8% 0.009 100); /* #F2F1EB */
    --color-stone-200: oklch(92.6% 0.012 100); /* #E8E7DE */
    --color-stone-300: oklch(87.5% 0.014 102); /* #D7D6CC */
    --color-stone-400: oklch(77% 0.015 105);   /* #B5B5AA */
    --color-stone-500: oklch(60% 0.016 112);   /* #808177 */
    --color-stone-600: oklch(49% 0.017 125);   /* #5E6258 */
    --color-stone-700: oklch(40% 0.018 140);   /* #434A41 */
    --color-stone-800: oklch(31% 0.018 150);   /* #2A332C */
    --color-stone-850: oklch(26.5% 0.017 152); /* #1F2821 */
    --color-stone-900: oklch(22.5% 0.016 155); /* #161E18 */
    --color-stone-950: oklch(18.5% 0.014 155); /* #0E1510 */

    /* Colour · heather (accent) */
    --color-heather-100: oklch(94.5% 0.026 345); /* #FBE6F1 */
    --color-heather-200: oklch(89% 0.055 345);   /* #F7CDE3 */
    --color-heather-300: oklch(81% 0.1 345);     /* #F0A7D0 */
    --color-heather-400: oklch(73% 0.135 345);   /* #E383BB */
    --color-heather-500: oklch(56% 0.17 345);    /* #B5418B */
    --color-heather-600: oklch(43.5% 0.16 345);  /* #891C65 */
    --color-heather-700: oklch(38% 0.14 345);    /* #711653 */
    --color-heather-800: oklch(30% 0.1 345);     /* #4E1239 */
    --color-heather-900: oklch(25% 0.06 345);    /* #351428 */

    /* Colour · moss (support) */
    --color-moss-100: oklch(94.5% 0.022 160); /* #E1F2E8 */
    --color-moss-200: oklch(89% 0.04 160);    /* #C5E3D2 */
    --color-moss-300: oklch(81% 0.065 160);   /* #9DCEB3 */
    --color-moss-400: oklch(71% 0.085 160);   /* #71B28F */
    --color-moss-500: oklch(57% 0.095 160);   /* #3D8864 */
    --color-moss-600: oklch(46% 0.085 160);   /* #236647 */
    --color-moss-700: oklch(38% 0.07 160);    /* #194E35 */
    --color-moss-800: oklch(30% 0.05 160);    /* #143525 */
    --color-moss-900: oklch(25% 0.035 160);   /* #11271C */

    /* Type · families (self-hosted variable WOFF2, font-display: swap) */
    --font-family-display: "Bricolage Grotesque", "Avenir Next", "Segoe UI", system-ui, sans-serif;
    --font-family-body: "Atkinson Hyperlegible Next", "Atkinson Hyperlegible", Verdana, system-ui, sans-serif;
    --font-family-mono: "Atkinson Hyperlegible Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

    /* Type · weights (three, across two variable files plus mono) */
    --font-weight-regular: 400;
    --font-weight-semibold: 600;
    --font-weight-bold: 700;

    /* Type · fluid scale, 320px → 1280px. rem + vi so text zoom still works. */
    --font-size-xs:  0.8125rem;
    --font-size-sm:  clamp(0.875rem, 0.854rem + 0.104vi, 0.9375rem);
    --font-size-md:  clamp(1.0625rem, 1.021rem + 0.208vi, 1.1875rem);
    --font-size-lg:  clamp(1.25rem, 1.167rem + 0.417vi, 1.5rem);
    --font-size-xl:  clamp(1.5rem, 1.333rem + 0.833vi, 2rem);
    --font-size-2xl: clamp(1.875rem, 1.583rem + 1.458vi, 2.75rem);
    --font-size-3xl: clamp(2.375rem, 1.917rem + 2.292vi, 3.75rem);
    --font-size-4xl: clamp(2.875rem, 2.167rem + 3.542vi, 5rem);

    /* Type · line height and tracking */
    --line-height-tight: 1.05;
    --line-height-snug: 1.2;
    --line-height-ui: 1.45;
    --line-height-prose: 1.7;
    --letter-spacing-tight: -0.02em;
    --letter-spacing-normal: 0;
    --letter-spacing-caps: 0.08em;

    /* Space · 4px base, --space-4 is 1rem */
    --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;

    /* Size */
    --size-1: 1rem;
    --size-2: 1.25rem;
    --size-3: 1.5rem;
    --size-4: 2rem;
    --size-5: 2.75rem;
    --size-6: 4rem;
    --size-prose: 44rem;
    --size-wide: 72rem;
    --size-sidebar: 15rem;

    /* Radius · a deliberate scale, one step per level of nesting */
    --radius-xs: 0.25rem;
    --radius-sm: 0.5rem;
    --radius-md: 0.75rem;
    --radius-lg: 1.25rem;
    --radius-xl: 2rem;
    --radius-2xl: 3rem;
    --radius-full: 999px;

    /* Border */
    --border-width-1: 1px;
    --border-width-2: 2px;
    --border-width-3: 3px;

    /* Motion */
    --duration-1: 120ms;
    --duration-2: 200ms;
    --duration-3: 320ms;
    --ease-out: cubic-bezier(0.2, 0.7, 0.2, 1);
    --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);

    /* Z-index */
    --z-base: 0;
    --z-raised: 1;
    --z-sticky: 10;
    --z-header: 20;
    --z-skip-link: 100;

    /* Breakpoints (reference only: custom properties cannot be used in
       @media or @container conditions; values are repeated in the queries) */
    --breakpoint-sm: 30rem;
    --breakpoint-md: 48rem;
    --breakpoint-lg: 64rem;
    --breakpoint-xl: 80rem;
  }

  /* ------------------------------------------------------------------------
     TIER 2 · SEMANTIC — intent. light-dark(light, dark).
     ------------------------------------------------------------------------ */
  :root {
    color-scheme: light dark;

    /* Surfaces: page, then three steps of tinted elevation */
    --color-bg-page:         light-dark(var(--color-stone-100), var(--color-stone-950));
    --color-bg-surface-1:    light-dark(var(--color-stone-200), var(--color-stone-900));
    --color-bg-surface-2:    light-dark(var(--color-stone-50),  var(--color-stone-850));
    --color-bg-surface-3:    light-dark(var(--color-stone-0),   var(--color-stone-800));
    --color-bg-accent-soft:  light-dark(var(--color-heather-100), var(--color-heather-900));
    --color-bg-support-soft: light-dark(var(--color-moss-100),  var(--color-moss-900));
    --color-bg-accent:       light-dark(var(--color-heather-600), var(--color-heather-300));
    --color-bg-accent-hover: light-dark(var(--color-heather-700), var(--color-heather-200));

    /* Text */
    --color-text-primary:    light-dark(var(--color-stone-900), var(--color-stone-100));
    --color-text-secondary:  light-dark(var(--color-stone-700), var(--color-stone-300));
    --color-text-muted:      light-dark(var(--color-stone-600), var(--color-stone-400));
    --color-text-accent:     light-dark(var(--color-heather-600), var(--color-heather-300));
    --color-text-support:    light-dark(var(--color-moss-700),  var(--color-moss-300));
    --color-text-on-accent:  light-dark(var(--color-stone-50),  var(--color-stone-950));

    /* Borders: subtle is decorative only; strong carries 3:1 for controls */
    --color-border-subtle:   light-dark(var(--color-stone-300), var(--color-stone-800));
    --color-border-strong:   light-dark(var(--color-stone-500), var(--color-stone-500));
    --color-border-accent:   var(--color-text-accent);

    /* Focus and decoration */
    --color-focus:           light-dark(var(--color-heather-600), var(--color-heather-300));
    --color-topo:            light-dark(var(--color-moss-400), var(--color-moss-600));

    /* Elevation: tint first, shadow only for things that lift on interaction */
    --shadow-1: 0 1px 2px light-dark(oklch(22.5% 0.016 155 / 0.06), oklch(0% 0 0 / 0.3));
    --shadow-2: 0 6px 24px -8px light-dark(oklch(22.5% 0.016 155 / 0.16), oklch(0% 0 0 / 0.5));

    /* Type roles */
    --font-heading: var(--font-family-display);
    --font-body: var(--font-family-body);
    --font-code: var(--font-family-mono);
    --font-size-body: var(--font-size-md);
    --font-size-prose: clamp(1.125rem, 1.0625rem + 0.3125vi, 1.3125rem);
    --measure-prose: 60ch; /* ch is the width of "0": 60ch sets roughly 68 to 72 characters */
    --measure-ui: 44ch;

    /* Space roles */
    --space-gutter: clamp(1rem, 0.5rem + 2.5vi, 2.5rem);
    --space-section: clamp(3rem, 2rem + 5vi, 6rem);
    --space-flow: 1.25em;

    /* Radius roles */
    --radius-inline: var(--radius-xs);
    --radius-control: var(--radius-md);
    --radius-card: var(--radius-lg);
    --radius-panel: var(--radius-xl);
    --radius-section: var(--radius-2xl);
    --radius-pill: var(--radius-full);

    /* Size roles */
    --size-target: var(--size-5);       /* 44px, the default hit area */
    --size-target-min: var(--size-3);   /* 24px, WCAG 2.2 floor, inline only */
    --size-icon: var(--size-2);

    /* Motion roles */
    --transition-quick: var(--duration-1) var(--ease-out);
    --transition-gentle: var(--duration-2) var(--ease-out);
  }

  /* Manual theme toggle: the attribute only flips color-scheme. */
  [data-theme="light"] { color-scheme: light; }
  [data-theme="dark"]  { color-scheme: dark; }

  @media (prefers-contrast: more) {
    :root {
      --color-text-muted:     light-dark(var(--color-stone-700), var(--color-stone-300));
      --color-text-secondary: light-dark(var(--color-stone-900), var(--color-stone-100));
      --color-border-subtle:  light-dark(var(--color-stone-500), var(--color-stone-500));
      --color-topo: transparent;
    }
  }

  @media (prefers-reduced-motion: reduce) {
    :root {
      --duration-1: 0.01ms;
      --duration-2: 0.01ms;
      --duration-3: 0.01ms;
    }
  }

  /* ------------------------------------------------------------------------
     TIER 3 · COMPONENT — the only tokens component CSS reads.
     ------------------------------------------------------------------------ */
  :root {
    /* Focus ring */
    --focus-ring-width: var(--border-width-3);
    --focus-ring-offset: var(--border-width-3);
    --focus-ring-color: var(--color-focus);

    /* Link */
    --link-color: var(--color-text-accent);
    --link-color-hover: var(--color-text-primary);
    --link-underline-thickness: 0.08em;
    --link-underline-thickness-hover: 0.16em;

    /* Button */
    --button-height: var(--size-target);
    --button-padding-inline: var(--space-5);
    --button-radius: var(--radius-pill);
    --button-font-weight: var(--font-weight-semibold);
    --button-primary-bg: var(--color-bg-accent);
    --button-primary-bg-hover: var(--color-bg-accent-hover);
    --button-primary-text: var(--color-text-on-accent);
    --button-secondary-bg: var(--color-bg-surface-1);
    --button-secondary-bg-hover: var(--color-bg-accent-soft);
    --button-secondary-text: var(--color-text-primary);

    /* Tag */
    --tag-radius: var(--radius-pill);
    --tag-padding-inline: var(--space-3);
    --tag-bg: var(--color-bg-surface-1);
    --tag-text: var(--color-text-secondary);
    --tag-accent-bg: var(--color-bg-accent-soft);
    --tag-accent-text: var(--color-text-accent);
    --tag-support-bg: var(--color-bg-support-soft);
    --tag-support-text: var(--color-text-support);

    /* Card and panel */
    --card-bg: var(--color-bg-surface-2);
    --card-radius: var(--radius-card);
    --card-padding: var(--space-5);
    --panel-bg: var(--color-bg-surface-1);
    --panel-radius: var(--radius-panel);
    --panel-padding: clamp(var(--space-5), 4cqi, var(--space-7));

    /* Form field */
    --input-height: var(--size-target);
    --input-radius: var(--radius-control);
    --input-bg: var(--color-bg-surface-3);
    --input-border: var(--color-border-strong);
    --input-border-hover: var(--color-text-primary);

    /* Code */
    --code-bg: var(--color-bg-surface-1);
    --code-text: var(--color-text-primary);
    --code-comment: var(--color-text-muted);
    --code-keyword: var(--color-text-accent);
    --code-string: var(--color-text-support);
    --code-radius: var(--radius-card);
    --code-inline-radius: var(--radius-inline);

    /* Header */
    --header-height: var(--size-6);

    /* Prose */
    --prose-font-size: var(--font-size-prose);
    --prose-line-height: var(--line-height-prose);
    --prose-measure: var(--measure-prose);
    --prose-flow: var(--space-flow);
  }
}
