:root {
  color-scheme: dark;
  --void: #090812;
  --obsidian: #111827;
  --indigo: #2b1d55;
  --cyan: #58f5ff;
  --gold: #f6d36b;
  --rose: #ff5f8f;
  --mint: #67f5b6;
  --ink: #1b2a44;
  --bone: #f4ead7;
  --muted: #aab7d4;
  --line: rgba(216, 246, 255, 0.22);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--void);
  color: var(--bone);
}

body {
  touch-action: manipulation;
}

button {
  font: inherit;
  letter-spacing: 0;
}

#gameRoot {
  position: fixed;
  inset: 0;
  min-width: 320px;
  min-height: 360px;
  overflow: hidden;
  background:
    radial-gradient(circle at 52% 42%, rgba(88, 245, 255, 0.13), transparent 34%),
    radial-gradient(circle at 60% 68%, rgba(255, 95, 143, 0.14), transparent 38%),
    linear-gradient(180deg, #101827 0%, #090812 62%, #05040b 100%);
}

#starfield {
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(circle, rgba(246, 211, 107, 0.7) 0 1px, transparent 1.5px),
    radial-gradient(circle, rgba(88, 245, 255, 0.65) 0 1px, transparent 1.5px),
    radial-gradient(circle, rgba(244, 234, 215, 0.45) 0 1px, transparent 1.5px);
  background-position: 13px 19px, 93px 64px, 51px 107px;
  background-size: 143px 151px, 197px 173px, 233px 211px;
  opacity: 0.42;
  animation: starDrift 18s linear infinite;
}

@keyframes starDrift {
  to { transform: translate3d(-44px, 38px, 0); }
}

#topHud {
  position: absolute;
  inset: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) auto max(12px, env(safe-area-inset-left));
  z-index: 4;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  pointer-events: none;
}

.brand,
.meter,
.combatant,
#resourceRow,
#rewardPanel,
.modal-frame {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(160deg, rgba(17, 24, 39, 0.84), rgba(43, 29, 85, 0.5));
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.32), inset 0 0 60px rgba(88, 245, 255, 0.04);
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
  padding: 10px 12px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, #fff 0 7%, transparent 8%),
    conic-gradient(from 20deg, var(--cyan), var(--gold), var(--rose), var(--mint), var(--cyan));
  border: 2px solid rgba(244, 234, 215, 0.35);
  box-shadow: 0 0 28px rgba(88, 245, 255, 0.5);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  color: white;
  font-size: clamp(19px, 2.6vh, 30px);
  line-height: 1;
  text-shadow: 0 0 20px rgba(88, 245, 255, 0.3);
}

#objectiveText {
  max-width: min(540px, 52vw);
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.25;
}

.run-meters {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  max-width: 50vw;
}

.meter {
  min-width: 100px;
  min-height: 52px;
  padding: 8px 10px;
}

.meter span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.meter b {
  display: block;
  margin-top: 3px;
  color: white;
  font-size: 20px;
}

#arena {
  position: absolute;
  inset: 118px 24px 214px;
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(210px, 0.84fr) minmax(280px, 1.25fr) minmax(210px, 0.84fr);
  align-items: center;
  gap: clamp(16px, 3vw, 42px);
}

.combatant {
  min-height: 280px;
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 12px;
  padding: 16px;
  position: relative;
  overflow: hidden;
}

.combatant::before {
  content: "";
  position: absolute;
  inset: -30%;
  opacity: 0.36;
  background: conic-gradient(from 60deg, transparent, rgba(88, 245, 255, 0.18), transparent, rgba(246, 211, 107, 0.12), transparent);
  animation: slowSpin 16s linear infinite;
}

.enemy::before {
  background: conic-gradient(from 130deg, transparent, rgba(255, 95, 143, 0.22), transparent, rgba(139, 92, 246, 0.16), transparent);
}

@keyframes slowSpin {
  to { transform: rotate(360deg); }
}

