:root {
  color-scheme: light;
  --ink: #26313d;
  --muted: #718093;
  --line: #eadfca;
  --paper: #fff9ea;
  --felt: #71c7a8;
  --felt-dark: #3f9a87;
  --gold: #f1a72b;
  --red: #ee5f73;
  --blue: #4a90e2;
  --panel: #ffffff;
  --shadow: 0 12px 28px rgba(83, 98, 122, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  background:
    linear-gradient(135deg, #fff0b8 0%, #bff1df 52%, #b9dcff 100%);
  color: var(--ink);
  text-align: center;
}

body::before {
  content: "♠  ♥  ♣  ♦";
  position: fixed;
  inset: auto 0 18px;
  z-index: -1;
  color: rgba(255, 255, 255, 0.34);
  font-size: 54px;
  font-weight: 900;
  letter-spacing: 18px;
  pointer-events: none;
  animation: suit-drift 9s ease-in-out infinite alternate;
}

button {
  font: inherit;
}

.app-shell {
  width: min(100%, 520px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom));
  animation: page-rise 420ms ease both;
}

.top-bar,
.score-panel,
.play-area,
.preview-panel {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.72);
  box-shadow: var(--shadow);
  transform-origin: center;
}

.top-bar {
  position: relative;
  display: grid;
  align-items: center;
  justify-items: center;
  padding: 16px;
  border-radius: 8px 8px 0 0;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 16px;
}

.icon-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
}

.score-bump {
  animation: soft-pop 360ms ease both;
}

.level-clear {
  animation: clear-flash 420ms ease both;
}

.score-panel {
  position: relative;
  margin-top: 10px;
  padding: 14px 16px;
  border-radius: 8px;
}

.score-float {
  position: absolute;
  left: 50%;
  top: 10px;
  z-index: 2;
  padding: 4px 12px;
  border-radius: 999px;
  background: #fff2b8;
  color: #e68c20;
  font-size: 20px;
  font-weight: 900;
  box-shadow: 0 8px 18px rgba(83, 98, 122, 0.18);
  pointer-events: none;
  transform: translateX(-50%);
  animation: score-float 900ms ease-out both;
}

.score-main {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
  font-weight: 900;
  font-size: 42px;
}

.number-bump {
  animation: number-pop 360ms ease both;
}

.score-main small {
  color: var(--muted);
  font-size: 18px;
}

.meter {
  height: 12px;
  margin: 10px 0;
  overflow: hidden;
  border-radius: 999px;
  background: #e9edf1;
}

.meter > div {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #ffbe4d, #5fd6a7, #7cc5ff, #ffbe4d);
  background-size: 220% 100%;
  animation: meter-flow 2.4s linear infinite;
  transition: width 220ms ease;
}

