:root {
  --color-bg: #fafaf9;
  --color-surface: #ffffff;
  --color-text: #1c1917;
  --color-text-muted: #78716c;
  --color-accent: #0D7377;
  --color-accent-hover: #14a3a8;
  --color-border: #e7e5e4;
  --color-highlight: #f0f9f9;
  --color-success: #059669;
  --color-warn: #d97706;

  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.875rem;

  --font-sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;

  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.08);

  --sidebar-width: 260px;
  --header-height: 60px;

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --duration-fast: 150ms;
  --duration-normal: 300ms;
  --duration-slow: 500ms;
}

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

html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: var(--font-sans);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

/* Header — .doc-header for old pages, .docs-header for index */
.doc-header, .docs-header {
  position: sticky; top: 0; z-index: 100;
  height: var(--header-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
}
/* Old markup: header is the flex row itself */
.doc-header {
  display: flex; align-items: center;
  padding: 0 var(--space-xl);
  gap: var(--space-lg);
}
/* New markup: .header-inner wraps the flex row */
.header-inner {
  display: flex; align-items: center;
  padding: 0 var(--space-xl);
  gap: var(--space-lg);
  height: 100%;
  max-width: 1440px;
  margin: 0 auto;
}
.doc-header .logo,
.header-logo {
  display: inline-flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: var(--text-lg);
  white-space: nowrap;
  color: var(--color-accent);
  text-decoration: none;
  flex-shrink: 0;
}
.doc-header .logo span,
.header-logo span { color: var(--color-text); }
.logo-icon { display: inline-block; width: 120px; vertical-align: middle; }
.header-search {
  flex: 1; max-width: 480px; position: relative;
}
.header-search input {
  width: 100%; height: 40px;
  padding: 0 var(--space-md) 0 40px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  background: var(--color-bg);
  transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
}
.header-search input:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.header-search .search-icon {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--color-text-muted); font-size: var(--text-base);
}
.header-actions { display: flex; gap: var(--space-sm); align-items: center; }
.btn-tts {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border: 1px solid var(--color-border);
  border-radius: var(--radius-md); background: var(--color-surface);
  cursor: pointer; font-size: var(--text-sm); color: var(--color-text);
  transition: all var(--duration-fast);
  white-space: nowrap;
}
.btn-tts:hover { border-color: var(--color-accent); color: var(--color-accent); }
.btn-tts.speaking { background: var(--color-accent); color: #fff; border-color: var(--color-accent); }
.menu-toggle {
  display: none; background: none; border: none; cursor: pointer;
  padding: 8px; color: var(--color-text);
}

/* Layout */
.doc-layout { display: flex; min-height: calc(100vh - var(--header-height)); }
.doc-sidebar {
  width: var(--sidebar-width); flex-shrink: 0;
  position: sticky; top: var(--header-height);
  height: calc(100vh - var(--header-height));
  overflow-y: auto;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: var(--space-lg) 0;
}
.doc-sidebar::-webkit-scrollbar { width: 4px; }
.doc-sidebar::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 2px; }
.sidebar-section { padding: 0 var(--space-lg); margin-bottom: var(--space-xs); }
.sidebar-section .section-title,
.sidebar-section .sidebar-heading {
  font-size: var(--text-xs); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--color-text-muted);
  padding: var(--space-sm) 0;
}
.sidebar-section a {
  display: block; padding: 6px 12px;
  font-size: var(--text-sm); color: var(--color-text);
  text-decoration: none; border-radius: var(--radius-sm);
  transition: background var(--duration-fast);
}
.sidebar-section a:hover { background: var(--color-highlight); }
.sidebar-section a.active {
  background: var(--color-highlight);
  color: var(--color-accent);
  font-weight: 600;
}
.sidebar-subhead {
  display: block; padding: 4px 12px;
  font-size: var(--text-xs); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--color-text-muted);
}
.nav-spacer { height: 8px; }

