:root {
  --color-bg: #0e1013;
  --color-surface: #14171c;
  --color-surface-raised: #1a1e25;
  --color-line: #262b33;
  --color-text: #e6e9ed;
  --color-text-muted: #99a1ad;
  --color-accent: #ffd23d;
  --color-ok: #6fcf82;
  --color-near: #e3b34c;

  --font-display: "Chakra Petch", "Segoe UI", sans-serif;
  --font-body: "IBM Plex Sans", "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", Consolas, monospace;

  --space-xs: 0.5rem;
  --space-sm: 1rem;
  --space-md: 1.5rem;
  --space-lg: 2.5rem;
  --space-section: clamp(4rem, 9vw, 6.5rem);

  --radius-sm: 6px;
  --radius-md: 10px;

  --page-gutter: clamp(1rem, 4vw, 3rem);
  --content-width: 1080px;
  --header-height: 64px;
}

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

html {
  scroll-padding-top: var(--header-height);
  scroll-behavior: smooth;
  /* Stops iOS Safari inflating text in landscape */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* ===== Scrollbars ===== */

html {
  scrollbar-width: thin;
  scrollbar-color: var(--color-surface-raised) var(--color-bg);
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: var(--color-bg);
}

::-webkit-scrollbar-thumb {
  background: var(--color-surface-raised);
  border: 2px solid var(--color-bg); /* fakes a gutter so the thumb reads as a pill */
  border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--color-text-muted);
}

::-webkit-scrollbar-corner {
  background: var(--color-bg);
}

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
  font-family: var(--font-display);
  line-height: 1.15;
  margin: 0 0 var(--space-sm);
}

h2 {
  font-size: 1.55rem;
}

h3 {
  font-size: 1.1rem;
}

p,
dl,
dd,
ul {
  margin: 0;
}

p + p {
  margin-top: var(--space-sm);
}

a {
  color: inherit;
}

button {
  color: inherit;
  font: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

img,
svg {
  display: block;
}

img {
  max-width: 100%;
}

svg {
  fill: currentColor;
}

/* Stroke-based UI icons (arrows etc.) — class must win over the svg fill rule above */
.icon {
  display: inline-block;
  width: 0.9em;
  height: 0.9em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -0.08em;
  flex-shrink: 0;
}

::selection {
  background: var(--color-accent);
  color: var(--color-bg);
}

:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 100;
  padding: 0.6rem 1rem;
  background: var(--color-accent);
  color: var(--color-bg);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  text-decoration: none;
  border-radius: var(--radius-sm);
  transform: translateY(-250%);
}

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

/* ===== Shared text styles ===== */

