/*
 * article.css
 * Loaded only on single-post views (is_singular('post')) via conditional
 * enqueue in functions.php. Zero impact on homepage, archives, library,
 * or any other page type.
 *
 * F1: empty stub — exists so the conditional enqueue has a real file to
 * load and we can verify the wiring works on production without changing
 * any visual behaviour.
 *
 * Built out across:
 *   F4: 3-column grid, sticky rails, TOC styling, share rail
 *   F5: mobile/tablet responsive variants, <details>-collapsed TOC
 *   F6: drop cap, author bio block, related-articles strip
 */

/* =============================================================================
   F3 v3 — TOC Rail
   Desktop: Numbered Column rail (Pattern 6, echoes .aa-article-card)
   Mobile:  Sticky top bar with section counter, slides-down dropdown
            (Pattern 3 + counter, VitePress-inspired)
   See docs/f3-design-v3.md.
   ============================================================================= */


/* ─── Visibility utilities ──────────────────────────────────────────────────
   !important is deliberate — these utilities must beat any component's own
   display value (e.g. .aa-toc-bar's display: flex, the rail's flex layout).
   Same pattern Tailwind / Bootstrap use for their visibility helpers.
   ─────────────────────────────────────────────────────────────────────────── */
.aa-desktop-only { display: block !important; }
.aa-mobile-only  { display: none  !important; }
@media (max-width: 1023.98px) {
  .aa-desktop-only { display: none  !important; }
  .aa-mobile-only  { display: block !important; }
}


/* ─── Desktop rail (Pattern 6) ──────────────────────────────────────────────
   Single fixed scroll-container per the Starlight pattern. The whole rail
   scrolls inside the viewport; the inner card has no height constraint.
   ─────────────────────────────────────────────────────────────────────────── */
.aa-toc-rail-root {
  position: fixed;
  right: 0;
  top: 0;
  width: 300px;
  height: 100vh;
  padding: 120px 24px 32px;
  overflow-y: auto;
  z-index: 10;
  scrollbar-width: thin;
  scrollbar-color: var(--aa-gold-border) transparent;
}

.aa-toc-rail {
  /* No card border — the typography carries the structure. Echoes the
     borderless .aa-article-card pattern from the homepage. */
  background: transparent;
}

.aa-toc-rail__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  border-bottom: 1px solid var(--aa-gold);
  padding-bottom: 6px;
  margin-bottom: 8px;
}

.aa-toc-rail__eyebrow {
  font-family: var(--aa-fu);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--aa-gold);
}

.aa-toc-rail__count {
  font-family: var(--aa-fu);
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--aa-white-3);
}


/* ─── Shared list (used by both desktop rail and mobile dropdown) ──────────
   Pattern 6 numbered cards, hairline dividers, indented italic H3 children.
   Override entry-content link styles (dotted gold underline) explicitly.
   ─────────────────────────────────────────────────────────────────────────── */
.aa-toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: aa-toc;
}

.aa-toc-item {
  border-bottom: 1px solid var(--aa-border);
}

.aa-toc-item:last-child {
  border-bottom: 0;
}

/* Override the article-body dotted-underline link style across both rails. */
.aa-toc-list .aa-toc-link {
  border-bottom: 0 !important;
  text-decoration: none;
}

/* H2 row — big Gloock numeral on the left, title on the right */
.aa-toc-item--h2 .aa-toc-link {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 10px;
  align-items: baseline;
  padding: 8px 4px 8px 4px;
  color: var(--aa-white-2);
  transition: color 0.15s, background-color 0.15s;
}

.aa-toc-num {
  font-family: var(--aa-fd);            /* Gloock display */
  font-size: 22px;
  line-height: 1;
  color: var(--aa-gold);
  text-align: right;
  /* Gold dim by default; brightens on active. Subtle. */
  opacity: 0.55;
  transition: opacity 0.15s;
}

.aa-toc-item--h2 .aa-toc-text {
  font-family: var(--aa-fb);
  font-size: 13px;
  line-height: 1.35;
}

