/* HackerSEC site.css: loaded on every page.
   Layer order is declared once, here. Later layers beat earlier ones regardless of specificity.
   Nav breakpoint is 48em; assets/js/nav.js must use the same value.
   Rule: no ancestor of a fixed/absolute element may use transform, filter, backdrop-filter or contain. */
@layer reset, base, layout, components, templates, utilities;

/* Self-hosted variable fonts. Add the .woff2 files to /assets/fonts/; system fallbacks apply until then. */
@font-face { font-family: "Inter"; src: url("/assets/fonts/inter-variable.woff2") format("woff2"); font-weight: 100 900; font-display: swap; }
@font-face { font-family: "Space Grotesk"; src: url("/assets/fonts/space-grotesk-variable.woff2") format("woff2"); font-weight: 300 700; font-display: swap; }
@font-face { font-family: "JetBrains Mono"; src: url("/assets/fonts/jetbrains-mono-variable.woff2") format("woff2"); font-weight: 100 800; font-display: swap; }

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  body, h1, h2, h3, p, ul, ol, figure { margin: 0; }
  ul, ol { padding: 0; }
  img, svg { display: block; max-width: 100%; }
  button { font: inherit; color: inherit; }
}

@layer base {
  :root {
    color-scheme: dark;

    /* primitives */
    --void: #0a0e17;
    --panel: #111927;
    --panel-2: #17212f;
    --ink: #e7ecf5;
    --slate: #7e8ca3;
    --slate-dim: #7a889f;   /* raised from #566073 (about 3:1); about 5:1 on --void, 4.5:1+ on --panel */
    --blue: #3e8ef7;
    --cyan: #29d9e8;
    --amber: #f5a93f;

    /* semantic roles: components use these, never primitives */
    --bg: var(--void);
    --surface: var(--panel);
    --surface-2: var(--panel-2);
    --border: rgb(255 255 255 / 0.1);
    --border-strong: rgb(255 255 255 / 0.2);
    --text: var(--ink);
    --text-muted: var(--slate);
    --text-faint: var(--slate-dim);
    --accent: var(--cyan);
    --link: var(--blue);
    --focus: var(--cyan);
    --on-accent: #071018;

    /* type */
    --font-body: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-display: "Space Grotesk", "Inter", system-ui, sans-serif;
    --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    --fs-sm: 0.875rem;
    --fs-base: 1rem;
    --fs-lg: 1.25rem;
    --fs-h2: clamp(1.5rem, 1.2rem + 1.5vw, 2rem);
    --fs-hero: clamp(2.75rem, 1.5rem + 6vw, 5rem);

    /* space, widths, shape, layers */
    --space-1: 0.5rem;
    --space-2: 1rem;
    --space-3: 1.5rem;
    --space-4: 2.5rem;
    --space-5: 4rem;
    --gutter: clamp(1rem, 4vw, 2rem);
    --measure: 40rem;
    --container: 72rem;
    --header-h: 4rem;
    --radius-sm: 6px;
    --radius-pill: 999px;
    --z-header: 10;
    --z-skip: 100;
  }

  html { scroll-padding-top: 1rem; }
  @media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }
  @media (min-width: 48em) { html { scroll-padding-top: calc(var(--header-h) + 1rem); } }

  body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    font-size: var(--fs-base);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
  }
  h1, h2, h3 { font-family: var(--font-display); line-height: 1.15; text-wrap: balance; }
  a { color: var(--link); text-underline-offset: 0.2em; }
  ::selection { background: var(--blue); color: var(--void); }
  :focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
  main:focus { outline: none; }
}

@layer layout {
  .container { width: 100%; max-width: var(--container); margin-inline: auto; padding-inline: var(--gutter); }
  /* Limit line length without shrinking or re-centring the container. */
  .prose-narrow > * { max-width: var(--measure); }
  .prose-narrow > * + * { margin-top: var(--space-2); }
}

