/* ============================================================
 * Realm Directory — Component Styles
 * Depends on: tokens.css (CSS custom properties only — no hard-coded values).
 * Layers:
 *   1. Reset & base
 *   2. Layout primitives (container, grid, stack)
 *   3. Components (card, chip, pill, hero, search, nav, breadcrumb)
 *   4. Page-specific blocks
 *   5. Utilities (sr-only, focus-visible)
 * ============================================================ */

/* ---------- 1. Reset & base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--core-font-family-rounded-sans);
  font-size: var(--realm-typography-body-size);
  font-weight: var(--realm-typography-body-weight);
  line-height: var(--realm-typography-body-lh);
  color: var(--realm-color-ink-strong);
  background: var(--realm-color-surface-base);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img,
svg {
  display: block;
  max-width: 100%;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

a {
  color: var(--realm-color-brand-primary-strong);
  text-decoration: none;
  transition: color var(--core-duration-fast) var(--core-easing-ease-out);
}

a:hover,
a:focus-visible {
  color: var(--realm-color-brand-secondary-strong);
}

/* ---------- 2. Layout primitives ---------- */
.container {
  width: 100%;
  max-width: var(--directory-grid-max-width);
  margin-inline: auto;
  padding-inline: var(--realm-spacing-lg);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--realm-spacing-md);
}

.cluster {
  display: flex;
  flex-wrap: wrap;
  gap: var(--realm-spacing-sm);
  align-items: center;
}

.grid-cards {
  display: grid;
  gap: var(--directory-grid-gutter);
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}

@media (min-width: 768px) {
  .grid-cards {
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  }
}

/* ---------- 3. Top nav ---------- */
.app-nav {
  position: sticky;
  top: 0;
  z-index: var(--directory-nav-z);
  background: var(--directory-nav-bg);
  border-bottom: 1px solid var(--directory-nav-border);
  backdrop-filter: blur(8px);
}

.app-nav__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--realm-spacing-md);
  height: var(--directory-nav-height);
}

.app-nav__brand {
  display: inline-flex;
  align-items: center;
  gap: var(--realm-spacing-sm);
  font-weight: var(--core-font-weight-bold);
  font-size: var(--core-font-size-20);
  color: var(--directory-nav-label);
}

.app-nav__brand-mark {
  width: 28px;
  height: 28px;
  border-radius: var(--realm-radius-md);
  background: linear-gradient(135deg, var(--realm-color-brand-primary), var(--realm-color-brand-secondary));
  display: grid;
  place-items: center;
  color: var(--core-color-white);
  font-size: var(--core-font-size-14);
  font-weight: var(--core-font-weight-extrabold);
}

.app-nav__links {
  display: flex;
  gap: var(--realm-spacing-md);
  align-items: center;
}

.app-nav__link {
  color: var(--directory-nav-label);
  font-weight: var(--core-font-weight-medium);
  padding: var(--realm-spacing-xs) var(--realm-spacing-sm);
  border-radius: var(--realm-radius-md);
  transition:
    color var(--core-duration-fast) var(--core-easing-ease-out),
    background var(--core-duration-fast) var(--core-easing-ease-out);
}

/* Direction D: subtle hover bg + color shift for nav affordance */
.app-nav__link:hover:not([aria-current="page"]) {
  color: var(--realm-color-brand-primary-strong);
  background: var(--realm-color-brand-primary-soft);
}

.app-nav__link[aria-current="page"] {
  color: var(--directory-nav-label-active);
  background: var(--realm-color-brand-primary-soft);
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--realm-spacing-xs);
  padding: var(--realm-spacing-xs) var(--realm-spacing-sm);
  border: 1px solid var(--realm-color-border-default);
  border-radius: var(--realm-radius-pill);
  color: var(--realm-color-ink-soft);
  font-size: var(--core-font-size-14);
  min-height: 36px;
  transition: border-color var(--core-duration-fast) var(--core-easing-ease-out),
              color var(--core-duration-fast) var(--core-easing-ease-out);
}

.theme-toggle:hover {
  border-color: var(--realm-color-brand-primary);
  color: var(--realm-color-ink-strong);
}

/* ---------- 3. Hero ---------- */
.hero {
  padding: var(--directory-hero-padding-y) var(--directory-hero-padding-x);
  border-radius: var(--directory-hero-radius);
  /* Direction D: single 4-stop mesh gradient replaces dual radial-gradients.
   * --directory-hero-mesh-opacity (0.6) applied via color-mix to soften the blend. */
  background:
    linear-gradient(
      135deg,
      color-mix(in srgb, var(--realm-color-brand-primary-soft) calc(var(--directory-hero-mesh-opacity) * 100%), transparent) 0%,
      var(--directory-hero-bg) 35%,
      var(--directory-hero-bg) 65%,
      color-mix(in srgb, var(--realm-color-brand-secondary-soft) calc(var(--directory-hero-mesh-opacity) * 100%), transparent) 100%
    );
  position: relative;
  overflow: hidden;
  margin-block: var(--realm-spacing-xl);
  /* M2: meshBreath — gradient mesh slowly drifts ±5% to give the hero surface a subtle pulse.
   * background-size 200% 200% gives position room to travel without visible seam. */
  background-size: 200% 200%;
  animation: meshBreath var(--directory-motion-mesh-duration, 12s) var(--realm-motion-easing-emphasis, ease-in-out) infinite alternate;
}

.hero__title {
  font-family: var(--realm-typography-display-font);
  font-size: var(--realm-typography-display-size);
  font-weight: var(--realm-typography-display-weight);
  line-height: var(--realm-typography-display-lh);
  letter-spacing: var(--realm-typography-display-ls);
  color: var(--directory-hero-title);
  margin: 0 0 var(--realm-spacing-md);
  text-transform: lowercase;
}

