/*
 * Goober Cards: animated tabletop presentation layer.
 * Gameplay remains in index.html; this file owns the battle-first visual system.
 */

:root {
  --arena-ink: #24180f;
  --arena-cream: #fff3c7;
  --arena-gold: #ffc83d;
  --arena-gold-deep: #d77a12;
  --arena-blue: #52c7ff;
  --arena-blue-deep: #1368a5;
  --arena-red: #ff6a54;
  --arena-green: #79e27e;
  --arena-wood: #7a351c;
  --arena-wood-dark: #35180f;
  --arena-felt: #123a3c;
  --arena-felt-light: #1a5551;
  --arena-shadow: rgba(20, 8, 3, 0.45);
}

body {
  background:
    radial-gradient(circle at 50% -14rem, rgba(255, 202, 62, 0.42), transparent 34rem),
    radial-gradient(circle at 12% 28rem, rgba(82, 199, 255, 0.26), transparent 29rem),
    linear-gradient(180deg, #fff9df 0%, #f9dfa2 48rem, #f4c873 100%);
}

body.dark-game {
  --panel: #1e2830;
  --text: #fff3c7;
  --muted: #d7cfbb;
  --soft: #303b43;
  background:
    radial-gradient(circle at 50% -14rem, rgba(255, 196, 61, 0.2), transparent 33rem),
    radial-gradient(circle at 12% 28rem, rgba(51, 151, 196, 0.2), transparent 29rem),
    linear-gradient(180deg, #17202b 0%, #10161f 100%);
}

body.dark-game header,
body.dark-game footer {
  border-color: #090d12;
}

header {
  max-width: 1440px;
  padding-top: 18px;
  padding-bottom: 10px;
}

.arena-page {
  max-width: 1440px;
  padding: 8px 18px 56px;
}

.arena-page .hero {
  max-width: none;
  padding: 4px 2px 8px;
  display: flex;
  align-items: end;
  justify-content: space-between;
}

.arena-page .hero h1 {
  color: #352012;
  font-size: clamp(2.65rem, 5.5vw, 5.2rem);
  line-height: 0.86;
  letter-spacing: -0.075em;
  text-shadow: 0 3px 0 #fff4c7, 0 7px 0 rgba(53, 32, 18, 0.12);
}

body.dark-game .arena-page .hero h1 {
  color: #fff3c7;
  text-shadow: 0 4px 0 #6e3a18, 0 9px 22px #000;
}

.arena-page .hero p {
  max-width: 680px;
  color: #62462e;
  font-size: clamp(0.96rem, 1.4vw, 1.08rem);
}

body.dark-game .arena-page .hero p {
  color: #dfd1b7;
}

.arena-page button {
  transition: transform 160ms ease, box-shadow 160ms ease, filter 160ms ease, background 160ms ease;
}

.arena-page button:not(:disabled):hover {
  transform: translateY(-2px);
  filter: brightness(1.05) saturate(1.05);
}

.arena-page button:not(:disabled):active {
  transform: translateY(1px) scale(0.98);
}

.topbar {
  position: sticky;
  top: 8px;
  z-index: 40;
  grid-template-columns: minmax(210px, 1fr) auto auto;
  gap: 10px;
  margin: 8px 0 14px;
  padding: 9px 11px;
  border: 3px solid #2b190e;
  border-radius: 22px;
  background:
    linear-gradient(135deg, rgba(28, 48, 58, 0.97), rgba(16, 29, 38, 0.97));
  box-shadow: 0 10px 24px rgba(31, 16, 7, 0.28), 0 3px 0 #0c1116;
  backdrop-filter: blur(12px);
}

.topbar .chip,
.topbar .ready {
  border: 2px solid rgba(255, 240, 188, 0.7);
  background: rgba(255, 248, 218, 0.94);
  color: #24180f;
  box-shadow: 0 2px 0 #080d11;
  font-size: 0.85rem;
}

.topbar .top-actions button {
  border-width: 2px;
  box-shadow: 0 3px 0 #080d11;
}

.topbar #attackBtn {
  display: none;
}

.board {
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: minmax(245px, 1fr) minmax(220px, 300px) minmax(245px, 1fr);
  grid-template-areas: "p2 mid p1";
  gap: clamp(8px, 1.5vw, 20px);
  min-height: 650px;
  padding: clamp(14px, 2.2vw, 28px);
  overflow: hidden;
  border: 10px solid var(--arena-wood-dark);
  border-radius: 52px;
  background:
    radial-gradient(circle at 50% 48%, rgba(255, 215, 90, 0.16) 0 8%, transparent 31%),
    radial-gradient(circle at 50% 50%, transparent 0 30%, rgba(4, 24, 25, 0.16) 60%, rgba(3, 15, 17, 0.48) 100%),
    repeating-linear-gradient(123deg, rgba(255, 255, 255, 0.018) 0 3px, transparent 3px 11px),
    linear-gradient(145deg, var(--arena-felt-light), var(--arena-felt));
  box-shadow:
    inset 0 0 0 5px #b55d28,
    inset 0 0 0 9px #e3943b,
    inset 0 0 65px rgba(0, 0, 0, 0.45),
    0 22px 0 #2b130c,
    0 34px 52px var(--arena-shadow);
  perspective: 1400px;
  zoom: 1 !important;
}

.board::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 8% 31%;
  border: 2px solid rgba(255, 227, 146, 0.16);
  border-radius: 50%;
  background:
    radial-gradient(circle, transparent 0 29%, rgba(255, 222, 117, 0.08) 30% 31%, transparent 32% 55%, rgba(255, 222, 117, 0.08) 56% 57%, transparent 58%),
    conic-gradient(from 20deg, transparent, rgba(255, 220, 115, 0.08), transparent 19%, transparent 81%, rgba(255, 220, 115, 0.08), transparent);
  box-shadow: inset 0 0 50px rgba(251, 212, 105, 0.06);
}

