/* =========================================================================
   TutorialHub — main stylesheet
   Light + dark theming via [data-theme]; three-column docs layout.
   ========================================================================= */

:root {
  --bg: #ffffff;
  --bg-soft: #f6f8fa;
  --bg-elev: #ffffff;
  --surface: #ffffff;
  --border: #e3e8ee;
  --border-strong: #cdd5df;
  --text: #1c2430;
  --text-soft: #4a5568;
  --text-muted: #6b7785;
  --brand: #2f6df6;
  --brand-strong: #1f54d6;
  --brand-soft: #e8f0ff;
  --accent: #00b388;
  --code-bg: #f6f8fa;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 16px rgba(16,24,40,.06);
  --shadow-lg: 0 12px 40px rgba(16,24,40,.14);
  --radius: 12px;
  --radius-sm: 8px;
  --header-h: 60px;
  --maxw: 1400px;
  --sidebar-w: 264px;
  --toc-w: 240px;
  --content-w: 820px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  --font-mono: "SFMono-Regular", "JetBrains Mono", "Fira Code", ui-monospace, Menlo, Consolas, monospace;
}

[data-theme="dark"] {
  --bg: #0b0f17;
  --bg-soft: #11161f;
  --bg-elev: #141b26;
  --surface: #141b26;
  --border: #232c3a;
  --border-strong: #313c4d;
  --text: #e6edf3;
  --text-soft: #b3bfce;
  --text-muted: #8593a4;
  --brand: #5b8dff;
  --brand-strong: #7aa3ff;
  --brand-soft: #16223b;
  --accent: #2dd4a7;
  --code-bg: #0f1521;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.35);
  --shadow-lg: 0 16px 48px rgba(0,0,0,.55);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--text);
  background: var(--bg);
  line-height: 1.65;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-strong); }

img { max-width: 100%; height: auto; }

.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 1000;
  background: var(--brand); color: #fff; padding: 8px 14px; border-radius: 0 0 8px 0;
}
.skip-link:focus { left: 0; }

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  height: var(--header-h);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: var(--maxw); margin: 0 auto; height: 100%;
  display: flex; align-items: center; gap: 16px; padding: 0 20px;
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 700; }
.brand:hover { color: var(--text); }
.brand-mark {
  display: grid; place-items: center; width: 30px; height: 30px;
  background: linear-gradient(135deg, var(--brand), var(--accent));
  color: #fff; border-radius: 8px; font-family: var(--font-mono); font-weight: 700; font-size: 13px;
}
.brand-name { font-size: 18px; letter-spacing: -.2px; }
.brand-accent { color: var(--brand); }

.search-trigger {
  display: flex; align-items: center; gap: 8px;
  margin-left: 8px; flex: 0 1 360px; max-width: 360px;
  height: 38px; padding: 0 12px;
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 999px; color: var(--text-muted); cursor: pointer; font-size: 14px;
  transition: border-color .15s, background .15s;
}
.search-trigger:hover { border-color: var(--border-strong); }
.search-trigger-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.top-nav { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.top-nav-link {
  padding: 8px 12px; border-radius: 8px; color: var(--text-soft);
  font-size: 14px; font-weight: 500; white-space: nowrap;
}
.top-nav-link:hover { background: var(--bg-soft); color: var(--text); }

.header-actions { display: flex; align-items: center; gap: 6px; }
.icon-btn {
  display: grid; place-items: center; width: 38px; height: 38px;
  background: transparent; border: 1px solid transparent; border-radius: 8px;
  color: var(--text-soft); cursor: pointer; transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--bg-soft); color: var(--text); }
.theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: block; }
.menu-toggle { display: none; }

/* ---------- Layout shell ---------- */
.shell {
  max-width: var(--maxw); margin: 0 auto;
  display: flex; align-items: flex-start; gap: 0;
  padding: 0 20px;
}