.hero__tagline {
  font-size: var(--core-font-size-20);
  color: var(--directory-hero-subtitle);
  margin: 0 0 var(--realm-spacing-lg);
  max-width: 60ch;
}

.hero__floats {
  position: absolute;
  inset: auto var(--realm-spacing-xl) var(--realm-spacing-xl) auto;
  display: flex;
  gap: var(--realm-spacing-sm);
  pointer-events: none;
  opacity: 0.95;
}

.hero__float {
  width: 64px;
  height: 64px;
  border-radius: var(--realm-radius-lg);
  box-shadow: var(--realm-shadow-card-rest);
  background: var(--realm-color-surface-card);
  transform: translateY(0);
  /* C1: hard-coded 4s replaced with token reference for Flow's keyframe binding */
  animation: floatY var(--directory-motion-float-duration) var(--core-easing-ease-in-out) infinite alternate;
}

/* Direction D: floats reduced to 1 card for visual restraint.
 * 2nd and 3rd float siblings should be removed from HTML by Artisan.
 * These nth-child rules are kept so no flash occurs if HTML still has 3. */
.hero__float:nth-child(2) { display: none; }
.hero__float:nth-child(3) { display: none; }

@keyframes floatY {
  from { transform: translateY(0); }
  to   { transform: translateY(-8px); }
}

/* ---------- Motion: foilShimmer (M1) ----------
 * C4 compliance: iteration-count = 1 (single sweep, stops after 1 pass).
 * WCAG 2.2.2: hover-only trigger. WCAG 2.3.1: no flash (opacity sweep only).
 * Sweeps background-position from offscreen-left to offscreen-right across
 * the card surface via the linear-gradient defined in --directory-card-foil-gradient. */
@keyframes foilShimmer {
  from { background-position: -100% 0; }
  to   { background-position: 200% 0; }
}

/* ---------- Motion: meshBreath (M2) ----------
 * Gently drifts the hero gradient mesh position ±5% over 12 s (infinite alternate).
 * Vibration amplitude kept small to avoid vestibular disturbance (WCAG 2.3.3 / EAA).
 * Uses transform-safe background-position — compositor-safe for background-attachment: scroll. */
@keyframes meshBreath {
  from { background-position: 45% 45%; }
  to   { background-position: 55% 55%; }
}

/* ---------- Motion: watermarkFade (M3) ----------
 * Fades the card watermark from rest opacity to hover opacity.
 * Opacity is the only animated property — compositor-safe, no layout cost. */
@keyframes watermarkFade {
  from { opacity: var(--directory-card-watermark-opacity-rest, 0.03); }
  to   { opacity: var(--directory-card-watermark-opacity-hover, 0.08); }
}

@media (max-width: 768px) {
  .hero__floats { display: none; }
}

/* ---------- 3. Search ---------- */
.search {
  display: flex;
  align-items: center;
  gap: var(--realm-spacing-sm);
  background: var(--directory-search-bg);
  border: 1px solid var(--directory-search-border);
  border-radius: var(--directory-search-radius);
  padding: var(--directory-search-padding-y) var(--directory-search-padding-x);
  min-height: var(--directory-search-min-height);
  transition: border-color var(--core-duration-fast) var(--core-easing-ease-out),
              box-shadow var(--core-duration-fast) var(--core-easing-ease-out);
}

.search:focus-within {
  border-color: var(--directory-search-border-focus);
  box-shadow: var(--directory-search-focus-ring);
}

.search__icon {
  color: var(--realm-color-ink-muted);
  flex: 0 0 auto;
  transition: color var(--core-duration-fast) var(--core-easing-ease-out);
}

/* Direction D: icon brightens to brand-primary when search is focused */
.search:focus-within .search__icon {
  color: var(--realm-color-brand-primary);
}

.search__input {
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--directory-search-text);
  font: inherit;
  min-width: 0;
}

.search__input::placeholder {
  color: var(--directory-search-placeholder);
}

.search__shortcut {
  font-family: var(--core-font-family-mono);
  font-size: var(--core-font-size-12);
  padding: 2px 6px;
  border: 1px solid var(--realm-color-border-default);
  border-radius: var(--realm-radius-sm);
  color: var(--realm-color-ink-muted);
}

/* ---------- 3. Filter chip ---------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--directory-chip-gap);
  padding: var(--directory-chip-padding-y) var(--directory-chip-padding-x);
  background: var(--directory-chip-bg);
  color: var(--directory-chip-label);
  border: 1px solid var(--directory-chip-border);
  border-radius: var(--directory-chip-radius);
  min-height: var(--directory-chip-min-height);
  font-size: var(--core-font-size-14);
  font-weight: var(--core-font-weight-medium);
  cursor: pointer;
  transition: background var(--core-duration-fast) var(--core-easing-ease-out),
              border-color var(--core-duration-fast) var(--core-easing-ease-out),
              color var(--core-duration-fast) var(--core-easing-ease-out);
}

.chip:hover {
  background: var(--directory-chip-bg-hover);
  border-color: var(--realm-color-brand-primary);
}

/* Direction D: focus-visible ring for keyboard navigation (WCAG 2.2 SC 2.4.11/2.4.13) */
.chip:focus-visible {
  outline: 3px solid var(--realm-color-border-focus);
  outline-offset: 2px;
  box-shadow: var(--realm-shadow-focus-ring);
}

.chip[aria-pressed="true"],
.chip.is-active {
  background: var(--directory-chip-bg-selected);
  color: var(--directory-chip-label-selected);
  border-color: var(--directory-chip-border-selected);
}

.chip--remove::after {
  content: "×";
  font-size: var(--core-font-size-16);
  margin-inline-start: var(--realm-spacing-xs);
  opacity: 0.8;
}

