:root {
  --bg: #0a1b2d;
  --bg-soft: #11273d;
  --felt: radial-gradient(circle at 30% 20%, #2f855a 0%, #1d5f41 45%, #123c2b 100%);
  --ink: #f3f7f0;
  --muted: #bad0c2;
  --accent: #ffd166;
  --danger: #ef476f;
  --line: rgba(255, 255, 255, 0.14);
  --card-bg: #fffef8;
  --card-ink: #111318;
}

* {
  box-sizing: border-box;
}

html {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  background: linear-gradient(150deg, #061322 0%, #0f2741 60%, #16345a 100%);
  font-family: "Bricolage Grotesque", sans-serif;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.bg-grid {
  position: fixed;
  inset: 0;
  background-image: linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 40px 40px;
  opacity: 0.16;
  pointer-events: none;
}

.topbar {
  position: relative;
  z-index: 1;
  display: flex;
  flex-wrap: nowrap;
  justify-content: space-between;
  align-items: center;
  gap: clamp(0.45rem, 1.4vw, 1rem);
  min-width: 0;
  padding: clamp(0.55rem, 1.4vh, 0.95rem) clamp(0.7rem, 1.8vw, 1.25rem);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: clamp(0.32rem, 0.9vw, 0.6rem);
  min-width: 0;
  flex: 0 0 auto;
  flex-wrap: nowrap;
  justify-content: flex-end;
}

.topbar-brand {
  display: grid;
  gap: 0.12rem;
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.3rem, 2.2vw, 2rem);
  letter-spacing: 0.02em;
  line-height: 1.08;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-version {
  display: inline-flex;
  align-items: center;
  min-height: 1.45em;
  margin-left: 0.35rem;
  padding: 0.08rem 0.38rem;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  color: var(--accent);
  background: rgba(3, 10, 20, 0.34);
  font-family: "Space Mono", monospace;
  font-size: 0.48em;
  font-weight: 700;
  vertical-align: middle;
}

.layout {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "lobby"
    "table"
    "hand";
  gap: clamp(0.45rem, 1.3vh, 0.85rem);
  width: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  padding: clamp(0.45rem, 1.3vh, 0.85rem) clamp(0.5rem, 1.4vw, 1rem);
  max-width: 1400px;
  margin: 0 auto;
  height: 100dvh;
}

.layout:has(#lobby-panel.hidden) {
  grid-template-columns: minmax(220px, 20vw) minmax(0, 1fr) minmax(220px, 20vw);
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas:
    "log table status"
    "hand hand hand";
  max-width: none;
  height: 100%;
  min-height: 0;
}

.lobby-panel {
  grid-area: lobby;
  display: grid;
  gap: clamp(0.65rem, 1.4vh, 0.95rem);
  min-width: 0;
}

.lobby-heading {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  align-items: baseline;
  gap: 0.8rem;
  min-width: 0;
}

.lobby-heading .hint {
  margin: 0;
  justify-self: end;
  min-width: 0;
  max-width: 100%;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lobby-heading h2,
.status-panel h2,
.log-panel h2 {
  margin: 0;
}

.lobby-heading h2 {
  font-size: clamp(1rem, 2.2vh, 1.45rem);
  white-space: nowrap;
}

.field-group {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  align-items: center;
  gap: 0.8rem;
  min-width: 0;
}

.join-code-panel {
  display: grid;
  gap: 0.5rem;
  border: 1px dashed rgba(255, 255, 255, 0.22);
  border-radius: 12px;
  padding: 0.65rem;
  background: rgba(8, 20, 36, 0.42);
}

.field {
  font-weight: 700;
  font-size: 0.88rem;
  white-space: nowrap;
}

.invite-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

#invite-link-row {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 0.8rem;
  min-width: 0;
}

#invite-link-row.hidden {
  display: none;
}

.text-input {
  width: 100%;
  min-height: 40px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(7, 17, 32, 0.7);
  color: var(--ink);
  padding: 0.55rem 0.7rem;
  font: inherit;
}

.invite-qr {
  width: clamp(130px, 24vw, 190px);
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  padding: 0.3rem;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(2, 9, 18, 0.74);
  display: grid;
  place-items: center;
  padding: 1rem;
  backdrop-filter: blur(6px);
}

.modal-sheet {
  min-width: min(360px, 100%);
  max-width: min(92vw, 420px);
  background: color-mix(in srgb, var(--bg-soft) 84%, black);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1rem;
  display: grid;
  justify-items: center;
  gap: 0.8rem;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}

.modal-sheet h2 {
  margin: 0;
  font-size: 1.05rem;
}

.join-code-modal-sheet {
  width: min(92vw, 560px);
  justify-items: stretch;
}

.modal-hint {
  margin: 0;
}

.qr-code-text {
  margin: 0;
  color: var(--muted);
  font-family: "Space Mono", monospace;
}

.lobby-actions {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.7rem;
  overflow-x: auto;
  scrollbar-width: thin;
}

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--muted);
}