@layer components {
  .skip-link {
    position: absolute; left: var(--space-1); top: -4rem; z-index: var(--z-skip);
    padding: 0.75rem 1rem; background: var(--surface-2); color: var(--text);
    border: 1px solid var(--accent); border-radius: var(--radius-sm);
  }
  .skip-link:focus { top: var(--space-1); }

  /* ----- header and primary nav (mobile first) ----- */
  .site-header { background: var(--bg); border-bottom: 1px solid var(--border); }
  .site-header__inner { position: relative; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; }
  .brand {
    display: inline-flex; align-items: center; min-height: var(--header-h);
    font-family: var(--font-display); font-size: var(--fs-lg); font-weight: 600;
    color: var(--text); text-decoration: none;
  }
  .brand__bracket { font-family: var(--font-mono); font-weight: 500; color: var(--accent); }

  .site-nav { flex: 1 0 100%; }
  .site-nav__toggle {
    position: absolute; top: calc((var(--header-h) - 2.75rem) / 2); right: var(--gutter);
    min-height: 2.75rem; padding: 0 1rem; cursor: pointer;
    background: transparent; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  }
  .site-nav__toggle[aria-expanded="true"] { background: var(--surface-2); border-color: var(--accent); }

  /* Without JS the list is a wrapped row; JS adds .is-enhanced and turns it into a disclosure. */
  .site-nav__list { display: flex; flex-wrap: wrap; gap: 0.25rem; list-style: none; padding-bottom: var(--space-1); }
  .site-nav.is-enhanced .site-nav__list { flex-direction: column; flex-wrap: nowrap; gap: 0; border-top: 1px solid var(--border); padding-block: var(--space-1); }
  .site-nav__list a {
    display: block; padding: 0.625rem 0.75rem; border-radius: var(--radius-sm);
    color: var(--text-muted); font-weight: 500; text-decoration: none;
  }
  .site-nav.is-enhanced .site-nav__list a { padding-block: 0.875rem; }
  .site-nav__list a:hover { color: var(--text); }

  /* current section: set per page by body[data-section], plus aria-current from JS */
  .site-nav a[aria-current="page"],
  body[data-section="articles"] .site-nav a[href="/articles/"],
  body[data-section="tutorials"] .site-nav a[href="/tutorials/"],
  body[data-section="reference"] .site-nav a[href="/reference/"],
  body[data-section="research"] .site-nav a[href="/research/"],
  body[data-section="topics"] .site-nav a[href="/topics/"],
  body[data-section="about"] .site-nav a[href="/about/"] {
    color: var(--text);
    text-decoration: underline; text-decoration-color: var(--accent);
    text-decoration-thickness: 2px; text-underline-offset: 0.45em;
  }

  @media (min-width: 48em) {
    .site-header {
      position: sticky; top: 0; z-index: var(--z-header);
      background: color-mix(in srgb, var(--bg) 82%, transparent);
      -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
    }
    .site-nav { flex: 0 0 auto; }
    .site-nav__toggle { display: none; }
    .site-nav__list, .site-nav.is-enhanced .site-nav__list {
      flex-direction: row; flex-wrap: nowrap; gap: 0.25rem; border-top: 0; padding: 0;
    }
    .site-nav__list a, .site-nav.is-enhanced .site-nav__list a { padding-block: 0.5rem; }
    @media (hover: hover) { .site-nav__list a:hover { background: var(--surface-2); } }
  }

  /* ----- buttons ----- */
  .btn {
    display: inline-flex; align-items: center; justify-content: center;
    min-height: 2.75rem; padding: 0 1.5rem;
    font-weight: 600; text-decoration: none; cursor: pointer;
    border: 1px solid transparent; border-radius: var(--radius-sm);
  }
  .btn--primary { background: linear-gradient(120deg, var(--blue), var(--cyan)); color: var(--on-accent); }
  .btn--ghost { border-color: var(--border-strong); color: var(--text); }
  @media (hover: hover) {
    .btn { transition: transform 0.2s ease, border-color 0.2s ease; }
    .btn:hover { transform: translateY(-2px); }
    .btn--ghost:hover { border-color: var(--accent); }
  }

  /* ----- chips ----- */
  .chip {
    display: inline-block; padding: 0.125rem 0.625rem;
    font-family: var(--font-mono); font-size: 0.75rem; line-height: 1.5;
    color: var(--text-muted); border: 1px solid var(--border-strong); border-radius: var(--radius-pill);
  }

  /* ----- footer ----- */
  .site-footer { margin-top: var(--space-5); padding-block: var(--space-3); border-top: 1px solid var(--border); }
  .site-footer__inner { display: grid; gap: var(--space-2); }
  .site-footer__list { display: flex; flex-wrap: wrap; gap: 0.25rem 1.25rem; list-style: none; }
  .site-footer a { color: var(--text-muted); }
  .site-footer a:hover { color: var(--text); }
  .site-footer p { color: var(--text-faint); font-size: var(--fs-sm); }
}

@layer utilities {
  /* Beats component display rules by layer order, so [hidden] always works. */
  [hidden] { display: none; }
  /* Keep the menu visible on wide screens even if JS left it collapsed. */
  @media (min-width: 48em) { .site-nav__list[hidden] { display: flex; } }

  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition-duration: 0.001ms; animation-duration: 0.001ms; scroll-behavior: auto; }
  }
}
