:root {
  --ink: #4c2357;
  --accent: #ff5fa2;
  --accent-deep: #8f4dff;
  --gold: #f4c66b;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  font-family: "Baloo 2", "ZCOOL KuaiLe", "Microsoft YaHei", sans-serif;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.32) 0%, rgba(255, 255, 255, 0) 36%),
    repeating-linear-gradient(-45deg, rgba(255, 255, 255, 0.12) 0 1px, rgba(255, 255, 255, 0) 1px 30px),
    linear-gradient(135deg, #ffd4e9 0%, #f0c4fb 45%, #d6bfff 100%);
}

.stage {
  position: relative;
  width: min(100%, 560px);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(20px, 5.5vh, 40px);
}

.stage::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    repeating-linear-gradient(90deg, rgba(146, 77, 255, 0.055) 0 1px, transparent 1px 64px),
    repeating-linear-gradient(0deg, rgba(255, 95, 162, 0.055) 0 1px, transparent 1px 64px);
}

.brand-kicker {
  margin: 0;
  font-family: "Baloo 2", "Microsoft YaHei", sans-serif;
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.42em;
  text-indent: 0.42em;
  text-transform: uppercase;
  color: #8e4da8;
}

.brand {
  margin: 5px 0 0;
  font-family: "ZCOOL KuaiLe", "Microsoft YaHei", sans-serif;
  font-size: clamp(2.3rem, 9vw, 3.2rem);
  font-weight: 400;
  line-height: 1;
  color: var(--ink);
  text-shadow:
    0 2px 0 rgba(255, 255, 255, 0.85),
    0 9px 20px rgba(150, 65, 175, 0.22);
}

.card-scene {
  position: relative;
  width: min(64vw, 286px);
  aspect-ratio: 5 / 7;
  perspective: 1100px;
}

.card {
  position: absolute;
  inset: 0;
}

.card.is-flipping {
  animation: card-flip 0.72s cubic-bezier(0.3, 1, 0.4, 1);
}

.card-face,
.card-back {
  position: absolute;
  inset: 0;
  border-radius: 20px;
}

.card-back {
  display: grid;
  place-items: center;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0) 38%),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.07) 0 10px, rgba(255, 255, 255, 0) 10px 20px),
    linear-gradient(145deg, #8b3ca8, #63237d 55%, #4c1a6b);
  box-shadow:
    0 30px 60px rgba(104, 34, 132, 0.34),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.card-back::before {
  content: "";
  position: absolute;
  inset: 14px;
  border: 2px solid rgba(255, 255, 255, 0.55);
  border-radius: 13px;
}

.card-back::after {
  content: "";
  position: absolute;
  inset: 20px;
  border: 1px dashed rgba(255, 255, 255, 0.42);
  border-radius: 9px;
}

.card-back__lattice {
  position: absolute;
  inset: 0;
  border-radius: 20px;
  overflow: hidden;
  background:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.1) 0 2px, rgba(255, 255, 255, 0) 2px 13px),
    repeating-linear-gradient(-45deg, rgba(255, 255, 255, 0.08) 0 2px, rgba(255, 255, 255, 0) 2px 13px);
}

.card-back__corner {
  position: absolute;
  z-index: 3;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
}

.card-back__corner--top-left {
  top: 25px;
  left: 25px;
}

.card-back__corner--top-right {
  top: 25px;
  right: 25px;
  transform: rotate(90deg);
}

.card-back__corner--bottom-left {
  bottom: 25px;
  left: 25px;
  transform: rotate(-90deg);
}

.card-back__corner--bottom-right {
  right: 25px;
  bottom: 25px;
  transform: rotate(180deg);
}

.card-back__pip {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  background: linear-gradient(135deg, #ff5fa2, #ffd36b);
  box-shadow:
    0 2px 6px rgba(0, 0, 0, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.6);
  transform: rotate(45deg);
}

.card-back__crest {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  border: 2px solid rgba(255, 255, 255, 0.7);
  border-radius: 15px;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0.03));
  box-shadow:
    0 12px 26px rgba(57, 17, 77, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.45);
  transform: rotate(-4deg);
}

.card-back__crest-text {
  font-family: "ZCOOL KuaiLe", "Microsoft YaHei", sans-serif;
  font-size: 1.15rem;
  line-height: 1;
  white-space: nowrap;
  color: #fff;
  text-shadow: 0 2px 0 rgba(120, 37, 150, 0.45);
}

.card-back__crest-diamond {
  width: 11px;
  height: 11px;
  border-radius: 2px;
  background: linear-gradient(135deg, #ffd68a, #ff5fa2);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.25);
  transform: rotate(45deg);
}

.card-face {
  display: none;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.62), rgba(255, 255, 255, 0) 26%),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.3) 0 1px, rgba(255, 255, 255, 0) 1px 9px),
    linear-gradient(160deg, #fffdf7 0%, #fff5ea 100%);
  box-shadow:
    0 24px 70px rgba(84, 34, 116, 0.32),
    inset 0 0 0 1px rgba(143, 77, 255, 0.2);
}

