/* ==========================================================================
   Nova Link base: reset, document defaults, typography, focus, a11y helpers.
   Depends on tokens.css (layer order is declared there).
   ========================================================================== */

/* ---- Reset ----------------------------------------------------------------
   Modern, minimal: border-box everywhere, no default margins, media is block,
   form controls inherit typography. Lives in the lowest layer. */
@layer reset {
  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }

  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    tab-size: 4;
  }

  body,
  h1, h2, h3, h4, h5, h6,
  p, figure, blockquote, dl, dd,
  ol, ul, menu, fieldset, legend, pre {
    margin: 0;
  }

  ol, ul, menu {
    padding: 0;
  }

  fieldset {
    min-width: 0;
    padding: 0;
    border: 0;
  }

  img, svg, video, canvas, audio, iframe, embed, object {
    display: block;
    max-width: 100%;
  }

  img, video {
    height: auto;
  }

  /* Icons inside text keep their inline flow. */
  :where(p, span, b, small, a, button, label, li, em, strong) > svg {
    display: inline-block;
  }

  input, button, textarea, select, optgroup {
    margin: 0;
    font: inherit;
    letter-spacing: inherit;
    color: inherit;
  }

  button {
    padding: 0;
    border: 0;
    background: none;
    text-align: inherit;
    cursor: pointer;
  }

  button:disabled {
    cursor: not-allowed;
  }

  textarea {
    resize: vertical;
  }

  table {
    border-collapse: collapse;
    border-spacing: 0;
  }

  summary {
    cursor: pointer;
  }

  dialog {
    color: inherit;
  }

  :where(h1, h2, h3, h4, h5, h6, p, li, dd, figcaption, blockquote) {
    overflow-wrap: break-word;
  }
}