.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  position: sticky; top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto; padding: 22px 8px 40px 0;
  border-right: 1px solid var(--border);
}
.sidebar-title {
  font-size: 12px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-muted); margin: 0 0 10px 10px; font-weight: 700;
}
.side-nav { display: flex; flex-direction: column; gap: 4px; }
.nav-group { margin-bottom: 6px; }
.nav-group-title {
  display: block; padding: 6px 10px; font-weight: 700; font-size: 14px;
  color: var(--text); border-radius: 8px;
}
.nav-group-title:hover { background: var(--bg-soft); color: var(--text); }
.nav-group-list { list-style: none; margin: 2px 0 6px; padding: 0 0 0 8px; }
.nav-group-list li { margin: 0; }
.nav-link {
  display: block; padding: 5px 10px; font-size: 13.5px; color: var(--text-soft);
  border-radius: 7px; border-left: 2px solid transparent; line-height: 1.4;
}
.nav-link:hover { background: var(--bg-soft); color: var(--text); }
.nav-link.active {
  color: var(--brand); background: var(--brand-soft); font-weight: 600;
  border-left-color: var(--brand);
}
.sidebar-cta {
  display: inline-block; margin: 14px 0 0 10px; font-size: 13px; color: var(--brand); font-weight: 600;
}

.main-col { flex: 1; min-width: 0; display: flex; gap: 32px; padding: 28px 0 64px 32px; }
.content { flex: 1; min-width: 0; max-width: var(--content-w); }

.toc {
  width: var(--toc-w); flex-shrink: 0;
  position: sticky; top: var(--header-h);
  align-self: flex-start; max-height: calc(100vh - var(--header-h));
  overflow-y: auto; padding-top: 4px;
}
.toc-title {
  font-size: 12px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-muted); margin: 0 0 10px; font-weight: 700;
}
.toc-inner .toc-nav, .toc-inner ul { list-style: none; margin: 0; padding: 0; }
.toc-inner ul ul { padding-left: 12px; }
.toc-inner li { margin: 0; }
.toc-inner a {
  display: block; padding: 4px 10px; font-size: 13px; color: var(--text-muted);
  border-left: 2px solid var(--border); line-height: 1.4;
}
.toc-inner a:hover { color: var(--text); border-left-color: var(--border-strong); }
.toc-inner a.active { color: var(--brand); border-left-color: var(--brand); font-weight: 600; }

/* ---------- Hero ---------- */
.hero {
  background:
    radial-gradient(1100px 380px at 12% -10%, color-mix(in srgb, var(--brand) 16%, transparent), transparent 60%),
    radial-gradient(900px 360px at 100% 0%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 55%);
  border: 1px solid var(--border); border-radius: 18px;
  padding: 56px 40px; margin-bottom: 44px; text-align: center;
}
.hero-eyebrow {
  display: inline-block; font-size: 13px; font-weight: 600; color: var(--brand);
  background: var(--brand-soft); padding: 5px 12px; border-radius: 999px; margin: 0 0 16px;
}
.hero-title { font-size: clamp(30px, 5vw, 48px); line-height: 1.1; margin: 0 0 14px; letter-spacing: -.02em; }
.hero-title .grad {
  background: linear-gradient(120deg, var(--brand), var(--accent));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero-sub { max-width: 640px; margin: 0 auto 26px; color: var(--text-soft); font-size: 17px; }
.hero-search {
  display: inline-flex; align-items: center; gap: 10px;
  height: 48px; padding: 0 22px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border-strong);
  color: var(--text-soft); font-size: 15px; cursor: pointer; box-shadow: var(--shadow);
  transition: transform .12s, border-color .15s;
}
.hero-search:hover { transform: translateY(-1px); border-color: var(--brand); }
.hero-stats { display: flex; gap: 36px; justify-content: center; margin-top: 30px; }
.stat { display: flex; flex-direction: column; }
.stat-num { font-size: 26px; font-weight: 800; color: var(--text); }
.stat-label { font-size: 13px; color: var(--text-muted); }

/* ---------- Sections ---------- */
.section { margin-bottom: 48px; }
.section-head { margin-bottom: 20px; }
.section-title { font-size: 24px; margin: 0 0 4px; letter-spacing: -.01em; }
.section-sub { color: var(--text-muted); margin: 0; font-size: 15px; }

