/*
 * PyDevices — shared org site chrome
 *
 * Design tokens + layout primitives shared by every PyDevices GitHub Pages
 * site (org root, lvgl-bindings, pydevices-examples, and the second-wave module
 * pages). Keep this file focused on *chrome*: header/nav, hero, buttons,
 * cards, footer, typography. Project-specific / demo-runtime styles belong
 * in a local stylesheet loaded after this one.
 *
 * Theme: dark by default; `<html data-theme="light">` switches to the light
 * palette. Pair with assets/js/theme-toggle.js, which flips the attribute
 * and persists the choice in localStorage. Pages that render the toggle
 * button should apply the visitor's stored preference in an inline <head>
 * script (before this stylesheet paints) to avoid a flash of the wrong
 * theme — see any page's <head> for the one-line snippet.
 *
 * Canonical copy: https://pydevices.github.io/assets/css/site.css
 * Repos vendor a copy under web/vendor/pydevices-chrome/site.css for
 * offline dev + CI; keep vendored copies in sync with this file.
 */

:root {
  --bg: #100e0b;
  --bg-soft: #17130f;
  --panel: #1c1712;
  --panel-2: #241e17;
  --border: #342a1d;
  --border-soft: #2a2117;
  --ink: #f3ecdf;
  --ink-soft: #c9bfae;
  --muted: #8f8474;
  --accent: #f54e00;
  --accent-soft: #ff7a3d;
  --accent-strong: #ff8a52;
  --accent-ink: #1a0d05;
  --indigo: #8b93ff;
  --good: #3ecf95;
  --warn: #e8b34e;
  --bad: #ef5c4e;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.45);
  --shadow-soft: 0 6px 18px rgba(0, 0, 0, 0.3);
  --hover-border: #4a3c28;
  --font-display: "Space Grotesk", ui-sans-serif, system-ui, "Segoe UI", Roboto, sans-serif;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "SF Mono", "JetBrains Mono", "Fira Code", ui-monospace, Menlo, Consolas, monospace;

  /* Tier-specific visual design tokens */
  --tier-1-amber: #f59e0b;
  --tier-1-bg: rgba(245, 158, 11, 0.08);
  --tier-1-border: rgba(245, 158, 11, 0.4);

  --tier-2-emerald: #10b981;
  --tier-2-bg: rgba(16, 185, 129, 0.08);
  --tier-2-border: rgba(16, 185, 129, 0.4);

  --tier-3-blue: #3b82f6;
  --tier-3-bg: rgba(59, 130, 246, 0.08);
  --tier-3-border: rgba(59, 130, 246, 0.4);

  --tier-4-purple: #8b5cf6;
  --tier-4-bg: rgba(139, 92, 246, 0.08);
  --tier-4-border: rgba(139, 92, 246, 0.4);

  --tier-5-steel: #06b6d4;
  --tier-5-bg: rgba(6, 182, 212, 0.08);
  --tier-5-border: rgba(6, 182, 212, 0.4);
}

:root[data-theme="light"] {
  --bg: #fbf9f5;
  --bg-soft: #f3eee6;
  --panel: #ffffff;
  --panel-2: #f6f1e9;
  --border: #e7e0d3;
  --border-soft: #eee8db;
  --ink: #201c16;
  --ink-soft: #5b5347;
  --muted: #8a8172;
  --accent-strong: #c33f00;
  --accent-ink: #fff7f1;
  --indigo: #5a4fd6;
  --good: #1f8f6b;
  --warn: #b5790a;
  --bad: #d1382b;
  --shadow: 0 18px 44px rgba(32, 24, 12, 0.1);
  --shadow-soft: 0 6px 18px rgba(32, 24, 12, 0.06);
  --hover-border: #d9cfba;

  /* Light theme tier adjustments */
  --tier-1-bg: rgba(245, 158, 11, 0.1);
  --tier-2-bg: rgba(16, 185, 129, 0.1);
  --tier-3-bg: rgba(59, 130, 246, 0.1);
  --tier-4-bg: rgba(139, 92, 246, 0.1);
  --tier-5-bg: rgba(6, 182, 212, 0.1);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--ink);
  line-height: 1.6;
  background:
    radial-gradient(1100px 560px at 14% -12%, rgba(245, 78, 0, 0.16), transparent 60%),
    radial-gradient(900px 520px at 100% 0%, rgba(139, 147, 255, 0.1), transparent 55%),
    var(--bg);
  background-attachment: fixed;
  display: flex;
  flex-direction: column;
}

