.hearts-main {
  max-width: 720px;
}

.hearts-main .header {
  margin-bottom: 0.25rem;
}

.title-heart {
  font-size: 2.2rem;
  line-height: 1;
  color: var(--primary);
  display: inline-block;
  animation: wiggle 2.4s ease-in-out infinite;
}

/* ---------- HUD ---------- */

.hearts-hud {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 0.9rem;
  margin-bottom: 0.9rem;
}

.hearts-hud .stat {
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  font-size: 0.92rem;
  box-shadow: var(--shadow);
  white-space: nowrap;
}

.hearts-hud .stat.best {
  border-color: var(--pick-border);
  background: var(--pick-bg);
}

.stat-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-right: 0.15rem;
}

#new-game {
  padding: 0.4rem 1rem;
  font-size: 0.9rem;
  font-weight: 700;
}

#sound-pill { margin-left: auto; }
#sound-pill input { display: none; }
#sound-pill.off { background: var(--btn); border-color: var(--border); color: var(--muted); }

/* ---------- Table ---------- */

.table {
  position: relative;
  display: grid;
  /* minmax(0,1fr) lets the centre column shrink below the hand's natural width
     so the player's fan wraps instead of blowing the table past the viewport. */
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    ".    north  ."
    "west center east"
    "south south south";
  gap: 0.4rem;
  align-items: center;
  justify-items: center;
  background: radial-gradient(circle at 50% 45%, #2f9e6b 0%, #1f8055 70%);
  border: 3px solid #15633f;
  border-radius: 24px;
  padding: 0.8rem;
  box-shadow: var(--shadow);
  min-height: 480px;
}

.seat-n { grid-area: north; }
.seat-w { grid-area: west; }
.seat-e { grid-area: east; }
.seat-s { grid-area: south; justify-self: stretch; width: 100%; }
.trick  { grid-area: center; }

.seat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
}

.seat-w, .seat-e { flex-direction: column; }

.seat-info {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  background: rgba(0, 0, 0, 0.22);
  color: #fff;
  border-radius: 999px;
  padding: 0.18rem 0.7rem;
  font-size: 0.85rem;
  font-weight: 700;
  white-space: nowrap;
}

.seat.active .seat-info {
  background: var(--primary);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.5);
}

/* Cute opponent faces */
.cat-face {
  width: 46px;
  height: 46px;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.28));
  transition: transform 0.2s ease;
}

.cat-face svg { width: 100%; height: 100%; display: block; }

.seat.active .cat-face { transform: translateY(-3px) scale(1.08); }

.seat-score {
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
  border-radius: 999px;
  padding: 0 0.45rem;
  font-variant-numeric: tabular-nums;
  font-size: 0.8rem;
}

/* ---------- Cards ---------- */

:root {
  --card-w: 58px;
  --card-h: 82px;
}

.card {
  position: relative;
  width: var(--card-w);
  height: var(--card-h);
  border-radius: 8px;
  background: #fff;            /* a playing card is white in any theme */
  border: 1px solid #d8d8e0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  font-family: "Fredoka", "Nunito", sans-serif;
  font-weight: 600;
  color: #2e2d4d;
  user-select: none;
  -webkit-user-select: none;
  flex-shrink: 0;
}

.card.red { color: #e23b5a; }

.card .corner {
  position: absolute;
  font-size: 0.82rem;
  line-height: 0.92;
  text-align: center;
}

.card .corner.tl { top: 3px; left: 4px; }
.card .corner.br { bottom: 3px; right: 4px; transform: rotate(180deg); }

.card .pip {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
}

/* Card back for opponents — a little fish on a pink card */
.back {
  width: var(--card-w);
  height: var(--card-h);
  border-radius: 8px;
  background: linear-gradient(145deg, #ffa9c4 0%, #ff6b9d 100%);
  border: 2px solid #fff;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.35), 0 1px 3px rgba(0, 0, 0, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Only the front card of a fan carries the fish (added in JS), so the overlap
   doesn't pile up into an unreadable jumble. */
.back svg {
  width: 78%;
  height: auto;
  display: block;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.18));
}

/* Opponent fans */
.hand.backs { display: flex; }
.seat-n .hand.backs { flex-direction: row; }
.seat-n .hand.backs .back:not(:first-child) { margin-left: -34px; }
/* Side fans grow downward (overlap < card height) so they never ride up over
   the name pill above them. */
.seat-w .hand.backs, .seat-e .hand.backs { flex-direction: column; }
.seat-w .hand.backs .back:not(:first-child),
.seat-e .hand.backs .back:not(:first-child) { margin-top: -52px; }

/* Shrink opponent cards a touch */
.seat-n .back, .seat-w .back, .seat-e .back {
  width: 44px;
  height: 62px;
}

/* ---------- Trick (center) ---------- */

.trick {
  position: relative;
  width: 190px;
  height: 200px;
  perspective: 700px;
}

.trick .card {
  position: absolute;
  /* Centre with calc (not transform) so the flip animation has the transform
     property to itself — no fighting, no snapping into place. */
  transform-origin: center top;
  animation: flipIn 0.36s cubic-bezier(0.22, 0.61, 0.36, 1) both;
  transition: box-shadow 0.25s ease;
}

.trick .from-0 { bottom: 0; left: calc(50% - var(--card-w) / 2); }
.trick .from-2 { top: 0;    left: calc(50% - var(--card-w) / 2); }
.trick .from-1 { left: 0;   top: calc(50% - var(--card-h) / 2); }
.trick .from-3 { right: 0;  top: calc(50% - var(--card-h) / 2); }

@keyframes flipIn {
  0%   { opacity: 0; transform: translateY(-9px) rotateX(58deg) scale(0.94); }
  100% { opacity: 1; transform: translateY(0)    rotateX(0deg)  scale(1); }
}

.trick .winner { box-shadow: 0 0 0 3px var(--primary), 0 2px 10px rgba(0, 0, 0, 0.3); }

@media (prefers-reduced-motion: reduce) {
  .trick .card { animation-duration: 0.01ms; }
}

/* ---------- Player hand ---------- */

.player-hand {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  row-gap: 0.3rem;
  width: 100%;
  max-width: 100%;
}

.player-hand .card {
  cursor: default;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

/* Modest overlap so each card still exposes a wide, full-height click target. */
.player-hand .card:not(:first-child) { margin-left: -14px; }

.player-hand .card.playable {
  cursor: pointer;
}

.player-hand .card.playable:hover {
  transform: translateY(-12px);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.3);
  z-index: 5;
}

.player-hand .card.disabled {
  filter: grayscale(0.55) brightness(0.86);
}

.player-hand .card.selected {
  transform: translateY(-16px);
  box-shadow: 0 0 0 3px var(--primary), 0 6px 14px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  z-index: 6;
}

/* ---------- Pass bar ---------- */

.pass-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.9rem;
  margin-top: 0.9rem;
  font-weight: 700;
  color: var(--ink);
}

