:root {
  --bg: #071113;
  --panel: #0d191d;
  --border: #40515a;
  --text: #f4f4f0;
  --muted: #a4abb0;
  --accent: #c39bf0;
  --accent-bg: #9b5de5;
  --on-accent: #071113;
  --line: 1.5rem;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 400 15px/var(--line) var(--mono);
}

a { color: var(--accent); text-underline-offset: 3px; }
a:hover { background: var(--accent-bg); color: var(--on-accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

kbd { color: var(--accent); font: inherit; font-weight: 700; }

.skip {
  position: absolute;
  left: 1ch;
  top: -4rem;
  z-index: 10;
  background: var(--accent-bg);
  color: var(--on-accent);
  padding: 0 1ch;
}
.skip:focus { top: 0; }

.app {
  display: grid;
  grid-template: "title title" auto "side main" minmax(0, 1fr) "status status" auto / 26ch minmax(0, 1fr);
  gap: 0 1ch;
  height: 100dvh;
  padding: 0 1ch;
}

.app:not(:has(.sidebar)) {
  grid-template: "title" auto "main" minmax(0, 1fr) "status" auto / minmax(0, 1fr);
}
.app:not(:has(.sidebar)) .content { padding-inline: 1ch; }
.app:not(:has(.sidebar)) .content > * { margin-inline: auto; }

.titlebar {
  grid-area: title;
  display: flex;
  gap: 2ch;
  align-items: baseline;
  padding: 0 1ch;
  margin: 0 -1ch .75rem;
  background: var(--accent-bg);
  color: var(--on-accent);
}
.titlebar a { color: inherit; }
.titlebar > a { font-weight: 700; text-decoration: none; }
.path { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lang { display: flex; gap: 1ch; }
.lang a { text-decoration: none; padding: 0 .5ch; }
.lang a[aria-current] { background: var(--on-accent); color: var(--text); }

.legend {
  margin: 0;
  color: var(--accent);
  font-weight: 700;
  text-transform: lowercase;
}

.sidebar, .pane, details { border: 1px solid var(--border); }

.sidebar {
  grid-area: side;
  position: relative;
  padding: 1rem 1ch;
  align-self: start;
}
.sidebar .legend, .pane > .legend {
  position: absolute;
  top: calc(var(--line) / -2);
  left: 1ch;
  max-width: calc(100% - 2ch);
  padding: 0 1ch;
  background: var(--bg);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar a {
  display: block;
  padding: 0 1ch;
  color: var(--text);
  text-decoration: none;
}
.sidebar a[aria-current] { background: var(--accent-bg); color: var(--on-accent); font-weight: 700; }
.sidebar a[aria-current] kbd { color: inherit; }

.content {
  grid-area: main;
  overflow-y: auto;
  padding: 0 2ch var(--line) 1ch;
  scrollbar-color: var(--border) transparent;
}
.content > * { max-width: 792px; }
.content:focus-visible { outline-offset: -2px; }

h1, h2, h3, h4, h5, h6 { font-size: 1rem; line-height: var(--line); margin: 0 0 var(--line); font-weight: 700; }
h1 { font-size: 1.25rem; }
h1::before { content: "# "; color: var(--accent); }
.pane > h2::before, .pane > h3::before, .pane > h4::before { content: "## "; color: var(--accent); }

p { margin: 0 0 var(--line); }
.muted { color: var(--muted); }

.banner {
  margin: var(--line) 0;
  color: var(--accent);
  font: 700 clamp(7px, 1.6vw, 13px)/1.05 var(--mono);
  overflow: hidden;
}

.command { color: var(--muted); }
.command span { color: var(--accent); }
.cursor {
  display: inline-block;
  width: 1ch;
  height: 1em;
  margin-left: 1ch;
  vertical-align: text-bottom;
  background: var(--accent);
  animation: blink 1.2s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.pane {
  position: relative;
  margin: var(--line) 0;
  padding: var(--line) 2ch 0;
  background: var(--panel);
}
.pane .legend { background: var(--panel); }
.content > .pane > .legend { background: linear-gradient(var(--bg) 50%, var(--panel) 50%); }
.pane .pane { background: var(--bg); }
.pane .pane > .legend { background: linear-gradient(var(--panel) 50%, var(--bg) 50%); }
details .pane > .legend { background: linear-gradient(var(--bg) 50%, var(--bg) 50%); }

.steps, .bullets, .links { margin: 0 0 var(--line); padding: 0; list-style: none; }
.steps li { display: grid; grid-template-columns: 4ch minmax(0, 1fr); }
.steps h3, .steps h4, .steps h5, .steps h6 { margin: 0; }
.steps p { color: var(--muted); }
.num { color: var(--accent); }
.bullets li { padding-left: 2ch; text-indent: -2ch; }
.bullets li::before { content: "▪ "; color: var(--accent); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(22ch, 1fr)); gap: var(--line) 2ch; margin: 0 0 var(--line); }
.stats dt { color: var(--accent); font-size: 1.25rem; font-weight: 700; }
.stats dd { margin: 0; color: var(--muted); }

figure { margin: 0 0 var(--line); max-width: 40ch; }
img { display: block; max-width: 100%; height: auto; }
figcaption { color: var(--muted); }

.diagram {
  margin: 0 0 var(--line);
  padding: 1ch;
  overflow-x: auto;
  border-left: 2px solid var(--accent-bg);
  color: var(--muted);
  font: inherit;
}

details { margin: 0 0 var(--line); padding: 0 2ch; }
summary { margin: 0 -2ch; padding: 0 2ch; color: var(--accent); cursor: pointer; font-weight: 700; }
summary:hover { background: var(--accent-bg); color: var(--on-accent); }
details[open] > summary { margin-bottom: var(--line); }

.statusbar {
  grid-area: status;
  display: flex;
  flex-wrap: wrap;
  gap: 0 3ch;
  margin: .75rem -1ch 0;
  padding: 0 1ch;
  background: var(--panel);
  color: var(--muted);
}
.statusbar a { color: inherit; }
.statusbar button {
  margin-left: auto;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

dialog {
  width: min(44ch, calc(100vw - 2rem));
  padding: 1rem 2ch;
  border: 1px solid var(--accent);
  background: var(--panel);
  color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / .6); }
dialog dl { margin: var(--line) 0 0; }
dialog dl div { display: grid; grid-template-columns: 10ch 1fr; }
dialog dd { margin: 0; }

@media (max-width: 760px) {
  html, body { height: auto; }
  .app { display: block; height: auto; }
  .titlebar { position: sticky; top: 0; z-index: 5; margin-bottom: .75rem; }
  .sidebar { margin-bottom: var(--line); }
  .sidebar ul { display: grid; grid-template-columns: 1fr 1fr; }
  .sidebar kbd { display: none; }
  .sidebar a { padding: .35rem 1ch; }
  .content { overflow: visible; padding: 0 0 var(--line); }
  .pane { padding-inline: 1ch; }
  details { padding-inline: 1ch; }
  summary { margin-inline: -1ch; padding-inline: 1ch; }
  #help-open { display: none; }
  .links a, .statusbar a { display: inline-block; padding-block: .35rem; }
}

@media (prefers-reduced-motion: reduce) {
  .cursor { animation: none; }
}

/* A story sits inside a pane already, so it adds no border of its own. */
.pane details { border: 0; padding: 0; }
.pane summary { margin-inline: 0; padding: 0; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* A single published page: no app chrome, just the page, centred. */
.app:not(:has(.titlebar)) { display: grid; grid-template: auto / auto; place-content: center; height: 100dvh; padding: 2ch; }
.app:not(:has(.titlebar)) .content { grid-area: auto; width: fit-content; max-width: 100%; padding: 0; overflow: visible; }
.app:not(:has(.titlebar)) .banner { font-size: clamp(7px, 2.4vw, 20px); }
.app:not(:has(.titlebar)) .links { margin: 0; }
.app:not(:has(.titlebar)) .content,
.app:not(:has(.titlebar)) .banner { text-align: center; }