:root[data-theme="light"] body {
  background:
    radial-gradient(1100px 560px at 14% -12%, rgba(245, 78, 0, 0.09), transparent 60%),
    radial-gradient(900px 520px at 100% 0%, rgba(90, 79, 214, 0.06), transparent 55%),
    var(--bg);
  background-attachment: fixed;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 600;
}

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

a:hover {
  text-decoration: underline;
}

code, kbd {
  font-family: var(--mono);
  font-size: 0.92em;
}

code {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.08em 0.4em;
  color: var(--ink);
}

kbd {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 0.1em 0.45em;
  color: var(--ink);
}

pre {
  margin: 0;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #1c1712;
  padding: 14px 16px;
}

pre code {
  background: none;
  border: none;
  padding: 0;
  color: #f3ecdf;
}

.wrap {
  width: min(1080px, 92vw);
  margin: 0 auto;
}

/* ---------- Header / nav ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(10px);
  background: rgba(16, 14, 11, 0.82);
  border-bottom: 1px solid var(--border-soft);
}

:root[data-theme="light"] .site-header {
  background: rgba(251, 249, 245, 0.82);
}

.site-header .wrap {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 14px 0;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
  font-size: 1.12rem;
}

.brand:hover {
  text-decoration: none;
}

.brand .logo {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: linear-gradient(135deg, var(--accent-soft), var(--accent));
  box-shadow: 0 4px 14px rgba(245, 78, 0, 0.32);
}

.brand .logo img,
.brand .logo svg {
  width: 100%;
  height: 100%;
  display: block;
}

.brand .accent {
  color: var(--accent-strong);
}

.nav {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 22px;
  font-size: 0.95rem;
}

.nav a {
  color: var(--ink-soft);
}

.nav a:hover {
  color: var(--ink);
  text-decoration: none;
}

/* ---------- Theme toggle ---------- */

.theme-toggle {
  flex: none;
  margin-left: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--ink-soft);
  cursor: pointer;
  padding: 0;
  transition: border-color 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}

.theme-toggle:hover {
  border-color: var(--accent-strong);
  color: var(--accent-strong);
  box-shadow: var(--shadow-soft);
}

.theme-toggle svg {
  width: 17px;
  height: 17px;
}

.theme-toggle .icon-moon {
  display: none;
}

.theme-toggle .icon-sun {
  display: block;
}

:root[data-theme="light"] .theme-toggle .icon-sun {
  display: none;
}

:root[data-theme="light"] .theme-toggle .icon-moon {
  display: block;
}

/* ---------- Hero ---------- */

.hero {
  padding: 90px 0 34px;
  text-align: left;
}

.hero-lead {
  display: flex;
  align-items: center;
  gap: clamp(20px, 4vw, 36px);
  margin: 0 0 20px;
}

.hero-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  flex: none;
  max-width: 11rem;
}

.logo-badge {
  width: 112px;
  height: 112px;
  margin: 0;
  border-radius: 28px;
  overflow: hidden;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--accent-soft), var(--accent));
  box-shadow: 0 16px 36px rgba(245, 78, 0, 0.32);
}

.logo-badge img,
.logo-badge svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* Product hero mark — same orange badge as the org logo, but the card icon
 * (stroke SVG under assets/img/products/) instead of the shared PyDevices mark.
 * Keeps header branding org-wide while each product page gets its own face. */
.logo-badge.product-mark {
  padding: 0;
}

.logo-badge.product-mark img,
.logo-badge.product-mark > svg {
  width: 54%;
  height: 54%;
}

/* Short API / install excerpts under section heads */
.snippet-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px;
}

.snippet-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow-soft);
  padding: 18px 20px;
  text-align: left;
}

