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

:root {
  --bg:        #0d1117;
  --bg2:       #161b22;
  --bg3:       #21262d;
  --border:    #30363d;
  --text:      #e6edf3;
  --text-muted:#8b949e;
  --accent:    #e85d4a;
  --accent2:   #ff8c7a;
  --cyan:      #58a6ff;
  --green:     #3fb950;
  --yellow:    #d29922;
  --code-bg:   #161b22;
  --sidebar-w: 280px;
  --topbar-h:  52px;
  --radius:    8px;
  --font:      'Inter', system-ui, sans-serif;
  --mono:      'JetBrains Mono', 'Courier New', monospace;
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  font-size: 15px;
  overflow-x: hidden;
}

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

/* ── TOPBAR ── */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--topbar-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
  display: none;
}
.topbar-title { flex: 1; font-size: 14px; font-weight: 500; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.topbar-title .brand { color: var(--accent); font-weight: 700; }
.topbar-title .sep { color: var(--text-muted); margin: 0 4px; }

.menu-btn, .search-btn {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; padding: 6px; border-radius: 6px;
  display: flex; flex-direction: column; gap: 4px; align-items: center;
  transition: color 0.2s, background 0.2s;
}
.menu-btn:hover, .search-btn:hover { color: var(--text); background: var(--bg3); }
.menu-btn span { display: block; width: 18px; height: 2px; background: currentColor; border-radius: 1px; transition: transform 0.2s, opacity 0.2s; }
.menu-btn.open span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.menu-btn.open span:nth-child(2) { opacity: 0; }
.menu-btn.open span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

/* ── SIDEBAR ── */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 90;
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
  transition: transform 0.3s ease;
}

.sidebar-header {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.logo { display: flex; align-items: center; gap: 4px; margin-bottom: 4px; }
.logo-bracket { color: var(--accent); font-family: var(--mono); font-size: 22px; font-weight: 700; line-height: 1; }
.logo-text { color: var(--text); font-family: var(--mono); font-size: 20px; font-weight: 700; letter-spacing: 3px; }
.subtitle { font-size: 11px; color: var(--text-muted); letter-spacing: 0.5px; }

.sidebar-search {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
  flex-shrink: 0;
}
.sidebar-search svg { color: var(--text-muted); flex-shrink: 0; }
.sidebar-search input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text); font-family: var(--font); font-size: 13px;
}
.sidebar-search input::placeholder { color: var(--text-muted); }

.module-nav { flex: 1; overflow-y: auto; padding: 8px 0; }

.nav-module { }
.nav-module-btn {
  width: 100%; background: none; border: none;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px; cursor: pointer;
  color: var(--text-muted); font-family: var(--font); font-size: 13px; font-weight: 500;
  text-align: left; transition: color 0.15s, background 0.15s;
  border-left: 3px solid transparent;
}
.nav-module-btn:hover { color: var(--text); background: var(--bg3); }
.nav-module-btn.active { color: var(--text); border-left-color: var(--accent); background: rgba(232,93,74,0.08); }
.nav-module-num { font-family: var(--mono); font-size: 11px; color: var(--accent); min-width: 20px; }
.nav-module-title { flex: 1; }
.nav-module-check { width: 16px; height: 16px; border-radius: 50%; border: 1.5px solid var(--border); flex-shrink: 0; transition: all 0.2s; }
.nav-module-check.done { background: var(--green); border-color: var(--green); }

