/* Campaign battle controls and the persistent progress earned in each run. */
#spellControls .spell-btn {
  --spell-accent: #dfbd80;
  min-width: 44px;
  min-height: 72px;
  padding: 5px 7px;
  gap: 2px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  box-shadow: none;
  color: #e9ddc9;
  text-shadow: 0 1px 2px #000, 0 0 5px #000, 0 0 9px #000a;
  touch-action: manipulation;
}

#spellControls .spell-frost { --spell-accent: #9ed5e4; }
#spellControls .spell-fire { --spell-accent: #e8ae6c; }
#spellControls .spell-light { --spell-accent: #e9d08c; }

#spellControls .spell-orbit,
#heroAbilityBtn .spell-orbit {
  position: relative;
  display: block;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  padding: 3px;
  border: 1px solid #c2a8755c;
  border-radius: 50%;
  background: transparent;
  box-shadow: 0 0 0 1px #05070a, 0 2px 6px #0008;
  pointer-events: none;
}

/* Mask only the cooldown ring; transparent art must reveal the button below. */
#spellControls .spell-orbit::before,
#heroAbilityBtn .spell-orbit::before {
  content: "";
  position: absolute;
  inset: 0;
  padding: inherit;
  border-radius: inherit;
  background: conic-gradient(var(--spell-accent, #c7b2ed) var(--spell-progress, 100%), #343039 0);
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  mask-composite: exclude;
}

.spell-orbit .spell-art {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background-color: transparent;
  background-image: url("assets4/ui/campaign-spells/spell-icons-v2-transparent.webp");
  background-repeat: no-repeat;
  background-size: 200% 200%;
  box-shadow: none;
  transition: filter 160ms ease;
}

.spell-orbit .spell-art--slow { background-position: 0% 0%; }
.spell-orbit .spell-art--damage { background-position: 100% 0%; }
.spell-orbit .spell-art--bomb { background-position: 0% 100%; }
.spell-orbit .spell-art--rift { background-position: 100% 100%; }

#spellControls .spell-caption {
  color: #d7cbb8;
  font-size: 9px;
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: .045em;
  opacity: 1;
}

#spellControls .spell-timer {
  color: #f1d5a0;
  font-size: 10px;
  line-height: 1.2;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  opacity: 1;
}

#spellControls .spell-key { top: 5px; left: 5px; color: #c5b69c; }
#spellControls .spell-btn:disabled { opacity: 1; }
#spellControls .spell-btn:disabled .spell-art,
#spellControls .spell-btn.on-cooldown .spell-art,
#heroAbilityBtn:disabled .spell-art { filter: saturate(.45) brightness(.65); }
#spellControls .spell-btn:disabled .spell-key,
#spellControls .spell-btn.on-cooldown .spell-key { opacity: .7; }

#spellControls .spell-btn:not(:disabled):hover,
#spellControls .spell-btn.active {
  border-color: transparent;
  box-shadow: none;
}

#spellControls .spell-btn:not(:disabled):hover .spell-orbit,
#spellControls .spell-btn.active .spell-orbit {
  border-color: var(--spell-accent);
  box-shadow: 0 0 0 1px #05070a, 0 0 10px var(--spell-accent);
}

#spellControls .spell-btn:focus-visible,
#heroCommandBtn:focus-visible,
#heroAbilityBtn:focus-visible,
.unit-info-panel.unit-dock .unit-info-card:focus-visible {
  outline: 2px solid #ffe0a5;
  outline-offset: 3px;
}

#heroCommandBtn,
#heroAbilityBtn {
  border-color: transparent;
  background: transparent;
  box-shadow: none;
  text-shadow: 0 1px 2px #000, 0 0 5px #000, 0 0 9px #000a;
  touch-action: manipulation;
}

#heroCommandBtn.active,
#heroAbilityBtn.ready {
  border-color: transparent;
  box-shadow: none;
}

#heroCommandBtn.active .hero-portrait {
  border-color: #ffe0a5;
  box-shadow: 0 0 0 1px #05070a, 0 0 12px #dfbd80a6;
}

#heroHud .hero-bar { box-shadow: 0 1px 3px #000c; }

#heroAbilityBtn {
  --spell-accent: #c7b2ed;
  min-width: 44px;
  min-height: 58px;
  padding-block: 4px;
  gap: 2px;
  border-radius: 10px;
  touch-action: manipulation;
}

#heroAbilityBtn .spell-orbit { width: 26px; height: 26px; padding: 2px; }
#heroAbilityBtn strong { color: #e7d8bf; font-size: 8px; line-height: 1.1; }
#heroAbilityBtn #heroAbilityCooldown { color: #ebcea1; font-size: 9px; line-height: 1.1; font-variant-numeric: tabular-nums; }
#heroAbilityBtn:disabled { opacity: 1; }
#heroAbilityBtn.ready .spell-orbit,
#heroAbilityBtn:not(:disabled):hover .spell-orbit { border-color: var(--spell-accent); box-shadow: 0 0 0 1px #05070a, 0 0 10px #b293d18c; }

