:root {
  color-scheme: dark;
  --felt-deep: oklch(21% 0.055 161);
  --felt: oklch(31% 0.07 159);
  --felt-light: oklch(39% 0.078 157);
  --cream: oklch(95% 0.025 88);
  --ink: oklch(24% 0.025 55);
  --muted: oklch(77% 0.035 154);
  --gold: oklch(79% 0.13 85);
  --red: oklch(58% 0.22 28);
  --black-suit: oklch(25% 0.018 250);
  --success: oklch(76% 0.16 140);
  --danger: oklch(68% 0.18 29);
  --space: clamp(16px, 4vw, 24px);
  --r-sm: 10px;
  --r-md: 18px;
  --r-lg: 28px;
  --r-pill: 999px;
  font-family: Avenir Next, Avenir, -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans SC", sans-serif;
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--felt-deep); }

body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  color: var(--cream);
  background:
    radial-gradient(circle at 50% 38%, color-mix(in oklch, var(--felt-light) 55%, transparent) 0, transparent 46%),
    repeating-radial-gradient(circle at 30% 20%, transparent 0 3px, rgba(255,255,255,.012) 4px 5px),
    var(--felt-deep);
  overscroll-behavior: none;
  touch-action: manipulation;
}

button { font: inherit; }

button:focus-visible, a:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 8px;
  left: 8px;
  padding: 10px 14px;
  color: var(--ink);
  background: var(--cream);
  border-radius: var(--r-sm);
  transform: translateY(-150%);
}

.skip-link:focus { transform: translateY(0); }

.game-shell {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(100%, 520px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 14px) var(--space) calc(env(safe-area-inset-bottom) + 18px);
  overflow: hidden;
}

.topbar, .brand, .scoreboard, .round-line, .answer-heading, .primary-button {
  display: flex;
  align-items: center;
}

.topbar { justify-content: space-between; }

.brand { gap: 10px; }

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  color: var(--felt-deep);
  font-family: Georgia, "Songti SC", serif;
  font-size: 25px;
  background: var(--gold);
  border-radius: 50% 50% 44% 44%;
  box-shadow: inset 0 -3px 0 rgba(70, 42, 0, .25), 0 5px 20px rgba(0,0,0,.18);
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--gold);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: .15em;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 20px; line-height: 1.05; }
h2 { margin-bottom: 0; font-size: 24px; letter-spacing: -.012em; text-wrap: balance; }

.icon-button {
  display: grid;
  width: 42px;
  height: 42px;
  padding: 0;
  place-items: center;
  color: var(--cream);
  font-size: 21px;
  border: 0;
  border-radius: 50%;
  background: rgba(255,255,255,.08);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.08);
  transition: transform 140ms ease-out, background-color 140ms ease-out;
}

.icon-button[aria-pressed="true"] { color: var(--felt-deep); background: var(--gold); }
.icon-button:active, .primary-button:active, .option-button:active, .install-button:active { transform: scale(.96); }

.scoreboard {
  justify-content: space-around;
  margin-top: 18px;
  padding: 10px 6px;
  background: rgba(255,255,255,.045);
  border-radius: var(--r-md);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.06);
}

.score-item { min-width: 70px; text-align: center; }
.score-item span { display: block; color: var(--muted); font-size: 11px; }
.score-item strong { font-size: 22px; font-variant-numeric: tabular-nums; line-height: 1.15; }
.score-divider { width: 1px; height: 24px; background: rgba(255,255,255,.11); }

.table {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 350px;
  padding-top: 18px;
}

.table-glow {
  position: absolute;
  inset: 54px 11% auto;
  height: min(58vw, 290px);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(231, 202, 99, .13), transparent 66%);
  animation: breathe 3.2s ease-in-out infinite alternate;
  pointer-events: none;
}

