@font-face {
  font-family: 'GT Flexa Mono';
  src: url('fonts/GT-Flexa-Mono-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --font: 'GT Flexa Mono', monospace;
  --text-size: 18px;
  --text-weight: 400;
  --text-line-height: 1.5;
  --nav-text-size: 17px;
  --nav-line-height: 1.6;

  --margin: 40px;
  --margin-top-desktop: 40px;
  --margin-top-mobile: 60px;
  --content-max-width: 800px;
  --sidebar-width: 300px;

  /* Light mode */
  --bg:              #F9F9F9;
  --sidebar-bg:      #FFFFFF;
  --text-body:       #666666;
  --text-heading:    #111111;
  --icon:            #111111;
  --nav-text:        #666666;
  --nav-text-active: #111111;
  --link-underline:  #666666;

  --theme-transition: background-color 0.4s ease, color 0.4s ease, border-color 0.4s ease;
}

[data-theme="dark"] {
  --bg:              #111111;
  --sidebar-bg:      #151515;
  --text-body:       #999999;
  --text-heading:    #F1F1F1;
  --icon:            #F1F1F1;
  --nav-text:        #999999;
  --nav-text-active: #F1F1F1;
  --link-underline:  #999999;
}

*, *::before, *::after {
  box-sizing: border-box;
  transition: var(--theme-transition);
}

.icon-btn svg, .icon-btn svg * {
  transition: fill 0.4s ease, stroke 0.4s ease;
}

html {
  scroll-behavior: smooth;
  background-color: var(--bg);
  min-height: 100%;
}


::selection {
  background-color: #666666;
  color: #F1F1F1;
}

@media (max-width: 767px) {
  ::selection {
    background-color: initial;
    color: initial;
  }
}

body {
  margin: 0;
  padding: 0;
  padding-bottom: env(safe-area-inset-bottom);
  min-height: 100%;
  background-color: var(--bg);
  font-family: var(--font);
  font-size: var(--text-size);
  font-weight: var(--text-weight);
  line-height: var(--text-line-height);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ─── Skip link ─────────────────────────────────────────── */

.skip-link {
  position: absolute;
  transform: translateY(-100%);
}

.skip-link:focus {
  transform: translateY(0);
}

/* ─── Top fade ──────────────────────────────────────────── */

.top-fade {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 40px;
  z-index: 25;
  background-color: var(--bg);
  -webkit-mask-image: linear-gradient(to bottom, black 0%, transparent 100%);
  mask-image: linear-gradient(to bottom, black 0%, transparent 100%);
  pointer-events: none;
}

/* ─── Fixed chrome ─────────────────────────────────────── */

.icon-btn {
  position: fixed;
  z-index: 30;
  color: var(--icon);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--theme-transition);
}

#nav-toggle {
  top: var(--margin);
  left: var(--margin);
}

#theme-toggle {
  top: var(--margin);
  right: var(--margin);
}

/* ─── Sidebar ───────────────────────────────────────────── */

.sidebar-container {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  z-index: 20;
  transform: translateX(calc(-1 * var(--sidebar-width)));
  transition: transform 0.3s ease;
  pointer-events: none;
  background: none;
}

.sidebar-container.open {
  transform: translateX(0);
  pointer-events: auto;
}

.sidebar {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  background-color: var(--sidebar-bg);
  padding-top: 120px;
  padding-left: var(--margin);
  padding-right: var(--margin);
  padding-bottom: max(var(--margin), env(safe-area-inset-bottom));
  transition: var(--theme-transition);
}

.sidebar nav {
  display: flex;
  flex-direction: column;
}

.nav-item {
  font-family: var(--font);
  font-size: var(--nav-text-size);
  font-weight: 400;
  line-height: var(--nav-line-height);
  color: var(--nav-text);
  text-decoration: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  text-align: left;
  display: block;
  transition: var(--theme-transition), opacity 0.2s ease;
}

.nav-item.active {
  color: var(--nav-text-active);
}

.nav-sep {
  display: block;
  font-family: var(--font);
  font-size: var(--nav-text-size);
  line-height: var(--nav-line-height);
  color: var(--nav-text);
  margin: 0.25em 0;
  user-select: none;
  pointer-events: none;
}

/* ─── Mobile overlay ────────────────────────────────────── */

.overlay {
  display: none;
}

/* ─── Page wrapper and content column ──────────────────── */

.page-wrapper {
  transition: var(--theme-transition), padding-left 0.3s ease;
}

.main-content {
  max-width: var(--content-max-width);
  margin: 0 auto;
  padding: var(--margin-top-desktop) var(--margin) 80px var(--margin);
}

/* ─── Typography ────────────────────────────────────────── */

.main-content p {
  margin: 0 0 28px 0;
  padding: 0;
  font-family: var(--font);
  font-size: var(--text-size);
  font-weight: var(--text-weight);
  line-height: var(--text-line-height);
}

.heading {
  color: var(--text-heading);
  margin-top: 2em;
}

.main-content p.list-item {
  margin-top: 0;
  margin-bottom: 0;
}

.main-content p.list-item + p:not(.list-item) {
  margin-top: 28px;
}

.separator {
  margin-bottom: 0;
}

/* H1-level headings get more breathing room */
.heading[data-nav-level="1"] {
  margin-top: 2em;
}

/* No top margin on the very first element */
.main-content p:first-child {
  margin-top: 0;
}

.body {
  color: var(--text-body);
}

/* ─── Links ─────────────────────────────────────────────── */

a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--link-underline);
}

.main-content a {
  color: var(--text-heading);
  text-decoration: underline;
  text-decoration-color: var(--link-underline);
  transition: color 0.2s ease;
}

.main-content a:hover {
  color: var(--text-body);
}

.nav-item:hover {
  color: var(--nav-text-active);
  text-decoration: none;
}

/* ─── Section images ────────────────────────────────────── */

.image-wrapper {
  border-radius: 12px;
  overflow: hidden;
  margin: 2em 0;
}

.section-image {
  width: 100%;
  display: block;
  vertical-align: bottom;
}

/* ─── Mid-size: ensure content clears fixed icons ──────── */

@media (min-width: 768px) and (max-width: 1100px) {
  .main-content {
    padding-left: 80px;
    padding-right: 80px;
  }
}

/* ─── Desktop: sidebar pushes content ──────────────────── */

@media (min-width: 768px) {
  body.sidebar-open .page-wrapper {
    padding-left: var(--sidebar-width);
  }
}

/* ─── Mobile ────────────────────────────────────────────── */

@media (max-width: 767px) {
  :root {
    --margin: 24px;
    --margin-top-mobile: 76px;
  }

  .main-content {
    padding-top: var(--margin-top-mobile);
  }

  .top-fade {
    height: 68px;
    background: var(--bg);
    mask-image: none;
    -webkit-mask-image: none;
  }


  .sidebar-container {
    width: 100%;
    transform: none;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
  }

  .sidebar-container.open {
    transform: none;
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar {
    padding-top: 80px;
    width: 100%;
    background-color: var(--bg);
  }

  .image-wrapper {
    border-radius: 8px;
  }

  .overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
  }

  .overlay.active {
    opacity: 1;
    pointer-events: auto;
  }
}
