/*
 * battle-section.css
 * The Fox vs Cubs rivalry section + AI Lab section
 * Mobile-first. Pure flexbox — no grid, no auto columns.
 * ─────────────────────────────────────────────────────────────
 */

/* ── SECTION SHELL ──────────────────────────────────────────── */

.battle-section {
  background: var(--c-navy);
  border-top:    1px solid var(--c-border);
  border-bottom: 1px solid var(--c-border);
  overflow: hidden;
}

/* ── HEADER ─────────────────────────────────────────────────── */

.battle-header { text-align: center; margin-bottom: var(--space-7); }

.battle-header__title {
  font-family: var(--font-display);
  font-size: clamp(32px, 6vw, 62px);
  font-weight: 900;
  color: var(--c-text-100);
  line-height: 1;
  letter-spacing: -0.02em;
  margin: var(--space-3) 0 var(--space-3);
}

.battle-header__sub {
  font-size: 15px;
  color: var(--c-text-55);
  max-width: 480px;
  margin: 0 auto;
  line-height: 1.6;
}

/* ── ARENA — mobile: vertical stack ────────────────────────── */

.battle-arena {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* ── BATTLE CARD ────────────────────────────────────────────── */

.battle-card {
  display: block;
  position: relative;
  text-decoration: none;
  color: inherit;
  background: var(--c-navy-card);
  border-radius: var(--r-lg);
  border: 1px solid var(--c-border-md);
  overflow: hidden;
  transition: border-color 0.25s, transform 0.25s;
  /* On mobile (flex column): fill the full width */
  width: 100%;
  box-sizing: border-box;
}

/*
 * Card primary navigation: full-area link under content (z-index stack).
 * The card cannot be a single <a> because horse picks use nested <a> links
 * (horse_name_link) — invalid HTML makes the parser close the outer anchor early.
 */
.battle-card__backdrop {
  position: absolute;
  inset: 0;
  z-index: 1;
  border-radius: inherit;
  text-decoration: none;
}

.battle-card__backdrop:focus-visible {
  outline: 2px solid var(--c-gold);
  outline-offset: -2px;
}

.battle-card--cubs .battle-card__backdrop:focus-visible {
  outline-color: #E05A2A;
}

.battle-card:hover { transform: translateY(-4px); }
.battle-card--fox:hover  { border-color: rgba(212,175,55,0.55); }
.battle-card--cubs:hover { border-color: rgba(224,90,42,0.55); }

.battle-card__inner {
  position: relative;
  z-index: 2;
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  /* Clicks reach .battle-card__backdrop except on nested links (horse picks). */
  pointer-events: none;
}

.battle-card__inner a {
  position: relative;
  z-index: 3;
  pointer-events: auto;
}

/* Hover glow */
.battle-card__glow {
  position: absolute;
  inset: 0;
  z-index: 1;
  opacity: 0;
  transition: opacity 0.35s;
  pointer-events: none;
  border-radius: var(--r-lg);
}
.battle-card--fox:hover  .battle-card__glow--fox  { opacity: 1; }
.battle-card--cubs:hover .battle-card__glow--cubs { opacity: 1; }
.battle-card__glow--fox  { background: radial-gradient(ellipse 70% 50% at 50% 100%, rgba(212,175,55,0.10) 0%, transparent 70%); }
.battle-card__glow--cubs { background: radial-gradient(ellipse 70% 50% at 50% 100%, rgba(224,90,42,0.10) 0%, transparent 70%); }

/* ── PORTRAIT ───────────────────────────────────────────────── */

.battle-card__portrait {
  width: 100%;
  max-width: 240px;
  margin: 0 auto;
  /* Ensure SVG inside always fills this div */
  display: block;
  line-height: 0;
}

/* Fox portrait: inline SVG (legacy) or <img> from mr_fox_portrait include */
.battle-card__portrait > svg,
.battle-card__portrait > img,
.battle-card__portrait .mr-fox-portrait,
.battle-card__portrait .cubs-portrait {
  width: 100%;
  height: auto;
  aspect-ratio: 1024 / 1536;
  display: block;
}

/*
 * Fox battle hero — triptych: warm gold flank | portrait | AI flank.
 * Center column matches 1024×1536 so the art fills that cell without letterboxing;
 * flanks take remaining width (animated; pointer-events none so backdrop link works).
 */
.battle-card--fox .battle-card__portrait--fox.battle-card__fox-hero {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  width: 100%;
  max-width: none;
  margin-left: 0;
  margin-right: 0;
  box-sizing: border-box;
  height: clamp(220px, 48vw, 340px);
  overflow: hidden;
  border-radius: var(--r-sm);
  background: var(--c-navy-raised);
  pointer-events: none;
}

.battle-card__fox-flank {
  flex: 1 1 0;
  min-width: 0;
  position: relative;
  overflow: hidden;
}

.battle-card__fox-flank--gold {
  background:
    radial-gradient(ellipse 140% 90% at 100% 45%, rgba(212, 175, 55, 0.32), transparent 58%),
    radial-gradient(ellipse 80% 70% at 40% 100%, rgba(200, 140, 50, 0.18), transparent 52%),
    linear-gradient(100deg, rgba(38, 30, 20, 0.98) 0%, rgba(24, 26, 34, 0.55) 100%);
}

.battle-card__fox-flank--gold::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 82% 32%, rgba(255, 230, 170, 0.14), transparent 42%);
  animation: battle-fox-gold-pulse 5.5s ease-in-out infinite;
  pointer-events: none;
}

