:root {
  --font-display: "Ma Shan Zheng", cursive;
  --font-title: "Noto Serif SC", serif;
  --font-main: "Noto Sans SC", sans-serif;
  --bg-deep: #fdf2d0;
  --bg-mid: #f7e7c0;
  --bg-light: #fff7e2;
  --text-main: #5d4037;
  --text-soft: rgba(93, 64, 55, 0.78);
  --stroke: rgba(75, 50, 42, 0.88);
  --btn-shadow: 0 18px 40px rgba(93, 64, 55, 0.16);
  --card-width: 340px;
  --card-height: 540px;
  --fx-accent: 229, 133, 181;
  --fx-accent-soft: 255, 226, 240;
  --fx-accent-cold: 255, 245, 250;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  overflow: hidden;
  font-family: var(--font-main);
  color: var(--text-main);
  background:
    radial-gradient(circle at 18% 20%, rgba(255, 255, 255, 0.48) 0%, transparent 34%),
    radial-gradient(circle at 78% 74%, rgba(255, 181, 216, 0.28) 0%, transparent 34%),
    radial-gradient(circle at 22% 82%, rgba(160, 233, 255, 0.22) 0%, transparent 30%),
    linear-gradient(180deg, #fff7de 0%, #fdf2d0 52%, #f8e7c3 100%);
}

#main-bg-canvas,
#summon-fx-canvas,
#confetti-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.card-art-stage {
  position: relative;
  flex: 0 0 54%;
  overflow: visible;
  isolation: isolate;
  z-index: 1;
  transform: translateZ(0);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.card-bg-image {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 186%;
  overflow: hidden;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  border-radius: 14px;
  border-bottom: none;
  transform: translate3d(0, 0, 0) scale(1.04);
  transform-origin: center center;
  transition: transform 0.18s ease-out, filter 0.18s ease-out;
  z-index: 1;
  will-change: transform;
  contain: paint;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  isolation: isolate;
  outline: 1px solid transparent;
}

.card-char-pop {
  position: absolute;
  left: 50%;
  bottom: -84%;
  width: 118%;
  height: 186%;
  transform: translateX(-50%) translateY(8px) translateZ(112px) scale(1.08);
  transform-origin: center bottom;
  background-size: auto 100%;
  background-position: center bottom;
  background-repeat: no-repeat;
  z-index: 3;
  opacity: 0.98;
  pointer-events: none;
  transition: transform 0.14s ease-out, filter 0.18s ease-out;
  filter:
    drop-shadow(0 22px 32px rgba(28, 18, 18, 0.22))
    drop-shadow(0 0 18px rgba(255, 255, 255, 0.42));
}

.card-char-pop::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 10%;
  width: 56%;
  height: 11%;
  transform: translateX(-50%);
  border-radius: 999px;
  background: radial-gradient(circle, rgba(var(--accent-main), 0.32) 0%, rgba(var(--accent-main), 0.14) 42%, transparent 75%);
  filter: blur(10px);
  z-index: -1;
}

.card-holographic-foil {
  position: absolute;
  inset: -20%;
  z-index: 2;
  border-radius: 22px;
  background: linear-gradient(
    115deg,
    transparent 8%,
    rgba(255, 255, 255, 0.1) 28%,
    rgba(255, 255, 255, 0.22) 44%,
    rgba(255, 255, 255, 0.34) 50%,
    rgba(255, 255, 255, 0.22) 56%,
    rgba(255, 255, 255, 0.1) 72%,
    transparent 92%
  );
  background-size: 360% 360%;
  background-position: 0% 0%;
  mix-blend-mode: color-dodge;
  opacity: var(--foil-opacity);
  pointer-events: none;
  filter: blur(4px);
}

#card-reveal-overlay[data-rarity="hard"] .card-holographic-foil {
  background: linear-gradient(
    115deg,
    transparent 8%,
    rgba(255, 215, 0, 0.12) 26%,
    rgba(255, 0, 255, 0.12) 36%,
    rgba(0, 255, 255, 0.16) 46%,
    rgba(255, 255, 255, 0.58) 50%,
    rgba(0, 255, 255, 0.16) 54%,
    rgba(255, 0, 255, 0.12) 64%,
    rgba(255, 215, 0, 0.12) 74%,
    transparent 92%
  );
  background-size: 380% 380%;
  opacity: calc(var(--foil-opacity) + 0.04);
}

.task-content-wrap {
  position: absolute;
  left: 24px;
  right: 24px;
  bottom: 32px;
  z-index: 10;
  transform: translateZ(60px); /* UI stays on top of character */
}

