:root {
  --felt: #12513a;
  --felt-dark: #0c3b2a;
  --felt-light: #1a6a4d;
  --wood: #3b2a1c;
  --cream: #f6f0df;
  --ink: #1b1b1b;
  --red: #c0272d;
  --gold: #e0b341;
  --gold-dark: #b8892a;
  --ice: #8fd3ff;
  --panel: rgba(0, 0, 0, 0.22);
  --cw: 58px; /* card width; everything on a card scales from this */
}

* { box-sizing: border-box; }

/* Text is drawn 25% larger than the browser default; cards are sized in px and keep their size. */
html { background: var(--felt-dark); font-size: 125%; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--cream);
  background: radial-gradient(ellipse at 50% 20%, var(--felt-light), var(--felt) 45%, var(--felt-dark));
  background-attachment: fixed;
}

/* the whole table is drawn at 80% of its design size */
/* 1450px at 80% is 1160px wide: fits an 11-inch iPad in landscape (1180px). */
.app { zoom: 0.8; max-width: 1450px; margin: 0 auto; padding: 12px 14px 24px; }
.noscript { text-align: center; padding: 2rem; }

h1, h2 { font-weight: 600; margin: 0; }
h1 { font-family: Georgia, "Times New Roman", serif; font-size: 1.7rem; letter-spacing: 0.04em; }
h2 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; opacity: 0.75; }

/* ---------- top bar ---------- */
/* Top row of the table: title in the left corner, North in the middle, buttons in the right corner. */
.board-top { display: grid; grid-template-columns: 1fr auto 1fr; align-items: start; gap: 10px; }
.corner { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.corner-left { flex-direction: column; align-items: flex-start; gap: 2px; }
.corner-right { justify-content: flex-end; }
.corner .btn { padding: 6px 11px; }
.score { background: var(--panel); border-radius: 10px; padding: 5px 12px; display: flex; flex-direction: column; line-height: 1.15; min-width: 110px; }
.score.ours { outline: 1px solid rgba(224, 179, 65, 0.6); }
.score .who { font-size: 0.72rem; opacity: 0.8; }
.score b { font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.handinfo { font-size: 0.8rem; opacity: 0.75; }
/* Meld box heading: meld total (left), title (centre), game score (right). */
.melds-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.melds-head .corner-total { margin-top: 0; flex: none; }
.melds-title { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-weight: 600; font-size: 0.9rem;
  padding: 8px 14px; border-radius: 8px; cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.1); color: var(--cream);
}
.btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.2); }
.btn.primary { background: var(--gold); border-color: var(--gold-dark); color: #2a1d05; }
.btn.primary:hover:not(:disabled) { background: #ecc255; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn:focus-visible, .card:focus-visible, .meld:focus-visible, .stock:focus-visible, .pile:focus-visible {
  outline: 3px solid var(--ice); outline-offset: 2px;
}

/* ---------- cards ---------- */
.card {
  position: relative; display: inline-block; flex: none;
  width: var(--cw); height: calc(var(--cw) * 1.42);
  border-radius: calc(var(--cw) * 0.1);
  background: #fffdf6; color: var(--ink);
  border: 1px solid #c8c0ab;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
  padding: 0; font: inherit;
  vertical-align: top;
}
.card.red { color: var(--red); }
.card .idx {
  position: absolute; top: calc(var(--cw) * 0.06); left: calc(var(--cw) * 0.1);
  display: flex; flex-direction: column; align-items: center; line-height: 1;
  font-size: calc(var(--cw) * 0.3);
}
.card .idx { z-index: 1; } /* the corner stays on top of the big centre suit */
.card .idx b { font-weight: 700; }
.card .idx i { font-style: normal; font-size: 0.85em; }
.card .pip {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--cw) * 0.85); line-height: 1;
  padding-top: calc(var(--cw) * 0.42); /* sits a little below centre, clear of the corner */
}
.card.wild { background: #fff6d6; box-shadow: inset 0 0 0 2px var(--gold), 0 1px 3px rgba(0, 0, 0, 0.45); }
.card.joker { color: #6a2c91; background: #fff url("../img/joker.webp") center top / cover no-repeat; }
.card.joker .idx, .card.joker .pip { visibility: hidden; }
.card.joker .pip { font-size: calc(var(--cw) * 0.16); letter-spacing: 0.06em; font-weight: 700; }
.card.back {
  background:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.14) 0 3px, transparent 3px 6px),
    linear-gradient(135deg, #274c9c, #17306b);
  border: calc(var(--cw) * 0.07) solid #fffdf6;
}
.card.empty { background: rgba(255, 255, 255, 0.06); border: 2px dashed rgba(255, 255, 255, 0.3); box-shadow: none; }
.card.small { --cw: 34px; }
.card.big { --cw: 76px; }
.card.tiny { --cw: 24px; }
.card.tiny + .card.tiny { margin-left: -15px; }

button.card { cursor: pointer; transition: transform 0.12s ease; }
button.card:hover { transform: translateY(-4px); }
button.card.selected { transform: translateY(-16px); outline: 3px solid var(--gold); outline-offset: 0; }
.card.fresh { animation: pop 0.35s ease-out; }
@keyframes pop {
  0% { transform: scale(0.7) translateY(-10px); opacity: 0.2; }
  100% { transform: none; opacity: 1; }
}
/* Reduced motion: set by the Reduced motion button, which starts from the device setting. */
.reduced-motion .seat.active, .reduced-motion .card.fresh, .reduced-motion .meld.landed { animation: none; }
.reduced-motion button.card { transition: none; }

/* ---------- board ---------- */
.board {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(0, 0, 0, 0.12)), var(--felt);
  border: 10px solid var(--wood);
  border-radius: 24px;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.35), 0 8px 24px rgba(0, 0, 0, 0.35);
  padding: 14px 16px 16px;
  display: flex; flex-direction: column; gap: 14px;
}