.battle-card__fox-flank--ai {
  background:
    repeating-linear-gradient(0deg, rgba(14, 165, 233, 0.045) 0 1px, transparent 1px 14px),
    repeating-linear-gradient(90deg, rgba(56, 189, 248, 0.04) 0 1px, transparent 1px 11px),
    linear-gradient(260deg, rgba(12, 28, 48, 0.98) 0%, rgba(22, 24, 34, 0.55) 100%);
}

.battle-card__fox-center {
  flex: 0 0 auto;
  height: 100%;
  width: auto;
  aspect-ratio: 1024 / 1536;
  max-height: 100%;
  box-sizing: border-box;
  /* Warm placeholder while SVG lazy-loads */
  background-color: #1a1208;
  background-image: var(--fox-battle-art, none);
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center center;
  /* Smooth fade-in when art arrives */
  transition: background-image 0.3s ease;
}

.battle-card__fox-binary {
  position: absolute;
  inset: 0;
  z-index: 1;
  padding: 6px 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 8px;
  line-height: 1.45;
  letter-spacing: 0.02em;
  color: rgba(103, 232, 249, 0.22);
  word-break: break-all;
  overflow: hidden;
  pointer-events: none;
  white-space: pre-wrap;
}

.battle-card__fox-flank__scan {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: linear-gradient(
    108deg,
    transparent 0%,
    rgba(34, 211, 238, 0) 40%,
    rgba(34, 211, 238, 0.1) 50%,
    rgba(14, 165, 233, 0.07) 52%,
    rgba(34, 211, 238, 0) 64%,
    transparent 100%
  );
  background-size: 220% 100%;
  animation: battle-fox-ai-scan 4.2s linear infinite;
  mix-blend-mode: screen;
}

.battle-card__fox-flank__ember {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 220, 150, 0.95) 0%, rgba(212, 175, 55, 0.2) 70%, transparent 100%);
  box-shadow: 0 0 12px rgba(255, 200, 100, 0.55);
  opacity: 0;
  animation: battle-fox-ember 4s ease-in-out infinite;
  pointer-events: none;
}

.battle-card__fox-flank__ember--1 {
  left: 38%;
  top: 22%;
  animation-delay: 0s;
}

.battle-card__fox-flank__ember--2 {
  left: 72%;
  top: 55%;
  animation-delay: 1.2s;
}

.battle-card__fox-flank__ember--3 {
  left: 55%;
  top: 78%;
  animation-delay: 2.4s;
}

@keyframes battle-fox-ai-scan {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

@keyframes battle-fox-ember {
  0%, 100% { opacity: 0; transform: translateY(6px) scale(0.6); }
  25% { opacity: 0.85; transform: translateY(0) scale(1); }
  55% { opacity: 0.35; transform: translateY(-4px) scale(0.85); }
}

@keyframes battle-fox-gold-pulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .battle-card__fox-flank__scan,
  .battle-card__fox-flank--gold::before,
  .battle-card__fox-flank__ember {
    animation: none !important;
  }

  .battle-card__fox-flank__ember {
    opacity: 0;
  }

  .battle-card__fox-flank--gold::before {
    opacity: 0.65;
  }
}

/*
 * Cubs portrait band — match Fox triptych outer height & card width (was capped by :not(--fox) for old mark).
 */
.battle-card--cubs .battle-card__portrait--cubs {
  display: block;
  padding: 0;
  width: 100%;
  max-width: none;
  margin-left: 0;
  margin-right: 0;
  box-sizing: border-box;
  height: clamp(220px, 48vw, 340px);
  overflow: hidden;
  border-radius: var(--r-sm);
  background: var(--c-navy-raised);
  pointer-events: none;
}