.portrait {
  position: relative;
  z-index: 1;
  min-height: 164px;
  display: grid;
  place-items: center;
}

.player-portrait .mask {
  width: 104px;
  height: 130px;
  border-radius: 52px 52px 34px 34px;
  background:
    radial-gradient(circle at 50% 35%, var(--cyan) 0 9%, transparent 10%),
    linear-gradient(145deg, #f4ead7 0 48%, #b8ccff 49% 100%);
  clip-path: polygon(50% 0, 82% 18%, 94% 55%, 70% 96%, 50% 100%, 30% 96%, 6% 55%, 18% 18%);
  box-shadow: 0 0 42px rgba(88, 245, 255, 0.35);
}

.player-portrait .orb {
  position: absolute;
  right: 20%;
  top: 18%;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, white, var(--cyan) 42%, var(--indigo));
  box-shadow: 0 0 34px rgba(88, 245, 255, 0.65);
}

.enemy-portrait .eye {
  width: 138px;
  height: 138px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, #fff 0 5%, var(--rose) 6% 18%, #230817 19% 42%, transparent 43%),
    conic-gradient(from 10deg, var(--rose), var(--indigo), var(--gold), var(--rose));
  box-shadow: 0 0 48px rgba(255, 95, 143, 0.45);
  border: 2px solid rgba(255, 95, 143, 0.44);
}

.horn {
  position: absolute;
  top: 18px;
  width: 54px;
  height: 88px;
  background: linear-gradient(180deg, var(--gold), var(--rose));
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
  opacity: 0.82;
}

.horn.left {
  left: 22%;
  transform: rotate(-26deg);
}

.horn.right {
  right: 22%;
  transform: rotate(26deg);
}

.combat-info {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 8px;
}

.combat-info h2 {
  color: white;
  font-size: 20px;
  text-align: center;
}

.bar {
  position: relative;
  height: 28px;
  overflow: hidden;
  border: 1px solid rgba(244, 234, 215, 0.16);
  border-radius: 999px;
  background: rgba(9, 8, 18, 0.66);
}

.bar i {
  position: absolute;
  inset: 0 auto 0 0;
  width: 100%;
  background: linear-gradient(90deg, var(--rose), #ff9f6b);
  transform-origin: left center;
}

.bar.ward i {
  width: 0%;
  background: linear-gradient(90deg, var(--cyan), var(--mint));
  box-shadow: 0 0 18px rgba(103, 245, 182, 0.45);
}

.enemy-health i {
  background: linear-gradient(90deg, var(--rose), var(--indigo));
  box-shadow: 0 0 18px rgba(255, 95, 143, 0.38);
}

.bar b {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: white;
  font-size: 13px;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.9);
}

.intent {
  min-height: 44px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid rgba(255, 95, 143, 0.36);
  border-radius: 8px;
  background: rgba(255, 95, 143, 0.14);
  box-shadow: inset 0 0 30px rgba(255, 95, 143, 0.16), 0 0 28px rgba(255, 95, 143, 0.12);
}

.intent.defend {
  border-color: rgba(88, 245, 255, 0.38);
  background: rgba(88, 245, 255, 0.12);
}

.intent.buff {
  border-color: rgba(246, 211, 107, 0.38);
  background: rgba(246, 211, 107, 0.12);
}

.intent span {
  font-size: 12px;
  color: var(--muted);
  font-weight: 900;
  text-transform: uppercase;
}

.intent b {
  color: white;
  font-size: 22px;
}

#spellLane {
  position: relative;
  min-height: 300px;
  display: grid;
  place-items: center;
}

.sigil-ring,
#spellBurst {
  position: absolute;
  border-radius: 50%;
}

.sigil-ring {
  border: 2px solid rgba(88, 245, 255, 0.2);
  box-shadow: 0 0 38px rgba(88, 245, 255, 0.08);
}

.ring-a {
  width: min(36vw, 360px);
  aspect-ratio: 1;
  animation: slowSpin 28s linear infinite;
}