.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: var(--realm-spacing-xs);
}

.chip-group__legend {
  font-size: var(--core-font-size-12);
  font-weight: var(--core-font-weight-semibold);
  letter-spacing: var(--core-letter-spacing-wide);
  text-transform: uppercase;
  color: var(--realm-color-ink-soft);
  margin: 0 0 var(--realm-spacing-xs);
}

/* ---------- 3. Rank pill ---------- */
.rank-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--realm-spacing-xs);
  padding: var(--directory-rank-badge-padding-y) var(--directory-rank-badge-padding-x);
  border-radius: var(--directory-rank-badge-radius);
  font-family: var(--directory-rank-badge-font-family);
  font-size: var(--directory-rank-badge-font-size);
  font-weight: var(--directory-rank-badge-font-weight);
  letter-spacing: var(--directory-rank-badge-letter-spacing);
  text-transform: uppercase;
  background: var(--rank-fill, var(--core-color-rank-recruit));
  color: var(--rank-on, var(--core-color-ink-50));
}

/* Direction D: high-rank gem — static inset glow for motion-off rank identification (C4 redundant cue).
 * Triggered via .rank--veteran / .rank--elite / .rank--champion / .rank--legend class on .rank-pill,
 * or data-rank-tier="veteran|elite|champion|legend" attribute. Both patterns supported. */
.rank-pill.rank--veteran,
.rank-pill[data-rank-tier="veteran"] {
  box-shadow: inset 0 0 0 1.5px rgba(109, 40, 217, 0.55), 0 0 6px 1px rgba(109, 40, 217, 0.20);
}

.rank-pill.rank--elite,
.rank-pill[data-rank-tier="elite"] {
  box-shadow: inset 0 0 0 1.5px rgba(212, 160, 23, 0.65), 0 0 6px 1px rgba(212, 160, 23, 0.28);
}

.rank-pill.rank--champion,
.rank-pill[data-rank-tier="champion"] {
  box-shadow: inset 0 0 0 1.5px rgba(234, 115, 23, 0.65), 0 0 6px 1px rgba(234, 115, 23, 0.28);
}

.rank-pill.rank--legend,
.rank-pill[data-rank-tier="legend"] {
  box-shadow: inset 0 0 0 2px rgba(185, 28, 28, 0.70), 0 0 8px 2px rgba(185, 28, 28, 0.30);
}

/* ---------- 3. Affinity icons ---------- */
.affinity-strip {
  display: inline-flex;
  align-items: center;
  gap: var(--directory-affinity-icon-gap);
}

.affinity {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: var(--directory-affinity-icon-radius);
  background: var(--directory-affinity-icon-bg);
  color: var(--affinity-color, var(--realm-color-ink-strong));
  position: relative;
}

.affinity svg {
  width: var(--directory-affinity-icon-size);
  height: var(--directory-affinity-icon-size);
}

/* Direction D: affinity level expressed via stroke weight + opacity combination.
 * Avoids color-only differentiation (WCAG 1.4.1). Aligns with detail page
 * .detail-affinity-matrix__dots which uses filled/unfilled dots for the same levels. */
.affinity[data-level="H"] { box-shadow: inset 0 0 0 2px var(--affinity-color); opacity: 1; }
.affinity[data-level="M"] { box-shadow: inset 0 0 0 1.5px var(--affinity-color); opacity: 0.85; }
.affinity[data-level="L"] { box-shadow: inset 0 0 0 1px var(--affinity-color); opacity: 0.55; }

/* ---------- 3. Agent card ---------- */
.agent-card {
  display: flex;
  flex-direction: column;
  gap: var(--directory-agent-card-gap);
  padding: var(--directory-agent-card-padding);
  background: var(--directory-agent-card-bg);
  border: 1px solid var(--directory-agent-card-border);
  border-radius: var(--directory-agent-card-radius);
  /* Direction D: rest shadow uses elevation-1 (subtler than card-rest) for chrome restraint */
  box-shadow: var(--realm-elevation-1);
  color: var(--directory-agent-card-title);
  transition:
    background var(--directory-agent-card-transition-duration) var(--directory-agent-card-transition-easing),
    border-color var(--directory-agent-card-transition-duration) var(--directory-agent-card-transition-easing),
    box-shadow var(--directory-agent-card-transition-duration) var(--directory-agent-card-transition-easing),
    transform var(--directory-agent-card-transition-duration) var(--directory-agent-card-transition-easing);
  text-decoration: none;
  position: relative;
  isolation: isolate;
}

.agent-card:hover,
.agent-card:focus-visible {
  background: var(--directory-agent-card-bg-hover);
  border-color: var(--directory-agent-card-border-hover);
  box-shadow: var(--directory-agent-card-shadow-hover);
  /* Direction D: 4px lift (up from 2px) for clearer hover affordance */
  transform: translateY(-4px);
}

/* ---------- M1: Foil overlay — ::before (z-index layer 1) ----------
 * Applies to veteran / elite / champion / legend rank tiers only.
 * Base state: invisible, positioned ready for the shimmer sweep.
 * C4: animation-iteration-count 1 — single pass and stops (WCAG 2.2.2 / 2.3.3).
 * HTML requirement: add data-rank-tier="veteran|elite|champion|legend" to .agent-card (Artisan).
 * z-index stack within .agent-card (isolation:isolate context):
 *   ::after (watermark) = z-index 0
 *   ::before (foil)     = z-index 1
 *   content (text/img)  = z-index 2  ← see .agent-card > * rule below */
