:root {
  --felt: #1d6b3a;
  --felt-dark: #124a27;
  --felt-line: rgba(255, 255, 255, 0.10);
  --ivory: #fbf6ea;
  --cream: #f4ebd6;
  --navy: #1e2f5c;
  --navy-2: #2b4385;
  --red: #c8322f;
  --ink: #161616;
  --gold: #f2c14e;
  --plate: rgba(9, 38, 20, 0.78);
  --cw: clamp(54px, 7.4vmin, 92px); /* my card width */
  --ow: clamp(26px, 3.6vmin, 46px); /* opponent card width */
  --pw: clamp(50px, 6.6vmin, 82px); /* pile card width */
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ivory);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--felt-dark); overscroll-behavior: none; }
button { font: inherit; cursor: pointer; }
.hidden { display: none !important; }

#app, .screen { position: fixed; inset: 0; }
.felt {
  background-color: var(--felt);
  background-image:
    radial-gradient(ellipse at 50% 45%, rgba(255,255,255,0.07), transparent 60%),
    radial-gradient(ellipse at 50% 50%, transparent 55%, rgba(0,0,0,0.35) 100%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.09 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------- Cards ---------- */
.card {
  position: relative;
  width: var(--w, var(--cw));
  aspect-ratio: 5 / 7;
  border-radius: calc(var(--w, var(--cw)) * 0.09);
  box-shadow: 0 2px 0 rgba(0,0,0,0.18), 0 4px 10px rgba(0,0,0,0.28);
  user-select: none;
  flex: none;
}
.card.sm { --w: var(--ow); }
.card.md { --w: var(--pw); }
.card.lg { --w: clamp(64px, 12vmin, 128px); }
.card.face {
  background: var(--ivory);
  border: 1px solid #d8cfb8;
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
}
.card.face.red { color: var(--red); }
.card .corner {
  position: absolute; top: 5%; left: 7%;
  font-weight: 700; line-height: 0.95; text-align: center;
  font-size: calc(var(--w, var(--cw)) * 0.22);
}
.card .corner.br { top: auto; left: auto; bottom: 5%; right: 7%; transform: rotate(180deg); }
.card .pip {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: calc(var(--w, var(--cw)) * 0.52);
}
.card .pip.court { font-size: calc(var(--w, var(--cw)) * 0.46); font-weight: 700; }
.card .pip.court i { font-style: normal; display: block; text-align: center; line-height: 1; }
.card .pip.court small { display: block; text-align: center; font-size: 0.55em; }
.card .val {
  position: absolute; bottom: 4%; left: 50%; transform: translateX(-50%);
  font: 700 calc(var(--w, var(--cw)) * 0.15) ui-sans-serif, system-ui, sans-serif;
  background: rgba(30,47,92,0.10); color: var(--navy); padding: 0 0.35em; border-radius: 99px;
}
.card.joker .pip { color: var(--navy); }
.card.joker .pip small { font-size: 0.32em; letter-spacing: 0.08em; font-weight: 700; display: block; text-align: center; }
.card.back {
  background-color: var(--navy);
  border: calc(var(--w, var(--cw)) * 0.055) solid var(--ivory);
  background-image:
    repeating-linear-gradient(45deg, rgba(255,255,255,0.16) 0 1px, transparent 1px 7px),
    repeating-linear-gradient(-45deg, rgba(255,255,255,0.16) 0 1px, transparent 1px 7px);
}
.card.back::after {
  content: "B"; position: absolute; inset: 0; margin: auto;
  width: 44%; height: 31%; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--navy); border: 2px solid rgba(251,246,234,0.75);
  font: 700 calc(var(--w, var(--cw)) * 0.2) Georgia, serif; color: var(--ivory);
}
.card.sm.back::after { border-width: 1px; }
.card.empty { background: transparent; box-shadow: none; border: 2px dashed rgba(255,255,255,0.25); }

.card.selectable { cursor: pointer; transition: transform .15s ease, box-shadow .15s ease; }
.card.selectable:hover, .card.selectable:focus-visible { transform: translateY(-6px); }
.card.glow { box-shadow: 0 0 0 3px var(--gold), 0 6px 16px rgba(0,0,0,0.35); }
.card.flip-in { animation: flipIn .45s ease both; }
.card.drop { animation: drop .35s cubic-bezier(.2,.9,.3,1.3) both; }
.card.bad { animation: shake .45s ease both; box-shadow: 0 0 0 3px var(--red); }
.card.dealt { animation: deal .5s cubic-bezier(.2,.8,.2,1) both; animation-delay: calc(var(--d, 0) * 60ms); }
@keyframes flipIn { from { transform: rotateY(90deg); } to { transform: rotateY(0); } }
@keyframes drop { from { transform: translateY(-24px) scale(1.12); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes shake { 0%,100% { transform: none } 20% { transform: translateX(-6px) } 40% { transform: translateX(6px) } 60% { transform: translateX(-4px) } 80% { transform: translateX(4px) } }
@keyframes deal { from { transform: translate(var(--fx, 0), var(--fy, -30vh)) rotate(-20deg); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Buttons ---------- */
.btn {
  border: none; border-radius: 12px; padding: 0.7em 1.3em;
  font-weight: 800; letter-spacing: 0.04em; color: #fff;
  box-shadow: 0 3px 0 rgba(0,0,0,0.28), inset 0 1px 0 rgba(255,255,255,0.25);
  transition: transform .08s ease, filter .15s ease, opacity .15s;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,0.28); }
.btn:disabled { opacity: 0.38; cursor: not-allowed; filter: grayscale(0.6); }
.btn.big { font-size: 1.1rem; padding: 0.85em 1.4em; width: 100%; }
.btn.primary { background: #2f9a4f; }
.btn.blue { background: #2f5fc4; }
.btn.red { background: var(--red); }
.btn.cream { background: var(--cream); color: var(--navy); }
.btn.link { background: none; box-shadow: none; color: var(--cream); text-decoration: underline; text-underline-offset: 4px; font-weight: 700; }
.btn.on { outline: 3px solid var(--gold); outline-offset: 2px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: none;
  background: var(--plate); color: var(--ivory); font-size: 1.1rem; font-weight: 700;
}
.icon-btn.off { opacity: 0.45; text-decoration: line-through; }

/* ---------- Intro ---------- */
#intro { display: grid; place-items: center; z-index: 20; }
.intro-stage { position: relative; display: grid; place-items: center; gap: 2vmin; }
.intro-deck { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); animation: deckOut .4s ease 1.9s forwards; }
.intro-row { display: flex; gap: 2vmin; perspective: 900px; }
.intro-card { animation: dealIn .55s cubic-bezier(.2,.8,.2,1) both; animation-delay: calc(0.15s + var(--i) * 0.16s); }
.intro-card .flipper {
  position: relative; transform-style: preserve-3d;
  animation: flip .5s ease forwards; animation-delay: calc(1.05s + var(--i) * 0.18s);
}
.intro-card .flipper > .card { backface-visibility: hidden; }
.intro-card .flipper > .face { position: absolute; inset: 0; transform: rotateY(180deg); }
.card.letter b { position: absolute; inset: 0; display: grid; place-items: center; font: 700 calc(var(--w) * 0.62) Georgia, serif; }
.intro-row { animation: rowUp .6s ease 2.25s forwards; }
.intro-logo { width: min(78vw, 560px); opacity: 0; transform: scale(0.6); animation: logoIn .7s cubic-bezier(.2,.9,.3,1.25) 2.45s forwards; margin-top: -4vmin; }
.intro-tag { margin: 0; font: italic 600 clamp(1rem, 2.6vmin, 1.4rem) Georgia, serif; color: var(--cream); opacity: 0; animation: fadeIn .5s ease 3.05s forwards; }
.skip { position: absolute; bottom: max(16px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); background: none; border: none; color: rgba(251,246,234,0.6); font-size: .9rem; }
@keyframes dealIn { from { transform: translateY(-2vh) scale(0.5) rotate(-12deg); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes flip { to { transform: rotateY(180deg); } }
@keyframes deckOut { to { opacity: 0; transform: translate(-50%, -50%) scale(0.7); } }
@keyframes rowUp { to { transform: translateY(-3vmin) scale(0.8); opacity: 0.0; } }
@keyframes logoIn { to { opacity: 1; transform: scale(1); } }
@keyframes fadeIn { to { opacity: 1; } }
#intro.leaving { animation: introOut .45s ease forwards; }
@keyframes introOut { to { opacity: 0; transform: scale(1.04); } }

/* ---------- Menu ---------- */
#menu { display: grid; grid-template-columns: minmax(0, 1fr); place-items: center; align-content: safe center; padding: 24px; overflow-y: auto; }
.menu-wrap { width: min(420px, 100%); min-width: 0; display: grid; gap: 14px; justify-items: center; animation: fadeIn .4s ease both; }
.menu-logo { width: 100%; filter: drop-shadow(0 6px 10px rgba(0,0,0,0.3)); }
.menu-sub { margin: -6px 0 6px; color: var(--cream); font: italic 1rem Georgia, serif; opacity: .9; text-align: center; }
.name-field { width: 100%; display: grid; gap: 6px; font-weight: 700; font-size: .85rem; color: var(--cream); }
.name-field input, .field input {
  width: 100%; padding: 0.75em 0.9em; border-radius: 10px; border: 2px solid rgba(0,0,0,0.15);
  background: var(--ivory); color: var(--navy); font-size: 1.05rem; font-weight: 700;
}
.menu-buttons { width: 100%; display: grid; gap: 10px; }
.sound-toggle { position: absolute; top: max(14px, env(safe-area-inset-top)); right: 14px; }

/* ---------- Panels / lobby ---------- */
.panel {
  background: var(--ivory); color: var(--navy); border-radius: 18px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
}
#lobby { display: grid; grid-template-columns: minmax(0, 1fr); place-items: center; align-content: safe center; padding: 16px; overflow-y: auto; }
.lobby-panel { width: min(460px, 100%); min-width: 0; padding: 18px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.lobby-head { display: grid; grid-template-columns: 40px minmax(0, 1fr) 40px; align-items: center; text-align: center; }
.lobby-head h2 { margin: 0; font: 700 1.2rem Georgia, serif; }
.lobby-head .icon-btn { background: var(--navy); }
.room-code { text-align: center; font: 800 2.4rem ui-monospace, Menlo, monospace; letter-spacing: 0.2em; background: #fff; border: 2px dashed #cdbf9e; border-radius: 12px; padding: 6px; }
.invite-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.invite-row .btn { box-shadow: none; border: 2px solid #ddd0b0; }
/* Collapse to one column before badges and names compete for a few pixels. */
.seat-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); gap: 6px; }
.seat-list li { display: flex; align-items: center; gap: 8px; min-width: 0; padding: 8px 10px; border-radius: 10px; background: #efe5cc; font-weight: 700; min-height: 44px; }
.seat-list li.empty { background: transparent; border: 2px dashed #ddd0b0; color: #a99a76; font-weight: 600; }
.seat-list li > span:not(.avatar):not(.tag) { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat-list .tag, .seat-list .x { flex: none; }
.seat-list .x { margin-left: auto; border: none; background: none; color: var(--red); font-weight: 800; font-size: 1.1rem; }
.avatar { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 800; font-size: .85rem; flex: none; }
.tag { font-size: .68rem; padding: 1px 6px; border-radius: 99px; background: var(--navy); color: var(--ivory); }
.host-controls { display: grid; gap: 10px; }
.setting { display: flex; align-items: center; justify-content: space-between; font-weight: 700; }
.stepper { display: flex; align-items: center; gap: 12px; }
.stepper button, .seg button { border: 2px solid #d8cba8; background: #fff; color: var(--navy); border-radius: 10px; font-weight: 800; }
.stepper button { width: 38px; height: 38px; font-size: 1.2rem; }
.stepper b { min-width: 2ch; text-align: center; font-size: 1.2rem; }
.seg { display: flex; gap: 6px; }
.seg button { padding: 8px 12px; }
.seg button.sel { background: var(--navy); color: var(--ivory); border-color: var(--navy); }
.lobby-wait { text-align: center; margin: 0; font-style: italic; color: #6b5f45; }

/* ---------- Table ---------- */
#table { overflow: hidden; }
.topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: max(8px, env(safe-area-inset-top)) 12px 8px;
  background: linear-gradient(rgba(0,0,0,0.25), transparent);
}
.top-logo { height: clamp(26px, 5vmin, 44px); filter: drop-shadow(0 2px 3px rgba(0,0,0,0.4)); }
.top-info { display: flex; gap: 8px; }
.top-actions { display: flex; gap: 8px; }
.pill { background: var(--plate); padding: 6px 14px; border-radius: 99px; font-weight: 800; font-size: .85rem; letter-spacing: .05em; white-space: nowrap; }
.pill.ghost { background: transparent; border: 1.5px solid rgba(255,255,255,0.3); font-family: ui-monospace, Menlo, monospace; }
.ring {
  position: absolute; left: 50%; top: 47%; width: min(88vw, 150vh); height: min(62vh, 62vw);
  transform: translate(-50%, -50%); border-radius: 50%;
  border: 2px solid var(--felt-line); pointer-events: none;
}
.ring::after { content: ""; position: absolute; inset: 22% 30%; border-radius: 50%; border: 2px solid var(--felt-line); }

#opponents { position: absolute; inset: 0; pointer-events: none; }
.opp {
  position: absolute; transform: translate(-50%, -50%);
  display: grid; justify-items: center; gap: 6px; pointer-events: auto;
}
.opp .mini-hand { display: flex; gap: 3px; }
.plate {
  display: flex; align-items: center; gap: 8px;
  background: var(--plate); border-radius: 12px; padding: 5px 10px 5px 5px;
  border: 2px solid transparent; position: relative; white-space: nowrap;
  font-size: clamp(.72rem, 1.7vmin, .9rem);
}
.plate .nm { font-weight: 800; max-width: 11ch; overflow: hidden; text-overflow: ellipsis; }
.plate .sc { font-weight: 800; background: rgba(255,255,255,0.12); padding: 1px 8px; border-radius: 99px; font-variant-numeric: tabular-nums; }
.plate .dot { width: 8px; height: 8px; border-radius: 50%; background: #5bd17a; }
.plate .dot.off { background: #9a9a9a; }
.plate.turn { border-color: var(--gold); box-shadow: 0 0 0 4px rgba(242,193,78,0.25); }
.plate .timer { position: absolute; left: 6px; right: 6px; bottom: -6px; height: 3px; border-radius: 3px; background: rgba(255,255,255,0.15); overflow: hidden; }
.plate .timer i { display: block; height: 100%; background: var(--gold); transform-origin: left; }
.plate .badge { font-size: .65rem; font-weight: 800; padding: 1px 6px; border-radius: 99px; background: var(--red); color: #fff; }
.plate .badge.final { background: var(--gold); color: var(--navy); }

.center { position: absolute; left: 50%; top: 45%; transform: translate(-50%, -50%); display: flex; gap: clamp(14px, 3vmin, 34px); align-items: flex-end; }
.pile { display: grid; justify-items: center; gap: 6px; }
.pile-label { font-size: .72rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: rgba(251,246,234,0.7); }
#deck { position: relative; }
#deck::before { content: ""; position: absolute; inset: 0; transform: translate(3px, 3px); border-radius: inherit; background: #e9dfc6; z-index: -1; box-shadow: 0 2px 6px rgba(0,0,0,0.3); }
.slot-target.can { cursor: pointer; }
.slot-target.can > .card, #deck.can { box-shadow: 0 0 0 3px var(--gold), 0 6px 16px rgba(0,0,0,0.35); }
.drawn .card { --w: calc(var(--pw) * 1.12); }

.me { position: absolute; left: 0; right: 0; bottom: 0; display: grid; justify-items: center; gap: 8px; padding: 0 10px max(12px, env(safe-area-inset-bottom)); }
.hand { display: flex; gap: clamp(6px, 1.4vmin, 14px); min-height: calc(var(--cw) * 1.4); align-items: flex-end; flex-wrap: nowrap; }
.hint { margin: 0; min-height: 1.3em; font-weight: 700; font-size: clamp(.8rem, 2vmin, 1rem); text-align: center; color: var(--cream); text-shadow: 0 1px 2px rgba(0,0,0,0.5); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.act { min-width: clamp(88px, 15vmin, 150px); font-size: clamp(.9rem, 2.2vmin, 1.1rem); }
.powers { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.powers .btn { font-size: .85rem; padding: .55em 1em; }

.feed { position: absolute; left: 12px; bottom: 12px; width: min(250px, 30vw); display: grid; gap: 4px; pointer-events: none; }
.feed div { background: rgba(0,0,0,0.28); border-radius: 8px; padding: 4px 8px; font-size: .75rem; line-height: 1.25; animation: fadeIn .3s ease both; opacity: 0; }
.feed div:nth-last-child(n+4) { display: none; }

.banner {
  position: absolute; left: 50%; top: 45%; transform: translate(-50%, -50%); z-index: 8;
  font: 900 clamp(2.2rem, 9vmin, 5rem) Georgia, serif; letter-spacing: .06em;
  color: var(--ivory); text-shadow: 0 4px 0 var(--navy), 0 8px 20px rgba(0,0,0,0.5);
  pointer-events: none; animation: bannerPop 1.6s ease forwards; white-space: nowrap;
}
.banner.red { color: #fff; text-shadow: 0 4px 0 #7d1a18, 0 8px 20px rgba(0,0,0,0.5); }
@keyframes bannerPop { 0% { opacity: 0; transform: translate(-50%, -50%) scale(.5); } 15% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); } 25% { transform: translate(-50%, -50%) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -60%); } }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 30; background: rgba(5, 20, 10, 0.6); display: grid; place-items: center; padding: 14px; animation: fadeIn .2s ease both; opacity: 0; }
.modal-card { background: var(--ivory); color: var(--navy); border-radius: 18px; width: min(560px, 100%); max-height: min(92vh, 100%); overflow-y: auto; padding: 20px; box-shadow: 0 16px 40px rgba(0,0,0,0.45); }
.modal-card h2 { margin: 0 0 8px; font: 700 1.5rem Georgia, serif; }
.modal-card h3 { margin: 16px 0 6px; font-size: .95rem; text-transform: uppercase; letter-spacing: .08em; color: var(--red); }
.modal-card ul { margin: 0; padding-left: 1.2em; display: grid; gap: 4px; line-height: 1.4; }
.modal-card .lead { margin: 0; line-height: 1.45; }
.modal-card .btn.big { margin-top: 18px; }
.values { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.values div { display: grid; justify-items: center; background: #efe5cc; border-radius: 10px; padding: 8px 4px; }
.values .mini { font: 700 1rem Georgia, serif; color: var(--ink); }
.values .mini.red { color: var(--red); }
.values b { font-size: 1.3rem; }
.values small { font-size: .72rem; color: #6b5f45; }
.form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; font-weight: 700; }
.field input { border-color: #d8cba8; background: #fff; text-transform: uppercase; letter-spacing: .2em; font-family: ui-monospace, Menlo, monospace; text-align: center; font-size: 1.4rem; }
.row2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.err { color: var(--red); font-weight: 700; margin: 0; min-height: 1.2em; }

/* Reveal */
.reveal h2 { text-align: center; }
.reveal-list { display: grid; gap: 8px; }
.reveal-row { display: grid; grid-template-columns: minmax(80px, 1fr) auto 64px; align-items: center; gap: 10px; background: #efe5cc; border-radius: 12px; padding: 8px 10px; }
.reveal-row.win { background: #ffe8a8; }
.reveal-row .who { font-weight: 800; display: flex; align-items: center; gap: 6px; min-width: 0; }
.reveal-row .who span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reveal-row .cards { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.reveal-row .cards .card { --w: clamp(30px, 5.5vmin, 44px); }
.reveal-row .pts { text-align: right; font-variant-numeric: tabular-nums; }
.reveal-row .pts b { display: block; font-size: 1.2rem; }
.reveal-row .pts small { color: #6b5f45; }
.reveal .auto { text-align: center; margin: 10px 0 0; color: #6b5f45; font-style: italic; }

.toast { position: fixed; top: max(64px, calc(env(safe-area-inset-top) + 56px)); left: 50%; transform: translateX(-50%); z-index: 40; background: var(--navy); color: var(--ivory); padding: 10px 18px; border-radius: 12px; font-weight: 700; box-shadow: 0 8px 20px rgba(0,0,0,0.35); max-width: 90vw; text-align: center; animation: fadeIn .2s ease both; opacity: 0; }
.toast.error { background: var(--red); }

/* Narrow / portrait tweaks */
@media (max-aspect-ratio: 4/5) {
  :root { --cw: clamp(58px, 17vw, 92px); --ow: clamp(20px, 5.4vw, 34px); --pw: clamp(54px, 15vw, 84px); }
  .center { top: 47%; }
  .feed { display: none; }
  .ring { height: 46vh; width: 94vw; }
  .top-info .ghost { display: none; }
}
@media (max-height: 520px) {
  :root { --cw: clamp(44px, 10vh, 70px); --ow: clamp(20px, 5vh, 32px); --pw: clamp(42px, 10vh, 64px); }
  .me { gap: 4px; }
  .feed { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-delay: 0ms !important; transition: none !important; }
}

/* Portrait: opponents in a tidy grid instead of an arc */
#opponents.grid {
  inset: auto 8px auto 8px; top: max(58px, calc(env(safe-area-inset-top) + 50px));
  display: grid; grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr)); gap: 10px 6px; justify-items: center;
}
#opponents.grid .opp { position: static; transform: none; }
#opponents.grid .plate { padding: 3px 7px 3px 3px; gap: 5px; }
#opponents.grid .plate .avatar { width: 22px; height: 22px; font-size: .7rem; }
#opponents.grid .plate .nm { max-width: 7ch; }
.pile-label { white-space: nowrap; }
.reveal-row .who .tag { flex: none; }
@media (max-width: 560px) {
  .reveal-row { grid-template-columns: 1fr auto; grid-template-areas: "who pts" "cards cards"; }
  .reveal-row .who { grid-area: who; }
  .reveal-row .pts { grid-area: pts; display: flex; gap: 8px; align-items: baseline; }
  .reveal-row .cards { grid-area: cards; justify-content: flex-start; }
}

/* Rival peek: the first selection is a player, not one of their cards. */
.opp.choose-rival { cursor: pointer; border-radius: 12px; }
.opp.choose-rival .plate { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(242,193,78,.25); }
.opp.choose-rival:hover .plate, .opp.choose-rival:focus-visible .plate { box-shadow: 0 0 0 4px var(--gold); }
.opp.choose-rival:focus-visible, .rival-peek .card:focus-visible { outline: 3px solid var(--gold); outline-offset: 4px; }
.rival-peek {
  position: fixed; inset: 0; z-index: 15; display: grid; place-items: center;
  padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  background: rgba(5,20,10,.75);
}
.rival-peek-panel {
  width: min(620px, 100%); max-height: 100%; overflow-y: auto; overscroll-behavior: contain;
  padding: clamp(16px, 4vw, 26px); border: 2px solid rgba(242,193,78,.7); border-radius: 18px;
  background: var(--felt-dark); box-shadow: 0 16px 40px rgba(0,0,0,.5); text-align: center;
}
.rival-peek-panel h2 { margin: 0; color: var(--ivory); font: 700 clamp(1.25rem, 5vw, 1.8rem) Georgia, serif; overflow-wrap: anywhere; }
.rival-peek-panel p { margin: 8px 0 14px; color: var(--cream); font-weight: 700; }
.rival-peek-cards { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; padding: 8px 4px; }
.card.rival-card { --w: clamp(64px, 18vw, 108px); }
.rival-peek-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 14px; }
.rival-peek-actions .btn { min-height: 44px; }

/* Keep hands reachable as penalties add cards. */
.hand { width: 100%; max-width: 100%; justify-content: safe center; overflow-x: auto; padding: 6px 4px; }

/* In a narrow or short viewport the table flows and scrolls instead of overlapping. */
@media (max-aspect-ratio: 4/5), (max-height: 520px) {
  #table { display: flex; flex-direction: column; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; }
  .topbar { position: relative; flex: none; }
  #opponents, #opponents.grid {
    position: relative; inset: auto; top: auto; display: grid; flex: none;
    grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr)); gap: 8px 6px;
    justify-items: center; padding: 4px 8px;
  }
  #opponents .opp, #opponents.grid .opp { position: static; transform: none; width: 100%; min-width: 0; max-width: 100%; gap: 4px; }
  #opponents .plate { min-width: 0; max-width: 100%; padding: 3px 7px 3px 3px; gap: 5px; }
  #opponents .plate .avatar { width: 22px; height: 22px; font-size: .7rem; }
  #opponents .plate .nm { min-width: 0; max-width: 7ch; }
  #opponents .plate .dot, #opponents .plate .sc { flex: none; }
  #opponents .plate .sc { padding: 1px 5px; }
  #opponents .mini-hand { max-width: 100%; overflow-x: auto; justify-content: safe center; padding: 4px; }
  .center { position: relative; left: auto; top: auto; transform: none; flex: none; justify-content: center; align-self: center; margin: 8px 0 12px; }
  .me { position: relative; left: auto; right: auto; bottom: auto; flex: none; width: 100%; margin-top: auto; gap: 6px; }
  .ring { position: fixed; }
  .feed { display: none; }
  #menu, #lobby { overflow-y: auto; align-content: safe center; }
}
@media (max-height: 520px) and (min-aspect-ratio: 5/4) {
  #table { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto auto minmax(min-content, 1fr); align-content: start; }
  .topbar { grid-column: 1 / -1; grid-row: 1; }
  #opponents, #opponents.grid { grid-column: 1; grid-row: 2; align-self: center; }
  .center { grid-column: 2; grid-row: 2; margin: 4px 8px; }
  .me { grid-column: 1 / -1; grid-row: 3; align-self: end; }
}
@media (max-width: 380px) {
  .topbar { gap: 4px; padding-left: 8px; padding-right: 8px; }
  .top-info, .top-actions { gap: 4px; }
  .topbar .icon-btn { width: 36px; height: 36px; }
  .topbar .pill { padding: 6px 8px; font-size: .75rem; }
  .actions { gap: 6px; }
  .act { min-width: 0; }
  #opponents .plate { gap: 2px; padding: 3px; }
  #opponents .plate .avatar { width: 18px; height: 18px; font-size: .65rem; }
  #opponents .plate .dot { width: 5px; height: 5px; }
  #opponents .plate .sc { padding: 1px 3px; font-size: .65rem; }
}
@media (max-height: 520px) {
  .rival-peek-panel { padding: 12px; }
  .rival-peek-panel p { margin: 4px 0 6px; }
  .rival-peek-cards { gap: 8px; padding: 4px; }
  .card.rival-card { --w: clamp(58px, 18vh, 90px); }
  .rival-peek-actions { margin-top: 8px; }
}