/* Content */
.doc-content {
  flex: 1; min-width: 0;
  max-width: 860px;
  padding: var(--space-2xl) var(--space-xl);
}
.doc-content h1 {
  font-size: var(--text-3xl); font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: var(--space-sm);
}
.doc-content h2 {
  font-size: var(--text-2xl); font-weight: 700;
  margin-top: var(--space-2xl); margin-bottom: var(--space-md);
  padding-bottom: var(--space-sm);
  border-bottom: 1px solid var(--color-border);
}
.doc-content h3 {
  font-size: var(--text-xl); font-weight: 600;
  margin-top: var(--space-xl); margin-bottom: var(--space-sm);
}
.doc-content p { margin-bottom: var(--space-md); color: var(--color-text); }
.doc-content ul, .doc-content ol {
  margin-bottom: var(--space-md); padding-left: var(--space-xl);
}
.doc-content li { margin-bottom: var(--space-xs); }

/* Tables */
.doc-table {
  width: 100%; border-collapse: collapse;
  margin: var(--space-lg) 0;
  font-size: var(--text-sm);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.doc-table th {
  background: var(--color-text);
  color: #fff;
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.doc-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
}
.doc-table tr:last-child td { border-bottom: none; }
.doc-table tr:nth-child(even) td { background: var(--color-bg); }

/* Step Flow */
.step-flow {
  background: var(--color-highlight);
  border: 1px solid #bfdbfe;
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  margin: var(--space-lg) 0;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 2;
  white-space: pre-wrap;
}

/* Info Cards */
.info-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  margin: var(--space-lg) 0;
  box-shadow: var(--shadow-sm);
}
.info-card.warn {
  border-left: 4px solid var(--color-warn);
  background: #fffbeb;
}
.info-card.tip {
  border-left: 4px solid var(--color-accent);
  background: var(--color-highlight);
}

/* Animations */
.fade-in {
  opacity: 0; transform: translateY(16px);
  transition: opacity var(--duration-slow) var(--ease-out),
              transform var(--duration-slow) var(--ease-out);
}
.fade-in.visible { opacity: 1; transform: translateY(0); }
.step-highlight {
  transition: background var(--duration-normal);
  border-radius: var(--radius-sm);
}
.step-highlight.flash { background: #fef3c7; }

/* Search Overlay */
.search-overlay {
  display: none;
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.3);
}
.search-overlay.open { display: block; }
.search-panel {
  position: fixed; top: 20%; left: 50%; transform: translateX(-50%);
  width: 90%; max-width: 560px; max-height: 60vh;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden; z-index: 201;
  display: flex; flex-direction: column;
}
.search-panel input {
  width: 100%; padding: var(--space-lg);
  border: none; border-bottom: 1px solid var(--color-border);
  font-size: var(--text-lg); outline: none;
}
.search-results {
  overflow-y: auto; padding: var(--space-md);
}
.search-results a {
  display: block; padding: var(--space-md);
  text-decoration: none; color: var(--color-text);
  border-radius: var(--radius-md);
  transition: background var(--duration-fast);
}
.search-results a:hover { background: var(--color-highlight); }
.search-results .result-title { font-weight: 600; }
.search-results .result-excerpt {
  font-size: var(--text-sm); color: var(--color-text-muted);
  margin-top: 4px;
}
.search-empty { text-align: center; padding: var(--space-xl); color: var(--color-text-muted); }

/* Breadcrumb */
.breadcrumb {
  display: flex; gap: var(--space-sm); align-items: center;
  font-size: var(--text-sm); color: var(--color-text-muted);
  margin-bottom: var(--space-xl);
}
.breadcrumb a { color: var(--color-accent); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }

/* Index Grid */
.chapter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-lg);
  margin-top: var(--space-xl);
}
.chapter-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  text-decoration: none; color: var(--color-text);
  transition: transform var(--duration-fast), box-shadow var(--duration-fast);
  box-shadow: var(--shadow-sm);
}
.chapter-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.chapter-card .card-num,
.chapter-card .chapter-number {
  font-size: var(--text-xs); font-weight: 700;
  color: var(--color-accent);
  text-transform: uppercase; letter-spacing: 0.1em;
}
.chapter-card .card-title,
.chapter-card .chapter-title {
  font-size: var(--text-lg); font-weight: 700;
  margin: var(--space-sm) 0;
}
.chapter-card .card-desc,
.chapter-card .chapter-desc {
  font-size: var(--text-sm); color: var(--color-text-muted);
  line-height: 1.5;
}

/* ---- MD Rendering Styles ---- */

.md-body { line-height: 1.85; }

.md-body h1 {
  font-size: var(--text-3xl); font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: var(--space-sm);
}
.md-body h2 {
  font-size: var(--text-2xl); font-weight: 700;
  margin-top: var(--space-2xl); margin-bottom: var(--space-md);
  padding-bottom: var(--space-sm);
  border-bottom: 1px solid var(--color-border);
}
.md-body h3 {
  font-size: var(--text-xl); font-weight: 600;
  margin-top: var(--space-xl); margin-bottom: var(--space-sm);
}
.md-body h4 {
  font-size: var(--text-lg); font-weight: 600;
  margin-top: var(--space-lg); margin-bottom: var(--space-xs);
}
.md-body p { margin-bottom: var(--space-md); }
.md-body ul, .md-body ol {
  margin-bottom: var(--space-md); padding-left: var(--space-xl);
}
.md-body li { margin-bottom: var(--space-xs); }
.md-body a { color: var(--color-accent); text-decoration: none; }
.md-body a:hover { text-decoration: underline; }

/* Tables (responsive wrap) */
.table-wrap {
  overflow-x: auto;
  margin: var(--space-lg) 0;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}
.md-body table {
  width: 100%; border-collapse: collapse;
  font-size: var(--text-sm);
  min-width: 600px;
}
.md-body th {
  background: var(--color-text);
  color: #fff;
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
.md-body td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
}
.md-body tr:last-child td { border-bottom: none; }
.md-body tr:nth-child(even) td { background: var(--color-bg); }

/* Code blocks */
.md-body code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: #f1f5f9;
  padding: 2px 6px;
  border-radius: 4px;
  color: #1e293b;
}
.md-body pre {
  background: #1e293b;
  color: #e2e8f0;
  padding: var(--space-lg);
  border-radius: var(--radius-md);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.65;
  margin: var(--space-lg) 0;
}
.md-body pre code {
  background: none;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

/* Blockquotes */
.md-body blockquote {
  border-left: 4px solid var(--color-accent);
  margin: var(--space-lg) 0;
  padding: var(--space-md) var(--space-lg);
  background: var(--color-highlight);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--color-text);
}
.md-body blockquote p:last-child { margin-bottom: 0; }

/* Horizontal rule */
.md-body hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: var(--space-2xl) 0;
}

/* Strong / emphasis */
.md-body strong { font-weight: 700; color: var(--color-text); }
.md-body em { font-style: italic; }

/* Images */
.md-body img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-md);
  margin: var(--space-md) 0;
}

