/* ─── Reset & base ─────────────────────────────────────────────────────────── */

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

:root {
  --sidebar-width: 260px;
  --progress-h: 3px;

  /* Field notebook palette */
  --cream: #faf6ee;
  --cream-deep: #f0ebe3;
  --ink: #3d3227;
  --ink-light: #5c4a3a;
  --ink-faint: #8b7355;
  --sepia: #c4956a;
  --sepia-light: #d4b08c;
  --sepia-muted: #a07347;
  --border: #e0d7c8;
  --border-light: #ebe5d9;

  /* Terminal palette (for :::terminal blocks) */
  --term-bg: #0d1117;
  --term-fg: #c9d1d9;
  --term-green: #3fb950;
  --term-border: #21262d;
  --term-surface: #161b22;
  --term-muted: #484f58;
  --term-link: #58a6ff;

  /* Accent */
  --accent: #8b6f57;
  --accent-light: #f5f0e8;

  --text: var(--ink);
  --muted: var(--ink-faint);
  --radius: 5px;
  --font: 'Literata', Georgia, 'Times New Roman', serif;
  --font-ui: 'Syne', -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: 'DM Mono', ui-monospace, 'Cascadia Code', Menlo, monospace;
  --mono-term: 'JetBrains Mono', ui-monospace, 'Cascadia Code', Menlo, monospace;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 32px;
}

body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.7;
  color: var(--text);
  background: #fdfcf9;
}

/* ─── Progress bar ──────────────────────────────────────────────────────────── */

#progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: var(--progress-h);
  width: 0%;
  background: var(--sepia);
  z-index: 1000;
  transition: width 0.1s linear;
}

/* ─── Sidebar ───────────────────────────────────────────────────────────────── */

#sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  overflow-y: auto;
  background: var(--cream);
  border-right: 1px solid var(--border);
  padding: 24px 0 40px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 0;
}

#sidebar-header {
  padding: 0 20px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

#site-title {
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

#total-time {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-faint);
  margin-top: 2px;
}

#nav-list {
  list-style: none;
  padding: 0;
}

#nav-list li a {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 20px;
  color: var(--ink-faint);
  text-decoration: none;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.4;
  border-left: 3px solid transparent;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

#nav-list li a:hover {
  color: var(--ink);
  background: var(--cream-deep);
}

#nav-list li a.active {
  color: var(--sepia-muted);
  border-left-color: var(--sepia);
  background: var(--accent-light);
  font-weight: 600;
}

.nav-title {
  flex: 1;
}

.nav-time {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--ink-faint);
  white-space: nowrap;
  background: var(--border-light);
  padding: 1px 6px;
  border-radius: 20px;
  flex-shrink: 0;
}

#nav-list li a.active .nav-time {
  background: var(--sepia-light);
  color: var(--ink);
}

/* ─── Hamburger ─────────────────────────────────────────────────────────────── */

#hamburger {
  display: none;
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 300;
  width: 36px;
  height: 36px;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  background: var(--cream);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  padding: 6px;
}

#hamburger span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--ink);
  border-radius: 2px;
  transition: transform 0.2s, opacity 0.2s;
}

#hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
#hamburger.open span:nth-child(2) { opacity: 0; }
#hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ─── Main content ──────────────────────────────────────────────────────────── */

#content {
  margin-left: var(--sidebar-width);
  max-width: 780px;
  padding: 60px 56px 120px;
}

/* ─── Sections ──────────────────────────────────────────────────────────────── */

.section-block {
  padding-bottom: 64px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 64px;
}

.section-block:last-child {
  border-bottom: none;
}

/* ─── Typography ────────────────────────────────────────────────────────────── */

.section-block h1 {
  font-family: var(--font);
  font-size: 28px;
  font-weight: 600;
  line-height: 1.25;
  margin-bottom: 24px;
  color: var(--ink);
}

.section-block h2 {
  font-family: var(--font);
  font-size: 20px;
  font-weight: 600;
  margin-top: 40px;
  margin-bottom: 12px;
  color: var(--ink);
}

.section-block h3 {
  font-family: var(--font);
  font-size: 17px;
  font-weight: 600;
  margin-top: 32px;
  margin-bottom: 10px;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.section-block h4 {
  font-size: 15px;
  font-weight: 600;
  margin-top: 24px;
  margin-bottom: 8px;
}

.section-block p {
  margin-bottom: 14px;
}

.section-block ul,
.section-block ol {
  margin: 0 0 14px 20px;
}

.section-block li {
  margin-bottom: 4px;
}

.section-block a {
  color: var(--sepia-muted);
  text-decoration: underline;
  text-decoration-color: var(--sepia-light);
  text-underline-offset: 2px;
}

.section-block a:hover {
  color: var(--ink);
  text-decoration-color: var(--sepia);
}

.section-block code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: var(--cream-deep);
  padding: 1px 5px;
  border-radius: 3px;
  border: 1px solid var(--border);
  color: var(--ink-light);
}

