/*
 * A restrained green-table presentation for the multiplayer game. The cards
 * provide the physical character; the surrounding interface stays quiet.
 */

html[data-ui="tabletop"] {
  --table-felt: #155d3b;
  --table-felt-deep: #0b3f29;
  --table-felt-dark: #082f20;
  --table-walnut: #2b2019;
  --table-cream: #f7efd9;
  --table-cream-muted: #d8cba8;
  --table-gold: #ddb654;
  --table-gold-light: #f2d984;
  --table-panel: rgba(5, 43, 27, .72);
  --table-panel-solid: #0d432c;
  --table-line: rgba(247, 239, 217, .24);
  --table-line-strong: rgba(247, 239, 217, .42);
}

html[data-ui="tabletop"][data-phase="playing"],
html[data-ui="tabletop"][data-phase="roundEnd"],
html[data-ui="tabletop"][data-phase="gameOver"] {
  background: var(--table-felt-deep);
}

html[data-ui="tabletop"][data-phase="playing"] body,
html[data-ui="tabletop"][data-phase="roundEnd"] body,
html[data-ui="tabletop"][data-phase="gameOver"] body {
  background: var(--table-felt-deep);
}

html[data-ui="tabletop"] .game-header {
  min-height: 60px;
  background: var(--table-walnut);
  border-bottom: 1px solid rgba(242, 217, 132, .38);
  box-shadow: none;
}

html[data-ui="tabletop"] .game-header .eyebrow {
  color: #cdbf9f;
}

html[data-ui="tabletop"] .room-code {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding-inline: 3px;
  color: #fffaf0;
  text-shadow: none;
}

html[data-ui="tabletop"] .connection {
  color: #ded2b7;
}

html[data-ui="tabletop"][data-phase="playing"] .game,
html[data-ui="tabletop"][data-phase="roundEnd"] .game,
html[data-ui="tabletop"][data-phase="gameOver"] .game {
  background: var(--table-felt-deep);
}

html[data-ui="tabletop"][data-phase="playing"] .game {
  padding-bottom: 0;
}

html[data-ui="tabletop"][data-phase="playing"] .table {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas:
    "scores"
    "turn"
    "surface"
    "hand";
  gap: 8px;
  width: 100%;
  max-width: 1180px;
  min-height: calc(100dvh - 60px);
  padding: 8px 8px calc(78px + env(safe-area-inset-bottom));
}

html[data-ui="tabletop"][data-phase="playing"] .table.has-undo {
  padding-bottom: calc(126px + env(safe-area-inset-bottom));
}

html[data-ui="tabletop"][data-phase="playing"] .score-strip {
  grid-area: scores;
  gap: 6px;
  min-width: 0;
  margin: 0;
  padding: 0;
  scrollbar-width: none;
}

html[data-ui="tabletop"][data-phase="playing"] .score-chip {
  display: grid;
  align-content: center;
  gap: 2px;
  min-width: 224px;
  min-height: 60px;
  padding: 6px 10px;
  color: var(--table-cream);
  background: rgba(5, 42, 27, .78);
  border: 1px solid var(--table-line);
  border-radius: 8px;
  box-shadow: none;
}

html[data-ui="tabletop"][data-phase="playing"] .score-chip:first-child:nth-last-child(2),
html[data-ui="tabletop"][data-phase="playing"] .score-chip:first-child:nth-last-child(2) ~ .score-chip {
  flex: 1 1 0;
  min-width: 0;
}

html[data-ui="tabletop"][data-phase="playing"] .score-chip.mine {
  background: rgba(24, 100, 64, .76);
  border-color: var(--table-line-strong);
}