#main-bg-canvas {
  z-index: 1;
  opacity: 0.82;
}

.noise-layer {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  opacity: 0.05;
  background:
    repeating-linear-gradient(
      180deg,
      rgba(255, 255, 255, 0.16) 0 1px,
      transparent 1px 3px
    );
  mix-blend-mode: overlay;
}

.deco-element {
  position: fixed;
  z-index: 3;
  pointer-events: none;
  color: rgba(255, 255, 255, 0.88);
  text-shadow: 0 0 24px rgba(229, 133, 181, 0.18);
  animation: deco-float 6s ease-in-out infinite alternate;
}

.deco-a { top: 8%; left: 7%; font-size: 2.8rem; }
.deco-b { top: 14%; right: 8%; font-size: 2rem; animation-delay: 0.7s; }
.deco-c { bottom: 14%; left: 10%; font-size: 2.4rem; animation-delay: 1.4s; }
.deco-d { bottom: 10%; right: 6%; font-size: 3.1rem; animation-delay: 2s; }

@keyframes deco-float {
  from { transform: translateY(0) rotate(0deg); opacity: 0.36; }
  to { transform: translateY(-18px) rotate(8deg); opacity: 0.76; }
}

#main-screen {
  position: relative;
  z-index: 10;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 44px;
  padding: 24px;
  overflow: hidden; /* Prevent breathing overflow */
}

.home-hero-char {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: calc(100% - 40px);
  height: 88vh;
  transform: translateX(-50%);
  background: url('char_2.webp') center bottom/contain no-repeat;
  z-index: 1;
  pointer-events: none;
  animation: hero-breathe 8s ease-in-out infinite alternate;
  opacity: 1;
}

/* 移动端响应式锁定：确保角色不再“矮小” */
@media screen and (max-width: 600px) {
  .home-hero-char {
    width: 160%; /* 允许横向溢出以保证纵向撑满 */
    height: 92vh; /* 进一步拉高占据空间 */
    background-position: center bottom 40px; /* 向上微调，防止遮挡按钮 */
    background-size: auto 100% !important; /* 强制纵向 100% 占满 */
  }
}

@keyframes hero-breathe {
  0% { transform: translateX(-50%) translateY(0) scale(1.02); }
  100% { transform: translateX(-50%) translateY(-22px) scale(1.05); }
}

#main-screen.fade-out {
  opacity: 0;
  transform: scale(0.96);
  pointer-events: none;
}

#title-container,
.subtitle,
.summon-btn {
  position: relative;
  z-index: 5; /* Ensure content is above hero char */
}

#title-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}

.eyebrow {
  letter-spacing: 0.42em;
  font-size: 0.88rem;
  color: rgba(93, 64, 55, 0.6);
}

.grand-title {
  font-family: var(--font-display);
  font-size: clamp(3.6rem, 11vw, 6.4rem);
  line-height: 1;
  color: #ffffff;
  text-shadow:
    4px 4px 0 rgba(75, 50, 42, 0.88),
    -4px -4px 0 rgba(75, 50, 42, 0.88),
    4px -4px 0 rgba(75, 50, 42, 0.88),
    -4px 4px 0 rgba(75, 50, 42, 0.88),
    0 10px 20px rgba(93, 64, 55, 0.16);
}

.subtitle {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  padding: 10px 22px;
  border: 4px solid rgba(75, 50, 42, 0.88);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.84);
  box-shadow: 0 6px 0 rgba(93, 64, 55, 0.1);
  color: var(--text-soft);
}

.star-icon {
  color: #ffcd03;
  font-size: 1.2rem;
  animation: star-spin 4.6s linear infinite;
}

@keyframes star-spin {
  to { transform: rotate(360deg); }
}

.summon-btn,
.retry-btn {
  position: relative;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  font-family: var(--font-title);
  color: #fff8ee;
  overflow: hidden;
}

.summon-btn {
  width: min(360px, calc(100vw - 28px));
  height: 78px;
  background:
    linear-gradient(180deg, #ffe671 0%, #ffcf1d 100%);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.32),
    0 0 0 4px rgba(75, 50, 42, 0.88),
    var(--btn-shadow);
  transition: transform 0.22s ease, box-shadow 0.22s ease;
}

.summon-btn:hover {
  transform: translateY(-2px) scale(1.01);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.38),
    0 0 0 4px rgba(75, 50, 42, 0.88),
    0 22px 36px rgba(93, 64, 55, 0.18);
}