.ring-b {
  width: min(27vw, 270px);
  aspect-ratio: 1;
  border-color: rgba(246, 211, 107, 0.24);
  animation: slowSpin 22s linear reverse infinite;
}

.ring-c {
  width: min(17vw, 180px);
  aspect-ratio: 1;
  border-color: rgba(255, 95, 143, 0.28);
  animation: slowSpin 12s linear infinite;
}

#spellBurst {
  width: 44px;
  height: 44px;
  background: radial-gradient(circle, white, var(--cyan) 35%, transparent 72%);
  opacity: 0;
  transform: scale(0.4);
}

#spellBurst.active {
  animation: spellBurst 0.42s ease-out;
}

@keyframes spellBurst {
  0% { opacity: 0; transform: scale(0.3); }
  35% { opacity: 1; transform: scale(1.8); }
  100% { opacity: 0; transform: scale(3.2); }
}

#resourceRow {
  position: absolute;
  left: 50%;
  bottom: 142px;
  z-index: 5;
  width: min(760px, calc(100vw - 28px));
  min-height: 64px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  transform: translateX(-50%);
}

.energy-orbs {
  display: flex;
  gap: 7px;
  justify-content: flex-start;
}

.orb-slot {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid rgba(88, 245, 255, 0.36);
  background: rgba(9, 8, 18, 0.6);
}

.orb-slot.full {
  background: radial-gradient(circle at 35% 28%, white, var(--cyan) 42%, var(--indigo));
  box-shadow: 0 0 22px rgba(88, 245, 255, 0.48);
}

#endTurnButton,
#modalPrimary {
  min-height: 46px;
  border: 1px solid rgba(244, 234, 215, 0.28);
  border-radius: 8px;
  color: #160d23;
  background: linear-gradient(135deg, var(--gold), var(--mint));
  box-shadow: 0 12px 36px rgba(246, 211, 107, 0.18);
  font-weight: 950;
  cursor: pointer;
}

#endTurnButton {
  min-width: 138px;
}

.deck-stats {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
}

.deck-stats b {
  color: white;
}

#hand {
  position: absolute;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 6;
  width: min(1180px, calc(100vw - 24px));
  min-height: 122px;
  display: grid;
  grid-template-columns: repeat(5, minmax(116px, 1fr));
  gap: 10px;
  transform: translateX(-50%);
}

.card {
  position: relative;
  min-height: 126px;
  padding: 10px;
  overflow: hidden;
  border: 2px solid rgba(246, 211, 107, 0.45);
  border-radius: 8px;
  color: var(--bone);
  background:
    radial-gradient(circle at 50% 28%, rgba(88, 245, 255, 0.18), transparent 36%),
    linear-gradient(160deg, #1b2a44, #111827 58%, #20143d);
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.34), inset 0 0 42px rgba(88, 245, 255, 0.06);
  cursor: pointer;
  text-align: left;
  transition: transform 0.16s ease, filter 0.16s ease, border-color 0.16s ease;
}

.card:hover,
.card:focus-visible {
  transform: translateY(-10px);
  border-color: var(--cyan);
  filter: brightness(1.12);
  outline: none;
}

.card.unplayable {
  cursor: not-allowed;
  filter: grayscale(0.7) brightness(0.62);
}

.card.playing {
  animation: cardPlay 0.34s ease-out;
}

@keyframes cardPlay {
  0% { transform: translateY(0) scale(1); }
  45% { transform: translateY(-38px) scale(1.08); }
  100% { transform: translateY(-10px) scale(1); }
}

.card .cost {
  position: absolute;
  left: 8px;
  top: 8px;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #07111d;
  background: radial-gradient(circle at 35% 25%, white, var(--cyan));
  font-weight: 950;
  box-shadow: 0 0 20px rgba(88, 245, 255, 0.4);
}