.nav-sections { display: none; padding: 2px 0 4px 0; }
.nav-sections.open { display: block; }
.nav-section-btn {
  width: 100%; background: none; border: none;
  display: flex; align-items: center; gap: 8px;
  padding: 5px 16px 5px 42px;
  cursor: pointer; text-align: left;
  color: var(--text-muted); font-family: var(--font); font-size: 12px;
  transition: color 0.15s;
}
.nav-section-btn:hover { color: var(--text); }
.nav-section-btn.active { color: var(--cyan); }
.nav-section-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--border); flex-shrink: 0; transition: background 0.2s; }
.nav-section-btn.active .nav-section-dot, .nav-section-btn.read .nav-section-dot { background: var(--green); }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.progress-summary { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.reset-btn {
  background: none; border: 1px solid var(--border); color: var(--text-muted);
  font-size: 11px; font-family: var(--font); padding: 4px 10px; border-radius: 4px;
  cursor: pointer; transition: all 0.2s;
}
.reset-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ── MAIN ── */
.main {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  transition: margin-left 0.3s ease;
}
.content-area { max-width: 820px; margin: 0 auto; padding: 48px 40px 120px; }

/* ── OVERLAY (mobile) ── */
.overlay {
  display: none; position: fixed; inset: 0; z-index: 80;
  background: rgba(0,0,0,0.6); backdrop-filter: blur(2px);
}
.overlay.show { display: block; }

/* ── LANDING ── */
.landing { padding-top: 20px; }
.landing-badge {
  display: inline-block; padding: 4px 12px; border-radius: 20px;
  background: rgba(232,93,74,0.12); border: 1px solid rgba(232,93,74,0.3);
  color: var(--accent2); font-size: 12px; font-weight: 500; margin-bottom: 20px;
}
.landing-title { font-size: clamp(2rem, 5vw, 3.2rem); font-weight: 700; line-height: 1.15; margin-bottom: 16px; }
.landing-sub { color: var(--text-muted); font-size: 16px; max-width: 560px; margin-bottom: 48px; line-height: 1.6; }

.module-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.module-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px;
  cursor: pointer; transition: border-color 0.2s, transform 0.15s, background 0.2s;
  text-decoration: none; color: inherit; display: block;
}
.module-card:hover { border-color: var(--accent); background: var(--bg3); transform: translateY(-2px); }
.module-card-num { font-family: var(--mono); font-size: 11px; color: var(--accent); margin-bottom: 8px; }
.module-card-title { font-size: 14px; font-weight: 600; margin-bottom: 6px; line-height: 1.4; }
.module-card-meta { font-size: 11px; color: var(--text-muted); }
.module-card-progress { margin-top: 10px; height: 2px; background: var(--border); border-radius: 1px; overflow: hidden; }
.module-card-bar { height: 100%; background: var(--green); border-radius: 1px; transition: width 0.4s ease; }

/* ── MODULE VIEW ── */
.module-view { display: none; }
.module-view.active { display: block; }
.module-header { margin-bottom: 36px; padding-bottom: 24px; border-bottom: 1px solid var(--border); }
.module-header-num { font-family: var(--mono); font-size: 12px; color: var(--accent); margin-bottom: 8px; }
.module-header h1 { font-size: clamp(1.6rem, 4vw, 2.4rem); font-weight: 700; line-height: 1.2; margin-bottom: 10px; }
.module-header-meta { color: var(--text-muted); font-size: 13px; display: flex; gap: 16px; flex-wrap: wrap; }
.module-header-meta span { display: flex; align-items: center; gap: 5px; }

.module-section { margin-bottom: 48px; }
.section-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; margin-bottom: 20px;
}
.section-header h2 { font-size: 1.25rem; font-weight: 600; line-height: 1.3; }
.mark-read-btn {
  flex-shrink: 0; background: none; border: 1px solid var(--border);
  color: var(--text-muted); font-size: 11px; font-family: var(--font);
  padding: 4px 10px; border-radius: 4px; cursor: pointer;
  transition: all 0.2s; white-space: nowrap;
}
.mark-read-btn:hover { border-color: var(--green); color: var(--green); }
.mark-read-btn.done { border-color: var(--green); color: var(--green); background: rgba(63,185,80,0.1); }