.agent-card[data-rank-tier="veteran"]::before,
.agent-card[data-rank-tier="elite"]::before,
.agent-card[data-rank-tier="champion"]::before,
.agent-card[data-rank-tier="legend"]::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--directory-card-foil-gradient, linear-gradient(120deg, transparent 30%, rgba(255,255,255,0.35) 50%, transparent 70%));
  background-size: 200% 100%;
  background-position: -100% 0;
  border-radius: inherit;
  pointer-events: none;
  opacity: 0;
  transition: opacity 200ms var(--core-easing-ease-out, ease-out);
  z-index: 1;
}

.agent-card[data-rank-tier="veteran"]:hover::before,
.agent-card[data-rank-tier="veteran"]:focus-visible::before,
.agent-card[data-rank-tier="elite"]:hover::before,
.agent-card[data-rank-tier="elite"]:focus-visible::before,
.agent-card[data-rank-tier="champion"]:hover::before,
.agent-card[data-rank-tier="champion"]:focus-visible::before,
.agent-card[data-rank-tier="legend"]:hover::before,
.agent-card[data-rank-tier="legend"]:focus-visible::before {
  opacity: 1;
  /* C4: iteration-count 1 — single sweep, halts. No infinite loop. */
  animation: foilShimmer var(--directory-motion-foil-duration, 800ms) var(--core-easing-ease-in-out, ease-in-out) 1;
}

/* ---------- M3: Watermark overlay — ::after (z-index layer 0) ----------
 * Renders the class symbol glyph at bottom-right of the card.
 * HTML requirement: Artisan injects the watermark image URL via
 * style="--directory-card-watermark-image: url('...')" on each .agent-card.
 * Opacity transitions from rest (0.03) to hover (0.08) via CSS transition.
 * watermarkFade keyframe is defined above for reference / JS-driven entry. */
.agent-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: var(--directory-card-watermark-image, none);
  background-position: bottom right;
  background-repeat: no-repeat;
  background-size: 60px 60px;
  opacity: var(--directory-card-watermark-opacity-rest, 0.03);
  transition: opacity var(--directory-motion-watermark-fade-duration, 240ms) var(--core-easing-ease-out, ease-out);
  pointer-events: none;
  border-radius: inherit;
  z-index: 0;
}

.agent-card:hover::after,
.agent-card:focus-visible::after {
  opacity: var(--directory-card-watermark-opacity-hover, 0.08);
}

/* ---------- z-index layer 2: card content above foil + watermark ----------
 * All direct children of .agent-card stack above pseudo-element overlays.
 * position: relative is required to participate in the stacking order. */
.agent-card > * {
  position: relative;
  z-index: 2;
}

.agent-card__portrait {
  aspect-ratio: 1 / 1;
  border-radius: var(--realm-radius-md);
  overflow: hidden;
  background: var(--realm-color-surface-subtle);
}

.agent-card__portrait svg,
.agent-card__portrait img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.agent-card__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--realm-spacing-xs);
  font-size: var(--core-font-size-12);
  color: var(--directory-agent-card-subtitle);
  letter-spacing: var(--core-letter-spacing-wide);
  text-transform: uppercase;
}

.agent-card__class {
  font-weight: var(--core-font-weight-semibold);
  color: var(--realm-color-brand-primary-strong);
}

.agent-card__archetype {
  font-size: var(--core-font-size-14);
  color: var(--directory-agent-card-subtitle);
  text-transform: none;
  letter-spacing: 0;
}

.agent-card__tagline {
  font-size: var(--core-font-size-14);
  color: var(--directory-agent-card-subtitle);
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.agent-card__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: auto;
}

/* ---------- 3. Breadcrumb ---------- */
.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--realm-spacing-xs);
  margin: var(--realm-spacing-md) 0;
  font-size: var(--core-font-size-14);
  color: var(--realm-color-ink-soft);
}

.breadcrumb__sep {
  opacity: 0.6;
}

.breadcrumb a {
  color: var(--realm-color-ink-soft);
  font-weight: var(--core-font-weight-medium);
}

.breadcrumb a:hover {
  color: var(--realm-color-brand-primary-strong);
}

.breadcrumb__current {
  color: var(--realm-color-ink-strong);
  font-weight: var(--core-font-weight-semibold);
}

/* ---------- 3. Section heading ---------- */
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--realm-spacing-md);
  margin: var(--realm-spacing-xl) 0 var(--realm-spacing-md);
}

.section-head__title {
  font-size: var(--realm-typography-h2-size);
  font-weight: var(--realm-typography-h2-weight);
  line-height: var(--realm-typography-h2-lh);
  margin: 0;
}

.section-head__count {
  font-size: var(--core-font-size-14);
  color: var(--realm-color-ink-soft);
  font-variant-numeric: tabular-nums;
}

/* ---------- 4. index.html layout ---------- */
.layout-with-rail {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--realm-spacing-xl);
}

@media (min-width: 1024px) {
  .layout-with-rail {
    grid-template-columns: 260px 1fr;
  }
  .filter-rail {
    position: sticky;
    top: calc(var(--directory-nav-height) + var(--realm-spacing-md));
    align-self: start;
    max-height: calc(100vh - var(--directory-nav-height) - var(--realm-spacing-xl));
    overflow-y: auto;
  }
}

.filter-rail {
  display: flex;
  flex-direction: column;
  gap: var(--realm-spacing-lg);
  padding: var(--realm-spacing-md);
  background: var(--realm-color-surface-card);
  border: 1px solid var(--realm-color-border-subtle);
  border-radius: var(--realm-radius-lg);
}

.filter-rail__section {
  display: flex;
  flex-direction: column;
  gap: var(--realm-spacing-xs);
}

/* ---------- 4. Category hero (category.html) ---------- */
.category-hero {
  padding: var(--realm-spacing-2xl) var(--realm-spacing-xl);
  border-radius: var(--directory-hero-radius);
  background: linear-gradient(135deg,
    var(--realm-color-brand-primary-soft) 0%,
    var(--realm-color-brand-secondary-soft) 100%);
  color: var(--realm-color-ink-strong);
  margin-block: var(--realm-spacing-lg);
}

