/* policy-page.css — style of the standalone policy pages (scripts/legal-page.ts, PLAN T-10). The pages
   cannot load the app's hashed CSS bundle, so they load tokens.css (design/tokens.css + the generated
   accent, written by generate.ts) first — one token source for the app and its pages (PLAN T-12).
   theme-init.js sets the saved theme (data-theme) before the first paint; without JavaScript the system
   theme applies. The look follows the forge template's page.css: frosted header, one text card. */
@layer tokens, base, layout, components, overrides;

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

  html {
    background: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font-sans);
    -webkit-text-size-adjust: 100%;
  }

  body {
    margin: 0;
    min-height: 100dvh;
    line-height: var(--leading-normal);
    -webkit-font-smoothing: antialiased;
  }

  /* Links without underline: accent + semibold, the weight is the non-colour cue (WCAG 1.4.1, G182);
     Moni 2026-11-06, DECISIONS 2026-11-19 (PLAN T-12). */
  a {
    color: var(--color-accent-text);
    font-weight: var(--weight-semibold);
    text-decoration: none;
  }

  :focus-visible {
    outline: var(--focus-ring-width) solid var(--color-focus);
    outline-offset: var(--focus-ring-offset);
  }

  /* Smooth navigation to and from the app (the app opts in too). */
  @view-transition {
    navigation: auto;
  }

  @media (prefers-reduced-motion: reduce) {
    @view-transition {
      navigation: none;
    }
  }
}

@layer layout {
  .policy-header {
    position: sticky;
    top: 0;
    /* The brand lines up with the text card below (same width as .policy). */
    padding: var(--safe-top) max(calc(var(--space-4) + var(--safe-right)), calc((100% - var(--measure)) / 2)) 0 max(calc(var(--space-4) + var(--safe-left)), calc((100% - var(--measure)) / 2));
    background: var(--header-bg);
    -webkit-backdrop-filter: var(--header-blur);
    backdrop-filter: var(--header-blur);

    @supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
      background: var(--color-bg);
    }
  }

  .policy {
    width: min(100% - 2 * var(--space-4), var(--measure));
    margin: var(--space-6) auto;
  }

  .policy-footer {
    width: min(100% - 2 * var(--space-4), var(--measure));
    margin: 0 auto;
    padding-bottom: calc(var(--space-8) + var(--safe-bottom));
    color: var(--color-text-secondary);
    font-size: var(--text-sm);
    text-align: center;

    & p {
      margin: 0;
    }
  }
}

@layer components {
  /* || Components: brand link (back to the app) */
  .policy-brand {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    min-height: var(--header-height);
    color: var(--color-text);
    font-size: var(--text-base);

    & img {
      border-radius: var(--radius-sm);
    }
  }

  /* || Components: policy text card */
  .policy-body {
    padding: clamp(var(--space-5), 4vw, var(--space-10));
    border-radius: var(--radius-lg);
    background: var(--color-surface);
    box-shadow: var(--shadow-1);
    font-size: var(--text-base);
    /* Long URLs and emails never overflow the card (Moni 2026-11-08). */
    overflow-wrap: anywhere;

    & h1 {
      margin: 0;
      font-size: var(--text-2xl);
      line-height: var(--leading-tight);
      letter-spacing: var(--tracking-tight);
      text-wrap: balance;
    }

    & h2 {
      margin: var(--space-8) 0 0;
      font-size: var(--text-lg);
      line-height: var(--leading-tight);
      letter-spacing: var(--tracking-tight);
      text-wrap: balance;
    }

    & li + li {
      margin-top: var(--space-2);
    }

    & code {
      padding: 0 var(--space-1);
      border-radius: var(--radius-sm);
      background: var(--color-fill);
      font-family: var(--font-mono);
      font-size: var(--text-sm);
    }
  }

  .policy-updated {
    margin-top: var(--space-2);
    color: var(--color-text-secondary);
    font-size: var(--text-sm);
  }

  /* || Components: footer links (same order as the app footer, WCAG 3.2.6) */
  .policy-nav {
    margin-bottom: var(--space-2);
    /* Inline links (2.5.8 inline exception); the line height spaces the rows for touch. */
    line-height: var(--tap-target);
  }
}

@layer overrides {
  @media print {
    .policy-header,
    .policy-nav {
      display: none;
    }

    .policy-body {
      box-shadow: none;
    }
  }
}
