/**
 * Builder Core v7.6.3 - Shared builder infrastructure
 * Extracted from team-builder.css monolith
 *
 * Contains: Animations, SPA container, app header bar,
 * stage system, step headers, page layout resets.
 * Loaded on ALL builder pages.
 *
 * DESIGN SYSTEM
 * =============
 * - Variables: Defined in /css/core/variables.css (single source of truth)
 * - Primary accent: Gold (#B89A57 / var(--gold-500))
 * - Font stack: Oswald (headings), system fonts (body)
 */

/* ========================================================
   VARIABLES - Now using core/variables.css
   All design tokens moved to single source of truth
   ======================================================== */

/* ========================================================
   ANIMATIONS
   ======================================================== */
@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 15px rgba(184, 154, 87, 0.2), inset 0 0 20px rgba(184, 154, 87, 0.05); }
  50% { box-shadow: 0 0 25px rgba(184, 154, 87, 0.35), inset 0 0 30px rgba(184, 154, 87, 0.1); }
}

@keyframes pop-in {
  0% { transform: scale(0.95); opacity: 0.8; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes fadeSlideIn {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes fadeSlideOut {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(-20px);
  }
}

@keyframes itemAdded {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); box-shadow: 0 0 20px rgba(184, 154, 87, 0.4); }
  100% { transform: scale(1); }
}

@keyframes countBump {
  0% { transform: scale(1); }
  50% { transform: scale(1.15); color: var(--gold-400); }
  100% { transform: scale(1); }
}

@keyframes buttonPulse {
  0% { box-shadow: 0 0 0 0 rgba(184, 154, 87, 0.4); }
  70% { box-shadow: 0 0 0 8px rgba(184, 154, 87, 0); }
  100% { box-shadow: 0 0 0 0 rgba(184, 154, 87, 0); }
}

/* ========================================================
   SPA CONTAINER
   ======================================================== */
.builder-app {
  padding: var(--space-6) 0 4rem;
  min-height: 100vh;
}

.app-card {
  max-width: 1200px;
  margin: 0 auto;
  background: linear-gradient(165deg, rgba(32, 38, 48, 0.98) 0%, rgba(22, 26, 34, 0.99) 100%);
  border: 3px solid var(--gold-700);
  border-radius: var(--radius-lg);
  box-shadow:
    inset 0 0 6px 2px rgba(0, 0, 0, 0.4),
    0 2px 4px 4px rgba(18, 15, 23, 0.8),
    0 -1px 3px 4px rgba(60, 45, 70, 0.6),
    0 0 0 8px var(--purple-900),
    0 0 0 10px var(--gold-700),
    0 10px 30px rgba(0, 0, 0, 0.5);
  position: relative;
  overflow: hidden; /* Clip children to border-radius */
}

/* Card background texture for all builders */
.app-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: url('../../assets/card_background_1.png') center / cover no-repeat;
  opacity: 0.15;
  pointer-events: none;
  z-index: 0;
}

/* Ensure all card content sits above the ::before texture */
.app-card > * {
  position: relative;
  z-index: 1;
}

/* In builder stage, card bottom is square so stats bar can join seamlessly */
.builder-app.stage-builder .app-card {
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  border-bottom: none;
  overflow: visible;
  padding-bottom: 100px; /* Reserve space for fixed stats bar */
}

/* ========================================================
   APP HEADER BAR
   ======================================================== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) 1rem;
  background: linear-gradient(180deg,
    rgba(20, 24, 28, 0.98) 0%,
    rgba(30, 35, 41, 0.95) 100%);
  border-bottom: 2px solid transparent;
  border-image: linear-gradient(90deg,
    transparent 0%,
    rgba(184, 154, 87, 0.6) 20%,
    var(--gold-600) 50%,
    rgba(184, 154, 87, 0.6) 80%,
    transparent 100%) 1;
  min-height: 52px;
  position: relative;
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.03);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0; /* Match parent's inner radius */
}

/* Subtle top accent line */
.app-header::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg,
    transparent 0%,
    rgba(184, 154, 87, 0.3) 30%,
    rgba(212, 165, 116, 0.4) 50%,
    rgba(184, 154, 87, 0.3) 70%,
    transparent 100%);
}

.app-header .header-back-btn {
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal), transform var(--transition-fast);
  flex-shrink: 0;
  width: 34px; /* Fixed width for balance */
}

.app-header.show-back .header-back-btn {
  opacity: 1;
  pointer-events: auto;
}

/* True center positioning */
.app-header .header-center {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  pointer-events: none;
}

.app-header .header-title {
  font-family: var(--font-heading);
  font-size: 2rem;
  font-weight: 700;
  color: var(--gold-500);
  text-transform: uppercase;
  letter-spacing: 2px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  position: relative;
}