.summon-btn:active {
  transform: translateY(2px) scale(0.995);
}

.btn-core {
  position: absolute;
  inset: 8px;
  border-radius: 999px;
  background:
    linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, 0.34) 50%, transparent 100%);
  transform: translateX(-120%);
  animation: btn-scan 3.4s ease-in-out infinite;
}

@keyframes btn-scan {
  0% { transform: translateX(-120%); }
  55% { transform: translateX(120%); }
  100% { transform: translateX(120%); }
}

.btn-text {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: 2rem;
  letter-spacing: 0.08em;
  color: #5d4037;
}

#summon-overlay,
#card-reveal-overlay {
  --accent-main: var(--fx-accent);
  --accent-soft: var(--fx-accent-soft);
  --accent-cold: var(--fx-accent-cold);
}

#summon-overlay[data-rarity="easy"],
#card-reveal-overlay[data-rarity="easy"] {
  --accent-main: 255, 194, 46;
  --accent-soft: 255, 231, 138;
  --accent-cold: 255, 248, 216;
}

#summon-overlay[data-rarity="normal"],
#card-reveal-overlay[data-rarity="normal"] {
  --accent-main: 255, 194, 46;
  --accent-soft: 255, 231, 138;
  --accent-cold: 255, 248, 216;
}

#summon-overlay[data-rarity="hard"],
#card-reveal-overlay[data-rarity="hard"] {
  --accent-main: 255, 194, 46;
  --accent-soft: 255, 231, 138;
  --accent-cold: 255, 248, 216;
}

#summon-overlay {
  --rift-open: 0.08;
  --rift-glow: 0.34;
  --shell-shift: 18px;
  --shell-tilt: 0deg;
  --shutter-gap: 28vh;
  --shake-intensity: 0px;
  position: fixed;
  inset: 0;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.34s ease;
  transform: translate(var(--shake-x, 0), var(--shake-y, 0));
}

#summon-overlay.active {
  opacity: 1;
}

.summon-backdrop,
.summon-grid,
.summon-column,
.summon-shutter,
.summon-rift-shell,
.summon-card-shell,
#white-flash {
  position: absolute;
  inset: 0;
}

.summon-backdrop {
  background:
    radial-gradient(circle at 50% 50%, rgba(var(--accent-main), 0.18) 0%, transparent 24%),
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.42) 0%, transparent 44%),
    linear-gradient(180deg, rgba(255, 248, 231, 0.86) 0%, rgba(248, 233, 204, 0.9) 34%, rgba(244, 224, 186, 0.96) 100%);
}

.summon-grid {
  inset: auto 0 0;
  height: 70vh;
  opacity: 0.32;
  background:
    linear-gradient(180deg, transparent 0%, rgba(var(--accent-main), 0.2) 100%),
    repeating-linear-gradient(90deg, rgba(var(--accent-main), 0.18) 0 2px, transparent 2px 9vw),
    repeating-linear-gradient(180deg, rgba(var(--accent-main), 0.14) 0 2px, transparent 2px 8vh);
  transform-origin: 50% 100%;
  transform: perspective(900px) rotateX(78deg) scaleY(1.6);
  filter: blur(0.4px);
}

.summon-gate-left,
.summon-gate-right {
  position: absolute;
  top: 0;
  width: 50.1%;
  height: 100%;
  z-index: 10;
  background:
    linear-gradient(to right, #fffcf0 0%, #f7e7c0 85%, rgba(var(--accent-main), 0.3) 100%);
  border-right: 4px solid rgba(var(--accent-main), 0.8);
  box-shadow: 10px 0 40px rgba(0, 0, 0, 0.2);
}

.summon-gate-left {
  left: 0;
  transform: translateX(calc(-100% + var(--gate-open, 50.1vw)));
}

.summon-gate-right {
  right: 0;
  transform: scaleX(-1) translateX(calc(-100% + var(--gate-open, 50.1vw)));
}

#summon-overlay.phase-charge {
  --gate-open: 49vw;
}

#summon-overlay.phase-compress {
  --gate-open: 51vw;
}

#summon-overlay.phase-compress .summon-gate-left,
#summon-overlay.phase-compress .summon-gate-right {
  border-color: rgba(var(--accent-main), 1);
  box-shadow: 0 0 50px rgba(var(--accent-main), 0.6);
}

#summon-overlay.phase-tear {
  --gate-open: -40vw;
}

#summon-overlay.phase-tear .summon-gate-left,
#summon-overlay.phase-tear .summon-gate-right {
  opacity: 1; /* GSAP will handle transform */
}

