/* Base layout and element defaults. Uses only the variables from tokens.css;
   raw colours, pixel values and font names live there. Breakpoints are written
   in rem directly because CSS variables cannot be used inside @media. */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-family: var(--font-ui);
  line-height: var(--leading-normal);
  color: var(--color-text);
  background: var(--color-bg);
}

body {
  margin: 0;
  min-height: 100vh;
  /* Base size lives on body, not html: the rem token scale is expressed against
     the initial root size, so setting the root font-size would shrink every rem
     token a second time (the compact base would compound below its target). */
  font-size: var(--text-base);
}

h1,
h2,
h3 {
  font-family: var(--font-display);
  letter-spacing: -0.02em;
  line-height: var(--leading-tight);
  margin: 0 0 var(--space-3) 0;
}

h1 {
  font-weight: 800;
}

h2,
h3 {
  font-weight: 700;
}

input[type="checkbox"],
input[type="radio"],
progress {
  accent-color: var(--color-primary);
}

a {
  color: var(--color-primary);
}

code,
kbd,
samp {
  font-family: var(--font-mono);
}

/* A block of source keeps its lines and scrolls in its own area, never the page (A-45). */
pre {
  max-width: 100%;
  overflow-x: auto;
}

:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
}

/* The header stays dark in both themes, so its focus ring uses a lighter tone. */
.app-header :focus-visible {
  outline-color: var(--color-header-focus);
}

/* A quiet button in the header keeps the header text colour; Fjord on Fjord would vanish. */
.app-header .button-quiet {
  color: var(--color-header-text);
}

/* Skip link: first focusable element, hidden until focused. */
.skip-link {
  position: absolute;
  left: var(--space-2);
  top: calc(-1 * var(--space-8));
  z-index: 100;
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface);
  color: var(--color-text);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-sm);
}

.skip-link:focus {
  top: var(--space-2);
}

/* App shell: the header band on top (brand, navigation pills, theme and account menus),
   main below. The band never wraps; below 64rem the pills and the theme pill fold into
   the Menu panel. No overflow on the band or the pill row: it would clip the open menus. */
.app-header {
  position: relative;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  border-bottom: var(--border-width) solid var(--color-border);
  background: var(--color-header-bg);
  color: var(--color-header-text);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 800;
  white-space: nowrap;
  color: var(--color-header-text);
  text-decoration: none;
}

.brand-dot {
  width: 0.75rem;
  height: 0.75rem;
  border-radius: var(--radius-full);
  background: var(--color-sun);
}

.header-spacer {
  flex: 1 1 auto;
}

/* Main navigation as pills; shown from 64rem on. The row overrides every axis of
   .nav-list (a column by default); components.css loads later, so the row needs the
   higher specificity of both classes (0,2,0) to win. */
.header-nav {
  display: none;
}

.nav-list.nav-pills {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  gap: var(--space-1);
}

.nav-pills > li > a {
  background: var(--color-header-nav);
  color: var(--color-header-text);
  font-size: var(--text-sm);
  white-space: nowrap;
  padding: var(--space-2) var(--space-2);
}

/* The group pill keeps the inner spacing of the link pills (0,2,0 beats .menu-trigger). */
.nav-pills .menu-trigger {
  padding-inline: var(--space-2);
}

/* Keeps the pill ground on hover (.nav-list a:hover would set the sunken surface). */
.nav-pills > li > a:hover {
  background: var(--color-header-nav);
  text-decoration: underline;
}

.nav-pills > li > a[aria-current="page"],
.nav-pills .menu-trigger[aria-current="true"] {
  background: var(--color-surface);
  color: var(--color-primary);
}

/* The panels are white: Sun on white would fall to 1.55 : 1, so the ring there is Fjord. */
.app-header .menu-panel :focus-visible {
  outline-color: var(--color-focus);
}

/* Signed in, the theme pill folds into the Menu panel on narrow windows. */
.header-theme-folds {
  display: none;
}

/* The theme form holds only hidden fields (the buttons submit via form=); as a box it
   would add one more gap at the end of the band. */
.theme-form {
  display: none;
}

/* The Menu panel spans the band instead of hanging from its pill. */
.header-menu > .menu {
  position: static;
}

.header-menu .menu-panel {
  left: 0;
  right: 0;
}

.header-theme .menu-panel,
.header-account .menu-panel {
  left: auto;
  right: 0;
}

.app-body {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-6);
  padding: var(--space-6) var(--space-4);
}

.app-footer {
  padding: var(--space-3) var(--space-4);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  text-align: center;
}

main {
  min-width: 0;
}

@media (min-width: 48rem) {
  .app-body {
    padding: var(--space-7);
  }
}

@media (min-width: 64rem) {
  .header-nav {
    display: block;
  }

  .header-theme-folds {
    display: block;
  }

  .header-menu {
    display: none;
  }
}

@media (min-width: 75rem) {
  .nav-pills > li > a,
  .nav-pills .menu-trigger {
    padding-inline: var(--space-3);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }
}
