/* base.css - element defaults and the layout shell.
 *
 * Mobile-first throughout: every rule here is the 320px layout, and
 * every media query is min-width. There are no max-width layout
 * queries, because they invert the cascade and make the small screen
 * the exception rather than the base.
 */

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-body);
  /* The notch moves to the SIDE in landscape, so horizontal insets
   * matter as much as vertical ones. max() keeps the normal gutter on
   * devices with no inset. */
  padding-left: max(0px, env(safe-area-inset-left));
  padding-right: max(0px, env(safe-area-inset-right));
  /* Belt and braces against sideways spill: no page should ever need
   * horizontal scroll, and a stray wide child is a bug, not a reason
   * to pan. */
  overflow-x: hidden;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  line-height: var(--leading-tight);
  font-weight: 600;
  margin: 0 0 var(--space-3);
  text-wrap: balance;
}
h1 { font-size: var(--text-3xl); letter-spacing: -0.01em; }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }
p { margin: 0 0 var(--space-4); max-width: var(--measure); }

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 0.2em; }
a:hover { text-decoration-thickness: 2px; }

/* Focus, once, globally. :focus-visible only, so a mouse click does not
 * paint a ring but a Tab key always does. */
:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}
/* A focused element must never end up hidden behind the sticky header
 * (WCAG 2.4.11). scroll-margin is what reserves that space. */
:target, :focus-visible { scroll-margin-top: 5rem; }

img, svg, video { max-width: 100%; height: auto; }

/* The hidden attribute must always win. A component that sets its own
 * display (a flex drawer, a grid panel) silently overrides the browser
 * default of display:none, leaving an invisible element still on top of
 * the page and still swallowing clicks. Found exactly that way: a closed
 * drawer was intercepting every click on the right of the board. */
[hidden] { display: none !important; }

table { border-collapse: collapse; width: 100%; }
code, kbd, samp { font-family: var(--font-mono); font-size: 0.95em; }

/* Every numeral in this system is monospaced and tabular, so columns of
 * money and durations line up and a changing value does not jitter. */
.num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

.skip-link {
  position: absolute;
  left: var(--space-2);
  top: var(--space-2);
  z-index: 100;
  padding: var(--space-2) var(--space-4);
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: var(--radius-sm);
  transform: translateY(-200%);
}
.skip-link:focus { transform: translateY(0); }

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap; border: 0;
}

/* --- Shell ---------------------------------------------------------- */

.page {
  width: 100%;
  max-width: var(--page-max);
  margin-inline: auto;
  padding-inline: var(--gutter);
  /* padding-block, never the shorthand: a `padding` shorthand here
   * would silently zero the inline gutter set above. */
  padding-block: var(--space-6) var(--space-16);
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in oklch, var(--paper) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--rule);
  padding-top: max(0px, env(safe-area-inset-top));
}

/* On a phone the brand, the nav and the theme control cannot share one
 * row without the nav being squeezed to a sliver. So: brand and toggle
 * on the first row, nav full-width on the second, and they collapse
 * back to a single row at 768 where there is room. */
.site-header__inner {
  max-width: var(--page-max);
  margin-inline: auto;
  padding-inline: var(--gutter);
  padding-block: var(--space-2);
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: var(--space-1) var(--space-3);
}
.site-header__inner > .nav {
  grid-column: 1 / -1;
  grid-row: 2;
}

@media (min-width: 768px) {
  .site-header__inner {
    grid-template-columns: auto 1fr auto;
    padding-block: var(--space-3);
  }
  .site-header__inner > .nav {
    grid-column: 2;
    grid-row: 1;
    justify-content: center;
  }
}

.brand {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-lg);
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}

/* Navigation scrolls horizontally on a phone rather than wrapping into
 * a tall block that pushes the content off screen. scroll-snap keeps
 * it feeling deliberate rather than loose. */
.nav {
  display: flex;
  gap: var(--space-1);
  overflow-x: auto;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  margin-inline: calc(var(--gutter) * -1);
  padding-inline: var(--gutter);
}
.nav::-webkit-scrollbar { display: none; }

.nav__link {
  scroll-snap-align: start;
  display: inline-flex;
  align-items: center;
  min-height: var(--tap-min);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--ink-muted);
  text-decoration: none;
  font-size: var(--text-sm);
  white-space: nowrap;
}
.nav__link:hover { background: var(--paper-sunken); color: var(--ink); }
.nav__link[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.site-footer {
  border-top: 1px solid var(--rule);
  color: var(--ink-faint);
  font-size: var(--text-sm);
  padding-block: var(--space-6);
  padding-bottom: max(var(--space-6), env(safe-area-inset-bottom));
  margin-top: var(--space-16);
}

/* On a short landscape viewport the sticky header and generous vertical
 * rhythm eat the screen, so both shrink. A height query, not
 * `orientation`, so a tall tablet held sideways is not punished. */
@media (max-height: 600px) {
  .site-header__inner { padding-block: var(--space-2); }
  .page { padding-block: var(--space-4) var(--space-8); }
  .site-footer { margin-top: var(--space-8); }
}

.theme-toggle {
  min-width: var(--tap-min);
  min-height: var(--tap-min);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  color: var(--ink-muted);
  font: inherit;
  font-size: var(--text-sm);
  cursor: pointer;
  padding-inline: var(--space-3);
}
.theme-toggle:hover { border-color: var(--rule-strong); color: var(--ink); }
