:root {
  --bg: #f6f5f2;
  --bg-accent: #edeae2;
  --text: #1a1816;
  --muted: #6b6259;
  --card: rgba(255, 255, 255, 0.92);
  --border: rgba(45, 38, 31, 0.11);
  --primary: #1a6b8a;
  --primary-soft: rgba(26, 107, 138, 0.08);
  --primary-ink: #ffffff;
  --accent: #c6932f;
  --shadow-sm: 0 2px 8px rgba(34, 28, 22, 0.06);
  --shadow: 0 8px 24px rgba(34, 28, 22, 0.07);
  --shadow-lg: 0 16px 40px rgba(34, 28, 22, 0.1);
  --radius: 12px;
  --radius-lg: 16px;
  --transition: 200ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: "Source Sans 3", "Segoe UI", system-ui, sans-serif;
  font-size: 18px;
  color: var(--text);
  background:
    radial-gradient(ellipse at 10% 0%, rgba(26, 107, 138, 0.1), transparent 50%),
    radial-gradient(ellipse at 90% 5%, rgba(198, 147, 47, 0.08), transparent 45%),
    var(--bg);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

.bg-shape { display: none; }

/* ── Header ─────────────────────────────────────────── */

.site-header {
  width: min(1120px, calc(100% - 2rem));
  margin: 1.2rem auto 0;
  padding: 0.85rem 1.3rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow-sm);
}

.brand {
  color: var(--text);
  text-decoration: none;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.subtitle {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.header-tools {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.top-nav {
  display: flex;
  align-items: center;
  gap: 0.2rem;
}

.top-nav a {
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.92rem;
  padding: 0.4rem 0.7rem;
  border-radius: 8px;
  transition: color var(--transition), background var(--transition);
}

.top-nav a:hover {
  color: var(--text);
  background: var(--primary-soft);
}

/* ── Search ─────────────────────────────────────────── */

.search-wrap {
  margin-top: 1rem;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  padding: 0.28rem 0.3rem 0.28rem 0.85rem;
  gap: 0.45rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.search-wrap:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26, 107, 138, 0.1);
}

.search-wrap.header-search { margin-top: 0; }
.search-wrap.header-search input { min-width: min(36vw, 260px); }

.search-wrap input {
  border: none;
  outline: none;
  min-width: min(55vw, 300px);
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text);
}

.search-wrap input::placeholder { color: #a09890; }

.search-wrap span {
  font-size: 0.85rem;
  font-weight: 700;
  color: #fff;
  background: var(--primary);
  border-radius: 7px;
  padding: 0.38rem 0.7rem;
}

/* ── Main Shell ─────────────────────────────────────── */

.main-shell {
  width: min(1120px, calc(100% - 2rem));
  margin: 1.2rem auto 2rem;
}

/* ── Hero ────────────────────────────────────────────── */

.hero {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: clamp(1.3rem, 3vw, 2.5rem);
  background: linear-gradient(150deg, rgba(255, 255, 255, 0.97), rgba(255, 255, 255, 0.88));
  box-shadow: var(--shadow);
  animation: fadeUp 320ms ease-out;
}

.hero h1 {
  margin: 0;
  font-family: "Merriweather", Georgia, serif;
  font-size: clamp(1.4rem, 4.5vw, 2.4rem);
  color: var(--text);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.hero p {
  margin: 0.6rem 0 0;
  max-width: 68ch;
  color: var(--muted);
  line-height: 1.6;
  font-size: 1.05rem;
}

/* ── Featured Card ──────────────────────────────────── */

.landing-featured { margin-top: 1.2rem; }

.featured-card {
  border: 1px solid rgba(26, 107, 138, 0.18);
  border-radius: var(--radius-lg);
  background: linear-gradient(145deg, rgba(26, 107, 138, 0.04), rgba(255, 255, 255, 0.96));
  box-shadow: var(--shadow);
  padding: clamp(1.2rem, 3vw, 2rem);
  animation: fadeUp 320ms ease-out;
  transition: box-shadow var(--transition);
}

.featured-card:hover {
  box-shadow: var(--shadow-lg);
}

.featured-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(1rem, 3vw, 2rem);
  align-items: center;
}

.featured-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--primary);
  background: var(--primary-soft);
  border: 1px solid rgba(26, 107, 138, 0.15);
  border-radius: 6px;
  padding: 0.22rem 0.6rem;
  margin-bottom: 0.7rem;
}