/* Preserve the dock's position and dimensions while sharpening purchase states. */
.unit-info-panel.unit-dock {
  border-color: #a888554d;
  background: #100f12ed;
  box-shadow: inset 0 1px #ead2a512, 0 12px 28px #0006;
}

.unit-info-panel.unit-dock .unit-info-card {
  min-width: 44px;
  min-height: 44px;
  border-color: #af8d594a;
  border-radius: 9px;
  background: radial-gradient(ellipse at 50% 27%, #b5945425, transparent 65%), linear-gradient(160deg, #2a2420, #111115);
  box-shadow: inset 0 1px #ddbd8810;
  touch-action: manipulation;
}

.unit-info-panel.unit-dock .unit-info-card.active {
  border-color: #e4bc79;
  box-shadow: inset 0 0 0 1px #e9c18426, 0 0 12px #c49b452e;
}

.unit-info-panel.unit-dock .unit-sprite { filter: drop-shadow(0 3px 3px #000b); }
.unit-info-panel.unit-dock .unit-key-hint { color: #c9bba3; }
.unit-info-panel.unit-dock .unit-info-count { border-color: #bd9b63b0; background: #3a2c1df5; color: #fae4b9; }

.unit-info-panel.unit-dock .unit-cost-badge {
  bottom: 3px;
  min-width: 35px;
  padding: 1px 5px;
  border: 1px solid #c4a36b4f;
  border-radius: 4px;
  background: #0a090bea;
  color: #f3d295;
  font-size: 10px;
  line-height: 1.2;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.unit-info-panel.unit-dock .unit-cost-badge.crystal-cost { border-color: #ab99d24d; color: #d9c9f4; }
.unit-info-panel.unit-dock .unit-info-card.unit-unaffordable { border-color: #78695c61; }
.unit-info-panel.unit-dock .unit-info-card.unit-unaffordable .unit-sprite { filter: saturate(.4) brightness(.8) drop-shadow(0 3px 3px #000b); }
.unit-info-panel.unit-dock .unit-info-card.unit-unaffordable .unit-cost-badge { border-color: #bb796a70; color: #e8a99b; }
.unit-info-panel.unit-dock .unit-info-card.unit-locked { filter: none; }
.unit-info-panel.unit-dock .unit-info-card.unit-locked .unit-sprite { filter: saturate(.25) brightness(.6); }
.unit-info-panel.unit-dock .unit-info-card.unit-locked .unit-cost-badge { border-color: #80778e66; color: #bdb0cd; }
.unit-info-panel.unit-dock .unit-info-card.active.unit-unaffordable { border-color: #c5a06b; }
.unit-info-panel.unit-dock .unit-tooltip { border-color: #ae8b5559; background: #141215fa; color: #e5d9c8; }

/* Both purchase surfaces share the same compact before / after receipt. */
.upgrade-receipt {
  padding: 12px 15px;
  border: 1px solid #ceab6870;
  border-radius: 8px;
  background: linear-gradient(145deg, #30271ef7, #101217fa);
  box-shadow: inset 0 1px #ead2a51c, 0 8px 24px #0008;
  color: #ebdeca;
  font-family: Inter, Arial, sans-serif;
}

.upgrade-receipt[hidden],
.run-progress-card[hidden] { display: none !important; }

#canvasWrap > #upgradeReceipt {
  position: absolute;
  z-index: 25;
  top: 18%;
  left: 50%;
  width: min(300px, calc(100% - 32px));
  transform: translateX(-50%);
  opacity: 0;
  pointer-events: none;
}

#canvasWrap > #upgradeReceipt.is-visible { opacity: 1; animation: campaign-receipt-in 180ms ease-out; }
.upgrade-receipt .upgrade-receipt-title { margin: 0 0 8px; color: #f0ce91; font: 600 15px/1.35 Georgia, serif; }
.upgrade-receipt .upgrade-receipt-rows { display: grid; gap: 5px; }
.upgrade-receipt .upgrade-receipt-rows > div { display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px; font-size: 12px; line-height: 1.45; }
.upgrade-receipt .upgrade-receipt-rows > div > span:first-child { margin-right: auto; color: #c3b6a3; }
.upgrade-receipt del { color: #b5a896; text-decoration-color: #9c8973; font-variant-numeric: tabular-nums; }
.upgrade-receipt :is(strong, b) { color: #e3d6a8; font-weight: 700; font-variant-numeric: tabular-nums; }
.upgrade-receipt .is-tradeoff b { color: #efaa91; }

.campaign-mastery-overlay #masteryUpgradeReceipt {
  position: static;
  width: 100%;
  max-width: none;
  margin: 16px 0;
  padding: 14px 17px;
  transform: none;
  box-shadow: inset 0 1px #ead2a51c;
}

.campaign-mastery-overlay #masteryUpgradeReceipt.is-visible { animation: campaign-mastery-receipt-in 160ms ease-out; }
.campaign-mastery-overlay #masteryUpgradeReceipt .upgrade-receipt-rows { max-width: 540px; }

/* The run's combat score and its permanent rewards remain distinct and readable. */
#gameOverOverlay .gameover-card {
  width: min(100%, 680px);
  max-height: calc(100vh - 48px);
  max-height: calc(100dvh - 48px);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-color: #8c704b #111014;
}

#gameOverOverlay .gameover-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 16px; }
#gameOverOverlay .gameover-stat { padding: 10px 8px; border-radius: 8px; }
#gameOverOverlay .gameover-stat span { margin-bottom: 4px; font-size: 10px; }
#gameOverOverlay .gameover-stat strong { font-size: 21px; font-variant-numeric: tabular-nums; }

#gameOverOverlay .run-progress-card {
  margin: 0 0 20px;
  padding: 17px;
  border: 1px solid #c19a5b59;
  border-radius: 9px;
  background: radial-gradient(ellipse at 0 0, #a37e3020, transparent 70%), #101015cf;
  box-shadow: inset 0 1px #f1d69e10;
  text-align: left;
}

#gameOverOverlay .run-progress-head { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 5px 12px; margin-bottom: 14px; }
#gameOverOverlay .run-progress-head h2 { margin: 0; color: #f0d6a9; font: 600 20px/1.3 Georgia, serif; }
#gameOverOverlay .run-progress-head :is(span, small, label) { color: #bfb09a; font-size: 10px; line-height: 1.5; letter-spacing: .045em; }
#gameOverOverlay .run-progress-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 9px; }
#gameOverOverlay .run-progress-grid > div { min-width: 0; }
#gameOverOverlay .run-progress-grid :is(span, label, small) { display: block; margin-bottom: 4px; color: #c1b5a1; font-size: 10px; line-height: 1.4; }
#gameOverOverlay .run-progress-grid strong { display: block; color: #efe0c5; font: 600 23px/1.3 Georgia, serif; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
#gameOverOverlay .run-progress-grid #runHeroXpEarned { color: #d1c1ee; }
#gameOverOverlay .run-progress-grid #runCrystalWallet { color: #d5c7f0; }
#gameOverOverlay .run-hero-track { margin-top: 14px; }
#gameOverOverlay .run-hero-track progress { appearance: none; display: block; width: 100%; height: 7px; overflow: hidden; border: 0; border-radius: 99px; background: #29242e; accent-color: #b199cb; }
#gameOverOverlay .run-hero-track progress::-webkit-progress-bar { border-radius: 99px; background: #29242e; }
#gameOverOverlay .run-hero-track progress::-webkit-progress-value { border-radius: 99px; background: linear-gradient(90deg, #776290, #ceb3e4); }
#gameOverOverlay .run-hero-track progress::-moz-progress-bar { border-radius: 99px; background: linear-gradient(90deg, #776290, #ceb3e4); }
#gameOverOverlay #runHeroProgressLabel { display: block; margin-top: 6px; color: #bdb0cd; font-size: 10px; line-height: 1.5; font-variant-numeric: tabular-nums; }

#gameOverOverlay .run-mastery-next {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 15px;
  padding-top: 13px;
  border-top: 1px solid #b8975c2e;
}

#gameOverOverlay #runMasteryHint { margin: 0; color: #d0c2ab; font-size: 11px; line-height: 1.5; }
#gameOverOverlay #openMasteryFromGameOverBtn { flex: 0 0 auto; min-height: 44px; padding: 10px 13px; border: 1px solid #cba26399; border-radius: 5px; background: linear-gradient(180deg, #d6b17b, #b28650); color: #231a10; font-size: 11px; font-weight: 700; line-height: 1.3; box-shadow: inset 0 1px #f8e1b746; cursor: pointer; touch-action: manipulation; }
#gameOverOverlay #openMasteryFromGameOverBtn:hover { filter: brightness(1.08); }
#gameOverOverlay #openMasteryFromGameOverBtn:focus-visible { outline: 2px solid #f4d6a1; outline-offset: 3px; }
#gameOverOverlay .gameover-actions .btn { min-height: 44px; touch-action: manipulation; }

/* Optional invitation, placed after the replay controls rather than blocking them. */
#gameOverOverlay .run-referral-card { margin-top: 20px; padding-top: 17px; border-top: 1px solid #c19a5b40; text-align: left; }
#gameOverOverlay .run-referral-card h2 { margin: 0 0 7px; color: #dfc49b; font: 600 18px/1.3 Georgia, serif; }
#gameOverOverlay #runReferralMessage { margin: 0 0 12px; color: #c1b8a8; font: 12px/1.6 Inter, Arial, sans-serif; }
#gameOverOverlay .run-referral-link label { display: block; margin-bottom: 6px; color: #c0ad8a; font-size: 10px; }
#gameOverOverlay .run-referral-controls { display: flex; gap: 8px; }
#gameOverOverlay #runReferralInput { flex: 1; min-width: 0; min-height: 44px; padding: 10px; border: 1px solid #9e845c66; border-radius: 6px; background: #0d1017; color: #e4d5bd; font: 12px/1.4 Inter, Arial, sans-serif; user-select: all; }
#gameOverOverlay .run-referral-card .btn { min-height: 44px; width: auto; padding: 9px 14px; font-size: 11px; text-decoration: none; touch-action: manipulation; }
#gameOverOverlay .run-referral-card [hidden] { display: none !important; }
#gameOverOverlay .run-referral-card :is(input, button, a):focus-visible { outline: 2px solid #eac795; outline-offset: 3px; }
#gameOverOverlay .run-referral-status { min-height: 1.4em; margin: 7px 0 0; color: #b4c7bc; font: 11px/1.5 Inter, Arial, sans-serif; }
#gameOverOverlay .run-referral-card[data-state="error"] .run-referral-status { color: #e4ad99; }
@media (max-width: 420px) {
  #gameOverOverlay .run-referral-controls { flex-direction: column; }
  #gameOverOverlay .run-referral-controls .btn { width: 100%; }
}

@keyframes campaign-receipt-in { from { opacity: 0; transform: translate(-50%, 5px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes campaign-mastery-receipt-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 700px) {
  #spellControls .spell-btn { min-height: 62px; padding: 4px; gap: 1px; aspect-ratio: auto; border-radius: 9px; }
  #spellControls .spell-orbit { width: 30px; height: 30px; padding: 2px; }
  #spellControls .spell-caption { font-size: 8px; }
  #spellControls .spell-timer { font-size: 9px; }
  #heroAbilityBtn { min-height: 52px; padding: 3px; }
  #heroAbilityBtn .spell-orbit { width: 22px; height: 22px; }
  #heroAbilityBtn strong { font-size: 7px; }
  #heroAbilityBtn #heroAbilityCooldown { font-size: 8px; }
  #canvasWrap > #upgradeReceipt { top: 25%; padding: 10px 12px; }
}

@media (max-width: 520px) {
  #gameOverOverlay { padding: 10px; }
  #gameOverOverlay .gameover-card { max-height: calc(100vh - 20px); max-height: calc(100dvh - 20px); padding: 22px 18px; border-radius: 14px; }
  #gameOverOverlay .gameover-card h1 { font-size: 40px; }
  #gameOverOverlay .gameover-subtitle,
  #gameOverOverlay .gameover-quote { font-size: 12px; line-height: 1.5; }
  #gameOverOverlay .gameover-stats { gap: 6px; }
  #gameOverOverlay .gameover-stat { padding: 9px 5px; }
  #gameOverOverlay .gameover-stat span { font-size: 9px; letter-spacing: .04em; }
  #gameOverOverlay .gameover-stat strong { font-size: 19px; }
  #gameOverOverlay .run-progress-card { padding: 14px; }
  #gameOverOverlay .run-progress-head h2 { font-size: 19px; }
  #gameOverOverlay .run-progress-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  #gameOverOverlay .run-progress-grid strong { font-size: 22px; }
  #gameOverOverlay .run-mastery-next { flex-direction: column; align-items: stretch; gap: 9px; }
  #gameOverOverlay #openMasteryFromGameOverBtn { width: 100%; }
  .campaign-mastery-overlay #masteryUpgradeReceipt { padding: 12px; }
}

@media (max-width: 380px) {
  #spellControls .spell-btn { min-height: 48px; }
  #spellControls .spell-caption { display: none; }
  #spellControls .spell-orbit { width: 28px; height: 28px; }
}

@media (max-width: 900px) and (max-height: 460px) {
  #spellControls .spell-btn { min-height: 44px; padding: 3px; }
  #spellControls .spell-orbit { width: 26px; height: 26px; padding: 2px; }
  #spellControls .spell-caption { display: none; }
  #spellControls .spell-timer { font-size: 9px; }
  #canvasWrap > #upgradeReceipt { top: 19%; }
  #gameOverOverlay .gameover-card { padding: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  #spellControls .spell-btn,
  .spell-orbit .spell-art,
  .unit-info-panel.unit-dock .unit-info-card,
  #gameOverOverlay .gameover-card,
  #canvasWrap > #upgradeReceipt.is-visible,
  .campaign-mastery-overlay #masteryUpgradeReceipt.is-visible { animation: none; transition: none; }
}
