.class-stage {
  --class-accent: 132 150 104;
  position: relative;
  display: grid;
  grid-template-columns: minmax(260px, 380px) minmax(0, 1fr);
  grid-template-areas: "portrait copy" "picker picker";
  gap: 2.5rem 4rem;
  align-items: center;
  padding: clamp(1.75rem, 4vw, 3.25rem);
  border: 1px solid var(--line);
  border-radius: 24px;
  background:
    radial-gradient(60% 90% at 18% 40%, rgb(var(--class-accent) / 0.22), transparent 70%),
    linear-gradient(180deg, rgb(28 24 18 / 0.92), rgb(12 10 8 / 0.95));
  overflow: hidden;
  transition: background 700ms ease;
}

.class-portrait { position: relative; grid-area: portrait; justify-self: center; width: min(340px, 72vw); aspect-ratio: 1; }
.class-portrait img { position: relative; width: 100%; height: 100%; border-radius: 50%; box-shadow: 0 0 0 3px rgb(8 7 5 / 0.9), 0 0 0 5px rgb(var(--class-accent) / 0.7), 0 30px 70px rgb(0 0 0 / 0.7); transition: opacity 260ms ease, transform 500ms var(--ease); }
.class-portrait img.is-swapping { opacity: 0; transform: scale(0.96); }
.class-halo {
  position: absolute;
  inset: -9%;
  border-radius: 50%;
  background: conic-gradient(from 90deg, rgb(var(--class-accent) / 0), rgb(var(--class-accent) / 0.8), rgb(var(--class-accent) / 0) 40%, rgb(var(--class-accent) / 0.55) 70%, rgb(var(--class-accent) / 0));
  filter: blur(22px);
  opacity: 0.8;
  animation: ring-turn 18s linear infinite;
}

.class-copy { display: grid; grid-area: copy; align-content: center; gap: 0.9rem; min-width: 0; }
.class-copy h3 { font-size: clamp(2.6rem, 5vw, 4.2rem); line-height: 1; font-variation-settings: "opsz" 60; }
.class-role { color: rgb(var(--class-accent)); font: 600 1.25rem / 1.3 var(--serif); filter: brightness(1.45); }
.class-copy > p:not(.kicker, .class-role) { max-width: 38rem; color: var(--text-2); font-size: 1.04rem; }

.class-signatures { display: flex; flex-wrap: wrap; gap: 0.75rem; margin: 0.6rem 0 0; padding: 0; list-style: none; }
.class-signatures li { display: flex; align-items: center; gap: 0.7rem; padding: 0.4rem 0.9rem 0.4rem 0.4rem; border: 1px solid var(--line); border-radius: 12px; background: rgb(8 7 5 / 0.5); font: 600 0.9rem / 1.2 var(--sans); }
.class-signatures img { width: 44px; height: 44px; border-radius: 9px; box-shadow: 0 0 0 1px var(--line-strong); }

.class-picker { display: grid; grid-area: picker; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 0.5rem; padding-top: 1.6rem; border-top: 1px solid var(--line); }
.class-picker button {
  display: grid;
  justify-items: center;
  gap: 0.55rem;
  padding: 0.7rem 0.25rem;
  border: 1px solid transparent;
  border-radius: 14px;
  color: var(--text-3);
  background: transparent;
  font: 650 0.8rem / 1 var(--sans);
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: color 180ms ease, background-color 180ms ease, border-color 180ms ease;
}
.class-picker img { width: 64px; height: 64px; border-radius: 50%; filter: grayscale(0.7) brightness(0.75); box-shadow: 0 0 0 2px rgb(8 7 5), 0 0 0 3px var(--line); transition: filter 220ms ease, box-shadow 220ms ease, transform 300ms var(--ease); }
.class-picker button:hover { color: var(--parchment); background: rgb(216 179 106 / 0.06); }
.class-picker button:hover img { filter: none; transform: translateY(-3px); }
.class-picker button[aria-selected="true"] { border-color: var(--line-strong); color: var(--gold-hi); background: rgb(216 179 106 / 0.1); }
.class-picker button[aria-selected="true"] img { filter: none; box-shadow: 0 0 0 2px rgb(8 7 5), 0 0 0 4px var(--gold), 0 0 22px rgb(246 217 148 / 0.4); }

