/* ============================================================
   CSS Design Tokens
   ============================================================ */
:root {
  --color-bg:            #f5f5f7;
  --color-card:          #ffffff;
  --color-text:          #1d1d1f;
  --color-text-secondary:#6e6e73;
  --color-accent:        #0071e3;
  --color-accent-hover:  #0051a8;
  --color-nav:           #000000;
  --color-hero-from:     #1a1a2e;
  --color-hero-to:       #0f3460;
  --color-border:        #d2d2d7;
  --color-tag-bg:        #e8f0fe;
  --color-tag-text:      #0071e3;
  --radius-card:         12px;
  --radius-pill:         20px;
  --shadow-card:         0 2px 8px rgba(0,0,0,0.08);
  --shadow-drawer:       0 -4px 24px rgba(0,0,0,0.15);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display",
          "Helvetica Neue", Arial, sans-serif;
  --transition:          300ms ease-out;
  --nav-height:          52px;
}

/* ============================================================
   Reset & Base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-font-smoothing: antialiased;
}
a { text-decoration: none; color: inherit; }

/* ============================================================
   Navigation
   ============================================================ */
.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--nav-height);
  background: rgba(0,0,0,0.85);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  display: flex;
  align-items: center;
  padding: 0 24px;
}
.navbar-brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.navbar-title-zh {
  font-size: 14px;
  font-weight: 600;
  color: #f5f5f7;
}
.navbar-title-en {
  font-size: 12px;
  color: rgba(245,245,247,0.5);
  font-weight: 400;
}

/* ============================================================
   Hero
   ============================================================ */
.hero {
  background: linear-gradient(160deg, var(--color-hero-from), var(--color-hero-to));
  padding: 80px 24px 72px;
  text-align: center;
}
.hero-eyebrow {
  font-size: 13px;
  font-weight: 600;
  color: #86b7fe;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  margin-bottom: 16px;
}
.hero-title {
  font-size: clamp(32px, 5vw, 56px);
  font-weight: 700;
  color: #ffffff;
  letter-spacing: -0.5px;
  line-height: 1.1;
  margin-bottom: 12px;
}
.hero-subtitle {
  font-size: 18px;
  color: rgba(255,255,255,0.55);
  margin-bottom: 16px;
}
.hero-meta {
  font-size: 13px;
  color: rgba(255,255,255,0.35);
}

/* ============================================================
   Tab Bar
   ============================================================ */
#tab-sentinel { height: 1px; }
.tab-bar {
  background: var(--color-bg);
  border-bottom: 1px solid transparent;
  position: sticky;
  top: var(--nav-height);
  z-index: 90;
  transition: border-color 200ms, background 200ms,
              backdrop-filter 200ms, -webkit-backdrop-filter 200ms;
}
.tab-bar.stuck {
  background: rgba(245,245,247,0.85);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom-color: var(--color-border);
}
.tab-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tab-inner::-webkit-scrollbar { display: none; }
.tab-btn {
  flex-shrink: 0;
  padding: 6px 16px;
  border-radius: var(--radius-pill);
  border: 1.5px solid var(--color-border);
  background: transparent;
  font-family: var(--font);
  font-size: 13px;
  color: var(--color-text);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.tab-btn:hover { border-color: var(--color-accent); color: var(--color-accent); }
.tab-btn.active {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: #ffffff;
}

/* ============================================================
   Container & Grid
   ============================================================ */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px 80px;
}
.grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(4, 1fr);
}
.grid-fade {
  animation: fadeIn 250ms ease-out;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   Cards
   ============================================================ */
.card {
  background: var(--color-card);
  border-radius: var(--radius-card);
  padding: 20px;
  cursor: pointer;
  box-shadow: var(--shadow-card);
  transition: transform var(--transition), box-shadow var(--transition);
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
}
.card-tag {
  font-size: 11px;
  font-weight: 500;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.card-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.3;
}
.card-subtitle {
  font-size: 12px;
  color: var(--color-text-secondary);
  font-style: italic;
}
.card-desc {
  font-size: 13px;
  color: var(--color-text-secondary);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: 4px;
}

/* ============================================================
   Drawer (Bottom Sheet)
   ============================================================ */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}
.drawer-overlay.show {
  opacity: 1;
  pointer-events: auto;
}
.drawer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--color-card);
  border-radius: 20px 20px 0 0;
  z-index: 201;
  padding: 12px 24px 48px;
  transform: translateY(100%);
  transition: transform var(--transition);
  max-height: 78vh;
  overflow-y: auto;
}
.drawer.open { transform: translateY(0); }
.drawer-handle {
  width: 36px;
  height: 4px;
  background: var(--color-border);
  border-radius: 2px;
  margin: 0 auto 20px;
}
.drawer-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  color: var(--color-accent);
  background: var(--color-tag-bg);
  padding: 3px 10px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}
.drawer-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.2;
  margin-bottom: 4px;
}
.drawer-subtitle {
  font-size: 13px;
  color: var(--color-text-secondary);
  font-style: italic;
  margin-bottom: 14px;
}
.drawer-desc {
  font-size: 14px;
  color: var(--color-text-secondary);
  line-height: 1.65;
  margin-bottom: 16px;
}
.drawer-skills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 22px;
}
.skill-pill {
  background: var(--color-tag-bg);
  color: var(--color-accent);
  font-size: 12px;
  font-weight: 500;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
}
.drawer-actions { display: flex; gap: 12px; flex-wrap: wrap; }

/* ============================================================
   Buttons
   ============================================================ */