.snippet-card h3 {
  margin: 0 0 6px;
  font-size: 1.02rem;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.snippet-card p {
  margin: 0 0 12px;
  color: var(--ink-soft);
  font-size: 0.92rem;
}

.snippet-card pre {
  margin: 0;
}

.hero .eyebrow {
  display: inline-block;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent-strong);
  margin: 0;
  text-align: center;
}

.hero-lead > h1,
.hero h1 {
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
  font-size: clamp(1.6rem, 3.2vw, 2.1rem);
  letter-spacing: -0.015em;
  line-height: 1.15;
  color: var(--ink);
}

.hero p {
  margin: 0;
  max-width: 100%;
  color: var(--ink-soft);
  font-size: 1.08rem;
  line-height: 1.55;
  text-align: left;
}

.hero p + p {
  margin-top: 1em;
}

@media (max-width: 640px) {
  .hero-lead {
    flex-direction: column;
    align-items: flex-start;
  }

  .hero-brand {
    align-items: flex-start;
    max-width: none;
  }

  .hero .eyebrow {
    text-align: left;
  }
}

.callout {
  margin: 26px auto 0;
  max-width: 660px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  text-align: left;
  padding: 14px 18px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--ink-soft);
  font-size: 0.95rem;
}

.callout svg {
  flex: none;
  width: 18px;
  height: 18px;
  margin-top: 2px;
  color: var(--accent-strong);
}

/* ---------- Buttons ---------- */

.cta {
  margin: 30px 0 8px;
  display: flex;
  justify-content: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 22px;
  border-radius: var(--radius-sm);
  font-size: 0.98rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  transition: border-color 0.16s ease, transform 0.1s ease, box-shadow 0.16s ease;
}

.btn:hover {
  border-color: var(--hover-border);
  box-shadow: var(--shadow-soft);
  text-decoration: none;
}

.btn:active {
  transform: translateY(1px);
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent-soft), var(--accent));
  border-color: transparent;
  color: var(--accent-ink);
}

.btn.primary:hover {
  box-shadow: 0 10px 24px rgba(245, 78, 0, 0.28);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn svg {
  width: 17px;
  height: 17px;
}

/* ---------- Section headings ---------- */

.section {
  padding: 30px 0;
}

.section-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin: 6px 0 20px;
}

.section-head h2 {
  margin: 0;
  font-size: 1.4rem;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.section-head .hint {
  color: var(--muted);
  font-size: 0.9rem;
}

/* ---------- Cards ---------- */

.cards {
  flex: 1;
  padding: 24px 0 60px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 18px;
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
  transition: transform 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}

.card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), transparent 70%);
  opacity: 0;
  transition: opacity 0.16s ease;
}

.card:hover {
  transform: translateY(-3px);
  border-color: var(--hover-border);
  box-shadow: var(--shadow);
  text-decoration: none;
}

.card:hover::before {
  opacity: 1;
}

.card .icon,
.card .card-icon {
  width: 42px;
  height: 42px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--accent-strong);
  margin-bottom: 6px;
}

.card .icon svg,
.card .card-icon svg {
  width: 22px;
  height: 22px;
}

.card h3 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.card p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.94rem;
  flex: 1;
}

.card .go {
  margin-top: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--accent-strong);
}

.card .go svg {
  width: 15px;
  height: 15px;
  transition: transform 0.16s ease;
}

.card:hover .go svg {
  transform: translateX(3px);
}

.tag {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.18em 0.55em;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--ink-soft);
  background: var(--panel-2);
}

.tag.async, .tag.featured {
  color: var(--indigo);
  border-color: rgba(139, 147, 255, 0.3);
  background: rgba(139, 147, 255, 0.1);
}

:root[data-theme="light"] .tag.async,
:root[data-theme="light"] .tag.featured {
  border-color: rgba(90, 79, 214, 0.3);
  background: rgba(90, 79, 214, 0.08);
}

.tag.all, .tag.tool {
  color: var(--good);
  border-color: rgba(62, 207, 149, 0.3);
  background: rgba(62, 207, 149, 0.1);
}