.spellbook-intro { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr); gap: 3rem; align-items: center; margin-bottom: 2.5rem; }
.tome-shelf { position: relative; height: 300px; }
.tome-shelf img { position: absolute; top: 50%; left: 50%; width: 190px; height: 190px; border-radius: 22px; box-shadow: 0 30px 50px -18px rgb(0 0 0 / 0.9), 0 0 0 1px rgb(246 217 148 / 0.2); animation: tome-float 7s ease-in-out infinite; }
.tome-shelf img:nth-child(1) { --x: -118%; --r: -14deg; z-index: 1; animation-delay: -1s; }
.tome-shelf img:nth-child(2) { --x: -84%; --r: -7deg; z-index: 2; animation-delay: -3s; }
.tome-shelf img:nth-child(3) { --x: -50%; --r: 0deg; z-index: 3; width: 214px; height: 214px; animation-delay: -5s; }
.tome-shelf img:nth-child(4) { --x: -16%; --r: 7deg; z-index: 2; animation-delay: -2s; }
.tome-shelf img:nth-child(5) { --x: 18%; --r: 14deg; z-index: 1; animation-delay: -4s; }

@keyframes tome-float {
  0%, 100% { transform: translate(var(--x), -50%) rotate(var(--r)); }
  50% { transform: translate(var(--x), -56%) rotate(var(--r)); }
}

.spell-filters { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-bottom: 1.4rem; }
.spell-filters button {
  padding: 0.5rem 0.95rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text-2);
  background: rgb(23 20 15 / 0.8);
  font: 600 0.84rem / 1 var(--sans);
  cursor: pointer;
  transition: color 160ms ease, border-color 160ms ease, background-color 160ms ease;
}
.spell-filters button:hover { border-color: var(--line-strong); color: var(--parchment); }
.spell-filters button[aria-pressed="true"] { border-color: var(--gold); color: #1d1307; background: linear-gradient(180deg, #f3d48f, #c99a4b); }

.spell-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1.5rem; align-items: start; }
.spell-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 0.7rem; margin: 0; padding: 0; list-style: none; }
.spell-grid li { transition: opacity 300ms ease, transform 300ms var(--ease); }
.spell-grid li.is-dimmed { opacity: 0.14; transform: scale(0.92); }
.spell-grid button { display: block; width: 100%; aspect-ratio: 1; padding: 0; border: 0; border-radius: 14px; background: var(--ink-2); cursor: pointer; overflow: hidden; box-shadow: 0 0 0 1px var(--line), 0 10px 22px -12px rgb(0 0 0 / 0.9); transition: transform 220ms var(--ease), box-shadow 220ms ease; }
.spell-grid button img { width: 100%; height: 100%; object-fit: cover; }
.spell-grid button:hover,
.spell-grid button:focus-visible,
.spell-grid button[aria-current="true"] { box-shadow: 0 0 0 2px var(--gold-hi), 0 0 26px rgb(246 217 148 / 0.35); transform: translateY(-3px) scale(1.04); }

.spell-detail {
  position: sticky;
  top: 90px;
  display: grid;
  gap: 0.75rem;
  padding: 1.6rem;
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  background: radial-gradient(120% 70% at 50% 0%, rgb(216 179 106 / 0.14), transparent 70%), linear-gradient(180deg, var(--ink-3), var(--ink-1));
  box-shadow: 0 30px 60px -30px rgb(0 0 0 / 0.9);
}
.spell-detail img { width: 112px; height: 112px; border-radius: 20px; box-shadow: 0 0 0 1px var(--line-strong), 0 14px 30px rgb(0 0 0 / 0.6), 0 0 40px rgb(238 98 30 / 0.2); }
.spell-detail h3 { font-size: 1.8rem; line-height: 1.1; }
.spell-detail p:last-child { color: var(--text-2); font-size: 0.97rem; }
.spell-detail .kicker { letter-spacing: 0.2em; }