.card .glyph {
  width: 54px;
  height: 54px;
  margin: 12px auto 6px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #160d23;
  background: radial-gradient(circle, white, var(--gold) 55%, var(--rose));
  font-size: 28px;
  font-weight: 950;
  box-shadow: 0 0 30px rgba(246, 211, 107, 0.35);
}

.card.attack { border-color: rgba(255, 95, 143, 0.62); }
.card.attack::after { background: linear-gradient(90deg, transparent, var(--rose), transparent); }
.card.attack .glyph { background: radial-gradient(circle, white, var(--rose) 55%, #6f1e51); }
.card.skill { border-color: rgba(103, 245, 182, 0.58); }
.card.skill::after { background: linear-gradient(90deg, transparent, var(--mint), transparent); }
.card.skill .glyph { background: radial-gradient(circle, white, var(--mint) 55%, #0f766e); }
.card.power { border-color: rgba(88, 245, 255, 0.6); }
.card.power::after { background: linear-gradient(90deg, transparent, var(--cyan), transparent); }
.card.power .glyph { background: radial-gradient(circle, white, var(--cyan) 55%, var(--indigo)); }

.card::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 8px;
  height: 4px;
  border-radius: 999px;
  opacity: 0.86;
  box-shadow: 0 0 16px rgba(255, 255, 255, 0.2);
}

#playerPanel::after,
#enemyPanel::after {
  content: "";
  position: absolute;
  left: 14px;
  right: 14px;
  top: 14px;
  height: 5px;
  z-index: 2;
  border-radius: 999px;
}

#playerPanel::after {
  background: linear-gradient(90deg, transparent, var(--mint), var(--cyan), transparent);
}

#enemyPanel::after {
  background: linear-gradient(90deg, transparent, var(--rose), var(--gold), transparent);
}

.card h3 {
  margin: 0;
  color: white;
  font-size: 15px;
  text-align: center;
}

.card p {
  margin-top: 5px;
  color: #dce8ff;
  font-size: 12px;
  line-height: 1.25;
  text-align: center;
}

.card .tag {
  display: block;
  margin-top: 7px;
  color: var(--gold);
  font-size: 10px;
  font-weight: 900;
  text-align: center;
  text-transform: uppercase;
}

#rewardPanel {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 8;
  width: min(920px, calc(100vw - 28px));
  padding: 16px;
  transform: translate(-50%, -50%);
}

#rewardPanel header {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 12px;
  margin-bottom: 12px;
}

#rewardPanel header p {
  color: var(--cyan);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

#rewardPanel h2 {
  color: white;
  font-size: clamp(22px, 3.6vh, 34px);
}

.reward-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.reward-cards .card {
  min-height: 190px;
}

#modal {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 18px;
  background:
    radial-gradient(circle at 50% 52%, rgba(88, 245, 255, 0.12), transparent 36%),
    rgba(5, 4, 11, 0.58);
  backdrop-filter: blur(7px);
}

.modal-frame {
  width: min(540px, calc(100vw - 28px));
  padding: 24px;
  text-align: center;
}

.big-sigil {
  width: 86px;
  height: 86px;
  display: inline-grid;
  margin-bottom: 10px;
  border-radius: 50%;
  background:
    radial-gradient(circle, #fff 0 8%, transparent 9%),
    conic-gradient(from 30deg, var(--cyan), var(--gold), var(--rose), var(--mint), var(--cyan));
  box-shadow: 0 0 42px rgba(88, 245, 255, 0.42);
}

.modal-frame > p {
  color: var(--cyan);
  font-size: 12px;
  font-weight: 950;
  text-transform: uppercase;
}

.modal-frame h2 {
  margin-top: 4px;
  color: white;
  font-size: clamp(42px, 8vw, 68px);
  line-height: 0.92;
  text-shadow: 0 0 26px rgba(88, 245, 255, 0.3);
}

.quick-rules {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 18px;
}

.quick-rules span {
  min-height: 48px;
  display: grid;
  place-items: center;
  padding: 8px;
  border: 1px solid rgba(216, 246, 255, 0.16);
  border-radius: 8px;
  color: #dce8ff;
  background: rgba(9, 8, 18, 0.42);
  font-size: 12px;
  font-weight: 850;
}

#modalPrimary {
  width: 100%;
  min-height: 62px;
  margin-top: 18px;
  font-size: 18px;
}