.hidden {
  display: none;
}

.table-panel {
  grid-area: table;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.status-panel {
  grid-area: status;
  align-self: stretch;
  min-height: 0;
  overflow: hidden;
}

.log-panel {
  grid-area: log;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
}

.hand-panel {
  grid-area: hand;
  min-width: 0;
  min-height: 160px;
  overflow: auto;
  overflow-x: auto;
  overflow-y: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.status-panel.hidden,
.log-panel.hidden,
.hand-panel.hidden,
.side-panels-toggle.hidden {
  display: none;
}

.hand-panel h2,
.hand-panel .hint {
  display: none;
}

.card {
  background: color-mix(in srgb, var(--bg-soft) 82%, black);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
}

.panel {
  padding: clamp(0.55rem, 1.3vh, 0.9rem);
}

.table-felt {
  position: relative;
  width: min(100%, 900px);
  height: min(100%, 500px);
  min-height: 0;
  aspect-ratio: 1.38;
  border-radius: clamp(16px, 2vw, 26px);
  overflow: hidden;
  background: var(--felt);
  border: 2px solid rgba(255, 255, 255, 0.2);
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.24), 0 20px 50px rgba(0, 0, 0, 0.36);
}

.layout:has(#lobby-panel.hidden) .table-felt {
  width: min(100%, 1040px, calc((100dvh - 18rem) * 1.38));
  height: min(100%, 620px, calc(100dvh - 18rem));
}

.seat {
  position: absolute;
  min-width: clamp(72px, 12vw, 130px);
  max-width: clamp(84px, 16vw, 150px);
  padding: clamp(0.32rem, 0.9vw, 0.45rem) clamp(0.42rem, 1.2vw, 0.7rem);
  border-radius: 12px;
  background: rgba(7, 19, 35, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.16);
  font-size: clamp(0.68rem, 1.2vw, 0.92rem);
  line-height: 1.15;
  overflow: hidden;
}

.seat > strong {
  display: block;
}

.seat.me::after {
  content: "";
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 999px;
  right: 12px;
  bottom: 12px;
  background: #84ff2f;
  box-shadow: 0 0 0 3px rgba(132, 255, 47, 0.16), 0 0 14px rgba(132, 255, 47, 0.55);
}

.seat.me.open::after {
  opacity: 0.35;
}

.seat-wait-layout {
  display: grid;
  grid-template-columns: auto 14px;
  align-items: center;
  column-gap: 0.5rem;
}

.seat-wait-copy {
  display: grid;
  gap: 0.08rem;
}

.seat-wait-copy > strong {
  display: block;
}

.seat-wait-pulse {
  justify-self: center;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #ffe18f;
  box-shadow: 0 0 0 0 rgba(255, 225, 143, 0.45);
  animation: wait-pulse 1500ms ease-out infinite;
}

.seat-stats {
  display: grid;
  gap: 0.08rem;
}

.seat-side {
  min-width: clamp(78px, 12vw, 140px);
}

.seat.active {
  outline: 2px solid var(--accent);
  box-shadow: 0 0 0 4px rgba(255, 209, 102, 0.26);
}

.seat.open {
  opacity: 0.65;
  border-style: dashed;
}

.seat.occupied {
  opacity: 1;
}

.seat.reorderable {
  cursor: grab;
  user-select: none;
}

.seat.reorderable:active,
.seat.dragging {
  cursor: grabbing;
}

.seat.selected {
  outline: 2px solid #9ad0ec;
  box-shadow: 0 0 0 4px rgba(154, 208, 236, 0.22);
}

.seat.drop-target {
  outline: 2px dashed #ffd166;
  box-shadow: 0 0 0 4px rgba(255, 209, 102, 0.18);
}

.seat-top {
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
}

.seat-left {
  top: 50%;
  left: 8px;
  transform: translateY(-50%);
}

.seat-right {
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
}

.seat-bottom {
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
}

.trick-area {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  width: min(50vw, 48vh, 360px);
  height: min(50vw, 48vh, 360px);
}

.table-wait-indicator {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  justify-content: center;
  color: rgba(241, 252, 244, 0.95);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.32);
  pointer-events: none;
}