/* H3 row — indented italic, no numeral, dimmer */
.aa-toc-item--h3 .aa-toc-link {
  display: block;
  padding: 5px 4px 5px 42px;
  color: var(--aa-white-3);
  font-family: var(--aa-fb);
  font-style: italic;
  font-size: 11.5px;
  line-height: 1.4;
  transition: color 0.15s, background-color 0.15s;
}

/* Hover */
.aa-toc-link:hover {
  color: var(--aa-gold-2);
}
.aa-toc-link:hover .aa-toc-num {
  opacity: 1;
}

/* Active state — subtle gold-tint background, brighter title, full-strength
   numeral. No left-border bar — the numeral lighting up IS the indicator. */
.aa-toc-link[aria-current="true"] {
  background: var(--aa-gold-dim);
  color: var(--aa-gold);
}
.aa-toc-link[aria-current="true"] .aa-toc-text {
  font-weight: 600;
}
.aa-toc-link[aria-current="true"] .aa-toc-num {
  opacity: 1;
}


/* ─── Mobile sticky bar (Pattern 3 + counter) ──────────────────────────────
   The wrapper is fixed-positioned at the top of the viewport. Hidden by
   default; JS adds .is-visible once the user scrolls past the article
   header. Inside, the bar is the click target; the dropdown panel is its
   sibling.
   ─────────────────────────────────────────────────────────────────────────── */
.aa-toc-bar-root {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  background: var(--aa-black);
  border-bottom: 1px solid var(--aa-gold);
  /* Slide-in: translate up off-screen by default. JS toggles is-visible. */
  transform: translateY(-100%);
  transition: transform 0.22s ease-out;
}

.aa-toc-bar-root.is-visible {
  transform: translateY(0);
}

/* Reduce-motion users: just toggle visibility, no slide. */
@media (prefers-reduced-motion: reduce) {
  .aa-toc-bar-root {
    transition: none;
  }
}

.aa-toc-bar-root[hidden] {
  display: none !important;
}

/* The bar itself is a button — full width, two-line content layout. */
.aa-toc-bar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  width: 100%;
  padding: 9px 16px;
  background: transparent;
  border: 0;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

.aa-toc-bar__counter {
  font-family: var(--aa-fu);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--aa-gold);
  line-height: 1;
  min-width: 36px;
}

.aa-toc-bar__label {
  font-family: var(--aa-fb);
  font-size: 13px;
  font-weight: 500;
  color: var(--aa-white);
  line-height: 1.2;
  /* Truncate gracefully on narrow screens / long heading text */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.aa-toc-bar__chevron {
  font-size: 12px;
  color: var(--aa-gold);
  line-height: 1;
  transition: transform 0.18s;
}

.aa-toc-bar[aria-expanded="true"] .aa-toc-bar__chevron {
  transform: rotate(180deg);
}

/* Dropdown panel — fades & slides down from below the bar */
.aa-toc-bar__panel {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  max-height: calc(100vh - 100px);   /* leave breathing room above */
  overflow-y: auto;
  background: var(--aa-black);
  border-bottom: 1px solid var(--aa-gold);
  border-top: 1px solid var(--aa-border);
  /* Animate in from translateY(-8px) + opacity:0 */
  transform: translateY(-8px);
  opacity: 0;
  transition: transform 0.18s ease-out, opacity 0.18s ease-out;
  scrollbar-width: thin;
  scrollbar-color: var(--aa-gold-border) transparent;
}

.aa-toc-bar__panel[hidden] {
  display: none;
}

/* Once JS sets the panel visible, also add this class for the open animation. */
.aa-toc-bar-root.is-open .aa-toc-bar__panel {
  transform: translateY(0);
  opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
  .aa-toc-bar__panel { transition: none; }
}

/* Tighter list spacing inside the mobile dropdown */
.aa-toc-bar__panel .aa-toc-list {
  padding: 4px 16px 8px;
}


/* ─── Heading scroll-margin ─────────────────────────────────────────────────
   Mobile bar is ~44px tall; admin bar ~32px on top of that for logged-in
   users. Use the larger desktop value (100px) as the universal margin —
   it's slightly generous on mobile but harmless.
   ─────────────────────────────────────────────────────────────────────────── */
.entry-content :is(h2, h3)[id^="aa-h-"] {
  scroll-margin-top: 100px;
}


/* =============================================================================
   F6c — Related articles strip ("Read next")
   Desktop (≥1024px): 3-column grid — number, title, excerpt, category eyebrow.
   Mobile  (<1024px): vertical list  — number, title, excerpt (no eyebrow).
   Both blocks rendered into the DOM; .aa-desktop-only / .aa-mobile-only toggle
   which one is visible. Zero JS.
   See f6c-design.md.
   ============================================================================= */

/* ─── Strip wrapper ──────────────────────────────────────────────────────────
   Both .aa-related asides share this: top border separating strip from article,
   breathing room above, and the "Read next" eyebrow heading.
   ─────────────────────────────────────────────────────────────────────────── */
.aa-related {
  border-top: 1px solid var(--aa-border);
  margin-top: 56px;
  padding-top: 40px;
}

.aa-related__eyebrow {
  font-family: var(--aa-fu);
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--aa-white-3);
  margin: 0 0 24px;
}


