/*
 * Legal and utility route composition.
 * Load after tokens.css, base.css, components.css, and layout.css.
 * Policy copy remains flat, selectable, and in normal flow; only the separate
 * aria-hidden static motif may use decorative surface treatment.
 */

/* Shared route-shell hooks build on the canonical site-shell/header/footer. */
:where(.legal-page, .utility-page, .not-found-page) {
  min-inline-size: 0;
  max-inline-size: 100%;
  color: var(--color-text-primary);
  background-color: var(--color-surface-canvas);
}

:where(.legal-main, .utility-main, .not-found-main) {
  min-inline-size: 0;
  max-inline-size: 100%;
  padding-block: var(--layout-section-space);
}

:where(.legal-container, .policy-container) {
  inline-size: min(
    calc(100% - var(--layout-gutter) - var(--layout-gutter)),
    var(--reading-max)
  );
  max-inline-size: 100%;
  margin-inline: auto;
}

:where(.legal-header, .policy-header) {
  display: grid;
  gap: var(--space-3);
  min-inline-size: 0;
  max-inline-size: var(--reading-max);
  margin-inline: auto;
  margin-block-end: var(--space-7);
  padding-block-end: var(--space-6);
  border-block-end: var(--border-width) solid var(--color-border-subtle);
}

:where(.legal-eyebrow, .policy-label, .not-found__code) {
  inline-size: fit-content;
  max-inline-size: 100%;
  margin: 0;
  padding: var(--space-1) var(--space-3);
  border: var(--border-width) solid var(--color-brand-gold-700);
  border-radius: var(--radius-pill);
  color: var(--color-brand-gold-700);
  background-color: var(--motif-surface);
  font-size: var(--text-step--1);
  font-weight: 700;
  line-height: 1.35;
  letter-spacing: 0.08em;
  overflow-wrap: anywhere;
  text-transform: uppercase;
}

:where(.legal-title, .policy-title, .not-found__title) {
  max-inline-size: 100%;
  margin: 0;
  color: var(--color-brand-navy-900);
  overflow-wrap: anywhere;
  text-wrap: balance;
}

:where(.legal-summary, .policy-summary, .not-found__message) {
  max-inline-size: var(--reading-max);
  margin: 0;
  color: var(--color-text-secondary);
  font-size: var(--text-step-1);
  line-height: var(--line-body);
  overflow-wrap: anywhere;
}

:where(.legal-meta, .policy-meta) {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  max-inline-size: 100%;
  margin: 0;
  color: var(--color-text-secondary);
  font-size: var(--text-step--1);
  overflow-wrap: anywhere;
}

/*
 * Essential policy content is deliberately not a card, scene, overlay, or
 * transformed plane. These declarations keep it readable and selectable even
 * if optional enhancement classes are unavailable.
 */
:where(.legal-document, .policy-content, [data-legal-content]) {
  position: static;
  inset: auto;
  display: block;
  inline-size: 100%;
  max-inline-size: var(--reading-max);
  max-block-size: none;
  margin-inline: auto;
  border: 0;
  border-radius: 0;
  color: var(--color-text-primary);
  background: transparent;
  box-shadow: none;
  filter: none;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  perspective: none;
  transform: none;
  opacity: 1;
  isolation: auto;
  overflow: visible;
  overflow-wrap: break-word;
  user-select: text;
}

:where(.legal-document, .policy-content, [data-legal-content])
  > :where(section, .legal-section, .policy-section) {
  position: static;
  min-inline-size: 0;
  max-inline-size: 100%;
  padding-block-start: var(--space-6);
  border-block-start: var(--border-width) solid var(--color-border-subtle);
}

:where(.legal-document, .policy-content, [data-legal-content])
  > :where(section, .legal-section, .policy-section)
  + :where(section, .legal-section, .policy-section) {
  margin-block-start: var(--space-6);
}

:where(.legal-document, .policy-content, [data-legal-content])
  > :where(section, .legal-section, .policy-section):first-child {
  padding-block-start: 0;
  border-block-start: 0;
}

:where(.legal-document, .policy-content, [data-legal-content]) h2 {
  margin-block: 0 var(--space-4);
  color: var(--color-brand-navy-900);
  font-size: var(--text-step-2);
}

