/* =============================================================================
   #stages — the twenty-stage journey. Relies on styles.css for tokens,
   .section/.container/.card/.chip/.reveal. Everything here is scoped.
   ========================================================================== */

#stages {
  --era: var(--gold);
  overflow: hidden;
}
#stages [data-era="1"] { --era: #E3B21F; }
#stages [data-era="2"] { --era: #E0763A; }
#stages [data-era="3"] { --era: #E0529C; }
#stages [data-era="4"] { --era: #2E97AD; }
#stages [data-era="5"] { --era: #9A63E0; }

/* ------------------------------------------------------- era ribbon --- */
#stages .st-overview {
  display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr);
  gap: clamp(16px, 2.4vw, 28px); align-items: stretch;
  margin-bottom: clamp(28px, 4vw, 44px);
}
#stages .st-ribbon {
  list-style: none; margin: 0; padding: clamp(20px, 2.6vw, 28px) clamp(12px, 2vw, 24px);
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px;
  position: relative; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-card); box-shadow: var(--shadow);
}
#stages .st-ribbon::before,
#stages .st-ribbon::after {
  content: ""; position: absolute; top: calc(clamp(20px, 2.6vw, 28px) + 24px);
  left: 10%; right: 10%; height: 6px; border-radius: var(--r-pill);
  background: var(--surface-alt); border: 1px solid var(--border); transform: translateY(-50%);
}
#stages .st-ribbon::after {
  border: 0; right: auto; width: 0;
  background: linear-gradient(90deg, #E3B21F, #E0763A, #E0529C, #2E97AD, #9A63E0);
  transition: width 1.6s cubic-bezier(.2, .8, .2, 1) .35s;
}
#stages .st-overview.in .st-ribbon::after { width: 80%; }

#stages .st-step {
  position: relative; z-index: 1; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0;
}
#stages .st-step-dot {
  width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center;
  font-size: 20px; color: #3A2A06;
  background: linear-gradient(145deg, var(--gold-light), var(--gold));
  box-shadow: inset 0 -3px 0 var(--gold-edge), 0 0 0 4px color-mix(in srgb, var(--era) 55%, var(--surface)), 0 8px 18px var(--glow);
  transform: scale(.4); opacity: 0;
}
#stages .st-overview.in .st-step-dot { animation: pop .6s cubic-bezier(.2, .8, .2, 1) forwards; animation-delay: calc(.35s + var(--i) * .28s); }
#stages .st-step-name { font: 800 14px/1.2 var(--ff-body); color: var(--ink); }
#stages .st-step-meta { font: 600 12.5px/1.3 var(--ff-body); color: var(--ink-2); }
#stages .st-step-meta .money { font-family: var(--ff-body); font-weight: 800; }

#stages .st-growth {
  background:
    radial-gradient(120% 90% at 100% 0%, var(--money-soft), transparent 60%),
    var(--surface);
  border: 1px solid var(--border); border-radius: var(--r-card); box-shadow: var(--shadow);
  padding: clamp(20px, 2.6vw, 28px); display: flex; flex-direction: column; justify-content: center;
}
#stages .st-growth-label {
  font: 800 12px/1 var(--ff-body); letter-spacing: .14em; text-transform: uppercase;
  color: var(--brand); margin-bottom: 10px;
}
#stages .st-growth-figs {
  font-size: clamp(26px, 3.4vw, 38px); line-height: 1.05; margin-bottom: 12px;
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px;
}
#stages .st-growth-arrow { color: var(--ink-3); }
#stages .st-growth-big { font-size: 1.25em; text-shadow: 0 4px 18px var(--money-soft); }
#stages .st-growth-note { font-size: 14.5px; line-height: 1.5; color: var(--ink-2); margin: 0; }

/* ------------------------------------------------------------- tabs --- */
#stages .st-tabs {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 10px;
  margin-bottom: clamp(24px, 3.4vw, 36px);
}
#stages .st-tab {
  display: inline-flex; align-items: center; gap: 10px; min-height: 48px;
  padding: 6px 16px 6px 8px; border-radius: var(--r-pill); cursor: pointer;
  font: 700 14px/1.15 var(--ff-body); color: var(--ink-2); text-align: left;
  background: var(--surface); border: 2px solid var(--border);
  transition: transform .2s, border-color .2s, box-shadow .2s, background .2s, color .2s;
}
#stages .st-tab:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--era) 70%, var(--border)); }
#stages .st-tab[data-filter="1"] { --era: #E3B21F; }
#stages .st-tab[data-filter="2"] { --era: #E0763A; }
#stages .st-tab[data-filter="3"] { --era: #E0529C; }
#stages .st-tab[data-filter="4"] { --era: #2E97AD; }
#stages .st-tab[data-filter="5"] { --era: #9A63E0; }
#stages .st-tab-num {
  min-width: 34px; height: 34px; padding: 0 8px; border-radius: var(--r-pill);
  display: grid; place-items: center; font-size: 16px; color: var(--ink);
  background: color-mix(in srgb, var(--era) 22%, var(--surface));
}
#stages .st-tab[aria-selected="true"] {
  color: #3A2A06; border-color: var(--gold-edge);
  background: linear-gradient(180deg, var(--gold-light), var(--gold));
  box-shadow: 0 4px 0 var(--gold-edge), 0 10px 22px var(--glow);
}
#stages .st-tab[aria-selected="true"] .st-tab-num { background: rgba(255, 255, 255, .55); color: #3A2A06; }

