/* ============================================================
   DS23 CSS ENGINE (Canonical Standalone)
   ============================================================ */

@layer base, tokens, layout, components, pages;
@layer tokens {
  :root {
    --ds-version: "1.1.0";
    interpolate-size: allow-keywords;
    --font-heading: 'Inter Tight', system-ui, sans-serif;
    --font-body: 'Inter Tight', system-ui, sans-serif;
    --ds-edge: 40px;
    --ds-gap: 20px;
    --ds-section-py: 80px;
    --ds-default-row-gap: 40px;
    --ds-card-padding: 40px;
    --ds-hero-py: 160px;
    --ds-tight-py: 40px;
    --ds-spacious-py: 160px;
    --fs-hero: 13.75rem;
    --fs-display: 8.75rem;
    --fs-h1: 2.625rem;
    --fs-h2: 1.75rem;
    --fs-h3: 1.5rem;
    --fs-lead: 1.125rem;
    --fs-body: 1rem;
    --fs-caption: 0.75rem;
    --ds-space-1: 10px;
    --ds-space-2: 20px;
    --ds-space-3: 40px;
    --ds-space-4: 80px;
    --ds-space-5: 160px;
    --lh-hero: 1;
    --fw-hero: 700;
    --ls-hero: -0.03em;
    --lh-display: 1;
    --fw-display: 700;
    --ls-display: -0.03em;
    --lh-h1: 1.1;
    --fw-h1: 700;
    --ls-h1: -0.02em;
    --lh-h2: 1.2;
    --fw-h2: 700;
    --ls-h2: -0.01em;
    --lh-h3: 1.25;
    --fw-h3: 700;
    --ls-h3: -0.01em;
    --lh-lead: 1.5;
    --fw-lead: 400;
    --ls-lead: 0em;
    --lh-body: 1.6;
    --fw-body: 400;
    --ls-body: 0em;
    --lh-caption: 1.4;
    --fw-caption: 400;
    --ls-caption: 0.02em;
    --btn-min-height: 44px;
    --btn-py: 10px;
    --btn-px: 20px;
    --btn-gap: 10px;
    --control-radius: 999px;
    --border-width: 1px;
    --focus-width: 2px;
    --focus-offset: 3px;
    --text-measure: 66ch;
    --duration: 0.22s;
    --btn-font-weight: 700;
    --btn-line-height: 1.25;
    --underline-offset: 0.15em;
    --disabled-opacity: 0.6;
    --color-bg: #FFFFFF;
    --color-bg-alt: #FAFAF8;
    --color-fg: #000000;
    --color-muted: #666666;
    --color-subtle: #666666;
    --color-border: #E5E5E5;
    --color-border-subtle: #F0F0F0;
    --color-control-border: #666666;
    --color-surface: #FFFFFF;
    --color-surface-hover: #F2F2F2;
  }
  .inv, [data-ds-theme=dark] {
    --color-bg: #0A0A0A;
    --color-bg-alt: #141414;
    --color-fg: #FFFFFF;
    --color-muted: #D8D8D8;
    --color-subtle: #D8D8D8;
    --color-border: #262626;
    --color-border-subtle: #262626;
    --color-control-border: #D8D8D8;
    --color-surface: #141414;
    --color-surface-hover: #1F1F1F;
    color-scheme: dark;
  }
  .theme-light, [data-ds-theme=light] {
    --color-bg: #FFFFFF;
    --color-bg-alt: #FAFAF8;
    --color-fg: #000000;
    --color-muted: #666666;
    --color-subtle: #666666;
    --color-border: #E5E5E5;
    --color-border-subtle: #F0F0F0;
    --color-control-border: #666666;
    --color-surface: #FFFFFF;
    --color-surface-hover: #F2F2F2;
    color-scheme: light;
  }
  @media (max-width: 1024px) {
    :root {
    --ds-edge: 40px;
    --ds-gap: 20px;
    --ds-section-py: 80px;
    --ds-default-row-gap: 40px;
    --ds-card-padding: 20px;
    --ds-hero-py: 80px;
    --ds-tight-py: 40px;
    --ds-spacious-py: 80px;
    --fs-hero: 8rem;
    --fs-display: 5.5rem;
    --fs-h1: 2.25rem;
    --fs-h2: 1.625rem;
    --fs-h3: 1.375rem;
    --fs-lead: 1.125rem;
    --fs-body: 1rem;
    --fs-caption: 0.75rem;
    }
  }
  @media (max-width: 640px) {
    :root {
    --ds-edge: 20px;
    --ds-gap: 20px;
    --ds-section-py: 40px;
    --ds-default-row-gap: 20px;
    --ds-card-padding: 20px;
    --ds-hero-py: 80px;
    --ds-tight-py: 20px;
    --ds-spacious-py: 80px;
    --fs-hero: 3.5rem;
    --fs-display: 2.75rem;
    --fs-h1: 2rem;
    --fs-h2: 1.5rem;
    --fs-h3: 1.375rem;
    --fs-lead: 1.125rem;
    --fs-body: 1rem;
    --fs-caption: 0.75rem;
    }
  }
}
/* Authored behavior. Numeric design values live in tokens.json. */
@layer base {
  *, *::before, *::after { box-sizing: border-box; }
  :where(body, h1, h2, h3, h4, h5, h6, p, figure, blockquote, dl, dd, ul, ol) { margin: 0; }
  html { font-size: 100%; scroll-behavior: smooth; }
  body {
    background: var(--color-bg); color: var(--color-fg);
    font-family: var(--font-body); font-size: var(--fs-body); line-height: var(--lh-body);
    overflow-wrap: anywhere;
  }
  :where(img, video, canvas, svg) { display: block; max-inline-size: 100%; block-size: auto; }
  :where(picture) { display: block; }
  :where(a) { color: inherit; text-underline-offset: var(--underline-offset); }
  :where(button, input, textarea, select) { font: inherit; color: inherit; }
  :where(button) { cursor: pointer; }
  :where(input, textarea, select) { max-inline-size: 100%; }
  :where(h1, h2, h3, h4, h5, h6, p) { text-wrap: wrap; }
  :where(pre) { overflow: auto; max-inline-size: 100%; }
  :focus-visible { outline: var(--focus-width) solid var(--color-fg); outline-offset: var(--focus-offset); }
  [hidden] { display: none; }
  @media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
  }
}