.seat { text-align: center; padding: 6px 10px; border-radius: 12px; transition: background 0.2s; }
.seat { border: 2px solid transparent; }
.seat.active {
  background: rgba(224, 179, 65, 0.2);
  border-color: var(--gold);
  box-shadow: 0 0 22px rgba(224, 179, 65, 0.45), inset 0 0 14px rgba(224, 179, 65, 0.15);
  animation: seat-glow 1.6s ease-in-out infinite;
}
.seat.active .backs .card { outline: 2px solid var(--gold); }
@keyframes seat-glow { 50% { box-shadow: 0 0 30px rgba(224, 179, 65, 0.7), inset 0 0 18px rgba(224, 179, 65, 0.25); } }
.seat-name { font-weight: 600; font-size: 0.9rem; display: flex; align-items: center; justify-content: center; gap: 6px; }
.turn-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 8px var(--gold); }
.backs { display: flex; justify-content: center; margin: 6px 0 2px; min-height: 34px; padding-left: 15px; }
.seat-count { font-size: 0.78rem; opacity: 0.8; }

.middle { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; }
.center { text-align: center; }
.piles { display: flex; gap: 26px; justify-content: center; align-items: flex-start; }
.stock, .pile { background: none; border: 0; color: inherit; font: inherit; padding: 4px; border-radius: 10px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.stock.can, .pile.can { cursor: pointer; }
.stock.can:hover, .pile.can:hover { background: rgba(255, 255, 255, 0.09); }
.pile.drop { outline: 2px dashed rgba(224, 179, 65, 0.7); outline-offset: 2px; border-radius: 10px; }
.pile.drop:hover { background: rgba(224, 179, 65, 0.14); }
.stock .stack { display: inline-flex; width: calc(76px + 8px); height: calc(76px * 1.42 + 4px); position: relative; }
.stock .stack .card { --cw: 76px; position: absolute; }
.stock .stack .card:nth-of-type(1) { left: 0; top: 4px; }
.stock .stack .card:nth-of-type(2) { left: 4px; top: 2px; }
.stock .stack .card:nth-of-type(3) { left: 8px; top: 0; }
.pile-label { font-size: 0.78rem; opacity: 0.85; }
/* the discard pile; a wild card that froze it lies crosswise underneath */
/* sized and offset like the stock: the top card sits up and to the right,
   with plain card edges (.pile-under) showing beneath it */
.pile-stack { --pw: 76px; position: relative; display: block; width: calc(var(--pw) + 8px); height: calc(var(--pw) * 1.42 + 4px); }
.pile-stack.has-cross { margin: 0 calc(var(--pw) * 0.42) 0 calc(var(--pw) * 0.02); }
.pile-stack .card { position: absolute; left: 8px; top: 0; }
.pile-under {
  position: absolute; width: var(--pw); height: calc(var(--pw) * 1.42);
  border-radius: calc(var(--pw) * 0.1);
  background: #f3eedf; border: 1px solid #c8c0ab;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
}
.pile-under[data-layer="0"] { left: 0; top: 4px; }
.pile-under[data-layer="1"] { left: 4px; top: 2px; }
.pile-stack .card.top { z-index: 1; }
/* shifted right so its corner index sticks out from under the top card */
.pile-stack .card.crosswise { left: 50%; top: 50%; transform: translate(calc(-50% + var(--pw) * 0.2), -50%) rotate(90deg); }
.pile.frozen .card { box-shadow: 0 0 0 3px var(--ice), 0 0 16px 2px rgba(143, 211, 255, 0.7); }
.pile.blocked .card { box-shadow: 0 0 0 3px #e0605a, 0 1px 3px rgba(0, 0, 0, 0.45); }
.pile-status { margin-top: 8px; font-size: 0.82rem; min-height: 1.2em; opacity: 0.9; max-width: 290px; margin-left: auto; margin-right: auto; }
.pile-status.frozen { color: var(--ice); }
.pile-status.blocked { color: #ff9b95; }

/* ---------- melds ---------- */
.meld-areas { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.melds { background: var(--panel); border-radius: 14px; padding: 10px 12px 12px; min-height: 96px; }
.melds.ours { outline: 1px solid rgba(224, 179, 65, 0.4); }
.meld-total {
  justify-self: start; background: var(--panel); border-radius: 10px; padding: 5px 12px;
  display: flex; flex-direction: column; line-height: 1.15; min-width: 110px; font-variant-numeric: tabular-nums;
}
.meld-total.ours { outline: 1px solid rgba(224, 179, 65, 0.6); }
.meld-total .who { font-size: 0.72rem; opacity: 0.8; }
.meld-total b { font-size: 1.3rem; font-weight: 800; }
.meld-total .need { font-size: 0.72rem; opacity: 0.85; }
.meld-total.short b { color: #ffb4a8; }
.meld-total.met b { color: #9be8a6; }
.meld-list { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 6px 4px; margin-top: 8px; }
.none { margin: 0; font-size: 0.82rem; opacity: 0.55; }
/* Melds have no frame, so more fit across; hover and focus draw an outline,
   which takes no room. */
.meld {
  display: flex; flex-direction: column; align-items: center;
  background: none; border: 0; padding: 0; margin: 0;
  color: inherit; font: inherit; border-radius: 6px; text-align: center;
}
button.meld { cursor: pointer; }
button.meld:hover { outline: 2px solid var(--gold); outline-offset: 2px; }
/* six cards: one card away from a canasta */
.meld.one-short { background: rgba(224, 179, 65, 0.16); padding: 5px; border-radius: 9px; }
.meld.one-short .meld-cards { box-shadow: 0 0 0 3px var(--gold), 0 0 12px rgba(224, 179, 65, 0.55); border-radius: 6px; }
/* a canasta that has just been completed glows for three seconds */
.meld.just-completed .card { animation: canasta-glow 3s ease-in-out; }
@keyframes canasta-glow {
  0%, 100% { box-shadow: 0 1px 3px rgba(0, 0, 0, 0.45); }
  15%, 50%, 85% { box-shadow: 0 0 0 3px var(--gold), 0 0 22px 6px rgba(255, 214, 102, 0.9); }
  32%, 68% { box-shadow: 0 0 0 2px var(--gold), 0 0 10px 2px rgba(255, 214, 102, 0.5); }
}
.reduced-motion .meld.just-completed .card { animation: none; box-shadow: 0 0 0 3px var(--gold), 0 0 18px 4px rgba(255, 214, 102, 0.8); }
/* Each meld is a column: its cards cascade downwards, each showing just its
   corner, so many melds fit side by side in one row. */
.meld-cards { display: flex; flex-direction: column; }
/* Melded cards are drawn larger than other small cards. */
.meld .card.small { --cw: 54px; }
.reds .card.small { --cw: 54px; } /* same size as the melded cards */
.meld-cards .card + .card { margin-top: calc(var(--cw) * -1.13); }
/* The corner index reads across (rank then suit) so a narrow strip shows both. */
.meld-cards .card .idx { flex-direction: row; gap: 1px; align-items: baseline; top: calc(var(--cw) * 0.03); left: calc(var(--cw) * 0.08); font-size: calc(var(--cw) * 0.26); }

.meld.canasta .card.small { box-shadow: 3px 3px 0 -1px #fffdf6, 3px 3px 0 0 #8c846f, 6px 6px 0 -1px #fffdf6, 6px 6px 0 0 #8c846f; margin-right: 6px; margin-bottom: 6px; }

.meld.sequence .meld-cards .card + .card { margin-top: calc(var(--cw) * -1.13); }
.card.small.gap { background: transparent; border: 2px dashed rgba(246, 240, 223, 0.55); box-shadow: none; }
.meld.landed { animation: meld-land 0.45s ease-out; }
@keyframes meld-land { 40% { box-shadow: 0 0 0 3px var(--gold), 0 0 18px rgba(224, 179, 65, 0.6); } }
.reds { display: flex; flex-direction: column; align-self: flex-start; margin: 2px 2px 0; padding-top: 5px; font-size: 0.75rem; opacity: 0.9; }
.reds .card + .card { margin-top: calc(var(--cw) * -1.13); }
.reds .card .idx { flex-direction: row; gap: 1px; align-items: baseline; top: calc(var(--cw) * 0.03); left: calc(var(--cw) * 0.08); font-size: calc(var(--cw) * 0.26); }
.reds span { margin-left: 8px; }
/* On overlapped (stacked) cards the suit in the corner is as big as the rank. */
.meld-cards .card .idx i, .reds .card .idx i { font-size: 1em; }

/* ---------- your hand ---------- */
.player { background: var(--panel); border-radius: 16px; padding: 10px 14px 6px; border: 1px solid transparent; }
.player.active { border-color: rgba(224, 179, 65, 0.55); box-shadow: 0 0 18px rgba(224, 179, 65, 0.15); }
.status { font-weight: 600; min-height: 1.4em; margin-bottom: 4px; }
.out-ask {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 10px;
  margin: 6px 0; padding: 8px 12px; border-radius: 8px; font-size: 0.92rem;
  background: rgba(224, 179, 65, 0.18); border: 1px solid var(--gold);
}
.message { margin: 6px 0; padding: 7px 12px; border-radius: 8px; font-size: 0.88rem; }
.message.error { background: rgba(192, 39, 45, 0.35); border: 1px solid rgba(255, 130, 125, 0.6); }
.message.info { background: rgba(143, 211, 255, 0.18); border: 1px solid rgba(143, 211, 255, 0.5); }
.hand { --cw: 76px; /* same size as the discard pile */ display: flex; flex-wrap: wrap; gap: 8px 14px; padding: 20px 4px 8px; min-height: calc(var(--cw) * 1.42 + 30px); }
.hand-group { display: flex; }
.hand-group .card + .card { margin-left: calc(var(--cw) * -0.56); }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 6px; }
.selection { margin-left: auto; font-size: 0.82rem; opacity: 0.85; }

.log { margin-top: 14px; padding: 0 4px; font-size: 0.82rem; }
.log ul { list-style: none; margin: 6px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 2px 18px; }
.log li { opacity: 0.8; }
.log li:first-child { opacity: 1; font-weight: 600; }

/* ---------- modal ---------- */
.summary-overlay { position: fixed; left: 24px; top: 24px; z-index: 20; box-shadow: 0 16px 48px rgba(0, 0, 0, 0.55); }
.summary-overlay.dragging { user-select: none; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: move; touch-action: none; margin: -8px -8px 4px; padding: 8px; border-radius: 10px; }
.modal-head:hover { background: rgba(0, 0, 0, 0.04); }
.modal .close { background: none; border: 0; font-size: 1.8rem; line-height: 1; cursor: pointer; color: #6b6352; padding: 0 6px; border-radius: 6px; }
.modal .close:hover { background: rgba(0, 0, 0, 0.08); color: var(--ink); }
.end-bar { margin-top: 16px; background: var(--panel); border-radius: 18px; padding: 12px 16px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; border: 1px solid rgba(224, 179, 65, 0.55); }
.end-actions { display: flex; gap: 8px; }
.end-actions .btn.primary { padding: 10px 28px; font-size: 1rem; }
.modal { background: #fbf6e6; color: var(--ink); border-radius: 16px; padding: 22px 24px; max-width: 520px; width: 100%; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5); max-height: 92vh; overflow: auto; }
.modal h2 { font-family: Georgia, serif; font-size: 1.5rem; text-transform: none; letter-spacing: 0; opacity: 1; margin-bottom: 4px; }
.modal p { margin: 0 0 12px; }
.scoretable { width: 100%; border-collapse: collapse; margin-bottom: 16px; font-variant-numeric: tabular-nums; }
.scoretable th, .scoretable td { padding: 6px 8px; text-align: right; border-bottom: 1px solid #ddd3b8; }
.scoretable th, .scoretable td { font-weight: 700; }
.scoretable th:first-child { text-align: left; font-weight: 700; }
.scoretable thead th { font-size: 0.8rem; }
.scoretable tr.grand th, .scoretable tr.grand td { font-weight: 700; border-top: 2px solid #8c846f; border-bottom: 0; }
.modal .btn.primary { width: 100%; padding: 11px; font-size: 1rem; }
.modal { max-width: 640px; }
.left-in-hand { margin: 0 0 16px; }
.left-in-hand h3 { margin: 0 0 6px; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: #6b6352; }
.lih-row { display: grid; grid-template-columns: 52px 1fr auto; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid #ddd3b8; }
.lih-row:last-child { border-bottom: 0; }
.lih-name { font-weight: 600; font-size: 0.9rem; }
.lih-row.ours .lih-name { color: #8a6417; }
.lih-cards { display: flex; flex-wrap: wrap; row-gap: 4px; padding-left: 14px; min-height: 20px; }
.lih-cards .card { margin-left: -14px; }
.lih-pts { font-size: 0.85rem; font-variant-numeric: tabular-nums; color: #5a5242; white-space: nowrap; }

/* ---------- moving cards ---------- */
.flight-layer { position: fixed; inset: 0; pointer-events: none; z-index: 30; }

/* "press F11 for full screen", shown for five seconds at the start of a hand */
.fullscreen-hint {
  position: fixed; left: 50%; top: 18px; transform: translateX(-50%); z-index: 40;
  max-width: calc(100vw - 32px); padding: 10px 18px; border-radius: 10px;
  background: rgba(10, 30, 20, 0.94); border: 1px solid var(--gold); color: #fff;
  font-size: 0.95rem; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5); pointer-events: none;
  animation: hint-in 0.25s ease-out, hint-out 0.4s ease-in 4.6s forwards;
}
.fullscreen-hint kbd {
  font: inherit; font-weight: 700; padding: 1px 7px; margin: 0 2px; border-radius: 5px;
  background: rgba(255, 255, 255, 0.12); border: 1px solid rgba(255, 255, 255, 0.4);
}
@keyframes hint-in { from { opacity: 0; transform: translate(-50%, -8px); } }
@keyframes hint-out { to { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .fullscreen-hint { animation: none; } }
.backs.many .card.tiny + .card.tiny { margin-left: -18px; }
.backs .card { will-change: transform; }
/* A bot's card turning over in flight: both faces sit back to back on a flipper. */
.flight-layer .flight { position: fixed; transform-origin: 50% 50%; will-change: transform; }
.flight-layer .flipper { position: absolute; inset: 0; transform-style: preserve-3d; }
.flight-layer .flipper .card { position: absolute; margin: 0; box-shadow: 0 8px 18px rgba(0, 0, 0, 0.45); left: 0; top: 0; width: 100%; height: 100%; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.flight-layer .flipper .card.under { transform: rotateY(180deg); }
.flight-layer > .card { position: fixed; margin: 0; transform-origin: 50% 50%; box-shadow: 0 8px 18px rgba(0, 0, 0, 0.45); will-change: transform; }


/* ---------- small screens ---------- */
@media (max-width: 760px) {
  :root { --cw: 46px; }
  .app { padding: 8px 8px 20px; }
  .board { border-width: 6px; padding: 8px; border-radius: 16px; }
  .meld-areas { grid-template-columns: 1fr; }
  .meld .card.small, .reds .card.small { --cw: 44px; }
  .meld-total, .melds-head .score { min-width: 0; padding: 4px 8px; }
  .melds-head { gap: 6px; }
  .corner .btn { padding: 4px 8px; font-size: 0.8rem; }
  .middle { grid-template-columns: 56px 1fr 56px; gap: 4px; }
  .seat { padding: 4px 2px; }
  .seat-west .backs, .seat-east .backs { display: none; }
  .seat-name { font-size: 0.75rem; }
  .piles { gap: 12px; }
  .card.big { --cw: 60px; }
  .pile-stack { --pw: 60px; }
  .stock .stack { width: calc(60px + 8px); height: calc(60px * 1.42 + 4px); }
  .stock .stack .card { --cw: 60px; }
  .hand { --cw: 60px; gap: 8px 10px; }
  .selection { margin-left: 0; width: 100%; }
  h1 { font-size: 1.3rem; }
  .board-top { grid-template-columns: 1fr 1fr; }
  .board-top .seat-north { grid-column: 1 / -1; grid-row: 2; }
}
.meld.sequence .meld-cards .card.gap,
.meld.sequence .meld-cards .card.gap + .card { margin-top: calc(var(--cw) * -0.9); }

/* ---------- end of hand: leftover cards on the table ---------- */
.seat.leftover .seat-cards { display: flex; flex-wrap: wrap; justify-content: center; row-gap: 4px; padding-left: 16px; margin: 4px 0; min-height: 20px; }
.seat.leftover .seat-cards .card { margin-left: -16px; }
.seat.leftover .seat-count.cost { color: #ffb4a8; font-weight: 600; opacity: 1; }
.seat-south.leftover { margin-top: 12px; background: var(--panel); }
.card.small.penalty { outline: 2px solid #ff8f88; }
.summary-note { font-size: 0.85rem; color: #5a5242; }
.modal .btn.primary { margin-top: 4px; }
.melds-title .breakdown { font-size: 0.72rem; opacity: 0.75; font-variant-numeric: tabular-nums; }
.melds-title { gap: 2px; }

/* ---------- melding by clicking your meld area ---------- */
.melds.can-drop { cursor: pointer; outline: 2px dashed rgba(224, 179, 65, 0.7); outline-offset: -2px; }
.melds.can-drop:hover { background: rgba(224, 179, 65, 0.14); }
.melds-head .new-meld {
  display: inline-block; padding: 1px 8px; border: 1px dashed var(--gold); border-radius: 999px;
  color: var(--gold); font-size: 0.72rem; font-weight: 600; letter-spacing: 0; text-transform: none; vertical-align: 1px;
}

/* ---------- table layout: their melds above the stock, scores in the meld boxes,
   hand totals in the corners, your hand along the bottom ---------- */
.table { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 12px; }
.table > .melds { grid-column: 1 / -1; min-width: 0; }
/* Stock and pile centred between West and East. */
.table-row { display: flex; justify-content: center; align-items: center; }
.corner-total .score {
  min-width: 130px; padding: 4px 14px; border-radius: 10px;
  background: #4d4935; border: 3px solid var(--gold); box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}
.corner-total .score.ours { outline: none; }
.corner-total .score b { font-size: 1.6rem; color: #ffe066; }
.corner-total .score { align-items: center; text-align: center; margin-bottom: 6px; }
.melds-head .corner-total { display: flex; flex-direction: column; align-items: stretch; }
.melds { min-height: 0; }
.melds-head h2 { margin: 0; }

/* West and East: name and card count to the left of a flat row of card backs,
   which keeps the middle row of the table short. */
.seat-west, .seat-east {
  display: grid; grid-template-columns: auto auto; grid-template-areas: "name cards" "count cards";
  align-items: center; column-gap: 10px; text-align: left; padding: 4px 6px;
}
.seat-west .seat-name, .seat-east .seat-name { grid-area: name; justify-content: flex-start; align-self: end; }
.seat-west .seat-count, .seat-east .seat-count { grid-area: count; align-self: start; white-space: nowrap; }
.seat-west .backs, .seat-east .backs,
.seat-west .seat-cards, .seat-east .seat-cards { grid-area: cards; margin: 0; justify-content: flex-start; }
/* Their card backs stack downwards, each card lying on its side (landscape). */
.seat-west .backs, .seat-east .backs { flex-direction: column; align-items: center; padding: 0; min-height: 0; }
.seat-west .backs .card.tiny, .seat-east .backs .card.tiny { width: calc(var(--cw) * 1.42); height: var(--cw); }
.seat-west .backs .card.tiny + .card.tiny, .seat-east .backs .card.tiny + .card.tiny,
.seat-west .backs.many .card.tiny + .card.tiny, .seat-east .backs.many .card.tiny + .card.tiny { margin-left: 0; margin-top: -17px; }

/* Running hand totals, at the top right of each meld box. */
.corner-total { margin-top: 6px; }
.corner-total .meld-total {
  display: inline-flex; flex-direction: row; align-items: baseline; gap: 2px; line-height: 1.15;
  padding: 4px 12px; border-radius: 9px; background: rgba(244, 233, 196, 0.95); color: #2a2315; border: 1px solid #b9a777;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.35); outline: none;
}
.corner-total .meld-total .who { color: #5a5242; opacity: 1; }
.corner-total .meld-total b { font-size: 1.35rem; }
.corner-total .meld-total.short b { color: #b3261e; }
.corner-total .meld-total.met b { color: #1d7a34; }
.corner-total .meld-total .need { font-size: 1.35rem; font-weight: 800; margin-left: 5px; }
.corner-total .meld-total { min-width: 130px; justify-content: center; }
.player .hand { padding-top: 16px; }

@media (max-width: 760px) {
  .table { grid-template-columns: auto minmax(0, 1fr) auto; gap: 4px; }
  .seat-west, .seat-east { grid-template-columns: auto; grid-template-areas: "name" "count" "cards"; }
  .table-row { gap: 12px; }
  .corner-total .score { min-width: 0; padding: 4px 8px; }
  .corner-total .score b { font-size: 1.2rem; }
}

/* Brief popup above the stock and pile (e.g. clicking the stock after drawing). */
.piles { position: relative; }
.toast {
  position: absolute; left: 50%; top: -6px; transform: translate(-50%, -100%); z-index: 5;
  white-space: nowrap; padding: 6px 12px; border-radius: 8px; font-size: 0.85rem; font-weight: 600;
  background: #fbf6e6; color: var(--ink); border: 1px solid var(--gold); box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
  pointer-events: none; animation: toast 1.8s ease-out forwards;
}
@keyframes toast { 0% { opacity: 0; } 10% { opacity: 1; } 80% { opacity: 1; } 100% { opacity: 0; } }
.reduced-motion .toast { animation: none; }

/* The end-of-hand summary is narrow and opaque; drag it aside or close it to see the melds. */
.modal.summary-overlay {
  max-width: 440px; padding: 14px 16px;
  background: #fbf6e6;
}
.summary-overlay .scoretable th, .summary-overlay .scoretable td { padding: 4px 6px; font-size: 0.9rem; }
.summary-overlay .scoretable thead th { font-size: 0.75rem; }
.summary-overlay .scoretable th, .summary-overlay .scoretable td { border-bottom-color: rgba(140, 132, 111, 0.35); }
.summary-overlay h2 { font-size: 1.25rem; }
.summary-overlay .scoretable tbody th { white-space: nowrap; } /* "Cards left in hand" on one line */
/* The score and hand total are pinned in the top-right corner of the meld box, so the
   melds start right under the heading and run alongside them. */
.melds { position: relative; }
.melds-head .corner-total { position: absolute; top: 10px; right: 12px; }
.melds .meld-list { padding-right: 150px; min-height: 94px; }
@media (max-width: 760px) { .melds .meld-list { padding-right: 96px; } }

/* Meld box: heading centred, game score top right, hand total bottom left; the melds
   run between the two side gutters. */
.melds-head { justify-content: center; }
.melds-title { justify-content: center; text-align: center; }
.melds-head .corner-total { position: static; }
.melds .corner-score { position: absolute; top: 10px; right: 12px; margin: 0; }
.melds .corner-hand { position: absolute; bottom: 10px; left: 12px; margin: 0; }
.melds .meld-list { padding-left: 150px; padding-right: 150px; }
.melds .none { width: 100%; text-align: center; }
@media (max-width: 760px) { .melds .meld-list { padding-left: 96px; padding-right: 96px; } }

/* East: the cards first, then the name and count to their right. */
.seat-east { grid-template-areas: "cards name" "cards count"; }
@media (max-width: 760px) { .seat-east { grid-template-areas: "name" "count" "cards"; } }

/* Hand total at the bottom right of its meld box, under the game score; the melds
   start at the left edge again. */
.melds .corner-hand { left: auto; right: 12px; }
.melds .meld-list { padding-left: 0; }
@media (max-width: 760px) { .melds .meld-list { padding-left: 0; } }

/* West and East names and card counts by the stock, half as big again. */
.seat-west .seat-name, .seat-east .seat-name { font-size: 1.35rem; }
.seat-west .seat-count, .seat-east .seat-count { font-size: 1.17rem; }
@media (max-width: 760px) {
  .seat-west .seat-name, .seat-east .seat-name { font-size: 1.1rem; }
  .seat-west .seat-count, .seat-east .seat-count { font-size: 0.95rem; }
}

/* Bottom right of each meld box: the hand total, with the game score just below it. */
.melds .corner-totals {
  position: absolute; right: 12px; bottom: 10px;
  display: flex; flex-direction: column; align-items: stretch; gap: 6px;
}
.melds .corner-totals .corner-total { position: static; margin: 0; display: flex; justify-content: flex-end; }
.melds .corner-totals .corner-total > * { width: 100%; }
.corner-total .score { margin-bottom: 0; }
.melds .meld-list { min-height: 112px; }

/* An empty stock: a dashed outline in the top card's place, like an empty pile. */
.stock .stack.empty .card.empty { left: 8px; top: 0; }

/* A card with another card lying on it shows only its corner (rank and small suit),
   so its big centre suit is hidden. A card shown in full has the big suit, so its
   corner shows just the rank. */
:is(.hand-group, .meld-cards, .reds, .seat-cards, .pile-stack, .lih-cards) > .card:has(~ .card) .pip { visibility: hidden; }
.card:not(:is(.hand-group, .meld-cards, .reds, .seat-cards, .pile-stack, .lih-cards) > .card:has(~ .card)) .idx i { display: none; }

/* Pile status: a text box to the right of the stock and pile, which stay centred. */
.center { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; column-gap: 18px; }
.center .piles { grid-column: 2; }
.pile-status-col { grid-column: 3; display: flex; justify-content: flex-start; min-width: 0; }
.center .pile-status {
  margin: 0; max-width: 220px; min-height: 0; text-align: left; opacity: 1;
  padding: 8px 12px; border-radius: 10px; font-size: 0.82rem; line-height: 1.3;
  background: rgba(0, 0, 0, 0.28); border: 1px solid rgba(255, 255, 255, 0.25);
}
.center .pile-status.open { border-color: rgba(155, 232, 166, 0.55); }
.center .pile-status.frozen { border-color: rgba(143, 211, 255, 0.7); }
.center .pile-status.blocked { border-color: rgba(255, 155, 149, 0.6); }
@media (max-width: 760px) { .center { column-gap: 8px; } .center .pile-status { max-width: 130px; padding: 6px 8px; font-size: 0.75rem; } }

/* End of the game: New game and Quit side by side. */
.summary-actions { display: flex; gap: 10px; margin-top: 4px; }
.summary-actions .btn { flex: 1; padding: 11px; font-size: 1rem; }
.modal .summary-actions .btn.primary { margin-top: 0; }
.modal .btn.quit { background: #ece3c8; border-color: #b9a777; color: var(--ink); }
.modal .btn.quit:hover { background: #e2d6b2; }
.modal-head { cursor: move; }

/* After Quit. */
.quit-screen { max-width: 460px; margin: 12vh auto 0; padding: 32px 28px; text-align: center; background: var(--panel); border-radius: 18px; border: 1px solid rgba(224, 179, 65, 0.55); }
.quit-screen h1 { margin-bottom: 10px; }
.quit-screen p { margin: 0 0 12px; }
.quit-screen .quit-thanks { font-size: 1.2rem; font-weight: 600; }
.quit-screen .btn { margin-top: 10px; padding: 10px 28px; font-size: 1rem; }

/* A card shown in full has only the rank in its corner, so its big suit sits in
   the centre of the card. */
.card:not(:is(.hand-group, .meld-cards, .reds, .seat-cards, .pile-stack, .lih-cards) > .card:has(~ .card)) .pip { padding-top: 0; }

/* "West went out": a big pop-up in the middle of the screen for six seconds when
   a hand ends. Clicks go through it to the table. */
.end-banner {
  position: fixed; left: 50%; top: 42%; transform: translate(-50%, -50%); z-index: 35;
  pointer-events: none; max-width: calc(100vw - 32px);
  padding: 28px 56px; border-radius: 22px; text-align: center;
  background: #fbf6e6; color: var(--ink); border: 4px solid var(--gold);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6), 0 0 40px rgba(224, 179, 65, 0.45);
  animation: end-banner 6s ease-in-out forwards;
}
.end-banner-text { font-family: Georgia, "Times New Roman", serif; font-size: 3.2rem; font-weight: 700; letter-spacing: 0.02em; white-space: nowrap; }
@keyframes end-banner {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
  6% { opacity: 1; transform: translate(-50%, -50%) scale(1.04); }
  10% { transform: translate(-50%, -50%) scale(1); }
  92% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1); }
}
.reduced-motion .end-banner { animation: none; }
@media (max-width: 760px) { .end-banner { padding: 18px 26px; } .end-banner-text { font-size: 1.9rem; white-space: normal; } }

/* Hand total: a gold border to match the game score box below it. */
.corner-total .meld-total { border: 3px solid var(--gold); }

/* Hand total: wider, solid and high-contrast. */
.corner-total .meld-total {
  min-width: 170px; background: #fffdf4; color: #111; border: 3px solid var(--gold);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
}
.corner-total .meld-total b { color: #111; font-size: 1.5rem; }
.corner-total .meld-total.short b, .corner-total .meld-total .need { color: #a3140c; }
.corner-total .meld-total.met b { color: #0a6424; }
.corner-total .score { min-width: 170px; }
.melds .meld-list { padding-right: 190px; }
@media (max-width: 760px) {
  .corner-total .meld-total, .corner-total .score { min-width: 0; }
  .melds .meld-list { padding-right: 96px; }
}

/* Your turn to draw: the stock pulses, and so does the pile when you can take it. */
.stock.pulse .stack .card:last-child, .pile.pulse .pile-stack .card.top, .pile.pulse .pile-stack .card.crosswise:only-of-type {
  animation: draw-pulse 1.3s ease-in-out infinite;
}
@keyframes draw-pulse {
  0%, 100% { box-shadow: 0 0 0 2px var(--gold), 0 0 6px 1px rgba(255, 214, 102, 0.45); }
  50% { box-shadow: 0 0 0 4px var(--gold), 0 0 24px 8px rgba(255, 214, 102, 0.85); }
}
.reduced-motion .stock.pulse .stack .card:last-child, .reduced-motion .pile.pulse .pile-stack .card.top {
  animation: none; box-shadow: 0 0 0 3px var(--gold), 0 0 16px 4px rgba(255, 214, 102, 0.7);
}

/* A sequence that can no longer be completed: greyed out. */
.meld.sequence.dead { filter: grayscale(1); opacity: 0.5; }
button.meld.sequence.dead:hover { opacity: 0.75; }

/* Hand total: a 5px border and a warm gold background. */
.corner-total .meld-total {
  border: 5px solid var(--gold-dark);
  background: linear-gradient(180deg, #ffe680, #ffc93c);
}
.corner-total .meld-total b { color: #1a1206; }
.corner-total .meld-total.short b, .corner-total .meld-total .need { color: #8f0f08; }
.corner-total .meld-total.met b { color: #075a1e; }

/* Cards in the stock and pile: a round badge at the bottom right of the top card. */
.stock .stack, .pile-stack { position: relative; }
.count-badge {
  position: absolute; z-index: 3; right: -8px; bottom: -6px;
  min-width: 32px; height: 32px; padding: 0 6px; border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  background: #2a1d05; color: #ffe066; border: 2px solid var(--gold);
  font-size: 0.85rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5); pointer-events: none;
}
@media (max-width: 760px) { .count-badge { min-width: 26px; height: 26px; font-size: 0.72rem; } }

/* The "went out" pop-up closes on a click. */
.end-banner { pointer-events: auto; cursor: pointer; }

/* Hand total: the same dark background as the game score box, with light figures. */
.corner-total .meld-total { background: #4d4935; color: #fffdf4; }
.corner-total .meld-total b { color: #fffdf4; }
.corner-total .meld-total.short b, .corner-total .meld-total .need { color: #ffb4a8; }
.corner-total .meld-total.met b { color: #9be8a6; }

/* Card counts: centred on the bottom edge of the top card, in the card-back blue
   with a white rim. (The top card sits 8px in from the left of its stack and 4px
   up from its bottom.) */
.count-badge {
  right: auto; left: calc(50% + 4px); bottom: 4px; transform: translate(-50%, 50%);
  background: linear-gradient(135deg, #274c9c, #17306b); color: #fffdf6; border: 2px solid #fffdf6;
}
/* Room under the cards for the half of the badge that hangs below them. */
.stock .pile-label, .pile .pile-label { margin-top: 10px; }

/* Hand total: the game score box's colours swapped round (yellow box, dark
   figures and border). */
.corner-total .meld-total { background: #ffe066; color: #4d4935; border-color: #4d4935; }
.corner-total .meld-total b { color: #4d4935; }
.corner-total .meld-total.short b, .corner-total .meld-total .need { color: #8f0f08; }
.corner-total .meld-total.met b { color: #075a1e; }

/* Pile status: a solid dark box with bright text, for contrast on the felt. */
.center .pile-status {
  background: #0a2419; color: #fffdf4; font-weight: 600; border-width: 2px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}
.center .pile-status.open { color: #c9f7cf; border-color: #6fd982; }
.center .pile-status.frozen { color: #c4e8ff; border-color: var(--ice); }
.center .pile-status.blocked { color: #ffc4bf; border-color: #ff8a82; }

/* A dead heart or diamond sequence is greyed to a reddish brown rather than grey. */
.meld.sequence.dead[data-suit="H"], .meld.sequence.dead[data-suit="D"] {
  filter: grayscale(1) sepia(1) hue-rotate(-35deg) saturate(2.6) brightness(0.72);
  opacity: 0.8; /* more opaque than the grey ones, so the green felt does not turn it olive */
}

/* Hand total and game score side by side at the bottom right of each meld box,
   with tighter padding so they take less room from the melds. */
.melds .corner-totals { flex-direction: row; align-items: stretch; gap: 6px; }
.melds .corner-totals .corner-total > * { width: auto; }
.corner-total .meld-total, .corner-total .score { min-width: 92px; padding: 1px 8px; border-width: 3px; }
.corner-total .meld-total b, .corner-total .score b { font-size: 1.3rem; }
.corner-total .meld-total .need { font-size: 1.3rem; }
.melds .meld-list { padding-right: 0; min-height: 0; padding-bottom: 46px; }
@media (max-width: 760px) {
  .corner-total .meld-total, .corner-total .score { min-width: 0; padding: 1px 6px; }
  .corner-total .meld-total b, .corner-total .score b, .corner-total .meld-total .need { font-size: 1.05rem; }
  .melds .meld-list { padding-right: 0; padding-bottom: 38px; }
}

/* Recent moves are numbered. */
.log .log-n { display: inline-block; min-width: 2.4em; margin-right: 4px; text-align: right; opacity: 0.7; font-variant-numeric: tabular-nums; }

/* A sequence laid as 3 + 3: the missing card is a solid grey strip in the middle
   of the run, the same height as the card corners around it, with its rank. */
.meld.sequence .meld-cards .card.gap,
.meld.sequence .meld-cards .card.gap + .card { margin-top: calc(var(--cw) * -1.13); }
.meld.sequence .meld-cards .card.small.gap {
  position: relative; background: #8e8e8e; border: 1px solid #5f5f5f;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.18), 0 1px 3px rgba(0, 0, 0, 0.45);
}
.card.gap .gap-idx {
  position: absolute; top: calc(var(--cw) * 0.03); left: calc(var(--cw) * 0.08);
  font-size: calc(var(--cw) * 0.26); font-weight: 700; line-height: 1.1; color: #3d3d3d;
}

/* End of hand: a big Continue button. */
.end-actions .btn.primary { padding: 16px 48px; font-size: 1.5rem; font-weight: 800; border-radius: 14px; box-shadow: 0 3px 10px rgba(0, 0, 0, 0.4); }
@media (max-width: 760px) { .end-actions .btn.primary { padding: 12px 32px; font-size: 1.25rem; } }

/* End of hand: Continue lies over the middle of the stock and pile. */
.piles .continue-over {
  position: absolute; left: 50%; top: 45%; transform: translate(-50%, -50%); z-index: 6;
  padding: 16px 48px; font-size: 1.5rem; font-weight: 800; border-radius: 14px; white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.55), 0 0 0 3px rgba(255, 253, 244, 0.85);
}
@media (max-width: 760px) { .piles .continue-over { padding: 12px 32px; font-size: 1.25rem; } }

/* A card shown in full: its big centre suit 5px larger and 5px lower. (The suit
   is centred in the card, so 10px of top padding moves its centre down 5px.) */
.card:not(:is(.hand-group, .meld-cards, .reds, .seat-cards, .pile-stack, .lih-cards) > .card:has(~ .card)) .pip {
  font-size: calc(var(--cw) * 0.85 + 5px);
  padding-top: 10px;
}