:root[data-theme="light"] .tag.all,
:root[data-theme="light"] .tag.tool {
  border-color: rgba(31, 143, 107, 0.3);
  background: rgba(31, 143, 107, 0.08);
}

.tag.loops, .tag.warn {
  color: var(--warn);
  border-color: rgba(232, 179, 78, 0.3);
  background: rgba(232, 179, 78, 0.1);
}

:root[data-theme="light"] .tag.loops,
:root[data-theme="light"] .tag.warn {
  border-color: rgba(181, 121, 10, 0.3);
  background: rgba(181, 121, 10, 0.08);
}

.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

/* Simple link list */
.linklist {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.linklist a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--ink-soft);
  font-size: 0.95rem;
  transition: border-color 0.16s ease, color 0.16s ease;
}

.linklist a:hover {
  border-color: var(--hover-border);
  color: var(--ink);
  text-decoration: none;
}

.linklist svg {
  width: 17px;
  height: 17px;
  color: var(--muted);
}

/* ---------- Simple content blocks (thin module pages) ---------- */

.prose {
  color: var(--ink-soft);
  font-size: 1.02rem;
}

.prose h2 {
  color: var(--ink);
  margin: 0 0 14px;
}

.install-block {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow-soft);
  padding: 22px 24px;
}

.install-block h2 {
  margin: 0 0 12px;
  font-size: 1.1rem;
  color: var(--ink);
}

/* ---------- Tier-Specific Visual Contrast Card Styles ---------- */

.card-tier-1 {
  border-color: var(--tier-1-border);
  background: linear-gradient(180deg, var(--tier-1-bg), var(--panel));
}
.card-tier-1::before {
  background: linear-gradient(90deg, var(--tier-1-amber), transparent 75%);
  opacity: 0.8;
}
.card-tier-1:hover {
  border-color: var(--tier-1-amber);
  box-shadow: 0 12px 30px rgba(245, 158, 11, 0.15);
}
.card-tier-1 .icon, .card-tier-1 .card-icon {
  color: var(--tier-1-amber);
  background: rgba(245, 158, 11, 0.12);
  border-color: var(--tier-1-border);
}
.tag-tier-1 {
  color: var(--tier-1-amber);
  border-color: var(--tier-1-border);
  background: var(--tier-1-bg);
}

.card-tier-2 {
  border-color: var(--tier-2-border);
  background: linear-gradient(180deg, var(--tier-2-bg), var(--panel));
}
.card-tier-2::before {
  background: linear-gradient(90deg, var(--tier-2-emerald), transparent 75%);
  opacity: 0.8;
}
.card-tier-2:hover {
  border-color: var(--tier-2-emerald);
  box-shadow: 0 12px 30px rgba(16, 185, 129, 0.15);
}
.card-tier-2 .icon, .card-tier-2 .card-icon {
  color: var(--tier-2-emerald);
  background: rgba(16, 185, 129, 0.12);
  border-color: var(--tier-2-border);
}
.tag-tier-2 {
  color: var(--tier-2-emerald);
  border-color: var(--tier-2-border);
  background: var(--tier-2-bg);
}

.card-tier-3 {
  border-color: var(--tier-3-border);
  background: linear-gradient(180deg, var(--tier-3-bg), var(--panel));
}
.card-tier-3::before {
  background: linear-gradient(90deg, var(--tier-3-blue), transparent 75%);
  opacity: 0.8;
}
.card-tier-3:hover {
  border-color: var(--tier-3-blue);
  box-shadow: 0 12px 30px rgba(59, 130, 246, 0.15);
}
.card-tier-3 .icon, .card-tier-3 .card-icon {
  color: var(--tier-3-blue);
  background: rgba(59, 130, 246, 0.12);
  border-color: var(--tier-3-border);
}
.tag-tier-3 {
  color: var(--tier-3-blue);
  border-color: var(--tier-3-border);
  background: var(--tier-3-bg);
}

