/* ===== BASE BOOK CSS ===== */

/* Default styles provided by pandoc.
    ** See https://pandoc.org/MANUAL.html#variables-for-html for config info.
    */
code {
  white-space: pre-wrap;
}

span.smallcaps {
  font-variant: small-caps;
}

div.columns {
  display: flex;
  gap: min(4vw, 1.5em);
}

div.column {
  flex: auto;
  overflow-x: auto;
}

div.hanging-indent {
  margin-left: 1.5em;
  text-indent: -1.5em;
}

/* The extra [class] is a hack that increases specificity enough to
       override a similar rule in reveal.js */
ul.task-list[class] {
  list-style: none;
}

ul.task-list li input[type="checkbox"] {
  font-size: inherit;
  width: 0.8em;
  margin: 0 0.8em 0.2em -1.6em;
  vertical-align: middle;
}

.display.math {
  display: block;
  text-align: center;
  margin: 0.5rem auto;
}

/* CSS for syntax highlighting */
html {
  -webkit-text-size-adjust: 100%;
}

pre>code.sourceCode {
  white-space: pre;
  position: relative;
}

pre>code.sourceCode>span {
  display: inline-block;
  line-height: 1.25;
}

pre>code.sourceCode>span:empty {
  height: 1.2em;
}

.sourceCode {
  overflow: visible;
}

code.sourceCode>span {
  color: inherit;
  text-decoration: inherit;
}

div.sourceCode {
  margin: 1em 0;
}

pre.sourceCode {
  margin: 0;
}

@media screen {
  div.sourceCode {
    overflow: auto;
  }
}

@media print {
  pre>code.sourceCode {
    white-space: pre-wrap;
  }

  pre>code.sourceCode>span {
    text-indent: -5em;
    padding-left: 5em;
  }
}

pre.numberSource code {
  counter-reset: source-line 0;
}

pre.numberSource code>span {
  position: relative;
  left: -4em;
  counter-increment: source-line;
}

pre.numberSource code>span>a:first-child::before {
  content: counter(source-line);
  position: relative;
  left: -1em;
  text-align: right;
  vertical-align: baseline;
  border: none;
  display: inline-block;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  padding: 0 4px;
  width: 4em;
  color: #aaaaaa;
}

pre.numberSource {
  margin-left: 3em;
  border-left: 1px solid #aaaaaa;
  padding-left: 4px;
}

div.sourceCode {
  background-color: #f8f8f8;
}

@media screen {
  pre>code.sourceCode>span>a:first-child::before {
    text-decoration: underline;
  }
}

code span.al {
  color: #ef2929;
}

/* Alert */
code span.an {
  color: #8f5902;
  font-weight: bold;
  font-style: italic;
}

/* Annotation */
code span.at {
  color: #204a87;
}

/* Attribute */
code span.bn {
  color: #0000cf;
}

/* BaseN */
code span.cf {
  color: #204a87;
  font-weight: bold;
}

/* ControlFlow */
code span.ch {
  color: #4e9a06;
}

/* Char */
code span.cn {
  color: #8f5902;
}

/* Constant */
code span.co {
  color: #8f5902;
  font-style: italic;
}

/* Comment */
code span.cv {
  color: #8f5902;
  font-weight: bold;
  font-style: italic;
}

/* CommentVar */
code span.do {
  color: #8f5902;
  font-weight: bold;
  font-style: italic;
}

/* Documentation */
code span.dt {
  color: #204a87;
}

/* DataType */
code span.dv {
  color: #0000cf;
}

/* DecVal */
code span.er {
  color: #a40000;
  font-weight: bold;
}

/* Error */
code span.ex {}

/* Extension */
code span.fl {
  color: #0000cf;
}

/* Float */
code span.fu {
  color: #204a87;
  font-weight: bold;
}

/* Function */
code span.im {}

/* Import */
code span.in {
  color: #8f5902;
  font-weight: bold;
  font-style: italic;
}

/* Information */
code span.kw {
  color: #204a87;
  font-weight: bold;
}

/* Keyword */
code span.op {
  color: #ce5c00;
  font-weight: bold;
}

/* Operator */
code span.ot {
  color: #8f5902;
}

/* Other */
code span.pp {
  color: #8f5902;
  font-style: italic;
}

/* Preprocessor */
code span.sc {
  color: #ce5c00;
  font-weight: bold;
}

/* SpecialChar */
code span.ss {
  color: #4e9a06;
}

/* SpecialString */
code span.st {
  color: #4e9a06;
}

/* String */
code span.va {
  color: #000000;
}

/* Variable */
code span.vs {
  color: #4e9a06;
}

/* VerbatimString */
code span.wa {
  color: #8f5902;
  font-weight: bold;
  font-style: italic;
}

/* Warning */


/* ===== READER UI ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --sidebar-w: 280px;
  --header-h: 48px;
  --accent: #2563eb;
  --accent-light: #eff6ff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --bg: #ffffff;
  --sidebar-bg: #f8fafc;
  --done: #16a34a;
  --done-bg: #f0fdf4;
}

@media (prefers-color-scheme: dark) {
  :root {
    --text: #e2e8f0;
    --muted: #94a3b8;
    --border: #334155;
    --bg: #0f172a;
    --sidebar-bg: #1e293b;
    --accent-light: #1e3a5f;
    --done-bg: #14532d;
  }
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* HEADER */
#header {
  height: var(--header-h);
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  padding: 0 1rem;
  gap: 1rem;
  flex-shrink: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .2);
}

#menu-btn {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  font-size: 1.4rem;
  padding: 4px 8px;
  border-radius: 4px;
}