.summon-rift-core {
  width: 140px;
  height: 80vh;
  border-radius: 2px;
  background:
    linear-gradient(90deg, transparent 0%, rgba(var(--accent-cold), 0.94) 50%, transparent 100%),
    linear-gradient(180deg, transparent 0%, rgba(var(--accent-cold), 0.4) 50%, transparent 100%);
  box-shadow:
    0 0 calc(40px + var(--rift-glow) * 60px) rgba(var(--accent-main), calc(0.2 + var(--rift-glow) * 0.4)),
    0 0 calc(100px + var(--rift-glow) * 100px) rgba(var(--accent-main), calc(0.1 + var(--rift-glow) * 0.22));
  transform: scaleX(var(--rift-open));
  transition: transform 0.26s ease, box-shadow 0.26s ease;
}

.summon-rift-edge {
  position: absolute;
  top: 10vh;
  width: 2px;
  height: 80vh;
  background: linear-gradient(180deg, transparent 0%, rgba(255, 255, 255, 0.92) 18%, rgba(var(--accent-main), 0.92) 50%, rgba(255, 255, 255, 0.92) 82%, transparent 100%);
  opacity: calc(0.28 + var(--rift-glow) * 0.6);
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.summon-rift-edge-left {
  transform: translateX(calc(-22px - var(--rift-open) * 38px));
}

.summon-rift-edge-right {
  transform: translateX(calc(22px + var(--rift-open) * 38px));
}

.summon-card-shell {
  display: grid;
  place-items: center;
  pointer-events: none;
}

.card-shell-frame,
.card-shell-line {
  position: absolute;
  width: calc(var(--card-width) * 0.9);
  height: calc(var(--card-height) * 0.9);
  border-radius: 28px;
}

.card-shell-frame {
  border: 1px solid rgba(255, 255, 255, 0.38);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08) 0%, rgba(var(--accent-main), 0.1) 100%);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.08),
    0 0 80px rgba(var(--accent-main), 0.18);
}

.card-shell-line {
  inset: 28px auto auto;
  width: calc(var(--card-width) * 0.74);
  height: calc(var(--card-height) * 0.74);
  border: 1px solid rgba(var(--accent-cold), 0.5);
}

.card-shell-line.line-two {
  width: calc(var(--card-width) * 0.58);
  height: calc(var(--card-height) * 0.58);
  border-style: dashed;
  border-color: rgba(var(--accent-main), 0.42);
}

.summon-card-shell {
  opacity: 0.16;
  transform:
    translateY(var(--shell-shift))
    rotateZ(var(--shell-tilt))
    scale(calc(0.84 + var(--rift-open) * 0.34));
  filter: blur(calc(10px - var(--rift-glow) * 7px));
  transition: opacity 0.22s ease, transform 0.22s ease, filter 0.22s ease;
}

#summon-overlay.active .summon-column {
  opacity: 0.36;
}

#summon-overlay.phase-charge {
  --shutter-gap: 22vh;
  --rift-open: 0.18;
  --rift-glow: 0.76;
}

#summon-overlay.phase-charge .summon-column {
  opacity: 0.62;
}

#summon-overlay.phase-charge .summon-card-shell {
  opacity: 0.54;
}

#summon-overlay.phase-compress {
  --shutter-gap: 0vh;
  --rift-open: 0.04;
  --rift-glow: 1.16;
}

#summon-overlay.phase-compress .summon-card-shell {
  opacity: 1;
}

#summon-overlay.phase-compress .summon-shutter {
  transition-duration: 0.18s;
  border-color: rgba(var(--accent-main), 1);
  box-shadow: 0 0 40px rgba(var(--accent-main), 0.4);
}

#summon-overlay.phase-compress .summon-grid {
  opacity: 0.76;
}

#summon-overlay.phase-tear {
  --shutter-gap: -20vh;
  --rift-open: 1.2;
  --rift-glow: 2.2;
}

#summon-overlay.phase-tear .summon-card-shell {
  opacity: 0;
  transform: translateY(-48px) scale(1.18);
}

#summon-fx-canvas {
  z-index: 5;
  mix-blend-mode: screen;
}

#white-flash {
  z-index: 6;
  opacity: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.98) 0%, rgba(255, 255, 255, 0.4) 24%, rgba(255, 255, 255, 0.08) 56%, transparent 100%);
}

/* Impact FX Layer */
.impact-fx-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 7;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s ease;
}

#summon-overlay.phase-tear .impact-fx-layer {
  opacity: 1;
}

