:root {
  color-scheme: light;
  --paper: #f2f0e8;
  --surface: #fffcf5;
  --ink: #172d25;
  --muted: #4d6357;
  --line: #d0dbd2;
  --felt: #103f33;
  --felt-deep: #0c2f27;
  --on-felt: #f4faf4;
  --mint: #dceee3;
  --accent: #e8bb75;
  --primary: #14543c;
  --danger: #a32721;
  --suit-red: #a6292c;
  --serif: "Songti SC", "Noto Serif CJK SC", SimSun, serif;
  --sans: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-family: var(--sans);
  font-size: 100%;
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scrollbar-gutter: stable; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
}

button, input { font: inherit; }
button { touch-action: manipulation; }
button:enabled { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible {
  outline: 3px solid #1a5da4;
  outline-offset: 3px;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .6rem 1rem;
  min-height: 4.3rem;
  max-width: 76rem;
  margin-inline: auto;
  padding: .5rem clamp(.65rem, 3vw, 2rem);
}

.brand {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: .6rem;
  color: var(--ink);
  font: 700 clamp(1.1rem, 4vw, 1.35rem) var(--serif);
  text-decoration: none;
  letter-spacing: .045em;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 2rem;
  height: 2.2rem;
  border-radius: .4rem;
  color: var(--surface);
  background: var(--felt);
  font: 1.4rem var(--sans);
}

.identity {
  display: flex;
  justify-content: end;
  align-items: center;
  gap: .2rem .65rem;
  min-width: 0;
  color: var(--muted);
  font-size: .875rem;
}

#participant {
  max-width: min(38vw, 24rem);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.button {
  min-height: 2.75rem;
  border: 1px solid transparent;
  border-radius: .65rem;
  padding: .55rem 1.15rem;
  font-weight: 700;
  white-space: nowrap;
}

.primary {
  color: #fff;
  background: var(--primary);
}

.primary:enabled:active { background: #103f30; }
.primary:disabled { color: #4d6357; background: #e2e9df; }

.secondary {
  color: var(--ink);
  background: #fffdf8;
  border-color: #9eb3a5;
}

.secondary:enabled:active { background: var(--mint); }
.secondary:disabled { color: #697b70; background: #f1f3ee; border-color: #d6ded6; }

.text-button {
  background: transparent;
  color: var(--primary);
  padding-inline: .45rem;
  font-size: .875rem;
}
.text-button:disabled { opacity: .55; }

.guide-button {
  flex: none;
  width: 2.5rem;
  min-height: 2.5rem;
  padding: 0;
  border-radius: 50%;
  font-size: 1.15rem;
}

.layout {
  width: min(100%, 76rem);
  margin-inline: auto;
  padding: clamp(.45rem, 2vw, 1.5rem) clamp(.45rem, 2.5vw, 1.5rem) max(1rem, env(safe-area-inset-bottom));
}

.entry-card {
  display: grid;
  place-items: center;
  width: min(100%, 25rem);
  margin: clamp(1.25rem, 8vh, 5rem) auto 0;
  border: 1px solid var(--line);
  border-radius: 1.1rem;
  padding: clamp(1rem, 5vw, 2rem);
  background: var(--surface);
  box-shadow: 0 .55rem 2rem #203d2d12;
}

.entry-card h1 {
  margin: .5rem 0 1.4rem;
  font: 700 2.4rem var(--serif);
  letter-spacing: .12em;
}

.entry-illustration {
  display: flex;
  height: 5.4rem;
  padding: .5rem .75rem 0;
}

.entry-illustration span {
  display: grid;
  width: 3.3rem;
  height: 4.5rem;
  place-items: center;
  border-radius: .45rem;
  border: 1px solid #b4c5bb;
  background: #fffdf7;
  box-shadow: 0 .28rem .6rem #18392b24;
  font-size: 2.3rem;
  transform: rotate(-13deg);
}

.entry-illustration span + span {
  margin-left: -.7rem;
  color: var(--suit-red);
  transform: rotate(12deg);
}

.login-form {
  display: grid;
  width: 100%;
  gap: .65rem;
}

.login-form label { font-size: 1.02rem; font-weight: 700; }
.login-form input {
  width: 100%;
  min-height: 3.1rem;
  border: 1px solid #7e9989;
  border-radius: .55rem;
  padding: .5rem .75rem;
  background: #fff;
  color: var(--ink);
  font-size: 1.125rem;
}
.login-form .button { min-height: 3rem; }
.form-error { margin: 0; color: var(--danger); }
#lobby-error { margin-top: .7rem; }
.game-menu { display: grid; width: 100%; gap: .8rem; }
.game-menu-buttons { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; }
.room-invite { display: grid; gap: .25rem; justify-items: center; }
.room-code { font-family: ui-monospace, monospace; font-size: 2rem; letter-spacing: .12em; user-select: all; }
.room-status { margin: 0; color: var(--muted); text-align: center; }
.entry-card:has(#room-lobby:not([hidden])) .entry-illustration { display: none; }

.lobby-table {
  position: relative;
  display: grid;
  grid-template-areas:
    ". partner ."
    "left . right"
    ". player .";
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .38rem .28rem;
  padding: .7rem .5rem;
  border-radius: .8rem;
  background: radial-gradient(ellipse at center, #1d5442, var(--felt-deep));
}
.lobby-table::before {
  position: absolute;
  inset: 18% 16%;
  border: 1px solid #93b9a674;
  border-radius: 50%;
  content: "";
  pointer-events: none;
}
.lobby-seat[data-seat="0"] { grid-area: player; }
.lobby-seat[data-seat="1"] { grid-area: right; }
.lobby-seat[data-seat="2"] { grid-area: partner; }
.lobby-seat[data-seat="3"] { grid-area: left; }
.lobby-seat {
  position: relative;
  display: grid;
  align-content: center;
  gap: .12rem;
  min-width: 0;
  min-height: 3.55rem;
  padding: .25rem .32rem;
  border: 1px solid #a8c2b3;
  border-radius: .55rem;
  background: #f6faf3;
  color: var(--ink);
  text-align: center;
}
.lobby-seat span { font-size: .75rem; }
.lobby-seat-name {
  overflow: hidden;
  font-size: .95rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lobby-seat.is-occupied { background: #214a3c; color: var(--on-felt); }
.lobby-seat[aria-pressed="true"] { border-color: var(--accent); background: var(--accent); color: var(--ink); }
.lobby-seat:enabled:hover { background: var(--mint); }
.lobby-controls { display: flex; flex-wrap: wrap; justify-content: center; gap: .5rem; }
.lobby-controls .primary { flex: 1; }
.result-buttons { display: flex; flex-wrap: wrap; gap: .5rem; }

.table {
  border: 1px solid #c4d1c5;
  overflow: hidden;
  border-radius: clamp(.75rem, 2vw, 1.25rem);
  box-shadow: 0 .5rem 2.2rem #112f2415;
}

.felt {
  position: relative;
  padding: clamp(.45rem, 1.2vw, 1rem);
  color: var(--on-felt);
  background: radial-gradient(ellipse at 50% 22%, #1b5744, var(--felt) 59%, var(--felt-deep));
}

.felt-top {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  position: relative;
  z-index: 1;
  gap: .3rem;
}

.level-chip {
  display: inline-flex;
  justify-self: start;
  align-items: baseline;
  gap: .25rem;
  padding: .32rem .5rem;
  border: 1px solid #d2b287aa;
  border-radius: .55rem;
  background: #183c30;
  color: #f8dfae;
  font-weight: 650;
  white-space: nowrap;
}

.level-chip strong {
  font-size: 1.2rem;
  line-height: 1;
}

.turn-status {
  margin: 0;
  padding: .35rem .65rem;
  min-height: 2.15rem;
  max-width: min(38vw, 25rem);
  overflow: hidden;
  text-overflow: ellipsis;
  border-radius: .45rem;
  color: var(--on-felt);
  background: #0c2b23a8;
  font-size: clamp(.9rem, 3.8vw, 1.2rem);
  font-weight: 750;
  line-height: 1.2;
  text-align: center;
  white-space: nowrap;
}

/* Keep the live announcement available when the visible cue is on the seat. */
.turn-status.is-human { clip-path: inset(50%); }
.end-button {
  justify-self: end;
  color: var(--on-felt);
  background: #0c3028;
  border-color: #759e8a;
  padding-inline: clamp(.35rem, 2vw, .75rem);
  font-size: .875rem;
}
.end-button.is-unavailable { visibility: hidden; }

.felt :focus-visible { outline-color: #ffd48f; }

.play-area {
  position: relative;
  display: grid;
  gap: .55rem;
  margin: .65rem auto .2rem;
  max-width: 64rem;
}

.deal-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.deal-back, .table.is-dealing .hand-card.is-dealt:not(.is-face-up) {
  border-color: #deeadb;
  background:
    linear-gradient(135deg, #ffffff20, transparent 50%),
    repeating-linear-gradient(45deg, transparent 0 4px, #c2e4d324 4px 5px),
    #326451;
}

.deal-back {
  position: absolute;
  border: 1px solid #deeadb;
  border-radius: .28rem;
  box-shadow: 0 2px 4px #07271d4b;
}

.deal-back::after {
  content: "";
  position: absolute;
  inset: 3px;
  border: 1px solid #d7e6dba0;
  border-radius: .14rem;
}

.deal-deck, .deal-flight {
  width: 32px;
  height: 44px;
}

.deal-deck {
  display: grid;
  place-items: center;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%) rotate(-6deg);
  color: #e8efdd;
  font-size: 1.05rem;
  box-shadow: 2px 2px #d3e3d3, 4px 4px #285241, 6px 6px #c0d4c3, 6px 8px 9px #07271d77;
}

.deal-flight { inset: 0 auto auto 0; will-change: transform; }
.deal-stack {
  width: 19px;
  height: 26px;
  transform: translate(-50%, -50%);
  box-shadow: 1px 1px #d2e4d7, 2px 2px #27503e, 3px 3px #b9d2c3;
}

.table.is-dealing .trick-label,
.table.is-dealing .seat-actions,
.table.is-dealing .hand-card,
.table.is-dealing .hand-card:not(.is-face-up) :is(.card-rank, .card-suit),
.table.is-dealing .hand-card:not(.is-face-up)::after { visibility: hidden; }
.table.is-dealing .hand-card.is-dealt { visibility: visible; }

.trick-label {
  margin: 0;
  color: #dfede4;
  font-size: .9rem;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
}

.table-seats {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
  gap: clamp(.4rem, 1.25vw, .8rem);
}

.seat {
  min-width: 0;
  border: 1px solid #739a86;
  border-radius: .6rem;
  background: #102f28;
}

.seat-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: .3rem .65rem;
  line-height: 1.2;
  padding: .48rem .65rem;
}

.seat.is-turn { box-shadow: inset 0 0 0 1px var(--accent); border-color: var(--accent); }
.seat-name {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  margin: 0;
  font-size: 1rem;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.seat-detail { flex: none; color: #dfede4; font-size: .9rem; white-space: nowrap; }
.partner-seat { background: #204d3d; border-color: #95b5a2; }

.seat-turn-cue {
  display: none;
  flex: none;
  margin-inline-start: auto;
  font-size: 1rem;
  font-weight: 800;
  white-space: nowrap;
}

.human-seat.is-turn { box-shadow: inset 0 0 0 2px var(--accent); }
.human-seat.is-turn .seat-header {
  border-radius: .5rem .5rem 0 0;
  background: var(--accent);
  color: var(--ink);
}
.human-seat.is-turn .seat-turn-cue { display: block; }

.seat-actions {
  display: grid;
  align-content: start;
  gap: .3rem;
  block-size: 8.5rem;
  overflow: auto;
  scrollbar-gutter: stable;
  margin: 0;
  padding: .35rem;
  border-top: 1px solid #759e8a66;
  list-style: none;
  scrollbar-color: #9bc1ac #102f28;
}

.trick-entry {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .25rem .5rem;
  min-width: 0;
  padding: .3rem .45rem;
  border: 1px solid #759e8a66;
  border-radius: .45rem;
  background: #0c2b238c;
}

.trick-entry.is-current {
  border-color: var(--accent);
  background: #193e30;
}

.trick-caption {
  display: flex;
  align-items: baseline;
  gap: .35rem;
  color: #dfede4;
  font-size: .875rem;
}

.current-play { color: #f8dfae; font-weight: 700; }
.trick-cards {
  display: flex;
  flex-wrap: wrap;
  gap: .15rem;
  min-width: 0;
}

.hand-panel, .result {
  padding: clamp(.55rem, 2vw, 1.25rem);
  background: var(--surface);
}

.result h2, dialog h2 {
  margin: 0;
  font-size: clamp(1rem, 4vw, 1.3rem);
}

.group-selection[aria-pressed="true"] {
  border-color: #ae8d57;
  color: #563f21;
  background: #faedd5;
}

.hand {
  --card-peek: clamp(1.85rem, 3vw, 2.45rem);
  --card-width: clamp(3.4rem, 8vw, 5.35rem);
  --card-overlap: calc(var(--card-width) - var(--card-peek));
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  row-gap: .5rem;
  padding-block-start: .25rem;
  padding-inline-end: var(--card-overlap);
}

.card {
  display: grid;
  position: relative;
  align-content: center;
  justify-items: center;
  gap: .06rem;
  border: 1px solid #a9b7ad;
  border-radius: .42rem;
  padding: .12rem .04rem;
  background: #fffefa;
  color: #202d27;
  line-height: .98;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 1px 2px #09261825;
  white-space: nowrap;
}

.hand-card {
  flex: 0 0 var(--card-width);
  min-width: 0;
  min-height: clamp(3.85rem, 8vw, 5rem);
  margin-inline-end: calc(-1 * var(--card-overlap));
  align-content: start;
  justify-items: start;
  padding: .28rem .17rem .45rem;
  border-radius: .35rem;
  font-size: clamp(1.19rem, 2.05vw, 1.6rem);
}

.hand-card .card-rank,
.hand-card .card-suit {
  min-width: calc(var(--card-peek) - .42rem);
  text-align: center;
}

.hand-card:disabled { opacity: 1; }
.card.red { color: var(--suit-red); }
.card-suit { font-size: .77em; line-height: 1.02; }
.card.joker .card-rank { font-size: .72em; }
.card.joker .card-suit { font-size: .65em; }
.hand-card.joker .card-rank {
  width: calc(var(--card-peek) - .42rem);
  writing-mode: vertical-rl;
  text-orientation: upright;
  line-height: 1.75;
}
.card.level-card { border-color: #92703f; }
.card.wild { border: 2px solid #ad711e; background: #fff1d3; }

.hand-card[aria-pressed="true"] {
  transform: translateY(-.2rem);
  border-color: #14543c;
  background: #d2edda;
  box-shadow: inset 0 0 0 1px #14543c;
}

.hand-card[aria-pressed="true"]::before {
  content: "";
  position: absolute;
  bottom: .44rem;
  left: .48rem;
  width: .4rem;
  height: .23rem;
  border-bottom: 2px solid #14543c;
  border-left: 2px solid #14543c;
  transform: rotate(-45deg);
}

.hand-card.grouped::after {
  content: "";
  position: absolute;
  inset: auto auto .16rem .26rem;
  width: calc(var(--card-peek) - .6rem);
  height: .17rem;
  border-radius: 1rem;
  background: #739e8a;
}
.hand-card.grouped.bomb::after { background: #a97126; }
.mini-card {
  min-width: 1.35rem;
  min-height: 2.2rem;
  border-radius: .28rem;
  font-size: .95rem;
}
.mini-card.wild { border-width: 1px; }

.play-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .35rem .85rem;
  padding-top: .55rem;
}
.play-message {
  flex: 1 1 12rem;
  min-height: 1.35rem;
  margin: 0;
  color: var(--muted);
  font-size: .94rem;
}
.play-message.warning { color: var(--danger); font-weight: 700; }
.play-buttons { display: flex; gap: .45rem; margin-left: auto; }
.play-buttons .button { min-width: clamp(5rem, 17vw, 8rem); }

.result {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: .6rem 1rem;
  flex-wrap: wrap;
}
.result p { margin: .35rem 0 0; color: var(--muted); }
.result .form-error { color: var(--danger); }
.finish-order {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  padding: 0;
  margin: .65rem 0 0;
  list-style: none;
}
.finish-order li {
  border-radius: .45rem;
  background: #e8f0e8;
  padding: .3rem .5rem;
  color: var(--ink);
  font-size: .94rem;
  overflow-wrap: anywhere;
}

.connection-error {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .6rem;
  padding: .55rem .65rem;
  margin: .75rem auto 0;
  background: #fff0db;
  color: #723311;
  border: 1px solid #c09866;
  border-radius: .65rem;
}
.connection-error p { margin: 0; }

dialog {
  width: min(90vw, 25rem);
  border: 1px solid #b2c5b7;
  border-radius: .8rem;
  padding: 1.15rem;
  background: var(--surface);
  color: var(--ink);
}
dialog p { line-height: 1.5; }
dialog::backdrop { background: #102f28a8; }
.confirm-buttons { display: flex; justify-content: end; flex-wrap: wrap; gap: .55rem; }

.guide-dialog {
  width: min(92vw, 46rem);
  max-height: calc(100dvh - 1.5rem);
  padding: 0;
}

.guide-dialog[open] {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.guide-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .6rem;
  border-bottom: 1px solid var(--line);
  padding: .55rem clamp(.65rem, 3vw, 1rem);
}

.guide-header .button { padding-inline: .65rem; }
.guide-content {
  container-type: inline-size;
  overflow: auto;
  overscroll-behavior: contain;
  padding: .7rem clamp(.65rem, 3vw, 1rem) 1rem;
}

.guide-jump {
  display: flex;
  justify-content: center;
  gap: .4rem;
  margin-bottom: .6rem;
}
.guide-jump .button { padding: .35rem .65rem; font-size: .875rem; }

.guide-sections {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 20rem), 1fr));
  align-items: start;
  gap: .75rem;
}

.guide-section {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: .65rem;
}
.guide-section header {
  padding: .65rem .75rem;
  border-radius: .6rem .6rem 0 0;
  background: #eff4ee;
}
.guide-section h3 { margin: 0; font-size: 1.1rem; }
.guide-content p { margin: .3rem 0; color: var(--muted); }
.guide-section header p { margin-bottom: 0; font-size: .875rem; }

.guide-patterns { margin: 0; padding-inline: .75rem; }
.guide-patterns > div {
  display: grid;
  grid-template-columns: 4.125rem minmax(0, 1fr);
  align-items: center;
  gap: .375rem;
  padding: .55rem 0;
}
.guide-patterns > div + div {
  border-top: 1px solid var(--line);
}
.guide-patterns > .guide-bomb-range { grid-template-columns: 5.875rem minmax(0, 1fr); }
.guide-patterns dt { font-size: .9375rem; font-weight: 750; }

.guide-example, .guide-card-group {
  display: flex;
  flex-wrap: wrap;
  min-width: 0;
}
.guide-example { gap: .3rem .55rem; margin: 0; }
.guide-card-group { gap: .1875rem; }
.guide-example .mini-card {
  width: 1.8125rem;
  min-width: 0;
  min-height: 2.8125rem;
  padding: 0;
}
.guide-example .card .card-rank { font-size: 1.25rem; letter-spacing: -.045em; }
.guide-example .card .card-suit { font-size: 1rem; }
.guide-example .joker .card-rank { writing-mode: vertical-rl; text-orientation: upright; }
.guide-example .joker .card-suit { display: none; }
.guide-rules { margin-top: .7rem; font-size: .875rem; }
.guide-rules b { color: var(--ink); }

@container (min-width: 40.75rem) {
  .guide-jump { display: none; }
}

@container (max-width: 20rem) {
  .guide-patterns > .guide-bomb-range { grid-template-columns: minmax(0, 1fr); }
}

@media (min-width: 36rem) {
  .mini-card { min-width: 2.05rem; min-height: 2.8rem; font-size: 1.16rem; }
}

@media (min-width: 42rem) {
  .table-seats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .human-seat { grid-column: 2; }
}

@media (max-width: 30rem) {
  .topbar-content { min-height: 3.4rem; }
  .felt-top { grid-template-columns: auto minmax(0, 1fr) auto; }
  .play-buttons { width: 100%; }
  .play-buttons .button { flex: 1; }
  .play-message { flex-basis: 100%; }
}

@media (max-width: 23rem) {
  .brand { gap: .3rem; }
  .brand-mark { width: 1.5rem; height: 1.75rem; font-size: 1.15rem; }
  .identity { gap: .1rem; }
  #participant { max-width: 34vw; }
}

@media (max-width: 41.99rem), (orientation: landscape) and (max-height: 30rem) and (max-width: 64rem) {
  html { scrollbar-gutter: auto; }

  body.has-game {
    --phone-rank-size: 1.125rem;
    --phone-suit-size: .875rem;
  }

  body.has-game .topbar { padding-top: env(safe-area-inset-top); }

  body.has-game .topbar-content {
    min-height: 2.75rem;
    padding: 0 max(.55rem, env(safe-area-inset-right)) 0 max(.55rem, env(safe-area-inset-left));
  }

  body.has-game .brand {
    gap: .35rem;
    font-size: 1.05rem;
  }

  body.has-game .brand-mark {
    width: 1.55rem;
    height: 1.65rem;
    font-size: 1.1rem;
  }

  body.has-game .identity { gap: .2rem; }
  body.has-game .guide-button { width: 2.4rem; min-height: 2.4rem; }
  body.has-game #logout { padding: .2rem .35rem; }

  body.has-game .layout {
    padding: .25rem max(.25rem, env(safe-area-inset-right)) max(.25rem, env(safe-area-inset-bottom)) max(.25rem, env(safe-area-inset-left));
  }

  body.has-game .felt, body.has-game .hand-panel { padding: .35rem; }
  body.has-game .felt-top { grid-template-columns: auto minmax(0, 1fr) auto; }
  body.has-game .level-chip { padding: .24rem .36rem; }
  body.has-game .turn-status { max-width: none; padding: .28rem; }

  body.has-game .end-button {
    min-height: 2.2rem;
    padding: .2rem .4rem;
  }

  body.has-game .play-area {
    gap: .18rem;
    margin: .22rem 0 0;
  }

  body.has-game .trick-label {
    font-size: .82rem;
    line-height: 1.2;
  }

  body.has-game .table-seats {
    grid-template-columns: minmax(0, 1fr);
    gap: .22rem;
  }

  body.has-game .seat {
    display: grid;
    grid-column: 1;
    grid-template-columns: 4.1rem minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    align-items: center;
    block-size: 2.4rem;
  }

  body.has-game .seat-header {
    flex-direction: column;
    justify-content: center;
    gap: .1rem;
    min-height: 2.15rem;
    padding: .06rem .45rem;
    line-height: 1.1;
  }

  body.has-game .seat-detail { font-size: .82rem; }
  body.has-game .seat-detail:empty { display: none; }
  body.has-game .human-seat.is-turn .seat-header { border-radius: .5rem 0 0 .5rem; }
  body.has-game .seat-turn-cue { margin-inline-start: 0; font-size: .8rem; }
  body.has-game .seat-turn-extra { display: none; }

  body.has-game .seat-actions {
    display: flex;
    align-items: center;
    gap: .24rem;
    block-size: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-inline: contain;
    padding: 0 .25rem;
    border-top: 0;
    border-inline-start: 1px solid #759e8a66;
    scrollbar-gutter: auto;
    scrollbar-width: none;
  }

  body.has-game .trick-entry {
    flex: 0 0 auto;
    flex-wrap: nowrap;
    gap: .25rem;
    padding: 0 .28rem;
  }

  body.has-game .trick-caption {
    flex-direction: column;
    gap: .02rem;
    font-size: .82rem;
    line-height: 1.05;
    white-space: nowrap;
  }

  body.has-game .trick-cards { flex-wrap: nowrap; gap: .12rem; }

  body.has-game .table .card .card-rank { font-size: var(--phone-rank-size); }
  body.has-game .table .card .card-suit { font-size: var(--phone-suit-size); }
  body.has-game .table .card.joker .card-suit { display: none; }
  body.has-game .hand-card.joker .card-rank { line-height: 1; }
  body.has-game .hand-card[aria-pressed="true"]::before { display: none; }

  body.has-game .table .mini-card {
    gap: 0;
    min-width: 1.45rem;
    min-height: 0;
    padding: 0 .075rem;
  }

  body.has-game .play-footer {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: .2rem;
    padding-top: .25rem;
  }

  body.has-game .play-message { min-width: 0; line-height: 1.2; }
  body.has-game .play-buttons { width: 100%; gap: .25rem; }
  body.has-game .play-buttons .button { flex: 1 1 0; min-width: 0; padding-inline: .45rem; }
  body.has-game .play-buttons .group-selection { flex-grow: 1.35; }
}

@media (orientation: landscape) and (max-height: 30rem) and (max-width: 64rem) {
  body.has-game .table {
    display: grid;
    grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr);
  }

  body.has-game .felt { align-self: start; }
  body.has-game .hand-card { min-height: 3.3rem; }
}

@media (max-width: 41.99rem) and (max-height: 36rem), (orientation: landscape) and (max-height: 30rem) and (max-width: 64rem) {
  body.has-game .layout { padding-block: .125rem max(.125rem, env(safe-area-inset-bottom)); }
  body.has-game .felt, body.has-game .hand-panel { padding-block: .25rem; }
  body.has-game .play-area { margin-top: .125rem; gap: .125rem; }
  body.has-game .table-seats { gap: .15rem; }
  body.has-game .hand { row-gap: .35rem; }
}

@media (max-width: 41.99rem) and (max-height: 33rem) and (orientation: portrait) {
  body.has-game .topbar-content, body.has-game #logout { min-height: 2.4rem; }
  body.has-game .hand-card { min-height: 2.9rem; padding-block: .15rem .35rem; }
}

/* Keep each seat and the action bar in place between turns. */
@media (orientation: portrait) and (22.5rem <= width < 42rem) and (min-height: 39rem),
       (orientation: landscape) and (44rem <= width <= 64rem) and (20rem <= height <= 30rem) {
  body.has-game {
    --seat-height: 4.2rem;
    --table-card-height: 2.4rem;
    --hand-card-height: 2.75rem;
    display: flex;
    flex-direction: column;
  }

  body.has-game .layout, body.has-game .table { flex: 1 0 auto; }
  body.has-game .layout, body.has-game .felt {
    display: flex;
    flex-direction: column;
  }

  body.has-game .table { display: grid; }
  body.has-game .felt, body.has-game .hand-panel { padding: .375rem; }
  body.has-game .felt { align-self: stretch; }
  body.has-game .turn-status { font-size: 1.0625rem; }

  body.has-game .play-area {
    flex: 1;
    grid-template-rows: auto minmax(0, 1fr);
    width: 100%;
    gap: .25rem;
  }

  body.has-game .trick-label { font-size: .9375rem; }

  body.has-game .table-seats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: var(--seat-height) var(--side-seat-height, var(--seat-height)) var(--seat-height);
    align-content: space-evenly;
    align-items: stretch;
    gap: .3rem;
  }

  body.has-game .seat {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    align-items: stretch;
    block-size: auto;
  }

  body.has-game .partner-seat, body.has-game .human-seat {
    grid-column: 1 / -1;
    justify-self: center;
    width: min(100%, 16rem);
  }

  body.has-game .partner-seat { grid-row: 1; }
  body.has-game .left-seat { grid-area: 2 / 1; }
  body.has-game .right-seat { grid-area: 2 / 2; }
  body.has-game .human-seat { grid-row: 3; }

  body.has-game .seat-header {
    flex-direction: row;
    justify-content: space-between;
    min-height: 0;
    padding: .11rem .35rem;
  }

  body.has-game .seat-name { font-size: 1.0625rem; }
  body.has-game .seat-detail, body.has-game .trick-caption { font-size: .875rem; }
  body.has-game .human-seat.is-turn .seat-header { border-radius: .5rem .5rem 0 0; }
  body.has-game .seat-turn-cue { margin-inline-start: auto; font-size: 1.0625rem; }
  body.has-game .seat-turn-extra { display: inline; }

  body.has-game .seat-actions {
    border-top: 1px solid #759e8a66;
    border-inline-start: 0;
  }

  body.has-game .table .mini-card {
    min-width: 1.8125rem;
    min-height: var(--table-card-height);
  }

  body.has-game .table .card .card-rank { letter-spacing: -.04em; }
  body.has-game .table .card.joker .card-rank {
    writing-mode: vertical-rl;
    text-orientation: upright;
  }

  body.has-game .hand-panel {
    display: grid;
    grid-template-rows: minmax(2rem, auto) minmax(0, 1fr) auto;
    gap: .1875rem;
    min-width: 0;
  }

  body.has-game .hand {
    --card-peek: 1.875rem;
    --card-width: 3.25rem;
    grid-row: 2;
    row-gap: .24rem;
    padding-block-start: .125rem;
  }

  body.has-game .hand-card {
    min-height: var(--hand-card-height);
    padding: .14rem .09rem .3rem;
  }

  body.has-game .play-footer { display: contents; }
  body.has-game .play-message { grid-row: 1; align-self: center; font-size: .875rem; line-height: 1.125; }
  body.has-game .play-buttons { grid-row: 3; }
}

@media (orientation: portrait) and (22.5rem <= width < 42rem) and (min-height: 39rem) {
  body.has-game {
    --seat-height: 5.25rem;
    --hand-panel-height: 15rem;
  }

  body.has-game .table { grid-template-rows: minmax(min-content, 1fr) var(--hand-panel-height); }
  body.has-game .play-area { margin-top: .125rem; gap: .125rem; }
  body.has-game .table-seats { row-gap: .2rem; }
  body.has-game .seat-name { font-size: 1.1875rem; }
  body.has-game .hand { align-content: end; }

  body.has-game .seat-actions {
    display: grid;
    align-content: start;
    align-items: start;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  body.has-game .trick-entry { flex-direction: column; align-items: flex-start; gap: .12rem; }
  body.has-game .trick-caption { flex-direction: row; gap: .35rem; }
  body.has-game .trick-entry:not(:has(.trick-cards)) { font-weight: 700; }
}

@media (orientation: portrait) and (22.5rem <= width < 42rem) and (min-height: 42.5rem),
       (orientation: landscape) and (44rem <= width <= 64rem) and (23.5rem <= height <= 30rem) {
  body.has-game {
    --phone-rank-size: 1.375rem;
    --phone-suit-size: 1.0625rem;
    --seat-height: 5rem;
    --table-card-height: 2.8125rem;
    --hand-card-height: 3.25rem;
  }

  body.has-game .table .mini-card { gap: .06rem; }
  body.has-game .hand { row-gap: .25rem; }
  body.has-game .hand-card { padding-block: .14rem .37rem; }
}

@media (orientation: portrait) and (22.5rem <= width < 42rem) and (min-height: 42.5rem) {
  body.has-game {
    --seat-height: 5.875rem;
    --hand-panel-height: 16.375rem;
  }
}

@media (orientation: portrait) and (22.5rem <= width < 42rem) and (min-height: 46rem) {
  body.has-game {
    --seat-height: 6.125rem;
    --side-seat-height: 9.125rem;
  }

  body.has-game :is(.left-seat, .right-seat) .trick-cards { flex-wrap: wrap; }
}

@media (orientation: landscape) and (44rem <= width <= 64rem) and (20rem <= height <= 30rem) {
  body.has-game .topbar-content { min-height: 2.1rem; }
  body.has-game .brand-mark { height: 1.45rem; }
  body.has-game .guide-button { width: 2rem; min-height: 2rem; }
  body.has-game #logout { min-height: 2rem; }
  body.has-game .table { grid-template-columns: minmax(0, 61fr) minmax(0, 39fr); }
  body.has-game .hand { align-content: center; }
  body.has-game .trick-entry { gap: .2rem; }
}

@media (orientation: landscape) and (44rem <= width <= 64rem) and (20rem <= height < 23.5rem) {
  body.has-game {
    --seat-height: 4.125rem;
    --hand-card-height: 2.625rem;
  }

  body.has-game .felt, body.has-game .hand-panel { padding: .3125rem; }
  body.has-game .play-area { gap: .125rem; }
  body.has-game .table-seats { gap: .22rem; }
  body.has-game .hand-panel { row-gap: .15rem; }
  body.has-game .hand { padding-block-start: .15rem; }
  body.has-game .hand-card { padding-block: .12rem .28rem; }
}