:where(.legal-document, .policy-content, [data-legal-content]) h3 {
  margin-block: var(--space-5) var(--space-3);
  color: var(--color-brand-navy-700);
  font-size: var(--text-step-1);
}

:where(.legal-document, .policy-content, [data-legal-content])
  :where(h4, h5, h6) {
  margin-block: var(--space-5) var(--space-2);
  color: var(--color-brand-navy-700);
  font-size: var(--text-step-0);
}

:where(.legal-document, .policy-content, [data-legal-content])
  :where(p, li, dt, dd, address, blockquote, code, a) {
  max-inline-size: 100%;
  overflow-wrap: anywhere;
  word-break: normal;
}

:where(.legal-document, .policy-content, [data-legal-content])
  :where(ul, ol) {
  max-inline-size: 100%;
  padding-inline-start: var(--space-6);
}

:where(.legal-document, .policy-content, [data-legal-content]) li + li {
  margin-block-start: var(--space-2);
}

:where(.legal-document, .policy-content, [data-legal-content]) li::marker,
:where(.legal-document, .policy-content, [data-legal-content]) dt {
  color: var(--color-brand-gold-700);
  font-weight: 700;
}

:where(.legal-document, .policy-content, [data-legal-content]) dd + dt {
  margin-block-start: var(--space-4);
}

:where(.legal-document, .policy-content, [data-legal-content]) blockquote {
  padding-inline-start: var(--space-4);
  border-inline-start: var(--focus-width) solid var(--color-brand-gold-700);
  color: var(--color-text-secondary);
}

:where(.legal-document, .policy-content, [data-legal-content])
  > :last-child,
:where(.legal-document, .policy-content, [data-legal-content])
  > :where(section, .legal-section, .policy-section):last-child
  > :last-child {
  margin-block-end: 0;
}

/* Policy and recovery links retain a visible affordance in every link state. */
:where(
  .legal-document,
  .policy-content,
  [data-legal-content],
  .not-found__copy
)
  a[href]:not(:where(.button, .action, .btn, [data-component="action"])):link {
  color: var(--color-brand-navy-700);
  font-weight: 600;
  text-decoration-line: underline;
  text-decoration-style: solid;
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.2em;
}

:where(
  .legal-document,
  .policy-content,
  [data-legal-content],
  .not-found__copy
)
  a[href]:not(:where(.button, .action, .btn, [data-component="action"])):visited {
  color: var(--color-brand-navy-900);
  text-decoration-style: double;
}

@media (hover: hover) and (pointer: fine) {
  :where(
    .legal-document,
    .policy-content,
    [data-legal-content],
    .not-found__copy
  )
    a[href]:not(:where(.button, .action, .btn, [data-component="action"])):hover {
    color: var(--color-brand-gold-700);
    text-decoration-thickness: 0.12em;
  }
}

