/**
 * Base Styles
 * Resets, normalization, and global element styling
 */

/* Fonts are loaded via <link rel="preconnect"> + <link rel="stylesheet"> in
   templates/base.html. Not with @import: an @import inside a stylesheet cannot
   be discovered by the preload scanner, so the font request only starts after
   this file has been fetched and parsed — one round trip later than a <link>
   in the document head. */

/* Box Sizing Reset */
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Root & Body */
html {
  /* 100%, not 16px. Every rem in the scale is computed against this, and a
     literal px here overrides the reader's own browser font-size setting, so
     the whole rem-based scale stops responding to it. 100% inherits that
     preference and still resolves to 16px by default, which is what the rem
     values in variables.css assume. */
  font-size: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  margin: 0;
  font-family: var(--font-primary);
  /* Tokenised, not the literal 17px this used to be: the token is what the
     breakpoints in variables.css act on, so hardcoding it here severed the
     root of the page from the responsive scale. */
  font-size: var(--text-base);
  font-weight: var(--font-normal);
  line-height: var(--leading-body);
  letter-spacing: var(--tracking-normal);
  color: var(--text-primary);
  background-color: var(--bg-page);

  /* Sticky footer. The page is a column at least as tall as the viewport, and
     .nim-page-main takes the slack, so .nimonik-footer is pushed to the bottom
     on a short page instead of leaving a band of --bg-page beneath it.

     Safe as a flex container because every body child between the content and
     the footer is out of flow already: #toast-stack and the cookie banner are
     position:fixed, the five modal includes are display:none until shown, and
     <script> elements never render.

     100dvh after 100vh so mobile uses the dynamic viewport — with 100vh the
     footer sits under the browser's collapsing toolbar and the page always
     scrolls by that much. */
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* Basis auto, shrink 0: grow to fill the leftover height, but never let a tall
   page get compressed to fit the viewport. */
.nim-page-main {
  flex: 1 0 auto;
}

/* Remove default margins */
h1, h2, h3, h4, h5, h6,
p, ul, ol, dl, dd, blockquote, figure {
  margin: 0;
}

/* Element-level heading scale.
   Previously these got only `margin: 0` here, so an unclassed <h2> — 43 of the
   169 heading tags in the templates carry no class — fell through to
   Bootstrap's scale (h1 40px, h2 32px) and bypassed the project's entirely.
   The mapping matches .nim-h1 .. .nim-h6 in typography.css; the classes remain
   for applying a heading's appearance to a non-heading element. */
h1, h2, h3, h4, h5, h6 {
  font-weight: var(--font-semibold);
  color: var(--text-primary);
}

h1 {
  font-size: var(--text-4xl);
  font-weight: var(--font-bold);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tighter);
}

h2 {
  font-size: var(--text-3xl);
  font-weight: var(--font-bold);
  line-height: var(--leading-snug);
  letter-spacing: var(--tracking-tighter);
}

h3 {
  font-size: var(--text-2xl);
  line-height: var(--leading-snug);
  letter-spacing: var(--tracking-tight);
}

h4 {
  font-size: var(--text-xl);
  line-height: var(--leading-normal);
  letter-spacing: var(--tracking-snug);
}

h5 {
  font-size: var(--text-lg);
  line-height: var(--leading-relaxed);
  letter-spacing: var(--tracking-normal);
}

h6 {
  font-size: var(--text-base);
  line-height: var(--leading-relaxed);
  letter-spacing: var(--tracking-normal);
}


/* List reset */
ul, ol {
  padding: 0;
  list-style: none;
}

/* Link reset */
a {
  color: inherit;
  text-decoration: none;
}



/* Form elements */
input, button, textarea, select {
  font: inherit;
  color: inherit;
}

/* Button reset */
button {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}

/* Remove button focus outline (add custom focus styles) */
button:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

/* Prevent text overflow */
p, h1, h2, h3, h4, h5, h6 {
  overflow-wrap: break-word;
}

/* ==========================================
   GLOBAL LAYOUT CONSTRAINTS
   ========================================== */

:root {
  --container-max-width: 1200px;
  /* Both were off the project's own spacing scale (20px had no step, 15px sat
     between 14 and 16). 20px is now --space-20px; the mobile gutter rounds up to
     16px rather than down to 14px, which is the conventional container gutter. */
  --container-padding: var(--space-20px);
  --container-padding-mobile: var(--space-16px);
}

.container {
  max-width: var(--container-max-width) !important;
  margin: 0 auto !important;
  padding-left: var(--container-padding) !important;
  padding-right: var(--container-padding) !important;
}

/* Mobile: Reduce padding */
@media (max-width: 767.98px) {
  .container {
    padding-left: var(--container-padding-mobile) !important;
    padding-right: var(--container-padding-mobile) !important;
  }
}