.foe-rail { margin-inline: calc(-1 * var(--gutter)); overflow: hidden; mask: linear-gradient(90deg, transparent, #000 6%, #000 94%, transparent); }
.foe-track { display: flex; gap: 1rem; width: max-content; margin: 0; padding: 1rem var(--gutter) 2rem; list-style: none; animation: foe-march 70s linear infinite; }
.foe-rail:hover .foe-track,
.foe-rail:focus-within .foe-track { animation-play-state: paused; }

@keyframes foe-march { to { transform: translateX(-50%); } }

.foe { position: relative; width: 230px; aspect-ratio: 3 / 4; border-radius: 18px; overflow: hidden; box-shadow: 0 0 0 1px var(--line), 0 24px 44px -20px rgb(0 0 0 / 0.95); transition: transform 320ms var(--ease), box-shadow 320ms ease; }
.foe img { width: 100%; height: 100%; object-fit: cover; transition: transform 700ms var(--ease), filter 400ms ease; filter: saturate(0.9) brightness(0.9); }
.foe::after { content: ''; position: absolute; inset: 40% 0 0; background: linear-gradient(180deg, transparent, rgb(8 7 5 / 0.96)); }
.foe div { position: absolute; right: 1rem; bottom: 0.95rem; left: 1rem; z-index: 1; display: grid; gap: 0.2rem; }
.foe strong { font: 600 1.2rem / 1.15 var(--serif); }
.foe span { color: #e08a5c; font: 650 0.72rem / 1.2 var(--sans); letter-spacing: 0.16em; text-transform: uppercase; }
.foe:hover { box-shadow: 0 0 0 1px rgb(238 98 30 / 0.7), 0 30px 60px -20px rgb(238 98 30 / 0.45); transform: translateY(-6px); }
.foe:hover img { transform: scale(1.07); filter: none; }

.trade-grid { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 1rem; margin: 0; padding: 0; list-style: none; }
.trade-grid li { display: grid; justify-items: center; gap: 0.75rem; color: var(--text-2); font: 600 0.84rem / 1.2 var(--sans); text-align: center; }
.trade-grid img { width: 100%; max-width: 120px; height: auto; aspect-ratio: 1; border-radius: 20px; box-shadow: 0 0 0 1px var(--line), 0 16px 30px -14px rgb(0 0 0 / 0.9); transition: transform 300ms var(--ease), box-shadow 300ms ease; }
.trade-grid li:hover img { box-shadow: 0 0 0 1px var(--gold), 0 0 30px rgb(246 217 148 / 0.25); transform: translateY(-5px) rotate(-2deg); }

.empire-panel {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr);
  gap: clamp(2rem, 5vw, 4.5rem);
  padding: clamp(1.75rem, 5vw, 4rem);
  border: 1px solid var(--line);
  border-radius: 26px;
  background:
    linear-gradient(90deg, rgb(12 10 8 / 0.96) 30%, rgb(12 10 8 / 0.78)),
    url('./media/realm.jpg') center / cover;
}
.empire-panel .section-head { align-self: start; position: sticky; top: 110px; }
.empire-panel .section-head > p:not(.kicker) { font-size: 1.02rem; }
.empire-panel .button { margin-top: 0.6rem; }

.chapter-path { position: relative; display: grid; gap: 0.3rem; margin: 0; padding: 0; list-style: none; counter-reset: none; }
.chapter-path::before { content: ''; position: absolute; top: 22px; bottom: 22px; left: 21px; width: 2px; background: linear-gradient(180deg, var(--gold-hi), var(--gold-deep) 70%, transparent); opacity: 0.55; }
.chapter-path li { position: relative; display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 1.1rem; align-items: start; padding: 0.7rem 0.9rem 0.7rem 0; border-radius: 12px; transition: background-color 200ms ease; }
.chapter-path li:hover { background: rgb(216 179 106 / 0.06); }
.chapter-number { display: grid; width: 44px; height: 44px; place-items: center; border: 1px solid var(--gold); border-radius: 50%; color: var(--gold-hi); background: radial-gradient(circle at 35% 30%, #3b2c14, #120e08); font: 650 1.1rem / 1 var(--serif); box-shadow: 0 0 0 4px var(--ink-1), 0 0 18px rgb(246 217 148 / 0.2); }
.chapter-path strong { display: block; margin-top: 0.2rem; font: 600 1.2rem / 1.25 var(--serif); }
.chapter-path p { color: var(--text-2); font-size: 0.93rem; }

.community-panel {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 1.1rem;
  padding: clamp(3rem, 7vw, 5rem) var(--gutter);
  border: 1px solid rgb(129 140 248 / 0.28);
  border-radius: 28px;
  background: linear-gradient(180deg, #14131d, #0c0b10);
  overflow: hidden;
  text-align: center;
  isolation: isolate;
}
.community-glow { position: absolute; inset: -30% 10% auto; z-index: -1; height: 90%; background: radial-gradient(closest-side, rgb(88 101 242 / 0.35), transparent); filter: blur(20px); }
.community-mark { width: 104px; height: 104px; border-radius: 50%; box-shadow: 0 0 0 1px rgb(165 172 255 / 0.4), 0 0 50px rgb(88 101 242 / 0.5); }
.community-panel .kicker { color: #aab1ff; }
.community-panel .kicker-rule { background: linear-gradient(90deg, transparent, #aab1ff); }
.community-panel .kicker-rule:not(:first-child) { background: linear-gradient(90deg, #aab1ff, transparent); }
.community-panel h2 { font-size: clamp(2.1rem, 4.6vw, 3.4rem); }
.community-panel > p:not(.kicker) { max-width: 36rem; color: #c9cae0; }
.discord-button {
  min-height: 54px;
  margin-top: 0.6rem;
  padding: 0.95rem 1.7rem;
  border-color: rgb(165 172 255 / 0.5);
  color: #fff;
  background: linear-gradient(180deg, #7480ff, #5865f2 55%, #4450d4);
  font-size: 1.02rem;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.3), 0 14px 36px -10px rgb(88 101 242 / 0.8);
}
.discord-button:hover { transform: translateY(-2px); filter: brightness(1.08); box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.35), 0 20px 44px -10px rgb(88 101 242 / 0.95); }
.discord-button:focus-visible,
.discord-button:active { outline: 2px solid #c7ccff; outline-offset: 4px; }

.resource-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; }
.resource-card { position: relative; display: grid; align-content: start; gap: 0.5rem; padding: 1.5rem 1.4rem; border: 1px solid var(--line); border-radius: 16px; background: linear-gradient(180deg, var(--ink-2), var(--ink-1)); text-decoration: none; transition: transform 240ms var(--ease), border-color 240ms ease; }
.resource-card:hover { border-color: var(--line-strong); transform: translateY(-4px); }
.resource-card h3 { font-size: 1.3rem; }
.resource-card p { color: var(--text-3); font-size: 0.92rem; }
.resource-arrow { position: absolute; top: 1.2rem; right: 1.2rem; color: var(--gold); transition: transform 200ms var(--ease); }
.resource-card:hover .resource-arrow { transform: translate(2px, -2px); }

.footer { display: grid; justify-items: center; gap: 0.8rem; margin-top: clamp(5rem, 10vw, 8rem); padding: 3rem var(--gutter) 3.5rem; border-top: 1px solid var(--line); color: var(--text-3); font-size: 0.88rem; text-align: center; }
.footer-brand { display: inline-flex; align-items: center; gap: 0.7rem; color: var(--parchment); font: 650 1.15rem / 1 var(--serif); letter-spacing: 0.1em; text-transform: uppercase; }
.footer-brand img { width: 40px; height: 40px; border-radius: 50%; }
.footer-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 1.4rem; }
.footer-links a { color: var(--text-2); text-decoration: none; }
.footer-links a:hover { color: var(--gold-hi); }

@media (width <= 1080px) {
  .nav-links { display: none; }
  .nav-cta { margin-left: auto; }
  .trade-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .resource-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .spell-layout { grid-template-columns: minmax(0, 1fr); }
  .spell-detail { position: relative; top: 0; grid-template-columns: 96px minmax(0, 1fr); grid-template-rows: auto auto 1fr; column-gap: 1.2rem; order: -1; }
  .spell-detail img { grid-row: 1 / 4; width: 96px; height: 96px; }
}

@media (width <= 860px) {
  .pillar-grid,
  .spellbook-intro,
  .empire-panel { grid-template-columns: minmax(0, 1fr); }
  .empire-panel .section-head { position: static; }
  .class-stage { grid-template-columns: minmax(0, 1fr); grid-template-areas: "portrait" "copy" "picker"; text-align: center; }
  .class-copy { justify-items: center; }
  .class-signatures { justify-content: center; }
  .class-picker { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .tome-shelf { height: 230px; }
  .tome-shelf img { width: 140px; height: 140px; }
  .tome-shelf img:nth-child(3) { width: 160px; height: 160px; }
}

@media (width <= 620px) {
  .hero { padding-bottom: 230px; }
  .hero-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); bottom: 70px; }
  .hero-stats div:nth-child(3) { border-left: 0; }
  .hero-stats div:nth-child(n + 3) { border-top: 1px solid var(--line); }
  .hero-actions .button { width: 100%; }
  .nav-brand span { display: none; }
  .resource-grid { grid-template-columns: minmax(0, 1fr); }
  .spell-grid { grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); }
  .spell-detail { grid-template-columns: minmax(0, 1fr); text-align: left; }
  .spell-detail img { grid-row: auto; }
  .foe { width: 190px; }
  .kicker { gap: 0.6rem; font-size: 0.66rem; letter-spacing: 0.22em; }
  .kicker-rule { width: 22px; flex: none; }
  .class-picker { gap: 0.3rem; }
  .class-picker button { padding: 0.55rem 0.1rem; font-size: 0.68rem; letter-spacing: 0; }
  .class-picker img { width: 52px; height: 52px; }
  .trade-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.6rem; }
  .trade-grid li { grid-template-columns: 56px minmax(0, 1fr); align-items: center; justify-items: start; gap: 0.8rem; padding: 0.5rem; border: 1px solid var(--line); border-radius: 14px; background: rgb(23 20 15 / 0.7); text-align: left; }
  .trade-grid img { max-width: 56px; border-radius: 10px; }
  .discord-button { width: 100%; white-space: normal; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *,
  *::before,
  *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
  .foe-rail { overflow-x: auto; }
  html.js [data-reveal] { opacity: 1; transform: none; }
}