/* Decorative lines around title */
.app-header .header-center::before,
.app-header .header-center::after {
  content: '';
  flex: 0 0 30px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(184, 154, 87, 0.5));
}

.app-header .header-center::after {
  background: linear-gradient(90deg, rgba(184, 154, 87, 0.5), transparent);
}

.app-header .header-badges {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal);
}

.app-header.show-badges .header-badges {
  opacity: 1;
  pointer-events: auto;
}

.header-badge {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: linear-gradient(180deg, rgba(40, 45, 52, 0.9), rgba(25, 30, 35, 0.95));
  border: 1px solid rgba(184, 154, 87, 0.35);
  padding: var(--space-2) 0.65rem;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
  font-family: var(--font-heading);
  letter-spacing: 0.5px;
  box-shadow: 
    0 2px 4px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.header-badge.tier-badge {
  color: var(--text-primary);
}

.header-badge.tier-badge i {
  color: var(--gold-600);
  font-size: 0.7rem;
}

.header-badge.price-badge {
  background: linear-gradient(180deg, var(--gold-600) 0%, #a06828 100%);
  color: var(--text-inverse);
  border-color: rgba(212, 165, 116, 0.5);
  font-weight: 700;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.2);
}

/* Header debug button (dev only) */
.header-debug-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: linear-gradient(180deg, rgba(60, 65, 72, 0.9), rgba(35, 40, 45, 0.95));
  border: 1px solid rgba(100, 100, 100, 0.4);
  border-radius: var(--radius-sm);
  color: #888;
  cursor: pointer;
  transition: all var(--transition-fast);
  font-size: 0.8rem;
}

.header-debug-btn:hover {
  background: linear-gradient(180deg, rgba(80, 85, 92, 0.9), rgba(45, 50, 55, 0.95));
  border-color: rgba(184, 154, 87, 0.5);
  color: var(--gold-500);
}

/* Header back button styles */
.header-back-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  background: linear-gradient(180deg, rgba(40, 45, 52, 0.9), rgba(25, 30, 35, 0.95));
  border: 1px solid rgba(184, 154, 87, 0.35);
  border-radius: var(--radius-sm);
  color: var(--gold-600);
  cursor: pointer;
  transition: all var(--transition-fast);
  flex-shrink: 0;
  box-shadow: 
    0 2px 4px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.header-back-btn:hover {
  background: linear-gradient(180deg, rgba(184, 154, 87, 0.25), rgba(184, 154, 87, 0.15));
  border-color: var(--gold-600);
  transform: translateX(-2px);
  color: var(--gold-400);
}

/* ========================================================
   STAGE SYSTEM
   ======================================================== */
.app-stages {
  position: relative;
  min-height: 400px;
}

.stage {
  display: none;
  opacity: 0;
  padding: 0; /* Override any section padding */
}

.stage.active {
  display: block;
  animation: fadeSlideIn 0.4s ease-out forwards;
}

.stage.exiting {
  display: block;
  animation: fadeSlideOut 0.3s ease-in forwards;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
}

.stage-content {
  /* Base stage content styling - centered within wider card */
  max-width: 900px;
  margin-left: auto;
  margin-right: auto;
  width: 100%;
}

.stage-padded {
  padding: var(--space-6);
}


/* ========================================================
   STEP HEADER (Steps 1 & 2)
   ======================================================== */
.step-header {
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
  margin-bottom: 1.5rem;
}

.step-number {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--gold-600) 0%, var(--gold-400) 100%);
  color: var(--text-on-gold);
  border-radius: 50%;
  font-size: 1.1rem;
  font-weight: 700;
  flex-shrink: 0;
}

.step-text {
  flex: 1;
}

.step-title {
  font-size: 1.5rem;
  font-weight: 600;
  font-family: var(--font-display);
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--gold-500);
}

.step-subtitle {
  font-size: 0.95rem;
  font-family: var(--font-body);
  font-weight: 400;
  color: var(--text-secondary);
  margin-top: var(--space-1);
}

/* ========================================================
   BASE / PAGE LAYOUT
   ======================================================== */
.team-builder-page {
  min-height: 100vh;
  padding-bottom: 80px; /* Space for mobile bottom bar */
}

/* Reset pages.css aggressive margins - use !important to override */
.team-builder-page h1,
.team-builder-page h2,
.team-builder-page h3,
.team-builder-page h4,
.team-builder-page p,
.team-builder-page ul,
.team-builder-page ol,
.team-builder-page li {
  margin: 0;
  padding-left: 0;
}

.team-builder-page .container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