/* Loading */
.loading {
  text-align: center;
  padding: var(--space-2xl);
  color: var(--color-text-muted);
  font-size: var(--text-lg);
}
.loading-spinner {
  display: inline-block;
  width: 24px; height: 24px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: var(--space-sm);
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Raw MD fallback */
.raw-md {
  background: var(--color-bg);
  padding: var(--space-xl);
  border-radius: var(--radius-md);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.6;
  white-space: pre-wrap;
}

/* ---- Tab Switching for L1-L4 ---- */

.tabs-bar {
  display: flex; gap: 4px;
  margin-bottom: var(--space-xl);
  border-bottom: 2px solid var(--color-border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.tab-btn {
  padding: 10px 20px;
  border: none; border-bottom: 3px solid transparent;
  background: none;
  cursor: pointer;
  font-size: var(--text-sm); font-weight: 600;
  color: var(--color-text-muted);
  white-space: nowrap;
  transition: all var(--duration-fast);
  position: relative; bottom: -2px;
}
.tab-btn:hover { color: var(--color-text); }
.tab-btn.active {
  color: var(--tab-color, var(--color-accent));
  border-bottom-color: var(--tab-color, var(--color-accent));
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.tabs-card {
  border: 2px solid var(--color-accent) !important;
  background: var(--color-highlight) !important;
}
.tabs-card:hover {
  border-color: var(--color-accent-hover) !important;
  box-shadow: 0 0 0 4px rgba(13,115,119,0.1) !important;
}

.tabs-link {
  font-weight: 600 !important;
  color: var(--color-accent) !important;
}
.tabs-link::before {
  content: '';
  display: inline-block;
  width: 6px; height: 6px;
  background: var(--color-accent);
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
  animation: pulse-dot 1.5s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.5); }
}

/* Sidebar expanded section */
.sidebar-section.expanded {
  background: var(--color-highlight);
  border-radius: var(--radius-sm);
}

/* ---- Slideshow / Presentation Mode ---- */

.slideshow-launch-btn {
  position: fixed; bottom: 24px; right: 24px; z-index: 99;
  padding: 12px 20px;
  background: var(--color-accent);
  color: #fff;
  border: none; border-radius: var(--radius-lg);
  font-size: var(--text-sm); font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(13,115,119,0.35);
  transition: all var(--duration-fast);
  display: flex; align-items: center; gap: 6px;
}
.slideshow-launch-btn:hover {
  background: var(--color-accent-hover);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(13,115,119,0.45);
}

.slideshow-overlay {
  display: none;
  position: fixed; inset: 0; z-index: 9999;
  background: #0f172a;
  color: #e2e8f0;
}
.slideshow-overlay.active { display: flex; flex-direction: column; }

.slideshow-close {
  position: absolute; top: 16px; right: 16px; z-index: 10;
  width: 40px; height: 40px;
  border: none; border-radius: 50%;
  background: rgba(255,255,255,0.1);
  color: #fff;
  font-size: 1.25rem; cursor: pointer;
  transition: background var(--duration-fast);
  display: flex; align-items: center; justify-content: center;
}
.slideshow-close:hover { background: rgba(255,255,255,0.2); }

.slideshow-slide {
  flex: 1; overflow-y: auto;
  padding: 5vh 8vw;
  display: flex; flex-direction: column; justify-content: center;
  font-size: 1.15rem; line-height: 1.9;
}
.slideshow-slide h1 { font-size: 2.5rem; margin-bottom: 1.5rem; color: #fff; }
.slideshow-slide h2 { font-size: 1.75rem; margin-bottom: 1rem; color: var(--color-accent-hover); border-bottom: 1px solid rgba(255,255,255,0.15); padding-bottom: 0.5rem; }
.slideshow-slide h3 { font-size: 1.35rem; margin: 1rem 0 0.5rem; color: #cbd5e1; }
.slideshow-slide p { margin-bottom: 0.75rem; }
.slideshow-slide ul, .slideshow-slide ol { padding-left: 1.5rem; margin-bottom: 0.75rem; }
.slideshow-slide li { margin-bottom: 0.35rem; }
.slideshow-slide table { width: 100%; border-collapse: collapse; font-size: 0.95rem; margin: 1rem 0; }
.slideshow-slide th { background: rgba(255,255,255,0.15); padding: 10px 14px; text-align: left; font-weight: 600; }
.slideshow-slide td { padding: 8px 14px; border-bottom: 1px solid rgba(255,255,255,0.1); }
.slideshow-slide strong { color: #fff; }
.slideshow-slide code { background: rgba(255,255,255,0.1); padding: 2px 6px; border-radius: 3px; font-size: 0.9em; }
.slideshow-slide pre { background: rgba(0,0,0,0.3); padding: 1rem; border-radius: 6px; overflow-x: auto; }
.slideshow-slide blockquote {
  border-left: 4px solid var(--color-accent);
  padding: 0.75rem 1rem;
  margin: 1rem 0;
  background: rgba(255,255,255,0.05);
  border-radius: 0 6px 6px 0;
}
.slide-title-wrap { text-align: center; }
.slide-title-wrap h1 { font-size: 3rem; margin-bottom: 1rem; }

.slideshow-controls {
  display: flex; align-items: center; justify-content: center;
  gap: 1.5rem;
  padding: 16px;
  background: rgba(0,0,0,0.4);
}
.slideshow-nav {
  width: 48px; height: 48px;
  border: 2px solid rgba(255,255,255,0.2); border-radius: 50%;
  background: transparent; color: #fff;
  font-size: 1.75rem; cursor: pointer;
  transition: all var(--duration-fast);
  display: flex; align-items: center; justify-content: center;
}
.slideshow-nav:hover { border-color: #fff; background: rgba(255,255,255,0.1); }
.slideshow-counter { font-size: 0.9rem; color: rgba(255,255,255,0.5); font-variant-numeric: tabular-nums; min-width: 60px; text-align: center; }

.slideshow-progress { height: 3px; background: rgba(255,255,255,0.1); }
.slideshow-progress-bar { height: 100%; background: var(--color-accent); transition: width 0.3s ease; width: 0%; }

@media (max-width: 768px) {
  .slideshow-slide { padding: 3vh 6vw; font-size: 1rem; }
  .slideshow-slide h1 { font-size: 1.75rem; }
  .slideshow-slide h2 { font-size: 1.35rem; }
  .slide-title-wrap h1 { font-size: 2rem; }
  .slideshow-launch-btn { bottom: 16px; right: 12px; padding: 10px 16px; font-size: 0.85rem; }
}

/* Print */
@media print {
  .doc-header, .docs-header, .doc-sidebar, .btn-tts, .menu-toggle { display: none !important; }
  .doc-layout { display: block; }
  .doc-content { max-width: 100%; padding: 0; }
  .doc-content h2, .md-body h2 { break-after: avoid; }
  .doc-table, .md-body table { box-shadow: none; border: 1px solid #ccc; }
  .doc-table th, .md-body th { background: #f5f5f5; color: #000; }
  .table-wrap { overflow-x: visible; }
  .md-body pre { background: #f5f5f5; color: #000; border: 1px solid #ccc; }
}

/* Responsive */
@media (max-width: 1024px) {
  .doc-content { padding: var(--space-xl); }
}
@media (max-width: 768px) {
  .menu-toggle { display: block; }
  .doc-header { padding: 0 var(--space-md) !important; }
  .header-inner { padding: 0 var(--space-md); }
  .doc-sidebar {
    position: fixed; top: var(--header-height); left: 0;
    transform: translateX(-100%);
    transition: transform var(--duration-normal) var(--ease-out);
    z-index: 150;
  }
  .doc-sidebar.open { transform: translateX(0); }
  .doc-content { padding: var(--space-lg); }
  .doc-content h1, .md-body h1 { font-size: var(--text-2xl); }
  .chapter-grid { grid-template-columns: 1fr; }
  .header-search { display: none; }
  .table-wrap { margin: var(--space-md) -var(--space-lg); border-radius: 0; }
}
@media (max-width: 480px) {
  .doc-header { padding: 0 var(--space-sm); }
  .docs-header { padding: 0; }
  .header-inner { padding: 0 var(--space-sm); }
  .btn-tts span { display: none; }
  .header-logo span,
  .doc-header .logo span { font-size: var(--text-sm); }
}
