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

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

  html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
  }

  body {
    margin: 0;
  }

  h1,
  h2,
  h3,
  h4,
  p,
  figure,
  blockquote,
  dl,
  dd {
    margin: 0;
  }

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

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

  [hidden] {
    display: none !important;
  }

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

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

    /* Surfaces */
    --bg: light-dark(#fafafa, #09090b);
    --surface: light-dark(#ffffff, #111114);
    --surface-subtle: light-dark(#f4f4f5, #18181b);
    --surface-code: light-dark(#f1f3f5, #141418);
    --surface-elevated: light-dark(#ffffff, #16161b);

    /* Typography colors (WCAG AA+ verified) */
    --text: light-dark(#09090b, #f4f4f5);
    --text-muted: light-dark(#52525b, #a1a1aa);
    --text-faint: light-dark(#62626e, #94949e);

    /* Borders */
    --border: light-dark(#e4e4e7, #27272a);
    --border-strong: light-dark(#d4d4d8, #3f3f46);

    /* Brand Accent (Precision Cobalt) */
    --accent: light-dark(#3b49df, #6e7bf2);
    --accent-hover: light-dark(#2e3ac4, #8893f8);
    --accent-btn: light-dark(#3b49df, #4854e0);
    --accent-btn-hover: light-dark(#2e3ac4, #3d48d1);
    --accent-subtle: light-dark(rgba(59, 73, 223, 0.08), rgba(110, 123, 242, 0.14));
    --accent-border: light-dark(rgba(59, 73, 223, 0.24), rgba(110, 123, 242, 0.34));
    --accent-contrast: #ffffff;

    /* Status */
    --ok: light-dark(#0b6b45, #34d399);
    --ok-subtle: light-dark(rgba(11, 107, 69, 0.08), rgba(52, 211, 153, 0.12));
    --ok-border: light-dark(rgba(11, 107, 69, 0.22), rgba(52, 211, 153, 0.28));

    /* Grid Overlay */
    --grid-line: light-dark(rgba(9, 9, 11, 0.045), rgba(244, 244, 245, 0.045));

    /* Typography Scale */
    --font-sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", system-ui, sans-serif;
    --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo, Consolas, monospace;

    --text-hero: clamp(2rem, 1.45rem + 2.4vw, 3.25rem);
    --text-h2: clamp(1.375rem, 1.15rem + 1vw, 1.9375rem);
    --text-h3: clamp(1.0625rem, 1rem + 0.3vw, 1.1875rem);
    --text-lead: clamp(1.03125rem, 0.96rem + 0.35vw, 1.1875rem);

    /* Spacing & Radii */
    --container-max: 70rem;
    --gutter: clamp(1rem, 3vw, 2rem);
    --section-gap: clamp(3.25rem, 6vw, 5.5rem);
    --radius-sm: 0.375rem;
    --radius-md: 0.625rem;
    --radius-lg: 0.875rem;
    --radius-full: 9999px;

    /* Elevation */
    --shadow-sm: light-dark(
      0 1px 2px rgba(9, 9, 11, 0.04),
      0 1px 2px rgba(0, 0, 0, 0.35)
    );
    --shadow-lg: light-dark(
      0 20px 50px -12px rgba(9, 9, 11, 0.16),
      0 24px 60px -12px rgba(0, 0, 0, 0.65)
    );

    /* View Transition click coords */
    --vt-x: 50%;
    --vt-y: 0%;
  }

  :root[data-theme="light"] {
    color-scheme: light;
  }

  :root[data-theme="dark"] {
    color-scheme: dark;
  }
}

@layer base {
  body {
    font-family: var(--font-sans);
    font-size: 1rem;
    line-height: 1.6;
    color: var(--text);
    background-color: var(--bg);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
  }

  main {
    flex: 1 0 auto;
    position: relative;
  }

  h1,
  h2,
  h3 {
    color: var(--text);
    font-weight: 600;
    letter-spacing: -0.02em;
    line-height: 1.18;
  }

  h1 {
    font-size: var(--text-hero);
    letter-spacing: -0.028em;
    line-height: 1.09;
  }

  h2 {
    font-size: var(--text-h2);
  }

  h3 {
    font-size: var(--text-h3);
    letter-spacing: -0.014em;
  }

  p {
    color: var(--text-muted);
  }

  a {
    color: var(--accent);
    text-decoration-thickness: 1px;
    text-underline-offset: 0.2em;
    transition: color 140ms ease;

    &:hover {
      color: var(--accent-hover);
    }
  }

  code {
    font-family: var(--font-mono);
    font-size: 0.875em;
    background-color: var(--surface-code);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.1em 0.38em;
    color: var(--text);
    word-break: break-word;
  }

  :focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }

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

@layer layout {
  .container {
    width: min(100% - 2 * var(--gutter), var(--container-max));
    margin-inline: auto;
  }

  .skip-link {
    position: absolute;
    left: -9999px;
    top: 0.5rem;
    z-index: 1000;
    padding: 0.625rem 1rem;
    background: var(--text);
    color: var(--bg);
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    text-decoration: none;

    &:focus {
      left: 0.75rem;
    }
  }

  .site-header {
    position: sticky;
    top: 0;
    z-index: 40;
    border-bottom: 1px solid var(--border);
    background-color: color-mix(in srgb, var(--bg) 86%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);

    & .header-inner {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      justify-content: space-between;
      gap: 0.75rem 1.25rem;
      padding-block: 0.875rem;
    }

    & .brand {
      display: inline-flex;
      align-items: center;
      gap: 0.625rem;
      text-decoration: none;
      color: var(--text);
      font-weight: 600;
      font-size: 0.9375rem;
      letter-spacing: -0.015em;
      white-space: nowrap;

      & svg {
        width: 1.75rem;
        height: 1.75rem;
        flex-shrink: 0;
      }

      &:hover {
        color: var(--text);
      }
    }

    & .header-controls {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      gap: 0.5rem 1rem;
    }

    & .primary-nav {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      gap: 0.25rem;

      & a {
        color: var(--text-muted);
        text-decoration: none;
        font-size: 0.875rem;
        font-weight: 500;
        padding: 0.4375rem 0.6875rem;
        border-radius: var(--radius-sm);
        transition: color 140ms ease, background-color 140ms ease;

        &:hover {
          color: var(--text);
          background-color: var(--surface-subtle);
        }

        &[aria-current="page"] {
          color: var(--text);
          background-color: var(--surface-subtle);
          font-weight: 600;
        }
      }
    }
  }

  .section {
    padding-block: var(--section-gap);
    border-top: 1px solid var(--border);
  }

  .section-header {
    max-width: 44rem;
    margin-bottom: clamp(1.75rem, 3.5vw, 2.75rem);

    & .eyebrow {
      display: inline-flex;
      align-items: center;
      gap: 0.45rem;
      font-family: var(--font-mono);
      font-size: 0.75rem;
      font-weight: 500;
      text-transform: uppercase;
      letter-spacing: 0.08em;
      color: var(--accent);
      margin-bottom: 0.625rem;
    }

    & p {
      margin-top: 0.75rem;
      font-size: 1.03125rem;
    }
  }

  .site-footer {
    border-top: 1px solid var(--border);
    background-color: var(--surface);
    padding-block: 2.5rem;

    & .footer-top {
      display: flex;
      flex-wrap: wrap;
      align-items: flex-start;
      justify-content: space-between;
      gap: 2rem;
      padding-bottom: 2rem;
      border-bottom: 1px solid var(--border);
    }

    & .footer-brand {
      max-width: 28rem;

      & .brand-row {
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
        font-weight: 600;
        color: var(--text);
        text-decoration: none;
        margin-bottom: 0.625rem;
      }

      & p {
        font-size: 0.875rem;
        color: var(--text-muted);
      }
    }

    & .footer-nav {
      display: flex;
      flex-wrap: wrap;
      gap: 1.5rem 2.5rem;

      & .footer-col {
        & h2 {
          font-size: 0.75rem;
          font-family: var(--font-mono);
          text-transform: uppercase;
          letter-spacing: 0.08em;
          color: var(--text-faint);
          margin-bottom: 0.625rem;
        }

        & ul {
          display: grid;
          gap: 0.45rem;
        }

        & a {
          font-size: 0.875rem;
          color: var(--text-muted);
          text-decoration: none;

          &:hover {
            color: var(--text);
            text-decoration: underline;
          }
        }
      }
    }

    & .footer-bottom {
      padding-top: 1.5rem;
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      justify-content: space-between;
      gap: 0.75rem 1.5rem;
      font-size: 0.8125rem;
      color: var(--text-faint);

      & p {
        color: var(--text-faint);
      }

      & a {
        color: var(--text-muted);
      }
    }
  }
}

@layer components {
  /* Theme Switcher */
  .theme-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.6875rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background-color: var(--surface);
    color: var(--text-muted);
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: border-color 140ms ease, color 140ms ease, background-color 140ms ease;

    &:hover {
      border-color: var(--border-strong);
      color: var(--text);
      background-color: var(--surface-subtle);
    }

    & svg {
      width: 0.9375rem;
      height: 0.9375rem;
    }
  }

  /* Buttons */
  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.0625rem;
    border-radius: var(--radius-md);
    font-size: 0.9375rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease, transform 100ms ease;

    &:active {
      transform: translateY(1px);
    }
  }

  .btn-primary {
    background-color: var(--accent-btn);
    color: var(--accent-contrast);

    &:hover {
      background-color: var(--accent-btn-hover);
      color: var(--accent-contrast);
    }
  }

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

    &:hover {
      background-color: var(--surface-subtle);
      color: var(--text);
    }
  }

  .btn-ghost {
    background-color: transparent;
    border-color: var(--border);
    color: var(--text-muted);

    &:hover {
      background-color: var(--surface-subtle);
      color: var(--text);
    }
  }

  /* Hero */
  .hero {
    position: relative;
    padding-block: clamp(3.25rem, 7vw, 5.75rem) clamp(2.75rem, 5vw, 4.25rem);
    overflow-x: clip;

    &::before {
      content: "";
      position: absolute;
      inset: 0;
      z-index: -1;
      pointer-events: none;
      background-image:
        linear-gradient(to right, var(--grid-line) 1px, transparent 1px),
        linear-gradient(to bottom, var(--grid-line) 1px, transparent 1px);
      background-size: 32px 32px;
      mask-image: radial-gradient(ellipse 75% 80% at 50% 10%, #000 35%, transparent 100%);
      -webkit-mask-image: radial-gradient(ellipse 75% 80% at 50% 10%, #000 35%, transparent 100%);
    }

    & .status-pill {
      display: inline-flex;
      align-items: center;
      gap: 0.5rem;
      padding: 0.3125rem 0.75rem;
      border-radius: var(--radius-full);
      border: 1px solid var(--ok-border);
      background-color: var(--ok-subtle);
      color: var(--ok);
      font-family: var(--font-mono);
      font-size: 0.75rem;
      font-weight: 500;
      margin-bottom: 1.375rem;

      & .pulse-dot {
        width: 0.45rem;
        height: 0.45rem;
        border-radius: 50%;
        background-color: currentColor;
      }
    }

    & .hero-title {
      max-width: 19ch;
    }

    & .hero-lead {
      max-width: 58ch;
      margin-top: 1.25rem;
      font-size: var(--text-lead);
      color: var(--text-muted);
    }

    & .hero-actions {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      gap: 0.75rem;
      margin-top: 1.875rem;
    }

    & .hero-legal-links {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      gap: 0.5rem 1.25rem;
      margin-top: 1.375rem;
      font-size: 0.875rem;
      color: var(--text-faint);

      & a {
        color: var(--text-muted);
        font-weight: 500;
      }
    }

    & .spec-strip {
      margin-top: clamp(2.25rem, 4.5vw, 3.25rem);
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(min(100%, 15.5rem), 1fr));
      gap: 1px;
      background-color: var(--border);
      border: 1px solid var(--border);
      border-radius: var(--radius-lg);
      overflow: hidden;
      box-shadow: var(--shadow-sm);

      & .spec-cell {
        background-color: var(--surface);
        padding: 1.125rem 1.25rem;
        container-type: inline-size;

        & .spec-label {
          font-family: var(--font-mono);
          font-size: 0.75rem;
          text-transform: uppercase;
          letter-spacing: 0.06em;
          color: var(--text-faint);
          margin-bottom: 0.3rem;
        }

        & .spec-value {
          font-size: 0.9375rem;
          font-weight: 600;
          color: var(--text);
          font-variant-numeric: tabular-nums;
        }

        & .spec-meta {
          font-size: 0.8125rem;
          color: var(--text-muted);
          margin-top: 0.25rem;
        }
      }
    }
  }

  /* Container-Queried Capability Cards */
  .bento-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 19rem), 1fr));
    gap: 1.25rem;
  }

  .card-shell {
    container-type: inline-size;
    container-name: capability-card;
  }

  .capability-card {
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1.5rem;
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition: border-color 160ms ease;

    &:hover {
      border-color: var(--border-strong);
    }

    & .card-head {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 0.75rem;
    }

    & .card-icon {
      width: 2.25rem;
      height: 2.25rem;
      display: grid;
      place-items: center;
      border-radius: var(--radius-md);
      background-color: var(--accent-subtle);
      border: 1px solid var(--accent-border);
      color: var(--accent);
      flex-shrink: 0;
    }

    & .card-tag {
      font-family: var(--font-mono);
      font-size: 0.75rem;
      color: var(--text-faint);
      border: 1px solid var(--border);
      border-radius: var(--radius-full);
      padding: 0.15rem 0.55rem;
    }

    & .card-body {
      display: grid;
      gap: 0.5rem;
    }

    & .card-list {
      margin-top: auto;
      padding-top: 0.875rem;
      border-top: 1px solid var(--border);
      display: grid;
      gap: 0.375rem;
      font-size: 0.84375rem;
      color: var(--text-muted);

      & li {
        display: flex;
        align-items: baseline;
        gap: 0.5rem;

        &::before {
          content: "—";
          color: var(--accent);
          font-family: var(--font-mono);
        }
      }
    }
  }

  @container capability-card (min-width: 30rem) {
    .capability-card {
      display: grid;
      grid-template-columns: 1fr auto;
      align-items: start;

      & .card-head {
        grid-column: 1 / -1;
      }

      & .card-list {
        border-top: 0;
        border-left: 1px solid var(--border);
        padding-top: 0;
        padding-left: 1.25rem;
        margin-top: 0;
      }
    }
  }

  /* Interactive System Architecture */
  .arch-workspace {
    container-type: inline-size;
    container-name: arch-box;
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
  }

  .arch-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.875rem 1.25rem;
    border-bottom: 1px solid var(--border);
    background-color: var(--surface-subtle);

    & .arch-tablist {
      display: flex;
      flex-wrap: wrap;
      gap: 0.375rem;
    }

    & .arch-tab {
      display: inline-flex;
      align-items: center;
      gap: 0.375rem;
      padding: 0.4rem 0.6875rem;
      border-radius: var(--radius-sm);
      border: 1px solid var(--border);
      background-color: var(--surface);
      color: var(--text-muted);
      font-family: var(--font-mono);
      font-size: 0.75rem;
      font-weight: 500;
      cursor: pointer;
      transition: background-color 140ms ease, color 140ms ease, border-color 140ms ease;

      &:hover {
        color: var(--text);
        border-color: var(--border-strong);
      }

      &[aria-pressed="true"] {
        background-color: var(--accent-subtle);
        border-color: var(--accent);
        color: var(--text);
      }
    }
  }

  .arch-content {
    display: grid;
    grid-template-columns: 1fr;
  }

  @container arch-box (min-width: 54rem) {
    .arch-content {
      grid-template-columns: minmax(0, 1.45fr) minmax(19rem, 1fr);
    }
  }

  .arch-diagram-wrap {
    padding: clamp(1rem, 2.5vw, 1.75rem);
    background-color: var(--surface);
    overflow-x: auto;
  }

  .arch-svg {
    width: 100%;
    min-width: 36rem;
    height: auto;
    font-family: var(--font-sans);

    & .svg-boundary {
      fill: var(--surface-subtle);
      stroke: var(--border-strong);
      stroke-dasharray: 4 4;
    }

    & .svg-boundary-label {
      fill: var(--text-faint);
      font-family: var(--font-mono);
      font-size: 10px;
      letter-spacing: 0.06em;
      text-transform: uppercase;
    }

    & .svg-link {
      stroke: var(--border-strong);
      stroke-width: 1.5;
      fill: none;
    }

    & .svg-flow {
      stroke: var(--accent);
      stroke-width: 1.75;
      stroke-dasharray: 5 5;
      fill: none;
    }

    & .svg-flow-label {
      fill: var(--text-faint);
      font-family: var(--font-mono);
      font-size: 9.5px;

      &.is-accent {
        fill: var(--accent);
        font-weight: 600;
      }
    }

    & .svg-node {
      cursor: pointer;

      & rect.node-box {
        fill: var(--surface-elevated);
        stroke: var(--border-strong);
        stroke-width: 1.35;
        transition: stroke 140ms ease, fill 140ms ease;
      }

      & .node-id {
        fill: var(--accent);
        font-family: var(--font-mono);
        font-size: 10px;
        font-weight: 600;
      }

      & .node-title {
        fill: var(--text);
        font-size: 12.5px;
        font-weight: 600;
      }

      & .node-sub {
        fill: var(--text-muted);
        font-size: 10.5px;
      }

      &:hover rect.node-box {
        stroke: var(--accent);
      }

      &.is-active rect.node-box {
        stroke: var(--accent);
        stroke-width: 2;
        fill: var(--accent-subtle);
      }
    }
  }

  .arch-inspector {
    border-top: 1px solid var(--border);
    padding: 1.375rem;
    background-color: var(--surface-subtle);
    display: flex;
    flex-direction: column;
    gap: 1rem;

    & .inspector-badge {
      display: inline-flex;
      align-self: flex-start;
      align-items: center;
      gap: 0.4rem;
      font-family: var(--font-mono);
      font-size: 0.75rem;
      color: var(--accent);
      background-color: var(--accent-subtle);
      border: 1px solid var(--accent-border);
      padding: 0.2rem 0.55rem;
      border-radius: var(--radius-sm);
    }

    & .inspector-dl {
      display: grid;
      gap: 0.75rem;

      & div {
        border-top: 1px solid var(--border);
        padding-top: 0.625rem;
      }

      & dt {
        font-family: var(--font-mono);
        font-size: 0.72rem;
        text-transform: uppercase;
        letter-spacing: 0.06em;
        color: var(--text-faint);
        margin-bottom: 0.2rem;
      }

      & dd {
        font-size: 0.875rem;
        color: var(--text);
      }
    }

    & .inspector-actions {
      margin-top: auto;
      padding-top: 0.5rem;
      display: flex;
      flex-wrap: wrap;
      gap: 0.5rem;
    }
  }

  @container arch-box (min-width: 54rem) {
    .arch-inspector {
      border-top: 0;
      border-left: 1px solid var(--border);
    }
  }

  /* Governance Grid */
  .governance-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr));
    gap: 1rem;
  }

  .governance-item {
    padding: 1.25rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background-color: var(--surface);

    & .gov-code {
      font-family: var(--font-mono);
      font-size: 0.75rem;
      color: var(--ok);
      margin-bottom: 0.5rem;
    }

    & h3 {
      margin-bottom: 0.45rem;
    }

    & p {
      font-size: 0.90625rem;
    }
  }

  .compliance-callout {
    margin-top: 1.5rem;
    padding: 1.25rem 1.5rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--accent-border);
    background-color: var(--accent-subtle);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;

    & p {
      color: var(--text);
      font-size: 0.9375rem;
      max-width: 58ch;
    }

    & .callout-links {
      display: flex;
      flex-wrap: wrap;
      gap: 0.625rem;
    }
  }

  /* FAQ Details/Summary */
  .faq-list {
    display: grid;
    gap: 0.75rem;
    max-width: 56rem;
  }

  .faq-item {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    transition: border-color 140ms ease;

    &:hover,
    &[open] {
      border-color: var(--border-strong);
    }

    & summary {
      list-style: none;
      cursor: pointer;
      padding: 1.0625rem 1.25rem;
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 1rem;
      font-weight: 600;
      font-size: 1rem;
      color: var(--text);

      &::-webkit-details-marker {
        display: none;
      }

      & .faq-chevron {
        width: 1.125rem;
        height: 1.125rem;
        flex-shrink: 0;
        color: var(--text-muted);
        transition: transform 180ms ease;
      }
    }

    &[open] summary .faq-chevron {
      transform: rotate(180deg);
      color: var(--accent);
    }

    & .faq-answer {
      padding: 0 1.25rem 1.1875rem;
      border-top: 1px solid var(--border);
      padding-top: 0.875rem;
      font-size: 0.9375rem;
      color: var(--text-muted);
    }
  }

  /* Legal / Document Pages */
  .doc-layout {
    padding-block: clamp(2.5rem, 5vw, 4rem);
    display: grid;
    grid-template-columns: 1fr;
    gap: 2.5rem;
    align-items: start;
  }

  @media (min-width: 58rem) {
    .doc-layout {
      grid-template-columns: 15.5rem minmax(0, 1fr);
    }
  }

  .doc-toc {
    padding: 1.125rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background-color: var(--surface);

    @media (min-width: 58rem) {
      position: sticky;
      top: 5rem;
    }

    & .toc-title {
      font-family: var(--font-mono);
      font-size: 0.75rem;
      text-transform: uppercase;
      letter-spacing: 0.08em;
      color: var(--text-faint);
      margin-bottom: 0.75rem;
    }

    & ol {
      display: grid;
      gap: 0.45rem;
    }

    & a {
      display: block;
      font-size: 0.84375rem;
      color: var(--text-muted);
      text-decoration: none;
      padding: 0.2rem 0;

      &:hover {
        color: var(--accent);
      }
    }
  }

  .legal-doc {
    min-width: 0;
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: clamp(1.5rem, 4vw, 3rem);
    box-shadow: var(--shadow-sm);

    & .doc-meta {
      display: flex;
      flex-wrap: wrap;
      gap: 0.5rem 1.25rem;
      font-family: var(--font-mono);
      font-size: 0.78125rem;
      color: var(--text-faint);
      margin-bottom: 1rem;
    }

    & .doc-lead {
      margin-top: 1rem;
      font-size: var(--text-lead);
      padding-bottom: 1.5rem;
      border-bottom: 1px solid var(--border);
    }

    & section {
      padding-top: 1.75rem;
      margin-top: 1.75rem;
      border-top: 1px solid var(--border);
      scroll-margin-top: 5.5rem;

      &:first-of-type {
        border-top: 0;
        margin-top: 0.5rem;
      }

      & h2 {
        font-size: clamp(1.1875rem, 1.08rem + 0.5vw, 1.4375rem);
        margin-bottom: 0.75rem;
      }

      & h3 {
        font-size: 1rem;
        margin-top: 1.125rem;
        margin-bottom: 0.45rem;
      }

      & p + p {
        margin-top: 0.75rem;
      }

      & ul,
      & ol {
        margin-top: 0.625rem;
        display: grid;
        gap: 0.5rem;
        padding-left: 1.25rem;
        color: var(--text-muted);
      }

      & ul {
        list-style: disc;
      }

      & ol {
        list-style: decimal;
      }
    }

    & .policy-highlight {
      margin-top: 1rem;
      padding: 1.125rem 1.25rem;
      border-radius: var(--radius-md);
      border: 1px solid var(--ok-border);
      background-color: var(--ok-subtle);

      & p {
        color: var(--text);
        font-size: 0.9375rem;
      }
    }

    & .spec-table-wrap {
      margin-top: 1rem;
      overflow-x: auto;
      border: 1px solid var(--border);
      border-radius: var(--radius-md);
    }

    & table {
      width: 100%;
      border-collapse: collapse;
      font-size: 0.875rem;
      text-align: left;

      & th,
      & td {
        padding: 0.75rem 1rem;
        border-bottom: 1px solid var(--border);
        vertical-align: top;
      }

      & th {
        font-family: var(--font-mono);
        font-size: 0.75rem;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: var(--text-faint);
        background-color: var(--surface-subtle);
      }

      & tr:last-child td {
        border-bottom: 0;
      }

      & td {
        color: var(--text-muted);

        &:first-child {
          color: var(--text);
          font-weight: 500;
        }
      }
    }
  }

  /* Native <dialog> & <dialog popover> */
  .native-dialog,
  .native-popover {
    margin: auto;
    width: min(calc(100% - 2rem), 40rem);
    max-height: min(88dvh, 46rem);
    padding: 0;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    background-color: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-lg);
    overflow: hidden;

    & .dialog-shell {
      display: flex;
      flex-direction: column;
      max-height: min(88dvh, 46rem);
    }

    & .dialog-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 1rem;
      padding: 1.125rem 1.375rem;
      border-bottom: 1px solid var(--border);
      background-color: var(--surface-subtle);

      & h2 {
        font-size: 1.0625rem;
      }
    }

    & .dialog-close {
      display: grid;
      place-items: center;
      width: 2rem;
      height: 2rem;
      border-radius: var(--radius-sm);
      border: 1px solid var(--border);
      background-color: var(--surface);
      color: var(--text-muted);
      cursor: pointer;

      &:hover {
        color: var(--text);
        border-color: var(--border-strong);
      }
    }

    & .dialog-body {
      padding: 1.375rem;
      overflow-y: auto;
      display: grid;
      gap: 1rem;
      font-size: 0.9375rem;
    }

    & .dialog-kv {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
      gap: 0.75rem;

      & .kv-box {
        padding: 0.75rem;
        border: 1px solid var(--border);
        border-radius: var(--radius-md);
        background-color: var(--surface-subtle);

        & span {
          display: block;
          font-family: var(--font-mono);
          font-size: 0.72rem;
          text-transform: uppercase;
          color: var(--text-faint);
          margin-bottom: 0.25rem;
        }

        & strong {
          font-size: 0.875rem;
          color: var(--text);
        }
      }
    }

    & .flow-steps {
      display: grid;
      gap: 0.625rem;

      & li {
        display: grid;
        grid-template-columns: 2rem 1fr;
        gap: 0.75rem;
        align-items: start;
        padding: 0.75rem;
        border: 1px solid var(--border);
        border-radius: var(--radius-md);
        background-color: var(--surface-subtle);

        & .step-num {
          font-family: var(--font-mono);
          font-size: 0.75rem;
          font-weight: 600;
          color: var(--accent);
          padding-top: 0.1rem;
        }

        & strong {
          display: block;
          font-size: 0.875rem;
          color: var(--text);
          margin-bottom: 0.15rem;
        }

        & span {
          font-size: 0.84375rem;
          color: var(--text-muted);
        }
      }
    }

    & .dialog-footer {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      justify-content: space-between;
      gap: 0.75rem;
      padding: 1rem 1.375rem;
      border-top: 1px solid var(--border);
      background-color: var(--surface-subtle);
    }
  }

  .native-dialog::backdrop,
  .native-popover::backdrop {
    background-color: rgba(9, 9, 11, 0.56);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
  }
}