/* ---------- Cards ---------- */
.card-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 18px;
}
.cat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); transition: transform .14s, border-color .14s, box-shadow .14s;
  overflow: hidden;
}
.cat-card:hover { transform: translateY(-3px); border-color: var(--border-strong); box-shadow: var(--shadow-lg); }
.cat-card-link { display: block; padding: 22px; color: var(--text); }
.cat-card-link:hover { color: var(--text); }
.cat-card-title { margin: 0 0 8px; font-size: 19px; }
.cat-card-desc { margin: 0 0 12px; color: var(--text-soft); font-size: 14px; min-height: 40px; }
.cat-card-count { margin: 0 0 12px; font-size: 13px; font-weight: 700; color: var(--brand); }
.cat-card-topics { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.cat-card-topics li {
  font-size: 12px; color: var(--text-muted); background: var(--bg-soft);
  border: 1px solid var(--border); padding: 3px 9px; border-radius: 999px;
}
.cat-card-cta { font-size: 14px; font-weight: 600; color: var(--brand); }

.tut-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.tut-card {
  display: flex; flex-direction: column; gap: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow);
  transition: transform .14s, border-color .14s, box-shadow .14s; color: var(--text);
}
.tut-card:hover { transform: translateY(-2px); border-color: var(--brand); color: var(--text); box-shadow: var(--shadow-lg); }
.tut-card-cat { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--brand); }
.tut-card-title { margin: 0; font-size: 17px; line-height: 1.3; }
.tut-card-desc { margin: 0; color: var(--text-soft); font-size: 13.5px; flex: 1; }
.tut-card-meta { font-size: 12.5px; color: var(--text-muted); }
.tut-grid--list { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }

/* ---------- Page head / breadcrumb ---------- */
.breadcrumb { font-size: 13px; color: var(--text-muted); margin-bottom: 14px; display: flex; gap: 8px; flex-wrap: wrap; }
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--brand); }
.page-head { margin-bottom: 26px; padding-bottom: 18px; border-bottom: 1px solid var(--border); }
.page-title { font-size: 34px; margin: 0 0 8px; letter-spacing: -.02em; }
.page-desc { color: var(--text-soft); margin: 0 0 6px; font-size: 16px; }
.page-count { color: var(--text-muted); font-size: 14px; margin: 0; }

/* ---------- Tutorial article ---------- */
.tut-head { margin-bottom: 28px; padding-bottom: 20px; border-bottom: 1px solid var(--border); }
.tut-title { font-size: 36px; margin: 0 0 12px; letter-spacing: -.02em; line-height: 1.15; }
.tut-desc { font-size: 18px; color: var(--text-soft); margin: 0 0 14px; }
.tut-meta { display: flex; flex-wrap: wrap; gap: 10px; font-size: 13.5px; color: var(--text-muted); }

.tut-body { font-size: 16.5px; }
.tut-body h2 {
  font-size: 26px; margin: 38px 0 14px; padding-top: 6px; letter-spacing: -.01em;
  border-top: 1px solid var(--border); padding-top: 26px;
}
.tut-body h2:first-child { border-top: none; padding-top: 0; }
.tut-body h3 { font-size: 20px; margin: 28px 0 10px; }
.tut-body h4 { font-size: 17px; margin: 22px 0 8px; }
.tut-body p { margin: 0 0 16px; }
.tut-body ul, .tut-body ol { margin: 0 0 16px; padding-left: 24px; }
.tut-body li { margin: 6px 0; }
.tut-body blockquote {
  margin: 0 0 18px; padding: 12px 18px; border-left: 4px solid var(--brand);
  background: var(--brand-soft); border-radius: 0 8px 8px 0; color: var(--text-soft);
}
.tut-body blockquote p:last-child { margin-bottom: 0; }

/* tables */
.tut-body table { width: 100%; border-collapse: collapse; margin: 0 0 18px; font-size: 15px; }
.tut-body th, .tut-body td { border: 1px solid var(--border); padding: 9px 12px; text-align: left; }
.tut-body th { background: var(--bg-soft); font-weight: 700; }
.tut-body tr:nth-child(even) td { background: var(--bg-soft); }

/* inline code */
.tut-body :not(pre) > code {
  font-family: var(--font-mono); font-size: .88em;
  background: var(--bg-soft); border: 1px solid var(--border);
  padding: .12em .4em; border-radius: 6px; color: var(--brand-strong);
}
[data-theme="dark"] .tut-body :not(pre) > code { color: var(--brand-strong); }

/* code blocks */
.highlight {
  margin: 0 0 20px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--code-bg); overflow: auto; box-shadow: var(--shadow);
}
.highlight pre.chroma {
  margin: 0; padding: 16px 18px; background: transparent !important;
  font-family: var(--font-mono); font-size: 14px; line-height: 1.6;
  -webkit-text-size-adjust: none;
}
.highlight pre.chroma code { font-family: var(--font-mono); }