.table-wait-indicator.hidden {
  display: none;
}

.wait-text {
  font-family: "Space Mono", monospace;
  font-weight: 700;
  letter-spacing: 0.02em;
  font-size: clamp(0.82rem, 1.4vw, 0.98rem);
  line-height: 1.2;
  text-align: center;
  animation: wait-fade 1100ms ease-in-out infinite alternate;
}

.trick-card {
  position: absolute;
  background: var(--card-bg);
  color: var(--card-ink);
  border-radius: 12px;
  border: 2px solid #d8ccb4;
  padding: 0.12rem;
  width: max-content;
  display: grid;
  gap: 0.3rem;
  align-content: center;
  justify-items: center;
  overflow: visible;
}

.trick-card-surface {
  display: grid;
  gap: 0.12rem;
  justify-items: center;
  padding: 0.12rem;
  border-radius: 12px;
  background: var(--card-bg);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.16);
  position: relative;
}

.trick-card-surface::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.55), transparent 34%);
  opacity: 0.22;
  pointer-events: none;
}

.trick-card-enter {
  animation: trick-enter 620ms cubic-bezier(0.16, 0.9, 0.2, 1);
}

.trick-card-player-0 {
  left: 50%;
  bottom: 0;
  transform: translate(-50%, 8%);
}

.trick-card-player-1 {
  left: 0;
  top: 50%;
  transform: translate(-6%, -50%);
}

.trick-card-player-2 {
  left: 50%;
  top: 0;
  transform: translate(-50%, 4%);
}

.trick-card-player-3 {
  right: 0;
  top: 50%;
  transform: translate(6%, -50%);
}

.status-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.45rem;
}

.status-list li {
  display: flex;
  justify-content: space-between;
  padding: 0.45rem 0.55rem;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
}

.totals-card {
  margin-top: 0.85rem;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 12px;
  background: rgba(3, 10, 20, 0.36);
  overflow: hidden;
}

.totals-card h3 {
  margin: 0;
  padding: 0.5rem 0.7rem;
  font-size: 0.95rem;
  color: var(--accent);
  border-bottom: 1px solid rgba(255, 255, 255, 0.18);
}

.totals-grid {
  padding: 0.4rem 0.6rem 0.55rem;
  display: grid;
  gap: 0.25rem;
}

.totals-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-radius: 8px;
  padding: 0.36rem 0.42rem;
  background: rgba(255, 255, 255, 0.04);
}

.totals-row span {
  font-weight: 700;
}

.totals-row strong {
  font-family: "Space Mono", monospace;
}

.log {
  flex: 1 1 auto;
  min-height: 0;
  max-height: min(100%, 31.95rem);
  font-family: "Space Mono", monospace;
  font-size: 0.8rem;
  overflow-y: auto;
  overflow-x: hidden;
  display: grid;
  align-content: start;
  gap: 0.45rem;
}

.log-entry {
  padding: 0.45rem 0.55rem;
  background: rgba(0, 0, 0, 0.28);
  border-radius: 8px;
  border-left: 3px solid var(--accent);
}