@layer animations {
  @keyframes settle-in {
    from {
      opacity: 0.15;
      transform: translateY(14px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  @keyframes packet-flow {
    to {
      stroke-dashoffset: -20;
    }
  }

  @media (prefers-reduced-motion: no-preference) {
    .arch-svg .svg-flow {
      animation: packet-flow 1.4s linear infinite;
    }

    @supports (animation-timeline: view()) {
      .reveal-card {
        animation: settle-in linear both;
        animation-timeline: view();
        animation-range: entry 0% entry 85%;
      }
    }

    /* Native View Transitions API Theme Reveal */
    ::view-transition-old(root),
    ::view-transition-new(root) {
      animation: none;
      mix-blend-mode: normal;
    }

    ::view-transition-new(root) {
      animation: theme-reveal 360ms cubic-bezier(0.22, 1, 0.36, 1) both;
    }

    @keyframes theme-reveal {
      from {
        clip-path: circle(0% at var(--vt-x) var(--vt-y));
      }
      to {
        clip-path: circle(150% at var(--vt-x) var(--vt-y));
      }
    }

    /* Native Dialog / Popover entry transitions */
    .native-dialog[open],
    .native-popover:popover-open {
      opacity: 1;
      transform: translateY(0) scale(1);
      transition: opacity 180ms ease, transform 180ms ease, display 180ms allow-discrete, overlay 180ms allow-discrete;
    }

    @starting-style {
      .native-dialog[open],
      .native-popover:popover-open {
        opacity: 0;
        transform: translateY(8px) scale(0.985);
      }
    }
  }
}

@layer utilities {
  .mono {
    font-family: var(--font-mono);
  }

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