/* ===== OpenClaw Tutorial — Custom Theme ===== */

/* ---------- CSS Variables ---------- */
:root {
  --bg: #ffffff;
  --fg: #24292e;
  --fg-secondary: #586069;
  --header-bg: linear-gradient(120deg, #155799, #159957);
  --header-fg: #fff;
  --link: #0366d6;
  --border: #e1e4e8;
  --code-bg: #f6f8fa;
  --card-bg: #f9f9f9;
  --search-bg: #fff;
  --search-shadow: rgba(0,0,0,0.1);
  --table-stripe: #f6f8fa;
  --footer-bg: #f6f8fa;
}

[data-theme="dark"] {
  --bg: #0d1117;
  --fg: #c9d1d9;
  --fg-secondary: #8b949e;
  --header-bg: linear-gradient(120deg, #0a2540, #0d4429);
  --header-fg: #e6edf3;
  --link: #58a6ff;
  --border: #30363d;
  --code-bg: #161b22;
  --card-bg: #161b22;
  --search-bg: #161b22;
  --search-shadow: rgba(0,0,0,0.4);
  --table-stripe: #161b22;
  --footer-bg: #161b22;
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
  transition: background 0.3s, color 0.3s;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Focus visible ring for accessibility */
:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
}

/* ---------- Header ---------- */
.site-header {
  background: var(--header-bg);
  color: var(--header-fg);
  text-align: center;
  padding: 2rem 1rem;
}

.header-inner { max-width: 800px; margin: 0 auto; }

.project-name {
  margin: 0 0 0.3rem;
  font-size: 2rem;
  font-weight: 700;
}

.project-tagline {
  margin: 0 0 1rem;
  font-size: 1.1rem;
  font-weight: 400;
  opacity: 0.85;
}

.btn {
  display: inline-block;
  padding: 0.5rem 1.2rem;
  margin: 0 0.3rem;
  border: 1px solid rgba(255,255,255,0.5);
  border-radius: 0.4rem;
  color: var(--header-fg);
  font-size: 0.9rem;
  transition: all 0.2s;
}
.btn:hover {
  background: rgba(255,255,255,0.15);
  text-decoration: none;
}

/* ---------- Toolbar (Search + Toggle) ---------- */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  max-width: 800px;
  margin: 1rem auto 0;
  padding: 0 1rem;
}

.search-container {
  position: relative;
  flex: 1;
  max-width: 500px;
}

#search-input {
  width: 100%;
  padding: 0.6rem 1rem;
  font-size: 0.95rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--search-bg);
  color: var(--fg);
  outline: none;
  transition: border 0.2s, box-shadow 0.2s;
}
#search-input:focus {
  border-color: var(--link);
  box-shadow: 0 0 0 3px var(--search-shadow);
}

#search-results {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--search-bg);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  box-shadow: 0 4px 12px var(--search-shadow);
  z-index: 100;
  max-height: 320px;
  overflow-y: auto;
}

.sr-item {
  display: block;
  padding: 0.5rem 1rem;
  color: var(--fg);
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}
.sr-item:last-child { border-bottom: none; }
.sr-item:hover {
  background: var(--table-stripe);
  text-decoration: none;
}

.sr-empty {
  padding: 0.7rem 1rem;
  color: var(--fg-secondary);
  font-size: 0.9rem;
}

#theme-toggle {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 40px; height: 40px;
  font-size: 1.2rem;
  cursor: pointer;
  transition: transform 0.2s, background 0.3s;
  flex-shrink: 0;
}
#theme-toggle:hover { transform: scale(1.1); }

/* ---------- Main Content ---------- */
.main-content {
  max-width: 800px;
  margin: 0 auto;
  padding: 2rem 1rem 3rem;
}

/* GitHub Markdown Body overrides for dark mode */
.markdown-body {
  color: var(--fg) !important;
  background: transparent !important;
}

[data-theme="dark"] .markdown-body {
  color-scheme: dark;
}

.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 {
  color: var(--fg) !important;
  border-bottom-color: var(--border) !important;
}

.markdown-body code, .markdown-body pre {
  background: var(--code-bg) !important;
  color: var(--fg) !important;
}

.markdown-body pre {
  border: 1px solid var(--border);
  border-radius: 0.5rem;
}

.markdown-body table {
  border-collapse: collapse;
  width: 100%;
}
.markdown-body table th,
.markdown-body table td {
  border: 1px solid var(--border) !important;
  padding: 0.5rem 0.75rem;
}
.markdown-body table tr:nth-child(2n) {
  background: var(--table-stripe) !important;
}
.markdown-body table th {
  background: var(--card-bg) !important;
}

