:root {
  --bg: #0a0b13;
  --bg-elevated: #141628;
  --sidebar-bg: #0e0f1c;
  --text: #e9e9f5;
  --text-muted: #8d8fac;
  --border: #232544;
  --accent: #5b7cfa;
  --accent-2: #9d7bff;
  --accent-lime: #b3e847;
  --accent-dim: #2a2f5c;
  --accent-soft: rgba(91, 124, 250, 0.15);
  --code-bg: #0f1122;
  --code-text: var(--accent-lime);
  --tip-bg: #10190f;
  --tip-border: #2c4023;
  --warn-bg: #1d1526;
  --warn-border: #5b3a63;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  --radius: 10px;
  --sidebar-w: 240px;
  --topbar-h: 3.1rem;
  --layout-max: 1440px;
  --font-display: Georgia, "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", serif;
  --font-body: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SF Mono", Consolas, Monaco, monospace;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

@view-transition { navigation: auto; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

@keyframes fade-up {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pop-in {
  from { opacity: 0; transform: scale(0.94); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes glow-drift {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(-4vw, 5vw) scale(1.1); }
}

/* --- Fine grain texture over the whole page - the thing that makes flat dark UI feel designed --- */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  opacity: 0.045;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* --- One warm ember glow, asymmetric, behind the article - not a rainbow blob --- */
.bg-orbs {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.bg-orbs .orb-b,
.bg-orbs .orb-c {
  display: none;
}

.bg-orbs .orb-a {
  position: absolute;
  width: 56vw;
  height: 56vw;
  max-width: 760px;
  max-height: 760px;
  right: -18vw;
  top: -20vw;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.16;
  background:
    radial-gradient(circle at 30% 35%, var(--accent), transparent 60%),
    radial-gradient(circle at 65% 60%, var(--accent-2), transparent 65%);
  animation: glow-drift 34s ease-in-out infinite;
  will-change: transform;
}

@media (max-width: 880px) {
  .bg-orbs .orb-a { opacity: 0.1; filter: blur(60px); }
}

/* --- Custom scrollbars --- */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background-color: var(--border);
  border-radius: 999px;
  border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background-color: var(--accent); }

.sidebar { scrollbar-color: var(--accent-dim) transparent; }
.sidebar::-webkit-scrollbar-thumb {
  background-color: var(--accent-dim);
  border: 2px solid var(--sidebar-bg);
}
.sidebar::-webkit-scrollbar-thumb:hover { background-color: var(--accent); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.65;
  font-size: 16px;
}

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- Top bar --- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--topbar-h);
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: var(--layout-max);
  height: 100%;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0 1.1rem;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--text);
  letter-spacing: -0.01em;
}

.logo-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.65rem;
  height: 1.65rem;
  border-radius: 6px;
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
  flex-shrink: 0;
}

.logo-mark svg { width: 1rem; height: 1rem; }

.logo .word span { color: var(--accent-2); }
.logo:hover { text-decoration: none; }

.nav-toggle { display: none; }

.hamburger {
  display: none;
  position: relative;
  width: 1.35rem;
  height: 1.35rem;
  flex-shrink: 0;
  cursor: pointer;
}

.hamburger::before,
.hamburger::after {
  content: "";
  position: absolute;
  left: 0.1rem;
  right: 0.1rem;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform 0.18s ease, top 0.18s ease, box-shadow 0.18s ease;
}
.hamburger::before { top: 0.45rem; box-shadow: 0 -0.38rem 0 var(--text); }
.hamburger::after { top: 0.45rem; transform: translateY(0.38rem); }

#nav-toggle:checked ~ .topbar .hamburger::before { top: 0.65rem; transform: rotate(45deg); box-shadow: none; }
#nav-toggle:checked ~ .topbar .hamburger::after { top: 0.65rem; transform: rotate(-45deg); }

.backdrop { display: none; }

/* --- Layout --- */
.layout {
  display: flex;
  align-items: flex-start;
  min-height: calc(100vh - var(--topbar-h));
  max-width: var(--layout-max);
  margin: 0 auto;
}