.impact-halo {
  position: absolute;
  width: 100vmax;
  height: 100vmax;
  background: linear-gradient(45deg, rgba(var(--accent-main), 0.6) 0%, transparent 70%);
  transform: scale(0) rotate(45deg);
  animation: halo-burst 0.8s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  border: 4px solid rgba(var(--accent-main), 0.4);
}

.impact-radial-beams {
  position: absolute;
  width: 200vmax;
  height: 200vmax;
  background: conic-gradient(
    from 0deg,
    transparent 0deg,
    rgba(var(--accent-main), 0.2) 10deg,
    transparent 20deg,
    rgba(var(--accent-main), 0.3) 40deg,
    transparent 60deg,
    rgba(var(--accent-main), 0.2) 80deg,
    transparent 100deg,
    rgba(var(--accent-main), 0.3) 140deg,
    transparent 180deg,
    rgba(var(--accent-main), 0.2) 220deg,
    transparent 260deg,
    rgba(var(--accent-main), 0.3) 300deg,
    transparent 340deg,
    transparent 360deg
  );
  mask: radial-gradient(circle, transparent 20%, black 60%);
  -webkit-mask: radial-gradient(circle, transparent 20%, black 60%);
  opacity: 0.6;
  animation: beam-spin 12s linear infinite;
}

#summon-overlay[data-rarity="hard"] .impact-radial-beams {
  opacity: 1;
  background: conic-gradient(
    from 0deg,
    transparent 0deg,
    rgba(255, 255, 255, 0.6) 5deg,
    transparent 10deg,
    rgba(var(--accent-main), 0.8) 25deg,
    transparent 40deg,
    rgba(255, 255, 255, 0.5) 55deg,
    transparent 70deg
  );
}

@keyframes halo-burst {
  0% { transform: scale(0); opacity: 1; }
  100% { transform: scale(1.2); opacity: 0; }
}

@keyframes beam-spin {
  to { transform: rotate(360deg); }
}

/* Shake & Chromatic Aberration */
.screen-shake-heavy {
  animation: shake-heavy 0.3s cubic-bezier(.36,.07,.19,.97) both;
}

@keyframes shake-heavy {
  10%, 90% { transform: translate3d(-4px, -2px, 0); filter: hue-rotate(5deg) contrast(1.2); }
  20%, 80% { transform: translate3d(8px, 4px, 0); filter: hue-rotate(-5deg) saturate(1.5); }
  30%, 50%, 70% { transform: translate3d(-12px, -6px, 0); filter: brightness(1.2) contrast(1.4); }
  40%, 60% { transform: translate3d(12px, 6px, 0); filter: brightness(1.5); }
}

.screen-shake-light {
  animation: shake-light 0.15s cubic-bezier(.36,.07,.19,.97) both;
}

@keyframes shake-light {
  10%, 90% { transform: translate3d(-1px, 0, 0); }
  20%, 80% { transform: translate3d(2px, 0, 0); }
  30%, 50%, 70% { transform: translate3d(-3px, 0, 0); }
  40%, 60% { transform: translate3d(3px, 0, 0); }
}

#summon-overlay.phase-tear[data-rarity="hard"] {
  filter: contrast(1.4) saturate(1.4) brightness(1.1);
}

#card-reveal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  perspective: 2200px;
  touch-action: none;
}

#card-reveal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.reveal-backdrop,
.reveal-horizon,
.reveal-runway,
.reveal-rings {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.reveal-backdrop {
  background:
    radial-gradient(circle at 50% 46%, rgba(var(--accent-main), 0.14) 0%, transparent 26%),
    linear-gradient(180deg, rgba(255, 248, 231, 1) 0%, rgba(248, 233, 204, 1) 34%, rgba(244, 224, 186, 1) 100%);
}

/* More Powerful Contrast for Reveal */
#card-reveal-overlay[data-rarity="hard"] .reveal-backdrop {
  background:
    radial-gradient(circle at 50% 46%, rgba(255, 255, 255, 0.4) 0%, transparent 50%),
    linear-gradient(180deg, #1a1a1a 0%, #3d2b1f 100%);
}

.reveal-beams-bg {
  position: absolute;
  inset: -50%;
  background: conic-gradient(
    from 0deg,
    transparent 0deg,
    rgba(var(--accent-main), 0.15) 15deg,
    transparent 30deg
  );
  opacity: 0;
  transition: opacity 0.5s ease;
  animation: beam-spin 20s linear infinite;
}

#card-reveal-overlay.active .reveal-beams-bg {
  opacity: 0.4;
}