.card-face::before {
  content: "";
  position: absolute;
  inset: 12px;
  border: 2px solid #f2b8d5;
  border-radius: 12px;
}

.card-face::after {
  content: "";
  position: absolute;
  inset: 18px;
  border: 1px solid rgba(143, 77, 255, 0.2);
  border-radius: 9px;
}

.face-corner {
  position: absolute;
  z-index: 2;
  display: grid;
  justify-items: center;
  gap: 3px;
  width: 48px;
  height: 64px;
}

.face-corner--top {
  top: 21px;
  left: 21px;
}

.face-corner--bottom {
  right: 21px;
  bottom: 21px;
  transform: rotate(180deg);
}

.corner-value {
  font-family: "Baloo 2", "Microsoft YaHei", sans-serif;
  font-size: 1.9rem;
  font-weight: 800;
  line-height: 1;
  color: #5d2468;
}

.corner-diamond {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  box-shadow: 0 2px 5px rgba(255, 95, 162, 0.35);
  transform: rotate(45deg);
}

.face-center {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  place-items: center;
}

.score-stack {
  display: grid;
  justify-items: center;
  gap: 6px;
  transform: rotate(-3deg);
}

.score-value {
  font-family: "Baloo 2", "Microsoft YaHei", sans-serif;
  font-size: clamp(6rem, 28vw, 8.5rem);
  font-weight: 800;
  line-height: 0.9;
  color: #e33b82;
  background: linear-gradient(180deg, #ff4d8d 15%, #8f3df2 85%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter:
    drop-shadow(0 7px 0 rgba(255, 255, 255, 0.65))
    drop-shadow(0 12px 18px rgba(153, 63, 192, 0.26));
}

.score-unit {
  font-family: "ZCOOL KuaiLe", "Microsoft YaHei", sans-serif;
  font-size: 1.55rem;
  line-height: 1;
  color: #7b2f93;
}

.card.is-joker .card-face {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0) 32%),
    repeating-linear-gradient(45deg, rgba(255, 215, 121, 0.11) 0 8px, rgba(255, 215, 121, 0) 8px 18px),
    linear-gradient(145deg, #2a1038, #48135f 55%, #1f0a2d);
  box-shadow:
    0 28px 80px rgba(58, 17, 74, 0.55),
    inset 0 0 0 1px rgba(255, 211, 116, 0.45);
}

.card.is-joker .card-face::before {
  border-color: #efc36d;
}

.card.is-joker .card-face::after {
  border-color: rgba(239, 195, 109, 0.35);
}

.card.is-joker .corner-value {
  color: #f5c875;
}

.card.is-joker .corner-diamond {
  background: linear-gradient(135deg, #ffe2a0, #c65cff);
}

.card.is-joker .score-value {
  font-size: clamp(3.2rem, 16vw, 5.4rem);
  letter-spacing: 0.08em;
  background: linear-gradient(180deg, #fff0bb, #e9ad47 70%);
  filter:
    drop-shadow(0 4px 0 rgba(0, 0, 0, 0.32))
    drop-shadow(0 10px 18px rgba(255, 214, 121, 0.2));
}

.card.is-joker .score-unit {
  color: #f5c875;
}

@supports not ((-webkit-background-clip: text) or (background-clip: text)) {
  .score-value,
  .card.is-joker .score-value {
    background: none;
    color: #e33b82;
    -webkit-text-fill-color: currentColor;
  }

  .card.is-joker .score-value {
    color: #f5c875;
  }
}

.card.is-flipped .card-face {
  display: block;
  animation: face-flash 0.72s 0.18s both;
}

.card.is-flipped .card-back {
  display: none;
}

.card.is-flipped.is-joker .card-face {
  animation:
    face-flash 0.72s 0.18s both,
    joker-glow 1.25s 0.3s both;
}

.card.is-flipped .score-stack {
  animation: score-pop 0.62s cubic-bezier(0.2, 1.42, 0.35, 1) 0.42s both;
}

.card.is-swapping .card-face {
  animation: swap-pop 0.58s cubic-bezier(0.2, 1.25, 0.35, 1);
}

.card.is-swapping .score-stack {
  animation: score-swap 0.58s cubic-bezier(0.2, 1.25, 0.35, 1);
}

@keyframes face-flash {
  0% {
    filter: brightness(1);
  }
  35% {
    filter: brightness(1.72) saturate(1.28);
  }
  100% {
    filter: brightness(1);
  }
}

@keyframes joker-glow {
  0%,
  100% {
    box-shadow:
      0 28px 80px rgba(58, 17, 74, 0.55),
      0 0 0 0 rgba(255, 213, 122, 0.25),
      inset 0 0 0 1px rgba(255, 211, 116, 0.45);
  }
  50% {
    box-shadow:
      0 28px 80px rgba(58, 17, 74, 0.58),
      0 0 46px 8px rgba(255, 213, 122, 0.48),
      inset 0 0 0 1px rgba(255, 211, 116, 0.75);
  }
}

@keyframes card-flip {
  0%,
  100% {
    transform: scaleX(1);
  }
  50% {
    transform: scaleX(0);
  }
}

@keyframes swap-pop {
  0%,
  100% {
    scale: 1;
    filter: brightness(1);
  }
  40% {
    scale: 0.86;
    filter: brightness(1.22);
  }
}

@keyframes score-swap {
  0% {
    opacity: 0;
    transform: rotate(-3deg) scale(0.55);
    filter: blur(8px);
  }
  55% {
    opacity: 1;
    transform: rotate(-3deg) scale(1.12);
    filter: blur(0);
  }
  100% {
    opacity: 1;
    transform: rotate(-3deg) scale(1);
    filter: blur(0);
  }
}

@keyframes score-pop {
  0% {
    opacity: 0;
    transform: rotate(-3deg) scale(0.35);
    filter: blur(10px);
  }
  55% {
    opacity: 1;
    transform: rotate(-3deg) scale(1.16);
    filter: blur(0) brightness(1.45);
  }
  100% {
    opacity: 1;
    transform: rotate(-3deg) scale(1);
    filter: blur(0);
  }
}

.draw-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-width: min(74vw, 300px);
  padding: 18px 34px 20px;
  border: 0;
  border-radius: 999px;
  color: #fff;
  font-family: "ZCOOL KuaiLe", "Microsoft YaHei", sans-serif;
  font-size: 1.55rem;
  line-height: 1;
  cursor: pointer;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-deep) 100%);
  box-shadow:
    0 16px 34px rgba(142, 61, 208, 0.38),
    0 6px 0 rgba(102, 31, 154, 0.35),
    inset 0 2px 0 rgba(255, 255, 255, 0.55),
    inset 0 -7px 0 rgba(90, 14, 135, 0.22);
  animation: breathe 2.3s ease-in-out infinite;
  transition:
    transform 0.2s ease,
    filter 0.2s ease,
    opacity 0.2s ease;
}