/* --- Sidebar --- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 0.9rem 0.7rem 2rem;
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
}

.search { margin-bottom: 0.7rem; padding: 0 0.15rem; }

.search input {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.82rem;
  padding: 0.45rem 0.7rem 0.45rem 1.9rem;
  border-radius: 999px;
  outline: none;
  font-family: inherit;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%239c8b76' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 0.65rem center;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.search input:focus { border-color: var(--accent-dim); box-shadow: 0 0 0 3px var(--accent-soft); }
.search input::placeholder { color: var(--text-muted); }

nav .nav-group {
  border: none;
  margin-bottom: 0.15rem;
}

nav summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  transition: background 0.15s ease, color 0.15s ease;
}

nav summary::-webkit-details-marker { display: none; }

.gicon {
  display: inline-flex;
  color: var(--text-muted);
  flex-shrink: 0;
}
.gicon svg { width: 0.95rem; height: 0.95rem; }
nav details[open] summary .gicon,
nav summary:hover .gicon { color: var(--accent); }

nav summary::after {
  content: "";
  margin-left: auto;
  width: 0.65rem;
  height: 0.65rem;
  flex-shrink: 0;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='9 18 15 12 9 6'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='9 18 15 12 9 6'/%3E%3C/svg%3E") center / contain no-repeat;
  transform: rotate(0deg);
  transition: transform 0.15s ease;
}

nav details[open] summary::after { transform: rotate(90deg); }
nav summary:hover { background: var(--bg-elevated); color: var(--text); }

nav .nav-group ul {
  overflow: hidden;
  animation: fade-up 0.22s ease both;
}

nav ul {
  list-style: none;
  margin: 0.1rem 0 0.5rem;
  padding: 0;
}

nav li a {
  display: block;
  color: var(--text-muted);
  padding: 0.36rem 0.6rem 0.36rem 1.7rem;
  border-radius: 6px;
  font-size: 0.85rem;
  text-decoration: none;
  border-left: 2px solid transparent;
  margin: 0.05rem 0;
  transition: background 0.15s ease, color 0.15s ease, padding-left 0.15s ease, border-color 0.15s ease;
}

nav li a:hover { background: var(--bg-elevated); color: var(--text); padding-left: 1.9rem; }

nav li a.active {
  background: var(--accent-soft);
  color: var(--accent-2);
  font-weight: 600;
  border-left: 2px solid var(--accent);
  animation: fade-up 0.35s ease both;
}

/* --- Content --- */
.content {
  position: relative;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  padding: 2.8rem clamp(1.25rem, 5vw, 3.5rem) 4rem;
  background: var(--bg);
  display: flex;
  justify-content: center;
}

.content > article {
  position: relative;
  z-index: 1;
  max-width: 760px;
  width: 100%;
}

article h1 {
  font-family: var(--font-display);
  font-size: clamp(1.9rem, 1.5rem + 1.8vw, 2.6rem);
  font-weight: 700;
  margin: 0 0 0.45rem;
  letter-spacing: -0.01em;
  color: var(--text);
  animation: fade-up 0.5s ease both;
}

article .subtitle {
  color: var(--text-muted);
  font-size: clamp(1rem, 0.92rem + 0.3vw, 1.15rem);
  margin: 0 0 2.2rem;
  padding-bottom: 1.4rem;
  border-bottom: 1px solid var(--border);
  animation: fade-up 0.5s ease 0.08s both;
}

.reveal {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.55s ease, transform 0.55s ease;
}
.reveal.in-view { opacity: 1; transform: translateY(0); }

article h2 {
  font-family: var(--font-display);
  font-size: clamp(1.25rem, 1.1rem + 0.6vw, 1.55rem);
  font-weight: 700;
  margin: 2.5rem 0 0.9rem;
  padding-top: 0.5rem;
  color: var(--text);
  position: relative;
}

article h2::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 2.4rem;
  height: 2px;
  background: var(--accent);
}

article h2:first-of-type { margin-top: 0; }

article h3 { font-family: var(--font-display); font-size: 1.08rem; margin: 1.6rem 0 0.6rem; }

article p { margin: 0.8rem 0; color: var(--text); }
article ul, article ol { margin: 0.8rem 0; padding-left: 1.4rem; }
article li { margin: 0.3rem 0; }
article ul { list-style: none; padding-left: 0.2rem; }
article ul > li {
  position: relative;
  padding-left: 1.3rem;
}
article ul > li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.55em;
  width: 6px;
  height: 6px;
  border-radius: 1px;
  background: var(--accent-lime);
  transform: rotate(45deg);
}

article code {
  background: var(--code-bg);
  color: var(--code-text);
  padding: 0.15em 0.4em;
  border-radius: 5px;
  font-size: 0.87em;
  font-family: var(--font-mono);
  border: 1px solid var(--border);
}

article pre {
  position: relative;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-left: 2px solid var(--accent-dim);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  overflow-x: auto;
  margin: 1rem 0 1.4rem;
}

