/* Gin Rummy — built from the Five Crowns table styles (navy felt), Gin additions at the end. */
:root {
  --felt: #1b3f73;
  --felt-dark: #0b1a36;
  --gold: #f5b700;
  --gold-deep: #c98a00;
  --ink: #1d1d1f;
  --paper: #fffdf6;
  --panel: rgba(6, 14, 34, 0.82);
  --text: #f4f1e8;
  --muted: #b9c8bf;
  --cw: 70px;
  --ch: 100px;
  --pw: 64px;
  --ph: 92px;
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none;
  font-family: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: var(--felt-dark);
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}
input { -webkit-user-select: text; user-select: text; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- shared bits ---------- */
.screen { position: fixed; inset: 0; }
#home, #lobby {
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: radial-gradient(ellipse at 50% 20%, #2a5a9e 0%, var(--felt) 40%, var(--felt-dark) 100%);
}
.home-wrap { max-width: 560px; margin: 0 auto; padding: 24px 16px 48px; }
.brand { text-align: center; margin: 8px 0 20px; }
.brand h1 { font-family: Georgia, "Times New Roman", serif; font-size: 44px; margin: 8px 0 0; letter-spacing: 1px; text-shadow: 0 3px 0 rgba(0,0,0,.3); }
.brand h1 em { color: var(--gold); font-style: normal; }
.brand.small h1 { font-size: 30px; }
.brand .tag { margin: 4px 0 0; color: var(--muted); font-style: italic; }

.panel { background: var(--panel); border: 1px solid rgba(255,255,255,.08); border-radius: 16px; padding: 16px; margin: 14px 0; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
.panel h2 { margin: 0 0 8px; font-size: 20px; display: flex; align-items: center; gap: 8px; }
.hint { color: var(--muted); margin: 6px 0; }
.hint.small { font-size: 13px; }
.field { display: block; margin: 8px 0 4px; }
.field span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 4px; }
.field input { width: 100%; font-size: 20px; padding: 12px 14px; border-radius: 12px; border: 2px solid rgba(255,255,255,.15); background: rgba(0,0,0,.3); color: var(--text); outline: none; }
.field input:focus { border-color: var(--gold); }
.row { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.row.center { justify-content: center; }
.center { text-align: center; }

.btn { border: 0; border-radius: 12px; padding: 12px 18px; font-size: 17px; font-weight: 700; background: rgba(255,255,255,.12); }
.btn:active { transform: translateY(1px); }
.btn.gold { background: linear-gradient(#ffd24a, var(--gold) 50%, var(--gold-deep)); color: #3a2800; box-shadow: 0 3px 0 #8a5d00; }
.btn.gold:disabled { filter: grayscale(.8); opacity: .6; }
.btn.big { width: 100%; font-size: 20px; padding: 14px; }
.btn.ghost { background: transparent; border: 2px solid rgba(255,255,255,.25); }
.btn.danger { background: #a3242f; }
.btn.small { padding: 8px 12px; font-size: 15px; }
.linkish { display: block; margin: 16px auto 0; background: none; border: 0; color: var(--gold); text-decoration: underline; font-size: 15px; }

.count-picker { display: flex; gap: 8px; margin: 8px 0 14px; }
.count-picker button { flex: 1; font-size: 22px; font-weight: 700; padding: 10px 0; border-radius: 12px; border: 2px solid rgba(255,255,255,.2); background: rgba(0,0,0,.25); }
.count-picker button.on { border-color: var(--gold); background: rgba(245,183,0,.2); color: var(--gold); }

.live-dot { width: 8px; height: 8px; border-radius: 50%; background: #4be08c; box-shadow: 0 0 8px #4be08c; animation: pulse 1.6s infinite; }
.game-list { display: flex; flex-direction: column; gap: 8px; }
.game-item { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 12px; background: rgba(255,255,255,.06); }
.game-item .gi-main { flex: 1; min-width: 0; }
.game-item .gi-title { font-weight: 700; font-size: 17px; }
.game-item .gi-sub { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.game-item .code { font-family: ui-monospace, Menlo, Consolas, monospace; background: rgba(0,0,0,.35); padding: 2px 6px; border-radius: 6px; font-size: 13px; margin-left: 6px; }

.code-row { display: flex; align-items: baseline; justify-content: space-between; }
.code-row strong { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 30px; color: var(--gold); letter-spacing: 4px; }
.seat-list { list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-direction: column; gap: 8px; }
.seat-list li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; background: rgba(255,255,255,.06); }
.seat-list li.empty { opacity: .5; border: 2px dashed rgba(255,255,255,.2); background: transparent; }
.seat-list .avatar { width: 34px; height: 34px; font-size: 16px; }
.seat-list .nm { flex: 1; font-weight: 700; font-size: 17px; }
.seat-list .tag { font-size: 12px; color: var(--muted); }
.seat-list .mini-btn { width: 36px; height: 36px; border-radius: 10px; border: 0; background: rgba(255,255,255,.12); font-size: 16px; }
.seat-list .mini-btn:disabled { opacity: .25; }

.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; color: #fff; font-size: 18px; border: 2px solid rgba(255,255,255,.9); box-shadow: 0 2px 6px rgba(0,0,0,.4); flex: none; text-shadow: 0 1px 2px rgba(0,0,0,.4); }
.offline .avatar { filter: grayscale(1) brightness(.7); }

/* ---------- table ---------- */
#table { overflow: hidden; touch-action: none; }
.felt {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse at 50% 45%, rgba(255,255,255,.10), transparent 60%),
    repeating-radial-gradient(circle at 30% 30%, rgba(0,0,0,.025) 0 2px, transparent 2px 4px),
    radial-gradient(ellipse at 50% 40%, #275596 0%, var(--felt) 45%, var(--felt-dark) 100%);
}
.topbar { position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: center; padding: 6px calc(10px + var(--safe-r)) 0 calc(10px + var(--safe-l)); z-index: 5; pointer-events: none; }
.topbar > * { pointer-events: auto; }
.round-info { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; text-shadow: 0 1px 2px rgba(0,0,0,.5); }
.top-buttons { display: flex; gap: 6px; }
.icon-btn { height: 34px; min-width: 34px; padding: 0 8px; border-radius: 10px; border: 0; background: rgba(0,0,0,.35); font-size: 16px; display: flex; align-items: center; gap: 4px; }
.icon-btn span { font-size: 13px; font-weight: 700; }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }

/* opponents */
.seat { position: absolute; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center; width: 96px; z-index: 2; transition: filter .3s; }
.seat .seat-top { position: relative; }
.seat .name { margin-top: 2px; font-size: 13px; font-weight: 700; max-width: 96px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: rgba(0,0,0,.4); padding: 1px 8px; border-radius: 999px; }
.seat .score { font-size: 11px; color: var(--muted); }
.seat .mini-fan { position: relative; height: 26px; width: 70px; margin-top: 2px; }
.seat .mini-fan .mb { position: absolute; bottom: 0; left: 50%; width: 16px; height: 23px; margin-left: -8px; border-radius: 3px; transform-origin: 50% 120%; }
.seat .count { position: absolute; right: -4px; bottom: -2px; background: #fff; color: #222; font-weight: 800; font-size: 11px; border-radius: 999px; padding: 0 5px; box-shadow: 0 1px 3px rgba(0,0,0,.4); }
.dealer-chip { position: absolute; left: -10px; top: -6px; width: 20px; height: 20px; border-radius: 50%; background: #fff; color: #222; font-size: 11px; font-weight: 900; display: grid; place-items: center; border: 2px solid var(--gold); box-shadow: 0 1px 4px rgba(0,0,0,.4); z-index: 1; }
.out-crown { position: absolute; left: 50%; top: -20px; transform: translateX(-50%); font-size: 20px; filter: drop-shadow(0 2px 3px rgba(0,0,0,.5)); animation: bob 1.4s ease-in-out infinite; }
.seat.turn .avatar, .me-seat.turn .avatar { box-shadow: 0 0 0 3px var(--gold), 0 0 18px 6px rgba(245,183,0,.75); animation: glow 1.2s ease-in-out infinite; }
.seat.turn .name { background: var(--gold); color: #3a2800; }
.last-turn { font-size: 10px; color: var(--gold); font-weight: 800; letter-spacing: .5px; }

/* center piles */
#center { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); display: flex; gap: 22px; z-index: 1; }
.pile-wrap { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.pile { position: relative; width: var(--pw); height: var(--ph); border-radius: calc(var(--pw) * .1); }
.pile-label { font-size: 12px; font-weight: 700; color: var(--muted); text-shadow: 0 1px 2px rgba(0,0,0,.5); }
.pile .card { position: absolute; left: 0; top: 0; width: var(--pw); height: var(--ph); }
.discard-pile:empty { border: 2px dashed rgba(255,255,255,.3); }
.pile.can-act { cursor: pointer; }
.pile.can-act::after { content: ""; position: absolute; inset: -6px; border-radius: 12px; border: 3px solid var(--gold); box-shadow: 0 0 18px rgba(245,183,0,.8); animation: pulse 1.2s ease-in-out infinite; pointer-events: none; }
.pile.drop-hot::after { content: ""; position: absolute; inset: -8px; border-radius: 12px; border: 4px solid #fff; box-shadow: 0 0 24px #fff; pointer-events: none; }
.draw-pile .stack-shadow { position: absolute; inset: 0; border-radius: inherit; }

/* status + banner */
.status { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(var(--ch) + 30px + var(--safe-b)); z-index: 3; font-size: 14px; font-weight: 700; padding: 5px 14px; border-radius: 999px; background: rgba(0,0,0,.45); white-space: nowrap; max-width: 60vw; overflow: hidden; text-overflow: ellipsis; }
.status.mine { background: var(--gold); color: #3a2800; box-shadow: 0 0 16px rgba(245,183,0,.7); animation: pop .35s ease-out; }
.status .go-out-btn { margin-left: 8px; }
.out-banner { align-self: center; background: rgba(0,0,0,.5); border: 2px solid var(--gold); border-radius: 12px; padding: 6px 8px; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 12px; font-weight: 700; max-width: 34vw; text-align: center; }
.out-banner .melds { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.meld { display: flex; }
.meld .card + .card { margin-left: -12px; }

/* me */
.me-seat { position: absolute; left: calc(8px + var(--safe-l)); bottom: calc(var(--ch) + 26px + var(--safe-b)); display: flex; align-items: center; gap: 6px; z-index: 3; }
.me-seat .avatar { width: 34px; height: 34px; font-size: 15px; }
.me-seat .me-name { font-size: 13px; font-weight: 700; line-height: 1.1; }
.me-seat .me-name small { display: block; color: var(--muted); font-weight: 400; }
.me-seat .dealer-chip { left: -6px; top: -6px; }
.me-seat .av-wrap { position: relative; }

.hand-tools { position: absolute; right: calc(8px + var(--safe-r)); bottom: calc(var(--ch) + 26px + var(--safe-b)); display: flex; gap: 6px; align-items: center; z-index: 3; }
.chip { border: 0; border-radius: 999px; padding: 5px 10px; font-size: 12px; font-weight: 800; background: rgba(0,0,0,.4); }
.chip:active { background: rgba(245,183,0,.4); }
.hand-points { font-size: 12px; font-weight: 700; color: var(--muted); padding: 0 4px; }

/* hand */
.hand { position: absolute; left: 0; right: 0; bottom: calc(8px + var(--safe-b)); height: calc(var(--ch) + 14px); z-index: 4; }
.hand .card { position: absolute; bottom: 0; width: var(--cw); height: var(--ch); transition: transform .18s ease, left .25s ease, box-shadow .2s; touch-action: none; }
.hand .card.selected { transform: translateY(-18px); box-shadow: 0 0 0 3px var(--gold), 0 8px 18px rgba(0,0,0,.5); }
.hand .card.dragging { opacity: .25; }
.hand .card.fresh { animation: fresh 1.6s ease-out; }
.hand .card.pending, .pile .card.pending { visibility: hidden; }
.drag-ghost { position: fixed; z-index: 50; pointer-events: none; width: var(--cw); height: var(--ch); transform: rotate(4deg) scale(1.08); box-shadow: 0 16px 30px rgba(0,0,0,.5) !important; }
.insert-mark { position: absolute; bottom: 0; width: 4px; height: calc(var(--ch) + 8px); background: var(--gold); border-radius: 4px; box-shadow: 0 0 10px var(--gold); z-index: 20; }

/* ---------- cards ---------- */
.card {
  --w: var(--cw);
  position: relative; border-radius: calc(var(--w) * .1); background: var(--paper);
  box-shadow: 0 1px 0 rgba(0,0,0,.15), 0 3px 8px rgba(0,0,0,.35);
  color: var(--ink); overflow: hidden; font-family: Georgia, "Times New Roman", serif;
  border: 1px solid rgba(0,0,0,.15);
}
.pile .card { --w: var(--pw); }
.card .c-rank { position: absolute; left: 7%; top: 3%; font-weight: 800; font-size: calc(var(--w) * .36); line-height: 1; letter-spacing: -1px; }
.card .c-suit { position: absolute; left: 8%; top: calc(3% + var(--w) * .38); font-size: calc(var(--w) * .26); line-height: 1; }
.card .c-big { position: absolute; left: 0; right: 0; bottom: 8%; text-align: center; font-size: calc(var(--w) * .62); line-height: 1; opacity: .92; }
.card .c-rank-br { position: absolute; right: 7%; bottom: 3%; font-weight: 800; font-size: calc(var(--w) * .2); transform: rotate(180deg); line-height: 1; opacity: .6; }
.card .c-points { display: none; }

.card .go-out-mark { position: absolute; left: 50%; top: -2px; transform: translateX(-50%); font-size: calc(var(--w) * .28); filter: drop-shadow(0 1px 2px rgba(0,0,0,.6)); z-index: 2; animation: bob 1.2s ease-in-out infinite; }

/* card back */
.card.back, .mb {
  background:
    radial-gradient(circle at 50% 50%, rgba(245,183,0,.9) 0 12%, transparent 13%),
    repeating-linear-gradient(45deg, rgba(255,255,255,.08) 0 4px, transparent 4px 8px),
    linear-gradient(135deg, #3b1f6e, #6a2c91 50%, #2a1552);
  border: 2px solid #fff;
  box-shadow: 0 2px 5px rgba(0,0,0,.4);
}
.card.back::after { content: "♛"; position: absolute; inset: 0; display: grid; place-items: center; color: #3a2800; font-size: calc(var(--w) * .2); }
.card.back > * { display: none; }

/* small cards (round summary, out banner) */
.mini .card, .card.mini { --w: 30px; width: 30px; height: 43px; border-radius: 4px; }
.mini .card .c-big { display: none; }
.mini .card .c-rank-br { display: none; }

/* flying cards */
#fx { position: absolute; inset: 0; pointer-events: none; z-index: 30; }
.fly { position: fixed; left: 0; top: 0; margin: 0; will-change: transform; perspective: 600px; }
.fly .flip { position: absolute; inset: 0; transform-style: preserve-3d; }
.fly .flip > .card { position: absolute; inset: 0; width: 100%; height: 100%; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.fly .flip > .card.face { transform: rotateY(180deg); }

/* ---------- overlays ---------- */
.overlay { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.6); display: grid; place-items: center; padding: 12px; animation: fade .2s ease-out; }
.sheet { position: relative; background: #0f2040; border: 1px solid rgba(255,255,255,.12); border-radius: 18px; padding: 16px 18px; max-width: 94vw; max-height: 92vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.6); animation: rise .25s ease-out; }
.sheet.narrow { width: 420px; }
.sheet.wide { width: 900px; }
.sheet h2 { margin: 0 0 10px; font-family: Georgia, serif; }
.sheet .close { position: absolute; right: 10px; top: 10px; width: 34px; height: 34px; border-radius: 50%; border: 0; background: rgba(255,255,255,.1); font-size: 16px; }
.sheet .btn { margin-top: 8px; }
.sheet .btn.ghost, .sheet .btn.danger { width: 100%; }
.toggle { display: flex; gap: 10px; align-items: center; font-size: 15px; margin: 8px 0; }
.toggle input { width: 22px; height: 22px; }
.rules { margin-top: 14px; font-size: 13px; color: var(--muted); }
.rules h3 { color: var(--text); margin: 0 0 4px; font-size: 15px; }
.rules p { margin: 4px 0; }
.claim-list { display: flex; flex-direction: column; gap: 8px; }
.claim-list button { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 12px; border: 0; background: rgba(255,255,255,.08); font-size: 17px; font-weight: 700; text-align: left; }

.score-table-wrap { overflow-x: auto; }
table.scores { border-collapse: collapse; width: 100%; font-size: 14px; }
table.scores th, table.scores td { padding: 5px 8px; text-align: center; border-bottom: 1px solid rgba(255,255,255,.08); white-space: nowrap; }
table.scores th { font-size: 13px; }
table.scores td.rd { color: var(--muted); text-align: left; }
table.scores tr.current td { background: rgba(245,183,0,.12); }
table.scores tr.total td { font-weight: 900; font-size: 16px; border-top: 2px solid rgba(255,255,255,.3); }
table.scores td.zero { color: #4be08c; font-weight: 800; }
table.scores td.leader { color: var(--gold); }
table.scores .th-name { display: inline-flex; align-items: center; gap: 4px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

.result-row { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 12px; background: rgba(255,255,255,.05); margin-bottom: 6px; }
.result-row.out { background: rgba(245,183,0,.15); border: 1px solid rgba(245,183,0,.5); }
.result-row .who { width: 110px; flex: none; display: flex; align-items: center; gap: 6px; font-weight: 700; }
.result-row .who .avatar { width: 28px; height: 28px; font-size: 13px; }
.result-row .cards { flex: 1; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.result-row .left { display: flex; gap: 3px; padding: 3px; border-radius: 6px; background: rgba(214,40,58,.25); outline: 1px dashed rgba(255,120,120,.6); }
.result-row .pts { width: 70px; text-align: right; font-weight: 900; font-size: 18px; }
.result-row .pts small { display: block; font-size: 11px; color: var(--muted); font-weight: 400; }
.winner-banner { text-align: center; font-size: 22px; margin: 4px 0 12px; }
.winner-banner .big { font-size: 48px; display: block; animation: float 1.4s ease-in-out infinite; }

/* go-out show */
.goout { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; background: radial-gradient(circle, rgba(245,183,0,.35), rgba(0,0,0,.85) 70%); animation: fade .25s ease-out; }
.goout canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.goout-inner { position: relative; text-align: center; }
.goout-crown { font-size: 22vh; line-height: 1; animation: crownDrop .9s cubic-bezier(.2,1.6,.4,1) both, float 1.6s ease-in-out .9s infinite; filter: drop-shadow(0 0 30px rgba(245,183,0,.9)); }
.goout-name { font-family: Georgia, serif; font-size: 11vh; font-weight: 900; color: #fff; text-shadow: 0 0 20px var(--gold), 0 4px 0 #8a5d00; animation: zoomIn .6s .3s cubic-bezier(.2,1.6,.4,1) both; }
.goout-sub { font-size: 7vh; font-weight: 900; letter-spacing: 6px; color: var(--gold); text-shadow: 0 3px 0 #5a3d00; animation: zoomIn .6s .55s cubic-bezier(.2,1.6,.4,1) both; }
.goout-note { margin-top: 10px; font-size: 3.2vh; color: #fff; opacity: .9; animation: fade .6s 1s both; }
.goout.shake { animation: shake .5s ease-in-out; }

.rotate { display: none; }
@media (orientation: portrait) {
  body.in-game .rotate { display: flex; position: fixed; inset: 0; z-index: 100; flex-direction: column; align-items: center; justify-content: center; background: var(--felt-dark); font-size: 20px; text-align: center; padding: 24px; }
  .rotate-phone { font-size: 80px; animation: turn 2s ease-in-out infinite; }
}

.toast { position: fixed; left: 50%; top: 14px; transform: translateX(-50%); z-index: 90; background: #222; color: #fff; padding: 10px 16px; border-radius: 12px; font-weight: 700; box-shadow: 0 8px 20px rgba(0,0,0,.5); animation: rise .2s ease-out; max-width: 90vw; }
.toast.err { background: #a3242f; }

.your-turn-flash { position: absolute; inset: 0; z-index: 25; pointer-events: none; box-shadow: inset 0 0 60px 10px rgba(245,183,0,.7); animation: fadeOut 1.2s ease-out forwards; }

@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .45; } }
@keyframes glow { 0%,100% { box-shadow: 0 0 0 3px var(--gold), 0 0 10px 3px rgba(245,183,0,.6); } 50% { box-shadow: 0 0 0 3px var(--gold), 0 0 22px 8px rgba(245,183,0,.95); } }
@keyframes bob { 0%,100% { transform: translate(-50%, 0); } 50% { transform: translate(-50%, -4px); } }
@keyframes float { 0%,100% { transform: none; } 50% { transform: translateY(-8px); } }
@keyframes crownDrop { from { transform: translateY(-80vh) rotate(-30deg) scale(.4); } to { transform: none; } }
@keyframes zoomIn { from { transform: scale(0); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes shimmer { from { background-position: 150% 0; } to { background-position: -100% 0; } }
@keyframes fresh { 0% { box-shadow: 0 0 0 3px #fff, 0 0 20px #fff; } 100% { box-shadow: 0 1px 0 rgba(0,0,0,.15), 0 3px 8px rgba(0,0,0,.35); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }
@keyframes rise { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes pop { 0% { transform: translateX(-50%) scale(.7); } 70% { transform: translateX(-50%) scale(1.08); } 100% { transform: translateX(-50%) scale(1); } }
@keyframes shake { 0%,100% { transform: none; } 20% { transform: translate(-8px, 4px); } 40% { transform: translate(8px, -4px); } 60% { transform: translate(-6px, -3px); } 80% { transform: translate(6px, 3px); } }
@keyframes turn { 0%,20% { transform: rotate(0); } 50%,80% { transform: rotate(-90deg); } 100% { transform: rotate(0); } }

/* discard button above the selected card */
.discard-btn { position: absolute; bottom: calc(var(--ch) + 24px); transform: translateX(-50%); z-index: 40; white-space: nowrap; border: 0; border-radius: 999px; padding: 7px 14px; font-weight: 900; font-size: 14px; background: linear-gradient(#ffd24a, var(--gold) 50%, var(--gold-deep)); color: #3a2800; box-shadow: 0 3px 0 #8a5d00, 0 6px 14px rgba(0,0,0,.4); animation: rise .15s ease-out; }
.discard-btn.go { font-size: 16px; padding: 9px 18px; box-shadow: 0 3px 0 #8a5d00, 0 0 24px 6px rgba(245,183,0,.9); animation: rise .15s ease-out, pulse 1s ease-in-out infinite; }
.status button { margin-left: 8px; border: 0; border-radius: 999px; padding: 2px 10px; font-weight: 800; background: var(--gold); color: #3a2800; }

/* round intro */
.round-intro { position: fixed; left: 50%; top: 45%; transform: translate(-50%, -50%); text-align: center; z-index: 31; animation: zoomIn .45s cubic-bezier(.2,1.6,.4,1) both; pointer-events: none; }
.round-intro.out { animation: fadeOut .3s ease-in forwards; }
.round-intro .ri-round { font-family: Georgia, serif; font-size: 12vh; font-weight: 900; color: #fff; text-shadow: 0 4px 0 rgba(0,0,0,.35), 0 0 30px rgba(0,0,0,.5); }
.round-intro .ri-wild { display: inline-block; margin-top: 4px; font-size: 5vh; font-weight: 900; padding: 4px 18px; border-radius: 999px; background: linear-gradient(#ffd24a, var(--gold-deep)); color: #3a2800; box-shadow: 0 0 30px rgba(245,183,0,.9); }
.round-intro .ri-dealer { margin-top: 8px; font-size: 3.4vh; font-weight: 700; text-shadow: 0 2px 4px rgba(0,0,0,.6); }
.celebrate { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 70; pointer-events: none; }
.sort-label { font-size: 11px; font-weight: 700; color: var(--muted); }
.chip.on { background: rgba(245,183,0,.35); }

/* game history */
#historyBtn { margin-top: 4px; }
.win-tally { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; }
.win-chip { background: rgba(245,183,0,.15); border: 1px solid rgba(245,183,0,.5); border-radius: 999px; padding: 4px 12px; font-size: 14px; }
.win-chip b { color: var(--gold); margin-left: 4px; }
.history-list { display: flex; flex-direction: column; gap: 8px; }
.history-item { background: rgba(255,255,255,.06); border-radius: 12px; overflow: hidden; }
.history-item.open { background: rgba(255,255,255,.1); }
.history-item.incomplete .hi-title { color: var(--muted); }
.hi-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; cursor: pointer; }
.hi-main { flex: 1; min-width: 0; }
.hi-date { font-size: 12px; color: var(--muted); }
.hi-title { font-size: 16px; margin: 2px 0; }
.hi-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hi-del { border: 0; background: rgba(0,0,0,.25); border-radius: 10px; width: 36px; height: 36px; font-size: 16px; flex: none; }
.hi-detail { padding: 0 12px 12px; overflow-x: auto; }
#login { overflow-y: auto; background: radial-gradient(ellipse at 50% 20%, #2a5a9e 0%, var(--felt) 40%, var(--felt-dark) 100%); }
.back-link { display: inline-block; color: var(--muted); text-decoration: none; font-weight: 700; font-size: 15px; padding: 4px 0; }
.back-link:active { color: var(--gold); }
/* Pop-ups opened from the round/game results must sit above them */
#scores, #menu { z-index: 65; }
/* Your prompt sits beside your name in the lower-left corner */
.me-seat .status { position: static; transform: none; bottom: auto; margin-left: 4px; max-width: 42vw; }
.me-seat .status.mine { animation: popIn .35s ease-out; }
.me-seat .status:empty { display: none; }
@keyframes popIn { 0% { transform: scale(.7); } 70% { transform: scale(1.08); } 100% { transform: scale(1); } }
.hand-points { color: #fff; font-weight: 900; font-size: 13px; text-shadow: 0 1px 2px rgba(0,0,0,.6); }
/* Players down the sides: bigger scores under the names */
.seat .score { font-size: clamp(14px, 4.4vh, 20px); font-weight: 800; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.6); margin-top: 2px; }
.seat .name { font-size: clamp(13px, 3.8vh, 16px); }
.me-seat .me-name small { font-size: clamp(14px, 4.4vh, 20px); font-weight: 800; color: #fff; }
/* Round results: bigger names, round scores and running totals */
.result-row .who { width: clamp(120px, 20vw, 170px); font-size: clamp(15px, 4.6vh, 20px); }
.result-row .who .avatar { width: clamp(28px, 8vh, 36px); height: clamp(28px, 8vh, 36px); font-size: clamp(13px, 4vh, 17px); }
.result-row .pts { width: clamp(84px, 14vw, 120px); font-size: clamp(22px, 7vh, 34px); line-height: 1.05; }
.result-row .pts small { font-size: clamp(13px, 3.8vh, 17px); font-weight: 700; color: #e8e2d4; margin-top: 2px; }
.winner-banner { font-size: clamp(20px, 5.5vh, 28px); }
/* Piles and the "went out" panel, 25% larger */
.pile-label { font-size: 15px; }
.out-banner { font-size: 15px; padding: 8px 10px; gap: 5px; max-width: 40vw; }
.out-banner .melds { gap: 8px; }
.out-banner .mini .card, .out-banner .card.mini { --w: 37px; width: 37px; height: 54px; border-radius: 5px; }
.out-banner .meld .card + .card { margin-left: -15px; }
/* Anchor the piles (and the "went out" panel) just above your hand, so a tall panel grows upward
   into the open space instead of down over the Sort buttons. */
#center { top: auto; bottom: calc(var(--ch) + 64px + var(--safe-b)); transform: translateX(-50%); align-items: flex-end; }
.out-banner { align-self: flex-end; max-height: calc(100vh - var(--ch) - 120px); overflow: hidden; }
/* A little higher */
#center { bottom: calc(var(--ch) + 88px + var(--safe-b)); }
.out-banner { max-height: calc(100vh - var(--ch) - 144px); }
/* Show every card in the "went out" panel: no height limit, and a bit wider so melds wrap less */
.out-banner { max-height: none; overflow: visible; max-width: 46vw; }
/* Other players look like your own seat: avatar, then name with score beneath, down the sides */
.seat.side { flex-direction: row; align-items: center; gap: 6px; width: auto; transform: translateY(-50%); }
.seat.side.left { left: calc(8px + var(--safe-l)); }
.seat.side.right { right: calc(8px + var(--safe-r)); left: auto; }
.seat.side .av-wrap { position: relative; }
.seat.side .avatar { width: 34px; height: 34px; font-size: 15px; }
.seat.side .me-name { font-size: 13px; font-weight: 700; line-height: 1.1; max-width: 22vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-shadow: 0 1px 2px rgba(0,0,0,.6); }
.seat.side .me-name small { display: block; font-size: clamp(14px, 4.4vh, 20px); font-weight: 800; color: #fff; }
.seat.side .last-turn { display: block; }
.seat.side .dealer-chip { left: -6px; top: -6px; }
.seat.side .out-crown { top: -16px; }
/* Right side mirrors the left: avatar against the edge, name and score to its left */
.seat.side.right { flex-direction: row-reverse; }
.seat.side.right .me-name { text-align: right; }
.seat.side.right .dealer-chip { left: auto; right: -6px; }
/* Centre the piles (and "went out" panel) in the open space between the top bar and your row */
#center { top: 44px; bottom: calc(var(--ch) + 64px + var(--safe-b)); transform: translateX(-50%); align-items: center; justify-content: center; }
.out-banner { align-self: center; }
/* The Joker: a photo card face, with the JOKER label on a dark strip so it stays readable */

/* ================= Gin Rummy ================= */
/* Standard suits */
.card.s-h, .card.s-d { color: #d6283a; }
.card.s-s, .card.s-c { color: #1d1d1f; }
/* Red card backs on the navy table */
.card.back, .mb {
  background:
    radial-gradient(circle at 50% 50%, rgba(255,255,255,.9) 0 9%, transparent 10%),
    repeating-linear-gradient(45deg, rgba(255,255,255,.1) 0 4px, transparent 4px 8px),
    linear-gradient(135deg, #8a1624, #c0283a 50%, #6a0f1b);
  border: 2px solid #fff;
}
.card.back::after { content: ""; }
.linkbtn { display: block; text-align: center; text-decoration: none; color: inherit; box-sizing: border-box; margin-top: 8px; }

/* Home header */
.brand-cards { display: flex; justify-content: center; height: 72px; margin: 0 auto; }
.brand-cards span { width: 44px; height: 62px; margin: 4px -6px 0; border-radius: 6px; background: var(--paper); border: 1px solid rgba(0,0,0,.2); box-shadow: 0 3px 8px rgba(0,0,0,.35); display: grid; place-items: center; font: 800 17px Georgia, serif; }
.brand-cards span:nth-child(1) { transform: rotate(-16deg) translateY(6px); } .brand-cards span:nth-child(2) { transform: rotate(-8deg) translateY(1px); }
.brand-cards span:nth-child(4) { transform: rotate(8deg) translateY(1px); } .brand-cards span:nth-child(5) { transform: rotate(16deg) translateY(6px); }
.brand-cards .bk { color: #1d1d1f; } .brand-cards .rd { color: #d6283a; }
.seat-list li.can-bot { flex-wrap: wrap; }
.bot-tag { font-size: 12px; font-weight: 700; color: var(--muted); margin-left: 4px; }

/* Top bar */
.target-pill { background: rgba(0,0,0,.35); padding: 3px 12px; border-radius: 999px; font-size: 14px; font-weight: 800; color: var(--gold); }

/* The other player's cards, face down under their name */
.opp-cards { display: flex; margin-top: 5px; height: 26px; }
.opp-cards .mb { width: 18px; height: 26px; border-radius: 3px; border-width: 1px; flex: none; }
.opp-cards .mb + .mb { margin-left: -11px; }
.seat.side.right .opp-cards { justify-content: flex-end; }

/* Pass on the face-up card */
.pass-btn { margin-top: 4px; border: 0; border-radius: 999px; padding: 7px 22px; font-weight: 900; font-size: 15px; background: rgba(255,255,255,.9); color: #1d1d1f; box-shadow: 0 3px 0 rgba(0,0,0,.35); animation: rise .2s ease-out; }
.pile.wiggle { animation: wiggle .5s ease-in-out; }
@keyframes wiggle { 0%,100% { transform: none; } 25% { transform: rotate(-4deg); } 75% { transform: rotate(4deg); } }

/* Meld colour bars on the cards in your hand */
.card .meld-bar { position: absolute; left: 8%; right: 8%; bottom: 4%; height: calc(var(--w) * .075); border-radius: 99px; background: var(--mc); box-shadow: 0 0 6px var(--mc); }
.card.m0 { --mc: #2bb673; } .card.m1 { --mc: #3a8dde; } .card.m2 { --mc: #f5a623; } .card.m3 { --mc: #b565e0; }
.hand .card .c-rank-br { bottom: 11%; }

/* Discard / Knock / Gin above the selected card */
.card-actions { position: absolute; bottom: calc(var(--ch) + 24px); transform: translateX(-50%); z-index: 40; display: flex; gap: 8px; white-space: nowrap; animation: rise .15s ease-out; }
.card-actions button, .card-actions .note { border: 0; border-radius: 999px; padding: 8px 15px; font-weight: 900; font-size: 15px; box-shadow: 0 3px 0 rgba(0,0,0,.35), 0 6px 14px rgba(0,0,0,.4); }
.card-actions .discard { background: linear-gradient(#ffd24a, var(--gold) 50%, var(--gold-deep)); color: #3a2800; }
.card-actions .knock { background: linear-gradient(#8ff0b8, #2bb673 50%, #1b7f4d); color: #04331c; }
.card-actions .knock.gin { font-size: 17px; padding: 9px 20px; box-shadow: 0 3px 0 #0d5a33, 0 0 24px 6px rgba(75,224,140,.9); animation: rise .15s ease-out, pulse 1s ease-in-out infinite; }
.card-actions .note { background: rgba(0,0,0,.7); color: #fff; font-size: 13px; }
.big-gin-btn { background: #fff !important; color: #6a0f1b !important; font-size: 15px; animation: pulse 1s ease-in-out infinite; }

/* Knock / Gin show */
.goout.knock { background: radial-gradient(circle, rgba(75,224,140,.3), rgba(0,0,0,.85) 70%); }
.goout.knock .goout-sub { color: #8ff0b8; text-shadow: 0 3px 0 #0d5a33; }

/* Hand results window */
.hand-result .hr-row { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 12px; background: rgba(255,255,255,.05); margin-bottom: 6px; animation: rise .4s ease-out both; }
.hand-result .hr-row.r2 { animation-delay: .5s; }
.hand-result .hr-row.won { background: rgba(245,183,0,.14); border: 1px solid rgba(245,183,0,.5); }
.hr-row .who { width: clamp(110px, 18vw, 160px); flex: none; display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: clamp(15px, 4.6vh, 20px); }
.hr-row .who small { display: block; font-size: 12px; font-weight: 700; color: var(--muted); }
.hr-row .who .avatar { width: clamp(28px, 8vh, 36px); height: clamp(28px, 8vh, 36px); font-size: clamp(13px, 4vh, 17px); }
.hr-cards { flex: 1; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.hand-result .mini .card { --w: clamp(30px, 8.5vh, 42px); width: var(--w); height: calc(var(--w) * 1.43); border-radius: 5px; }
.hand-result .meld .card + .card { margin-left: calc(var(--w) * -0.4); }
.card.laid { box-shadow: 0 0 0 2px #4be08c, 0 0 10px rgba(75,224,140,.9); z-index: 1; }
.deadwood { display: flex; gap: 3px; padding: 3px; border-radius: 6px; background: rgba(214,40,58,.25); outline: 1px dashed rgba(255,120,120,.7); }
.hr-row .pts { width: clamp(76px, 12vw, 110px); text-align: right; font-weight: 900; font-size: clamp(22px, 7vh, 34px); line-height: 1.05; }
.hr-row .pts small { display: block; font-size: 12px; color: var(--muted); font-weight: 700; }
.hr-outcome { text-align: center; font-weight: 900; font-size: clamp(18px, 5.6vh, 26px); margin: 10px 0 6px; animation: zoomIn .45s 1s cubic-bezier(.2,1.6,.4,1) both; }
.hr-outcome.good { color: #4be08c; } .hr-outcome.bad { color: #ff9aa5; }
.hr-totals { display: flex; justify-content: center; flex-wrap: wrap; gap: 18px; font-size: clamp(15px, 4.4vh, 19px); margin-bottom: 4px; }
.hr-totals b { color: var(--gold); font-size: 1.2em; }
.hr-totals .muted { color: var(--muted); }
.final-box { margin-top: 10px; border-top: 1px solid rgba(255,255,255,.15); padding-top: 8px; }
table.scores.final { max-width: 520px; margin: 0 auto; font-size: clamp(14px, 4vh, 17px); }
table.scores td.dead { color: var(--muted); }
#handEnd .sheet { max-width: 96vw; }
/* Pass sits beside the discard pile so nothing shifts when it appears */
.pile-wrap { position: relative; }
.pass-btn { position: absolute; left: calc(100% + 14px); top: calc(var(--ph) / 2); transform: translateY(-50%); margin: 0; animation: fade .2s ease-out; }