.category-hero__label {
  font-size: var(--core-font-size-12);
  font-weight: var(--core-font-weight-semibold);
  letter-spacing: var(--core-letter-spacing-wide);
  text-transform: uppercase;
  color: var(--realm-color-brand-primary-strong);
  margin: 0;
}

.category-hero__title {
  font-family: var(--realm-typography-display-font);
  font-size: var(--realm-typography-h1-size);
  font-weight: var(--realm-typography-h1-weight);
  line-height: var(--realm-typography-h1-lh);
  margin: var(--realm-spacing-xs) 0 var(--realm-spacing-sm);
}

.category-hero__flavor {
  margin: 0;
  color: var(--realm-color-ink-soft);
  max-width: 60ch;
}

.category-hero__stats {
  display: flex;
  gap: var(--realm-spacing-lg);
  margin-top: var(--realm-spacing-md);
}

.category-hero__stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.category-hero__stat-num {
  font-size: var(--core-font-size-25);
  font-weight: var(--core-font-weight-bold);
}

.category-hero__stat-label {
  font-size: var(--core-font-size-12);
  color: var(--realm-color-ink-soft);
  text-transform: uppercase;
  letter-spacing: var(--core-letter-spacing-wide);
}

/* ---------- 4. Sub-nav tabs ---------- */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--realm-spacing-xs);
  border-bottom: 1px solid var(--realm-color-border-subtle);
  margin-block: var(--realm-spacing-lg);
}

.tabs__item {
  padding: var(--realm-spacing-sm) var(--realm-spacing-md);
  border-radius: var(--realm-radius-md) var(--realm-radius-md) 0 0;
  color: var(--realm-color-ink-soft);
  font-weight: var(--core-font-weight-medium);
  /* Direction D: underline thickness now token-bound via --directory-tab-active-underline-thickness (2px) */
  border-bottom: var(--directory-tab-active-underline-thickness) solid transparent;
  margin-bottom: -1px;
  transition:
    color var(--core-duration-fast) var(--core-easing-ease-out),
    border-bottom-color var(--core-duration-fast) var(--core-easing-ease-out),
    background var(--core-duration-fast) var(--core-easing-ease-out);
}

.tabs__item:hover:not([aria-selected="true"]) {
  color: var(--realm-color-ink-strong);
  background: var(--realm-color-surface-subtle);
}

.tabs__item[aria-selected="true"] {
  color: var(--realm-color-brand-primary-strong);
  border-bottom-color: var(--realm-color-brand-primary-strong);
}

.tab-panel[hidden] { display: none; }

/* ---------- 4. detail.html ---------- */
.detail-hero {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--realm-spacing-xl);
  margin-block: var(--realm-spacing-lg);
  /* Direction D: stacking context for .detail-hero__watermark pseudo-layer */
  position: relative;
  overflow: hidden;
  isolation: isolate;
}

@media (min-width: 768px) {
  .detail-hero {
    grid-template-columns: minmax(220px, 320px) 1fr;
  }
}

/* Direction D: class watermark — decorative backdrop glyph.
 * HTML element (<span class="detail-hero__watermark" aria-hidden="true">) added by Artisan.
 * Position is absolute; stacks behind content via z-index: -1 within .detail-hero context. */
.detail-hero__watermark {
  position: absolute;
  inset-block-start: 50%;
  inset-inline-end: var(--realm-spacing-xl);
  transform: translateY(-50%);
  z-index: -1;
  width: var(--directory-detail-hero-watermark-size);
  height: var(--directory-detail-hero-watermark-size);
  opacity: var(--directory-detail-hero-watermark-opacity);
  color: var(--realm-color-brand-primary-soft);
  pointer-events: none;
  user-select: none;
  font-family: var(--realm-typography-display-font);
  font-size: var(--directory-detail-hero-watermark-size);
  font-weight: var(--core-font-weight-extrabold);
  line-height: 1;
  overflow: hidden;
}

.detail-hero__portrait {
  aspect-ratio: 1 / 1;
  border-radius: var(--realm-radius-lg);
  overflow: hidden;
  background: var(--realm-color-surface-card);
  border: 1px solid var(--realm-color-border-subtle);
  box-shadow: var(--realm-shadow-card-rest);
}

.detail-hero__portrait svg,
.detail-hero__portrait img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.detail-hero__name {
  font-family: var(--realm-typography-display-font);
  font-size: var(--realm-typography-display-size);
  font-weight: var(--realm-typography-display-weight);
  line-height: var(--realm-typography-display-lh);
  margin: 0;
  text-transform: lowercase;
}

.detail-hero__archetype {
  font-size: var(--core-font-size-14);
  color: var(--realm-color-ink-soft);
  text-transform: uppercase;
  letter-spacing: var(--core-letter-spacing-wide);
  margin: var(--realm-spacing-xs) 0;
}

.detail-hero__tagline {
  font-size: var(--core-font-size-20);
  color: var(--realm-color-ink-soft);
  margin: var(--realm-spacing-sm) 0 var(--realm-spacing-md);
  max-width: 50ch;
}

.detail-hero__cta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--realm-spacing-sm);
  margin-top: var(--realm-spacing-md);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--realm-spacing-xs);
  padding: var(--realm-spacing-sm) var(--realm-spacing-md);
  border-radius: var(--realm-radius-md);
  font-weight: var(--core-font-weight-semibold);
  font-size: var(--core-font-size-14);
  border: 1px solid transparent;
  min-height: 40px;
  transition:
    background var(--core-duration-fast) var(--core-easing-ease-out),
    border-color var(--core-duration-fast) var(--core-easing-ease-out);
}