.orbit {
  position: absolute;
  inset: 48% auto auto 50%;
  width: min(82vw, 410px);
  aspect-ratio: 1;
  border: 1px solid rgba(231, 202, 99, .09);
  border-radius: 50%;
  opacity: .7;
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.orbit::before { content: ""; position: absolute; inset: 11%; border: 1px dashed rgba(255,255,255,.045); border-radius: 50%; }
.orbit span { position: absolute; color: rgba(246,240,215,.14); font-family: Georgia, serif; font-size: 15px; }
.orbit span:first-child { top: -8px; left: 50%; }
.orbit span:last-child { right: -7px; bottom: 42%; }
.orbit-one { animation: orbit-spin 18s linear infinite; }
.orbit-two { width: min(64vw, 320px); opacity: .45; animation: orbit-spin-reverse 14s linear infinite; }

.shockwave {
  position: absolute;
  z-index: 2;
  inset: 48% auto auto 50%;
  width: 180px;
  aspect-ratio: 1;
  border: 2px solid var(--gold);
  border-radius: 50%;
  opacity: 0;
  transform: translate(-50%, -50%) scale(.6);
  pointer-events: none;
}
.shockwave.burst { animation: shockwave 760ms cubic-bezier(.16,1,.3,1) both; }

.round-line { justify-content: space-between; color: var(--muted); font-size: 12px; font-weight: 650; }
.round-line span:last-child { color: var(--gold); }

.card-stage {
  position: relative;
  display: grid;
  flex: 1;
  min-height: 256px;
  place-items: center;
  perspective: 1000px;
}

.playing-card {
  position: relative;
  width: clamp(156px, 45vw, 206px);
  aspect-ratio: 5 / 7;
  color: var(--ink);
  -webkit-transform-style: preserve-3d;
  transform-style: preserve-3d;
  transition: transform 520ms cubic-bezier(.16,1,.3,1), opacity 180ms ease-out;
}

.playing-card.is-back { transform: rotateY(180deg); }
.playing-card.is-back.is-concealed { transition: none; transform: rotateY(180deg); }
.playing-card.is-dealing { animation: deal-in 520ms cubic-bezier(.16,1,.3,1); }
.playing-card.is-celebrating { animation: card-celebrate 820ms cubic-bezier(.16,1,.3,1); }

.card-face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  border-radius: var(--r-lg);
  background: var(--cream);
  box-shadow: 0 22px 55px rgba(0,0,0,.35), 0 3px 0 rgba(255,255,255,.55) inset;
}

.card-front { -webkit-transform: rotateY(0deg); transform: rotateY(0deg); }
.playing-card.is-back.is-concealed .card-front { visibility: hidden; opacity: 0; }

.card-front::after {
  content: "";
  position: absolute;
  inset: 7px;
  border: 1px solid color-mix(in oklch, currentColor 12%, transparent);
  border-radius: 22px;
  pointer-events: none;
}
.card-front::before {
  content: "";
  position: absolute;
  z-index: 3;
  inset: -25% -85%;
  background: linear-gradient(105deg, transparent 40%, rgba(255,255,255,.72) 50%, transparent 60%);
  opacity: 0;
  transform: translateX(-28%) rotate(8deg);
  pointer-events: none;
}
.playing-card.is-dealing .card-front::before,
.playing-card.is-celebrating .card-front::before { animation: card-shine 760ms 110ms ease-out both; }

.card-back { padding: 10px; -webkit-transform: rotateY(180deg); transform: rotateY(180deg); background: var(--cream); }
.back-frame {
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  align-content: center;
  gap: 10px;
  color: var(--cream);
  font-family: Georgia, "Songti SC", serif;
  font-size: 36px;
  font-weight: 800;
  background:
    repeating-linear-gradient(45deg, transparent 0 9px, rgba(255,255,255,.055) 9px 11px),
    var(--red);
  border-radius: 20px;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.72), inset 0 0 0 7px var(--red), inset 0 0 0 8px rgba(255,255,255,.45);
}
.back-frame i { display: block; width: 34px; height: 2px; background: var(--gold); }

.card-corner {
  position: absolute;
  z-index: 1;
  display: grid;
  justify-items: center;
  left: 18px;
  top: 15px;
  font-family: Georgia, "Songti SC", serif;
  font-weight: 700;
  line-height: .9;
}
.card-corner-bottom { inset: auto 18px 15px auto; transform: rotate(180deg); }
.card-rank { font-size: 30px; letter-spacing: -.04em; }
.card-suit { margin-top: 5px; font-size: 23px; }
.card-center-suit { position: absolute; inset: 50% auto auto 50%; font-family: Georgia, serif; font-size: 76px; transform: translate(-50%, -50%); }
.playing-card.is-red { color: var(--red); }
.playing-card.is-black { color: var(--black-suit); }

