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

@layer tokens {
  :root {
    color-scheme: dark;

    /* Tier 1 — Locked DM/T palette (Anodized Graphite + Factory Ochre) */
    --raw-graphite-950: #0D0E0F;
    --raw-graphite-900: #121315;
    --raw-graphite-850: #181A1D;
    --raw-graphite-800: #222529;

    --raw-aluminum-100: #EAECEF;
    --raw-aluminum-200: #CFD4DC;
    --raw-aluminum-300: #9EA5AE;
    --raw-aluminum-500: #7C848E;

    --raw-ochre-400: #ECC052;
    --raw-ochre-500: #E2AB2B;
    --raw-ochre-600: #C8941F;

    --raw-emerald-500: #4CC38A;
    --raw-crimson-500: #E5484D;

    /* Tier 2 — Semantic surfaces & text roles */
    --surface-deepest: var(--raw-graphite-950);
    --surface-base: var(--raw-graphite-900);
    --surface-card: var(--raw-graphite-850);
    --surface-raised: var(--raw-graphite-800);

    --text-primary: var(--raw-aluminum-100);
    --text-secondary: var(--raw-aluminum-300);
    --text-muted: var(--raw-aluminum-500);

    --accent: var(--raw-ochre-500);
    --accent-hover: var(--raw-ochre-400);
    --accent-active: var(--raw-ochre-600);
    --text-on-accent: var(--raw-graphite-950);
    --accent-subtle: rgba(226, 171, 43, 0.12);

    --status-positive: var(--raw-emerald-500);
    --status-negative: var(--raw-crimson-500);

    /* Tier 3 — Quiet hairlines + WCAG 1.4.11 (>=3:1) control borders */
    --border-hairline: rgba(234, 236, 239, 0.11);
    --border-strong: rgba(234, 236, 239, 0.24);
    --border-control: rgba(234, 236, 239, 0.38);
    --border-crosshair: rgba(234, 236, 239, 0.38);
    --highlight-top: inset 0 1px 0 rgba(234, 236, 239, 0.10);

    /* Surface interaction tints (centralized tokens) */
    --surface-hover-tint: rgba(234, 236, 239, 0.035);
    --border-dashed-tint: rgba(234, 236, 239, 0.08);
    --overlay-backdrop: rgba(13, 14, 15, 0.86);
    --overlay-menu-backdrop: rgba(13, 14, 15, 0.72);
    --overlay-pill-bg: rgba(13, 14, 15, 0.88);
    --accent-surface-tint: rgba(226, 171, 43, 0.06);
    --accent-border-tint: rgba(226, 171, 43, 0.48);

    /* Typography — Locked Martian Mono (h1/h2 @ wdth 94, specs @ wdth 100) + Onest (UI/body) */
    --font-display: "Martian Mono", "Cascadia Mono", "Consolas", ui-monospace, monospace;
    --font-body: "Onest", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --font-mono: "Martian Mono", "Cascadia Mono", "Consolas", ui-monospace, monospace;

    --weight-regular: 400;
    --weight-medium: 500;
    --weight-semibold: 600;

    --text-meta: 0.75rem;
    --text-caption: 0.875rem;
    --text-body: 1rem;
    --text-lead: 1.125rem;
    --text-section: clamp(1.375rem, 1.05rem + 1.05vw, 2rem);
    --text-hero: clamp(1.75rem, 1.15rem + 2.1vw, 3.125rem);

    --leading-tight: 1.08;
    --leading-snug: 1.18;
    --leading-body: 1.55;

    /* 4px grid scale in rem */
    --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-16: 4rem;
    --space-20: 5rem;
    --space-24: 6rem;
    --space-32: 8rem;

    /* Crisp machined radii per BRAND.md (2 / 4 / 6px) */
    --radius-tag: 2px;
    --radius-control: 4px;
    --radius-card: 4px;
    --radius-panel: 6px;

    /* Single easing curve across all interactions per BRAND.md */
    --ease-craft: cubic-bezier(0.22, 1, 0.36, 1);
    --duration-fast: 140ms;
    --duration-base: 180ms;
    --duration-enter: 360ms;

    --container-max: 76rem;
    --gutter-inline: clamp(1rem, 0.65rem + 2vw, 2.5rem);
    --target-size: 24px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
  }

  @media (pointer: coarse) {
    :root {
      --target-size: 44px;
    }
  }

  @media (prefers-contrast: more) {
    :root {
      --border-hairline: rgba(234, 236, 239, 0.24);
      --border-strong: rgba(234, 236, 239, 0.44);
      --text-muted: #B6BDC6;
    }
  }

  @media (forced-colors: active) {
    :root {
      --surface-deepest: Canvas;
      --surface-base: Canvas;
      --surface-card: Canvas;
      --surface-raised: Canvas;
      --text-primary: CanvasText;
      --text-secondary: CanvasText;
      --text-muted: GrayText;
      --accent: Highlight;
      --text-on-accent: HighlightText;
      --border-hairline: ButtonBorder;
      --border-strong: CanvasText;
    }
  }
}

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

  :where(body, h1, h2, h3, h4, p, figure, dl, dd) {
    margin: 0;
  }

  :where(ul, ol) {
    margin: 0;
    padding-inline-start: 0;
    list-style: none;
  }

  :where(img, svg, video, picture) {
    display: block;
    max-inline-size: 100%;
  }

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