#card-reveal-overlay[data-rarity="hard"].active .reveal-beams-bg {
  opacity: 0.8;
  background: conic-gradient(
    from 0deg,
    transparent 0deg,
    rgba(255, 255, 255, 0.3) 10deg,
    transparent 20deg,
    rgba(var(--accent-main), 0.4) 40deg,
    transparent 60deg
  );
}

.reveal-horizon {
  top: 50%;
  height: 2px;
  background: linear-gradient(90deg, transparent 0%, rgba(var(--accent-main), 0.84) 50%, transparent 100%);
  box-shadow: 0 0 36px rgba(var(--accent-main), 0.42);
  opacity: 0.28;
}

.reveal-runway {
  inset: auto 0 0;
  height: 74vh;
  background:
    linear-gradient(180deg, transparent 0%, rgba(var(--accent-main), 0.12) 100%),
    repeating-linear-gradient(90deg, rgba(var(--accent-main), 0.14) 0 2px, transparent 2px 9vw),
    repeating-linear-gradient(180deg, rgba(var(--accent-main), 0.12) 0 2px, transparent 2px 8vh);
  transform-origin: 50% 100%;
  transform: perspective(1000px) rotateX(76deg) scaleY(1.45);
  opacity: 0.36;
}

.reveal-rings {
  display: grid;
  place-items: center;
}

.reveal-frame {
  position: absolute;
  width: min(85vmin, 780px);
  aspect-ratio: 1;
  border-radius: 4px; /* Almost square */
  opacity: 0;
  border: 2px solid rgba(var(--accent-main), 0.4);
  box-shadow: 0 0 50px rgba(var(--accent-main), 0.15);
  transform: rotate(45deg); /* Diamond shape */
}

.reveal-frame-b {
  width: min(65vmin, 580px);
  border-style: dashed;
}

.reveal-frame-c {
  width: min(48vmin, 420px);
  border-color: rgba(255, 255, 255, 0.4);
}

#card-reveal-overlay.impacting .reveal-frame-a {
  animation: reveal-ring-burst 1.05s cubic-bezier(0.16, 0.88, 0.16, 1) forwards;
}

#card-reveal-overlay.impacting .reveal-frame-b {
  animation: reveal-ring-burst 0.95s cubic-bezier(0.16, 0.88, 0.16, 1) forwards 0.08s;
}

#card-reveal-overlay.impacting .reveal-frame-c {
  animation: reveal-ring-burst 0.82s cubic-bezier(0.16, 0.88, 0.16, 1) forwards 0.16s;
}

@keyframes reveal-ring-burst {
  0% { transform: scale(0.24) rotate(45deg); opacity: 0; }
  18% { opacity: 0.9; }
  100% { transform: scale(1.3) rotate(45deg); opacity: 0; }
}

#confetti-canvas {
  z-index: 2;
  mix-blend-mode: screen;
  pointer-events: none;
}

#card-stage {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--card-width);
  height: var(--card-height);
  transform: translate(-50%, -50%); /* Clean base */
  perspective: 1800px;
  perspective-origin: 50% 50%;
  opacity: 0;
  pointer-events: none;
  z-index: 10;
  touch-action: none;
  transform-style: preserve-3d;
}

#reveal-title-wrap {
  position: absolute;
  top: 8%;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  text-align: center;
  z-index: 5;
  width: 100%;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.8s ease, transform 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}

#card-reveal-overlay.active #reveal-title-wrap {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  transition-delay: 0.2s;
}

.reveal-eyebrow {
  font-size: 1rem;
  letter-spacing: 0.4em;
  color: rgba(93, 64, 55, 0.5);
  margin-bottom: 8px;
  text-transform: uppercase;
}

.reveal-grand-title {
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 10vw, 3.8rem);
  color: #ffffff;
  white-space: nowrap;
  text-shadow:
    2px 2px 0 rgba(75, 50, 42, 0.8),
    -2px -2px 0 rgba(75, 50, 42, 0.8),
    0 4px 12px rgba(93, 64, 55, 0.18);
}

@keyframes reveal-title-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

#card-stage.materializing {
  transform: translate(-50%, calc(-50% - 7vh)) scale(1.16) rotateX(-10deg) rotateZ(3deg);
  opacity: 1;
  filter: blur(2px);
}

#card-stage.presented {
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
  filter: blur(0);
  pointer-events: auto;
}