.count-badge {
  position: absolute;
  z-index: 3;
  bottom: 5px;
  padding: 7px 12px;
  color: var(--felt-deep);
  font-size: 11px;
  font-weight: 800;
  background: var(--gold);
  border-radius: var(--r-pill);
  box-shadow: 0 6px 18px rgba(0,0,0,.24);
  transform: translateY(0);
}
.count-badge.is-popping { animation: badge-pop 460ms cubic-bezier(.16,1,.3,1); }

.card-shadow {
  position: absolute;
  z-index: -1;
  width: clamp(136px, 42vw, 190px);
  height: 28px;
  margin-top: min(67vw, 300px);
  border-radius: 50%;
  background: rgba(0,0,0,.34);
  filter: blur(11px);
  transform: scale(.86);
  animation: shadow-float 2.6s ease-in-out infinite alternate;
}

.instruction {
  min-height: 24px;
  margin: 4px auto 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
  text-align: center;
  text-wrap: balance;
}

.start-panel, .answer-panel {
  position: relative;
  z-index: 5;
  margin: auto calc(var(--space) * -1) calc(env(safe-area-inset-bottom) * -1 - 18px);
  padding: 22px var(--space) calc(env(safe-area-inset-bottom) + 20px);
  color: var(--ink);
  background: var(--cream);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  box-shadow: 0 -16px 50px rgba(0,0,0,.2);
  animation: panel-rise 480ms cubic-bezier(.16,1,.3,1) both;
}

.start-panel p:not(.eyebrow) { margin: 8px 0 16px; color: oklch(42% 0.03 80); font-size: 13px; line-height: 1.7; text-wrap: pretty; }
.start-panel .eyebrow, .answer-panel .eyebrow { color: var(--red); }

.primary-button {
  width: 100%;
  min-height: 54px;
  justify-content: space-between;
  padding: 0 18px 0 20px;
  color: var(--cream);
  font-weight: 800;
  border: 0;
  border-radius: var(--r-md);
  background: var(--red);
  box-shadow: 0 8px 0 color-mix(in oklch, var(--red) 70%, black), 0 14px 24px rgba(80,10,12,.2);
  transition: transform 120ms ease-out, box-shadow 120ms ease-out;
}

.primary-button:active { box-shadow: 0 3px 0 color-mix(in oklch, var(--red) 70%, black), 0 8px 18px rgba(80,10,12,.18); }
.primary-button span:last-child { font-size: 24px; }

.install-button {
  width: 100%;
  min-height: 44px;
  margin-top: 14px;
  color: var(--ink);
  font-weight: 700;
  border: 1px solid color-mix(in oklch, var(--ink) 18%, transparent);
  border-radius: var(--r-md);
  background: transparent;
  transition: transform 120ms ease-out, background-color 120ms ease-out;
}

.answer-panel { padding-top: 17px; }
.answer-heading { justify-content: space-between; margin-bottom: 12px; }
.selection-preview { color: oklch(43% 0.03 80); font-family: Georgia, "Songti SC", serif; font-size: 14px; }
fieldset { min-width: 0; margin: 0 0 12px; padding: 0; border: 0; }
legend { margin-bottom: 7px; color: oklch(45% 0.03 80); font-size: 11px; font-weight: 700; }
.suit-options, .rank-options { display: grid; gap: 8px; }
.suit-options { grid-template-columns: repeat(4, 1fr); }
.rank-options { grid-template-columns: repeat(4, 1fr); }

.option-button {
  min-width: 0;
  min-height: 48px;
  padding: 6px 3px;
  color: var(--ink);
  font-family: Georgia, "Songti SC", serif;
  font-size: 18px;
  font-weight: 700;
  border: 0;
  border-radius: var(--r-sm);
  background: oklch(89% 0.025 88);
  box-shadow: inset 0 0 0 1px rgba(45,32,20,.08);
  transition: transform 120ms ease-out, background-color 120ms ease-out, box-shadow 120ms ease-out;
}
.option-button small { display: block; margin-top: 1px; font-family: inherit; font-size: 9px; font-weight: 650; }
.option-button.red { color: var(--red); }
.option-button.selected { color: var(--cream); background: var(--felt); box-shadow: 0 5px 0 var(--felt-deep); }