@layer base {
  html {
    background-color: var(--surface-deepest);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    accent-color: var(--accent);
    scrollbar-color: var(--raw-graphite-800) var(--surface-deepest);
    scrollbar-width: thin;
    scroll-padding-top: calc(4.25rem + var(--safe-top));
  }

  :where(a, code) {
    overflow-wrap: anywhere;
  }

  :where(input, textarea) {
    caret-color: var(--accent);
  }

  body {
    min-block-size: 100dvh;
    background-color: var(--surface-deepest);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: var(--text-body);
    font-weight: var(--weight-regular);
    line-height: var(--leading-body);
    overflow-wrap: break-word;
    text-align: start;
  }

  :where(h1, h2) {
    font-family: var(--font-display);
    font-weight: var(--weight-medium);
    font-variation-settings: "wdth" 94;
    line-height: var(--leading-snug);
    color: var(--text-primary);
    text-wrap: balance;
  }

  @media (max-width: 47.99rem) {
    :where(h1, h2) {
      font-variation-settings: "wdth" 86;
    }
  }

  :where(h3) {
    font-family: var(--font-body);
    font-weight: var(--weight-medium);
    line-height: var(--leading-snug);
    color: var(--text-primary);
    text-wrap: balance;
    letter-spacing: 0;
  }

  h1 {
    font-size: var(--text-hero);
    line-height: var(--leading-tight);
    letter-spacing: -0.04em;
  }

  h2 {
    font-size: var(--text-section);
    letter-spacing: -0.03em;
  }

  :where(p, li) {
    text-wrap: pretty;
  }

  :where(p) {
    max-inline-size: 62ch;
  }

  :where(a) {
    color: inherit;
    text-decoration-color: var(--border-strong);
    text-underline-offset: 0.24em;
  }

  :where(a, button, input, textarea, select, summary):focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }

  ::selection {
    background-color: var(--accent);
    color: var(--text-on-accent);
  }
}

@layer components {
  /* Factory Ochre #E2AB2B primary action per BRAND.md (9.4:1 contrast with #0D0E0F) */
  .btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-block-size: 2.75rem;
    padding-block: 0.625rem;
    padding-inline: var(--space-5);
    border: 1px solid transparent;
    border-radius: var(--radius-control);
    background-color: var(--accent);
    color: var(--text-on-accent);
    font-family: var(--font-body);
    font-size: 0.9375rem;
    font-weight: var(--weight-medium);
    line-height: 1.2;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color var(--duration-fast) var(--ease-craft),
                transform var(--duration-fast) var(--ease-craft);
  }

  .btn-primary:hover:not(:disabled) {
    background-color: var(--accent-hover);
  }

  .btn-primary:active:not(:disabled) {
    background-color: var(--accent-active);
    transform: scale(0.985);
  }

  .btn-primary:disabled {
    opacity: 0.4;
    cursor: not-allowed;
  }

  .btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-block-size: 2.75rem;
    padding-block: 0.625rem;
    padding-inline: var(--space-5);
    border: 1px solid var(--border-control);
    border-radius: var(--radius-control);
    background-color: var(--surface-card);
    color: var(--text-primary);
    box-shadow: var(--highlight-top);
    font-family: var(--font-body);
    font-size: 0.9375rem;
    font-weight: var(--weight-medium);
    line-height: 1.2;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: border-color var(--duration-fast) var(--ease-craft),
                background-color var(--duration-fast) var(--ease-craft),
                transform var(--duration-fast) var(--ease-craft);
  }

  .btn-secondary:hover:not(:disabled) {
    background-color: var(--surface-raised);
    border-color: var(--text-secondary);
  }

  .btn-secondary:active:not(:disabled) {
    transform: scale(0.985);
  }
}

@layer utilities {
  [hidden] {
    display: none !important;
  }

  .font-mono-spec {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
  }

  .tabular-nums {
    font-variant-numeric: tabular-nums;
  }
}

@media (prefers-reduced-motion: no-preference) {
  @view-transition {
    navigation: auto;
  }
}