#the-card {
  --card-depth: 8px;
  --face-shell: linear-gradient(180deg, rgba(255, 255, 255, 0.98) 0%, rgba(255, 251, 245, 0.98) 100%);
  --face-border: rgba(255, 255, 255, 0.95);
  --face-outline: rgba(255, 255, 255, 0.35);
  --panel-surface: linear-gradient(180deg, rgba(255, 255, 255, 0.94) 0%, rgba(248, 244, 238, 0.86) 100%);
  --panel-rule: rgba(255, 255, 255, 0.9);
  --art-divider: rgba(255, 255, 255, 0.95);
  --foil-opacity: 0.65;
  --glare-opacity: 0.28;
  --star-color: #ffcd03;
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transform-origin: 50% 50%;
  filter: none;
  /* transition: transform 0.18s ease-out, filter 0.18s ease-out;  -- REMOVED TO PREVENT GSAP CONFLICT */
  touch-action: none;
}

#card-stage.materializing #the-card {
  animation: card-entry-slam 0.92s cubic-bezier(0.18, 0.92, 0.16, 1) forwards;
}

@keyframes card-entry-slam {
  0% { transform: scale(3) rotateX(40deg) rotateZ(-30deg); filter: brightness(3) blur(10px); }
  40% { transform: scale(0.9) rotateX(-10deg) rotateZ(5deg); filter: brightness(1.5) blur(0); }
  60% { transform: scale(1.1) rotateX(5deg) rotateZ(-2deg); }
  100% { transform: scale(1) rotateX(0deg) rotateZ(0deg); }
}

.card-inner-wrap {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transform-origin: 50% 50%;
  transition: none;
  will-change: transform;
}

.card-face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border: 12px solid var(--face-border);
  border-radius: 26px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  box-shadow: 0 0 0 1px var(--face-outline);
  transform-style: preserve-3d;
}

.face-back {
  box-shadow: none;
}

.face-back {
  z-index: 1;
  transform: rotateY(0deg) translateZ(-1px);
  display: grid;
  place-items: center;
  background:
    linear-gradient(145deg, rgba(255, 244, 198, 0.82) 0%, rgba(255, 207, 29, 0.96) 100%),
    url('card_back.webp') center/cover no-repeat;
}

.face-back::before {
  content: none;
}

.face-back::after {
  content: none;
  position: relative;
  z-index: 2;
  font-family: var(--font-title);
  padding: 10px 22px;
  border: 4px solid rgba(255, 255, 255, 0.92);
  color: var(--color-white, #ffffff);
  font-size: 3rem;
  text-shadow: 0 6px 18px rgba(93, 64, 55, 0.16);
  transform: rotate(-8deg);
}

.face-front {
  display: flex;
  flex-direction: column;
  z-index: 2;
  overflow: hidden;
  transform: rotateY(180deg) translateZ(1px);
  background: var(--face-shell);
  transform-style: preserve-3d;
  box-shadow:
    0 0 0 1px var(--face-outline),
    inset 0 0 0 4px rgba(var(--accent-main), 0.18);
}

#card-bg-image {
  background-position: center top;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.28);
  transform: translate3d(0, 0, 0) translateZ(0.1px) scale(1.04);
}

#card-bg-image::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.16) 0%, transparent 26%, rgba(255, 255, 255, 0.08) 58%, rgba(255, 255, 255, 0.22) 100%),
    radial-gradient(circle at 18% 18%, rgba(255, 255, 255, 0.42) 0%, transparent 22%);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transform: translateZ(0);
}

.task-content-wrap {
  position: relative;
  left: auto;
  right: auto;
  bottom: auto;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 12px;
  padding: 24px 20px 18px;
  z-index: 6;
  min-height: 0;
  background: var(--panel-surface);
  transform: translateZ(0);
  transform-style: preserve-3d;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
  border-top: 3px solid var(--panel-rule);
  border-radius: 0;
}

.rarity-badge {
  width: fit-content;
  padding: 4px 15px;
  border-radius: 999px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.08);
  font-family: var(--font-title);
  font-size: 1.08rem;
  color: #ffffff;
}

.task-desc {
  margin: 4px 0;
  font-size: 1.48rem;
  line-height: 1.34;
  font-weight: 900;
  color: #5d4037;
}

.stars-container {
  color: var(--star-color);
  font-size: 1.5rem;
  letter-spacing: 4px;
  margin-top: auto;
}