/* pager */
.tut-pager { display: flex; justify-content: space-between; gap: 16px; margin-top: 48px; padding-top: 24px; border-top: 1px solid var(--border); }
.pager-link {
  flex: 1; max-width: 48%; display: flex; flex-direction: column; gap: 4px;
  padding: 14px 18px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); transition: border-color .15s, transform .12s;
}
.pager-link:hover { border-color: var(--brand); transform: translateY(-1px); color: var(--text); }
.pager-next { text-align: right; align-items: flex-end; }
.pager-dir { font-size: 12.5px; color: var(--text-muted); font-weight: 600; }
.pager-name { font-size: 15px; font-weight: 700; }

/* ---------- Categories list page ---------- */
.cat-list { display: flex; flex-direction: column; gap: 14px; }
.cat-row { border: 1px solid var(--border); border-radius: var(--radius); padding: 22px 24px; background: var(--surface); box-shadow: var(--shadow); }
.cat-row-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.cat-row-title { margin: 0; font-size: 21px; }
.cat-row-title a { color: var(--text); }
.cat-row-count { font-size: 13px; color: var(--brand); font-weight: 700; white-space: nowrap; }
.cat-row-desc { color: var(--text-soft); margin: 0 0 12px; font-size: 14.5px; }
.cat-row-items { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; }
.cat-row-items a {
  font-size: 13.5px; padding: 5px 12px; border-radius: 999px;
  background: var(--bg-soft); border: 1px solid var(--border); color: var(--text-soft);
}
.cat-row-items a:hover { color: var(--brand); border-color: var(--brand); }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--border); background: var(--bg-soft); margin-top: 40px; }
.footer-inner {
  max-width: var(--maxw); margin: 0 auto; padding: 40px 20px 24px;
  display: flex; gap: 40px; flex-wrap: wrap; justify-content: space-between;
}
.footer-brand { max-width: 320px; }
.footer-tagline { color: var(--text-muted); font-size: 14px; margin: 10px 0 0; }
.footer-cols { display: flex; gap: 48px; flex-wrap: wrap; }
.footer-col-title { font-size: 14px; font-weight: 700; color: var(--text); margin: 0 0 10px; display: block; }
.footer-col ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.footer-col a { color: var(--text-soft); font-size: 14px; }
.footer-col a:hover { color: var(--brand); }
.footer-bottom { border-top: 1px solid var(--border); padding: 16px 20px; text-align: center; }
.footer-bottom p { margin: 0; color: var(--text-muted); font-size: 13px; }

/* ---------- Search modal ---------- */
.search-overlay {
  position: fixed; inset: 0; z-index: 200; display: none;
  background: rgba(8,12,20,.55); backdrop-filter: blur(3px);
  padding: 8vh 16px 16px;
}
.search-overlay.open { display: flex; justify-content: center; align-items: flex-start; }
.search-modal {
  width: 100%; max-width: 680px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-lg);
  overflow: hidden; max-height: 84vh; display: flex; flex-direction: column;
}
.search-modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.search-modal-title { font-weight: 700; font-size: 15px; }
.search-modal #search { overflow-y: auto; padding: 8px 14px 14px; }
#search input { background: var(--bg-soft) !important; color: var(--text) !important; border-color: var(--border) !important; }
#search mark { background: color-mix(in srgb, var(--brand) 35%, transparent) !important; color: inherit !important; }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .toc { display: none; }
}
@media (max-width: 980px) {
  .sidebar {
    position: fixed; top: var(--header-h); left: 0; bottom: 0; z-index: 60;
    background: var(--bg); border-right: 1px solid var(--border);
    transform: translateX(-100%); transition: transform .22s ease; width: 280px;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .main-col { padding-left: 0; }
  .top-nav { display: none; }
  .menu-toggle { display: grid; }
  .search-trigger { flex-basis: auto; }
  .search-trigger-text { display: none; }
}
@media (max-width: 640px) {
  .hero { padding: 40px 22px; }
  .hero-stats { gap: 22px; }
  .shell { padding: 0 14px; }
  .main-col { padding: 20px 0 48px; }
  .page-title, .tut-title { font-size: 28px; }
  .tut-pager { flex-direction: column; }
  .pager-link { max-width: 100%; }
  .pager-next { text-align: left; align-items: flex-start; }
}

/* toast for theme (optional) */
::selection { background: color-mix(in srgb, var(--brand) 28%, transparent); }
