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

:root {
  --bg: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --text: #e6edf3;
  --text-secondary: #8b949e;
  --border: #30363d;
  --accent: #58a6ff;
  --accent-hover: #79c0ff;
  --green: #3fb950;
  --orange: #d29922;
  --red: #f85149;
  --purple: #bc8cff;
  --nav-width: 260px;
  --header-height: 60px;
}

[data-theme="light"] {
  --bg: #ffffff;
  --bg-secondary: #f6f8fa;
  --bg-tertiary: #e1e4e8;
  --text: #1f2328;
  --text-secondary: #656d76;
  --border: #d0d7de;
  --accent: #0969da;
  --accent-hover: #0550ae;
  --green: #1a7f37;
  --orange: #9a6700;
  --red: #cf222e;
  --purple: #8250df;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: background 0.3s, color 0.3s;
}

/* Header */
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 100;
}

.header h1 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

.header h1 span { color: var(--accent); }

.header-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.theme-toggle {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.2s;
}

.theme-toggle:hover { background: var(--border); }

/* Sidebar */
.sidebar {
  position: fixed;
  top: var(--header-height);
  left: 0;
  bottom: 0;
  width: var(--nav-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px 0;
  z-index: 90;
  transition: transform 0.3s;
}

.sidebar-toggle {
  display: none;
  position: fixed;
  top: calc(var(--header-height) + 8px);
  left: 8px;
  z-index: 95;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 18px;
}

.nav-section {
  padding: 8px 16px 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
}

.nav-link {
  display: block;
  padding: 6px 16px 6px 24px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  border-left: 2px solid transparent;
  transition: all 0.2s;
}

.nav-link:hover, .nav-link.active {
  color: var(--accent);
  background: var(--bg-tertiary);
  border-left-color: var(--accent);
}

/* Main */
.main {
  margin-left: var(--nav-width);
  margin-top: var(--header-height);
  padding: 32px 40px;
}

/* Sections */
section {
  margin-bottom: 48px;
}

section > h2 {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

section > h2 .section-num {
  color: var(--accent);
  font-weight: 400;
  margin-right: 8px;
}

h3 {
  font-size: 18px;
  font-weight: 600;
  margin: 24px 0 12px;
  color: var(--text);
}

p {
  margin-bottom: 12px;
  color: var(--text-secondary);
}

.lead {
  font-size: 16px;
  color: var(--text);
  margin-bottom: 24px;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
  margin: 16px 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th, td {
  padding: 10px 14px;
  text-align: left;
  border: 1px solid var(--border);
}

th {
  background: var(--bg-tertiary);
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

td { color: var(--text-secondary); }

tr:hover td { background: var(--bg-secondary); }

.col-order { width: 50px; text-align: center; }
.col-name { width: 160px; }
.col-example { min-width: 260px; max-width: 400px; }
.col-example code { display: block; white-space: pre-wrap; word-break: break-word; font-size: 12px; line-height: 1.4; max-height: 120px; overflow-y: auto; padding: 6px 8px; }

td code, p code {
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  color: var(--accent);
}

/* Flow diagram */
.flow {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  margin: 24px 0;
}

.flow-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  width: 100%;
}

.flow-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 18px;
  text-align: center;
  font-size: 13px;
  min-width: 180px;
  transition: border-color 0.2s, transform 0.2s;
}

.flow-box:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.flow-box .flow-title {
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.flow-box .flow-file {
  font-size: 11px;
  color: var(--text-secondary);
  font-family: monospace;
}

.flow-box.core {
  border-color: var(--accent);
  background: rgba(88, 166, 255, 0.08);
}

.flow-box.hook {
  border-color: var(--purple);
  background: rgba(188, 140, 255, 0.08);
}

.flow-box.entry {
  border-color: var(--green);
  background: rgba(63, 185, 80, 0.08);
}

.flow-arrow {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 4px 0;
  color: var(--text-secondary);
  font-size: 18px;
}

.flow-arrow.wide {
  width: 100%;
}

.flow-converge {
  display: flex;
  justify-content: center;
  gap: 16px;
  width: 100%;
  position: relative;
}

.flow-converge::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 50%;
  transform: translateX(-50%);
  width: 2px;
  height: 12px;
  background: var(--text-secondary);
}

.flow-branch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}

/* Collapsible */
.collapsible {
  margin: 12px 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.collapsible-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--bg-secondary);
  cursor: pointer;
  user-select: none;
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  transition: background 0.2s;
}

.collapsible-header:hover { background: var(--bg-tertiary); }

.collapsible-arrow {
  transition: transform 0.2s;
  font-size: 12px;
  color: var(--text-secondary);
}

.collapsible.open .collapsible-arrow { transform: rotate(90deg); }

