/* ═══════════════════════════════════════════════════════════════════
   x86/x64 Assembly Book — Shared Stylesheet
   ═══════════════════════════════════════════════════════════════════ */

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

/* ── Design tokens (dark theme default) ── */
:root {
  --bg:          #0d1117;
  --bg-sec:      #161b22;
  --bg-hover:    #1c2128;
  --border:      #30363d;
  --text:        #e6edf3;
  --text-muted:  #8b949e;
  --text-subtle: #6e7681;
  --accent:      #58a6ff;
  --accent-dim:  #1f6feb;

  /* Callout accent colors */
  --c-why:     #1f6feb;
  --c-wild:    #8b5cf6;
  --c-mistake: #f85149;
  --c-try:     #3fb950;
  --c-mental:  #d29922;

  /* Syntax highlight tokens */
  --syn-keyword:     #ff7b72;
  --syn-string:      #a5d6ff;
  --syn-comment:     #8b949e;
  --syn-number:      #79c0ff;
  --syn-register:    #ffa657;
  --syn-mnemonic:    #d2a8ff;
  --syn-label:       #7ee787;
  --syn-directive:   #f0883e;

  --sidebar-width: 290px;
  --content-max:   800px;
}

[data-theme="light"] {
  --bg:          #ffffff;
  --bg-sec:      #f6f8fa;
  --bg-hover:    #eef1f4;
  --border:      #d0d7de;
  --text:        #1f2328;
  --text-muted:  #636c76;
  --text-subtle: #818b98;
  --accent:      #0969da;
  --accent-dim:  #dbeafe;

  --c-why:     #0969da;
  --c-wild:    #7c3aed;
  --c-mistake: #cf222e;
  --c-try:     #1a7f37;
  --c-mental:  #9a6700;
}

/* ── Base ── */
html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.75;
  display: flex;
}

/* ══════════════════════════════════════
   SIDEBAR
   ══════════════════════════════════════ */
.sidebar {
  position: fixed;
  left: 0; top: 0;
  width: var(--sidebar-width);
  height: 100vh;
  overflow-y: auto;
  background: var(--bg-sec);
  border-right: 1px solid var(--border);
  z-index: 100;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 1.25rem 1.1rem;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0;
  background: var(--bg-sec);
  z-index: 10;
}
.sidebar-header .book-series {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-subtle);
  margin-bottom: 0.2rem;
}
.sidebar-header .book-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}

.sidebar-nav { flex: 1; padding-bottom: 2rem; }

/* Part groups */
.nav-part { }
.nav-part-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1.1rem 0.3rem;
  cursor: pointer;
  user-select: none;
}
.nav-part-label {
  font-size: 0.63rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-subtle);
}
.nav-part-toggle {
  color: var(--text-subtle);
  font-size: 0.6rem;
  transition: transform 0.2s ease;
  display: inline-block;
}
.nav-part.collapsed .nav-part-toggle { transform: rotate(-90deg); }
.nav-part.collapsed .nav-chapters { display: none; }

/* Chapter links */
.nav-chapters { }
.nav-ch {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.28rem 1.1rem 0.28rem 1.4rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-decoration: none;
  border-left: 2px solid transparent;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
  line-height: 1.4;
}
.nav-ch:hover { background: var(--bg-hover); color: var(--text); }
.nav-ch.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--bg-hover);
  font-weight: 500;
}
.nav-ch .ch-n {
  font-size: 0.65rem;
  color: var(--text-subtle);
  min-width: 1.8rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

/* ══════════════════════════════════════
   MAIN CONTENT
   ══════════════════════════════════════ */
.content {
  margin-left: var(--sidebar-width);
  padding: 2.5rem 4rem 5rem;
  flex: 1;
  min-width: 0;
}

article { max-width: var(--content-max); }

/* ── Breadcrumb ── */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 2.5rem;
}
.breadcrumb .sep { color: var(--text-subtle); }
.breadcrumb a { color: var(--accent); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }

/* ── Chapter header ── */
.chapter-header {
  margin-bottom: 3rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border);
}
.ch-number {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  margin-bottom: 0.6rem;
}
.chapter-header h1 {
  font-size: 2.1rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
  letter-spacing: -0.01em;
  margin-bottom: 0.9rem;
}
.ch-subtitle {
  font-size: 1.05rem;
  color: var(--text-muted);
  line-height: 1.65;
  max-width: 660px;
}

/* ── Section headings ── */
h2 {
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--text);
  margin: 3rem 0 1rem;
  padding-top: 0.25rem;
  scroll-margin-top: 1.5rem;
  letter-spacing: -0.01em;
}
h3 {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  margin: 2rem 0 0.75rem;
  scroll-margin-top: 1.5rem;
}
h4 {
  font-size: 0.9rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 1.5rem 0 0.5rem;
}

/* ── Body text ── */
p { margin-bottom: 1.1rem; }
p:last-child { margin-bottom: 0; }

ul, ol {
  padding-left: 1.6rem;
  margin-bottom: 1.1rem;
}
li { margin-bottom: 0.35rem; }
li:last-child { margin-bottom: 0; }
li p { margin-bottom: 0.3rem; }

strong { color: var(--text); font-weight: 600; }
em { font-style: italic; }

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.5rem 0;
}

/* ── Inline code ── */
:not(pre) > code {
  font-family: 'Fira Code', 'Cascadia Code', 'Consolas', 'Courier New', monospace;
  font-size: 0.84em;
  background: var(--bg-sec);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1em 0.4em;
  color: var(--syn-register);
  white-space: nowrap;
}

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

/* ══════════════════════════════════════
   CALLOUT BOXES
   ══════════════════════════════════════ */