.hint {
  margin-top: 0;
  color: var(--muted);
}

#lobby-status:empty {
  display: none;
}

.hand {
  display: flex;
  flex-wrap: nowrap;
  gap: clamp(0.32rem, 0.9vw, 0.6rem);
  justify-content: center;
  overflow-x: auto;
  overflow-y: hidden;
  align-items: center;
  padding: 0.25rem 0 0.45rem;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
  scrollbar-width: thin;
}

.play-card {
  border: 2px solid #d8ccb4;
  background: var(--card-bg);
  color: var(--card-ink);
  border-radius: 12px;
  width: clamp(60px, 9vw, 110px);
  height: clamp(100px, 18vh, 170px);
  min-width: 0;
  min-height: 0;
  padding: 0.12rem;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease, filter 120ms ease, opacity 120ms ease;
  overflow: hidden;
}

.play-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 7px 14px rgba(0, 0, 0, 0.24);
}

.play-card.illegal {
  opacity: 0.48;
  filter: saturate(0.55) brightness(0.86) contrast(0.92);
  cursor: not-allowed;
}

.play-card:disabled {
  color: var(--card-ink);
}

.play-card.legal {
  border-color: #ffd166;
  box-shadow: 0 0 0 2px rgba(255, 209, 102, 0.38), 0 8px 18px rgba(0, 0, 0, 0.2);
  filter: saturate(1.08) brightness(1.03);
  transform: translateY(-2px);
}

.play-card.legal:hover {
  border-color: #ffe18f;
  box-shadow: 0 0 0 3px rgba(255, 209, 102, 0.48), 0 12px 24px rgba(0, 0, 0, 0.28);
  transform: translateY(-5px);
}

.card-face {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 6px;
  object-fit: contain;
}

.card-face-hand {
  max-width: 100%;
  max-height: 100%;
}

.card-face-trick {
  width: clamp(78px, 7vw, 104px);
  max-width: 100%;
}

.card-fallback {
  font-family: "Space Mono", monospace;
  font-size: 0.82rem;
  text-align: center;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 999px;
  padding: clamp(0.52rem, 1.2vh, 0.75rem) clamp(0.78rem, 1.8vw, 1.15rem);
  font-weight: 700;
  font-size: clamp(0.82rem, 1.5vw, 0.95rem);
  background: linear-gradient(135deg, #ffd166 0%, #f6a437 100%);
  color: #2b2108;
  cursor: pointer;
  white-space: nowrap;
  min-width: 0;
  min-height: 40px;
}

.action-btn:hover {
  filter: brightness(1.05);
}

.action-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: saturate(0.7);
}

.action-btn.is-active {
  box-shadow: 0 0 0 3px rgba(255, 209, 102, 0.28);
}

.action-btn-secondary {
  background: linear-gradient(135deg, #9ad0ec 0%, #66a3d2 100%);
  color: #0f2230;
}

.action-btn-danger {
  background: linear-gradient(135deg, #ff6b6b 0%, #d93b54 100%);
  color: #fff5f5;
}

.icon-btn {
  width: clamp(2.45rem, 5.4vh, 2.9rem);
  height: clamp(2.45rem, 5.4vh, 2.9rem);
  flex: 0 0 auto;
  padding: 0;
  aspect-ratio: 1;
}

.icon-btn.hidden {
  display: none;
}

.btn-icon {
  width: 1.2rem;
  height: 1.2rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.1;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.icon-btn[aria-label="Avvia partita"] .btn-icon {
  fill: currentColor;
  stroke-width: 0;
}

.side-panels-toggle {
  display: none;
}

.panel-fade-in {
  animation: panel-fade-in 220ms ease-out;
}

@keyframes trick-enter {
  0% {
    opacity: 0;
    transform: scale(0.72) translateY(-26px) rotate(-5deg);
    filter: saturate(0.82) blur(1.5px);
    box-shadow: 0 0 0 rgba(255, 209, 102, 0);
  }
  68% {
    opacity: 1;
    transform: scale(1.06) translateY(4px) rotate(1.5deg);
    filter: saturate(1) blur(0);
    box-shadow: 0 0 0 4px rgba(255, 209, 102, 0.28), 0 14px 30px rgba(0, 0, 0, 0.24);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0) rotate(0deg);
    filter: saturate(1) blur(0);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.16);
  }
}

@keyframes panel-fade-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes wait-pulse {
  0% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(255, 225, 143, 0.52);
  }
  70% {
    transform: scale(1.06);
    box-shadow: 0 0 0 18px rgba(255, 225, 143, 0);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(255, 225, 143, 0);
  }
}