.collapsible-body {
  display: none;
  padding: 16px;
  border-top: 1px solid var(--border);
}

.collapsible.open .collapsible-body { display: block; }

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.badge-full { background: rgba(63, 185, 80, 0.15); color: var(--green); }
.badge-minimal { background: rgba(210, 153, 34, 0.15); color: var(--orange); }
.badge-none { background: rgba(248, 81, 73, 0.15); color: var(--red); }

/* Code blocks */
pre {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.5;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  color: var(--text);
  margin: 12px 0;
}

/* Mode comparison cards */
.mode-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin: 16px 0;
}

.mode-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.mode-card-header {
  padding: 12px 16px;
  font-weight: 600;
  font-size: 16px;
  border-bottom: 1px solid var(--border);
}

.mode-card-header.full { background: rgba(63, 185, 80, 0.1); color: var(--green); border-top: 3px solid var(--green); }
.mode-card-header.minimal { background: rgba(210, 153, 34, 0.1); color: var(--orange); border-top: 3px solid var(--orange); }
.mode-card-header.none { background: rgba(248, 81, 73, 0.1); color: var(--red); border-top: 3px solid var(--red); }

.mode-card-body {
  padding: 12px 16px;
}

.mode-card-body p {
  font-size: 13px;
  margin-bottom: 8px;
}

.mode-card-body ul {
  list-style: none;
  padding: 0;
}

.mode-card-body li {
  padding: 4px 0;
  font-size: 13px;
  color: var(--text-secondary);
}

.mode-card-body li::before {
  content: '\2022';
  color: var(--accent);
  margin-right: 8px;
}

/* Channel grid */
.channel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin: 16px 0;
}

.channel-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}

.channel-card h4 {
  font-size: 15px;
  margin-bottom: 8px;
  color: var(--text);
}

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

.channel-card li {
  font-size: 12px;
  color: var(--text-secondary);
  padding: 2px 0;
}

.channel-card li::before {
  content: '\2192';
  color: var(--accent);
  margin-right: 6px;
}

/* Footer */
.footer {
  margin-top: 64px;
  padding: 24px 0;
  border-top: 1px solid var(--border);
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
}

/* Responsive */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: block; }
  .main { margin-left: 0; padding: 24px 16px; }
  .mode-cards { grid-template-columns: 1fr; }
  .flow-row { flex-direction: column; }
}

@media (max-width: 600px) {
  .header h1 { font-size: 14px; }
  .main { padding: 16px 12px; }
  section > h2 { font-size: 20px; }
  table { font-size: 12px; }
  th, td { padding: 6px 8px; }
}

/* Scroll offset for fixed header */
section[id] { scroll-margin-top: calc(var(--header-height) + 16px); }

/* Highlight row on hover */
.section-table tr[data-modes] { cursor: default; }

/* Annotated prompt */
.prompt-annotated {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.6;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  color: var(--text);
  margin: 12px 0;
}

.prompt-annotated .section-label {
  display: inline-block;
  background: rgba(88, 166, 255, 0.15);
  color: var(--accent);
  padding: 1px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  margin: 8px 0 2px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
}

.prompt-annotated .prompt-line {
  color: var(--text-secondary);
}

.prompt-annotated .prompt-line.dim {
  color: var(--border);
  font-style: italic;
}

/* Topic cards (landing page) */
.topic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
  margin: 24px 0;
}

.topic-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
  text-decoration: none;
  transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
  display: block;
}

.topic-card:hover {
  border-color: var(--accent);
  transform: translateY(-3px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.topic-card .topic-num {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.topic-card h3 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 8px;
}

.topic-card p {
  font-size: 14px;
  color: var(--text-secondary);
  margin: 0;
  line-height: 1.5;
}

.topic-card .topic-arrow {
  margin-top: 16px;
  font-size: 13px;
  color: var(--accent);
  font-weight: 500;
}

.topic-card.coming-soon {
  opacity: 0.5;
  cursor: default;
  border-style: dashed;
}

.topic-card.coming-soon:hover {
  border-color: var(--border);
  transform: none;
  box-shadow: none;
}

/* Landing page main (no sidebar) */
.main-landing {
  margin-top: var(--header-height);
  padding: 48px 40px;
  max-width: 960px;
  margin-left: auto;
  margin-right: auto;
}

/* Back link */
.back-link {
  display: inline-block;
  color: var(--accent);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  padding: 4px 0;
  margin-bottom: 8px;
  transition: color 0.2s;
}

.back-link:hover {
  color: var(--accent-hover);
}

@media (max-width: 600px) {
  .main-landing { padding: 24px 16px; }
  .topic-grid { grid-template-columns: 1fr; }
}
