:root {
  --bg: #0e0a14;
  --card: #1a1424;
  --edge: rgb(255 255 255 / .1);
}

body {
  background:
    radial-gradient(90% 50% at 50% 0%, rgb(255 77 210 / .12), transparent 70%),
    radial-gradient(80% 40% at 50% 100%, rgb(106 216 255 / .06), transparent 70%),
    var(--bg);
}

#app {
  position: fixed;
  inset: 0;
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

/* progress track */
#track {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: calc(14px + var(--safe-top)) 12px 6px 52px;
  font: 700 14px/1 var(--mono);
}
#track span { color: rgb(255 255 255 / .2); transition: color .3s, transform .3s; }
#track span.done { color: var(--dim); }
#track span.now { color: #fff; transform: scale(1.5); text-shadow: 0 0 10px var(--rift-hot); }
#track span.home { color: #ffb547; }
#track span.rift { color: var(--rift-hot); }
#track i { width: 12px; height: 1px; background: rgb(255 255 255 / .15); }

#stage { flex: 1; position: relative; min-height: 0; }

/* journey: swipeable card */
#journey { position: absolute; inset: 8px 0 8px; display: grid; place-items: center; }
#journey[hidden] { display: none; }
.stack-shadow, .jcard {
  position: absolute;
  width: min(78vw, 330px);
  height: min(58vh, 440px);
  border-radius: 22px;
}
.stack-shadow { background: var(--card); border: 1px solid var(--edge); transform: translateY(10px) scale(.95); opacity: .5; }
.stack-shadow.s2 { transform: translateY(20px) scale(.9); opacity: .25; }
#slot { display: contents; }