/* ─── Desktop grid ───────────────────────────────────────────────────────────
   3-column equal-width grid. Each card stacks: numeral + eyebrow → title →
   excerpt. Category eyebrow floats right inside the card-head row.
   ─────────────────────────────────────────────────────────────────────────── */
.aa-related__grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 28px;
}

.aa-related__card {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.aa-related__card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.aa-related__num {
  font-family: var(--aa-fd);   /* Gloock */
  font-size: 32px;
  line-height: 1;
  color: var(--aa-gold);
  opacity: 0.6;
  flex-shrink: 0;
}

.aa-related__cat {
  font-family: var(--aa-fu);   /* Courier Prime */
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--aa-white-3);
  text-align: right;
}

.aa-related__title {
  font-family: var(--aa-fb);   /* Crimson Pro */
  font-size: 14px;
  font-weight: 500;
  line-height: 1.35;
  margin: 0;
}

/* Override article-body dotted-underline link style. */
.aa-related__title a {
  color: var(--aa-white-2);
  text-decoration: none;
  border-bottom: 0 !important;
  transition: color 0.15s;
}

.aa-related__title a:hover {
  color: var(--aa-gold-2);
}

.aa-related__excerpt {
  font-size: 12px;
  line-height: 1.5;
  color: var(--aa-white-3);
  margin: 0;
}


/* ─── Mobile list ────────────────────────────────────────────────────────────
   Vertical stack. Each row is a 2-column grid: numeral on the left, title +
   excerpt on the right. No category eyebrow (saves vertical space).
   ─────────────────────────────────────────────────────────────────────────── */
.aa-related__list {
  display: flex;
  flex-direction: column;
}

.aa-related__row {
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: 14px;
  align-items: start;
  padding: 16px 0;
  border-bottom: 1px solid var(--aa-border);
}

.aa-related__row:first-child {
  border-top: 1px solid var(--aa-border);
}

.aa-related__row .aa-related__num {
  font-size: 28px;
  padding-top: 2px;   /* optical alignment with title baseline */
}

.aa-related__row-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.aa-related__row .aa-related__title {
  font-size: 16px;
}


/* =============================================================================
   F9a — Library archive page
   ============================================================================= */

.aa-library {
  max-width: 1180px;
  margin: 0 auto;
  padding: 56px 32px 80px;
}

.aa-library__header {
  margin-bottom: 40px;
  padding-bottom: 24px;
  border-bottom: 1px solid rgba(200, 168, 75, 0.18);
}

.aa-library__eyebrow {
  font-family: var(--aa-fu);
  font-size: 11px;
  color: var(--aa-gold);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  margin: 0;
}

.aa-library__title {
  font-family: var(--aa-fd);
  font-size: 48px;
  font-weight: 400;
  color: var(--aa-white);
  line-height: 1.1;
  margin: 12px 0 16px 0;
}

.aa-library__intro {
  font-family: var(--aa-fb);
  font-size: 17px;
  color: var(--aa-white-3);
  max-width: 580px;
  line-height: 1.6;
  margin: 0;
}