.board::after {
  content: "";
  position: absolute;
  z-index: 0;
  inset: 0;
  pointer-events: none;
  border-radius: 39px;
  background:
    linear-gradient(90deg, rgba(65, 174, 224, 0.08), transparent 29%, transparent 71%, rgba(255, 122, 70, 0.08));
  mix-blend-mode: screen;
}

.panel,
.mid {
  position: relative;
  z-index: 2;
}

.panel {
  align-content: center;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 10px;
  min-width: 0;
  padding: 4px;
  border: 0;
  border-radius: 28px;
  background: transparent;
  box-shadow: none;
}

.p1::before,
.p2::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 7% -7% 16%;
  border-radius: 50%;
  filter: blur(25px);
  opacity: 0.42;
}

.p1::before {
  background: radial-gradient(circle, rgba(255, 130, 72, 0.55), transparent 68%);
}

.p2::before {
  background: radial-gradient(circle, rgba(75, 190, 255, 0.55), transparent 68%);
}

.panel-head {
  justify-content: center;
  gap: 6px;
}

.zone-title,
.panel-head .chip,
.panel-head .ready {
  border: 2px solid rgba(255, 240, 198, 0.78);
  border-radius: 999px;
  background: rgba(15, 30, 35, 0.78);
  color: #fff5d7;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.42);
  padding: 5px 9px;
  font-size: 0.78rem;
  backdrop-filter: blur(8px);
}

.zone-title {
  font-size: 0.92rem;
}

.panel-head .ready.on {
  background: var(--arena-green);
  color: #17331c;
  border-color: #17331c;
}

.slot {
  position: relative;
  align-self: center;
  min-height: 430px;
  padding: 12px;
  border: 0;
  background: transparent;
  perspective: 950px;
}

.slot::before {
  content: "";
  position: absolute;
  inset: 12% 6% 4%;
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(3, 10, 13, 0.54), transparent 67%);
  transform: translateY(38%);
  filter: blur(8px);
  pointer-events: none;
}