.eyebrow {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.lede {
  max-width: 58ch;
  color: var(--color-text-muted);
}

.text-link {
  color: var(--color-accent);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: rgba(255, 210, 61, 0.4);
}

.text-link:hover {
  text-decoration-color: currentColor;
}

.text-link--nowrap {
  white-space: nowrap; /* keeps the trailing icon glued to its label */
}

/* ===== Buttons ===== */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.btn--accent {
  background: var(--color-accent);
  color: var(--color-bg);
}

.btn--accent:hover {
  background: #ffdf6b;
}

.btn--ghost {
  border: 0;
  box-shadow: inset 0 0 0 1px var(--color-line);
  color: var(--color-text);
}

.btn--ghost:hover {
  box-shadow: inset 0 0 0 1px var(--color-text-muted);
}

/* ===== Header ===== */

.site-header {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  height: var(--header-height);
  padding: 0 var(--page-gutter);
  border-bottom: 1px solid var(--color-line);
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(14, 16, 19, 0.92);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.01em;
  text-decoration: none;
  margin-right: auto;
  white-space: nowrap; /* wraps to two lines at ~320px otherwise */
}

.brand__logo {
  width: 30px;
  height: 30px;
  border-radius: 6px;
}

.site-nav {
  display: flex;
  gap: var(--space-md);
}

.site-nav__link {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  text-decoration: none;
  color: var(--color-text-muted);
  padding: 0.35rem 0;
  border-bottom: 2px solid transparent;
}

.site-nav__link:hover {
  color: var(--color-text);
}

.site-nav__link.is-current {
  color: var(--color-text);
  border-bottom-color: var(--color-accent);
}

.header-links {
  display: flex;
  gap: var(--space-xs);
}

.header-icon {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: var(--radius-sm);
  box-shadow: inset 0 0 0 1px var(--color-line);
  color: #fffcfc;
  transition: box-shadow 0.15s ease, color 0.15s ease;
}

.header-icon:hover {
  box-shadow: inset 0 0 0 1px var(--color-text-muted);
  color: #fff;
}

.header-icon svg {
  width: 18px;
  height: 18px;
}

.header-icon img {
  width: 18px;
  height: 18px;
}

.logo-fallback {
  display: inline-grid;
  place-items: center;
  font-family: var(--font-mono);
  font-size: 0.75em;
  color: var(--color-text-muted);
}

.menu-button {
  display: none;
  align-items: center;
  gap: 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 0.55rem 0.9rem;
  border: 1px solid var(--color-line);
  border-radius: var(--radius-sm);
}

.menu-button__lines {
  position: relative;
  width: 15px;
  height: 11px;
}

.menu-button__lines span {
  position: absolute;
  left: 0;
  width: 100%;
  height: 2px;
  border-radius: 1px;
  background: currentColor;
  transition: transform 0.2s ease, top 0.2s ease;
}

.menu-button__lines span:first-child {
  top: 1px;
}

.menu-button__lines span:last-child {
  top: 8px;
}

.menu-button[aria-expanded="true"] .menu-button__lines span:first-child {
  top: 4.5px;
  transform: rotate(45deg);
}

.menu-button[aria-expanded="true"] .menu-button__lines span:last-child {
  top: 4.5px;
  transform: rotate(-45deg);
}

.site-nav__meta {
  display: none;
}

@media (max-width: 720px) {
  .menu-button {
    display: flex;
    order: 3;
  }

  .header-links {
    margin-left: auto;
  }

  .brand {
    margin-right: 0;
  }

  /* Absolute, not fixed: the header's backdrop-filter makes it the
     containing block for fixed descendants */
  .site-nav {
    position: absolute;
    top: calc(100% + 8px);
    right: 12px;
    width: min(calc(100% - 24px), 320px);
    flex-direction: column;
    gap: 2px;
    padding: 0.4rem;
    background: var(--color-surface);
    border: 1px solid var(--color-line);
    border-radius: var(--radius-md);
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.55);
    display: none;
    max-height: calc(100vh - var(--header-height) - 24px);
    overflow-y: auto;
    transform-origin: top right;
  }

  .site-nav.is-open {
    display: flex;
    animation: menu-drop 0.18s ease-out;
  }

  .site-nav__link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--color-text);
    padding: 0.85rem 0.9rem;
    border-bottom: 0;
    border-radius: var(--radius-sm);
  }

  .site-nav__link:hover,
  .site-nav__link:active {
    background: var(--color-surface-raised);
  }

  .site-nav.is-open .site-nav__link {
    animation: menu-item 0.22s ease-out backwards;
  }

  .site-nav.is-open .site-nav__link:nth-child(2) {
    animation-delay: 0.04s;
  }

  .site-nav.is-open .site-nav__link:nth-child(3) {
    animation-delay: 0.08s;
  }

  .site-nav__link.is-current {
    background: var(--color-surface-raised);
  }

  .site-nav__link.is-current .site-nav__label {
    color: var(--color-accent);
  }

  .site-nav__meta {
    display: inline;
    font-family: var(--font-mono);
    font-size: 0.68rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--color-text-muted);
  }

  body.is-menu-open::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 200vh; /* mobile viewport height shifts as the toolbar collapses */
    z-index: 40; /* under the header (50), over everything else */
    background: rgba(5, 6, 8, 0.6);
    animation: scrim-in 0.2s ease-out;
  }

  /* A fixed backdrop-filter region undershoots on phones; blurring the
     elements can't */
  body.is-menu-open main,
  body.is-menu-open .site-footer {
    filter: blur(3px);
  }
}

@keyframes menu-drop {
  from {
    opacity: 0;
    transform: translateY(-6px) scale(0.97);
  }
}

@keyframes menu-item {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
}

@keyframes scrim-in {
  from {
    opacity: 0;
  }
}

@media (max-width: 400px) {
  .site-header {
    gap: var(--space-sm);
  }

  .brand {
    font-size: 0.95rem;
    gap: 0.4rem;
  }

  .brand__logo {
    width: 26px;
    height: 26px;
  }

  .header-icon {
    width: 32px;
    height: 32px;
  }
}

/* ===== Page shell ===== */

main {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 0 var(--page-gutter) var(--space-section);
}

/* ===== Footer ===== */

.site-footer {
  border-top: 1px solid var(--color-line);
  padding: var(--space-lg) var(--page-gutter);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm) var(--space-lg);
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.site-footer__brand {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--color-text);
  margin-right: var(--space-sm);
}

.site-footer nav {
  display: flex;
  gap: var(--space-md);
}

.site-footer a {
  text-decoration: none;
}

.site-footer a:hover {
  color: var(--color-text);
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