.aa-library__count {
  color: #888;
  font-style: italic;
  margin-left: 4px;
}

/* The shelf — borderless grid where adjacent tiles share borders */
.aa-library__grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  border: 1px solid rgba(200, 168, 75, 0.18);
}

.aa-library__tile {
  border-right: 1px solid rgba(200, 168, 75, 0.18);
  border-bottom: 1px solid rgba(200, 168, 75, 0.18);
  background: transparent;
  transition: background-color 0.15s ease;
  margin: 0;
  padding: 0;
}

.aa-library__tile:hover {
  background: rgba(200, 168, 75, 0.04);
}

/* Drop right border on every 3rd tile (last column) */
.aa-library__tile:nth-child(3n) {
  border-right: none;
}

/* Drop bottom border on the last row.
   Pure CSS solution that handles row counts of 1, 2, or 3 mod 3. */
.aa-library__tile:nth-last-child(-n+3):nth-child(3n+1),
.aa-library__tile:nth-last-child(-n+3):nth-child(3n+1) ~ .aa-library__tile {
  border-bottom: none;
}

.aa-library__link {
  display: flex;
  text-decoration: none;
  color: inherit;
  height: 100%;
}

.aa-library__spine {
  width: 6px;
  flex-shrink: 0;
  align-self: stretch;
}

.aa-library__body {
  flex: 1;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
}

.aa-library__tile-title {
  font-family: var(--aa-fd);
  font-size: 16px;
  font-weight: 400;
  color: var(--aa-white);
  line-height: 1.3;
  margin: 0 0 6px 0;
}

.aa-library__tile:hover .aa-library__tile-title {
  color: var(--aa-gold);
}

.aa-library__author {
  font-family: var(--aa-fb);
  font-style: italic;
  font-size: 12px;
  color: var(--aa-white-3);
  margin: 0 0 10px 0;
}

.aa-library__footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding-top: 8px;
  margin-top: auto;
  border-top: 1px solid rgba(200, 168, 75, 0.1);
}

.aa-library__pills {
  display: inline-flex;
  gap: 4px;
}

.aa-library__pill {
  font-family: var(--aa-fu);
  font-size: 9px;
  padding: 1px 6px;
  background: #1a1a1a;
  border: 1px solid rgba(200, 168, 75, 0.3);
  color: var(--aa-white-3);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.aa-library__meta {
  font-family: var(--aa-fu);
  font-size: 10px;
  color: #888;
  margin-left: auto;
}

/* Empty state */
.aa-library-empty {
  max-width: 640px;
  margin: 0 auto;
  padding: 120px 32px;
  text-align: center;
}

.aa-library-empty__eyebrow {
  font-family: var(--aa-fu);
  font-size: 11px;
  color: var(--aa-gold);
  letter-spacing: 0.16em;
  margin: 0 0 12px 0;
}

.aa-library-empty__title {
  font-family: var(--aa-fd);
  font-size: 36px;
  font-weight: 400;
  color: var(--aa-white);
  margin: 0 0 16px 0;
}

.aa-library-empty__body {
  font-family: var(--aa-fb);
  font-size: 16px;
  color: var(--aa-white-3);
  margin: 0;
  line-height: 1.6;
}

/* Mobile — single column, drop the 3n border tricks */
@media (max-width: 1023px) {
  .aa-library {
    padding: 40px 16px 60px;
  }
  .aa-library__title {
    font-size: 34px;
  }
  .aa-library__grid {
    grid-template-columns: 1fr;
  }
  .aa-library__tile {
    border-right: none;
  }
  .aa-library__tile:nth-child(3n) {
    border-right: none;  /* redundant but explicit */
  }
  /* Reset the 3n+1 last-row rule; last tile drops bottom border on mobile */
  .aa-library__tile:nth-last-child(-n+3):nth-child(3n+1),
  .aa-library__tile:nth-last-child(-n+3):nth-child(3n+1) ~ .aa-library__tile {
    border-bottom: 1px solid rgba(200, 168, 75, 0.18);
  }
  .aa-library__tile:last-child {
    border-bottom: none;
  }
}