:where(
  .legal-document,
  .policy-content,
  [data-legal-content],
  .not-found__copy
)
  a[href]:not(:where(.button, .action, .btn, [data-component="action"])):focus-visible {
  border-radius: var(--radius-control);
  outline: var(--focus-width) solid var(--color-focus-ring);
  outline-offset: var(--focus-offset);
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

:where(
  .legal-document,
  .policy-content,
  [data-legal-content],
  .not-found__copy
)
  a[href]:not(:where(.button, .action, .btn, [data-component="action"])):active {
  color: var(--color-brand-ink-950);
  text-decoration-style: double;
  text-decoration-thickness: 0.12em;
}

:where(
  .legal-document,
  .policy-content,
  [data-legal-content],
  .not-found__copy
)
  a[href]:not(:where(.button, .action, .btn, [data-component="action"])):where(
    [aria-current="page"],
    [aria-current="location"]
  ) {
  color: var(--color-brand-ink-950);
  background-color: var(--color-brand-gold-300);
  box-shadow: 0 var(--border-width) 0 currentColor;
}

:where(
  .legal-document,
  .policy-content,
  [data-legal-content],
  .not-found__copy
)
  a[href]:not(:where(.button, .action, .btn, [data-component="action"]))[aria-disabled="true"] {
  color: var(--color-text-secondary);
  text-decoration-style: dashed;
  cursor: not-allowed;
}

/*
 * Small static book/bookmark form. The root reserves its final dimensions,
 * owns all positioned decoration, and must be aria-hidden="true" in markup.
 */
:where(
  .legal-motif,
  .legal-decoration,
  .not-found__motif,
  [data-static-legal-motif]
) {
  --legal-motif-inline-size: 16rem;
  --legal-motif-block-size: 11rem;

  position: relative;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  inline-size: min(100%, var(--legal-motif-inline-size));
  block-size: var(--legal-motif-block-size);
  min-inline-size: 0;
  max-inline-size: 100%;
  max-block-size: var(--legal-motif-block-size);
  margin-inline: auto;
  contain: layout paint;
  contain-intrinsic-size: var(--legal-motif-inline-size)
    var(--legal-motif-block-size);
  isolation: isolate;
  overflow: clip;
  pointer-events: none;
  user-select: none;
  animation: none;
  filter: none;
  perspective: none;
  transform: none;
  transition: none;
}

:where(
  .legal-motif,
  .legal-decoration,
  .not-found__motif,
  [data-static-legal-motif]
)::before {
  content: "";
  position: absolute;
  inset-inline: var(--space-5);
  inset-block: var(--space-5);
  border: var(--border-width) solid var(--motif-edge);
  border-block-start: var(--space-1) solid var(--color-brand-navy-900);
  border-radius: var(--radius-card);
  background-color: var(--motif-surface);
  box-shadow: var(--shadow-raised), var(--shadow-inset);
}

:where(
  .legal-motif,
  .legal-decoration,
  .not-found__motif,
  [data-static-legal-motif]
)::after {
  content: "";
  position: absolute;
  inset-block-start: var(--space-5);
  inset-inline-end: var(--space-7);
  inline-size: var(--space-5);
  block-size: var(--space-7);
  border: var(--border-width) solid var(--color-brand-gold-700);
  border-block-start: 0;
  border-radius: 0 0 var(--radius-control) var(--radius-control);
  background-color: var(--color-brand-gold-300);
  box-shadow: var(--shadow-inset);
}

/* The 404 route uses the same shell and static motif without advanced assets. */
.not-found-main {
  display: grid;
  align-items: center;
}

:where(.not-found, .not-found__layout) {
  display: grid;
  grid-template-areas: "copy motif";
  grid-template-columns: minmax(0, 1fr) minmax(0, 16rem);
  align-items: center;
  gap: var(--space-7);
  inline-size: min(
    calc(100% - var(--layout-gutter) - var(--layout-gutter)),
    var(--content-max)
  );
  max-inline-size: 100%;
  margin-inline: auto;
}

.not-found__copy {
  grid-area: copy;
  display: grid;
  justify-items: start;
  gap: var(--space-4);
  min-inline-size: 0;
  max-inline-size: var(--reading-max);
}

.not-found__motif {
  grid-area: motif;
  justify-self: center;
}

.not-found__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  min-inline-size: 0;
  max-inline-size: 100%;
  margin-block-start: var(--space-2);
}

.not-found__actions > * {
  min-inline-size: 0;
  max-inline-size: 100%;
  overflow-wrap: anywhere;
}

/* Effective narrow layouts include phones and the required 200%-zoom case. */
@media (max-width: 40rem) {
  :where(.legal-main, .utility-main, .not-found-main) {
    padding-block: var(--space-7);
  }

  :where(.legal-header, .policy-header) {
    margin-block-end: var(--space-6);
    padding-block-end: var(--space-5);
  }

  :where(.legal-document, .policy-content, [data-legal-content])
    > :where(section, .legal-section, .policy-section) {
    padding-block-start: var(--space-5);
  }

  :where(.legal-document, .policy-content, [data-legal-content])
    > :where(section, .legal-section, .policy-section)
    + :where(section, .legal-section, .policy-section) {
    margin-block-start: var(--space-5);
  }

  :where(.not-found, .not-found__layout) {
    grid-template-areas:
      "copy"
      "motif";
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-6);
  }

  .not-found__copy {
    justify-items: center;
    margin-inline: auto;
    text-align: center;
  }

  .not-found__actions {
    justify-content: center;
    inline-size: 100%;
  }
}

@supports not (overflow: clip) {
  :where(
    .legal-motif,
    .legal-decoration,
    .not-found__motif,
    [data-static-legal-motif]
  ) {
    overflow: hidden;
  }
}