.btn--primary {
  background: var(--realm-color-brand-primary-strong);
  color: var(--realm-color-ink-inverse);
}

.btn--primary:hover { background: var(--realm-color-brand-primary); }

.btn--ghost {
  background: transparent;
  border-color: var(--realm-color-border-default);
  color: var(--realm-color-ink-strong);
}

.btn--ghost:hover {
  border-color: var(--realm-color-brand-primary);
  color: var(--realm-color-brand-primary-strong);
}

/* ---------- 4. Capability list ---------- */
.cap-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: var(--realm-spacing-sm);
}

.cap-list li {
  padding: var(--realm-spacing-md);
  background: var(--realm-color-surface-card);
  border: 1px solid var(--realm-color-border-subtle);
  border-radius: var(--realm-radius-md);
}

.cap-list__key {
  font-family: var(--core-font-family-mono);
  font-size: var(--core-font-size-12);
  color: var(--realm-color-brand-primary-strong);
  margin-bottom: 4px;
  letter-spacing: var(--core-letter-spacing-wide);
  text-transform: uppercase;
}

/* ---------- 4. Collaboration micro-graph ---------- */
.collab-graph {
  background: var(--realm-color-surface-card);
  border: 1px solid var(--realm-color-border-subtle);
  border-radius: var(--realm-radius-lg);
  padding: var(--realm-spacing-md);
  display: flex;
  flex-direction: column;
  gap: var(--realm-spacing-md);
}

.collab-graph__svg {
  width: 100%;
  height: auto;
  max-height: 380px;
}

.collab-graph__node-text {
  font-family: var(--core-font-family-rounded-sans);
  font-size: 12px;
  fill: var(--realm-color-ink-strong);
}

.collab-graph__node-circle {
  fill: var(--realm-color-surface-subtle);
  stroke: var(--realm-color-brand-primary);
  stroke-width: 2;
}

.collab-graph__node-circle--center {
  fill: var(--realm-color-brand-primary-soft);
  stroke: var(--realm-color-brand-primary-strong);
  stroke-width: 2.5;
}

.collab-graph__node-link {
  cursor: pointer;
  text-decoration: none;
}

.collab-graph__node-link:hover .collab-graph__node-circle {
  stroke: var(--realm-color-brand-primary-strong);
  stroke-width: 3;
}

.collab-graph__node-link:hover .collab-graph__node-text {
  fill: var(--realm-color-brand-primary-strong);
}

.collab-graph__node-link:focus-visible .collab-graph__node-circle {
  stroke: var(--realm-color-brand-primary-strong);
  stroke-width: 3;
  outline: 2px solid var(--realm-color-brand-primary);
  outline-offset: 2px;
}

.collab-graph__edge {
  stroke: var(--realm-color-border-default);
  stroke-width: 1.5;
  fill: none;
}

/* ---------- 3.5. Agent network map ---------- */
.map-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--realm-spacing-md);
  padding-block: var(--realm-spacing-sm);
  margin-bottom: var(--realm-spacing-sm);
  border-bottom: 1px solid var(--realm-color-border-subtle);
  flex-wrap: wrap;
}

.map-controls__count {
  font-size: var(--core-font-size-14);
  color: var(--realm-color-ink-soft);
  font-weight: var(--core-font-weight-semibold);
}

.map-controls__toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--realm-spacing-xs);
  font-size: var(--core-font-size-14);
  cursor: pointer;
  color: var(--realm-color-ink-strong);
}

.map-controls__toggle input {
  cursor: pointer;
}

.map-graph-wrapper {
  background: var(--realm-color-surface-card);
  border: 1px solid var(--realm-color-border-subtle);
  border-radius: var(--realm-radius-lg);
  padding: var(--realm-spacing-md);
  overflow: auto;
  max-height: 75vh;
}

.map-graph__svg {
  display: block;
  min-width: 600px;
  height: auto;
}