.featured-title {
  margin: 0 0 0.45rem;
  font-family: "Merriweather", Georgia, serif;
  font-size: clamp(1.15rem, 2.8vw, 1.55rem);
  color: var(--text);
  font-weight: 700;
  letter-spacing: -0.015em;
  line-height: 1.3;
}

.featured-excerpt {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.6;
}

.featured-thumb {
  position: relative;
  display: block;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 16/9;
  box-shadow: var(--shadow);
  transition: transform var(--transition), box-shadow var(--transition);
}

.featured-thumb:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.featured-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 400ms ease;
}

.featured-thumb:hover img {
  transform: scale(1.03);
}

.play-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.25);
  transition: background var(--transition);
}

.featured-thumb:hover .play-overlay {
  background: rgba(0, 0, 0, 0.35);
}

.play-overlay svg {
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.3));
  transition: transform var(--transition);
}

.featured-thumb:hover .play-overlay svg {
  transform: scale(1.1);
}

/* ── Section Label ──────────────────────────────────── */

.section-label {
  margin: 2rem 0 0.7rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ── Labs Grid ──────────────────────────────────────── */

.landing-labs-section .labs-grid { margin-top: 0; }

.labs-grid {
  margin-top: 1rem;
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

/* ── Lab Card ───────────────────────────────────────── */

.lab-card,
.panel,
.lab-content {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow-sm);
}

.lab-card {
  padding: 1.1rem 1.2rem;
  opacity: 0;
  transform: translateY(6px);
  animation: fadeUp 320ms ease-out forwards;
  transition: box-shadow var(--transition), transform var(--transition), border-color var(--transition);
}

.lab-card:hover {
  box-shadow: var(--shadow);
  transform: translateY(-2px);
  border-color: rgba(26, 107, 138, 0.18);
}

.lab-card-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.35rem;
}

.lab-badge {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-soft);
  border-radius: 8px;
  letter-spacing: 0.02em;
}

.lab-card h3 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--text);
  font-weight: 700;
  line-height: 1.3;
}

.lab-card p {
  margin: 0.3rem 0 0;
  color: var(--muted);
  line-height: 1.5;
  font-size: 0.95rem;
}

/* ── Buttons ────────────────────────────────────────── */

.card-actions {
  margin-top: 0.8rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  border-radius: 8px;
  padding: 0.5rem 0.85rem;
  font-size: 0.9rem;
  font-weight: 700;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-lg {
  padding: 0.6rem 1.1rem;
  font-size: 0.95rem;
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-ink);
}

.btn-primary:hover {
  background: #15596f;
  box-shadow: 0 4px 12px rgba(26, 107, 138, 0.25);
}

.btn-ghost {
  background: #fff;
  color: var(--muted);
  border-color: var(--border);
}

.btn-ghost:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-soft);
}

/* ── Landing Panels ─────────────────────────────────── */

.landing-panels {
  margin-top: 1.2rem;
  display: grid;
  gap: 0.9rem;
  grid-template-columns: 1.8fr 1fr;
}

.panel { padding: 1rem; }
.panel h2 { margin: 0; font-family: "Merriweather", Georgia, serif; }
.panel p, .panel li { color: var(--muted); line-height: 1.6; font-size: 1rem; }
.panel ul { margin: 0.7rem 0 0; padding-left: 1rem; }

/* ── Lab Content ────────────────────────────────────── */

.lab-content {
  margin-top: 1.2rem;
  padding: clamp(1rem, 2.5vw, 2rem);
}

/* ── Pagination ─────────────────────────────────────── */

.part-pagination {
  margin-top: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  flex-wrap: wrap;
}

