:root {
  --bg: #f2f3f1;
  --surface: #fbfbfa;
  --ink: #171b21;
  --muted: #3d4654;
  --line: #c9cdc9;
  --accent: #0f5c9e;
  --accent-soft: #e8f1ff;
  --green: #1c6b45;
  --green-soft: #e9f4ee;
  --orange: #b4540a;
  --orange-soft: #fff1e4;
  --shadow: none;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(#e5e8e5 1px, transparent 1px),
    linear-gradient(90deg, #e5e8e5 1px, transparent 1px),
    var(--bg);
  background-size: 24px 24px;
  font-family: "Segoe UI", Arial, Helvetica, sans-serif;
  font-size: 14px;
  line-height: 1.4;
}

a {
  color: var(--accent);
}

.wiki-shell {
  width: min(100%, 1360px);
  margin: 0 auto;
  padding: 6px;
}

.wiki-topbar,
.wiki-sidebar,
.wiki-reader,
.wiki-rail {
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.wiki-topbar {
  display: grid;
  grid-template-columns: minmax(260px, 420px) 1fr;
  gap: 12px;
  align-items: start;
  margin-bottom: 6px;
  padding: 9px 12px;
  border-color: #171b21;
  background: #171b21;
}

.wiki-topbar h1,
.wiki-reader h2,
.wiki-rail h2,
.wiki-sidebar h2,
.wiki-article h1,
.wiki-article h2,
.wiki-article h3 {
  margin: 0;
  letter-spacing: 0;
}

.wiki-topbar h1 {
  color: #fbfbfa;
  font-size: 24px;
  font-weight: 800;
  line-height: 1;
}

.wiki-topbar p {
  margin: 4px 0 0;
  color: #d4d9df;
  font-size: 12px;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-family: "Courier New", Consolas, monospace;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.wiki-top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px;
}

.wiki-top-actions a,
.practice-link,
.rail-practice-link,
.sequence-buttons a,
.lab-shortcuts a {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 6px 9px;
  color: var(--ink);
  background: #fbfbfa;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.15;
  text-decoration: none;
}

.wiki-top-actions a {
  color: #f6f7f5;
  border-color: #49515a;
  background: #242a32;
}

.wiki-top-actions a:hover,
.sequence-buttons a:hover,
.lab-shortcuts a:hover,
.topic-link:hover {
  border-color: var(--accent);
}

.practice-link,
.rail-practice-link {
  border-color: var(--accent);
  color: white;
  background: var(--accent);
}

.wiki-layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 250px;
  gap: 6px;
  align-items: start;
}

.wiki-sidebar,
.wiki-rail {
  position: sticky;
  top: 6px;
  max-height: calc(100vh - 12px);
  overflow: auto;
  padding: 10px;
}

.wiki-search {
  margin-bottom: 12px;
}

.wiki-search label,
.topic-group h2,
.wiki-rail h2 {
  display: block;
  margin: 0 0 6px;
  color: var(--muted);
  font-family: "Courier New", Consolas, monospace;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.wiki-search input {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 7px 9px;
  color: var(--ink);
  font: inherit;
  background: #fbfbfa;
}

.wiki-status-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  margin-bottom: 10px;
}

.wiki-stat {
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 6px;
  background: #f5f6f4;
}

.wiki-stat strong {
  display: block;
  color: var(--accent);
  font-size: 18px;
  line-height: 1;
}

.wiki-stat span {
  color: var(--muted);
  font-family: "Courier New", Consolas, monospace;
  font-size: 9px;
  font-weight: 700;
  line-height: 1.2;
}

.topic-group {
  margin-bottom: 10px;
}

.topic-group ol {
  display: grid;
  gap: 3px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.topic-link {
  width: 100%;
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  gap: 6px;
  align-items: center;
  border: 1px solid transparent;
  border-radius: 3px;
  padding: 5px;
  color: var(--ink);
  font-size: 12px;
  text-align: left;
  text-decoration: none;
}

.topic-link.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.topic-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  border-radius: 3px;
  background: #e8f1ff;
  color: var(--accent);
  font-family: "Courier New", Consolas, monospace;
  font-size: 11px;
  font-weight: 800;
}

.topic-link span:last-child {
  overflow-wrap: anywhere;
}

.wiki-reader {
  min-width: 0;
  padding: 0;
  overflow: hidden;
}

.reader-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  border-top: 3px solid #171b21;
  background: #fbfbfa;
}

.reader-toolbar h2 {
  margin-top: 4px;
  font-size: 22px;
  font-weight: 800;
  line-height: 1.15;
}

.wiki-article {
  padding: 14px 16px 18px;
}

.wiki-article > * + * {
  margin-top: 10px;
}

.wiki-article h1 {
  font-size: 24px;
}

.wiki-article h2 {
  padding-top: 2px;
  font-size: 18px;
}

.wiki-article h3 {
  font-size: 15px;
}

.wiki-article p {
  margin-bottom: 0;
}

.wiki-article ul,
.wiki-article ol {
  padding-left: 24px;
}

.wiki-article li + li {
  margin-top: 4px;
}

.wiki-article code {
  border-radius: 3px;
  padding: 2px 5px;
  background: #e8f1ff;
  color: #26364d;
  font-size: .95em;
}

.wiki-article pre {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 12px;
  background: #101828;
  color: white;
}

.wiki-article pre code {
  padding: 0;
  background: transparent;
  color: inherit;
}

.mermaid-card {
  margin: 12px 0;
  border: 1px solid var(--line);
  border-radius: 3px;
  overflow: hidden;
  background: #fbfbfa;
}

.mermaid-stage {
  min-height: 160px;
  display: grid;
  place-items: center;
  padding: 12px;
  color: var(--muted);
  overflow: auto;
}

.mermaid-stage svg {
  max-width: 100%;
  height: auto;
}

.diagram-error {
  margin: 0;
  border: 1px solid #f2c4b7;
  border-radius: 3px;
  padding: 10px 12px;
  color: var(--orange);
  background: var(--orange-soft);
  font-weight: 700;
}

.mermaid-source {
  border-top: 1px solid var(--line);
  background: #fbfbfa;
}

.mermaid-source summary {
  cursor: pointer;
  padding: 10px 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.mermaid-source pre {
  margin: 0 12px 12px;
}

.wiki-table-wrap {
  overflow: auto;
}

.wiki-article table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.wiki-article th,
.wiki-article td {
  border: 1px solid var(--line);
  padding: 6px 8px;
  text-align: left;
  vertical-align: top;
}

.wiki-article th {
  background: var(--accent-soft);
}

.checklist {
  padding-left: 0;
  list-style: none;
}

.checklist li {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.checkmark {
  flex: 0 0 auto;
  min-width: 22px;
  height: 22px;
  border: 1px solid var(--line);
  border-radius: 3px;
  color: var(--green);
  background: var(--green-soft);
  text-align: center;
  font-weight: 800;
}

.wiki-rail {
  display: grid;
  gap: 10px;
}

.wiki-rail section {
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.wiki-rail section:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.wiki-rail p {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
}

.sequence-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.sequence-buttons a[aria-disabled="true"] {
  opacity: .45;
  pointer-events: none;
}

.page-outline,
.lab-shortcuts {
  display: grid;
  gap: 4px;
}

.page-outline a,
.lab-shortcuts a {
  justify-content: flex-start;
  min-height: 30px;
  padding: 6px 8px;
  font-size: 12px;
}

.page-outline a {
  border: 0;
  color: var(--muted);
  background: transparent;
}

.page-outline a:hover {
  color: var(--accent);
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 3px;
  padding: 10px;
  color: var(--muted);
  background: #fbfbfa;
}

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

  .wiki-rail {
    position: static;
    grid-column: 1 / -1;
    max-height: none;
  }
}

@media (max-width: 760px) {
  .wiki-shell {
    padding: 6px;
  }

  .reader-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .wiki-topbar {
    grid-template-columns: 1fr;
  }

  .wiki-top-actions {
    justify-content: flex-start;
  }

  .wiki-layout {
    grid-template-columns: 1fr;
  }

  .wiki-sidebar,
  .wiki-rail {
    position: static;
    max-height: none;
  }

  .wiki-article {
    padding: 16px;
  }
}
