/* Reset, page shell, navigation and typography. Values come from tokens.css only. */

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

html {
  font-family: var(--font-sans);
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
  background: var(--c-bg);
  color: var(--c-text);
}

body {
  margin: 0;
  min-height: 100vh;
  font-size: var(--text-base);
  line-height: var(--leading-base);
}

a {
  color: var(--c-accent);
  text-underline-offset: 0.2em;
}

:focus-visible {
  outline: var(--focus-width) solid var(--c-accent);
  outline-offset: var(--focus-offset);
}

code,
.mono {
  font-family: var(--font-mono);
  font-size: var(--text-code);
}

/* Skip link: first in the tab order, visible only when focused. */
.skip-link {
  position: absolute;
  left: var(--space-2);
  top: -6rem;
  z-index: 10;
  padding: var(--space-2) var(--space-3);
  background: var(--c-surface);
  color: var(--c-text);
  border: var(--border-width) solid var(--c-border);
  border-radius: var(--radius-1);
}

.skip-link:focus {
  top: var(--space-2);
}

/* Shell: a left rail on wide screens, a top strip below 48rem. */
.shell {
  display: grid;
  grid-template-columns: var(--rail-width) minmax(0, 1fr);
  min-height: 100vh;
}

.rail {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  padding: var(--space-4) var(--space-3);
  background: var(--c-sunken);
  border-right: var(--border-width) solid var(--c-rule);
}

.brand {
  margin: 0;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: 700;
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
}

.brand__sub {
  display: block;
  font-weight: 400;
  color: var(--c-muted);
}

.nav__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.nav__link {
  display: flex;
  gap: var(--space-2);
  align-items: baseline;
  padding: var(--space-1) var(--space-2);
  color: var(--c-text);
  text-decoration: none;
  border-left: var(--focus-width) solid transparent;
  font-size: var(--text-sm);
}

.nav__link:hover {
  background: var(--c-bg);
}

.nav__link[aria-current="page"] {
  font-weight: 700;
  border-left-color: var(--c-text);
  background: var(--c-bg);
}

.nav__index {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--c-muted);
}

.rail__foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.content {
  min-width: 0;
  max-width: var(--content-max);
  padding: var(--space-5);
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2) var(--space-5);
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-2);
  border-bottom: var(--border-width) solid var(--c-border);
}

.page-title {
  margin: 0;
  font-size: var(--text-xl);
  line-height: var(--leading-tight);
  font-weight: 700;
  letter-spacing: -0.01em;
}

.section-title {
  margin: 0 0 var(--space-2);
  font-size: var(--text-lg);
  line-height: var(--leading-tight);
  font-weight: 600;
}

.label {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--c-muted);
}

.caption {
  margin: var(--space-2) 0 0;
  font-size: var(--text-xs);
  color: var(--c-muted);
}

/* Signed-out pages (login): no navigation, so the rail is a plain top strip at any width. */
.shell--bare {
  grid-template-columns: minmax(0, 1fr);
}

.shell--bare .rail {
  position: static;
  height: auto;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  border-right: 0;
  border-bottom: var(--border-width) solid var(--c-rule);
}

.shell--bare .rail__foot {
  margin: 0;
}

.shell--bare .theme-toggle {
  width: auto;
}

/* Narrow screens (below 48rem, designed from 360px): the rail becomes a top strip and the
   navigation stays usable without JavaScript. */
@media (max-width: 48rem) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .rail {
    position: static;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-4);
    border-right: 0;
    border-bottom: var(--border-width) solid var(--c-rule);
  }

  .nav {
    order: 3;
    flex: 1 0 100%;
    overflow-x: auto;
  }

  .nav__list {
    flex-direction: row;
  }

  .nav__link {
    border-left: 0;
    border-bottom: var(--focus-width) solid transparent;
    white-space: nowrap;
  }

  .nav__link[aria-current="page"] {
    border-bottom-color: var(--c-text);
  }

  .rail__foot {
    margin: 0 0 0 auto;
    flex-direction: row;
    align-items: center;
  }

  .content {
    padding: var(--space-4) var(--space-3);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
    scroll-behavior: auto !important;
  }
}