@keyframes wait-fade {
  from {
    opacity: 0.45;
  }
  to {
    opacity: 1;
  }
}

@media (min-width: 981px) {
  .layout:has(#lobby-panel.hidden) .trick-area {
    width: min(48vw, 54vh, 430px);
    height: min(48vw, 54vh, 430px);
  }

  .layout:has(#lobby-panel.hidden) .card-face-trick {
    width: clamp(86px, 6.8vw, 102px);
  }

  .layout:has(#lobby-panel.hidden) .trick-card-player-0 {
    transform: translate(-50%, 8%);
  }

  .layout:has(#lobby-panel.hidden) .trick-card-player-1 {
    transform: translate(-14%, -50%);
  }

  .layout:has(#lobby-panel.hidden) .trick-card-player-2 {
    transform: translate(-50%, -12%);
  }

  .layout:has(#lobby-panel.hidden) .trick-card-player-3 {
    transform: translate(14%, -50%);
  }
}

@media (max-width: 980px) {
  .table-felt {
    width: min(100%, calc((100dvh - 8rem) * 1.38));
    height: min(100%, 460px, calc((100vw - 1rem) / 1.38));
  }

  .layout:has(#lobby-panel.hidden) {
    grid-template-columns: minmax(180px, 22vw) minmax(0, 1fr) minmax(180px, 22vw);
  }

  .layout:has(#lobby-panel.hidden) .table-felt {
    width: min(100%, calc((100dvh - 13rem) * 1.38));
    height: min(100%, calc(100dvh - 13rem), calc((100vw - 26rem) / 1.38));
  }

  .trick-area {
    width: min(54vw, 42vh, 280px);
    height: min(54vw, 42vh, 280px);
  }

  .card-face-trick {
    max-width: 112px;
  }

  .trick-card-player-1 {
    transform: translate(-10%, -50%);
  }

  .trick-card-player-3 {
    transform: translate(10%, -50%);
  }
}

