:root {
  --bg: #0d1117;
  --bg-raised: #161b22;
  --bg-hover: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --text-dim: #b1bac4;
  --text-faint: #7d8590;
  --accent: #58a6ff;
  --purple: #bc8cff;
  --nav-h: 3.25rem;
  --side-w: 15rem;
  --kicker-h: 2.75rem;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  line-height: 1.5;
  overflow: hidden;
}

a:focus-visible,
button:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: 0.5rem;
  top: -3rem;
  z-index: 50;
  padding: 0.5rem 0.8rem;
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 6px;
}

.skip-link:focus { top: 0.5rem; }

/* Top bar ---------------------------------------------------------------- */

.site-nav {
  position: relative;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  height: var(--nav-h);
  padding: 0 1.25rem;
  background: rgba(13, 17, 23, 0.96);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--text);
  text-decoration: none;
  font-weight: 650;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.mark {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  width: 14px;
  height: 14px;
}

.mark i { display: block; border-radius: 1px; }
.mark i:nth-child(1) { background: #f85149; }
.mark i:nth-child(2) { background: #58a6ff; }
.mark i:nth-child(3) { background: #3fb950; }
.mark i:nth-child(4) { background: #d29922; }

.nav-current {
  min-width: 0;
  overflow: hidden;
  color: var(--text-faint);
  font-size: 0.9rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-current:not(:empty)::before { content: "/ "; }

.menu-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  margin-left: -0.4rem;
  padding: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
}

.menu-toggle:hover { background: var(--bg-hover); }

.menu-icon { display: grid; gap: 4px; width: 18px; }
.menu-icon i { display: block; height: 2px; background: currentColor; border-radius: 1px; }

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

.shell {
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr);
  height: calc(100% - var(--nav-h));
}

.side-nav {
  overflow-y: auto;
  padding: 0.9rem 0.6rem 1.5rem;
  background: var(--bg);
  border-right: 1px solid var(--border);
}

.side-nav ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.nav-group {
  margin: 1.1rem 0 0.35rem;
  padding: 0 0.7rem;
  color: var(--text-faint);
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.side-nav a {
  display: block;
  padding: 0.38rem 0.7rem;
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 0.92rem;
  text-decoration: none;
}

.side-nav a:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.side-nav a[aria-current="page"] {
  color: var(--accent);
  background: var(--bg-hover);
  box-shadow: inset 2px 0 0 var(--accent);
}

.nav-scrim { display: none; }

main {
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  outline: none;
}

main.is-viewer { overflow: hidden; display: flex; flex-direction: column; }

/* Overview ---------------------------------------------------------------- */

.overview-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 3.5rem 1.5rem 4rem;
}

.eyebrow {
  margin: 0 0 0.75rem;
  color: var(--purple);
  font-size: 0.82rem;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.overview h1 {
  margin: 0 0 1rem;
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 1.15;
  letter-spacing: -0.03em;
  max-width: 18ch;
}

.lead {
  margin: 0 0 2rem;
  max-width: 62ch;
  color: var(--text-dim);
  font-size: 1.08rem;
}

.math {
  font-family: "Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif;
  font-style: italic;
  color: var(--text);
}

.cards-heading {
  margin: 2.25rem 0 0.8rem;
  color: var(--text-faint);
  font-size: 0.78rem;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.9rem;
}

.card {
  display: block;
  padding: 1.15rem 1.15rem 1.25rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: inherit;
  text-decoration: none;
  min-height: 100%;
}

.card:hover,
.card:focus-visible { border-color: var(--accent); }

.card-kicker {
  display: block;
  margin-bottom: 0.7rem;
  color: var(--text-faint);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
}

.card h3 {
  margin: 0 0 0.45rem;
  font-size: 1.15rem;
}

.card p {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.95rem;
}

/* Viewer ------------------------------------------------------------------ */

.viewer {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

.viewer[hidden] { display: none; }

.kicker {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  min-height: var(--kicker-h);
  padding: 0.7rem 1.25rem;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
}

.kicker h2 {
  margin: 0;
  font-size: 0.95rem;
  outline: none;
}

.kicker p {
  margin: 0;
  color: var(--text-faint);
  font-size: 0.82rem;
  text-align: right;
}

.kicker a { color: var(--accent); }

.frames {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
}

.frame {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--bg);
}

.frame[hidden] { display: none; }

.placeholder {
  max-width: 40rem;
  margin: 0 auto;
  padding: 4rem 1.5rem;
  color: var(--text-dim);
}

.placeholder h3 { margin: 0 0 0.5rem; color: var(--text); }
.placeholder a { color: var(--accent); }

/* Responsive -------------------------------------------------------------- */

@media (max-width: 800px) {
  :root { --nav-h: 3rem; }

  .site-nav { padding: 0 0.75rem; }

  .menu-toggle { display: inline-flex; }

  .shell { grid-template-columns: minmax(0, 1fr); }

  .side-nav {
    position: fixed;
    top: var(--nav-h);
    bottom: 0;
    left: 0;
    z-index: 25;
    width: min(18rem, 85vw);
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 0.2s ease, visibility 0s linear 0.2s;
  }

  body.nav-open .side-nav {
    transform: none;
    visibility: visible;
    transition: transform 0.2s ease;
  }

  body.nav-open .nav-scrim {
    display: block;
    position: fixed;
    inset: var(--nav-h) 0 0 0;
    z-index: 24;
    background: rgba(1, 4, 9, 0.6);
  }

  .kicker { align-items: center; min-height: 0; padding: 0.45rem 0.75rem; }
  .kicker .viewer-sub, .kicker .sep { display: none; }
  .kicker p { flex: none; }
  .overview-inner { padding: 2.25rem 1rem 3rem; }
  .cards { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .side-nav, body.nav-open .side-nav { transition: none; }
}