/* ------------------------------------------------------------- grid --- */
#stages .st-grid {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: clamp(16px, 2.2vw, 24px);
}
#stages .st-card {
  padding: 0; overflow: hidden; display: flex; flex-direction: column; min-width: 0;
}
#stages .st-card.is-hidden { display: none; }
#stages .st-card.st-pop { animation: st-in .55s cubic-bezier(.2, .8, .2, 1) backwards; animation-delay: var(--pd, 0s); }
@keyframes st-in {
  0% { opacity: 0; transform: translateY(18px) scale(.9); }
  65% { opacity: 1; transform: translateY(-3px) scale(1.02); }
  100% { opacity: 1; transform: none; }
}

#stages .st-art {
  position: relative; aspect-ratio: 3 / 2; overflow: hidden;
  background:
    radial-gradient(90% 80% at 50% 60%, color-mix(in srgb, var(--era) 30%, var(--surface)), transparent 75%),
    color-mix(in srgb, var(--era) 14%, var(--surface-alt));
  border-bottom: 1px solid var(--border);
}
#stages .st-art img {
  width: 100%; height: 100%; object-fit: cover;
  transition: transform .6s cubic-bezier(.2, .8, .2, 1);
}
#stages .st-card:hover .st-art img,
#stages .st-card:focus-within .st-art img { transform: scale(1.08) rotate(-1.5deg); }

#stages .st-num {
  position: absolute; top: 12px; left: 12px; font-size: 24px; line-height: 1;
  padding: 9px 12px 6px; border-radius: 12px; letter-spacing: .02em;
  box-shadow: inset 0 -3px 0 var(--gold-edge), 0 6px 14px rgba(58, 42, 6, .25);
  transition: transform .3s cubic-bezier(.2, .8, .2, 1);
}
#stages .st-card:hover .st-num { transform: rotate(-6deg) scale(1.08); }

#stages .st-body { padding: 16px 18px 18px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
#stages .st-title { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 2px; }
#stages .st-card h3 { font-family: var(--ff-display); font-weight: 400; font-size: 21px; line-height: 1.1; margin: 0; color: var(--ink); }
#stages .st-era {
  flex: none; font-size: 12px; padding: 5px 10px; color: var(--ink);
  background: color-mix(in srgb, var(--era) 20%, var(--surface));
  border-color: color-mix(in srgb, var(--era) 50%, transparent);
}
#stages .st-card p { margin: 0; font-size: 15px; line-height: 1.4; color: var(--ink-2); }
#stages .st-card .st-sale { font-weight: 700; color: var(--ink); }
#stages .st-sale .money { font-size: 1.15em; }
#stages .st-machines { padding: 7px 10px; border-radius: 10px; background: var(--surface-alt); border: 1px dashed var(--border); }
#stages .st-arrow { color: var(--brand); font-weight: 800; }
#stages .st-unlock strong { color: var(--ink); }
#stages .st-unlock .chip { font-size: 12px; padding: 5px 10px; }
#stages .st-card .st-crew { margin-top: auto; padding-top: 8px; border-top: 1px solid var(--border); font-size: 13.5px; }
#stages .st-crew-label {
  display: inline-block; margin-right: 4px; font: 800 11px/1 var(--ff-body);
  letter-spacing: .12em; text-transform: uppercase; color: var(--brand);
}

/* ------------------------------------------------------ stage 20 hero --- */
#stages .st-hero {
  grid-column: 1 / -1; flex-direction: row; border: 3px solid transparent;
  background:
    linear-gradient(var(--surface), var(--surface)) padding-box,
    linear-gradient(100deg, var(--gold-edge), var(--gold-light) 25%, var(--gold) 50%, var(--gold-light) 75%, var(--gold-edge)) border-box;
  background-size: 100% 100%, 300% 100%;
  animation: st-border 6s linear infinite;
  box-shadow: var(--shadow-lg), 0 0 40px var(--glow);
}
#stages .st-hero.st-pop { animation: st-in .55s cubic-bezier(.2, .8, .2, 1) backwards, st-border 6s linear infinite; animation-delay: var(--pd, 0s), 0s; }
@keyframes st-border { from { background-position: 0 0, 0% 0; } to { background-position: 0 0, 300% 0; } }

