:root {
  /* Sidan är alltid mörk. */
  --bg: #151413;
  --surface: #1e1d1b;
  --fg: #ecebe8;
  --muted: #a39e97;
  --border: #2f2d2a;
  /* TIOM-blå. Originalet (#3a6ea5) är för mörkt för text mot mörk
     bakgrund, så länkar och markeringar använder en ljusare nyans. */
  --accent: #3a6ea5;
  --accent-text: #86acd6;
  --accent-soft: #1d2835;
  --code-bg: #1e1d1b;
  --sidebar-w: 260px;
  --measure: 46rem;
}

* { box-sizing: border-box; }

/* Sidan ska inte gå att dra utanför sina kanter, varken i sidled eller med studs. */
html, body { overflow-x: hidden; overflow-x: clip; overscroll-behavior: none; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 17px/1.65 "Instrument Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-text); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }

.topbar { display: none; }
.menu-toggle { display: none; }

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow-y: auto;
  padding: 2rem 1.25rem;
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.brand {
  font: 400 1.2rem/1.2 "Instrument Sans", ui-sans-serif, system-ui, sans-serif;
  letter-spacing: -0.02em;
  color: var(--fg);
  text-decoration: none;
}

.sidebar ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }

.sidebar li a {
  display: block;
  padding: 0.4rem 0.7rem;
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.95rem;
}

.sidebar li a:hover { color: var(--fg); background: var(--border); }

.sidebar li a[aria-current="page"] {
  color: var(--accent-text);
  background: var(--accent-soft);
  font-weight: 500;
}

.repo-link { margin-top: auto; font-size: 0.9rem; }

.content {
  padding: 3rem clamp(1rem, 5vw, 4rem) 2rem;
  min-width: 0;
}

article { max-width: var(--measure); }

h1, h2, h3 { line-height: 1.2; letter-spacing: -0.02em; font-weight: 500; }
h1 { font-size: 2.4rem; font-weight: 400; margin: 0 0 1rem; }
h2 { font-size: 1.55rem; font-weight: 400; margin: 2.6rem 0 0.8rem; padding-top: 1rem; border-top: 1px solid var(--border); }
h3 { font-size: 1.12rem; margin: 1.8rem 0 0.5rem; }

p, ul, ol { margin: 0 0 1rem; }
li + li { margin-top: 0.25rem; }

.lead { font-size: 1.15rem; color: var(--muted); }

code {
  font: 0.84em/1.5 "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1em 0.35em;
}

pre, div.highlight pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.1rem;
  overflow-x: auto;
  margin: 0 0 1.2rem;
}

pre code { background: none; border: 0; padding: 0; font-size: 0.85rem; }

div.highlighter-rouge { margin: 0 0 1.2rem; }
div.highlighter-rouge pre { margin: 0; }

table {
  display: block;
  overflow-x: auto;
  border-collapse: collapse;
  margin: 0 0 1.4rem;
  font-size: 0.93rem;
}

th, td { text-align: left; vertical-align: top; padding: 0.5rem 0.8rem; border-bottom: 1px solid var(--border); }
th { font-weight: 600; background: var(--surface); }

blockquote {
  margin: 0 0 1.2rem;
  padding: 0.8rem 1rem;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 6px 6px 0;
}

blockquote p:last-child { margin-bottom: 0; }

.page-footer {
  max-width: var(--measure);
  margin-top: 4rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--muted);
}

/* Rouge-färger, dämpade så att de fungerar i båda lägena */
.highlight .c, .highlight .c1, .highlight .cm { color: var(--muted); font-style: italic; }
.highlight .s, .highlight .s1, .highlight .s2 { color: #6cc193; }
.highlight .k, .highlight .kd, .highlight .nt { color: var(--accent-text); }
.highlight .mi, .highlight .kc { color: #e0a562; }

@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); }

  .topbar {
    display: flex;
    position: sticky;
    top: 0;
    z-index: 4;
    height: 56px;
    align-items: center;
    justify-content: space-between;
    padding: 0.8rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
  }

  /* Hamburgerikon som blir ett kryss när menyn är öppen. */
  .menu-button {
    display: grid;
    align-content: center;
    justify-items: center;
    gap: 4px;
    width: 34px;
    height: 34px;
    cursor: pointer;
    border-radius: 8px;
  }

  .menu-button:hover { background: var(--border); }

  .menu-button span {
    display: block;
    width: 16px;
    height: 1.5px;
    border-radius: 1px;
    background: var(--fg);
    transition: transform 0.2s ease, opacity 0.2s ease;
  }

  .menu-toggle:checked ~ .topbar .menu-button span:nth-child(1) { transform: translateY(5.5px) rotate(45deg); }
  .menu-toggle:checked ~ .topbar .menu-button span:nth-child(2) { opacity: 0; }
  .menu-toggle:checked ~ .topbar .menu-button span:nth-child(3) { transform: translateY(-5.5px) rotate(-45deg); }

  .menu-toggle:focus-visible ~ .topbar .menu-button { outline: 2px solid var(--accent-text); outline-offset: 2px; }

  /* Menyn fälls ut direkt under headern, var på sidan man än är. */
  .sidebar {
    display: none;
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    z-index: 3;
    height: auto;
    max-height: calc(100dvh - 56px);
    overflow-y: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 16px 32px -16px rgba(0, 0, 0, 0.25);
    padding: 1rem;
  }

  .brand-side { display: none; }
  .menu-toggle:checked ~ .layout .sidebar { display: flex; }

  .content { padding: 2rem 1rem; }
  h1 { font-size: 1.8rem; }
}