.map-graph__class-label {
  font-family: var(--core-font-family-rounded-sans);
  font-size: 11px;
  font-weight: 700;
  fill: var(--realm-color-ink-strong);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.map-graph__class-count {
  font-family: var(--core-font-family-rounded-sans);
  font-size: 10px;
  font-weight: 600;
  fill: var(--realm-color-ink-soft);
}

.map-graph__node {
  fill: var(--realm-color-surface-subtle);
  stroke: var(--realm-color-brand-primary);
  stroke-width: 2;
  transition: stroke-width 0.15s ease, opacity 0.15s ease;
}

.map-graph__node--active {
  stroke: var(--realm-color-brand-primary-strong);
  stroke-width: 4;
}

.map-graph__node--partner {
  stroke: var(--realm-color-brand-primary-strong);
  stroke-width: 3;
}

.map-graph__node--dim {
  opacity: 0.35;
}

.map-graph__node-link {
  cursor: pointer;
  text-decoration: none;
}

.map-graph__node-link:hover .map-graph__node,
.map-graph__node-link:focus-visible .map-graph__node {
  stroke-width: 3.5;
  stroke: var(--realm-color-brand-primary-strong);
}

.map-graph__node-link:focus-visible {
  outline: 2px solid var(--realm-color-brand-primary);
  outline-offset: 2px;
  border-radius: 50%;
}

.map-graph__node-text {
  font-family: var(--core-font-family-rounded-sans);
  font-size: 11px;
  font-weight: var(--core-font-weight-semibold);
  fill: var(--realm-color-ink-strong);
  pointer-events: none;
}

.map-graph__node-text--dim {
  opacity: 0.5;
}

.map-graph__edge {
  stroke: var(--realm-color-border-default);
  stroke-width: 1;
  fill: none;
  opacity: 0.55;
}

.map-graph__edge--in {
  stroke: var(--realm-color-feedback-info, #5b8cff);
}

.map-graph__edge--out {
  stroke: var(--realm-color-feedback-success, #50b97c);
}

.map-info {
  margin-top: var(--realm-spacing-lg);
  background: var(--realm-color-surface-card);
  border: 1px solid var(--realm-color-border-subtle);
  border-radius: var(--realm-radius-lg);
  padding: var(--realm-spacing-md);
}

.map-info__title {
  font-size: var(--core-font-size-24, 24px);
  margin: 0 0 var(--realm-spacing-xs) 0;
}

.map-info__sub {
  color: var(--realm-color-ink-soft);
  margin: 0 0 var(--realm-spacing-sm) 0;
  font-size: var(--core-font-size-14);
}

.map-info__desc {
  margin: 0 0 var(--realm-spacing-sm) 0;
}

.map-info__links {
  display: flex;
  gap: var(--realm-spacing-sm);
  flex-wrap: wrap;
}

/* ---------- 4. Footer legend ---------- */
.legend {
  display: grid;
  gap: var(--realm-spacing-lg);
  padding: var(--realm-spacing-lg);
  margin-block: var(--realm-spacing-2xl);
  background: var(--realm-color-surface-card);
  border: 1px solid var(--realm-color-border-subtle);
  border-radius: var(--realm-radius-lg);
}

@media (min-width: 768px) {
  .legend {
    grid-template-columns: repeat(3, 1fr);
  }
}

.legend__title {
  font-size: var(--core-font-size-12);
  font-weight: var(--core-font-weight-semibold);
  letter-spacing: var(--core-letter-spacing-wide);
  text-transform: uppercase;
  color: var(--realm-color-ink-soft);
  margin: 0 0 var(--realm-spacing-sm);
}

.legend__row {
  display: flex;
  align-items: center;
  gap: var(--realm-spacing-sm);
  font-size: var(--core-font-size-14);
  margin-bottom: var(--realm-spacing-xs);
}

.legend__swatch {
  width: 16px;
  height: 16px;
  border-radius: var(--realm-radius-sm);
  flex: 0 0 auto;
}

/* ---------- 4. Empty state ---------- */
.empty-state {
  padding: var(--realm-spacing-2xl);
  text-align: center;
  border: 1px dashed var(--realm-color-border-default);
  border-radius: var(--realm-radius-lg);
  color: var(--realm-color-ink-soft);
  background: var(--realm-color-surface-card);
}

.empty-state__icon {
  font-size: 48px;
  margin-bottom: var(--realm-spacing-md);
}

.empty-state__hint {
  margin-top: var(--realm-spacing-sm);
  font-size: var(--core-font-size-14);
}

/* ---------- 5. Utilities ---------- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 3px solid var(--realm-color-border-focus);
  outline-offset: 2px;
  border-radius: var(--realm-radius-sm);
}

.is-hidden { display: none !important; }

/* Pending portrait badge */
.portrait-pending-badge {
  fill: var(--realm-color-feedback-info);
}

/* Card grid keyboard active */
.agent-card[data-keynav="true"] {
  outline: 3px solid var(--realm-color-border-focus);
  outline-offset: 2px;
}

/* ---------- 4. detail.html — enriched tab panels ---------- */

/* Tagline blockquote */
.detail-quote {
  margin: 0 0 var(--realm-spacing-md);
  padding-inline-start: var(--realm-spacing-md);
  border-inline-start: 3px solid var(--realm-color-brand-primary-strong);
  font-style: italic;
  font-size: var(--core-font-size-18, 18px);
  color: var(--realm-color-ink-soft);
  quotes: none;
}

/* Class flavor card */
.detail-flavor {
  background: var(--realm-color-surface-card);
  border: 1px solid var(--realm-color-border-subtle);
  border-radius: var(--realm-radius-md);
  padding: var(--realm-spacing-md);
  margin-block: var(--realm-spacing-md);
}

.detail-flavor__label {
  font-family: var(--core-font-family-mono);
  font-size: var(--core-font-size-12);
  color: var(--realm-color-brand-primary-strong);
  text-transform: uppercase;
  letter-spacing: var(--core-letter-spacing-wide);
  margin: 0 0 var(--realm-spacing-xs);
}

.detail-flavor__archetype {
  font-size: var(--core-font-size-18, 18px);
  font-weight: var(--core-font-weight-semibold);
  margin: 0 0 var(--realm-spacing-xs);
  color: var(--realm-color-ink-strong);
}

.detail-flavor__passive {
  font-size: var(--core-font-size-14);
  color: var(--realm-color-ink-soft);
  margin: 0 0 var(--realm-spacing-xs);
}

.detail-flavor__meta {
  font-size: var(--core-font-size-12);
  color: var(--realm-color-ink-subtle, var(--realm-color-ink-soft));
  margin: 0;
  text-transform: uppercase;
  letter-spacing: var(--core-letter-spacing-wide);
}

/* Affinity matrix grid */
.detail-affinity-matrix {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: var(--realm-spacing-sm);
  margin-block: var(--realm-spacing-sm);
}

.detail-affinity-matrix__cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: var(--realm-spacing-sm);
  background: var(--realm-color-surface-card);
  border: 1px solid var(--realm-color-border-subtle);
  border-radius: var(--realm-radius-md);
  text-align: center;
}

.detail-affinity-matrix__cell--none {
  opacity: 0.4;
}

.detail-affinity-matrix__icon svg {
  width: 20px;
  height: 20px;
  color: var(--realm-color-brand-primary-strong);
}

.detail-affinity-matrix__label {
  font-size: var(--core-font-size-12);
  font-weight: var(--core-font-weight-semibold);
  color: var(--realm-color-ink-strong);
}

.detail-affinity-matrix__dots {
  font-size: var(--core-font-size-12);
  color: var(--realm-color-border-default);
  letter-spacing: 2px;
}

.detail-affinity-matrix__dot--filled {
  color: var(--realm-color-brand-primary-strong);
}

.detail-affinity-matrix__level {
  font-family: var(--core-font-family-mono);
  font-size: var(--core-font-size-12);
  font-weight: var(--core-font-weight-semibold);
  color: var(--realm-color-ink-soft);
}

/* Quick stats footer */
.detail-stats {
  font-size: var(--core-font-size-14);
  color: var(--realm-color-ink-soft);
  margin: var(--realm-spacing-md) 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--realm-spacing-xs);
}

/* Recipes chips wrapper */
.recipes-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--realm-spacing-xs);
}