.jcard {
  background: linear-gradient(170deg, #241b31, #140f1c 70%);
  border: 1px solid var(--edge);
  box-shadow: 0 20px 50px rgb(0 0 0 / .5);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  touch-action: none;
  cursor: grab;
  animation: deal .45s cubic-bezier(.2, .9, .3, 1.15);
  will-change: transform;
}
.jcard.fly { transition: transform .35s ease-in, opacity .35s; opacity: 0; }
.jcard.snap { transition: transform .3s cubic-bezier(.2, .9, .3, 1.3); }
@keyframes deal { from { transform: translateY(60px) rotate(4deg) scale(.9); opacity: 0; } }

.jcard .art {
  flex: 1.2;
  display: grid;
  place-items: center;
  font: 400 72px/1 var(--mono);
  color: var(--tint, #fff);
  text-shadow: 0 0 30px var(--tint, #fff);
  background: radial-gradient(circle at 50% 60%, color-mix(in srgb, var(--tint, #fff) 18%, transparent), transparent 65%);
  position: relative;
}
.jcard .art span { animation: float 3s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-8px); } }
.jcard .kind {
  position: absolute;
  top: 14px;
  left: 16px;
  font: 700 10px/1 var(--mono);
  letter-spacing: .2em;
  color: var(--tint);
  opacity: .8;
}
.jcard .body { padding: 0 20px 18px; }
.jcard h2 { margin: 0 0 6px; font: 800 22px/1.15 var(--serif); }
.jcard p { margin: 0; color: #b9aec9; font-size: 15px; line-height: 1.45; }
.jcard .opts { display: flex; justify-content: space-between; gap: 10px; margin-top: 14px; font: 700 12px/1.3 var(--mono); }
.jcard .opts div { flex: 1; color: var(--dim); transition: color .15s, transform .15s; }
.jcard .opts .r { text-align: right; }
.jcard .label {
  position: absolute;
  top: 18px;
  padding: 8px 12px;
  border-radius: 10px;
  font: 800 13px/1.2 var(--mono);
  max-width: 60%;
  opacity: 0;
  border: 2px solid currentColor;
  background: rgb(0 0 0 / .6);
  pointer-events: none;
}
.jcard .label.l { right: 14px; color: var(--ice); transform: rotate(8deg); }
.jcard .label.r { left: 14px; color: var(--toxic); transform: rotate(-8deg); }

/* party strip */
#party {
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 6px 10px;
}
.pm {
  position: relative;
  flex: 1;
  max-width: 120px;
  padding: 8px 8px 7px;
  border-radius: 14px;
  background: rgb(255 255 255 / .04);
  border: 1px solid var(--edge);
  font-family: var(--mono);
  transition: transform .15s, border-color .15s, box-shadow .15s, opacity .3s;
}
.pm .top { display: flex; align-items: center; gap: 6px; }
.pm .g { font: 800 18px/1 var(--mono); }
.pm .n { font-size: 11px; font-weight: 700; }
.pm .bar { height: 5px; margin-top: 6px; background: rgb(255 255 255 / .08); border-radius: 3px; overflow: hidden; }
.pm .bar i { display: block; height: 100%; transition: width .3s; }
.pm .hp { font-size: 10px; color: var(--dim); margin-top: 3px; display: flex; justify-content: space-between; }
.pm .guard { color: var(--ice); font-weight: 700; }
.pm.down { opacity: .35; filter: grayscale(1); }
.pm.hurt { animation: shake .3s; }
.pm.target-ok { border-color: var(--toxic); box-shadow: 0 0 16px rgb(125 255 106 / .4); transform: translateY(-4px); }
.pm.targeted::after {
  content: "⚔";
  position: absolute;
  top: -10px;
  right: -4px;
  color: var(--blood);
  font-size: 14px;
  animation: cor .8s infinite;
}
@keyframes cor { 50% { opacity: .4; } }

/* battle */
#battle { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: center; }
#battle[hidden] { display: none; }
#enemies { display: flex; justify-content: center; align-items: flex-end; gap: 10px; padding: 0 10px; }
.foe {
  position: relative;
  width: 104px;
  padding: 34px 8px 10px;
  border-radius: 16px;
  background: linear-gradient(170deg, #2a1a2e, #160e1a);
  border: 1px solid var(--edge);
  text-align: center;
  font-family: var(--mono);
  animation: deal .45s cubic-bezier(.2, .9, .3, 1.15) backwards;
  transition: transform .2s, border-color .15s, box-shadow .15s;
}
.foe.boss { width: 150px; }
.foe.shown { animation: none; }
.foe .g { font: 800 44px/1 var(--mono); display: block; text-shadow: 0 0 18px currentColor; animation: float 2.4s ease-in-out infinite; }
.foe.boss .g { font-size: 64px; }
.foe .n { font-size: 11px; font-weight: 700; margin-top: 6px; color: #ddd; }
.foe .bar { height: 5px; margin-top: 6px; background: rgb(255 255 255 / .08); border-radius: 3px; overflow: hidden; }
.foe .bar i { display: block; height: 100%; background: var(--blood); transition: width .3s; }
.foe .hp { font-size: 10px; color: var(--dim); margin-top: 3px; }
.foe .hp b { color: var(--ice); }
.foe.target-ok { border-color: var(--blood); box-shadow: 0 0 18px rgb(255 59 78 / .5); transform: scale(1.04); }
.foe.hit { animation: hit .3s; }
.foe.lunge { animation: lunge .4s cubic-bezier(.3, 0, .3, 1); z-index: 2; }
.foe.die { animation: burn .7s forwards; }
@keyframes hit { 30% { transform: translateX(-6px) rotate(-3deg); filter: brightness(2.5); } 60% { transform: translateX(5px); } }
@keyframes lunge { 45% { transform: translateY(70px) scale(1.12); } }
@keyframes burn {
  0% { filter: brightness(3); }
  100% { opacity: 0; transform: scale(.7) translateY(-20px); filter: blur(6px) brightness(3); }
}

.intent {
  position: absolute;
  top: -14px;
  left: 50%;
  translate: -50% 0;
  padding: 6px 9px;
  border-radius: 999px;
  white-space: nowrap;
  font: 800 12px/1 var(--mono);
  background: #2a0f16;
  border: 1px solid rgb(255 59 78 / .6);
  color: #ff8a93;
  transition: transform .15s, box-shadow .15s;
  animation: intent-in .3s cubic-bezier(.2, .9, .3, 1.4) backwards .2s;
}
.intent.guard { background: #0f1d2a; border-color: rgb(106 216 255 / .6); color: var(--ice); }
.intent.blight, .intent.summon { background: #1e0f2a; border-color: rgb(178 77 255 / .7); color: #d09aff; }
.intent.cancelled { text-decoration: line-through; opacity: .35; }
.intent.target-ok { transform: scale(1.2); box-shadow: 0 0 14px #fff; }
@keyframes intent-in { from { transform: scale(0); } }

#battle-log { text-align: center; margin-top: 18px; min-height: 20px; font: 12px var(--mono); color: var(--dim); }
#battle-log b { color: #fff; }

/* table: hand + energy */
#table {
  position: relative;
  height: 196px;
  padding-bottom: var(--safe-bottom);
}
#table[hidden] { display: none; }
#energy {
  position: absolute;
  left: 10px;
  top: 0;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  display: grid;
  place-content: center;
  text-align: center;
  background: radial-gradient(circle at 40% 35%, #ff9ae8, var(--rift) 60%, #3a0f52);
  box-shadow: 0 0 18px rgb(178 77 255 / .6);
  font: 800 20px/1 var(--mono);
  z-index: 5;
}
#energy small { font-size: 10px; opacity: .7; }
#energy.empty { filter: grayscale(.8) brightness(.6); box-shadow: none; }
#energy.pulse { animation: bump .3s; }
@keyframes bump { 40% { transform: scale(1.25); } }
#end-turn {
  position: absolute;
  right: 10px;
  top: 0;
  width: 58px;
  height: 50px;
  border-radius: 14px;
  border: 1px solid rgb(255 181 71 / .5);
  color: #ffb547;
  font: 800 11px/1.15 var(--mono);
  z-index: 5;
  background: rgb(255 181 71 / .08);
}
#end-turn:active { transform: scale(.94); }
#end-turn.nudge { animation: bump .6s 2; }
#piles { position: absolute; left: 0; right: 0; top: 18px; text-align: center; font: 10px var(--mono); color: var(--dim); }

#hand {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(22px + var(--safe-bottom));
  height: 150px;
}
.card {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 92px;
  height: 132px;
  margin-left: -46px;
  border-radius: 12px;
  background: linear-gradient(170deg, #2b2138, #191223);
  border: 1px solid var(--owner);
  box-shadow: 0 6px 18px rgb(0 0 0 / .5), inset 0 0 0 1px rgb(255 255 255 / .03);
  transform-origin: 50% 120%;
  transform: translateX(var(--x)) rotate(var(--r)) translateY(var(--y));
  transition: transform .25s cubic-bezier(.2, .9, .3, 1.2), opacity .2s;
  padding: 7px 7px 6px;
  font-family: var(--mono);
  touch-action: none;
  animation: draw .35s cubic-bezier(.2, .9, .3, 1.2) backwards;
}
@keyframes draw { from { transform: translateX(-200px) translateY(80px) rotate(-30deg); opacity: 0; } }
.card .cost {
  position: absolute;
  top: -8px;
  left: -8px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--rift);
  font: 800 13px/1 var(--mono);
  box-shadow: 0 0 8px rgb(178 77 255 / .7);
}
.card .cg { display: block; text-align: center; font: 400 30px/1.2 var(--mono); color: var(--owner); margin-top: 4px; }
.card .cn { display: block; text-align: center; font-size: 10.5px; white-space: nowrap; font-weight: 800; margin-top: 2px; }
.card .ct { display: block; text-align: center; font-size: 9.5px; line-height: 1.3; color: #b9aec9; margin-top: 4px; }
.card .ct b { color: #fff; }
.card .co { position: absolute; bottom: 5px; left: 0; right: 0; text-align: center; font-size: 8px; letter-spacing: .1em; color: var(--owner); opacity: .8; text-transform: uppercase; }
.card.poor { opacity: .45; }
.card.dragging { transition: none; z-index: 50; transform: none !important; animation: none; position: fixed; margin: 0; box-shadow: 0 16px 40px rgb(0 0 0 / .7), 0 0 20px var(--owner); }
.card.played { transition: transform .25s ease-in, opacity .25s; opacity: 0; }

.pop {
  position: fixed;
  z-index: 60;
  font: 800 22px/1 var(--mono);
  pointer-events: none;
  translate: -50% -50%;
  text-shadow: 0 2px 0 #000, 0 0 10px #000;
  animation: pop .8s ease-out forwards;
}
@keyframes pop {
  0% { transform: scale(.4); opacity: 0; }
  20% { transform: scale(1.4); opacity: 1; }
  100% { transform: translateY(-40px) scale(1); opacity: 0; }
}

#overlay { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: rgb(8 4 12 / .8); backdrop-filter: blur(5px); animation: fade .5s; }
#overlay[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }
.panel { text-align: center; padding: 24px; animation: deal .5s cubic-bezier(.2, .9, .3, 1.15); }
.panel h2 { font: 800 32px/1.1 var(--serif); margin: 0 0 10px; color: var(--rift-hot); }
.panel p { color: #b9aec9; margin: 0 0 20px; line-height: 1.5; }
.panel button { padding: 12px 28px; border-radius: 999px; border: 1px solid var(--rift-hot); color: var(--rift-hot); font: 700 14px var(--mono); }
