/* ============================================================================
   base.css — reset, typography, layout primitives, @layer order.
   The cascade order is declared once here so component/page overrides are
   predictable and the old inline-style sprawl never comes back.
   ========================================================================== */

@layer reset, base, components, pages, utilities;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  * { margin: 0; padding: 0; }
  html, body { height: 100%; }
  body {
    font-family: var(--font-sans);
    font-size: var(--fs-md);
    line-height: var(--lh-normal);
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
  }
  img, svg, video { display: block; max-width: 100%; }
  button, input, select, textarea { font: inherit; color: inherit; }
  button { cursor: pointer; background: none; border: none; }
  a { color: inherit; text-decoration: none; }
  ul, ol { list-style: none; }
  :focus { outline: none; }
  /* Visible, consistent focus ring on real keyboard focus only. */
  :focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--r-sm); }
}

@layer base {
  /* Global default size for inline SVG icons. Context rules (.nav-item .ico,
     .btn .ico, …) override this; this just prevents an un-scoped .ico from
     ballooning to full size (the giant-magnifier bug). */
  .ico { width: 18px; height: 18px; flex: none; }
  h1, h2, h3, h4 { line-height: var(--lh-tight); font-weight: var(--fw-semibold); color: var(--text); }
  h1 { font-size: var(--fs-2xl); letter-spacing: -.01em; }
  h2 { font-size: var(--fs-xl); }
  h3 { font-size: var(--fs-lg); }
  p  { color: var(--text-2); }
  code, pre, kbd, samp { font-family: var(--font-mono); }

  /* Markdown answer body — rendered by marked into .md-body */
  .md-body { color: var(--text); line-height: var(--lh-relaxed); }
  .md-body > * + * { margin-top: var(--sp-3); }
  .md-body h1, .md-body h2, .md-body h3 { margin-top: var(--sp-5); }
  .md-body h1 { font-size: var(--fs-xl); }
  .md-body h2 { font-size: var(--fs-lg); }
  .md-body h3 { font-size: var(--fs-md); }
  .md-body ul, .md-body ol { padding-left: var(--sp-5); }
  .md-body ul { list-style: disc; }
  .md-body ol { list-style: decimal; }
  .md-body li { margin-top: var(--sp-1); }
  .md-body a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
  .md-body code {
    background: var(--surface-2); border: 1px solid var(--border);
    padding: .1em .35em; border-radius: var(--r-sm); font-size: .9em;
  }
  .md-body pre {
    background: var(--surface-2); border: 1px solid var(--border);
    padding: var(--sp-3); border-radius: var(--r-md); overflow-x: auto;
  }
  .md-body pre code { background: none; border: none; padding: 0; }
  .md-body blockquote {
    border-left: 3px solid var(--border-strong);
    padding-left: var(--sp-3); color: var(--text-2);
  }
  .md-body table { border-collapse: collapse; width: 100%; font-size: var(--fs-sm); }
  .md-body th, .md-body td { border: 1px solid var(--border); padding: var(--sp-2); text-align: left; }
}

@layer utilities {
  .visually-hidden {
    position: absolute !important; width: 1px; height: 1px;
    padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0);
    white-space: nowrap; border: 0;
  }
  .hidden { display: none !important; }
  .text-2 { color: var(--text-2); }
  .text-3 { color: var(--text-3); }
  .mono  { font-family: var(--font-mono); }
  .truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .row { display: flex; align-items: center; gap: var(--sp-2); }
  .grow { flex: 1 1 auto; min-width: 0; }
  .spacer { flex: 1 1 auto; }
}