.section-block pre {
  background: #2c2825;
  color: #e8dfd3;
  padding: 16px;
  border-radius: var(--radius);
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 16px;
}

.section-block pre code {
  background: none;
  padding: 0;
  border: none;
  color: inherit;
  font-size: inherit;
}

.section-block blockquote {
  border-left: 3px solid var(--sepia-light);
  padding-left: 16px;
  color: var(--ink-faint);
  margin: 16px 0;
  font-style: italic;
}

.section-block hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 32px 0;
}

/* ─── Section header with time badge ───────────────────────────────────────── */

.section-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.section-header h1 {
  margin-bottom: 0;
  flex: 1;
}

.time-badge {
  display: inline-flex;
  align-items: center;
  font-family: var(--mono);
  background: var(--cream-deep);
  color: var(--ink-faint);
  font-size: 11px;
  font-weight: 400;
  padding: 3px 10px;
  border-radius: 20px;
  white-space: nowrap;
  margin-top: 6px;
  border: 1px solid var(--border);
}

/* ─── Context blocks (field notebook: warm sepia callout) ──────────────────── */

.block-context {
  background: var(--cream);
  border-left: 3px solid var(--sepia);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 14px 18px;
  margin: 20px 0;
}

.block-context-title {
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--sepia-muted);
  margin-bottom: 8px;
}

.block-context p:last-child,
.block-context ul:last-child,
.block-context ol:last-child {
  margin-bottom: 0;
}

/* ─── Prompt blocks (field notebook: warm dark with copy) ──────────────────── */

.block-prompt {
  position: relative;
  background: #0f172a;
  border-radius: var(--radius);
  margin: 20px 0;
}

.block-prompt pre {
  background: none;
  margin: 0;
  padding: 16px 48px 16px 18px;
  white-space: pre-wrap;
  word-break: break-word;
  color: #e2e8f0;
  font-family: var(--mono);
}

.block-prompt .copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(255,255,255,0.08);
  color: #94a3b8;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 11px;
  font-family: var(--mono);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  letter-spacing: 0.03em;
}

.block-prompt .copy-btn:hover {
  background: rgba(255,255,255,0.14);
  color: #e2e8f0;
}

.block-prompt .copy-btn.copied {
  color: #4ade80;
  border-color: rgba(74,222,128,0.3);
}

/* ─── Terminal blocks (terminal native: dark GitHub-style) ─────────────────── */

.block-terminal {
  position: relative;
  background: var(--term-bg);
  border: 1px solid var(--term-border);
  border-radius: 6px;
  margin: 20px 0;
}

.block-terminal pre {
  background: none;
  margin: 0;
  padding: 16px 48px 16px 18px;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--term-fg);
  font-family: var(--mono-term);
  font-size: 13px;
}

.block-terminal pre code {
  background: none;
  padding: 0;
  border: none;
  color: inherit;
  font-size: inherit;
  font-family: inherit;
}

.block-terminal pre code::before {
  content: "$ ";
  color: var(--term-green);
  user-select: none;
}

.block-terminal .copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--term-surface);
  color: var(--term-link);
  border: 1px solid var(--term-border);
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 10px;
  font-family: var(--mono-term);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  letter-spacing: 0.03em;
}

.block-terminal .copy-btn:hover {
  background: #1c2128;
  color: #79c0ff;
}

.block-terminal .copy-btn.copied {
  color: var(--term-green);
  border-color: rgba(63,185,80,0.3);
}

/* ─── Aside blocks (editorial: bold border, high contrast) ─────────────────── */

.block-aside {
  border: 2px solid var(--ink);
  border-radius: 0;
  margin: 20px 0;
  overflow: hidden;
  max-width: 100%;
}

.block-aside summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 16px;
  cursor: pointer;
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.01em;
  background: #fff;
  color: var(--ink);
  user-select: none;
  list-style: none;
}

.block-aside summary::-webkit-details-marker { display: none; }

.block-aside summary::before {
  content: "▶";
  font-size: 8px;
  color: var(--ink);
  transition: transform 0.2s;
  flex-shrink: 0;
}