.theme-easy {
  --accent-main: 93, 214, 255;
  --accent-soft: 174, 239, 255;
  --accent-cold: 237, 251, 255;
  --face-shell: linear-gradient(180deg, rgba(248, 254, 255, 0.99) 0%, rgba(231, 249, 255, 0.98) 100%);
  --face-border: rgba(223, 247, 255, 0.98);
  --face-outline: rgba(93, 214, 255, 0.68);
  --panel-surface: linear-gradient(180deg, rgba(255, 255, 255, 0.96) 0%, rgba(226, 246, 255, 0.9) 100%);
  --panel-rule: rgba(93, 214, 255, 0.62);
  --art-divider: rgba(93, 214, 255, 0.56);
  --foil-opacity: 0.42;
  --glare-opacity: 0.22;
  --star-color: #7ad9f0;
}

.theme-normal {
  --accent-main: 229, 133, 181;
  --accent-soft: 255, 226, 240;
  --accent-cold: 255, 245, 250;
  --face-shell: linear-gradient(180deg, rgba(255, 251, 254, 0.99) 0%, rgba(255, 240, 248, 0.98) 100%);
  --face-border: rgba(255, 238, 247, 0.98);
  --face-outline: rgba(229, 133, 181, 0.62);
  --panel-surface: linear-gradient(180deg, rgba(255, 255, 255, 0.96) 0%, rgba(255, 235, 246, 0.92) 100%);
  --panel-rule: rgba(229, 133, 181, 0.56);
  --art-divider: rgba(229, 133, 181, 0.48);
  --foil-opacity: 0.58;
  --glare-opacity: 0.26;
  --star-color: #e685b5;
}

.theme-hard {
  --accent-main: 255, 194, 46;
  --accent-soft: 255, 231, 138;
  --accent-cold: 255, 248, 216;
  --face-shell: linear-gradient(180deg, rgba(255, 252, 238, 0.99) 0%, rgba(255, 243, 203, 0.98) 100%);
  --face-border: rgba(255, 246, 192, 0.99);
  --face-outline: rgba(255, 194, 46, 0.72);
  --panel-surface: linear-gradient(180deg, rgba(255, 255, 255, 0.96) 0%, rgba(255, 244, 205, 0.92) 100%);
  --panel-rule: rgba(255, 194, 46, 0.66);
  --art-divider: rgba(255, 194, 46, 0.62);
  --foil-opacity: 0.82;
  --glare-opacity: 0.32;
  --star-color: #ffb300;
}

.theme-easy .rarity-badge { background-color: #74d6e4; }
.theme-normal .rarity-badge { background-color: #e685b5; }
.theme-hard .rarity-badge { background-color: #ffb300; }

.card-glare {
  position: absolute;
  inset: -32%;
  pointer-events: none;
  background:
    radial-gradient(circle at 28% 20%, rgba(255, 255, 255, 0.72) 0%, rgba(255, 255, 255, 0.18) 18%, transparent 38%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.16) 0%, transparent 42%, rgba(255, 255, 255, 0.12) 72%, transparent 100%);
  mix-blend-mode: screen;
  filter: blur(14px);
  opacity: var(--glare-opacity);
  z-index: 5;
  transition: transform 0.18s ease-out;
  transform: translateZ(18px);
}

.retry-btn {
  position: absolute;
  left: 50%;
  bottom: 8%; /* Switched to bottom-based relative positioning */
  z-index: 120; /* High priority to stay above char-pop */
  transform: translateX(-50%) translateY(30px);
  width: min(240px, calc(100vw - 40px));
  height: 64px;
  background:
    linear-gradient(180deg, rgba(255, 252, 238, 0.98) 0%, rgba(255, 218, 102, 0.98) 100%);
  box-shadow: 
    0 20px 40px rgba(93, 64, 55, 0.2),
    0 0 0 1px rgba(255, 255, 255, 0.4);
  color: #5d4037;
  font-size: 1.4rem;
  letter-spacing: 2px;
  opacity: 0;
  pointer-events: none;
  backdrop-filter: blur(8px); /* Premium look */
  transition: opacity 0.3s ease, transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.retry-btn.active {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 600px) {
  :root {
    --card-width: 300px;
    --card-height: 476px;
  }

  .grand-title {
    font-size: 3.4rem;
  }

  .subtitle {
    font-size: 0.94rem;
    gap: 10px;
  }

  .summon-btn {
    width: min(320px, calc(100vw - 24px));
    height: 70px;
  }

  .btn-text {
    font-size: 1.64rem;
  }

  .retry-btn {
    top: calc(50% + (var(--card-height) / 2) + 28px);
    height: 56px;
    font-size: 1.2rem;
  }
}