.card-tier-4 {
  border-color: var(--tier-4-border);
  background: linear-gradient(180deg, var(--tier-4-bg), var(--panel));
}
.card-tier-4::before {
  background: linear-gradient(90deg, var(--tier-4-purple), transparent 75%);
  opacity: 0.8;
}
.card-tier-4:hover {
  border-color: var(--tier-4-purple);
  box-shadow: 0 12px 30px rgba(139, 92, 246, 0.15);
}
.card-tier-4 .icon, .card-tier-4 .card-icon {
  color: var(--tier-4-purple);
  background: rgba(139, 92, 246, 0.12);
  border-color: var(--tier-4-border);
}
.tag-tier-4 {
  color: var(--tier-4-purple);
  border-color: var(--tier-4-border);
  background: var(--tier-4-bg);
}

.card-tier-5 {
  border-color: var(--tier-5-border);
  background: linear-gradient(180deg, var(--tier-5-bg), var(--panel));
}
.card-tier-5::before {
  background: linear-gradient(90deg, var(--tier-5-steel), transparent 75%);
  opacity: 0.8;
}
.card-tier-5:hover {
  border-color: var(--tier-5-steel);
  box-shadow: 0 12px 30px rgba(6, 182, 212, 0.15);
}
.card-tier-5 .icon, .card-tier-5 .card-icon {
  color: var(--tier-5-steel);
  background: rgba(6, 182, 212, 0.12);
  border-color: var(--tier-5-border);
}
.tag-tier-5 {
  color: var(--tier-5-steel);
  border-color: var(--tier-5-border);
  background: var(--tier-5-bg);
}

/* Ecosystem Stats Bar */
.stats-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 24px;
}

.stat-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.88rem;
  color: var(--ink-soft);
}

.stat-pill strong {
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 1.05rem;
}

.stat-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
}
.stat-pill .dot.gold { background: var(--tier-1-amber); box-shadow: 0 0 8px var(--tier-1-amber); }
.stat-pill .dot.green { background: var(--tier-2-emerald); box-shadow: 0 0 8px var(--tier-2-emerald); }
.stat-pill .dot.blue { background: var(--tier-3-blue); box-shadow: 0 0 8px var(--tier-3-blue); }

/* ---------- Interactive Tree Navigation Component ---------- */
.tree-container {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-soft);
  margin-bottom: 36px;
}

.tree-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.tree-header h3 {
  margin: 0;
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.tree-search-wrap {
  position: relative;
  flex: 1;
  max-width: 320px;
}

.tree-search {
  width: 100%;
  padding: 8px 12px 8px 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--ink);
  font-size: 0.9rem;
  font-family: var(--font);
}

.tree-search:focus {
  outline: none;
  border-color: var(--accent-strong);
  box-shadow: 0 0 0 3px rgba(245, 78, 0, 0.15);
}

.tree-search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  color: var(--muted);
  pointer-events: none;
}

.tree-view {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.92rem;
}

.tree-branch {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  overflow: hidden;
}

.tree-branch-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  user-select: none;
  font-weight: 600;
  color: var(--ink);
  transition: background 0.16s ease;
}

.tree-branch-header:hover {
  background: var(--panel-2);
}

.tree-toggle-icon {
  width: 16px;
  height: 16px;
  transition: transform 0.2s ease;
  color: var(--muted);
}

.tree-branch.open .tree-toggle-icon {
  transform: rotate(90deg);
}

.tree-branch-children {
  display: none;
  padding: 4px 10px 10px 28px;
  border-top: 1px solid var(--border-soft);
}

.tree-branch.open .tree-branch-children {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 8px;
  padding-top: 10px;
}

.tree-leaf {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--border-soft);
  color: var(--ink-soft);
  font-size: 0.88rem;
  transition: all 0.16s ease;
}

.tree-leaf:hover {
  border-color: var(--hover-border);
  color: var(--ink);
  text-decoration: none;
  transform: translateX(2px);
}

.tree-leaf-name {
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

.tree-leaf-desc {
  font-size: 0.78rem;
  color: var(--muted);
}

/* Tree Overlay Modal */
.tree-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  display: grid;
  place-items: center;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.tree-modal-backdrop.active {
  opacity: 1;
  visibility: visible;
}

.tree-modal {
  width: min(720px, 94vw);
  max-height: 85vh;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.tree-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-soft);
}