.float-text {
  position: absolute;
  z-index: 9;
  left: 50%;
  top: 50%;
  color: white;
  font-weight: 950;
  font-size: 24px;
  text-shadow: 0 0 18px currentColor;
  transform: translate(-50%, -50%);
  animation: floatText 0.9s ease-out forwards;
  pointer-events: none;
}

@keyframes floatText {
  to {
    opacity: 0;
    transform: translate(-50%, -110%);
  }
}

.shake {
  animation: shake 0.18s linear;
}

@keyframes shake {
  0%, 100% { transform: translate3d(0, 0, 0); }
  25% { transform: translate3d(-5px, 3px, 0); }
  50% { transform: translate3d(5px, -2px, 0); }
  75% { transform: translate3d(-3px, -4px, 0); }
}

.hidden {
  display: none !important;
}

@media (max-width: 860px) {
  #topHud {
    display: grid;
    grid-template-columns: 1fr;
  }

  .brand {
    padding: 8px 10px;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
  }

  #objectiveText {
    max-width: calc(100vw - 86px);
    font-size: 12px;
  }

  .run-meters {
    max-width: 100%;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .meter {
    min-width: 0;
    min-height: 44px;
    padding: 7px 8px;
  }

  .meter b {
    font-size: 16px;
  }

  #arena {
    inset: 142px 10px 274px;
    grid-template-columns: 1fr 0.72fr 1fr;
    gap: 8px;
  }

  .combatant {
    min-height: 198px;
    padding: 10px;
  }

  .portrait {
    min-height: 106px;
  }

  .player-portrait .mask {
    width: 72px;
    height: 92px;
  }

  .player-portrait .orb {
    width: 27px;
    height: 27px;
    right: 12%;
  }

  .enemy-portrait .eye {
    width: 88px;
    height: 88px;
  }

  .horn {
    width: 36px;
    height: 58px;
    top: 12px;
  }

  .combat-info h2 {
    font-size: 13px;
  }

  .bar {
    height: 24px;
  }

  .intent {
    min-height: 38px;
    padding: 6px 8px;
  }

  .intent b {
    font-size: 18px;
  }

  #spellLane {
    min-height: 170px;
  }

  .ring-a { width: 31vw; }
  .ring-b { width: 23vw; }
  .ring-c { width: 15vw; }

  #resourceRow {
    bottom: 188px;
    min-height: 58px;
    grid-template-columns: 1fr auto;
  }

  .deck-stats {
    grid-column: 1 / -1;
    justify-content: center;
  }

  .orb-slot {
    width: 24px;
    height: 24px;
  }

  #endTurnButton {
    min-width: 112px;
    min-height: 44px;
  }

  #hand {
    min-height: 168px;
    grid-template-columns: repeat(5, minmax(64px, 1fr));
    gap: 6px;
    bottom: max(10px, env(safe-area-inset-bottom));
  }

  .card {
    min-height: 164px;
    padding: 7px 5px;
  }

  .card .cost {
    width: 24px;
    height: 24px;
    font-size: 13px;
  }

  .card .glyph {
    width: 42px;
    height: 42px;
    margin-top: 20px;
    font-size: 21px;
  }

  .card h3 {
    font-size: 11px;
  }

  .card p {
    font-size: 10px;
    line-height: 1.18;
  }

  .card .tag {
    font-size: 9px;
  }

  #rewardPanel {
    width: calc(100vw - 20px);
    max-height: calc(100vh - 24px);
    overflow: auto;
  }

  .reward-cards {
    grid-template-columns: 1fr;
  }

  .reward-cards .card {
    min-height: 104px;
  }

  .quick-rules {
    grid-template-columns: 1fr;
  }
}