#stages .st-hero-art {
  position: relative; flex: 1.15 1 0; min-width: 0; overflow: hidden; min-height: 280px;
  background:
    radial-gradient(80% 80% at 50% 55%, color-mix(in srgb, var(--gold) 40%, var(--surface)), transparent 75%),
    color-mix(in srgb, var(--era) 16%, var(--surface-alt));
}
#stages .st-hero-art img {
  width: 100%; height: 100%; object-fit: cover;
  transition: transform .8s cubic-bezier(.2, .8, .2, 1);
}
#stages .st-hero:hover .st-hero-art img { transform: scale(1.06); }
#stages .st-hero .st-num { font-size: 34px; padding: 12px 16px 8px; animation: pulse 2.6s ease-in-out infinite; }

#stages .st-hero-body {
  flex: 1 1 0; min-width: 0; padding: clamp(20px, 3vw, 36px);
  display: flex; flex-direction: column; gap: 10px;
}
#stages .st-hero-kicker { display: flex; flex-wrap: wrap; gap: 8px; }
#stages .st-hero h3 { font-size: clamp(28px, 3.6vw, 42px); }
#stages .st-hero .st-hero-lede { font-size: 16px; line-height: 1.5; }

#stages .st-hero-stats {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 4px 0;
}
#stages .st-hero-stats div {
  background: var(--surface-alt); border: 1px solid var(--border); border-radius: 14px;
  padding: 10px 12px; text-align: center; min-width: 0;
}
#stages .st-hero-stats dt { font: 800 11px/1 var(--ff-body); letter-spacing: .12em; text-transform: uppercase; color: var(--ink-2); margin-bottom: 6px; }
#stages .st-hero-stats dd { margin: 0; font-size: clamp(18px, 2.2vw, 24px); line-height: 1.1; color: var(--ink); }
#stages .st-hero-stats dd.money { color: var(--money); }

#stages .st-zones { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
#stages .st-zones .chip { font-size: 12.5px; padding: 6px 10px; transition: transform .2s, border-color .2s; }
#stages .st-zones .chip:hover { transform: translateY(-2px); border-color: var(--border-strong); }
#stages .st-hero.in .st-zones .chip { animation: st-in .5s cubic-bezier(.2, .8, .2, 1) backwards; animation-delay: calc(.4s + var(--z) * .05s); }

/* -------------------------------------------------------- responsive --- */
@media (max-width: 1080px) {
  #stages .st-overview { grid-template-columns: 1fr; }
}
@media (max-width: 960px) {
  #stages .st-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #stages .st-hero { flex-direction: column; }
  #stages .st-hero-art { flex: none; min-height: 0; aspect-ratio: 3 / 2; }
  #stages .st-hero-body { flex: none; }
}
@media (max-width: 640px) {
  #stages .st-ribbon { grid-template-columns: 1fr; gap: 14px; padding: 20px 16px; }
  #stages .st-ribbon::before,
  #stages .st-ribbon::after { top: 44px; bottom: 44px; left: 40px; right: auto; width: 6px; height: auto; transform: translateX(-50%); }
  #stages .st-ribbon::after { height: 0; bottom: auto; transition: height 1.6s cubic-bezier(.2, .8, .2, 1) .35s; background: linear-gradient(180deg, #E3B21F, #E0763A, #E0529C, #2E97AD, #9A63E0); }
  #stages .st-overview.in .st-ribbon::after { width: 6px; height: calc(100% - 88px); }
  #stages .st-step { display: grid; grid-template-columns: 48px minmax(0, 1fr); column-gap: 14px; row-gap: 2px; text-align: left; align-items: center; }
  #stages .st-step-dot { grid-row: span 2; }
  #stages .st-tabs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  #stages .st-tab { padding-right: 10px; font-size: 12.5px; border-radius: 16px; }
  #stages .st-tab-name { min-width: 0; overflow-wrap: anywhere; }
}
@media (max-width: 540px) {
  #stages .st-grid { grid-template-columns: 1fr; }
  #stages .st-hero-stats { gap: 6px; }
  #stages .st-hero-stats div { padding: 8px 6px; }
}

@media (prefers-reduced-motion: reduce) {
  #stages .st-step-dot { transform: none; opacity: 1; }
  #stages .st-hero, #stages .st-hero .st-num { animation: none; }
}
.no-js #stages .st-step-dot { transform: none; opacity: 1; }
.no-js #stages .st-ribbon::after { width: 80%; }