.btn-primary {
  display: inline-flex;
  align-items: center;
  padding: 10px 22px;
  background: var(--color-accent);
  color: #ffffff;
  border-radius: var(--radius-pill);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition);
  border: none;
}
.btn-primary:hover { background: var(--color-accent-hover); }
.btn-secondary {
  display: inline-flex;
  align-items: center;
  padding: 10px 22px;
  background: transparent;
  color: var(--color-text);
  border-radius: var(--radius-pill);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  border: 1.5px solid var(--color-border);
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition);
}
.btn-secondary:hover { border-color: var(--color-accent); color: var(--color-accent); }

/* ============================================================
   Focus Styles (Accessibility)
   ============================================================ */
.tab-btn:focus-visible,
.btn-primary:focus-visible,
.btn-secondary:focus-visible,
.toc-link:focus-visible,
.card:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* ============================================================
   Detail Page — Hero
   ============================================================ */
.detail-hero {
  background: linear-gradient(160deg, var(--color-hero-from), var(--color-hero-to));
  padding: 60px 24px 48px;
  text-align: center;
}
.detail-hero .back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: rgba(255,255,255,0.6);
  font-size: 13px;
  margin-bottom: 24px;
  transition: color var(--transition);
}
.detail-hero .back-link:hover { color: #ffffff; }
.detail-tag {
  display: inline-block;
  background: rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.85);
  font-size: 12px;
  font-weight: 500;
  padding: 4px 14px;
  border-radius: var(--radius-pill);
  letter-spacing: 0.5px;
  margin-bottom: 16px;
}
.detail-title {
  font-size: clamp(28px, 4vw, 44px);
  font-weight: 700;
  color: #ffffff;
  line-height: 1.15;
  margin-bottom: 8px;
}
.detail-subtitle-text {
  font-size: 16px;
  color: rgba(255,255,255,0.5);
}

/* ============================================================
   Detail Page — Layout
   ============================================================ */
.detail-layout {
  max-width: 1100px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 48px;
  padding: 40px 24px 100px;
  align-items: start;
}
.detail-sidebar {
  position: sticky;
  top: calc(var(--nav-height) + 24px);
}
.toc-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 0 12px;
  margin-bottom: 8px;
}
.toc { display: flex; flex-direction: column; gap: 2px; }
.toc-link {
  display: block;
  font-size: 13px;
  color: var(--color-text-secondary);
  padding: 7px 12px;
  border-radius: 8px;
  border-left: 2px solid transparent;
  transition: all 200ms;
  line-height: 1.4;
}
.toc-link:hover {
  color: var(--color-text);
  background: rgba(0,0,0,0.04);
}
.toc-link.active {
  color: var(--color-accent);
  border-left-color: var(--color-accent);
  background: var(--color-tag-bg);
  font-weight: 500;
}

/* ============================================================
   Detail Page — Content
   ============================================================ */
.detail-section {
  padding: 32px 0;
  border-bottom: 1px solid var(--color-border);
}
.detail-section:last-child { border-bottom: none; }
.detail-section > h2 {
  font-size: 20px;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 16px;
}
.detail-section > p {
  font-size: 15px;
  line-height: 1.7;
  color: var(--color-text-secondary);
}
.skills-list { display: flex; flex-wrap: wrap; gap: 8px; }
.github-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--color-accent);
  font-size: 14px;
  font-weight: 500;
}
.github-link:hover { text-decoration: underline; }

/* ============================================================
   Markdown Body (rendered usage content)
   ============================================================ */
.markdown-body {
  font-size: 14px;
  line-height: 1.7;
  color: var(--color-text-secondary);
}
.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
  color: var(--color-text);
  font-weight: 600;
  margin: 24px 0 10px;
  line-height: 1.3;
}
.markdown-body h1 { font-size: 20px; }
.markdown-body h2 { font-size: 17px; }
.markdown-body h3 { font-size: 15px; }
.markdown-body p { margin-bottom: 12px; }
.markdown-body ul,
.markdown-body ol {
  padding-left: 20px;
  margin-bottom: 12px;
}
.markdown-body li { margin-bottom: 5px; }
.markdown-body blockquote {
  border-left: 3px solid var(--color-border);
  padding-left: 14px;
  color: var(--color-text-secondary);
  margin: 12px 0;
}
.markdown-body pre {
  background: #1d1d1f;
  color: #f5f5f7;
  border-radius: 10px;
  padding: 16px 20px;
  overflow-x: auto;
  margin: 14px 0;
  font-size: 13px;
  line-height: 1.55;
}
.markdown-body code {
  background: rgba(0,0,0,0.06);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
  font-family: "SF Mono", "Fira Code", monospace;
}
.markdown-body pre code {
  background: none;
  padding: 0;
  color: inherit;
}
.markdown-body a {
  color: var(--color-accent);
  text-decoration: underline;
}
.markdown-body a:hover {
  color: var(--color-accent-hover);
}

/* ============================================================
   Error / Not Found
   ============================================================ */
.error-page {
  text-align: center;
  padding: 120px 24px;
}
.error-page h2 {
  font-size: 28px;
  font-weight: 600;
  margin-bottom: 12px;
}
.error-page p {
  color: var(--color-text-secondary);
  margin-bottom: 28px;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 1023px) {
  .grid { grid-template-columns: repeat(2, 1fr); }
  .detail-layout {
    grid-template-columns: 1fr;
    gap: 0;
  }
  .detail-sidebar { display: none; }
  .detail-content { padding-top: 24px; }
}
@media (max-width: 767px) {
  .grid { grid-template-columns: 1fr; }
  .container { padding: 20px 16px 60px; }
  .hero { padding: 56px 16px 48px; }
  .tab-inner { padding: 10px 16px; }
  .navbar { padding: 0 16px; }
  .detail-layout { padding: 24px 16px 80px; }
  .detail-hero { padding: 48px 16px 36px; }
  .drawer { padding: 12px 20px 48px; }
}