/* ── CONTENT TYPOGRAPHY ── */
.section-body h3 { font-size: 1rem; font-weight: 600; color: var(--cyan); margin: 24px 0 10px; }
.section-body h4 { font-size: 0.9rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin: 20px 0 8px; }
.section-body p { margin-bottom: 14px; color: #c9d1d9; }
.section-body strong { color: var(--text); }
.section-body em { color: var(--text-muted); font-style: italic; }
.section-body ul, .section-body ol { padding-left: 20px; margin-bottom: 14px; }
.section-body li { margin-bottom: 5px; color: #c9d1d9; }
.section-body li strong { color: var(--text); }
.section-body a { color: var(--cyan); text-decoration: none; }
.section-body a:hover { text-decoration: underline; }
.section-body hr { border: none; border-top: 1px solid var(--border); margin: 28px 0; }

/* ── TABLES ── */
.section-body table {
  width: 100%; border-collapse: collapse; margin: 18px 0 22px;
  font-size: 13.5px; overflow: hidden; border-radius: 6px;
  border: 1px solid var(--border);
}
.section-body th {
  background: var(--bg3); color: var(--text); font-weight: 600;
  padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border);
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px;
}
.section-body td { padding: 9px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.section-body tr:last-child td { border-bottom: none; }
.section-body tr:hover td { background: var(--bg3); }

/* ── CODE ── */
.section-body pre {
  background: var(--code-bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin: 14px 0 20px;
  overflow-x: auto; position: relative;
}
.section-body pre code {
  font-family: var(--mono); font-size: 13px; color: #c9d1d9; line-height: 1.6;
  background: none; padding: 0; border: none; border-radius: 0;
}
.section-body code {
  font-family: var(--mono); font-size: 12.5px;
  background: var(--bg3); color: var(--accent2);
  padding: 2px 6px; border-radius: 4px;
  border: 1px solid var(--border);
}
.copy-btn {
  position: absolute; top: 8px; right: 8px;
  background: var(--bg3); border: 1px solid var(--border); color: var(--text-muted);
  font-size: 11px; font-family: var(--font); padding: 3px 8px; border-radius: 4px;
  cursor: pointer; transition: all 0.2s; opacity: 0;
}
pre:hover .copy-btn { opacity: 1; }
.copy-btn:hover { color: var(--text); border-color: var(--text-muted); }
.copy-btn.copied { color: var(--green); border-color: var(--green); }

/* ── CALLOUT BLOCKS ── */
.callout {
  border-left: 3px solid var(--accent); background: rgba(232,93,74,0.08);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 14px 16px; margin: 16px 0; font-size: 14px;
}
.callout.info { border-color: var(--cyan); background: rgba(88,166,255,0.07); }
.callout.success { border-color: var(--green); background: rgba(63,185,80,0.07); }
.callout.warn { border-color: var(--yellow); background: rgba(210,153,34,0.07); }

/* ── MODULE NAVIGATION ── */
.module-nav-footer {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 60px; padding-top: 28px; border-top: 1px solid var(--border);
  gap: 12px;
}
.nav-btn {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg2); border: 1px solid var(--border);
  color: var(--text); font-family: var(--font); font-size: 13px; font-weight: 500;
  padding: 10px 16px; border-radius: var(--radius); cursor: pointer;
  transition: all 0.2s; text-decoration: none; flex: 1; max-width: 220px;
}
.nav-btn:hover { border-color: var(--accent); background: var(--bg3); }
.nav-btn.next { margin-left: auto; justify-content: flex-end; }
.nav-btn-dir { font-size: 11px; color: var(--text-muted); display: block; }
.nav-btn-label { font-weight: 600; display: block; }

/* ── SEARCH OVERLAY ── */
.search-overlay {
  display: none; position: fixed; inset: 0; z-index: 200;
  background: rgba(13,17,23,0.9); backdrop-filter: blur(8px);
  flex-direction: column; align-items: center; padding-top: 80px;
}
.search-overlay.show { display: flex; }
.search-box {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 16px;
  width: min(600px, 90vw);
}
.search-box svg { color: var(--text-muted); flex-shrink: 0; }
.search-box input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text); font-family: var(--font); font-size: 16px;
}
.search-box input::placeholder { color: var(--text-muted); }
#searchClose { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 18px; padding: 0 4px; }
.search-results {
  width: min(600px, 90vw); margin-top: 12px;
  background: var(--bg2); border: 1px solid var(--border); border-radius: 10px;
  overflow: hidden; max-height: 60vh; overflow-y: auto;
}
.search-result {
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  cursor: pointer; transition: background 0.15s;
}
.search-result:last-child { border-bottom: none; }
.search-result:hover { background: var(--bg3); }
.search-result-module { font-size: 11px; color: var(--accent); margin-bottom: 4px; }
.search-result-title { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.search-result-preview { font-size: 12px; color: var(--text-muted); line-height: 1.5; }
.search-result-preview mark { background: rgba(232,93,74,0.25); color: var(--accent2); border-radius: 2px; }
.search-empty { padding: 24px; text-align: center; color: var(--text-muted); font-size: 14px; }

/* ── BACK TO TOP ── */
.back-top {
  position: fixed; bottom: 24px; right: 24px; z-index: 50;
  background: var(--bg2); border: 1px solid var(--border); color: var(--text-muted);
  width: 40px; height: 40px; border-radius: 50%; font-size: 16px;
  cursor: pointer; display: none; align-items: center; justify-content: center;
  transition: all 0.2s; box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
.back-top.show { display: flex; }
.back-top:hover { color: var(--text); border-color: var(--accent); }

/* ── BREADCRUMB ── */
.breadcrumb {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-muted); margin-bottom: 28px;
}
.breadcrumb a { color: var(--text-muted); text-decoration: none; cursor: pointer; }
.breadcrumb a:hover { color: var(--text); }
.breadcrumb span { color: var(--border); }

/* ── PROGRESS BAR (top) ── */
.reading-progress {
  position: fixed; top: 0; left: 0; right: 0; z-index: 200;
  height: 3px; background: var(--accent);
  transform-origin: left; transform: scaleX(0);
  transition: transform 0.1s;
}

/* ── RESPONSIVE ── */
@media (max-width: 768px) {
  .topbar { display: flex; }
  .sidebar {
    top: var(--topbar-h);
    transform: translateX(-100%);
    z-index: 95;
  }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; padding-top: var(--topbar-h); }
  .content-area { padding: 28px 20px 80px; }
  .module-grid { grid-template-columns: 1fr 1fr; }
  .module-nav-footer { flex-direction: column; }
  .nav-btn { max-width: 100%; }
}

