/* ================================================================
   BigLedger — applet detail pages: tabbed-chapter layout
   Loaded on pages with front-matter `applet_tabs: true`, on top of
   applet-detail.css. JS (js/applet-tabs.js) splits the content into
   per-H2 chapters, builds the tab bar, and rebuilds the right-hand
   section menu for whichever chapter is active.
================================================================ */

/* ── Reading progress bar (very top of the viewport) ─────────── */
.apt-progress {
  position: fixed; top: 0; left: 0; height: 2px; width: 0;
  background: linear-gradient(90deg, #e5333f, #ff6b75);
  box-shadow: 0 0 10px rgba(229, 51, 63, 0.55);
  z-index: 1000;
  transition: width 0.08s linear;
}

/* ── Tab bar: equal-sized button grid, sticky while scrolling ── */
.apt-tabs {
  position: sticky; top: 76px; z-index: 20;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
  margin: 30px 0 40px;
  padding: 14px;
  background: rgba(19, 13, 15, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid #2e2226;
  border-radius: 16px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}
.apt-tab {
  appearance: none; cursor: pointer;
  display: block; width: 100%;
  height: 40px; line-height: 38px; text-align: center;
  overflow: hidden; text-overflow: ellipsis;
  font-family: inherit; font-size: 13px; font-weight: 600;
  letter-spacing: 0.01em; white-space: nowrap;
  color: #b3a6aa; background: #171114;
  border: 1px solid #2e2226; border-radius: 10px;
  padding: 0 10px;
  transition: color 0.15s ease, border-color 0.15s ease,
              background 0.15s ease, box-shadow 0.15s ease,
              transform 0.15s ease;
}
.apt-tab:hover {
  color: #f4eff0; border-color: #4a3a3f;
  transform: translateY(-2px);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.4);
}
.apt-tab.active {
  color: #fff;
  background: linear-gradient(135deg, #e5333f, #b3202c);
  border-color: transparent;
  box-shadow: 0 4px 16px rgba(229, 51, 63, 0.32);
}
.apt-tab.active:hover { transform: none; }

/* Chapters: one visible at a time */
.apt-chapter { display: none; }
.apt-chapter.active { display: block; animation: apt-fade 0.22s ease; }
@keyframes apt-fade {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
/* The chapter's own H2 opens the tab panel: no top margin/rule needed */
.apt-chapter > h2:first-child,
.apt-chapter > h1:first-child { margin-top: 0 !important; }

/* ── Reading polish inside chapters ──────────────────────────── */
/* Anchor jumps must clear the sticky header + sticky tab bar */
.apt-chapter h2, .apt-chapter h3, .apt-chapter h4 {
  scroll-margin-top: 250px;
}
/* H3 subsections: red accent bar gives structure while scrolling */
.apt-chapter h3 {
  position: relative;
  padding-left: 15px;
  margin: 40px 0 14px !important;
}
.apt-chapter h3::before {
  content: "";
  position: absolute; left: 0; top: 0.16em; bottom: 0.16em;
  width: 3px; border-radius: 2px;
  background: linear-gradient(180deg, #e5333f, rgba(229, 51, 63, 0.25));
}
/* H4 group labels: quiet small-caps eyebrows */
.apt-chapter h4 {
  font-size: 11.5px !important; font-weight: 700 !important;
  text-transform: uppercase; letter-spacing: 0.1em;
  color: #8d7d82 !important;
  margin: 26px 0 10px !important;
}
/* Slightly more breathing room between list blocks */
.apt-chapter ul, .apt-chapter ol { margin-bottom: 18px; }

/* ── Right-hand section menu (rebuilt per chapter by JS) ─────── */
.apd-toc.apt-toc { padding-top: 8px; }
.apt-toc-chapter {
  display: block;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.14em;
  color: #8d7d82;
  padding: 0 0 6px 16px;
}
.apt-toc-chapter::before { content: "// "; color: rgba(229, 51, 63, 0.65); }
.apt-toc-list {
  list-style: none; margin: 8px 0 0; padding: 0;
  border-left: 1px solid #241a1d;
}
.apt-toc-list li { margin: 0; }
.apt-toc-list a {
  display: flex; align-items: baseline; gap: 10px;
  margin-left: -1px;
  padding: 7px 12px 7px 15px;
  border-left: 2px solid transparent;
  font-size: 12.5px; line-height: 1.45;
  color: #b3a6aa; text-decoration: none;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.apt-toc-n {
  flex: none;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10.5px; font-weight: 600;
  color: rgba(229, 51, 63, 0.75);
}
.apt-toc-list a:hover { color: #f4eff0; }
.apt-toc-list a.active {
  color: #f4eff0; font-weight: 600;
  border-left-color: #e5333f;
  background: linear-gradient(90deg, rgba(229, 51, 63, 0.1), transparent 70%);
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 900px) {
  /* On small screens the grid wraps into many rows — too tall to pin */
  .apt-tabs { position: static; }
  .apt-chapter h2, .apt-chapter h3, .apt-chapter h4 { scroll-margin-top: 90px; }
}
@media (max-width: 640px) {
  .apt-tabs {
    gap: 6px; margin: 24px 0 32px; padding: 10px;
    grid-template-columns: repeat(auto-fill, minmax(105px, 1fr));
  }
  .apt-tab { font-size: 12px; height: 36px; line-height: 34px; }
}
