/* ==========================================================================
   howtoai.sh — Design System
   Via-dashboard warm cream palette · single-page layout
   ========================================================================== */

/* --------------------------------------------------------------------------
   Design Tokens
   -------------------------------------------------------------------------- */
:root {
  --bg-primary:   #FFFDF5;
  --bg-secondary: #FBF7F0;
  --bg-tertiary:  #F5EFE6;
  --bg-active:    #EDE7DB;

  --text-primary:   #1C1917;
  --text-secondary: #78716C;
  --text-tertiary:  #A8A29E;

  --accent:       #DA7757;
  --accent-dark:  #C26040;
  --accent-muted: rgba(218, 119, 87, 0.1);

  --border:        #DDD5C8;
  --border-subtle: #F0E8DC;

  --shadow-sm: 0 1px 2px rgba(44, 36, 22, 0.06);
  --shadow-md: 0 2px 8px rgba(44, 36, 22, 0.10);

  --font-ui:   "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  /* CHANGED: JetBrains Mono added as primary monospace to match OpenClaw's code font.
     Research: code legibility scored 6.5/10 partly due to Geist Mono's weaker glyph
     disambiguation. JetBrains Mono improves 0/O and 1/l/I distinction at small sizes.
     Geist Mono kept as first fallback to preserve the brand stack on systems where
     JetBrains Mono hasn't loaded yet. */
  --font-mono: "JetBrains Mono", "Geist Mono", "Fira Code", monospace;

  /* CHANGED: Font size scale aligned toward OpenClaw's ergonomic baseline.
     --text-sm:   11px → 12px  sidebar links and labels; more legible at distance
     --text-base: 14px → 15px  body text; recommendation from FINDINGS.md §1
     --text-md:   16px → 18px  h2 headings; restores size-based hierarchy over body
     These are conservative nudges — not full parity with OpenClaw's 16px base —
     to preserve howtoai-sh's compact, brand-forward density. */
  --text-xs:   10px;
  --text-sm:   12px;
  --text-base: 15px;
  --text-md:   18px;
  --text-lg:   20px;
  --text-xl:   26px;

  --r-sm: 2px;
  --r-md: 4px;
  --r-lg: 6px;

  --topbar-h:  44px;
  --sidebar-w: 240px;
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  font-family: var(--font-ui);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  height: 100vh;
  overflow: hidden;
}

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

/* --------------------------------------------------------------------------
   App Shell
   -------------------------------------------------------------------------- */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Topbar */
#topbar {
  height: var(--topbar-h);
  min-height: var(--topbar-h);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.25rem;
  background: var(--bg-primary);
  z-index: 100;
}

#site-name {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--accent);
  letter-spacing: 0.02em;
  cursor: pointer;
}

#site-sub {
  font-size: var(--text-sm);
  color: var(--text-tertiary);
}

/* Two-column layout below topbar */
#layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* --------------------------------------------------------------------------
   Sidebar — all chapters + all lessons
   -------------------------------------------------------------------------- */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  background: var(--bg-secondary);
}

#sidebar-nav {
  padding: 0.75rem 0 2rem;
}

/* Chapter group */
.sb-chapter {
  margin-bottom: 0.25rem;
}

.sb-chapter-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem 0.4rem;
  border-bottom: 1px solid var(--border-subtle);
  margin-top: 0.5rem;
}

.sb-chapter:first-child .sb-chapter-header {
  margin-top: 0;
}

.sb-tag {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 1px 5px;
  border: 1px solid;
  border-radius: var(--r-sm);
  white-space: nowrap;
}

.sb-chapter-title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

/* Lesson links */
.sb-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.38rem 1rem;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  cursor: pointer;
  border-left: 2px solid transparent;
  transition: background 0.1s, color 0.1s;
}

.sb-link:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.sb-link.active {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-weight: 500;
  border-left-color: var(--accent);
}

.sb-num {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  min-width: 20px;
}

.sb-link.active .sb-num {
  color: var(--accent);
}

/* --------------------------------------------------------------------------
   Content area
   -------------------------------------------------------------------------- */
