/* Palette and type scale adapted from soroushesnaashari.github.io
   (plain black-and-white, typography-first, system font stack). */

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, Roboto, "Segoe UI", Helvetica, Arial, sans-serif;
  color: #333;
  line-height: 1.6;
  margin: 0;
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 4rem 2rem;
}

/* ---------- Header ---------- */

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 3rem;
}

header h1 {
  margin: 0;
  font-weight: 600;
  font-size: 1.2rem;
}

header h1 a {
  text-decoration: none;
  color: inherit;
}

nav.site-links {
  display: flex;
}

nav.site-links a {
  margin-left: 1rem;
  color: #777;
  text-decoration: none;
  font-size: 0.75rem;
}

nav.site-links a:hover {
  color: #000;
}

/* ---------- Global text justification ---------- */

.intro p,
section.lesson p,
section.lesson li,
.arch-diagram figcaption {
  text-align: justify;
  hyphens: auto;
  text-justify: inter-word;
}

/* ---------- Intro ---------- */

.intro p {
  margin-bottom: 1.5rem;
  font-size: 0.85rem;
  color: #444;
  line-height: 1.5;
}

.intro p a {
  color: #444;
  text-decoration: underline;
}

.intro p a:hover {
  color: #000;
}

/* ---------- Lessons ---------- */

section.lesson {
  scroll-margin-top: 2rem;
}

section.lesson h2 {
  margin: 3rem 0 0.5rem 0;
  font-weight: 600;
  font-size: 1.1rem;
  color: #333;
}

section.lesson > p.goal {
  font-size: 0.75rem;
  color: #777;
  margin: 0 0 1.5rem 0;
}

section.lesson h3 {
  margin: 1.5rem 0 1rem 0;
  font-weight: 600;
  font-size: 0.95rem;
  color: #333;
}

section.lesson p,
section.lesson li {
  margin-bottom: 1rem;
  font-size: 0.9rem;
  font-weight: 400;
  color: #444;
  line-height: 1.5;
}

section.lesson a {
  color: #444;
  text-decoration: underline;
}

section.lesson a:hover {
  color: #000;
}

section.lesson ul,
section.lesson ol {
  margin: 0 0 1.5rem 0;
  padding-left: 1.25rem;
}

/* ---------- Code ---------- */

.copy-btn {
  position: absolute;
  top: 0.45rem;
  right: 0.45rem;
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: #777;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 0.2rem 0.45rem;
  cursor: pointer;
  opacity: 0.85;
  transition: color 0.12s ease, border-color 0.12s ease, opacity 0.12s ease;
}

.copy-btn:hover {
  color: #000;
  border-color: #aaa;
  opacity: 1;
}

.copy-btn.copied {
  color: #1a7f37;
  border-color: #1a7f37;
}

code {
  font-family: "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.85rem;
  background: #f5f5f5;
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
}

pre {
  position: relative;
  background: #f5f5f5;
  padding: 1rem;
  overflow-x: auto;
  margin: 1rem 0 1.5rem 0;
  border-radius: 4px;
  padding-top: 2rem;
}

pre code {
  background: none;
  padding: 0;
  font-size: 0.8rem;
  line-height: 1.5;
}

/* ---------- Tables (markdown-like, minimal rules) ---------- */

table {
  border-collapse: collapse;
  width: 100%;
  margin: 1rem 0 1.5rem 0;
  font-size: 0.85rem;
}

th,
td {
  text-align: left;
  padding: 0.5rem 0.75rem 0.5rem 0;
  border-bottom: 1px solid #eee;
  color: #444;
  line-height: 1.5;
  vertical-align: top;
}

th {
  font-weight: 600;
  color: #333;
  border-bottom: 1px solid #ddd;
}

td code,
th code {
  white-space: nowrap;
}

/* ---------- Footer ---------- */

footer {
  margin-top: 4rem;
  text-align: left;
  font-size: 0.7rem;
}

/* ---------- Architecture diagram (full page width) ---------- */

.arch-diagram {
  margin: 2rem 0 1rem 0;
  width: 100%;
}

.arch-diagram svg {
  display: block;
  width: 100%;
  height: auto;
}

.arch-diagram figcaption {
  font-size: 0.85em;
  opacity: 0.75;
  margin-top: 8px;
}

footer a {
  color: #777;
  text-decoration: none;
}

footer a:hover {
  color: #000;
}

/* ---------- Right-rail table of contents ---------- */
/* Fixed, vertically centered, numbers only; hover reveals the title
   inline; the active section's number is highlighted. Hidden on mobile. */

#toc {
  position: fixed;
  right: 2rem;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
}

#toc ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

#toc li {
  display: flex;
  justify-content: flex-end;
  align-items: baseline;
}

#toc a {
  display: flex;
  justify-content: flex-end;
  align-items: baseline;
  text-decoration: none;
  max-width: 16rem;
}

#toc .toc-title {
  opacity: 0;
  transition: opacity 0.15s ease;
  color: #777;
  font-size: 0.7rem;
  margin-right: 0.6rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

#toc li:hover .toc-title {
  opacity: 1;
}

#toc .toc-num {
  color: #777;
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
  transition: color 0.15s ease;
}

#toc a:hover .toc-num {
  color: #000;
}

#toc li.active .toc-num {
  color: #000;
  font-weight: 700;
}

@media (max-width: 768px) {
  #toc {
    display: none;
  }
}