@media (max-width: 480px) {
  .module-grid { grid-template-columns: 1fr; }
  .section-body pre { font-size: 12px; }
  .copy-btn { opacity: 1; }
}

/* ── SYNTAX HIGHLIGHTING (basic) ── */
.kw  { color: #ff7b72; }
.str { color: #a5d6ff; }
.cmt { color: #8b949e; font-style: italic; }
.fn  { color: #d2a8ff; }
.num { color: #79c0ff; }
.op  { color: #ff7b72; }

/* ── ANIMATIONS ── */
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.module-view { animation: fadeIn 0.25s ease; }

/* ── FIX: module-view should display block when rendered ── */
.module-view { display: block; }

/* ── FIX: reading-progress uses width not scaleX ── */
.reading-progress { transform: none; width: 0; transition: width 0.1s; }

/* ── NAV ITEM (sidebar entries) ── */
.nav-item { border-bottom: 1px solid transparent; }
.nav-item.active .nav-module-btn { color: var(--text); border-left-color: var(--accent); background: rgba(232,93,74,0.08); }

.nav-num  { font-family: var(--mono); font-size: 11px; color: var(--accent); min-width: 22px; flex-shrink: 0; }
.nav-title { flex: 1; }
.nav-badge {
  font-size: 10px; font-family: var(--mono); color: var(--text-muted);
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 10px; padding: 1px 6px; white-space: nowrap;
}
.nav-badge.done { color: var(--green); border-color: var(--green); background: rgba(63,185,80,0.1); }
.nav-progress-bar { height: 2px; background: var(--border); margin: 0 16px 6px; border-radius: 1px; overflow: hidden; }
.nav-progress-fill { height: 100%; background: var(--green); border-radius: 1px; transition: width 0.4s ease; }

/* ── MODULE CARD (grid) ── */
.card-number { font-family: var(--mono); font-size: 11px; color: var(--accent); margin-bottom: 8px; }
.card-title  { font-size: 14px; font-weight: 600; margin-bottom: 6px; line-height: 1.4; }
.card-meta   { font-size: 11px; color: var(--text-muted); margin-bottom: 10px; }
.card-bar    { height: 2px; background: var(--border); border-radius: 1px; overflow: hidden; margin-bottom: 4px; }
.card-bar-fill { height: 100%; background: var(--green); border-radius: 1px; transition: width 0.4s ease; }
.card-pct    { font-size: 10px; color: var(--text-muted); font-family: var(--mono); }

/* ── MODULE VIEW HEADER ── */
.back-btn {
  background: none; border: 1px solid var(--border); color: var(--text-muted);
  font-size: 12px; font-family: var(--font); padding: 5px 12px; border-radius: 6px;
  cursor: pointer; margin-bottom: 20px; transition: all 0.2s;
}
.back-btn:hover { border-color: var(--text-muted); color: var(--text); }
.module-meta-row { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.module-num-badge { font-family: var(--mono); font-size: 12px; color: var(--accent); flex-shrink: 0; }
.module-title-h1 { font-size: clamp(1.5rem, 4vw, 2.2rem); font-weight: 700; line-height: 1.2; }
.module-submeta  { color: var(--text-muted); font-size: 13px; margin-bottom: 14px; }

.source-pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.source-pill  {
  font-size: 11px; font-family: var(--mono);
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text-muted); padding: 2px 8px; border-radius: 4px;
}

/* ── SECTION BLOCK ── */
.section-block { margin-bottom: 48px; padding-bottom: 24px; border-bottom: 1px solid var(--border); }
.section-block:last-of-type { border-bottom: none; }
.section-block.read .section-title { color: var(--text-muted); }
.section-title { font-size: 1.25rem; font-weight: 600; line-height: 1.3; }
.mark-read-btn.read { border-color: var(--green); color: var(--green); background: rgba(63,185,80,0.1); }

/* ── NAV ARROWS (prev/next) ── */
.nav-arrow {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg2); border: 1px solid var(--border);
  color: var(--text); font-family: var(--font); font-size: 13px; font-weight: 500;
  padding: 10px 16px; border-radius: var(--radius); cursor: pointer;
  transition: all 0.2s; flex: 1; max-width: 260px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.nav-arrow:hover { border-color: var(--accent); background: var(--bg3); }
.nav-arrow.next { margin-left: auto; justify-content: flex-end; text-align: right; }

/* ── SEARCH RESULT ITEMS ── */
.search-result-item {
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  cursor: pointer; transition: background 0.15s;
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--bg3); }
.sr-module  { font-size: 11px; color: var(--accent); margin-bottom: 3px; }
.sr-section { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.sr-snip    { font-size: 12px; color: var(--text-muted); line-height: 1.5; }
.sr-snip mark { background: rgba(232,93,74,0.25); color: var(--accent2); border-radius: 2px; }
.landing { animation: fadeIn 0.3s ease; }