.copy-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: var(--bg-elevated);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.72rem;
  padding: 0.25rem 0.55rem;
  cursor: pointer;
  opacity: 0;
  transform: translateY(-3px);
  transition: opacity 0.15s ease, transform 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  font-family: inherit;
}

article pre:hover .copy-btn,
.copy-btn:focus-visible {
  opacity: 1;
  transform: translateY(0);
}

.copy-btn:hover { color: var(--text); border-color: var(--accent-dim); }

.copy-btn.copied {
  color: var(--accent-lime);
  border-color: var(--accent-dim);
  opacity: 1;
  transform: translateY(0);
  animation: pop-in 0.25s ease;
}

article pre code {
  background: none;
  border: none;
  padding: 0;
  color: var(--code-text);
  font-size: 0.85rem;
  line-height: 1.55;
}

.callout {
  border-radius: var(--radius);
  padding: 0.9rem 1.1rem;
  margin: 1.3rem 0;
  font-size: 0.93rem;
  border: 1px solid transparent;
  border-left-width: 3px;
}
.callout.tip { background: var(--tip-bg); border-color: var(--tip-border); }
.callout.warn { background: var(--warn-bg); border-color: var(--warn-border); }
.callout .label {
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  display: block;
  margin-bottom: 0.3rem;
  opacity: 0.8;
}

table { width: 100%; border-collapse: collapse; margin: 1.3rem 0 1.7rem; font-size: 0.9rem; }
th, td { text-align: left; padding: 0.6rem 0.7rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--text-muted); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; }
tr:hover td { background: var(--bg-elevated); }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 1px; margin: 1.6rem 0; background: var(--border); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.card {
  position: relative;
  background: var(--bg-elevated);
  padding: 1.3rem 1.2rem 1.1rem;
  counter-increment: card;
  transition: background 0.2s ease;
}
.card::before {
  content: counter(card, decimal-leading-zero);
  display: block;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--accent);
  opacity: 0.7;
  margin-bottom: 0.6rem;
  letter-spacing: 0.05em;
}
.cards { counter-reset: card; }
.card:hover { background: #241a0f; }
.card h4 { margin: 0 0 0.35rem; font-size: 0.98rem; color: var(--text); font-weight: 700; }
.card p { margin: 0; font-size: 0.85rem; color: var(--text-muted); }

.pager {
  display: flex;
  justify-content: space-between;
  margin-top: 3rem;
  padding-top: 1.4rem;
  border-top: 1px solid var(--border);
  font-size: 0.88rem;
  gap: 1rem;
}
.pager a {
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.9rem;
  flex: 1;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.pager a:hover {
  border-color: var(--accent-dim);
  text-decoration: none;
  background: var(--bg-elevated);
  transform: translateY(-2px);
}
.pager .to-label { display: block; color: var(--text-muted); font-size: 0.72rem; margin-bottom: 0.15rem; }
.pager .next { text-align: right; margin-left: auto; }

kbd {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 0.05em 0.45em;
  font-family: var(--font-mono);
  font-size: 0.85em;
}

.badge {
  display: inline-block;
  background: var(--code-bg);
  color: var(--accent-2);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15em 0.5em;
  border-radius: 5px;
  border: 1px solid var(--border);
  margin-left: 0.3rem;
  vertical-align: middle;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.badge:hover { border-color: var(--accent-dim); box-shadow: 0 0 0 3px var(--accent-soft); }

.made-with {
  position: fixed;
  right: 1.2rem;
  bottom: 1rem;
  z-index: 35;
  color: var(--text-muted);
  font-size: 0.76rem;
  opacity: 0.75;
  animation: fade-up 0.4s ease 0.3s both;
  transition: opacity 0.2s ease;
}
.made-with:hover { opacity: 1; }
.made-with span { color: var(--accent-2); font-weight: 700; }

/* --- Mobile / tablet --- */
@media (max-width: 880px) {
  .hamburger { display: inline-block; }

  .layout { flex-direction: column; }

  .backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 25;
  }
  #nav-toggle:checked ~ .backdrop { opacity: 1; pointer-events: auto; }

  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    bottom: 0;
    width: min(82vw, 300px);
    height: calc(100vh - var(--topbar-h));
    z-index: 28;
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: var(--shadow);
  }
  #nav-toggle:checked ~ .layout .sidebar { transform: translateX(0); }

  .content { padding: 1.7rem 1.1rem 3rem; }
  .made-with { display: none; }
}

@media (min-width: 600px) and (max-width: 880px) {
  .sidebar { width: min(58vw, 320px); }
  .content { padding: 2.1rem 2.2rem 3rem; }
}