.battle-card--cubs .battle-card__portrait--cubs > .cubs-portrait,
.battle-card--cubs .battle-card__portrait--cubs > img.cubs-portrait {
  width: 100% !important;
  height: 100% !important;
  min-height: 100%;
  object-fit: cover;
  /* Anchor to top so faces sit in the band (center was cropping chins / leaving headroom). */
  object-position: center top;
  aspect-ratio: unset !important;
  display: block;
}

/* ── IDENTITY ───────────────────────────────────────────────── */

.battle-card__identity { text-align: center; }

.battle-card__faction {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  padding: 4px 14px;
  border-radius: var(--r-pill);
  margin-bottom: var(--space-2);
}

.battle-card__faction--fox  { background: rgba(212,175,55,0.12); color: var(--c-gold);  border: 1px solid var(--c-border-gold); }
.battle-card__faction--cubs { background: rgba(224,90,42,0.12);  color: #E05A2A; border: 1px solid rgba(224,90,42,0.3); }

.battle-card__name {
  font-family: var(--font-display);
  font-size: clamp(26px, 4vw, 38px);
  font-weight: 900;
  color: var(--c-text-100);
  letter-spacing: -0.01em;
  line-height: 1;
  margin: 0 0 var(--space-2);
}

.battle-card__descriptor {
  font-size: 12px;
  color: var(--c-text-35);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* ── PICK ───────────────────────────────────────────────────── */

.battle-card__pick {
  background: var(--c-navy-raised);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: center;
}

.battle-card__pick-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--c-text-35);
}

.battle-card__pick-horse {
  font-family: var(--font-display);
  font-size: clamp(16px, 3vw, 22px);
  font-weight: 700;
  color: var(--c-text-100);
  line-height: 1.2;
}

.battle-card__pick-horse--pending {
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 400;
  color: var(--c-text-35);
  font-style: italic;
}

.battle-card__pick-odds { font-size: 12px; color: var(--c-text-55); }