.part-pages {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.part-link, .part-nav {
  text-decoration: none;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  padding: 0.34rem 0.65rem;
  font-size: 0.84rem;
  font-weight: 700;
  transition: all var(--transition);
}

.part-link:hover { border-color: var(--primary); color: var(--primary); }

.part-link.active {
  background: var(--primary);
  color: var(--primary-ink);
  border-color: var(--primary);
}

.part-nav.disabled { opacity: 0.4; pointer-events: none; }

/* ── Markdown Body ──────────────────────────────────── */

.markdown-body {
  line-height: 1.6;
  font-size: 1.08rem;
}

.markdown-body p { margin: 0.45rem 0 0.6rem; }

.markdown-body ol, .markdown-body ul {
  padding-left: 1.3rem;
  margin-top: 0.4rem;
  margin-bottom: 0.65rem;
}

.markdown-body li { margin: 0.1rem 0; }
.markdown-body ol li > p, .markdown-body ul li > p { margin: 0.1rem 0; }

.markdown-body ol ol, .markdown-body ul ul,
.markdown-body ol ul, .markdown-body ul ol {
  margin-top: 0.2rem;
  margin-bottom: 0.4rem;
  padding-left: 1.1rem;
}

.markdown-body ol ol { list-style-type: lower-alpha; }
.markdown-body ol ol ol { list-style-type: lower-roman; }

.markdown-body h1, .markdown-body h2, .markdown-body h3 {
  font-family: "Merriweather", Georgia, serif;
  margin-top: 1.2rem;
  margin-bottom: 0.5rem;
  color: var(--text);
  letter-spacing: -0.01em;
}

.markdown-body .header-anchor {
  color: inherit;
  text-decoration: none;
}

.markdown-body .header-anchor:hover {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.markdown-body table {
  width: 100%;
  max-width: 980px;
  border-collapse: collapse;
  margin: 0.8rem auto;
  display: table;
  background: rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  overflow: hidden;
}

.markdown-body th, .markdown-body td {
  border: 1px solid var(--border);
  padding: 0.44rem 0.58rem;
  text-align: left;
  vertical-align: middle;
}

.markdown-body th {
  font-weight: 700;
  background: var(--primary-soft);
}

.markdown-body tbody tr:nth-child(even) {
  background: rgba(26, 107, 138, 0.02);
}

.markdown-body pre {
  position: relative;
  border-radius: var(--radius);
  overflow-x: auto;
  padding-top: 2rem;
  margin: 0.7rem 0 0.9rem;
}

.markdown-body pre code {
  display: block;
  padding: 0.9rem 1rem 1rem;
  line-height: 1.48;
  font-size: 0.95rem;
  white-space: pre;
  tab-size: 4;
  font-family: "Cascadia Code", Consolas, "Fira Code", monospace;
}

.markdown-body :not(pre) > code {
  background: rgba(26, 107, 138, 0.07);
  border: 1px solid rgba(26, 107, 138, 0.1);
  border-radius: 5px;
  padding: 0.08rem 0.32rem;
  font-size: 0.88em;
}

.markdown-body table code {
  background: transparent;
  border: none;
  padding: 0;
  border-radius: 0;
  font-size: 0.94em;
}

.markdown-body img {
  display: block;
  margin: 1rem auto;
  width: auto !important;
  max-width: min(100%, 980px) !important;
  max-height: 520px;
  height: auto !important;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.markdown-body p > img:only-child,
.markdown-body p > a > img:only-child {
  margin-left: auto;
  margin-right: auto;
}

/* ── Copy Button ────────────────────────────────────── */

.copy-button {
  position: absolute;
  top: 0.45rem;
  right: 0.45rem;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  background: rgba(26, 29, 34, 0.82);
  color: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  padding: 0.22rem 0.55rem;
  font-size: 0.72rem;
  font-weight: 700;
  transition: color var(--transition), background var(--transition);
}

.copy-button:hover {
  background: rgba(26, 29, 34, 0.95);
  color: #fff;
}

.copy-button.success { color: #6ee7b7; }

/* ── Footer ─────────────────────────────────────────── */

.site-footer {
  width: min(1120px, calc(100% - 2rem));
  margin: 0 auto 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.88rem;
}

/* ── Animations ─────────────────────────────────────── */

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Responsive ─────────────────────────────────────── */

@media (max-width: 880px) {
  .site-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .header-tools { width: 100%; flex-wrap: wrap; }

  .featured-body {
    grid-template-columns: 1fr;
  }

  .featured-thumb {
    order: -1;
  }

  .landing-panels { grid-template-columns: 1fr; }
}

@media (max-width: 680px) {
  .header-tools {
    flex-direction: column;
    align-items: stretch;
  }

  .top-nav { flex-wrap: wrap; gap: 0.4rem; }
  .search-wrap { width: 100%; }
  .search-wrap input { min-width: 0; width: 100%; }

  .labs-grid {
    grid-template-columns: 1fr;
  }

  .markdown-body table {
    width: 100%;
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }

  .markdown-body img {
    max-width: min(100%, 720px) !important;
    max-height: 360px;
  }
}