.tree-modal-header h3 {
  margin: 0;
  font-size: 1.15rem;
}

.tree-modal-close {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  display: grid;
  place-items: center;
  border-radius: 6px;
}

.tree-modal-close:hover {
  color: var(--ink);
  background: var(--panel-2);
}

.tree-modal-body {
  padding: 20px;
  overflow-y: auto;
}

/* Runtime Matrix Table */
.matrix-wrap {
  overflow-x: auto;
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
}

.matrix-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.9rem;
}

.matrix-table th, .matrix-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-soft);
}

.matrix-table th {
  background: var(--panel-2);
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.88rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.matrix-table tr:last-child td {
  border-bottom: none;
}

.matrix-table .check {
  color: var(--good);
  font-weight: bold;
}

.matrix-table .dash {
  color: var(--muted);
}

/* ---------- Custom Component Layouts (Non-Card Layouts) ---------- */

/* 1. Color Swatch Grid (palettes) */
.swatch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin: 20px 0;
}

.swatch-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel);
  overflow: hidden;
  box-shadow: var(--shadow-soft);
  transition: transform 0.16s ease, border-color 0.16s ease;
}

.swatch-card:hover {
  transform: translateY(-2px);
  border-color: var(--tier-2-emerald);
}

.swatch-preview {
  height: 80px;
  width: 100%;
  display: flex;
}

.swatch-bar {
  flex: 1;
  height: 100%;
}

.swatch-info {
  padding: 10px 12px;
  font-size: 0.85rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.swatch-name {
  font-weight: 600;
  color: var(--ink);
}

.swatch-code {
  font-family: var(--mono);
  color: var(--muted);
  font-size: 0.78rem;
}

/* 2. Feature Matrix & Specification Table (pygraphics, displayif, pydevices) */
.spec-block {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 24px;
  margin: 20px 0;
  box-shadow: var(--shadow-soft);
}

.spec-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 20px;
}

.spec-item {
  border-left: 3px solid var(--accent);
  padding-left: 14px;
}

.spec-item.tier-1 { border-left-color: var(--tier-1-amber); }
.spec-item.tier-2 { border-left-color: var(--tier-2-emerald); }
.spec-item.tier-3 { border-left-color: var(--tier-3-blue); }
.spec-item.tier-4 { border-left-color: var(--tier-4-purple); }
.spec-item.tier-5 { border-left-color: var(--tier-5-steel); }

.spec-item h4 {
  margin: 0 0 6px;
  font-size: 1.02rem;
  color: var(--ink);
}

.spec-item p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

/* 3. Workbench IDE Layout (mpftp) */
.workbench-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #14110d;
  box-shadow: var(--shadow);
  overflow: hidden;
  margin: 24px 0;
}

.workbench-bar {
  background: #1c1712;
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.workbench-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  display: inline-block;
}
.workbench-dot.red { background: #ef5c4e; }
.workbench-dot.yellow { background: #e8b34e; }
.workbench-dot.green { background: #3ecf95; }

.workbench-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border);
}

@media (max-width: 768px) {
  .workbench-body {
    grid-template-columns: 1fr;
  }
}

.workbench-pane {
  background: #14110d;
  padding: 16px;
}

.workbench-pane h4 {
  margin: 0 0 10px;
  font-size: 0.9rem;
  color: var(--tier-5-steel);
  font-family: var(--mono);
  text-transform: uppercase;
}

/* 4. Code Playground & Snippet Showcase */
.code-block-wrap {
  position: relative;
  margin: 16px 0;
}

.code-badge {
  position: absolute;
  top: 10px;
  right: 12px;
  font-size: 0.72rem;
  font-family: var(--mono);
  color: var(--muted);
  text-transform: uppercase;
}

/* ---------- Footer ---------- */

.site-footer {
  border-top: 1px solid var(--border-soft);
  margin-top: 40px;
  padding: 26px 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.site-footer .wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: space-between;
  align-items: center;
}

.site-footer a {
  color: var(--ink-soft);
}

@media (max-width: 640px) {
  .nav {
    gap: 14px;
    font-size: 0.88rem;
  }
}