/* Horse links in battle cards */
.battle-horse-link {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid rgba(255,255,255,0.15);
  transition: color 0.2s, border-color 0.2s;
}
.battle-card--fox  .battle-horse-link:hover { color: var(--c-gold);  border-bottom-color: var(--c-gold); }
.battle-card--cubs .battle-horse-link:hover { color: #E05A2A; border-bottom-color: #E05A2A; }

/* ── RECORD ─────────────────────────────────────────────────── */

.battle-card__record {
  display: flex;
  align-items: baseline;
  gap: 8px;
  justify-content: center;
}

.battle-card__record-num {
  font-family: var(--font-display);
  font-size: 40px;
  font-weight: 900;
  line-height: 1;
}

.battle-card--fox  .battle-card__record-num { color: var(--c-gold); }
.battle-card--cubs .battle-card__record-num { color: #E05A2A; }

.battle-card__record-label { font-size: 12px; color: var(--c-text-35); }

/* ── CTA ────────────────────────────────────────────────────── */

.battle-card__cta {
  text-align: center;
  padding-top: var(--space-2);
  border-top: 1px solid var(--c-border);
}

.battle-card__cta-text { font-size: 13px; font-weight: 600; letter-spacing: 0.04em; transition: color 0.2s; }
.battle-card--fox  .battle-card__cta-text { color: var(--c-gold); }
.battle-card--cubs .battle-card__cta-text { color: #E05A2A; }

/* ── VS DIVIDER — mobile: horizontal strip ──────────────────── */

.battle-vs {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  padding: var(--space-2) 0;
}

.battle-vs__line {
  flex: 1;
  height: 1px;
  background: var(--c-border-md);
}

/* On mobile the top/bottom lines become left/right */
.battle-vs__line--top,
.battle-vs__line--bottom { height: 1px; }

.battle-vs__badge {
  width: 52px; height: 52px;
  border-radius: 50%;
  border: 1px solid var(--c-border-gold);
  background: var(--c-navy-card);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.battle-vs__text {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 900;
  color: var(--c-gold);
  letter-spacing: 0.1em;
}

/* Score + bar below VS on mobile — hidden, shown at 768px */
.battle-vs__score,
.battle-vs__bar,
.battle-vs__bar-labels,
.battle-vs__caption { display: none; }

/* ── FOOTER ─────────────────────────────────────────────────── */

.battle-footer {
  text-align: center;
  margin-top: var(--space-6);
  padding-top: var(--space-5);
  border-top: 1px solid var(--c-border);
}

.battle-footer__link {
  font-size: 13px;
  font-weight: 600;
  color: var(--c-text-55);
  letter-spacing: 0.04em;
  transition: color 0.2s;
}
.battle-footer__link:hover { color: var(--c-gold); }

/* Mr Fox raster portrait (optional nameplate under image) */
.mr-fox-portrait-caption {
  text-align: center;
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.22em;
  color: var(--c-gold);
  margin: 10px 0 0;
}


/* ═══════════════════════════════════════════════════════
   TABLET 768px+ — side-by-side layout
   Flexbox row: [fox card] [vs column] [cubs card]
   Each card: calc(50% - 80px)  VS column: 160px fixed
═══════════════════════════════════════════════════════ */

@media (min-width: 768px) {

  .battle-header { margin-bottom: var(--space-5); }

  .battle-arena {
    flex-direction: row;
    align-items: stretch;
    gap: 0;
    /* Collapse anonymous whitespace flex items (stray text nodes between tags) */
    font-size: 0;
    line-height: 0;
  }

  .battle-arena > * {
    font-size: inherit;  /* restore from body 15px, not browser 'medium' */
    line-height: inherit;
  }

  /*
   * Equal-width cards: flex-basis 0 + grow, min-width 0 — do NOT set width: 0;
   * that shrinks percentage-based SVGs to zero height on some engines.
   */
  .battle-card {
    flex: 1 1 0%;
    width: auto; /* override mobile width:100% so three columns share one row */
    min-width: 0;
    align-self: stretch;
  }

  /* VS column: fixed 160px, never shrinks, never grows */
  .battle-vs {
    flex: 0 0 160px;
    width: 160px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-5) var(--space-4);
    gap: var(--space-3);
  }

  .battle-vs__line--top,
  .battle-vs__line--bottom {
    width: 1px;
    height: 60px;
    flex: 0 0 auto;
  }

  /* Show score and bar on desktop */
  .battle-vs__score  { display: flex; align-items: center; gap: var(--space-3); background: var(--c-navy-raised); border: 1px solid var(--c-border-md); border-radius: var(--r-pill); padding: var(--space-2) var(--space-4); }
  .battle-vs__bar,
  .battle-vs__bar-labels { display: flex; width: 100%; }
  .battle-vs__caption { display: block; }

  .battle-vs__score-side { display: flex; flex-direction: column; align-items: center; gap: 2px; }
  .battle-vs__score-num  { font-family: var(--font-display); font-size: 26px; font-weight: 900; line-height: 1; }
  .battle-vs__score-side--fox .battle-vs__score-num { color: var(--c-gold); }
  .battle-vs__score-side--cub .battle-vs__score-num { color: #E05A2A; }
  .battle-vs__score-label { font-size: 9px; font-weight: 600; letter-spacing: 0.15em; text-transform: uppercase; color: var(--c-text-35); }
  .battle-vs__score-dash  { color: var(--c-border-md); font-size: 18px; }

  .battle-vs__bar { height: 6px; border-radius: var(--r-pill); overflow: hidden; background: var(--c-navy-raised); }
  .battle-vs__bar-fox  { background: var(--c-gold);  height: 100%; }
  .battle-vs__bar-draw { background: var(--c-border-md); height: 100%; }
  .battle-vs__bar-cub  { background: #E05A2A; height: 100%; }

  .battle-vs__bar-labels { justify-content: space-between; }
  .battle-vs__bar-label--fox { font-size: 10px; font-weight: 600; color: var(--c-gold); }
  .battle-vs__bar-label--cub { font-size: 10px; font-weight: 600; color: #E05A2A; }

  .battle-vs__caption { font-size: 11px; color: var(--c-text-35); text-align: center; line-height: 1.5; font-style: italic; }

  /* Desktop row: tighter card chrome so the section does not dominate the viewport. */
  .battle-card__inner {
    padding: var(--space-4);
    gap: var(--space-3);
  }

  .battle-card__pick {
    padding: var(--space-3);
  }

  .battle-card__pick-horse {
    font-size: clamp(14px, 2.2vw, 18px);
  }

  .battle-card__record-num {
    font-size: clamp(26px, 4vw, 32px);
  }

  .battle-card__name {
    font-size: clamp(22px, 3vw, 30px);
  }

  /* Fox hero + Cubs portrait: same band height on row layout */
  .battle-card--cubs .battle-card__portrait--cubs {
    height: clamp(240px, 34vh, 380px);
  }

  .battle-card--fox .battle-card__portrait--fox {
    max-width: none;
    width: 100%;
    margin-left: 0;
    margin-right: 0;
    height: clamp(240px, 34vh, 380px);
  }
}


/* ═══════════════════════════════════════════════════════
   DESKTOP 1024px+
═══════════════════════════════════════════════════════ */

@media (min-width: 1024px) {

  .battle-vs { flex: 0 0 160px; width: 160px; padding: var(--space-4) var(--space-3); }

  .battle-card--cubs .battle-card__portrait--cubs {
    height: clamp(260px, 32vh, 400px);
  }

  .battle-card--fox .battle-card__portrait--fox {
    max-width: none;
    width: 100%;
    margin-left: 0;
    margin-right: 0;
    height: clamp(260px, 32vh, 400px);
  }

  .battle-card__name { font-size: clamp(24px, 2.6vw, 34px); }

  .battle-vs__line--top,
  .battle-vs__line--bottom { height: 56px; }
}

/* ─────────────────────────────────────────────────────────────
   AI LAB SECTION
   /simulation/how-it-works/ — process + methodology
───────────────────────────────────────────────────────────── */

.ai-lab-section {
  background:
    radial-gradient(ellipse 65% 55% at 5% 50%,  rgba(14,90,170,0.10), transparent 52%),
    radial-gradient(ellipse 50% 50% at 95% 45%, rgba(212,175,55,0.06), transparent 48%),
    var(--c-midnight);
  border-top: 1px solid rgba(14,165,233,0.08);
}

.ai-lab-inner {
  display: flex;
  flex-direction: column;
  gap: var(--space-7);
}

.ai-lab__title {
  font-family: var(--font-display);
  font-size: clamp(26px, 6vw, 48px);
  font-weight: 900;
  color: var(--c-text-100);
  line-height: 1.05;
  letter-spacing: -0.01em;
  margin: var(--space-3) 0 var(--space-4);
}

.ai-lab__text {
  font-size: 15px;
  line-height: 1.8;
  color: var(--c-text-55);
  margin-bottom: var(--space-5);
}

.ai-lab__text em {
  color: var(--c-text-100);
  font-style: italic;
}

.ai-lab__mechanics {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.ai-lab__mechanic       { display: flex; align-items: flex-start; gap: 14px; }
.ai-lab__mechanic-icon  { font-size: 20px; flex-shrink: 0; margin-top: 2px; }
.ai-lab__mechanic-title { font-size: 14px; font-weight: 700; color: var(--c-text-100); margin-bottom: 2px; }
.ai-lab__mechanic-body  { font-size: 13px; line-height: 1.6; color: var(--c-text-55); }

.ai-lab__cta { width: 100%; justify-content: center; min-height: 48px; }

/* Terminal mockup */
.ai-lab__visual {
  display: flex;
  align-items: center;
  justify-content: center;
}

.ai-lab__terminal {
  width: 100%;
  max-width: 480px;
  background: #030305;
  border: 1px solid rgba(14,165,233,0.2);
  border-radius: var(--r-md);
  overflow: hidden;
  box-shadow: var(--shadow-raised), 0 0 40px rgba(14,165,233,0.06);
}

.ai-lab__terminal-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: rgba(255,255,255,0.03);
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.ai-lab__terminal-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.ai-lab__terminal-dot--red   { background: #ff5f57; }
.ai-lab__terminal-dot--amber { background: #febc2e; }
.ai-lab__terminal-dot--green { background: #28c840; }

.ai-lab__terminal-title {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--c-text-35);
  text-transform: uppercase;
  margin-left: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-lab__terminal-body {
  padding: var(--space-4) var(--space-5);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ai-lab__terminal-line {
  font-family: 'Courier New', Courier, monospace;
  font-size: 12px;
  color: var(--c-text-55);
  line-height: 1.5;
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
}

.ai-lab__terminal-line--dim   { color: var(--c-text-35); }
.ai-lab__terminal-line--blink { color: var(--c-cyan); animation: mf-seam 1.2s ease-in-out infinite; }

.ai-lab__terminal-val              { color: var(--c-text-100); font-weight: 600; text-align: right; }
.ai-lab__terminal-val--gold        { color: var(--c-gold); }
.ai-lab__terminal-val--green       { color: var(--c-emerald-lt); }

@media (min-width: 768px) {
  .ai-lab-inner   { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-8); align-items: center; }
  .ai-lab__cta    { width: auto; }
}