.callout {
  border-left: 4px solid;
  padding: 1rem 1.3rem;
  margin: 2rem 0;
  border-radius: 0 8px 8px 0;
  background: var(--bg-sec);
}
.callout-label {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.callout-label::before {
  content: '';
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
.callout p:last-child,
.callout ul:last-child,
.callout ol:last-child { margin-bottom: 0; }
.callout code { background: var(--bg); }

.callout.why     { border-color: var(--c-why); }
.callout.why     .callout-label { color: var(--c-why); }
.callout.wild    { border-color: var(--c-wild); }
.callout.wild    .callout-label { color: var(--c-wild); }
.callout.mistake { border-color: var(--c-mistake); }
.callout.mistake .callout-label { color: var(--c-mistake); }
.callout.try     { border-color: var(--c-try); }
.callout.try     .callout-label { color: var(--c-try); }
.callout.mental  { border-color: var(--c-mental); }
.callout.mental  .callout-label { color: var(--c-mental); }

/* ══════════════════════════════════════
   DIAGRAM BLOCKS
   ══════════════════════════════════════ */
.diagram {
  background: var(--bg-sec);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.4rem 1.6rem;
  margin: 2rem 0;
  overflow-x: auto;
}
.diagram-title {
  font-size: 0.63rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 1rem;
}
.diagram pre {
  font-family: 'Fira Code', 'Cascadia Code', 'Consolas', 'Courier New', monospace;
  font-size: 0.82rem;
  line-height: 1.65;
  color: var(--text);
  margin: 0;
  white-space: pre;
}

/* ══════════════════════════════════════
   CODE BLOCKS
   ══════════════════════════════════════ */
.code-block {
  margin: 1.75rem 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.code-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.45rem 1rem;
  background: var(--bg-sec);
  border-bottom: 1px solid var(--border);
}
.code-lang {
  font-size: 0.63rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}
.code-filename {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: 'Fira Code', 'Cascadia Code', monospace;
}
.copy-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.18rem 0.6rem;
  border-radius: 4px;
  font-size: 0.68rem;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.copy-btn:hover   { background: var(--accent); color: #fff; border-color: var(--accent); }
.copy-btn.copied  { background: var(--c-try);  color: #fff; border-color: var(--c-try); }

.code-block pre {
  margin: 0;
  padding: 1.2rem 1.5rem;
  overflow-x: auto;
  background: #0d1117 !important;
}
[data-theme="light"] .code-block pre { background: #f6f8fa !important; }

.code-block pre code {
  font-family: 'Fira Code', 'Cascadia Code', 'Consolas', monospace !important;
  font-size: 0.85rem;
  background: none !important;
  border: none !important;
  padding: 0 !important;
  color: var(--text);
  white-space: none !important;
}

/* ══════════════════════════════════════
   COMPARISON PANES (two-column side by side)
   ══════════════════════════════════════ */
.compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin: 2rem 0;
}
.compare .code-block { margin: 0; }

/* ══════════════════════════════════════
   TABLES
   ══════════════════════════════════════ */
.table-wrap { overflow-x: auto; margin: 2rem 0; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
thead th {
  text-align: left;
  padding: 0.55rem 1rem;
  background: var(--bg-sec);
  color: var(--text-muted);
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: 0.55rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: top;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg-sec); }
td code { font-size: 0.8em; }

/* ══════════════════════════════════════
   REGISTER STATE VISUALIZER
   ══════════════════════════════════════ */
.regstate {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.5rem;
  background: var(--bg-sec);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  margin: 1.5rem 0;
  font-family: 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  font-size: 0.8rem;
}
.reg-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.reg-name {
  color: var(--syn-register);
  min-width: 3.5rem;
  font-weight: 600;
}
.reg-val {
  color: var(--text-muted);
  font-size: 0.78rem;
}
.reg-val.changed {
  color: var(--c-try);
  font-weight: 600;
}
.reg-val.highlight {
  color: var(--syn-mnemonic);
  font-weight: 600;
}

/* ══════════════════════════════════════
   KBD (keyboard shortcuts)
   ══════════════════════════════════════ */
kbd {
  display: inline-block;
  font-family: 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  font-size: 0.78em;
  padding: 0.1em 0.45em;
  background: var(--bg-sec);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  color: var(--text);
  white-space: nowrap;
}

/* ══════════════════════════════════════
   CHAPTER NAVIGATION (prev / next)
   ══════════════════════════════════════ */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
  gap: 1rem;
}
.chapter-nav a {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 1rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s;
  max-width: 48%;
  min-width: 0;
}
.chapter-nav a:hover { border-color: var(--accent); }
.chapter-nav .nav-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-muted);
}
.chapter-nav .nav-title {
  font-size: 0.88rem;
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chapter-nav .nav-arrow { color: var(--accent); }
.chapter-nav .nav-next { margin-left: auto; text-align: right; }
.chapter-nav .nav-spacer { flex: 1; }

/* ══════════════════════════════════════
   THEME TOGGLE
   ══════════════════════════════════════ */
.theme-toggle {
  position: fixed;
  top: 1rem;
  right: 1.5rem;
  background: var(--bg-sec);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.35rem 0.85rem;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-family: inherit;
  z-index: 200;
  transition: border-color 0.15s, color 0.15s;
  letter-spacing: 0.02em;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }

/* ══════════════════════════════════════
   SCROLLBAR
   ══════════════════════════════════════ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-subtle); }

/* ══════════════════════════════════════
   UTILITY
   ══════════════════════════════════════ */
.text-muted  { color: var(--text-muted); }
.text-subtle { color: var(--text-subtle); }
.mono { font-family: 'Fira Code', 'Cascadia Code', 'Consolas', monospace; }

/* Section anchor offset */
section { scroll-margin-top: 1.5rem; }

/* ══════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════ */
@media (max-width: 900px) {
  .sidebar { display: none; }
  .content { margin-left: 0; padding: 1.5rem 1.5rem 3rem; }
  .compare { grid-template-columns: 1fr; }
}