.score-row,
.section-head {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.play-area {
  margin-top: 12px;
  padding: 14px;
  border-radius: 8px;
}

.hand {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.card {
  position: relative;
  display: grid;
  align-content: space-between;
  justify-items: center;
  aspect-ratio: 0.74;
  min-width: 0;
  padding: 8px;
  border: 1px solid #d9d2c1;
  border-radius: 8px;
  background:
    linear-gradient(145deg, #fff 0%, #fff7df 100%);
  box-shadow: 0 6px 12px rgba(83, 98, 122, 0.14);
  color: var(--ink);
  cursor: pointer;
  transform: translateY(0) rotate(0deg);
  animation: card-deal 360ms cubic-bezier(.2,.9,.2,1.2) both;
  animation-delay: calc(var(--i) * 42ms);
  transition: transform 170ms ease, box-shadow 170ms ease, border-color 170ms ease, filter 170ms ease;
}

.card::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(120deg, transparent 20%, rgba(255,255,255,0.72) 46%, transparent 70%);
  opacity: 0;
  transform: translateX(-60%);
  pointer-events: none;
}

.card:hover {
  filter: brightness(1.03);
  transform: translateY(-4px) rotate(-1deg);
}

.card:hover::after {
  animation: card-shine 700ms ease;
}

.card.red {
  color: var(--red);
}

.card.joker {
  color: #a85d00;
  background:
    linear-gradient(145deg, #fff8dc 0%, #ffd37c 100%);
}

.card.selected {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(35, 100, 170, 0.25), 0 8px 16px rgba(23, 32, 42, 0.2);
  transform: translateY(-12px) rotate(-2deg);
  animation: select-hop 240ms ease both;
}

.card:active {
  transform: translateY(-2px) scale(0.97);
}

.rank {
  font-size: clamp(22px, 8vw, 34px);
  font-weight: 900;
  line-height: 1;
}

.suit {
  place-self: center;
  font-size: clamp(34px, 13vw, 56px);
  line-height: 1;
}

.card-name {
  max-width: 100%;
  color: currentColor;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.small-card {
  width: 56px;
  height: 78px;
  aspect-ratio: auto;
  padding: 5px;
}

.small-card .rank {
  font-size: 15px;
}

.small-card .suit {
  font-size: 24px;
}

.small-card .card-name {
  font-size: 9px;
}

.preview-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 10px;
  padding: 14px;
  border-radius: 8px;
  animation: panel-float 4.2s ease-in-out infinite;
}

#previewName {
  display: block;
  margin: 3px 0;
  font-size: 18px;
}

#previewDetail {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.preview-score {
  min-width: 62px;
  color: var(--gold);
  font-size: 36px;
  font-weight: 900;
  text-align: center;
  text-shadow: 0 3px 0 rgba(241, 167, 43, 0.16);
}

.actions {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

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

.primary-button,
.danger-button {
  display: grid;
  place-items: center;
  gap: 2px;
  min-height: 58px;
  padding: 7px 8px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  font-weight: 900;
  box-shadow: 0 10px 20px rgba(13, 36, 46, 0.18);
  transition: transform 150ms ease, box-shadow 150ms ease, filter 150ms ease;
}

.action-main {
  display: block;
  font-size: 20px;
  line-height: 1.1;
}

.action-sub {
  display: block;
  font-size: 12px;
  line-height: 1.2;
  opacity: 0.92;
}

.primary-button:not(:disabled):hover,
.danger-button:not(:disabled):hover {
  filter: brightness(1.04);
  transform: translateY(-2px);
  box-shadow: 0 13px 24px rgba(13, 36, 46, 0.2);
}

.primary-button:not(:disabled):active,
.danger-button:not(:disabled):active {
  transform: translateY(1px) scale(0.98);
}

.primary-button {
  background: var(--blue);
}

.danger-button {
  background: #a33f35;
}

button:disabled {
  cursor: not-allowed;
  filter: grayscale(0.65);
  opacity: 0.5;
  transform: none;
}

dialog {
  width: min(92vw, 520px);
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.48);
  animation: fade-in 180ms ease both;
}

.modal-card {
  max-height: min(78vh, 680px);
  overflow: auto;
  padding: 16px;
  border-radius: 8px;
  background: #fff;
  animation: modal-pop 240ms ease both;
}

.modal-head {
  position: sticky;
  top: -16px;
  z-index: 1;
  display: grid;
  align-items: center;
  justify-items: center;
  margin: -16px -16px 14px;
  padding: 14px 16px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.icon-button {
  position: absolute;
  right: 16px;
  width: 34px;
  height: 34px;
  font-size: 22px;
}

.pile-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.empty {
  color: var(--muted);
  line-height: 1.6;
}

.result-card {
  display: grid;
  gap: 12px;
}

.result-card h3 {
  color: var(--gold);
  font-size: 30px;
  animation: number-pop 520ms ease both;
}

.result-card pre {
  overflow: auto;
  margin: 0;
  padding: 14px;
  border-radius: 8px;
  background: var(--felt-dark);
  color: #fff;
  white-space: pre-wrap;
  line-height: 1.55;
}

.full {
  width: 100%;
}

@media (max-width: 390px) {
  .app-shell {
    padding-inline: 10px;
  }

  .hand {
    gap: 8px;
  }

  .card {
    padding: 7px;
  }

  .rank {
    font-size: clamp(20px, 8vw, 30px);
  }

  .suit {
    font-size: clamp(30px, 13vw, 48px);
  }

  .score-main {
    font-size: 36px;
  }

  .preview-panel,
  .play-area,
  .score-panel {
    padding: 12px;
  }
}

@keyframes page-rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes card-deal {
  from {
    opacity: 0;
    transform: translateY(18px) rotate(4deg) scale(0.92);
  }
  to {
    opacity: 1;
    transform: translateY(0) rotate(0deg) scale(1);
  }
}

@keyframes select-hop {
  0% {
    transform: translateY(0) scale(1);
  }
  60% {
    transform: translateY(-16px) scale(1.04);
  }
  100% {
    transform: translateY(-12px) rotate(-2deg) scale(1);
  }
}

@keyframes soft-pop {
  0% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.018);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes clear-flash {
  0% {
    box-shadow: var(--shadow);
  }
  45% {
    box-shadow: 0 0 0 5px rgba(255, 190, 77, 0.3), 0 16px 34px rgba(83, 98, 122, 0.2);
    transform: scale(1.022);
  }
  100% {
    box-shadow: var(--shadow);
    transform: scale(1);
  }
}

@keyframes score-float {
  0% {
    opacity: 0;
    transform: translate(-50%, 8px) scale(0.86);
  }
  18% {
    opacity: 1;
    transform: translate(-50%, -6px) scale(1.08);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -48px) scale(1);
  }
}

@keyframes number-pop {
  0% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.14);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes meter-flow {
  from {
    background-position: 0% 50%;
  }
  to {
    background-position: 220% 50%;
  }
}

@keyframes card-shine {
  0% {
    opacity: 0;
    transform: translateX(-70%);
  }
  35% {
    opacity: 0.72;
  }
  100% {
    opacity: 0;
    transform: translateX(70%);
  }
}

@keyframes panel-float {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-3px);
  }
}

@keyframes modal-pop {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes suit-drift {
  from {
    transform: translateY(0);
  }
  to {
    transform: translateY(-10px);
  }
}