#menu-btn:hover {
  background: rgba(255, 255, 255, .15);
}

.home-btn {
  background: none;
  border: none;
  color: white;
  text-decoration: none;
  cursor: pointer;
  font-size: 1.2rem;
  padding: 4px 8px;
  border-radius: 4px;
  display: flex;
  align-items: center;
}

.home-btn:hover {
  background: rgba(255, 255, 255, .15);
}

#header-title {
  flex: 1;
  font-weight: 600;
  font-size: .9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#progress-bar-wrap {
  width: 120px;
  height: 6px;
  background: rgba(255, 255, 255, .3);
  border-radius: 3px;
  flex-shrink: 0;
}

#progress-bar {
  height: 100%;
  background: #4ade80;
  border-radius: 3px;
  transition: width .4s;
}

#progress-text {
  font-size: .75rem;
  opacity: .85;
  white-space: nowrap;
}

/* LAYOUT */
#layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* SIDEBAR */
#sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform .25s ease;
  z-index: 50;
}

#sidebar.hidden {
  transform: translateX(calc(-1 * var(--sidebar-w)));
  position: absolute;
  height: calc(100vh - var(--header-h));
}

#sidebar-search {
  padding: .6rem;
  border-bottom: 1px solid var(--border);
}

#sidebar-search input {
  width: 100%;
  padding: .4rem .7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: .85rem;
}

#sidebar-search input:focus {
  outline: none;
  border-color: var(--accent);
}

#chapter-list {
  flex: 1;
  overflow-y: auto;
  padding: .4rem 0;
}

.ch-item {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .45rem 1rem;
  cursor: pointer;
  font-size: .82rem;
  color: var(--muted);
  border-left: 3px solid transparent;
  transition: all .15s;
  line-height: 1.35;
}

.ch-item:hover {
  background: var(--accent-light);
  color: var(--accent);
}

.ch-item.active {
  background: var(--accent-light);
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 600;
}

.ch-item.done {
  color: var(--done);
}

.ch-item.done .ch-check {
  opacity: 1;
}

.ch-check {
  font-size: .8rem;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity .2s;
}

.ch-num {
  font-size: .7rem;
  color: var(--muted);
  flex-shrink: 0;
  min-width: 1.8rem;
}

/* Sidebar Hierarchy */
.ch-project {
  font-weight: 700;
  color: var(--text);
  padding-top: 1rem;
  border-left: 3px solid transparent !important;
}

.ch-project:hover {
  background: var(--sidebar-bg);
  color: var(--accent);
}

.ch-step {
  padding-left: 2.2rem;
  font-size: 0.82rem;
  color: var(--muted);
  border-left-color: transparent !important;
}

.ch-step.active {
  border-left-color: var(--accent) !important;
}

/* MAIN CONTENT */
#content-wrap {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

#chapter-content {
  max-width: 820px;
  margin: 0 auto;
  padding: 2.5rem 2rem 4rem;
  width: 100%;
  counter-reset: h2counter;
}

/* NAV BUTTONS */
#nav-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  gap: 1rem;
  max-width: 820px;
  margin: 0 auto;
  width: 100%;
}

.nav-btn {
  background: var(--accent);
  color: white;
  border: none;
  cursor: pointer;
  padding: .5rem 1.2rem;
  border-radius: 6px;
  font-size: .85rem;
  transition: opacity .15s;
  display: flex;
  align-items: center;
  gap: .4rem;
}

.nav-btn:hover {
  opacity: .85;
}

.nav-btn:disabled {
  opacity: .3;
  cursor: not-allowed;
}

.nav-btn.secondary {
  background: var(--border);
  color: var(--text);
}

#mark-done-btn {
  background: var(--done);
  color: white;
  border: none;
  cursor: pointer;
  padding: .5rem 1.1rem;
  border-radius: 6px;
  font-size: .85rem;
}

#mark-done-btn.done {
  background: var(--done-bg);
  color: var(--done);
  border: 1px solid var(--done);
}

/* CHAPTER NUMBER BADGE */
#ch-progress {
  font-size: .8rem;
  color: var(--muted);
  text-align: center;
}

/* CONTENT STYLING override */
#chapter-content h2 {
  font-size: 1.6rem;
  margin-bottom: 1.5rem;
  padding-bottom: .5rem;
  border-bottom: 2px solid var(--accent);
}

#chapter-content h2::before {
  counter-increment: h2counter;
  content: counter(h2counter) ". ";
  color: var(--accent);
}

#chapter-content h3 {
  font-size: 1.15rem;
  margin-top: 1.8rem;
  margin-bottom: .6rem;
}

#chapter-content pre {
  border-radius: 8px;
  font-size: .85rem;
  overflow-x: auto;
}

#chapter-content img {
  max-width: 100%;
  border-radius: 8px;
}

#chapter-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: .9rem;
}

#chapter-content td,
#chapter-content th {
  padding: .5rem .8rem;
  border: 1px solid var(--border);
}

#chapter-content blockquote {
  border-left: 4px solid var(--accent);
  padding-left: 1rem;
  margin: 1rem 0;
}

#chapter-content p {
  line-height: 1.75;
  margin-bottom: 1.2rem;
}

#chapter-content ul,
#chapter-content ol {
  margin-bottom: 1.2rem;
  padding-left: 1.5rem;
}

#chapter-content li {
  line-height: 1.75;
  margin-bottom: 0.5rem;
}

/* Objective Callout */
.objective-callout {
  background: var(--accent-light);
  border-left: 4px solid var(--accent);
  padding: 1.2rem;
  margin: 1.5rem 0;
  border-radius: 6px;
  font-size: 0.95rem;
  line-height: 1.6;
}