/* ---- Document defaults --------------------------------------------------- */
@layer base {
  html {
    background: var(--nv-bg);
    color: var(--nv-text);
    scrollbar-color: var(--nv-surface-4) transparent;
    scroll-padding-top: calc(var(--nv-nav-h) + var(--nv-space-4));
  }

  @media (prefers-reduced-motion: no-preference) {
    html:focus-within {
      scroll-behavior: smooth;
    }
  }

  body {
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--nv-bg);
    color: var(--nv-text);
    font-family: var(--nv-font-sans);
    font-size: var(--nv-fs-14);
    font-weight: var(--nv-fw-regular);
    line-height: var(--nv-lh-ui);
    font-feature-settings: "cv11", "ss01";
    font-synthesis-weight: none;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
  }

  /* Headings: Onest 500, balanced wrapping; hierarchy from size and colour, not weight (r181).
     Sizes are the app scale; the landing hero uses .display / --nv-fs-display. Slightly tight
     tracking from 22px only; smaller headings keep 0. The clamp reads the heading's own size, so a
     page that sets an h2/h3 to 16-18px gets 0 without its own override (1em >= 22px -> -.01em, else 0). */
  h1, h2, h3, h4, h5, h6 {
    color: var(--nv-text);
    font-family: var(--nv-font-display);
    font-weight: var(--nv-fw-medium);
    line-height: var(--nv-lh-snug);
    letter-spacing: clamp(var(--nv-tracking-tight), calc((21.5px - 1em) * 1000), 0px);
    text-wrap: balance;
  }

  h1 { font-size: var(--nv-fs-36); line-height: var(--nv-lh-tight); }
  h2 { font-size: var(--nv-fs-28); }
  h3 { font-size: var(--nv-fs-22); }
  h4 { font-size: var(--nv-fs-18); letter-spacing: 0; }
  h5, h6 { font-size: var(--nv-fs-16); letter-spacing: 0; }

  p {
    text-wrap: pretty;
  }

  small {
    font-size: var(--nv-fs-12);
  }

  b, strong {
    font-weight: var(--nv-fw-semibold);
  }

  /* Links: the accent ink on dark, underline appears on hover (one ink, no second amber). */
  a {
    color: var(--nv-accent-text);
    text-decoration: none;
    text-underline-offset: .2em;
    text-decoration-thickness: 1px;
    transition: color var(--nv-dur-1) var(--nv-ease);
  }

  a:hover {
    color: var(--nv-accent-text);
    text-decoration-line: underline;
  }

  /* Inline links inside running text are always underlined (not colour-only). */
  :where(p, li, dd, small, .prose) > a:not([class]) {
    text-decoration-line: underline;
    text-decoration-color: color-mix(in srgb, currentColor 40%, transparent);
  }

  :where(p, li, dd, small, .prose) > a:not([class]):hover {
    text-decoration-color: currentColor;
  }

  code, kbd, samp, pre {
    font-family: var(--nv-font-mono);
    font-size: .92em;
  }

  code {
    padding: .1em .38em;
    border: 1px solid var(--nv-line);
    border-radius: var(--nv-r-xs);
    background: var(--nv-surface-2);
    color: var(--nv-text);
    overflow-wrap: anywhere;
  }

  pre {
    overflow: auto;
    padding: var(--nv-space-4);
    border: 1px solid var(--nv-line);
    border-radius: var(--nv-r-md);
    background: var(--nv-bg-deep);
    line-height: 1.55;
  }

  pre code {
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
  }

  hr {
    height: 1px;
    margin: var(--nv-space-6) 0;
    border: 0;
    background: var(--nv-line);
  }

  ::placeholder {
    color: var(--nv-text-3);
    opacity: 1;
  }

  /* Safety net for icons without explicit size. Decorative inline SVGs
     (aria-hidden) and SVG <img>s without width/height would otherwise grow
     to the container width. Any component or surface rule overrides this. */
  svg[aria-hidden="true"]:not([width]),
  img[src$=".svg"]:not([width], [height]) {
    flex: none;
    width: 1.25em;
    height: 1.25em;
  }

  ::selection {
    background: rgba(255, 122, 26, .38);
    color: #fff;
  }

  /* ---- Focus ---------------------------------------------------------------
     Two-tone ring: a dark gap (box-shadow) right outside the element and an
     amber outline outside that. Visible on the dark canvas AND on orange
     fills. Mouse clicks do not show it (focus-visible only). */
  :focus {
    outline: none;
  }

  :focus-visible {
    outline: 2px solid var(--nv-focus);
    outline-offset: 2px;
    box-shadow: 0 0 0 2px var(--nv-focus-gap);
  }

  /* ---- Scrollbars (thin, warm, unobtrusive) ------------------------------ */
  ::-webkit-scrollbar {
    width: 10px;
    height: 10px;
  }

  ::-webkit-scrollbar-track {
    background: transparent;
  }

  ::-webkit-scrollbar-thumb {
    border: 3px solid transparent;
    border-radius: var(--nv-r-round);
    background: var(--nv-surface-3) padding-box;
  }

  ::-webkit-scrollbar-thumb:hover {
    background: var(--nv-surface-4) padding-box;
  }

  ::-webkit-scrollbar-corner {
    background: transparent;
  }

  /* ---- Prose: flow spacing for long-form text (legal, FAQ, help) --------- */
  .prose {
    color: var(--nv-text-2);
    font-size: var(--nv-fs-16);
    line-height: var(--nv-lh-body);
  }

  .prose > * + * {
    margin-top: 1em;
  }

  .prose :where(h1, h2, h3, h4) {
    color: var(--nv-text);
  }

  .prose > :where(h2, h3) {
    margin-top: 1.8em;
  }

  .prose :where(ul, ol) {
    padding-left: 1.4em;
  }

  .prose li + li {
    margin-top: .4em;
  }

  .prose li::marker {
    color: var(--nv-text-3);
  }

  .prose strong {
    color: var(--nv-text);
  }

  /* ---- Skip link: off-screen until focused ------------------------------- */
  .skip-link,
  .legal-skip {
    position: fixed;
    top: var(--nv-space-3);
    left: var(--nv-space-3);
    z-index: var(--nv-z-boot);
    padding: var(--nv-space-3) var(--nv-space-4);
    border-radius: var(--nv-r-control);
    background: var(--nv-accent);
    color: var(--nv-on-accent);
    font-weight: var(--nv-fw-medium);
    text-decoration: none;
    transform: translateY(calc(-100% - 24px));
    transition: transform var(--nv-dur-2) var(--nv-ease);
  }

  .skip-link:focus,
  .legal-skip:focus {
    color: var(--nv-on-accent);
    transform: none;
  }
}

/* ---- Utilities: last layer, so they beat components and surfaces --------- */
@layer utilities {
  /* The hidden attribute and the legacy .hidden class (app.js toggles it on
     #marketing / #studio) always win over component display values. */
  [hidden],
  .hidden {
    display: none;
  }

  /* Visually hidden, still announced by screen readers. */
  .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
  }

  .text-muted { color: var(--nv-text-2); }
  .text-subtle { color: var(--nv-text-3); }
  .text-accent { color: var(--nv-accent-text); }
  .mono, .tabular { font-variant-numeric: tabular-nums; }
  .mono { font-family: var(--nv-font-mono); }
  .truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* r180: iOS zooms the page into any field under 16px on focus. Page sheets (@layer surfaces) set
     13-15px on some fields and always beat the components layer, so the touch floor lives here.
     No field is drawn larger than 16px on touch, so nothing shrinks. */
  @media (pointer: coarse) {
    :where(input:not([type="checkbox"], [type="radio"], [type="range"], [type="color"], [type="file"], [type="submit"], [type="button"], [type="reset"], [type="image"], [type="hidden"]), select, textarea) {
      font-size: var(--nv-fs-16);
    }
  }

  /* Respect reduced motion everywhere (utilities beat component animations). */
  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      animation-duration: .01ms;
      animation-iteration-count: 1;
      transition-duration: .01ms;
      scroll-behavior: auto;
    }
  }
}