.pass-bar.hidden { display: none; }

.primary-pass {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  font-weight: 700;
  padding: 0.5rem 1.5rem;
}

.primary-pass:hover:not(:disabled) {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
}

.primary-pass:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Status ---------- */

.status {
  text-align: center;
  font-weight: 700;
  color: var(--primary-dark);
  min-height: 1.4em;
  margin: 0.9rem 0 0;
}

/* ---------- Toast + overlay ---------- */

.hearts-toast {
  position: absolute;
  top: 0.6rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: 999px;
  padding: 0.35rem 1rem;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--primary-dark);
  box-shadow: var(--shadow);
  pointer-events: none;
  z-index: 20;
  animation: cardPop 0.3s cubic-bezier(0.17, 0.89, 0.32, 1.275);
}
.hearts-toast.hidden { display: none; }

.hearts-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 0.5rem;
  padding: 1.5rem;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(3px);
  border-radius: 24px;
  z-index: 30;
}
.hearts-overlay.hidden { display: none; }

.hearts-overlay h2 {
  margin: 0;
  font-family: "Fredoka", "Nunito", sans-serif;
  font-weight: 600;
  font-size: 2rem;
  color: var(--ink);
}

.hearts-overlay #overlay-body { color: var(--muted); max-width: 40ch; }

.score-table {
  border-collapse: collapse;
  margin: 0.4rem auto;
  font-size: 0.95rem;
}
.score-table th, .score-table td {
  padding: 0.3rem 0.9rem;
  text-align: center;
  border-bottom: 1px solid var(--border);
  color: var(--ink);
}
.score-table th { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; }
.score-table .you { font-weight: 800; color: var(--primary-dark); }
.score-table tr.leader td { background: var(--pick-bg); }

.hearts-overlay button {
  font-family: "Fredoka", "Nunito", sans-serif;
  font-size: 1.05rem;
  font-weight: 500;
  padding: 0.6rem 1.8rem;
  border: none;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  box-shadow: var(--shadow);
  margin-top: 0.4rem;
}
.hearts-overlay button:hover { background: var(--primary-dark); transform: translateY(-1px); }

/* ---------- How to play ---------- */

.how-to {
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: 20px;
  padding: 1.25rem 1.4rem 1.1rem;
  margin-top: 1.5rem;
  box-shadow: var(--shadow);
}
.how-to h2 {
  margin: 0 0 0.6rem;
  font-family: "Fredoka", "Nunito", sans-serif;
  font-size: 1.15rem;
  font-weight: 500;
}
.how-to ul { margin: 0; padding-left: 1.2rem; color: var(--muted); }
.how-to li { margin-bottom: 0.35rem; }
.how-to b { color: var(--ink); }

/* ---------- Responsive ---------- */

@media (max-width: 560px) {
  :root { --card-w: 44px; --card-h: 62px; }
  .card .pip { font-size: 1.3rem; }
  .card .corner { font-size: 0.66rem; }
  .player-hand .card:not(:first-child) { margin-left: -18px; }
  .seat-n .back, .seat-w .back, .seat-e .back { width: 32px; height: 46px; }
  .seat-n .hand.backs .back:not(:first-child) { margin-left: -24px; }
  .seat-w .hand.backs .back:not(:first-child),
  .seat-e .hand.backs .back:not(:first-child) { margin-top: -36px; }
  .trick { width: 132px; height: 158px; }
  .table { min-height: 420px; padding: 0.5rem; gap: 0.25rem; }
  .seat-info { font-size: 0.74rem; padding: 0.15rem 0.5rem; gap: 0.3rem; }
  .cat-face { width: 36px; height: 36px; }
}