html[data-ui="tabletop"][data-phase="playing"] .score-chip-name {
  overflow: hidden;
  color: var(--table-cream-muted);
  font-size: .72rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

html[data-ui="tabletop"][data-phase="playing"] .score-chip-value {
  color: var(--table-cream);
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

html[data-ui="tabletop"][data-phase="playing"] .score-chip-books,
html[data-ui="tabletop"][data-phase="playing"] .score-chip-status {
  margin: 0;
  color: var(--table-cream-muted);
  font-size: .64rem;
  line-height: 1.15;
}

html[data-ui="tabletop"][data-phase="playing"] .score-chip-books {
  color: var(--table-cream);
}

html[data-ui="tabletop"][data-phase="playing"] .turn-banner {
  grid-area: turn;
  display: grid;
  align-content: center;
  min-height: 48px;
  margin: 0;
  padding: 7px 12px;
  color: #352d1b;
  background: #f0dfae;
  border: 1px solid #d2b35f;
  border-radius: 8px;
  box-shadow: none;
}

html[data-ui="tabletop"][data-phase="playing"] .turn-banner.mine {
  color: #2e2717;
  background: var(--table-gold-light);
  border-color: var(--table-gold);
}

html[data-ui="tabletop"][data-phase="playing"] .turn-banner strong {
  display: block;
  overflow: hidden;
  font-size: .94rem;
  font-weight: 850;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

html[data-ui="tabletop"][data-phase="playing"] .turn-banner span {
  display: block;
  overflow: hidden;
  margin-top: 2px;
  color: #665a38;
  font-size: .7rem;
  font-weight: 700;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

html[data-ui="tabletop"][data-phase="playing"] .tabletop-surface {
  grid-area: surface;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(108px, 31%);
  grid-template-areas: "melds piles";
  gap: 8px;
  min-width: 0;
  padding: 9px;
  overflow: hidden;
  background: var(--table-felt);
  border: 2px solid #062e1e;
  border-radius: 16px;
  box-shadow: none;
}

html[data-ui="tabletop"][data-phase="playing"] .piles {
  grid-area: piles;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
  gap: 8px;
  min-width: 0;
  max-width: none;
  margin: 0;
}

html[data-ui="tabletop"][data-phase="playing"] .pile {
  min-width: 0;
  min-height: 118px;
  padding: 7px 4px;
  gap: 3px;
  color: var(--table-cream);
  background: rgba(4, 45, 28, .68);
  border: 1px solid var(--table-line);
  border-radius: 9px;
  box-shadow: none;
  transition: transform .15s ease, border-color .15s ease, background-color .15s ease;
}

html[data-ui="tabletop"][data-phase="playing"] .pile:not(:disabled) {
  background: rgba(7, 63, 39, .9);
  border: 2px solid var(--table-gold-light);
}

html[data-ui="tabletop"][data-phase="playing"] .pile:not(:disabled):active {
  transform: translateY(1px);
}

html[data-ui="tabletop"][data-phase="playing"] .pile:disabled {
  opacity: 1;
  color: #c9bea3;
  background: rgba(7, 47, 31, .58);
  border-color: rgba(238, 226, 194, .18);
}

html[data-ui="tabletop"][data-phase="playing"] .pile strong {
  color: inherit;
  font-size: .7rem;
  line-height: 1.15;
}

html[data-ui="tabletop"][data-phase="playing"] .pile small {
  color: #cfc2a2;
  font-size: .6rem;
  line-height: 1.15;
}

html[data-ui="tabletop"][data-phase="playing"] .pile .card-back,
html[data-ui="tabletop"][data-phase="playing"] .pile .playing-card {
  width: 50px;
  height: 68px;
  border-radius: 6px;
}

html[data-ui="tabletop"][data-phase="playing"] .card-back {
  color: #fff8e7;
  background: repeating-linear-gradient(45deg, #174e38 0 7px, #0f402d 7px 14px);
  border: 3px double #d8c07c;
  box-shadow: 0 3px 7px rgba(0, 18, 10, .26);
}

html[data-ui="tabletop"][data-phase="playing"] .playing-card {
  color: #121a16;
  background: #fffdf7;
  border-color: #d9cfbb;
  box-shadow: 0 3px 7px rgba(0, 22, 12, .24);
}

html[data-ui="tabletop"][data-phase="playing"] .playing-card.wild {
  background: #f5effb;
}

html[data-ui="tabletop"][data-phase="playing"] .playing-card.red {
  color: var(--red);
}

html[data-ui="tabletop"][data-phase="playing"] .playing-card.joker {
  color: #604879;
}

html[data-ui="tabletop"][data-phase="playing"] .playing-card .corner {
  top: 5px;
  left: 6px;
  font-size: .82rem;
  line-height: .88;
}

html[data-ui="tabletop"][data-phase="playing"] .meld-area {
  grid-area: melds;
  min-width: 0;
  margin: 0;
  padding: 8px;
  overflow: auto;
  color: var(--table-cream);
  background: var(--table-panel);
  border: 1px solid var(--table-line);
  border-radius: 10px;
  box-shadow: none;
  scrollbar-width: thin;
}

html[data-ui="tabletop"][data-phase="playing"] .team-melds + .team-melds {
  margin-top: 8px;
  padding-top: 8px;
  border-color: var(--table-line);
}

html[data-ui="tabletop"][data-phase="playing"] .team-melds h3 {
  margin-bottom: 5px;
  color: var(--table-cream-muted);
  font-size: .66rem;
}

html[data-ui="tabletop"][data-phase="playing"] .meld-row {
  gap: 7px;
  padding: 1px 1px 5px;
  scroll-padding-inline: 1px;
  scrollbar-width: thin;
}

html[data-ui="tabletop"][data-phase="playing"] .meld-row > .muted {
  color: var(--table-cream-muted);
  font-size: .72rem;
}

html[data-ui="tabletop"][data-phase="playing"] .meld {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  grid-template-areas:
    "visual copy"
    "add add";
  align-items: center;
  gap: 6px;
  flex: 0 1 142px;
  min-width: 106px;
  max-width: 142px;
  min-height: 74px;
  padding: 6px;
  color: var(--table-cream);
  background: rgba(4, 37, 24, .7);
  border: 1px solid var(--table-line);
  border-radius: 8px;
  box-shadow: none;
  text-align: left;
}

html[data-ui="tabletop"][data-phase="playing"] .meld.complete {
  border-color: var(--table-line-strong);
}

html[data-ui="tabletop"][data-phase="playing"] .meld.available-target {
  border-color: var(--table-gold-light);
  box-shadow: 0 0 0 2px var(--table-gold);
}

html[data-ui="tabletop"][data-phase="playing"] .meld-visual {
  grid-area: visual;
  display: block;
  width: 44px;
  height: 60px;
}

html[data-ui="tabletop"][data-phase="playing"] .meld-visual .playing-card {
  width: 44px;
  height: 60px;
  border-radius: 5px;
  font-size: 1rem;
}

html[data-ui="tabletop"][data-phase="playing"] .meld-visual .playing-card .corner {
  top: 4px;
  left: 5px;
  font-size: .62rem;
}

html[data-ui="tabletop"][data-phase="playing"] .meld-copy {
  grid-area: copy;
  min-width: 0;
}

html[data-ui="tabletop"][data-phase="playing"] .meld-copy strong {
  overflow: hidden;
  color: var(--table-cream);
  font-family: Georgia, serif;
  font-size: 1rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

html[data-ui="tabletop"][data-phase="playing"] .meld-copy small {
  display: block;
  color: var(--table-cream-muted);
  font-size: .61rem;
  line-height: 1.3;
}

html[data-ui="tabletop"][data-phase="playing"] .meld-kind {
  display: block;
  margin-bottom: 2px;
  color: #c9decf;
  font-size: .56rem;
  font-weight: 900;
  letter-spacing: .05em;
  text-transform: uppercase;
}

html[data-ui="tabletop"][data-phase="playing"] .meld-dirty .meld-kind {
  color: #d9d4c4;
}

html[data-ui="tabletop"][data-phase="playing"] .meld-dirty .meld-wild-count {
  color: var(--table-gold-light);
  font-weight: 800;
}

html[data-ui="tabletop"][data-phase="playing"] .meld-wild .meld-kind {
  color: #d9c8ed;
}

html[data-ui="tabletop"][data-phase="playing"] .meld-add {
  grid-area: add;
  width: 100%;
  min-height: 44px;
  margin-top: 1px;
  padding: 5px;
  color: #302710;
  background: var(--table-gold-light);
  border-color: var(--table-gold);
  border-radius: 7px;
  font-size: .68rem;
}

html[data-ui="tabletop"][data-phase="playing"] .hand-area {
  grid-area: hand;
  min-width: 0;
  margin: 0;
  padding: 8px 10px;
  overflow: hidden;
  color: var(--table-cream);
  background: var(--table-panel-solid);
  border: 1px solid var(--table-line);
  border-radius: 10px;
  box-shadow: none;
}

html[data-ui="tabletop"][data-phase="playing"] .hand-area.has-undo {
  padding-bottom: 8px;
}

html[data-ui="tabletop"][data-phase="playing"] .hand-area .section-heading {
  margin-bottom: 1px;
}

html[data-ui="tabletop"][data-phase="playing"] .opening-progress {
  color: var(--table-cream);
  background: rgba(4, 37, 24, .62);
  border-color: var(--table-line);
}

html[data-ui="tabletop"][data-phase="playing"] .opening-progress-label,
html[data-ui="tabletop"][data-phase="playing"] .opening-progress small {
  color: var(--table-cream-muted);
}

html[data-ui="tabletop"][data-phase="playing"] .opening-progress.ready {
  background: rgba(72, 55, 15, .46);
  border-color: var(--table-gold);
}

html[data-ui="tabletop"][data-phase="playing"] .opening-progress.ready small {
  color: var(--table-gold-light);
}

html[data-ui="tabletop"][data-phase="playing"] .opening-progress.projected {
  border-color: var(--table-line-strong);
}

html[data-ui="tabletop"][data-phase="playing"] .hand-area h2 {
  color: var(--table-cream);
  font-family: inherit;
  font-size: 1.02rem;
  font-weight: 850;
  text-shadow: none;
}

html[data-ui="tabletop"][data-phase="playing"] .hand-area .muted {
  color: var(--table-cream-muted);
  font-size: .67rem;
}

html[data-ui="tabletop"][data-phase="playing"] .hand {
  min-height: 108px;
  padding: 7px 3px 11px;
  scroll-padding-inline: 3px;
  scrollbar-color: rgba(239, 220, 166, .4) transparent;
}

html[data-ui="tabletop"][data-phase="playing"] .hand .card-button {
  position: relative;
  flex: 0 0 48px;
  width: 70px;
  min-width: 44px;
  min-height: 104px;
  border-radius: 7px;
  transition: transform .15s ease;
}

html[data-ui="tabletop"][data-phase="playing"] .hand .card-button:last-child {
  flex-basis: 72px;
}

html[data-ui="tabletop"][data-phase="playing"] .hand .playing-card {
  width: 70px;
  height: 98px;
  border-radius: 7px;
  transition: transform .15s ease, box-shadow .15s ease;
}

html[data-ui="tabletop"][data-phase="playing"] .hand .card-button.selected {
  z-index: 3;
}

html[data-ui="tabletop"][data-phase="playing"] .hand .card-button.selected .playing-card {
  transform: translateY(-6px);
  box-shadow: 0 0 0 3px var(--table-gold), 0 7px 11px rgba(0, 18, 10, .34);
}

html[data-ui="tabletop"][data-phase="playing"] .action-dock {
  position: fixed;
  z-index: 15;
  left: 50%;
  right: auto;
  bottom: 0;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  width: min(100%, 700px);
  margin: 0;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #092f20;
  border: 1px solid var(--table-line);
  border-bottom: 0;
  border-radius: 10px 10px 0 0;
  box-shadow: none;
  backdrop-filter: none;
}

html[data-ui="tabletop"][data-phase="playing"] .action-dock button {
  min-height: 46px;
  border-radius: 7px;
}

html[data-ui="tabletop"][data-phase="playing"] .action-dock .primary {
  color: #302710;
  background: var(--table-gold);
  border-color: var(--table-gold-light);
}

html[data-ui="tabletop"][data-phase="playing"] .action-dock .secondary {
  color: #173025;
  background: var(--table-cream);
  border-color: #d5c9a9;
}

html[data-ui="tabletop"][data-phase="playing"] .action-dock .ghost-dark {
  color: var(--table-cream);
  background: transparent;
  border-color: var(--table-line-strong);
}

html[data-ui="tabletop"][data-phase="playing"] .action-dock button:disabled {
  opacity: 1;
  color: #8f938b;
  background: #27453a;
  border-color: #3c5a4e;
}

html[data-ui="tabletop"][data-phase="playing"] button:focus-visible,
html[data-ui="tabletop"][data-phase="roundEnd"] button:focus-visible,
html[data-ui="tabletop"][data-phase="gameOver"] button:focus-visible {
  outline: 3px solid #ffe49a;
  outline-offset: 2px;
}

html[data-ui="tabletop"][data-phase="playing"] .toast {
  color: #fff8e8;
  background: #251d17;
  border: 1px solid var(--table-line-strong);
  box-shadow: none;
}

html[data-ui="tabletop"][data-phase="roundEnd"] .game > .panel,
html[data-ui="tabletop"][data-phase="gameOver"] .game > .panel {
  width: min(calc(100% - 28px), 720px);
  color: #17251f;
  background: #fffdf6;
  border: 2px solid #6a4b31;
  border-radius: 14px;
  box-shadow: none;
}

html[data-ui="tabletop"][data-phase="roundEnd"] .round-score,
html[data-ui="tabletop"][data-phase="gameOver"] .round-score {
  background: #f3ead8;
  border: 1px solid #d8c9aa;
}

@media (min-width: 760px) {
  html[data-ui="tabletop"][data-phase="playing"] .table {
    grid-template-columns: minmax(230px, .8fr) minmax(320px, 1.2fr);
    grid-template-areas:
      "scores turn"
      "surface surface"
      "hand hand";
    gap: 10px;
    padding: 12px 14px;
  }

  html[data-ui="tabletop"][data-phase="playing"] .table.has-undo {
    padding-bottom: 12px;
  }

  html[data-ui="tabletop"][data-phase="playing"] .score-strip {
    align-items: stretch;
  }

  html[data-ui="tabletop"][data-phase="playing"] .tabletop-surface {
    grid-template-columns: minmax(0, 1fr) minmax(236px, 28%);
    grid-template-rows: minmax(0, 1fr);
    gap: 10px;
    height: clamp(350px, 44dvh, 420px);
    min-height: 330px;
    padding: 12px;
    border-radius: 18px;
  }

  html[data-ui="tabletop"][data-phase="playing"] .piles {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-content: center;
  }

  html[data-ui="tabletop"][data-phase="playing"] .pile {
    min-height: 176px;
  }

  html[data-ui="tabletop"][data-phase="playing"] .pile .card-back,
  html[data-ui="tabletop"][data-phase="playing"] .pile .playing-card {
    width: 62px;
    height: 84px;
  }

  html[data-ui="tabletop"][data-phase="playing"] .meld-area {
    min-height: 252px;
    padding: 10px;
  }

  html[data-ui="tabletop"][data-phase="playing"] .meld {
    flex-basis: 156px;
    min-width: 120px;
    max-width: 156px;
  }

  html[data-ui="tabletop"][data-phase="playing"] .hand-area {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "heading heading"
      "hand actions";
    align-items: end;
    gap: 0 10px;
    padding: 8px 12px 10px;
  }

  html[data-ui="tabletop"][data-phase="playing"] .hand-area.has-undo {
    padding-bottom: 10px;
  }

  html[data-ui="tabletop"][data-phase="playing"] .hand-area .section-heading {
    grid-area: heading;
  }

  html[data-ui="tabletop"][data-phase="playing"] .hand {
    grid-area: hand;
  }

  html[data-ui="tabletop"][data-phase="playing"] .action-dock {
    position: static;
    grid-area: actions;
    align-self: end;
    width: 292px;
    margin: 0;
    padding: 7px;
    transform: none;
    border: 1px solid var(--table-line);
    border-radius: 9px;
  }

  html[data-ui="tabletop"][data-phase="playing"] .hand .card-button {
    flex-basis: 56px;
    width: 78px;
    min-height: 112px;
  }

  html[data-ui="tabletop"][data-phase="playing"] .hand .card-button:last-child {
    flex-basis: 80px;
  }

  html[data-ui="tabletop"][data-phase="playing"] .hand .playing-card {
    width: 78px;
    height: 108px;
  }
}

@media (max-width: 430px) {
  html[data-ui="tabletop"][data-phase="playing"] .game-header {
    min-height: 58px;
    padding-inline: 12px;
  }

  html[data-ui="tabletop"][data-phase="playing"] .table {
    min-height: calc(100dvh - 58px);
    padding: 7px 7px calc(78px + env(safe-area-inset-bottom));
  }

  html[data-ui="tabletop"][data-phase="playing"] .tabletop-surface {
    grid-template-columns: minmax(0, 1fr) minmax(104px, 31%);
    gap: 7px;
    padding: 7px;
    border-radius: 13px;
  }

  html[data-ui="tabletop"][data-phase="playing"] .score-chip {
    min-width: 208px;
  }

  html[data-ui="tabletop"][data-phase="playing"] .piles {
    gap: 7px;
  }

  html[data-ui="tabletop"][data-phase="playing"] .pile {
    min-height: 112px;
  }

  html[data-ui="tabletop"][data-phase="playing"] .meld {
    flex-basis: 132px;
    min-width: 106px;
    max-width: 132px;
  }

  html[data-ui="tabletop"][data-phase="playing"] .action-dock {
    border-inline: 0;
    border-radius: 0;
  }

  html[data-ui="tabletop"][data-phase="playing"] .action-dock button {
    padding-inline: 7px;
    font-size: .84rem;
    white-space: nowrap;
  }
}

/*
 * Phone landscape is a distinct play surface, not a compressed desktop page.
 * The document is locked to one dynamic viewport; dense regions scroll inside
 * their own rails while the turn, table, hand, and actions stay visible.
 */
@media (orientation: landscape) and (min-width: 560px) and (max-width: 1000px) and (max-height: 500px) {
  html[data-ui="tabletop"][data-phase="playing"],
  html[data-ui="tabletop"][data-phase="playing"] body {
    width: 100%;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }

  html[data-ui="tabletop"][data-phase="playing"] .game {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    width: 100%;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }

  html[data-ui="tabletop"][data-phase="playing"] .game-header {
    position: relative;
    min-height: 48px;
    padding:
      max(2px, env(safe-area-inset-top))
      max(8px, env(safe-area-inset-right))
      2px
      max(8px, env(safe-area-inset-left));
  }

  html[data-ui="tabletop"][data-phase="playing"] .game-header .eyebrow,
  html[data-ui="tabletop"][data-phase="playing"] .interface-toggle-label {
    display: none;
  }

  html[data-ui="tabletop"][data-phase="playing"] .room-code {
    font-size: 1rem;
  }

  html[data-ui="tabletop"][data-phase="playing"] .header-right {
    gap: 5px;
  }

  html[data-ui="tabletop"][data-phase="playing"] .connection {
    max-width: 112px;
    overflow: hidden;
    font-size: .62rem;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  html[data-ui="tabletop"][data-phase="playing"] .interface-toggle {
    justify-content: center;
    width: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 4px;
  }

  html[data-ui="tabletop"][data-phase="playing"] #leave-room {
    min-height: 44px;
    padding: 5px 9px;
  }

  html[data-ui="tabletop"][data-phase="playing"] .table,
  html[data-ui="tabletop"][data-phase="playing"] .table.has-undo {
    grid-template-columns: minmax(0, 1fr) minmax(220px, .8fr);
    grid-template-rows: auto minmax(0, 1fr) 100px;
    grid-template-areas:
      "scores turn"
      "surface surface"
      "hand hand";
    gap: 5px;
    width: 100%;
    height: 100%;
    min-height: 0;
    max-width: none;
    padding:
      5px
      max(6px, env(safe-area-inset-right))
      max(5px, env(safe-area-inset-bottom))
      max(6px, env(safe-area-inset-left));
    overflow: hidden;
  }

  html[data-ui="tabletop"][data-phase="playing"] .score-strip,
  html[data-ui="tabletop"][data-phase="playing"] .meld-row,
  html[data-ui="tabletop"][data-phase="playing"] .hand {
    min-height: 0;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  html[data-ui="tabletop"][data-phase="playing"] .score-strip {
    min-height: 60px;
    gap: 4px;
    overflow-x: auto;
  }

  html[data-ui="tabletop"][data-phase="playing"] .score-chip {
    min-width: 214px;
    min-height: 58px;
    padding: 4px 7px;
  }

  html[data-ui="tabletop"][data-phase="playing"] .score-chip-name {
    font-size: .59rem;
  }

  html[data-ui="tabletop"][data-phase="playing"] .score-chip-value {
    font-size: .82rem;
  }

  html[data-ui="tabletop"][data-phase="playing"] .score-chip-books,
  html[data-ui="tabletop"][data-phase="playing"] .score-chip-status {
    font-size: .5rem;
    line-height: 1.05;
  }

  html[data-ui="tabletop"][data-phase="playing"] .turn-banner {
    min-height: 60px;
    padding: 3px 8px;
  }

  html[data-ui="tabletop"][data-phase="playing"] .turn-banner strong {
    font-size: .76rem;
  }

  html[data-ui="tabletop"][data-phase="playing"] .turn-banner span {
    display: block;
    font-size: .54rem;
  }

  html[data-ui="tabletop"][data-phase="playing"] .tabletop-surface {
    grid-template-columns: minmax(0, 1fr) clamp(150px, 24vw, 210px);
    grid-template-rows: minmax(0, 1fr);
    grid-template-areas: "melds piles";
    gap: 5px;
    width: 100%;
    height: 100%;
    min-height: 0;
    padding: 5px;
    border-width: 2px;
    border-radius: 11px;
    overflow: hidden;
  }

  html[data-ui="tabletop"][data-phase="playing"] .piles {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-content: stretch;
    gap: 5px;
    width: 100%;
    height: 100%;
    min-height: 0;
  }

  html[data-ui="tabletop"][data-phase="playing"] .pile {
    height: 100%;
    min-height: 0;
    padding: 2px;
    gap: 1px;
    border-radius: 6px;
  }

  html[data-ui="tabletop"][data-phase="playing"] .pile .card-back,
  html[data-ui="tabletop"][data-phase="playing"] .pile .playing-card {
    width: 34px;
    height: 46px;
    border-radius: 4px;
  }

  html[data-ui="tabletop"][data-phase="playing"] .pile .card-back {
    border-width: 2px;
    font-size: .62rem;
  }

  html[data-ui="tabletop"][data-phase="playing"] .pile .playing-card {
    font-size: .8rem;
  }

  html[data-ui="tabletop"][data-phase="playing"] .pile .playing-card .corner {
    top: 2px;
    left: 3px;
    font-size: .48rem;
  }

  html[data-ui="tabletop"][data-phase="playing"] .pile strong {
    font-size: .55rem;
    line-height: 1.05;
  }

  html[data-ui="tabletop"][data-phase="playing"] .pile small {
    font-size: .49rem;
    line-height: 1.05;
  }

  html[data-ui="tabletop"][data-phase="playing"] .meld-area {
    width: 100%;
    height: 100%;
    min-height: 0;
    padding: 4px;
    overflow: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  html[data-ui="tabletop"][data-phase="playing"] .team-melds {
    display: grid;
    grid-template-columns: 58px minmax(0, 1fr);
    align-items: start;
    gap: 3px;
  }

  html[data-ui="tabletop"][data-phase="playing"] .team-melds + .team-melds {
    margin-top: 2px;
    padding-top: 2px;
  }

  html[data-ui="tabletop"][data-phase="playing"] .team-melds h3 {
    margin: 3px 0 0;
    overflow: hidden;
    font-size: .52rem;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  html[data-ui="tabletop"][data-phase="playing"] .meld-row {
    gap: 4px;
    min-height: 49px;
    padding: 0 1px 2px;
    overflow-x: auto;
  }

  html[data-ui="tabletop"][data-phase="playing"] .meld-row > .muted {
    font-size: .57rem;
  }

  html[data-ui="tabletop"][data-phase="playing"] .meld {
    grid-template-columns: 32px minmax(0, 1fr);
    gap: 4px;
    flex-basis: 102px;
    min-width: 88px;
    max-width: 102px;
    min-height: 50px;
    padding: 3px;
    border-radius: 5px;
  }

  html[data-ui="tabletop"][data-phase="playing"] .meld-visual,
  html[data-ui="tabletop"][data-phase="playing"] .meld-visual .playing-card {
    width: 32px;
    height: 44px;
    border-radius: 4px;
  }

  html[data-ui="tabletop"][data-phase="playing"] .meld-visual .playing-card {
    font-size: .72rem;
  }

  html[data-ui="tabletop"][data-phase="playing"] .meld-visual .playing-card .corner {
    top: 2px;
    left: 3px;
    font-size: .45rem;
  }

  html[data-ui="tabletop"][data-phase="playing"] .meld-copy strong {
    font-size: .72rem;
  }

  html[data-ui="tabletop"][data-phase="playing"] .meld-copy small,
  html[data-ui="tabletop"][data-phase="playing"] .meld-kind {
    font-size: .48rem;
  }

  html[data-ui="tabletop"][data-phase="playing"] .meld-add {
    min-height: 44px;
    padding: 2px;
    font-size: .58rem;
  }

  html[data-ui="tabletop"][data-phase="playing"] .hand-area,
  html[data-ui="tabletop"][data-phase="playing"] .hand-area.has-undo {
    display: grid;
    grid-template-columns: 100px minmax(0, 1fr) auto;
    grid-template-areas: "heading hand actions";
    align-items: stretch;
    gap: 5px;
    width: 100%;
    height: 100px;
    min-height: 0;
    padding: 4px 5px;
    overflow: hidden;
    border-radius: 8px;
  }

  html[data-ui="tabletop"][data-phase="playing"] .hand-area .section-heading {
    grid-area: heading;
    display: block;
    min-width: 0;
    margin: 0;
    overflow: hidden;
  }

  html[data-ui="tabletop"][data-phase="playing"] .hand-area h2 {
    overflow: hidden;
    font-size: .8rem;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  html[data-ui="tabletop"][data-phase="playing"] .opening-progress {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas: "label points" "detail detail";
    gap: 0 3px;
    width: 100%;
    margin: 2px 0 0;
    padding: 2px 4px;
  }

  html[data-ui="tabletop"][data-phase="playing"] .opening-progress-label {
    display: block;
    font-size: .46rem;
  }

  html[data-ui="tabletop"][data-phase="playing"] .opening-progress strong,
  html[data-ui="tabletop"][data-phase="playing"] .opening-progress small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  html[data-ui="tabletop"][data-phase="playing"] .opening-progress strong {
    font-size: .56rem;
  }

  html[data-ui="tabletop"][data-phase="playing"] .opening-progress small {
    font-size: .48rem;
  }

  html[data-ui="tabletop"][data-phase="playing"] .hand-area .muted {
    display: -webkit-box;
    overflow: hidden;
    margin-top: 2px;
    font-size: .54rem;
    line-height: 1.2;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  html[data-ui="tabletop"][data-phase="playing"] .hand-area.opening-tracking .muted {
    -webkit-line-clamp: 1;
  }

  html[data-ui="tabletop"][data-phase="playing"] .hand {
    grid-area: hand;
    height: 92px;
    min-height: 0;
    padding: 6px 2px 3px;
    overflow-x: auto;
  }

  html[data-ui="tabletop"][data-phase="playing"] .hand .card-button {
    flex: 0 0 44px;
    width: 58px;
    min-width: 44px;
    min-height: 82px;
  }

  html[data-ui="tabletop"][data-phase="playing"] .hand .card-button:last-child {
    flex-basis: 60px;
  }

  html[data-ui="tabletop"][data-phase="playing"] .hand .playing-card {
    width: 58px;
    height: 80px;
    border-radius: 6px;
    font-size: 1.25rem;
  }

  html[data-ui="tabletop"][data-phase="playing"] .hand .playing-card .corner {
    top: 4px;
    left: 5px;
    font-size: .66rem;
  }

  html[data-ui="tabletop"][data-phase="playing"] .hand .card-button.selected .playing-card {
    transform: translateY(-4px);
  }

  html[data-ui="tabletop"][data-phase="playing"] .action-dock {
    position: static;
    grid-area: actions;
    align-self: stretch;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: clamp(190px, 29vw, 250px);
    height: 92px;
    margin: 0;
    padding: 3px;
    gap: 4px;
    transform: none;
    border: 1px solid var(--table-line);
    border-radius: 6px;
  }

  html[data-ui="tabletop"][data-phase="playing"] .hand-area.has-undo .action-dock {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  html[data-ui="tabletop"][data-phase="playing"] .action-dock #undo-opening {
    grid-column: auto;
  }

  html[data-ui="tabletop"][data-phase="playing"] .action-dock button {
    min-width: 0;
    min-height: 44px;
    padding: 2px 4px;
    font-size: .68rem;
    line-height: 1.1;
    white-space: normal;
  }

  html[data-ui="tabletop"][data-phase="playing"] .toast {
    top: calc(52px + env(safe-area-inset-top));
    bottom: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  html[data-ui="tabletop"] .pile,
  html[data-ui="tabletop"] .hand .card-button,
  html[data-ui="tabletop"] .hand .playing-card,
  html[data-ui="tabletop"] .toast {
    transition-duration: .01ms !important;
  }

  html[data-ui="tabletop"][data-phase="playing"] .pile:not(:disabled):active,
  html[data-ui="tabletop"][data-phase="playing"] .hand .card-button.selected .playing-card {
    transform: none;
  }
}
