*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-dark:     #1e1e2e;
  --bg-medium:   #252537;
  --bg-light:    #2f2f47;
  --bg-lighter:  #3a3a58;
  --accent:      #00b4d8;
  --accent-hover:#0090b0;
  --accent-dim:  rgba(0,180,216,0.1);
  --text:        #e8e8f0;
  --text-muted:  #8888aa;
  --border:      #3a3a58;
  --success:     #4ade80;
  --warning:     #fbbf24;
  --danger:      #f87171;
  --radius:      6px;
  --toc-w:       220px;
  --content-max: 860px;
}

html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-dark);
  color: var(--text);
  font-size: 14px;
  line-height: 1.7;
}

/* ── Top nav ── */
.topnav {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 24px;
  background: var(--bg-medium);
  border-bottom: 1px solid var(--border);
}

.back-btn {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  font-size: 13px;
  padding: 5px 12px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  transition: background 0.15s;
  white-space: nowrap;
}
.back-btn:hover { background: var(--accent-dim); }

.nav-title {
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
  flex: 1;
}

.nav-version {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-lighter);
  padding: 2px 8px;
  border-radius: 10px;
}

/* ── Layout ── */
.layout {
  display: flex;
  max-width: 1140px;
  margin: 0 auto;
  padding: 32px 24px;
  gap: 40px;
  align-items: flex-start;
}

/* ── TOC sidebar ── */
.toc {
  position: sticky;
  top: 58px;
  width: var(--toc-w);
  min-width: var(--toc-w);
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  padding: 16px;
  background: var(--bg-medium);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
}

.toc::-webkit-scrollbar { width: 3px; }
.toc::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.toc-heading {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.toc ul {
  list-style: none;
  padding: 0;
}

.toc > ul > li { margin-bottom: 4px; }

.toc a {
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s;
  display: block;
  padding: 2px 0;
}
.toc a:hover { color: var(--accent); }

.toc ul ul {
  padding-left: 12px;
  margin-top: 2px;
  border-left: 1px solid var(--border);
}
.toc ul ul a { font-size: 12px; }

/* ── Content ── */
.content {
  flex: 1;
  min-width: 0;
  max-width: var(--content-max);
}

h1 {
  font-size: 28px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 8px;
  line-height: 1.2;
}

h1 .subtitle {
  font-size: 16px;
  font-weight: 400;
  color: var(--text-muted);
  display: block;
  margin-top: 4px;
}

.lead {
  font-size: 15px;
  color: var(--text-muted);
  margin-bottom: 40px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 24px;
}

section {
  margin-bottom: 56px;
  scroll-margin-top: 72px;
}

h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin: 24px 0 10px;
}

h4 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin: 16px 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

p { margin-bottom: 12px; }

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

ul, ol {
  padding-left: 20px;
  margin-bottom: 12px;
}
li { margin-bottom: 6px; }

/* ── Quick start steps ── */
.steps { display: grid; gap: 12px; }

.step {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  background: var(--bg-medium);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.step-num {
  width: 28px;
  height: 28px;
  min-width: 28px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  font-size: 14px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.step-body strong {
  display: block;
  margin-bottom: 2px;
  font-size: 14px;
}

.step-body p { margin: 0; color: var(--text-muted); font-size: 13px; }

/* ── Diagram ── */
.diagram {
  display: flex;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin: 16px 0;
  font-size: 12px;
}

.diagram-sidebar {
  background: var(--bg-medium);
  width: 260px;
  min-width: 260px;
  border-right: 1px solid var(--border);
}

.dia-row {
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
}
.dia-row:last-child { border-bottom: none; }
.dia-row.highlight { color: var(--text); background: var(--bg-light); }

.diagram-map {
  flex: 1;
  background: #1a2a1a;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px;
  color: var(--text-muted);
  text-align: center;
  min-height: 180px;
}

.diagram-map span:first-child {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
}

.dia-sub { font-size: 12px; line-height: 1.6; }

/* ── Callouts ── */
.callout {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin: 14px 0;
  font-size: 13px;
  line-height: 1.6;
  border-left: 3px solid;
}

.callout.info    { background: rgba(0,180,216,0.08);  border-color: var(--accent);  color: #b8eaf4; }
.callout.warning { background: rgba(251,191,36,0.08); border-color: var(--warning); color: #fde68a; }
.callout.danger  { background: rgba(248,113,113,0.08);border-color: var(--danger);  color: #fca5a5; }

/* ── Formula ── */
.formula {
  background: var(--bg-medium);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  padding: 12px 16px;
  border-radius: var(--radius);
  font-family: 'Courier New', Courier, monospace;
  font-size: 13px;
  color: var(--accent);
  margin: 14px 0;
}

/* ── Two column ── */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 12px 0;
}

.two-col > div {
  background: var(--bg-medium);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.two-col strong { display: block; color: var(--accent); margin-bottom: 6px; }
.two-col p { margin: 0; font-size: 13px; color: var(--text-muted); }

/* ── Tables ── */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0;
  font-size: 13px;
}

th {
  background: var(--bg-lighter);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 9px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 9px 12px;
  border-bottom: 1px solid rgba(58,58,88,0.5);
  vertical-align: top;
}

tr:last-child td { border-bottom: none; }
tr:nth-child(even) td { background: rgba(255,255,255,0.02); }

.table-note {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 8px;
  font-style: italic;
}

/* ── Compat table badges ── */
.yes     { color: var(--success); font-weight: 600; }
.no      { color: var(--danger);  font-weight: 600; }
.partial { color: var(--warning); font-weight: 600; }
.badge-red { color: var(--danger); font-weight: 600; }

/* ── File tree ── */
.file-tree {
  background: var(--bg-medium);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin: 14px 0;
  font-family: 'Courier New', Courier, monospace;
  font-size: 13px;
}

.ft-item { padding: 3px 0; }
.ft-folder { color: var(--accent); font-weight: 700; }
.ft-file { color: var(--text); padding-left: 12px; }
.ft-desc { color: var(--text-muted); font-family: sans-serif; font-size: 12px; }

/* ── Keyboard ── */
kbd {
  background: var(--bg-lighter);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 12px;
  font-family: inherit;
  color: var(--text);
  white-space: nowrap;
}

/* ── Details / Accordion ── */
details {
  background: var(--bg-medium);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  overflow: hidden;
}

summary {
  padding: 13px 16px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}

summary::before {
  content: '▶';
  color: var(--accent);
  font-size: 10px;
  transition: transform 0.2s;
  flex-shrink: 0;
}

details[open] summary::before { transform: rotate(90deg); }
details[open] summary { border-bottom: 1px solid var(--border); }

details > *:not(summary) {
  padding: 14px 16px;
  font-size: 13px;
  color: var(--text-muted);
}

details ul, details ol { color: var(--text-muted); }

/* ── Footer ── */
.page-footer {
  text-align: center;
  padding: 24px;
  color: var(--text-muted);
  font-size: 12px;
  border-top: 1px solid var(--border);
  margin-top: 24px;
}

/* ── Responsive ── */
@media (max-width: 800px) {
  .layout { flex-direction: column; padding: 16px; gap: 24px; }
  .toc { position: static; width: 100%; min-width: 0; max-height: none; }
  .diagram { flex-direction: column; }
  .diagram-sidebar { width: 100%; min-width: 0; border-right: none; border-bottom: 1px solid var(--border); }
  .two-col { grid-template-columns: 1fr; }
  h1 { font-size: 22px; }
}