@media (max-width: 760px) {
  .topbar {
    align-items: center;
    gap: 0.45rem;
    padding: 0.55rem 0.6rem;
  }

  .topbar h1 {
    font-size: clamp(1.02rem, 5vw, 1.35rem);
  }

  .topbar-actions {
    align-items: center;
    gap: 0.32rem;
  }

  .icon-btn {
    width: 2.35rem;
    height: 2.35rem;
    min-height: 2.35rem;
  }

  .topbar:has(#side-panels-toggle:not(.hidden)) {
    gap: 0.35rem;
    padding: 0.35rem 0.45rem;
  }

  .topbar:has(#side-panels-toggle:not(.hidden)) .topbar-brand {
    flex: 1 1 auto;
  }

  .topbar:has(#side-panels-toggle:not(.hidden)) h1 {
    font-size: clamp(0.92rem, 4.1vw, 1.08rem);
  }

  .topbar:has(#side-panels-toggle:not(.hidden)) .topbar-actions {
    flex: 0 0 auto;
    gap: 0.35rem;
  }

  .topbar:has(#side-panels-toggle:not(.hidden)) .icon-btn {
    width: 2.25rem;
    height: 2.25rem;
    min-height: 2.25rem;
  }

  .invite-row {
    flex-direction: column;
    align-items: stretch;
  }

  #invite-link-row {
    grid-template-columns: max-content minmax(0, 1fr) auto auto;
  }

  .lobby-actions {
    align-items: center;
  }

  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "lobby"
      "table"
      "hand";
    gap: 0.5rem;
    padding: 0.5rem;
  }

  .layout:has(#lobby-panel.hidden) {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) clamp(214px, 29dvh, 244px);
    grid-template-areas:
      "table"
      "hand";
    max-width: 1400px;
    height: 100%;
    min-height: 0;
  }

  .side-panels-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .status-panel,
  .log-panel {
    position: fixed;
    z-index: 30;
    left: 0.5rem;
    right: 0.5rem;
    display: none;
    max-height: calc((100dvh - 5rem) / 2);
    overflow: auto;
    box-shadow: 0 18px 46px rgba(0, 0, 0, 0.42);
  }

  body.side-panels-open .status-panel:not(.hidden),
  body.side-panels-open .log-panel:not(.hidden) {
    display: block;
  }

  body.side-panels-open .status-panel {
    top: 4.5rem;
  }

  body.side-panels-open .log-panel {
    bottom: calc(0.5rem + env(safe-area-inset-bottom));
  }

  .layout:has(#lobby-panel.hidden) .hand-panel {
    min-height: 0;
    overflow: hidden;
    padding: 0.18rem calc(0.18rem + env(safe-area-inset-right)) calc(0.18rem + env(safe-area-inset-bottom))
      calc(0.18rem + env(safe-area-inset-left));
    justify-content: center;
  }

  .layout:has(#lobby-panel.hidden) .hand {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    grid-auto-rows: minmax(0, 1fr);
    grid-template-rows: repeat(2, minmax(0, 1fr));
    justify-content: center;
    align-content: center;
    gap: clamp(0.12rem, 0.65vw, 0.25rem);
    width: 100%;
    height: 100%;
    overflow: hidden;
    padding: 0;
  }

  .layout:has(#lobby-panel.hidden) .play-card {
    width: 100%;
    height: 100%;
    padding: 0.08rem;
  }

  .panel {
    padding: 0.85rem;
  }

  .card {
    border-radius: 14px;
  }

  .table-felt {
    width: min(100%, calc((100dvh - 7.25rem) * 1.38));
    height: min(100%, calc((100vw - 1rem) / 1.38));
    border-radius: 18px;
  }

  .layout:has(#lobby-panel.hidden) .table-felt {
    width: 100%;
    height: 100%;
    aspect-ratio: auto;
  }

  .seat-left {
    left: 5px;
  }

  .seat-right {
    right: 5px;
  }

  .seat-top {
    top: 5px;
  }

  .seat-bottom {
    bottom: 5px;
  }

  .trick-area {
    width: min(52vw, 30vh, 180px);
    height: min(52vw, 30vh, 180px);
  }

  .trick-card {
    padding: 0.08rem;
    min-height: 0;
    border-radius: 8px;
  }

  .trick-card-surface {
    gap: 0.08rem;
    padding: 0.08rem;
    border-radius: 8px;
  }

  .trick-card-player-0 {
    transform: translate(-50%, 12%);
  }

  .trick-card-player-1 {
    transform: translate(-12%, -50%);
  }

  .trick-card-player-2 {
    transform: translate(-50%, -42%);
  }

  .trick-card-player-3 {
    transform: translate(12%, -50%);
  }

  .card-face-trick {
    max-width: 52px;
  }
}

@media (max-width: 560px) {
  .status-list li {
    font-size: 0.92rem;
    gap: 0.5rem;
  }

  .card-face-trick {
    max-width: 48px;
  }

  .log {
    max-height: 180px;
  }

  .hand-panel:not(.hidden) {
    padding-bottom: calc(0.85rem + env(safe-area-inset-bottom));
  }

  .layout:has(#lobby-panel.hidden) .hand-panel {
    padding-bottom: calc(0.18rem + env(safe-area-inset-bottom));
  }
}

@media (max-height: 640px) {
  .lobby-panel {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
  }

  .lobby-heading {
    grid-column: 1 / -1;
  }

  .field-group {
    min-width: 0;
  }

  .table-felt {
    width: min(100%, calc((100dvh - 6.6rem) * 1.38));
  }

  .layout:not(:has(#lobby-panel.hidden)) .play-card {
    height: clamp(74px, 16vh, 112px);
  }
}