.card {
  --card-accent: var(--arena-gold);
  --card-accent-dark: var(--arena-gold-deep);
  position: relative;
  width: min(100%, 310px);
  overflow: visible;
  border: 5px solid #3a210f;
  border-radius: 30px;
  color: #26180f;
  background:
    linear-gradient(150deg, #fff8d8 0%, #f4d789 50%, #c67a28 100%);
  box-shadow:
    0 0 0 3px var(--card-accent),
    0 0 0 7px #6d3517,
    0 20px 28px rgba(5, 12, 14, 0.55),
    inset 0 2px 0 rgba(255, 255, 255, 0.7);
  transform-style: preserve-3d;
  transition: transform 180ms ease, filter 180ms ease, box-shadow 180ms ease;
  will-change: transform;
}

.card.rarity-mythic-chaos-loaf {
  --card-accent: #f06dff;
  --card-accent-dark: #8738a3;
}

.card.rarity-legendary-loaf {
  --card-accent: #ffba26;
  --card-accent-dark: #c66812;
}

.card.rarity-ultra-goober {
  --card-accent: #5edcff;
  --card-accent-dark: #197ca6;
}

.card.rarity-rare-loaf {
  --card-accent: #82e987;
  --card-accent-dark: #338b47;
}

.card::before {
  content: "";
  position: absolute;
  z-index: -2;
  inset: -15px;
  border-radius: 38px;
  background: radial-gradient(circle at 50% 38%, color-mix(in srgb, var(--card-accent) 64%, transparent), transparent 67%);
  opacity: 0.34;
  filter: blur(14px);
  animation: auraPulse 3.4s ease-in-out infinite;
}

.card::after {
  content: "";
  position: absolute;
  z-index: 8;
  inset: 0;
  pointer-events: none;
  border-radius: 23px;
  background: linear-gradient(120deg, transparent 12%, rgba(255, 255, 255, 0.34) 23%, transparent 35%);
  background-size: 240% 100%;
  opacity: 0.45;
  animation: cardShimmer 5s ease-in-out infinite;
}

.p1 .card {
  rotate: 1deg;
}

.p2 .card {
  rotate: -1deg;
}

.card:hover,
.card:focus-within {
  filter: brightness(1.05) saturate(1.06);
  box-shadow:
    0 0 0 3px var(--card-accent),
    0 0 0 7px #6d3517,
    0 27px 34px rgba(5, 12, 14, 0.64),
    0 0 32px color-mix(in srgb, var(--card-accent) 45%, transparent);
}

.card.win {
  outline: 0;
  box-shadow:
    0 0 0 4px #9cff82,
    0 0 40px rgba(132, 255, 117, 0.85),
    0 23px 34px rgba(5, 12, 14, 0.62);
}

.card.lose {
  opacity: 1;
  filter: saturate(0.72) brightness(0.82);
}

.card-topline {
  position: relative;
  z-index: 4;
  display: grid;
  grid-template-columns: 40px 1fr 44px;
  align-items: center;
  gap: 5px;
  min-height: 58px;
  margin: -9px 8px -4px;
  transform: translateZ(26px);
}

.role-crest,
.momentum-gem {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border: 3px solid #2f190d;
  box-shadow: 0 3px 0 #2f190d, inset 0 2px 0 rgba(255, 255, 255, 0.75);
}

.role-crest {
  border-radius: 50%;
  background: linear-gradient(145deg, #fff3a5, var(--card-accent));
  font-size: 1.12rem;
}

.momentum-gem {
  position: relative;
  border-radius: 50% 50% 50% 10%;
  color: #fff;
  background: linear-gradient(145deg, #77e6ff, #2369e2 64%, #173f9d);
  font-size: 0.76rem;
  rotate: -45deg;
}

.momentum-gem b {
  rotate: 45deg;
}

.card-title {
  overflow: hidden;
  padding: 8px 8px 7px;
  border: 3px solid #3a210f;
  border-radius: 14px;
  background: linear-gradient(#fff4bf, #eab95d);
  box-shadow: 0 3px 0 #3a210f, inset 0 2px 0 rgba(255, 255, 255, 0.78);
  text-align: center;
}

.card-title h3 {
  overflow: hidden;
  margin: 0;
  font-size: clamp(0.98rem, 1.4vw, 1.2rem);
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-title small {
  display: block;
  overflow: hidden;
  margin-top: 2px;
  color: #664222;
  font-size: 0.63rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card .art {
  position: relative;
  z-index: 2;
  display: grid;
  min-height: 0;
  aspect-ratio: 1.1 / 0.82;
  margin: 0 10px;
  padding: 0;
  overflow: hidden;
  border: 4px solid #3a210f;
  border-radius: 19px;
  background:
    radial-gradient(circle at 50% 35%, #fffdf1, #e7c97d 70%, #b66d25);
  box-shadow:
    inset 0 0 24px rgba(74, 35, 11, 0.25),
    0 4px 0 #7d411c;
  transform: translateZ(16px);
}

.card .art img {
  width: 100%;
  height: 100%;
  min-height: 190px;
  object-fit: contain;
  padding: 7px;
  filter: drop-shadow(0 9px 7px rgba(35, 18, 7, 0.26));
  animation: portraitFloat 4.5s ease-in-out infinite;
}

.rarity-ribbon,
.action-rune {
  position: absolute;
  z-index: 3;
  border: 2px solid #2f190d;
  background: rgba(255, 247, 207, 0.94);
  color: #29170d;
  box-shadow: 0 2px 0 #2f190d;
  font-size: 0.64rem;
  font-weight: 900;
}

.rarity-ribbon {
  left: 7px;
  bottom: 7px;
  max-width: calc(100% - 14px);
  padding: 4px 7px;
  overflow: hidden;
  border-radius: 999px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.action-rune {
  top: 7px;
  right: 7px;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 1rem;
}

.action-rune[data-action="defend"] {
  background: #aee9ff;
}

.action-rune[data-action="charge"] {
  background: #fff08b;
  animation: chargedRune 1.2s ease-in-out infinite;
}

.action-rune[data-action="trick"] {
  background: #f4b9ff;
}

.action-rune[data-action="swap"] {
  background: #b7f0c2;
}

.card .info {
  position: relative;
  z-index: 4;
  gap: 7px;
  padding: 8px 10px 11px;
  transform: translateZ(20px);
}

.ability-copy {
  min-height: 43px;
  padding: 7px 9px;
  border: 2px solid #70411f;
  border-radius: 12px;
  background: rgba(255, 246, 207, 0.82);
  text-align: center;
  font-size: 0.7rem;
  font-weight: 900;
  line-height: 1.15;
}

.ability-copy strong {
  display: block;
  color: #8a4117;
  font-size: 0.76rem;
}

.card-meter {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 6px;
  color: #4b2c18;
  font-size: 0.67rem;
  font-weight: 900;
}

.hpbar {
  height: 12px;
  border: 2px solid #351c10;
  border-radius: 999px;
  background: #55251b;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.42);
}

.hpbar span {
  border-right: 2px solid #351c10;
  background: linear-gradient(90deg, #50d36c, #b8ea5c 58%, #ffd45a);
  transition: width 520ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.stat-orbs {
  display: grid;
  grid-template-columns: 50px 1fr 50px;
  align-items: center;
  gap: 6px;
  margin-top: 1px;
}

.stat-orb,
.roll-orb {
  display: grid;
  place-items: center;
  min-height: 38px;
  border: 3px solid #351c10;
  box-shadow: 0 3px 0 #351c10, inset 0 2px 0 rgba(255, 255, 255, 0.7);
  font-weight: 900;
}

.stat-orb {
  border-radius: 50%;
  color: #fff;
  font-size: 0.78rem;
}

.stat-orb.attack {
  background: linear-gradient(145deg, #ffca6d, #eb521f);
}

.stat-orb.health {
  background: linear-gradient(145deg, #ff8b88, #c91f34);
}

.roll-orb {
  grid-template-columns: auto auto;
  justify-content: center;
  gap: 4px;
  min-width: 0;
  padding: 5px 7px;
  border-radius: 999px;
  background: linear-gradient(180deg, #fff9d9, #e9c05d);
  color: #3d250f;
  font-size: 0.68rem;
  white-space: nowrap;
}

.detailsBtn {
  position: absolute;
  right: 14px;
  bottom: -18px;
  z-index: 12;
  min-height: 36px !important;
  padding: 5px 9px !important;
  border: 3px solid #311b0f;
  background: #a6e4ff;
  box-shadow: 0 3px 0 #311b0f;
  font-size: 0.7rem;
}

.hand-title {
  color: rgba(255, 248, 218, 0.86);
  text-align: center;
  text-shadow: 0 2px 2px rgba(0, 0, 0, 0.7);
  letter-spacing: 0.08em;
}

.hand {
  display: flex;
  align-items: end;
  justify-content: center;
  min-height: 105px;
  padding: 10px 0 0;
  gap: 0;
  overflow: visible;
}

.mini {
  --fan-angle: 0deg;
  position: relative;
  display: grid;
  grid-template-columns: 1fr;
  width: clamp(82px, 8vw, 112px);
  min-height: 94px;
  margin-left: -14px;
  padding: 5px;
  overflow: hidden;
  border: 3px solid #351c10;
  border-radius: 15px;
  background: linear-gradient(145deg, #fff6cf, #d99b45);
  box-shadow: 0 5px 0 #351c10, 0 11px 14px rgba(0, 0, 0, 0.34);
  color: #2c190d;
  text-align: center;
  transform: rotate(var(--fan-angle)) translateY(var(--fan-lift, 0));
  transform-origin: 50% 120%;
  transition: transform 180ms ease, filter 180ms ease, box-shadow 180ms ease;
}

.mini:first-child {
  margin-left: 0;
}

.mini:disabled {
  cursor: default;
  opacity: 1;
}

.mini:not(:disabled):hover,
.mini:not(:disabled):focus-visible {
  z-index: 10;
  transform: rotate(0deg) translateY(-14px) scale(1.06);
  box-shadow: 0 7px 0 #351c10, 0 19px 22px rgba(0, 0, 0, 0.4);
}

.mini.active {
  z-index: 4;
  background: linear-gradient(145deg, #fff4a5, #f1ad2f);
  box-shadow: 0 0 0 3px #fff06f, 0 6px 0 #351c10, 0 0 23px rgba(255, 216, 63, 0.72);
  transform: rotate(var(--fan-angle)) translateY(-8px);
}

.mini.switchable:not(.active) {
  outline: 0;
}

.mini.switchable:not(.active)::after {
  content: "SWAP";
  position: absolute;
  right: 4px;
  top: 4px;
  padding: 2px 4px;
  border: 1px solid #17371d;
  border-radius: 999px;
  background: #89ea8b;
  font-size: 0.48rem;
  font-weight: 900;
}

.mini.ko {
  filter: grayscale(1) brightness(0.63);
}

.mini img {
  width: 100%;
  height: 54px;
  padding: 2px;
  object-fit: contain;
  border: 2px solid #3b210f;
  border-radius: 10px;
  background: #fff9df;
}

.mini strong {
  display: block;
  overflow: hidden;
  margin-top: 3px;
  font-size: 0.64rem;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini small {
  display: block;
  overflow: hidden;
  color: #714626;
  font-size: 0.54rem;
  line-height: 1.05;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini-hp {
  position: absolute;
  left: 4px;
  top: 43px;
  display: grid;
  place-items: center;
  min-width: 26px;
  height: 26px;
  border: 2px solid #391c10;
  border-radius: 50%;
  background: #d92b3f;
  color: white;
  box-shadow: 0 2px 0 #391c10;
  font-size: 0.52rem;
  font-weight: 900;
}

.mid {
  grid-area: mid;
  align-content: center;
  display: grid;
  gap: 9px;
  min-width: 0;
  text-align: center;
}

.mid > .chip {
  justify-self: center;
  min-width: 64px;
  border: 3px solid #2f190d;
  background: linear-gradient(#fff3a8, #f4a12e);
  box-shadow: 0 5px 0 #2f190d, 0 0 23px rgba(255, 194, 61, 0.54);
  color: #2f190d;
  font-size: 1rem;
}

.diebox {
  position: relative;
  display: grid;
  gap: 9px;
  padding: 12px;
  border: 3px solid rgba(255, 235, 175, 0.72);
  border-radius: 26px;
  background: linear-gradient(155deg, rgba(20, 36, 40, 0.92), rgba(5, 19, 23, 0.9));
  box-shadow: 0 8px 0 rgba(7, 13, 15, 0.82), 0 18px 28px rgba(0, 0, 0, 0.28);
  color: #fff4cf;
  backdrop-filter: blur(8px);
}

.die {
  width: 76px;
  height: 76px;
  border: 4px solid #2f190d;
  border-radius: 50% 50% 46% 54%;
  background:
    radial-gradient(circle at 35% 27%, #fffbe0 0 7%, transparent 8%),
    radial-gradient(circle at 40% 35%, #b7f1ff, #4fc7ff 35%, #3161db 71%, #243170);
  box-shadow:
    0 5px 0 #2f190d,
    0 0 0 3px #ffc64a,
    0 0 32px rgba(80, 202, 255, 0.72),
    inset 0 -8px 15px rgba(17, 25, 91, 0.5);
  color: #fff;
  text-shadow: 0 2px 2px #142c70;
}

.die.pop {
  animation: crystalRoll 620ms cubic-bezier(0.3, 0.8, 0.3, 1);
}

.result {
  border: 2px solid rgba(255, 232, 167, 0.64);
  border-radius: 13px;
  background: rgba(255, 247, 211, 0.94);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.52);
  color: #2c1d13;
  font-size: 0.76rem;
  line-height: 1.25;
}

#dieText {
  min-height: 48px;
  display: grid;
  place-items: center;
}

#battleResult {
  max-height: 96px;
  overflow: auto;
}

.action-panel {
  gap: 6px;
  border: 2px solid #30190e;
  border-radius: 17px;
  background: linear-gradient(145deg, #f5b2df, #c86bb7);
  box-shadow: 0 4px 0 #30190e;
}

.action-label {
  color: #42233b;
  letter-spacing: 0.08em;
}

.action-grid {
  grid-template-columns: 1fr 1fr;
  gap: 5px;
}

.action-grid button {
  position: relative;
  min-height: 39px;
  padding: 6px 7px;
  border-width: 2px;
  border-radius: 12px;
  box-shadow: 0 3px 0 #31190f;
  font-size: 0.68rem;
}

.action-grid button.selected {
  z-index: 2;
  background: linear-gradient(#eaffb8, #77d96e);
  box-shadow: 0 0 0 2px #fff4a4, 0 3px 0 #31190f, 0 0 19px rgba(135, 239, 111, 0.72);
  animation: selectedAction 1.6s ease-in-out infinite;
}

#ultimateBtn:not(:disabled) {
  color: #fff;
  background: linear-gradient(145deg, #b758ef, #6436ca);
  box-shadow: 0 3px 0 #2d155e, 0 0 18px rgba(191, 85, 255, 0.75);
  animation: ultimateReady 1.15s ease-in-out infinite;
}

#attackBtn.battle-button {
  display: block;
  width: 100%;
  min-height: 52px;
  border: 3px solid #2f190d;
  border-radius: 17px;
  background: linear-gradient(180deg, #fff27c 0%, #ffba28 48%, #e3701a 100%);
  box-shadow: 0 5px 0 #2f190d, 0 0 24px rgba(255, 179, 44, 0.48);
  color: #351d0c;
  font-size: 1rem;
  letter-spacing: 0.015em;
  text-transform: uppercase;
}

#attackBtn.battle-button:not(:disabled):hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 7px 0 #2f190d, 0 0 34px rgba(255, 190, 47, 0.8);
}

#attackBtn.battle-button:disabled {
  filter: grayscale(0.45);
  opacity: 0.68;
}

.setup,
.logpanel,
.library,
.rules-strip {
  position: relative;
  z-index: 3;
  border: 3px solid #321b0f;
  border-radius: 24px;
  box-shadow: 0 7px 0 #321b0f, 0 16px 26px rgba(73, 38, 15, 0.2);
}

.setup {
  gap: 12px;
  margin-top: 34px;
}

.box {
  border: 3px solid #321b0f;
  border-radius: 22px;
  background: linear-gradient(145deg, #b9eaff, #67bce7);
  box-shadow: 0 6px 0 #321b0f;
  color: #26333a;
}

.box:nth-child(2) {
  background: linear-gradient(145deg, #d9ffbd, #83d47a);
}

.box:nth-child(3) {
  background: linear-gradient(145deg, #ffe8ac, #f4b74e);
}

.logpanel {
  background: linear-gradient(145deg, #baf0bc, #6fca79);
}

.library {
  background: linear-gradient(145deg, #fff1aa, #f2b946);
}

.rules-strip {
  background: linear-gradient(145deg, #ffc7e9, #eb80c0);
}

body.dark-game .box,
body.dark-game .logpanel,
body.dark-game .library,
body.dark-game .rules-strip {
  color: #21160e;
}

.libcard {
  transition: transform 150ms ease, box-shadow 150ms ease;
}

.libcard:hover {
  transform: translateY(-3px) rotate(-0.5deg);
  box-shadow: 3px 6px 0 var(--ink);
}

.effects-layer {
  position: absolute;
  z-index: 30;
  inset: 0;
  overflow: hidden;
  border-radius: 39px;
  pointer-events: none;
}

.combat-banner {
  position: absolute;
  z-index: 35;
  left: 50%;
  top: 49%;
  display: grid;
  place-items: center;
  min-width: 180px;
  max-width: 70%;
  min-height: 64px;
  padding: 9px 18px;
  border: 4px solid #2e180d;
  border-radius: 18px;
  background: linear-gradient(180deg, #fff8b4, #f0a827);
  box-shadow: 0 7px 0 #2e180d, 0 15px 35px rgba(0, 0, 0, 0.5);
  color: #321b0d;
  font-size: clamp(1.05rem, 2vw, 1.45rem);
  font-weight: 900;
  line-height: 1;
  text-align: center;
  text-transform: uppercase;
  transform: translate(-50%, -50%) scale(0.3) rotate(-7deg);
  opacity: 0;
}

.combat-banner.show {
  animation: bannerBurst 900ms cubic-bezier(0.2, 0.9, 0.25, 1) both;
}

.combat-banner.ultimate {
  color: white;
  background: linear-gradient(145deg, #e782ff, #6535d9);
  box-shadow: 0 7px 0 #2e185a, 0 0 42px rgba(210, 103, 255, 0.9);
}

.fx-projectile {
  position: absolute;
  z-index: 34;
  width: 34px;
  height: 34px;
  margin: -17px;
  border: 3px solid #fff7c7;
  border-radius: 50%;
  background: radial-gradient(circle at 37% 31%, #fff, #ffe259 28%, #ff7330 65%, transparent 68%);
  box-shadow: 0 0 15px #fff1a5, 0 0 35px #ff7a35;
  transform: translate(0, 0) scale(0.6);
  opacity: 0;
}

.fx-projectile.fly {
  opacity: 1;
  transition: transform 300ms cubic-bezier(0.3, 0.72, 0.42, 1), opacity 70ms ease;
}

.fx-projectile.ultimate {
  width: 52px;
  height: 52px;
  margin: -26px;
  background: radial-gradient(circle at 37% 31%, #fff, #eab0ff 24%, #8439ef 65%, transparent 68%);
  box-shadow: 0 0 18px #fff, 0 0 50px #c05dff;
}

.damage-pop {
  position: absolute;
  z-index: 38;
  color: #fff;
  font-size: clamp(1.8rem, 4vw, 3.4rem);
  font-weight: 900;
  -webkit-text-stroke: 4px #48180f;
  paint-order: stroke fill;
  text-shadow: 0 5px 0 #b12b1e, 0 10px 19px rgba(0, 0, 0, 0.58);
  transform: translate(-50%, -50%) scale(0.2) rotate(-12deg);
  animation: damageBurst 1.05s cubic-bezier(0.16, 0.9, 0.25, 1) forwards;
}

.damage-pop.dodge {
  color: #d9f8ff;
  font-size: clamp(1.2rem, 3vw, 2.2rem);
  -webkit-text-stroke-color: #134a67;
  text-shadow: 0 4px 0 #237e9f;
}

.damage-pop.ko {
  color: #fff08f;
}

.spark {
  position: absolute;
  z-index: 33;
  width: var(--spark-size, 9px);
  height: var(--spark-size, 9px);
  border-radius: 50% 0 50% 50%;
  background: var(--spark-color, #ffd94d);
  box-shadow: 0 0 8px var(--spark-color, #ffd94d);
  transform: translate(-50%, -50%) rotate(45deg);
  animation: sparkScatter 650ms ease-out forwards;
}

.card.deal-in {
  animation: dealCard 620ms cubic-bezier(0.17, 0.84, 0.25, 1.18) both;
}

.mini.deal-mini {
  animation: dealMini 470ms cubic-bezier(0.17, 0.84, 0.25, 1.15) both;
  animation-delay: var(--deal-delay, 0ms);
}

.card.swap-in {
  animation: swapCard 520ms cubic-bezier(0.2, 0.9, 0.25, 1.16) both;
}

.card.strike-left {
  animation: strikeLeft 520ms cubic-bezier(0.26, 0.76, 0.32, 1) both;
}

.card.strike-right {
  animation: strikeRight 520ms cubic-bezier(0.26, 0.76, 0.32, 1) both;
}

.card.hit-card {
  animation: cardHit 500ms ease both;
}

.card.knockout-card {
  animation: knockoutCard 680ms cubic-bezier(0.25, 0.8, 0.3, 1) both;
}

.card.dodge-left {
  animation: dodgeLeft 560ms ease both;
}

.card.dodge-right {
  animation: dodgeRight 560ms ease both;
}

.board.impact {
  animation: boardImpact 360ms ease;
}

body.is-resolving .action-panel,
body.is-resolving .hand,
body.is-resolving #attackBtn {
  pointer-events: none;
}

body.is-resolving #attackBtn {
  filter: saturate(0.7);
}

@keyframes auraPulse {
  0%, 100% { opacity: 0.28; transform: scale(0.96); }
  50% { opacity: 0.48; transform: scale(1.03); }
}

@keyframes cardShimmer {
  0%, 64% { background-position: 135% 0; }
  88%, 100% { background-position: -55% 0; }
}

@keyframes portraitFloat {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-3px) scale(1.012); }
}

@keyframes chargedRune {
  0%, 100% { box-shadow: 0 2px 0 #2f190d, 0 0 5px #ffe96a; }
  50% { box-shadow: 0 2px 0 #2f190d, 0 0 19px #fff27d; }
}

@keyframes selectedAction {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-2px); }
}

@keyframes ultimateReady {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.23); }
}

@keyframes crystalRoll {
  0% { transform: rotate(0deg) scale(1); }
  32% { transform: rotate(145deg) scale(1.18); }
  70% { transform: rotate(302deg) scale(0.93); }
  100% { transform: rotate(360deg) scale(1); }
}

@keyframes bannerBurst {
  0% { transform: translate(-50%, -50%) scale(0.3) rotate(-8deg); opacity: 0; }
  19% { transform: translate(-50%, -50%) scale(1.14) rotate(3deg); opacity: 1; }
  32%, 70% { transform: translate(-50%, -50%) scale(1) rotate(-1deg); opacity: 1; }
  100% { transform: translate(-50%, -75%) scale(0.88) rotate(1deg); opacity: 0; }
}

@keyframes damageBurst {
  0% { transform: translate(-50%, -50%) scale(0.2) rotate(-12deg); opacity: 0; }
  22% { transform: translate(-50%, -65%) scale(1.24) rotate(5deg); opacity: 1; }
  55% { transform: translate(-50%, -82%) scale(1) rotate(-2deg); opacity: 1; }
  100% { transform: translate(-50%, -140%) scale(0.78) rotate(4deg); opacity: 0; }
}

@keyframes sparkScatter {
  0% { transform: translate(-50%, -50%) rotate(45deg) scale(0.25); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--spark-x)), calc(-50% + var(--spark-y))) rotate(280deg) scale(0); opacity: 0; }
}

@keyframes dealCard {
  0% { transform: translateY(220px) rotate(14deg) scale(0.62); opacity: 0; }
  75% { transform: translateY(-10px) rotate(-2deg) scale(1.03); opacity: 1; }
  100% { transform: translateY(0) rotate(0) scale(1); opacity: 1; }
}

@keyframes dealMini {
  0% { transform: translateY(90px) rotate(20deg) scale(0.6); opacity: 0; }
  100% { transform: rotate(var(--fan-angle)) translateY(var(--fan-lift, 0)) scale(1); opacity: 1; }
}

@keyframes swapCard {
  0% { transform: translateY(80px) rotate(9deg) scale(0.72); opacity: 0; }
  72% { transform: translateY(-8px) rotate(-2deg) scale(1.04); opacity: 1; }
  100% { transform: translateY(0) rotate(0) scale(1); opacity: 1; }
}

@keyframes strikeLeft {
  0%, 100% { transform: translateX(0) rotate(0) scale(1); }
  28% { transform: translateX(22px) rotate(3deg) scale(0.98); }
  59% { transform: translateX(-58px) rotate(-6deg) scale(1.07); }
  76% { transform: translateX(-38px) rotate(-3deg) scale(1.03); }
}

@keyframes strikeRight {
  0%, 100% { transform: translateX(0) rotate(0) scale(1); }
  28% { transform: translateX(-22px) rotate(-3deg) scale(0.98); }
  59% { transform: translateX(58px) rotate(6deg) scale(1.07); }
  76% { transform: translateX(38px) rotate(3deg) scale(1.03); }
}

@keyframes cardHit {
  0%, 100% { transform: translateX(0) rotate(0); filter: brightness(1); }
  23% { transform: translateX(-10px) rotate(-3deg); filter: brightness(1.6) saturate(1.4); }
  42% { transform: translateX(12px) rotate(4deg); filter: brightness(0.7) saturate(1.2); }
  62% { transform: translateX(-7px) rotate(-2deg); }
  79% { transform: translateX(4px) rotate(1deg); }
}

@keyframes knockoutCard {
  0% { transform: translate(0) rotate(0) scale(1); filter: brightness(1); opacity: 1; }
  20% { transform: translate(-12px, 0) rotate(-4deg) scale(1.05); filter: brightness(1.7) saturate(1.5); opacity: 1; }
  48% { transform: translate(14px, 10px) rotate(8deg) scale(0.96); filter: grayscale(0.45) brightness(0.72); opacity: 1; }
  100% { transform: translate(32px, 120px) rotate(19deg) scale(0.68); filter: grayscale(1) brightness(0.42); opacity: 0; }
}

@keyframes dodgeLeft {
  0%, 100% { transform: translateX(0) rotate(0); opacity: 1; }
  42% { transform: translateX(-64px) rotate(-8deg) scale(0.94); opacity: 0.58; }
  70% { transform: translateX(13px) rotate(3deg); opacity: 1; }
}

@keyframes dodgeRight {
  0%, 100% { transform: translateX(0) rotate(0); opacity: 1; }
  42% { transform: translateX(64px) rotate(8deg) scale(0.94); opacity: 0.58; }
  70% { transform: translateX(-13px) rotate(-3deg); opacity: 1; }
}

@keyframes boardImpact {
  0%, 100% { transform: translate(0); }
  22% { transform: translate(-4px, 2px); }
  43% { transform: translate(5px, -2px); }
  65% { transform: translate(-3px, -1px); }
  82% { transform: translate(2px, 1px); }
}

@media (min-width: 721px) and (max-width: 1120px) {
  .board {
    grid-template-columns: minmax(220px, 1fr) minmax(170px, 220px) minmax(220px, 1fr);
    grid-template-areas: "p2 mid p1";
    min-height: 600px;
    padding: 16px;
  }

  .slot {
    min-height: 390px;
    padding: 8px;
  }

  .card {
    width: min(100%, 275px);
  }

  .card .art img {
    min-height: 165px;
  }

  .card-title small,
  .ability-copy {
    font-size: 0.59rem;
  }

  .diebox {
    padding: 9px;
  }

  .action-grid button {
    font-size: 0.62rem;
  }

  .setup {
    grid-template-columns: 1fr 1fr 1fr;
  }
}

@media (max-width: 720px) {
  header {
    padding-bottom: 5px;
  }

  .arena-page {
    padding: 4px 8px max(36px, env(safe-area-inset-bottom));
  }

  .arena-page .hero {
    align-items: center;
  }

  .arena-page .hero h1 {
    font-size: clamp(2.1rem, 13vw, 3.25rem);
  }

  .arena-page .hero p {
    display: none;
  }

  #themeToggle {
    width: auto;
    min-height: 40px;
    padding: 7px 10px;
    font-size: 0.78rem;
  }

  .topbar {
    position: relative;
    top: auto;
    grid-template-columns: 1fr;
    gap: 7px;
    padding: 8px;
    border-radius: 17px;
  }

  .topbar .chips,
  .topbar .top-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }

  .topbar .top-actions {
    grid-template-columns: 1fr 1fr;
  }

  .topbar .top-actions #soundToggleBtn {
    grid-column: auto;
  }

  .board {
    grid-template-columns: 1fr;
    grid-template-areas: "p2" "mid" "p1";
    gap: 7px;
    min-height: 0;
    padding: 10px;
    border-width: 6px;
    border-radius: 32px;
    box-shadow:
      inset 0 0 0 3px #b55d28,
      inset 0 0 0 6px #e3943b,
      inset 0 0 40px rgba(0, 0, 0, 0.4),
      0 12px 0 #2b130c,
      0 21px 30px var(--arena-shadow);
  }

  .board::before {
    inset: 29% 4%;
  }

  .panel {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    gap: 5px;
    padding: 0;
  }

  .p2,
  .p1 {
    grid-area: auto;
  }

  .p2 {
    grid-area: p2;
  }

  .p1 {
    grid-area: p1;
  }

  .panel-head {
    justify-content: flex-start;
  }

  .zone-title,
  .panel-head .chip,
  .panel-head .ready {
    padding: 4px 7px;
    font-size: 0.65rem;
  }

  .slot {
    min-height: 0;
    padding: 4px;
  }

  .card {
    display: grid;
    grid-template-columns: 112px minmax(0, 1fr);
    width: 100%;
    max-width: 520px;
    border-width: 3px;
    border-radius: 21px;
    box-shadow:
      0 0 0 2px var(--card-accent),
      0 0 0 4px #6d3517,
      0 11px 18px rgba(5, 12, 14, 0.5);
  }

  .card-topline {
    grid-column: 1 / -1;
    grid-template-columns: 32px 1fr 35px;
    min-height: 45px;
    margin: -6px 6px -2px;
  }

  .role-crest,
  .momentum-gem {
    border-width: 2px;
    font-size: 0.82rem;
  }

  .card-title {
    padding: 6px;
    border-width: 2px;
    border-radius: 10px;
  }

  .card-title h3 {
    font-size: 0.9rem;
  }

  .card-title small {
    font-size: 0.52rem;
  }

  .card .art {
    grid-column: 1;
    aspect-ratio: auto;
    height: 124px;
    margin: 4px 0 8px 7px;
    border-width: 3px;
    border-radius: 14px;
  }

  .card .art img {
    min-height: 0;
    padding: 4px;
  }

  .rarity-ribbon {
    display: none;
  }

  .action-rune {
    width: 29px;
    height: 29px;
    font-size: 0.8rem;
  }

  .card .info {
    grid-column: 2;
    align-content: center;
    padding: 5px 7px 8px;
  }

  .ability-copy {
    min-height: 0;
    padding: 5px 6px;
    font-size: 0.57rem;
  }

  .ability-copy strong {
    font-size: 0.62rem;
  }

  .card-meter {
    font-size: 0.57rem;
  }

  .stat-orbs {
    grid-template-columns: 40px 1fr 40px;
  }

  .stat-orb,
  .roll-orb {
    min-height: 32px;
    border-width: 2px;
    font-size: 0.58rem;
  }

  .detailsBtn {
    right: 7px;
    bottom: -14px;
    min-height: 30px !important;
    padding: 3px 7px !important;
    border-width: 2px;
    font-size: 0.58rem;
  }

  .hand-title {
    margin-top: 4px;
    font-size: 0.6rem;
  }

  .hand {
    min-height: 78px;
    padding-top: 4px;
  }

  .mini {
    width: 84px;
    min-height: 72px;
    margin-left: -9px;
    padding: 4px;
    border-width: 2px;
    border-radius: 12px;
    box-shadow: 0 4px 0 #351c10, 0 7px 9px rgba(0, 0, 0, 0.28);
  }

  .mini img {
    height: 39px;
    border-width: 1.5px;
    border-radius: 7px;
  }

  .mini strong {
    font-size: 0.54rem;
  }

  .mini small {
    font-size: 0.45rem;
  }

  .mini-hp {
    top: 31px;
    min-width: 22px;
    height: 22px;
    border-width: 1.5px;
    font-size: 0.46rem;
  }

  .mid {
    grid-template-columns: 46px minmax(0, 1fr);
    grid-template-areas: "vs controls";
    align-items: center;
    gap: 6px;
  }

  .mid > .chip {
    grid-area: vs;
    min-width: 44px;
    padding: 7px 4px;
    border-width: 2px;
    font-size: 0.72rem;
  }

  .diebox {
    grid-area: controls;
    grid-template-columns: 52px minmax(0, 1fr);
    gap: 6px;
    padding: 7px;
    border-width: 2px;
    border-radius: 17px;
  }

  #dieText {
    display: none;
  }

  .die {
    grid-column: 1;
    grid-row: 1;
    width: 48px;
    height: 48px;
    border-width: 2px;
    font-size: 1.25rem;
  }

  .action-panel {
    grid-column: 2;
    grid-row: 1 / span 2;
    padding: 5px;
  }

  .action-label {
    display: none;
  }

  .action-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .action-grid button {
    min-height: 33px;
    padding: 4px 3px;
    font-size: 0.56rem;
  }

  #attackBtn.battle-button {
    grid-column: 1;
    grid-row: 2;
    min-height: 38px;
    padding: 5px 3px;
    border-width: 2px;
    border-radius: 12px;
    font-size: 0.62rem;
  }

  #battleResult {
    grid-column: 1 / -1;
    grid-row: 3;
    max-height: 62px;
    padding: 6px;
    font-size: 0.67rem;
  }

  .setup {
    grid-template-columns: 1fr;
    margin-top: 25px;
  }

  .combat-banner {
    top: 50%;
    min-width: 150px;
    min-height: 50px;
    padding: 7px 11px;
    border-width: 3px;
  }
}

@media (max-width: 390px) {
  .arena-page {
    padding-left: 5px;
    padding-right: 5px;
  }

  .board {
    padding: 7px;
  }

  .card {
    grid-template-columns: 94px minmax(0, 1fr);
  }

  .card .art {
    height: 112px;
  }

  .ability-copy {
    display: none;
  }

  .action-grid button {
    padding-inline: 1px;
    font-size: 0.5rem;
  }

  .topbar .chip {
    font-size: 0.7rem;
  }
}

@media (orientation: landscape) and (max-height: 600px) and (pointer: coarse) {
  header,
  .arena-page .hero {
    display: none;
  }

  .arena-page {
    padding: 4px 7px 15px;
  }

  .topbar {
    position: relative;
    top: auto;
    grid-template-columns: 1fr auto auto;
    margin: 2px 0 7px;
    padding: 5px 7px;
  }

  .board {
    grid-template-columns: minmax(210px, 1fr) 180px minmax(210px, 1fr);
    grid-template-areas: "p2 mid p1";
    min-height: 470px;
    padding: 9px;
  }

  .slot {
    min-height: 315px;
  }

  .card {
    display: grid;
    grid-template-columns: 95px 1fr;
    width: 100%;
  }

  .card-topline {
    grid-column: 1 / -1;
  }

  .card .art {
    grid-column: 1;
    height: 145px;
    aspect-ratio: auto;
  }

  .card .art img {
    min-height: 0;
  }

  .card .info {
    grid-column: 2;
  }

  .ability-copy {
    display: none;
  }

  .hand {
    min-height: 70px;
  }

  .mini {
    min-height: 66px;
  }

  .mini img {
    height: 34px;
  }

  .setup,
  .logpanel,
  .library,
  .rules-strip,
  footer {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .card::before,
  .card::after,
  .card .art img,
  .action-grid button.selected,
  #ultimateBtn:not(:disabled),
  .action-rune,
  .die,
  .card,
  .mini,
  .combat-banner,
  .fx-projectile,
  .damage-pop,
  .spark,
  .board {
    animation: none !important;
    transition-duration: 0.01ms !important;
  }
}