.block-aside[open] summary::before {
  transform: rotate(90deg);
}

.block-aside .aside-body {
  padding: 14px 16px;
  border-top: 2px solid var(--ink);
  font-size: 14px;
  overflow-wrap: break-word;
  word-break: break-word;
}

.block-aside .aside-body p:last-child,
.block-aside .aside-body ul:last-child {
  margin-bottom: 0;
}

/* ─── Tab blocks (field notebook with sepia accents) ───────────────────────── */

.block-tabs {
  margin: 20px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.tab-bar {
  display: flex;
  background: var(--cream);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.tab-btn {
  padding: 8px 16px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  font-size: 12px;
  font-family: var(--mono);
  font-weight: 400;
  color: var(--ink-faint);
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
  margin-bottom: -1px;
}

.tab-btn:hover {
  color: var(--ink);
}

.tab-btn.active {
  color: var(--ink);
  border-bottom-color: var(--sepia);
  background: #fdfcf9;
  font-weight: 500;
}

.tab-panel {
  display: none;
  padding: 16px 20px;
}

.tab-panel.active {
  display: block;
}

.tab-panel p:last-child,
.tab-panel ul:last-child,
.tab-panel ol:last-child {
  margin-bottom: 0;
}

/* ─── Definition tooltips ──────────────────────────────────────────────────── */

.def {
  position: relative;
  border-bottom: 1px dotted var(--sepia-light);
  cursor: help;
}

.def sup {
  font-size: 10px;
  color: var(--ink-faint);
  margin-left: 1px;
}

.def-tooltip {
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: #2c2825;
  color: #e8dfd3;
  border: 1px solid #4a3f35;
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: 13px;
  line-height: 1.4;
  width: max-content;
  max-width: 280px;
  z-index: 100;
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}

.def-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: #4a3f35;
}

.def:hover .def-tooltip,
.def:focus .def-tooltip {
  display: block;
}

/* ─── GIF link hover preview ───────────────────────────────────────────────── */

a.gif-preview {
  position: relative;
}

a.gif-preview .gif-tooltip {
  display: none;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  pointer-events: none;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  border: 1px solid var(--border);
}

a.gif-preview .gif-tooltip img {
  display: block;
  max-width: 320px;
  border-radius: var(--radius);
}

a.gif-preview:hover .gif-tooltip,
a.gif-preview:focus .gif-tooltip {
  display: block;
}

/* ─── Time block (inline, handled by section header) ───────────────────────── */

.block-time {
  display: none;
}

/* ─── Responsive ────────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  #hamburger {
    display: flex;
  }

  #sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }

  #sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 20px rgba(0,0,0,0.12);
  }

  #content {
    margin-left: 0;
    padding: 60px 20px 80px;
  }
}

@media (max-width: 480px) {
  #content {
    padding: 56px 16px 80px;
  }

  .section-block h1 {
    font-size: 22px;
  }

  .tab-btn {
    padding: 8px 12px;
    font-size: 11px;
  }
}

/* ─── Subscribe popup ──────────────────────────────────────────────────────── */

.subscribe-overlay {
  position: fixed;
  inset: 0;
  background: rgba(61, 50, 39, 0.4);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.subscribe-overlay.visible {
  opacity: 1;
}

.subscribe-popup {
  background: var(--cream);
  border: 2px solid var(--ink);
  padding: 32px;
  max-width: 380px;
  width: 90%;
  position: relative;
  font-family: var(--font);
}

.subscribe-close {
  position: absolute;
  top: 10px;
  right: 14px;
  background: none;
  border: none;
  font-size: 22px;
  color: var(--ink-faint);
  cursor: pointer;
  line-height: 1;
}

.subscribe-close:hover {
  color: var(--ink);
}

.subscribe-heading {
  font-family: var(--font-ui);
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 6px;
}

.subscribe-body {
  font-size: 14px;
  color: var(--ink-light);
  line-height: 1.5;
  margin-bottom: 16px;
}

.subscribe-form {
  display: flex;
  gap: 8px;
}

.subscribe-input {
  flex: 1;
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  background: white;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--ink);
  outline: none;
}

.subscribe-input:focus {
  border-color: var(--sepia);
}

.subscribe-btn {
  padding: 8px 18px;
  background: var(--ink);
  color: var(--cream);
  border: none;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.subscribe-btn:hover {
  background: var(--ink-light);
}

.subscribe-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.subscribe-msg {
  font-family: var(--mono);
  font-size: 12px;
  margin-top: 8px;
  min-height: 18px;
}