.draw-button::after {
  content: "";
  position: absolute;
  inset: 6px;
  border: 1px dashed rgba(255, 255, 255, 0.55);
  border-radius: 999px;
  pointer-events: none;
}

.draw-button:hover:not(:disabled) {
  transform: translateY(-2px) scale(1.02);
  filter: brightness(1.05);
}

.draw-button:active:not(:disabled) {
  transform: translateY(3px) scale(0.99);
  filter: brightness(0.95);
}

.draw-button:focus-visible {
  outline: 4px solid rgba(255, 255, 255, 0.85);
  outline-offset: 3px;
}

.draw-button:disabled {
  opacity: 0.8;
  cursor: wait;
  animation: none;
}

.button-icon {
  width: 26px;
  height: 26px;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.button-icon--small {
  width: 20px;
  height: 20px;
}

.actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.flip-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: min(74vw, 300px);
  padding: 15px 30px 17px;
  border: 2px solid rgba(143, 77, 255, 0.32);
  border-radius: 999px;
  color: #6b2a86;
  background: rgba(255, 255, 255, 0.55);
  font-family: "ZCOOL KuaiLe", "Microsoft YaHei", sans-serif;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  box-shadow:
    0 10px 24px rgba(142, 61, 208, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
  transition:
    transform 0.2s ease,
    background 0.2s ease,
    opacity 0.2s ease;
}

.flip-button:hover:not(:disabled) {
  transform: translateY(-2px);
  background: rgba(255, 255, 255, 0.75);
}

.flip-button:active:not(:disabled) {
  transform: translateY(1px) scale(0.99);
}

.flip-button:focus-visible {
  outline: 4px solid rgba(255, 255, 255, 0.85);
  outline-offset: 3px;
}

.flip-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

@keyframes breathe {
  0%,
  100% {
    transform: translateY(0) scale(1);
    box-shadow:
      0 16px 34px rgba(142, 61, 208, 0.38),
      0 6px 0 rgba(102, 31, 154, 0.35),
      inset 0 2px 0 rgba(255, 255, 255, 0.55),
      inset 0 -7px 0 rgba(90, 14, 135, 0.22);
  }
  50% {
    transform: translateY(-4px) scale(1.035);
    box-shadow:
      0 22px 44px rgba(142, 61, 208, 0.46),
      0 6px 0 rgba(102, 31, 154, 0.35),
      inset 0 2px 0 rgba(255, 255, 255, 0.55),
      inset 0 -7px 0 rgba(90, 14, 135, 0.22);
  }
}

@media (max-width: 380px) {
  .brand {
    font-size: 2.15rem;
  }

  .card-scene {
    width: min(66vw, 236px);
  }

  .draw-button {
    min-width: 78vw;
    padding: 16px 24px 18px;
    font-size: 1.4rem;
  }

  .flip-button {
    min-width: 78vw;
    padding: 14px 24px 16px;
    font-size: 1.15rem;
  }
}

@media (min-width: 760px) {
  .card-scene {
    width: 292px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0.01ms !important;
  }

  .draw-button {
    animation: none;
  }
}