#content {
  flex: 1;
  overflow-y: auto;
  padding: 2rem 2.5rem 4rem;
  background: var(--bg-primary);
}

/* Lesson sections */
/* CHANGED: max-width 700px → 740px (readability fix #2 of 3).
   OpenClaw uses ~850px; 740px is a midpoint that widens the reading column
   slightly, reducing aggressive line wrapping on code-heavy paragraphs
   while preserving the compact, focused feel of the original layout. */
.lesson-section {
  max-width: 740px;
}

.lesson-section[hidden] { display: none; }

/* Eyebrow */
.lesson-eyebrow {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.lesson-num {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  letter-spacing: 0.05em;
}

.tag-badge {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: 0.08em;
  padding: 1px 6px;
  border-radius: var(--r-sm);
  text-transform: uppercase;
  white-space: nowrap;
  border: 1px solid;
}

/* Heading */
.lesson-section > h1 {
  font-size: var(--text-xl);
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  line-height: 1.25;
  margin-bottom: 1.5rem;
}

/* --------------------------------------------------------------------------
   Lesson content typography
   -------------------------------------------------------------------------- */
.lesson-content {
  font-size: var(--text-base);
  line-height: 1.75;
  color: var(--text-secondary);
}

.lesson-content h2 {
  font-size: var(--text-md);
  font-weight: 600;
  color: var(--text-primary);
  margin: 2rem 0 0.75rem;
  letter-spacing: -0.01em;
  padding-top: 2rem;
  border-top: 1px solid var(--border-subtle);
}

.lesson-content h2:first-child {
  margin-top: 0; padding-top: 0; border-top: none;
}

.lesson-content h3 {
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--text-primary);
  margin: 1.5rem 0 0.5rem;
}

/* CHANGED: paragraph margin-bottom 1rem → 1.25rem (readability fix #3 of 3).
   Research: OpenClaw uses medium-to-generous spacing throughout. At 15px base,
   1rem (15px) of paragraph gap is proportionally tighter than at 16px.
   1.25rem (≈19px) restores the visual breathing room between paragraphs. */
.lesson-content p  { margin-bottom: 1.25rem; }

.lesson-content ul,
.lesson-content ol { padding-left: 1.5rem; margin-bottom: 1rem; }

.lesson-content li { margin-bottom: 0.35rem; }

/* CHANGED: Code font sizes bumped from 12px → 13px to match OpenClaw's ~13-14px
   code size. Research: 12px is aggressive and loses fine detail at >18-inch viewing
   distances. Also bumped pre line-height 1.6 → 1.65 (readability fix #1 of 3):
   tighter lines in code blocks make multi-line patterns harder to track; 1.65
   adds one pixel of vertical breathing room without changing block proportions. */
.lesson-content code {
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-sm);
  padding: 1px 5px;
  color: var(--text-primary);
}

.lesson-content pre {
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 1rem 1.25rem;
  overflow-x: auto;
  margin: 1rem 0;
  line-height: 1.65;
  color: var(--text-primary);
}

.lesson-content pre code {
  background: none; border: none; padding: 0; font-size: inherit;
}

.lesson-content table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  margin: 1.25rem 0;
}

.lesson-content th {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.lesson-content td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: top;
}

.lesson-content tr:last-child td { border-bottom: none; }

.callout {
  background: var(--bg-tertiary);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--r-md) var(--r-md) 0;
  padding: 0.85rem 1.25rem;
  margin: 1.25rem 0;
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.callout strong { color: var(--text-primary); }

/* --------------------------------------------------------------------------
   Prev / Next nav
   -------------------------------------------------------------------------- */
.pn-nav {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  gap: 1rem;
}

.pn-link {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--bg-secondary);
  max-width: 46%;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.pn-link:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.pn-next { margin-left: auto; text-align: right; }

.pn-label {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

.pn-title { display: block; }

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 640px) {
  :root { --sidebar-w: 0px; }

  #sidebar {
    display: none;
  }

  #content {
    padding: 1.25rem 1rem 3rem;
  }
}