@layer layout {
  .section {
    padding-inline: var(--ds-edge); padding-block: var(--ds-section-py);
    background: var(--color-bg); color: var(--color-fg);
  }
  .inv, .theme-light, [data-ds-theme] { background: var(--color-bg); color: var(--color-fg); }
  .section--alt { background: var(--color-bg-alt); }
  .section--tight { padding-block: var(--ds-tight-py); }
  .section--spacious { padding-block: var(--ds-spacious-py); }
  .section--hero { padding-block: var(--ds-hero-py); }
  .section--screen { min-block-size: 100svh; display: flex; flex-direction: column; justify-content: space-between; gap: var(--ds-space-4); }
  .row {
    --ds-cols: 4; --ds-anchor-span: 2; --ds-narrative-start: 3;
    --ds-row-gap: var(--ds-default-row-gap);
    display: grid; grid-template-columns: repeat(var(--ds-cols), minmax(0, 1fr));
    column-gap: var(--ds-gap); row-gap: var(--ds-row-gap); align-items: start;
    min-inline-size: 0;
  }
  .row-4 { --ds-cols: 4; --ds-anchor-span: 2; --ds-narrative-start: 3; }
  .row-8 { --ds-cols: 8; --ds-anchor-span: 4; --ds-narrative-start: 5; }
  .row > *, .subgrid > *, .row-item > *, .cards > * { min-inline-size: 0; }
  .col-1 { grid-column-end: span 1; }
  .col-2 { grid-column-end: span 2; }
  .col-3 { grid-column-end: span 3; }
  .col-4 { grid-column-end: span 4; }
  .col-5 { grid-column-end: span 5; }
  .col-6 { grid-column-end: span 6; }
  .col-7 { grid-column-end: span 7; }
  .col-8 { grid-column-end: span 8; }
  .col-start-1 { grid-column-start: 1; }
  .col-start-2 { grid-column-start: 2; }
  .col-start-3 { grid-column-start: 3; }
  .col-start-4 { grid-column-start: 4; }
  .col-start-5 { grid-column-start: 5; }
  .col-start-6 { grid-column-start: 6; }
  .col-start-7 { grid-column-start: 7; }
  .col-start-8 { grid-column-start: 8; }
  .col-full { grid-column: 1 / -1; }
  .col-anchor { grid-column: 1 / span var(--ds-anchor-span); }
  .col-narrative { grid-column: var(--ds-narrative-start) / -1; }
  /* v1 subgrids are full-width only; partial grids use an explicit nested .row. */
  .subgrid, .row-item {
    grid-column: 1 / -1; display: grid; grid-template-columns: subgrid;
    column-gap: var(--ds-gap); row-gap: var(--ds-row-gap, var(--ds-default-row-gap)); min-inline-size: 0;
  }
  @supports not (grid-template-columns: subgrid) {
    .subgrid, .row-item { grid-template-columns: repeat(var(--ds-cols, 4), minmax(0, 1fr)); }
  }
  .gap-1 { --ds-row-gap: var(--ds-space-1); }
  .gap-2 { --ds-row-gap: var(--ds-space-2); }
  .gap-3 { --ds-row-gap: var(--ds-space-3); }
  .gap-4 { --ds-row-gap: var(--ds-space-4); }
  .gap-5 { --ds-row-gap: var(--ds-space-5); }
  .flow-1, .flow-2, .flow-3, .flow-4, .flow-5 { display: flex; flex-direction: column; min-inline-size: 0; }
  .flow-1 { gap: var(--ds-space-1); }
  .flow-2 { gap: var(--ds-space-2); }
  .flow-3 { gap: var(--ds-space-3); }
  .flow-4 { gap: var(--ds-space-4); }
  .flow-5 { gap: var(--ds-space-5); }
  .cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--ds-space-2); }
  .cluster--between { justify-content: space-between; }
  .cards { --ds-card-cols: 2; display: grid; grid-template-columns: repeat(var(--ds-card-cols), minmax(0, 1fr)); gap: var(--ds-gap); }
  .cards-4 { --ds-card-cols: 4; }
  .cards-2 { --ds-card-cols: 2; }
  .measure { max-inline-size: var(--text-measure); }
  .divider { inline-size: 100%; block-size: var(--border-width); margin: 0; border: 0; background: var(--color-border); grid-column: 1 / -1; }
  .media { margin: 0; }
  .media > img, .media > video { inline-size: 100%; }
  .scroll-region { overflow: auto; max-inline-size: 100%; }
  @media (max-width: 1024px) {
    .col-anchor, .col-narrative { grid-column: 1 / -1; }
    .cards-4 { --ds-card-cols: 2; }
  }
  @media (max-width: 640px) {
    .row, .row-4, .row-8 { --ds-cols: 1; --ds-anchor-span: 1; --ds-narrative-start: 1; }
    .row > *, .subgrid > *, .row-item > * { grid-column: 1 / -1; }
    .cards, .cards-2, .cards-4 { --ds-card-cols: 1; }
    .cards--mobile-2 { --ds-card-cols: 2; }
  }
}