.feedback {
  position: fixed;
  z-index: 50;
  top: 22%;
  left: 50%;
  display: none;
  width: max-content;
  max-width: calc(100vw - 40px);
  padding: 13px 20px;
  color: var(--felt-deep);
  font-size: 19px;
  font-weight: 900;
  background: var(--success);
  border-radius: var(--r-pill);
  box-shadow: 0 15px 50px rgba(0,0,0,.35);
  transform: translate(-50%, 0);
}
.feedback.show { display: block; animation: feedback-in 900ms cubic-bezier(.16,1,.3,1) both; }
.feedback.wrong { color: var(--cream); background: var(--danger); }

.confetti { position: fixed; z-index: 40; inset: 0; overflow: hidden; pointer-events: none; }
.confetti-piece { position: absolute; top: 28%; left: 50%; width: 8px; height: 13px; border-radius: 2px; animation: confetti-pop 900ms cubic-bezier(.16,1,.3,1) forwards; }

[hidden] { display: none !important; }

@keyframes breathe { from { transform: scale(.92); opacity: .55; } to { transform: scale(1.08); opacity: 1; } }
@keyframes orbit-spin { from { transform: translate(-50%, -50%) rotate(0); } to { transform: translate(-50%, -50%) rotate(360deg); } }
@keyframes orbit-spin-reverse { from { transform: translate(-50%, -50%) rotate(360deg); } to { transform: translate(-50%, -50%) rotate(0); } }
@keyframes deal-in { 0% { opacity: 0; transform: translateX(var(--deal-x, 58px)) translateY(18px) rotateY(-18deg) rotateZ(var(--deal-r, 6deg)) scale(.9); } 62% { opacity: 1; transform: translateX(-4px) translateY(-3px) rotateY(2deg) rotateZ(-.8deg) scale(1.015); } 100% { opacity: 1; transform: translateX(0) translateY(0) rotateY(0) rotateZ(0) scale(1); } }
@keyframes card-shine { 0% { opacity: 0; transform: translateX(-28%) rotate(8deg); } 30% { opacity: .85; } 100% { opacity: 0; transform: translateX(28%) rotate(8deg); } }
@keyframes card-celebrate { 0% { transform: scale(1) rotateZ(0); } 34% { transform: scale(1.09) rotateZ(-2deg); } 68% { transform: scale(1.025) rotateZ(1deg); } 100% { transform: scale(1) rotateZ(0); } }
@keyframes shadow-float { from { opacity: .62; transform: scale(.78); } to { opacity: .9; transform: scale(.96); } }
@keyframes shockwave { 0% { opacity: .9; transform: translate(-50%, -50%) scale(.55); } 100% { opacity: 0; transform: translate(-50%, -50%) scale(2.7); } }
@keyframes badge-pop { 0% { opacity: 0; transform: translateY(8px) scale(.8); } 100% { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes panel-rise { from { opacity: 0; transform: translateY(34px); } to { opacity: 1; transform: translateY(0); } }
@keyframes feedback-in { 0% { opacity: 0; transform: translate(-50%, 18px) scale(.75); } 25%, 70% { opacity: 1; transform: translate(-50%, 0) scale(1); } 100% { opacity: 0; transform: translate(-50%, -10px) scale(.96); } }
@keyframes confetti-pop { 0% { opacity: 1; transform: translate(0,0) rotate(0); } 100% { opacity: 0; transform: translate(var(--x), var(--y)) rotate(var(--r)); } }

@media (min-height: 760px) {
  .table { min-height: 400px; }
  .card-stage { min-height: 300px; }
}

@media (max-height: 700px) {
  .game-shell { padding-top: calc(env(safe-area-inset-top) + 8px); }
  .scoreboard { margin-top: 10px; padding-block: 7px; }
  .table { min-height: 300px; padding-top: 10px; }
  .card-stage { min-height: 220px; }
  .playing-card { width: 145px; }
  .instruction { margin-bottom: 6px; }
  .start-panel, .answer-panel { padding-top: 14px; }
  .answer-heading { margin-bottom: 8px; }
  fieldset { margin-bottom: 8px; }
  .option-button { min-height: 43px; }
}

@media (hover: hover) {
  .icon-button:hover { background: rgba(255,255,255,.14); }
  .option-button:hover { background: oklch(86% 0.035 88); }
  .install-button:hover { background: oklch(91% 0.025 88); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
