:root {
  --bg: #f4f6f9; --panel: #ffffff; --ink: #1d2430; --muted: #5d6877; --line: #d7dde5;
  --accent: #1f6feb; --accent-soft: #e8f0fe; --ok: #15803d; --err: #c62828; --warn-bg: #fff6e0; --warn-line: #f1c45b;
  --code-bg: #eef2f7; --x: #d32f2f; --y: #2e7d32; --z: #1565c0;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 70px; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.6 system-ui, -apple-system, "Segoe UI", sans-serif; }
html[lang="en"] body [lang="sv"], html[lang="sv"] body [lang="en"] { display: none !important; }

header { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px; padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; font-size: 17px; }
.brand span { color: var(--accent); }
.spacer { flex: 1; }
.langs { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.langs button { border: none; background: var(--panel); padding: 5px 12px; font: inherit; font-size: 14px; cursor: pointer; color: var(--muted); }
.langs button[aria-pressed="true"] { background: var(--accent); color: #fff; font-weight: 600; }
a.btn, button.btn { display: inline-block; border: 1px solid var(--accent); background: var(--accent); color: #fff; padding: 6px 13px; border-radius: 8px; text-decoration: none; font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; }
button.btn.ghost, a.btn.ghost { background: var(--panel); color: var(--accent); }

.layout { display: grid; grid-template-columns: 240px minmax(0, 780px); gap: 36px; justify-content: center; padding: 28px 20px 80px; }
nav.toc { position: sticky; top: 76px; align-self: start; font-size: 14px; }
nav.toc ol { list-style: none; margin: 0; padding: 0; }
nav.toc a { display: block; padding: 4px 10px; border-left: 2px solid var(--line); color: var(--muted); text-decoration: none; }
nav.toc a:hover { color: var(--ink); }
nav.toc a.active { border-left-color: var(--accent); color: var(--accent); font-weight: 600; }

main section { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 6px 30px 22px; margin-bottom: 26px; }
h1 { font-size: 32px; line-height: 1.2; margin: 0 0 6px; }
.lead { font-size: 18px; color: var(--muted); margin-top: 0; }
h2 { font-size: 24px; margin: 22px 0 8px; }
h3 { font-size: 18px; margin: 22px 0 6px; }
p, li { max-width: 70ch; }
code, kbd { background: var(--code-bg); border-radius: 5px; padding: 1px 5px; font: 0.9em ui-monospace, Consolas, monospace; }
.blk { display: inline-block; border-radius: 5px; padding: 0 7px; color: #fff; font-size: 0.88em; font-weight: 600; white-space: nowrap; }
.blk.m { background: #5b80a5; } .blk.s { background: #a5745b; } .blk.c { background: #a55ba5; } .blk.g { background: #5ba58c; } .blk.st { background: #a5a55b; } .blk.l { background: #5ba55b; }
.x { color: var(--x); font-weight: 700; } .y { color: var(--y); font-weight: 700; } .z { color: var(--z); font-weight: 700; }
table { border-collapse: collapse; width: 100%; margin: 10px 0 14px; font-size: 15px; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .03em; }
.note { background: var(--accent-soft); border-left: 4px solid var(--accent); padding: 10px 14px; border-radius: 0 8px 8px 0; margin: 14px 0; }
.warn { background: var(--warn-bg); border-left: 4px solid var(--warn-line); padding: 10px 14px; border-radius: 0 8px 8px 0; margin: 14px 0; }
.try { border: 1px dashed var(--accent); border-radius: 10px; padding: 8px 14px; margin: 14px 0; }
.try::before { content: attr(data-label); display: block; font-weight: 700; color: var(--accent); font-size: 14px; }
details.quiz { border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px; margin: 10px 0; background: #fafbfd; }
details.quiz summary { cursor: pointer; font-weight: 600; }
details.quiz[open] summary { margin-bottom: 6px; }
figure { margin: 16px 0; }
figcaption { color: var(--muted); font-size: 14px; margin-top: 4px; }
figure svg { width: 100%; height: auto; display: block; background: #fbfcfe; border: 1px solid var(--line); border-radius: 10px; }
pre.code { background: #0f1620; color: #d6e2ef; padding: 12px 14px; border-radius: 10px; overflow: auto; font: 13px/1.5 ui-monospace, Consolas, monospace; }

/* widgets */
.widget { border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin: 16px 0; background: #fbfcfe; }
.widget .row { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-start; }
.widget svg { display: block; background: #fff; border: 1px solid var(--line); border-radius: 8px; touch-action: none; }
.widget .main { flex: 1 1 380px; min-width: 0; }
.widget .main svg { width: 100%; height: auto; }
.widget .side { flex: 0 1 230px; display: flex; flex-direction: column; gap: 8px; }
.slider { display: grid; grid-template-columns: 30px 1fr 52px; align-items: center; gap: 6px; font-size: 14px; }
.slider b { font-family: ui-monospace, Consolas, monospace; }
.slider output { text-align: right; font-family: ui-monospace, Consolas, monospace; }
.slider input { width: 100%; }
.readout { font: 14px/1.6 ui-monospace, Consolas, monospace; background: #141a24; color: #e6edf5; border-radius: 8px; padding: 8px 10px; }
.status { font-size: 14px; min-height: 1.4em; }
.status.ok { color: var(--ok); } .status.err { color: var(--err); }
.widget .buttons { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.widget .hint { color: var(--muted); font-size: 13px; }
.legend { display: flex; gap: 16px; font-size: 14px; flex-wrap: wrap; margin-top: 8px; }
.legend i { display: inline-block; width: 22px; height: 0; border-top: 3px solid; vertical-align: middle; margin-right: 5px; }
svg .drag { cursor: grab; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 16px 16px 60px; }
  nav.toc { display: none; }
  main section { padding: 4px 16px 16px; }
  header { padding: 8px 16px; flex-wrap: wrap; }
  h1 { font-size: 26px; }
}