/* Partner list (collab / examples) */
.partner-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: var(--realm-spacing-xs);
}

.partner-list__item {
  display: flex;
  align-items: baseline;
  gap: var(--realm-spacing-sm);
  padding: var(--realm-spacing-sm) var(--realm-spacing-md);
  background: var(--realm-color-surface-card);
  border: 1px solid var(--realm-color-border-subtle);
  border-radius: var(--realm-radius-md);
}

.partner-list__link {
  font-weight: var(--core-font-weight-semibold);
  color: var(--realm-color-brand-primary-strong);
  text-decoration: none;
}

.partner-list__link:hover {
  text-decoration: underline;
}

.partner-list__role {
  font-size: var(--core-font-size-12);
  color: var(--realm-color-ink-soft);
}

.partner-list__more {
  font-size: var(--core-font-size-12);
  color: var(--realm-color-ink-soft);
  font-style: italic;
}

/* Collab panel 2-column layout */
.collab-detail-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--realm-spacing-lg);
  margin-top: var(--realm-spacing-lg);
}

@media (min-width: 768px) {
  .collab-detail-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* Invocation block */
.invocation-block {
  display: flex;
  align-items: center;
  gap: var(--realm-spacing-sm);
  padding: var(--realm-spacing-md);
  background: var(--realm-color-surface-card);
  border: 1px solid var(--realm-color-border-subtle);
  border-radius: var(--realm-radius-md);
  flex-wrap: wrap;
}

.invocation-block--sm {
  padding: var(--realm-spacing-xs) var(--realm-spacing-sm);
}

.invocation-block__code {
  font-family: var(--core-font-family-mono);
  font-size: var(--core-font-size-18, 18px);
  color: var(--realm-color-ink-strong);
  flex: 1;
  min-width: 0;
  word-break: break-all;
}

.invocation-block--sm .invocation-block__code {
  font-size: var(--core-font-size-14);
}

/* Empty note (tab-level inline empty state) */
.empty-note {
  color: var(--realm-color-ink-soft);
  font-size: var(--core-font-size-14);
  font-style: italic;
  padding: var(--realm-spacing-sm) 0;
}

/* chip--muted modifier */
.chip--muted {
  opacity: 0.6;
  font-style: italic;
}

/* ---------- M4/M5: reduced-motion safety net (C1 — Warden compliance) ----------
 * Token-side 0ms fallback (tokens.css) is the primary guard.
 * This block is the secondary CSS-layer override, ensuring animation and transition
 * are completely suppressed even if tokens.css fails to load or is overridden.
 * !important is deliberate: this is an a11y override, not a specificity hack.
 * Covers: floatY (M4), foilShimmer (M1), meshBreath (M2), watermarkFade (M3). */
@media (prefers-reduced-motion: reduce) {
  .hero {
    animation: none !important;
    transition: none !important;
  }

  .hero__float {
    animation: none !important;
  }

  .agent-card[data-rank-tier="veteran"]::before,
  .agent-card[data-rank-tier="elite"]::before,
  .agent-card[data-rank-tier="champion"]::before,
  .agent-card[data-rank-tier="legend"]::before,
  .agent-card[data-rank-tier="veteran"]:hover::before,
  .agent-card[data-rank-tier="veteran"]:focus-visible::before,
  .agent-card[data-rank-tier="elite"]:hover::before,
  .agent-card[data-rank-tier="elite"]:focus-visible::before,
  .agent-card[data-rank-tier="champion"]:hover::before,
  .agent-card[data-rank-tier="champion"]:focus-visible::before,
  .agent-card[data-rank-tier="legend"]:hover::before,
  .agent-card[data-rank-tier="legend"]:focus-visible::before {
    animation: none !important;
    transition: none !important;
  }

  .agent-card::after,
  .agent-card:hover::after,
  .agent-card:focus-visible::after {
    animation: none !important;
    transition: none !important;
  }
}

/* ---------- Z-index ladder: content sits above foil(1) and watermark(0) ----------
 * Flow z-index contract: ::after watermark=0, ::before foil=1, content=2.
 * Applying position:relative + z-index:2 to direct children ensures content
 * is never hidden behind the pseudo-element overlays. */
.agent-card > .agent-card__portrait,
.agent-card > .agent-card__meta,
.agent-card > .agent-card__archetype,
.agent-card > .agent-card__tagline,
.agent-card > .agent-card__footer,
.agent-card > * {
  position: relative;
  z-index: 2;
}

/* ---------- Warden C5: @supports backdrop-filter fallback ----------
 * Browsers that lack backdrop-filter (Firefox < 103 without flag, older
 * Chromium-based, some WebViews) will render glass surfaces as transparent.
 * Fall back to a fully opaque card surface so contrast remains WCAG AA. */
@supports not (backdrop-filter: blur(1px)) {
  .detail-hero {
    background: var(--realm-color-surface-card) !important;
    /* Remove any residual transparency from glass token */
    backdrop-filter: none;
  }

  /* Any other glass surfaces get the same solid fallback */
  .agent-card {
    background: var(--realm-color-surface-card) !important;
  }
}