@layer components {
  h1, .t-h1 { font-family: var(--font-heading); font-size: var(--fs-h1); font-weight: var(--fw-h1); line-height: var(--lh-h1); letter-spacing: var(--ls-h1); }
  h2, .t-h2 { font-family: var(--font-heading); font-size: var(--fs-h2); font-weight: var(--fw-h2); line-height: var(--lh-h2); letter-spacing: var(--ls-h2); }
  h3, .t-h3 { font-family: var(--font-heading); font-size: var(--fs-h3); font-weight: var(--fw-h3); line-height: var(--lh-h3); letter-spacing: var(--ls-h3); }
  .t-hero { font-family: var(--font-heading); font-size: var(--fs-hero); font-weight: var(--fw-hero); line-height: var(--lh-hero); letter-spacing: var(--ls-hero); }
  .t-display { font-family: var(--font-heading); font-size: var(--fs-display); font-weight: var(--fw-display); line-height: var(--lh-display); letter-spacing: var(--ls-display); }
  .t-body, p { font-size: var(--fs-body); font-weight: var(--fw-body); line-height: var(--lh-body); letter-spacing: var(--ls-body); }
  .t-lead { font-size: var(--fs-lead); font-weight: var(--fw-lead); line-height: var(--lh-lead); letter-spacing: var(--ls-lead); }
  .t-caption { font-size: var(--fs-caption); font-weight: var(--fw-caption); line-height: var(--lh-caption); letter-spacing: var(--ls-caption); color: var(--color-subtle); }
  .t-muted { color: var(--color-muted); }
  .t-mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
  .t-balance { text-wrap: balance; }
  .t-pretty { text-wrap: pretty; }
  .t-right { text-align: right; }
  .btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: var(--btn-gap); min-block-size: var(--btn-min-height); max-inline-size: 100%;
    padding: var(--btn-py) var(--btn-px); border: var(--border-width) solid transparent;
    border-radius: var(--control-radius); font: inherit; font-size: var(--fs-body);
    font-weight: var(--btn-font-weight); line-height: var(--btn-line-height); text-align: center; text-decoration: none;
    white-space: normal; overflow-wrap: anywhere; cursor: pointer;
    transition: background-color var(--duration), color var(--duration);
  }
  .btn-primary { background: var(--color-fg); color: var(--color-bg); border-color: var(--color-fg); }
  .btn-outline { background: transparent; color: var(--color-fg); border-color: var(--color-control-border); }
  .btn-outline:hover { background: var(--color-surface-hover); }
  .btn-link { color: var(--color-fg); text-decoration: underline; text-underline-offset: var(--underline-offset); font-weight: var(--btn-font-weight); }
  .btn:disabled { cursor: not-allowed; opacity: var(--disabled-opacity); }
  .card { padding: var(--ds-card-padding); background: var(--color-surface); border: var(--border-width) solid var(--color-border); display: flex; flex-direction: column; gap: var(--ds-space-2); }
  .row-item { align-items: start; padding-block: var(--ds-space-2); border-block-end: var(--border-width) solid var(--color-border); }
  .field { display: flex; flex-direction: column; gap: var(--ds-space-1); }
  .field :where(input, textarea, select) { inline-size: 100%; min-block-size: var(--btn-min-height); padding: var(--ds-space-1); border: var(--border-width) solid var(--color-control-border); background: var(--color-surface); }
  .field [aria-invalid=true] { border-style: dashed; }
  .field ::placeholder { color: var(--color-muted); opacity: 1; }
  .skip-link { position: fixed; inset-block-start: var(--ds-space-1); inset-inline-start: var(--ds-space-1); z-index: 100; padding: var(--ds-space-1); background: var(--color-bg); color: var(--color-fg); transform: translateY(-200%); }
  .skip-link:focus { transform: translateY(0); }
}
