:root {
  color-scheme: dark;
  --felt: #186b51;
  --felt-dark: #0f3f32;
  --ink: #f8f4e8;
  --muted: #bdd2c7;
  --line: rgba(255, 255, 255, 0.22);
  --card: #fffaf0;
  --card-ink: #15120e;
  --red: #b7192a;
  --gold: #e1b84f;
  --shadow: rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 10%, rgba(225, 184, 79, 0.16), transparent 28rem),
    linear-gradient(135deg, var(--felt), var(--felt-dark));
}

button {
  border: 0;
  font: inherit;
  cursor: pointer;
}

.table {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(18rem, 24rem);
  gap: clamp(1rem, 3vw, 2rem);
  padding: clamp(1rem, 4vw, 3rem);
}

.play-area {
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  gap: clamp(1rem, 3vh, 2rem);
  min-width: 0;
}

.intro {
  max-width: 46rem;
}

.eyebrow {
  margin: 0 0 0.4rem;
  color: var(--gold);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.04;
}

h1 {
  font-size: clamp(2.15rem, 6vw, 5.6rem);
  max-width: 11ch;
}

h2 {
  font-size: 1.25rem;
}

.card-stage {
  display: grid;
  grid-template-columns: minmax(9rem, 15rem) minmax(13rem, 22rem);
  place-content: center;
  align-items: center;
  gap: clamp(1.25rem, 6vw, 4rem);
  min-height: 24rem;
}

.deck {
  position: relative;
  width: min(38vw, 12.5rem);
  min-width: 8.5rem;
  aspect-ratio: 5 / 7;
  background: transparent;
  transform: rotate(-7deg);
  transition: transform 180ms ease;
}

.deck:hover,
.deck:focus-visible {
  transform: rotate(-4deg) translateY(-0.25rem);
  outline: none;
}

.deck-layer,
.deck-top {
  position: absolute;
  inset: 0;
  border-radius: 0.55rem;
  box-shadow: 0 1.2rem 2rem var(--shadow);
}

.deck-layer:first-child {
  transform: translate(0.72rem, 0.72rem);
  background: #efe2c4;
}

.deck-layer:nth-child(2) {
  transform: translate(0.36rem, 0.36rem);
  background: #d9c99f;
}

.deck-top {
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 0.28rem solid #f7e9c6;
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.13) 25%, transparent 25% 50%, rgba(255, 255, 255, 0.13) 50% 75%, transparent 75%),
    #183e73;
  background-size: 1.2rem 1.2rem;
}

.deck-mark {
  display: grid;
  place-items: center;
  width: 42%;
  aspect-ratio: 1;
  border: 0.16rem solid rgba(255, 255, 255, 0.65);
  border-radius: 50%;
  color: #f7e9c6;
  font-size: clamp(2rem, 6vw, 4.5rem);
}

.card {
  width: min(58vw, 20rem);
  min-width: 13rem;
  aspect-ratio: 5 / 7;
  position: relative;
  display: grid;
  place-items: center;
  border-radius: 0.75rem;
  color: var(--card-ink);
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.95), rgba(255, 246, 225, 0.92)),
    var(--card);
  box-shadow: 0 1.6rem 3rem rgba(0, 0, 0, 0.38);
  transform: rotate(4deg);
  transition: transform 220ms ease, opacity 180ms ease;
}

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

.card.is-empty {
  opacity: 0.78;
  color: #7f7665;
}

.card.is-drawing {
  animation: draw 430ms ease;
}

@keyframes draw {
  0% {
    transform: translateX(-8rem) rotate(-18deg) scale(0.72);
    opacity: 0.3;
  }
  100% {
    transform: rotate(4deg) scale(1);
    opacity: 1;
  }
}

.corner {
  position: absolute;
  display: grid;
  justify-items: center;
  font-weight: 900;
  line-height: 0.95;
}

.corner.top {
  top: 1rem;
  left: 1rem;
}

.corner.bottom {
  right: 1rem;
  bottom: 1rem;
  transform: rotate(180deg);
}

.rank {
  font-size: clamp(1.6rem, 5vw, 2.9rem);
}

.suit {
  font-size: clamp(1.4rem, 4vw, 2.4rem);
}

.suit-center {
  font-size: clamp(5rem, 17vw, 11rem);
  line-height: 1;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
}

.controls button,
.icon-button {
  min-height: 2.8rem;
  border-radius: 0.5rem;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid var(--line);
  padding: 0.75rem 1rem;
  transition: transform 160ms ease, background 160ms ease;
}

.controls button:hover,
.controls button:focus-visible,
.icon-button:hover,
.icon-button:focus-visible {
  background: rgba(255, 255, 255, 0.2);
  outline: none;
  transform: translateY(-0.08rem);
}

.controls .primary {
  color: #1c170b;
  background: var(--gold);
  border-color: rgba(0, 0, 0, 0.16);
  font-weight: 800;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.7rem;
  margin: 0;
}

.stats div,
.history-panel {
  border: 1px solid var(--line);
  background: rgba(5, 28, 22, 0.42);
  backdrop-filter: blur(12px);
}

.stats div {
  min-height: 5rem;
  border-radius: 0.5rem;
  padding: 0.85rem;
}

dt {
  color: var(--muted);
  font-size: 0.78rem;
}

dd {
  margin: 0.2rem 0 0;
  font-size: clamp(1.25rem, 3vw, 1.8rem);
  font-weight: 900;
}

.history-panel {
  align-self: stretch;
  border-radius: 0.5rem;
  padding: 1rem;
  min-height: 0;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.icon-button {
  width: 2.35rem;
  min-height: 2.35rem;
  display: grid;
  place-items: center;
  padding: 0;
  font-size: 1.45rem;
}

.history {
  display: grid;
  gap: 0.5rem;
  max-height: calc(100vh - 8rem);
  overflow: auto;
  margin: 0;
  padding: 0;
  list-style: none;
}

.history li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  border-radius: 0.45rem;
  background: rgba(255, 255, 255, 0.1);
  padding: 0.7rem 0.8rem;
}

.history .mini-card {
  font-weight: 900;
}

.history .red {
  color: #ff9aa5;
}

.muted {
  color: var(--muted);
}

@media (max-width: 780px) {
  .table {
    grid-template-columns: 1fr;
  }

  h1 {
    max-width: 13ch;
  }

  .card-stage {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .deck {
    width: 8.7rem;
    justify-self: center;
  }

  .card {
    width: min(76vw, 18rem);
    justify-self: center;
  }

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

  .history {
    max-height: 18rem;
  }
}