.markdown-body blockquote {
  border-left: 4px solid var(--link);
  color: var(--fg-secondary);
  background: var(--card-bg);
  padding: 0.5rem 1rem;
  margin: 1rem 0;
  border-radius: 0 0.3rem 0.3rem 0;
}

.markdown-body img {
  max-width: 100%;
  border-radius: 0.3rem;
}

.markdown-body hr {
  border: none;
  border-top: 1px solid var(--border);
}

/* Badge images - no dark inversion */
.markdown-body img[src*="shields.io"] {
  filter: none !important;
}

/* ---------- Reading Progress Bar ---------- */
#progress-bar {
  position: fixed;
  top: 0; left: 0;
  height: 3px;
  width: 0;
  background: linear-gradient(90deg, #159957, #155799);
  z-index: 9999;
  transition: width 0.1s linear;
}

[data-theme="dark"] #progress-bar {
  background: linear-gradient(90deg, #58a6ff, #3fb950);
}

/* ---------- Chapter Navigation Bar ---------- */
.chapter-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 800px;
  margin: 0.5rem auto;
  padding: 0.6rem 1rem;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  font-size: 0.9rem;
}

.nav-link {
  color: var(--link);
  min-width: 0;
  max-width: 40%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nav-link:hover { text-decoration: underline; }

.nav-current {
  color: var(--fg-secondary);
  font-weight: 600;
  flex-shrink: 0;
}

/* Nav center links (目录 / 大纲) */
#nav-center {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}
.nav-mid-link {
  color: var(--fg-secondary);
  font-size: 0.85rem;
  transition: color 0.2s;
}
.nav-mid-link:hover { color: var(--link); text-decoration: none; }
.nav-sep { color: var(--fg-secondary); opacity: 0.5; }

/* ---------- Back to Top ---------- */
#back-to-top {
  display: none;
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--fg);
  font-size: 1.3rem;
  cursor: pointer;
  box-shadow: 0 2px 8px var(--search-shadow);
  z-index: 100;
  transition: transform 0.2s, background 0.3s;
}
#back-to-top:hover { transform: scale(1.1); }

/* ---------- Footer ---------- */
.site-footer {
  background: var(--footer-bg);
  border-top: 1px solid var(--border);
  text-align: center;
  padding: 1.5rem 1rem;
  font-size: 0.85rem;
  color: var(--fg-secondary);
  transition: background 0.3s;
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .chapter-nav {
    font-size: 0.8rem;
    padding: 0.5rem 0.6rem;
  }
  .nav-link { max-width: 35%; }
}

@media (max-width: 600px) {
  .project-name { font-size: 1.5rem; }
  .project-tagline { font-size: 0.95rem; }
  .toolbar { flex-direction: column; }
  .search-container { max-width: 100%; }
  .main-content { padding: 1rem 0.8rem 2rem; }
  .chapter-nav { font-size: 0.75rem; gap: 0.3rem; }
  #nav-center { display: none; }  /* Hide middle links on small screens */
}

/* ---------- Scroll to Top ---------- */
.markdown-body h1:first-child {
  margin-top: 0;
}

/* ---------- Code Copy Button ---------- */
.copy-btn {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  padding: 0.25rem 0.6rem;
  font-size: 0.75rem;
  background: var(--card-bg);
  color: var(--fg-secondary);
  border: 1px solid var(--border);
  border-radius: 0.3rem;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s, background 0.2s;
  z-index: 1;
}
pre:hover .copy-btn { opacity: 1; }
.copy-btn:hover { background: var(--link); color: #fff; border-color: var(--link); }

/* ---------- Details / Summary ---------- */
.markdown-body details {
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.5rem 1rem;
  margin: 1rem 0;
  background: var(--card-bg);
}
.markdown-body details[open] { padding-bottom: 1rem; }
.markdown-body summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--fg);
  padding: 0.3rem 0;
  user-select: none;
}
.markdown-body summary:hover { color: var(--link); }

/* ---------- Print Styles ---------- */
@media print {
  .site-header, .toolbar, #chapter-nav, #back-to-top,
  #progress-bar, .site-footer, .copy-btn { display: none !important; }
  .main-content { max-width: 100%; padding: 0; margin: 0; }
  .markdown-body { font-size: 11pt; }
  .markdown-body pre { border: 1px solid #ccc; page-break-inside: avoid; }
  a { color: inherit; text-decoration: underline; }
  a[href]::after { content: " (" attr(href) ")"; font-size: 0.8em; }
}
