:root {
  --sky: #8bd9ff;
  --mint: #7ef2c2;
  --pink: #ff8ccf;
  --peach: #ffb36d;
  --lemon: #ffe96f;
  --grape: #9b7cff;
  --table: #40c9b5;
  --table-deep: #1f9fba;
  --text: #fffaf5;
  --muted: #6f5d80;
  --ink: #392844;
  --red: #ff4f7b;
  --gold: #ffe66f;
  --shadow: 0 26px 0 rgba(69, 67, 139, 0.28), 0 38px 70px rgba(64, 39, 112, 0.3);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(circle at 10% 18%, rgba(255, 233, 111, 0.9) 0 70px, transparent 72px),
    radial-gradient(circle at 86% 12%, rgba(255, 140, 207, 0.74) 0 92px, transparent 96px),
    radial-gradient(circle at 88% 82%, rgba(126, 242, 194, 0.68) 0 120px, transparent 124px),
    linear-gradient(135deg, #7ec8ff 0%, #a987ff 45%, #ff9dd8 100%);
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle, rgba(255, 255, 255, 0.52) 0 5px, transparent 6px) 8% 72% / 120px 120px,
    radial-gradient(circle, rgba(255, 255, 255, 0.38) 0 4px, transparent 5px) 78% 28% / 96px 96px;
  opacity: 0.75;
}

button {
  border: 0;
  border-radius: 16px;
  padding: 12px 18px;
  color: #4b3166;
  background: linear-gradient(180deg, #fff 0%, #efe5ff 100%);
  box-shadow: 0 7px 0 #bba1ff, 0 16px 30px rgba(79, 49, 130, 0.2);
  cursor: pointer;
  font-size: 15px;
  font-weight: 900;
  transition: transform 130ms ease, box-shadow 130ms ease, filter 130ms ease;
}

button:hover {
  transform: translateY(-2px);
  filter: saturate(1.08);
}

button:active {
  transform: translateY(4px);
  box-shadow: 0 3px 0 #bba1ff, 0 9px 18px rgba(79, 49, 130, 0.16);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.46;
  filter: grayscale(0.2);
}

.primary {
  color: #5a3900;
  background: linear-gradient(180deg, #fff6a8, #ffbe4d);
  box-shadow: 0 7px 0 #e48b2e, 0 16px 30px rgba(218, 111, 49, 0.25);
}

.mode-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 22px;
  background:
    radial-gradient(circle at 30% 18%, rgba(255, 246, 168, 0.86), transparent 28%),
    rgba(89, 56, 148, 0.52);
  backdrop-filter: blur(12px);
}

.mode-screen.show {
  display: flex;
}

.mode-panel {
  width: min(720px, 100%);
  padding: 30px;
  border-radius: 28px;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.88), rgba(255, 224, 248, 0.8));
  border: 4px solid rgba(255, 255, 255, 0.72);
  box-shadow: 0 18px 0 rgba(124, 86, 203, 0.32), 0 36px 70px rgba(65, 35, 116, 0.28);
  color: var(--ink);
}

.mode-panel h2 {
  margin: 0 0 20px;
  font-size: clamp(30px, 5vw, 48px);
  letter-spacing: 0;
  color: #563081;
  text-shadow: 0 3px 0 rgba(255, 255, 255, 0.85);
}

.mode-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.mode-card {
  min-height: 148px;
  display: grid;
  align-content: center;
  gap: 10px;
  text-align: left;
  border-radius: 22px;
  background: linear-gradient(145deg, #ffffff, #e7dcff);
}

.mode-card strong {
  font-size: 23px;
}

.mode-card span {
  color: #7e629c;
  line-height: 1.55;
  font-weight: 800;
}

.mode-card.primary span {
  color: #795014;
}

.online-panel {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 2px dashed rgba(119, 85, 168, 0.32);
}

.mode-panel.in-room .mode-options,
.mode-panel.in-room .online-actions {
  display: none;
}

.name-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
  padding: 14px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.34);
}

.mode-panel.in-room .name-row {
  display: none;
}

.name-row label {
  display: grid;
  gap: 6px;
  color: #765592;
  font-size: 13px;
  font-weight: 900;
}

.name-row input {
  width: 100%;
  border: 0;
  border-radius: 16px;
  padding: 13px 15px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.72);
  box-shadow: inset 0 0 0 2px rgba(143, 103, 207, 0.18), 0 6px 0 rgba(163, 129, 217, 0.24);
  font: inherit;
  font-weight: 900;
}

.dice-btn {
  width: 52px;
  height: 48px;
  padding: 0;
  font-size: 25px;
  line-height: 1;
}

.online-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: end;
  padding: 16px;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.44);
  box-shadow: inset 0 0 0 2px rgba(143, 103, 207, 0.12);
}

.online-actions #create-room-btn {
  grid-column: 1 / -1;
  justify-self: start;
}

.online-actions label {
  display: grid;
  gap: 6px;
  color: #765592;
  font-size: 13px;
  font-weight: 900;
}

.online-actions input {
  width: 100%;
  border: 0;
  border-radius: 16px;
  padding: 13px 15px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.72);
  box-shadow: inset 0 0 0 2px rgba(143, 103, 207, 0.18), 0 6px 0 rgba(163, 129, 217, 0.24);
  font: inherit;
  font-weight: 900;
  text-transform: uppercase;
}

#online-status {
  margin: 14px 0 0;
  color: #765592;
  line-height: 1.6;
  font-weight: 900;
}

.online-lobby {
  display: grid;
  gap: 14px;
}

.room-code-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  border-radius: 18px;
  color: #563081;
  background: rgba(255, 255, 255, 0.58);
  box-shadow: inset 0 0 0 2px rgba(143, 103, 207, 0.12), 0 6px 0 rgba(139, 124, 255, 0.14);
}

.room-code-card span {
  color: #875d99;
  font-size: 13px;
  font-weight: 1000;
}

.room-code-card strong {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 8px 13px;
  border-radius: 14px;
  color: #4f2b72;
  background: linear-gradient(180deg, #fff8ae, #ffe0f1);
  box-shadow: 0 4px 0 rgba(220, 127, 189, 0.24);
  font-size: clamp(22px, 4vw, 32px);
  letter-spacing: 0.06em;
  text-shadow: 0 3px 0 rgba(255, 255, 255, 0.7);
}

.seat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.seat-chip {
  min-height: 96px;
  display: grid;
  place-items: center;
  gap: 4px;
  padding: 12px;
  border-radius: 20px;
  color: #735091;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.78), rgba(231, 220, 255, 0.76));
  box-shadow: 0 6px 0 rgba(139, 124, 255, 0.22);
  font-weight: 1000;
}

.seat-chip.joined {
  color: #4f2b72;
  background: linear-gradient(145deg, #c7fff0, #dcd5ff);
}

.seat-chip.ai {
  color: #6a4300;
  background: linear-gradient(145deg, #fff8ae, #ffd7a3);
}

.seat-chip .seat-avatar {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  color: #fff;
  background: linear-gradient(145deg, #8b7cff, #ff77c8);
}

.seat-chip small {
  color: #8a6aa4;
  font-size: 12px;
}

.seat-ai-btn {
  margin-top: 4px;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 13px;
  box-shadow: 0 4px 0 #e48b2e, 0 10px 18px rgba(218, 111, 49, 0.18);
}

.seat-ai-btn.cancel {
  color: #563081;
  background: linear-gradient(180deg, #fff, #efe5ff);
  box-shadow: 0 4px 0 #bba1ff, 0 10px 18px rgba(79, 49, 130, 0.16);
}

.table-shell {
  position: relative;
  z-index: 1;
  width: min(1440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 22px;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  gap: 16px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.table-actions {
  display: flex;
  gap: 10px;
  margin-left: auto;
}

.table-actions button {
  padding: 10px 14px;
  color: #66428a;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(239, 229, 255, 0.92));
  box-shadow: 0 5px 0 rgba(139, 124, 255, 0.34), 0 12px 22px rgba(79, 49, 130, 0.14);
}

.eyebrow {
  margin: 0 0 3px;
  color: #fff6a8;
  font-size: 12px;
  font-weight: 1000;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-shadow: 0 2px 0 rgba(88, 48, 127, 0.34);
}

h1 {
  margin: 0;
  color: #fffaf5;
  font-size: clamp(34px, 5vw, 58px);
  letter-spacing: 0;
  text-shadow: 0 5px 0 #7a50c8, 0 12px 28px rgba(65, 34, 121, 0.24);
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(2, minmax(132px, 1fr));
  gap: 12px;
}

.score-card {
  padding: 13px 16px;
  border-radius: 20px;
  color: #563081;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.86), rgba(255, 230, 251, 0.78));
  border: 3px solid rgba(255, 255, 255, 0.62);
  box-shadow: 0 8px 0 rgba(120, 86, 184, 0.24), 0 18px 28px rgba(88, 55, 145, 0.18);
}

.score-card span {
  display: block;
  color: #8d6bab;
  font-size: 12px;
  font-weight: 900;
}

.score-card strong {
  font-size: 28px;
  text-shadow: 0 2px 0 #fff;
}

.game-table {
  position: relative;
  min-height: 650px;
  border-radius: 44px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 30%, rgba(255, 255, 255, 0.45), transparent 31%),
    linear-gradient(90deg, rgba(255, 255, 255, 0.18) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.16) 1px, transparent 1px),
    radial-gradient(circle at center, #5ff5d6 0%, var(--table) 43%, var(--table-deep) 100%);
  background-size: auto, 46px 46px, 46px 46px, auto;
  border: 8px solid rgba(255, 255, 255, 0.72);
  box-shadow: var(--shadow), inset 0 -22px 0 rgba(61, 92, 184, 0.16), inset 0 18px 0 rgba(255, 255, 255, 0.18);
  transform: perspective(1100px) rotateX(3deg);
  transform-origin: center bottom;
}

.game-table::before,
.game-table::after {
  content: "";
  position: absolute;
  pointer-events: none;
  border-radius: 999px;
}

.game-table::before {
  width: 190px;
  height: 190px;
  right: 8%;
  top: 10%;
  background: radial-gradient(circle, rgba(255, 246, 168, 0.54), transparent 62%);
}

.game-table::after {
  width: 230px;
  height: 160px;
  left: 4%;
  bottom: 18%;
  background: radial-gradient(circle, rgba(255, 140, 207, 0.35), transparent 64%);
}

.opponent,
.player-area {
  position: absolute;
  display: grid;
  gap: 10px;
  align-items: center;
  z-index: 2;
}

.opponent-top {
  top: 22px;
  left: 50%;
  transform: translateX(-50%);
  width: min(540px, 54vw);
}

.opponent-left {
  left: 24px;
  top: 50%;
  transform: translateY(-50%);
  width: 205px;
}

.opponent-right {
  right: 24px;
  top: 50%;
  transform: translateY(-50%);
  width: 205px;
}

.player-area {
  left: 28px;
  right: 28px;
  bottom: 24px;
}

.player-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 82px;
  padding: 13px;
  border-radius: 24px;
  color: #60407d;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.86), rgba(236, 228, 255, 0.76));
  border: 3px solid rgba(255, 255, 255, 0.64);
  box-shadow: 0 8px 0 rgba(93, 66, 151, 0.22), 0 18px 28px rgba(67, 45, 117, 0.18);
}

.player-card.active {
  background: linear-gradient(145deg, #fff8ae, #ffb8de);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.8), 0 10px 0 #dc7fbd, 0 22px 34px rgba(103, 56, 144, 0.25);
}

.avatar {
  width: 52px;
  height: 52px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(145deg, #8b7cff, #ff77c8);
  box-shadow: inset 0 4px 0 rgba(255, 255, 255, 0.34), 0 6px 0 rgba(88, 55, 145, 0.22);
  font-weight: 1000;
}

.player-info {
  min-width: 0;
}

.player-info strong {
  display: block;
  overflow: hidden;
  color: #4c2e72;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-info span {
  color: #8a6aa4;
  font-size: 13px;
  font-weight: 850;
}

.handoff-note {
  color: #e271a8;
  font-size: 12px;
  font-weight: 1000;
}

.card-back-row {
  display: flex;
  justify-content: center;
  min-width: 74px;
}

.mini-card {
  width: 29px;
  height: 42px;
  margin-left: -16px;
  border-radius: 9px;
  background:
    radial-gradient(circle at 50% 30%, rgba(255, 255, 255, 0.84) 0 5px, transparent 6px),
    repeating-linear-gradient(45deg, #ff7ac6, #ff7ac6 6px, #8e7cff 6px, #8e7cff 12px);
  border: 3px solid rgba(255, 255, 255, 0.92);
  box-shadow: 0 4px 0 rgba(87, 62, 150, 0.2);
}

.center-panel {
  position: absolute;
  left: 50%;
  top: 45%;
  transform: translate(-50%, -50%);
  width: min(560px, 46vw);
  display: grid;
  gap: 12px;
  place-items: center;
  z-index: 3;
}

.level-chip,
.turn-timer {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  border-radius: 999px;
  color: #573179;
  background: linear-gradient(180deg, #ffffff, #ffe3f7);
  border: 3px solid rgba(255, 255, 255, 0.72);
  box-shadow: 0 6px 0 rgba(116, 80, 183, 0.22), 0 14px 22px rgba(76, 45, 122, 0.17);
}

.level-chip {
  padding: 10px 16px;
}

.turn-timer {
  min-width: 154px;
  padding: 9px 14px;
}

.level-chip span,
.turn-timer span {
  color: #8a6aa4;
  font-size: 12px;
  font-weight: 1000;
}

.level-chip strong,
.turn-timer strong {
  color: #ff6eaa;
  font-size: 25px;
  min-width: 28px;
  text-align: center;
  text-shadow: 0 2px 0 #fff7b4;
}

.turn-timer.warning {
  background: linear-gradient(180deg, #fff6a8, #ff8b8b);
  animation: pulseTimer 650ms ease-in-out infinite alternate;
}

.turn-callout {
  padding: 10px 18px;
  border-radius: 999px;
  color: #5a3900;
  background: linear-gradient(180deg, #fff8ae, #ffbe4d);
  box-shadow: 0 7px 0 rgba(228, 139, 46, 0.5), 0 0 34px rgba(255, 248, 124, 0.72);
  font-weight: 1000;
  animation: yourTurnPulse 1s ease-in-out infinite alternate;
}

@keyframes pulseTimer {
  from { transform: scale(1); }
  to { transform: scale(1.05); }
}

@keyframes yourTurnPulse {
  from { transform: translateY(0) scale(1); filter: brightness(1); }
  to { transform: translateY(-3px) scale(1.04); filter: brightness(1.08); }
}

.last-play {
  position: relative;
  min-height: 128px;
  width: 100%;
  display: grid;
  align-items: center;
  justify-items: center;
  gap: 9px;
  padding: 16px;
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.25);
  border: 3px solid rgba(255, 255, 255, 0.35);
  box-shadow: inset 0 6px 0 rgba(255, 255, 255, 0.12), 0 12px 26px rgba(70, 45, 116, 0.13);
}

.last-play.bomb-play {
  animation: tableBoom 520ms cubic-bezier(.2, 1.4, .35, 1) both;
  background:
    radial-gradient(circle at center, rgba(255, 248, 120, 0.62), transparent 42%),
    rgba(255, 255, 255, 0.28);
  box-shadow: 0 0 0 6px rgba(255, 245, 120, 0.32), 0 22px 44px rgba(255, 90, 135, 0.28);
}

.boom-burst {
  position: absolute;
  inset: 50% auto auto 50%;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  pointer-events: none;
  transform: translate(-50%, -50%);
  background:
    radial-gradient(circle, #fff 0 18%, #fff36d 19% 34%, #ff7b6e 35% 52%, transparent 54%),
    conic-gradient(from 0deg, transparent 0 8deg, #fff176 8deg 15deg, transparent 15deg 32deg, #ff67b3 32deg 40deg, transparent 40deg 60deg);
  animation: burstPop 760ms ease-out both;
  filter: drop-shadow(0 0 18px rgba(255, 240, 90, 0.86));
  z-index: 0;
}

.last-play-meta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 13px;
  border-radius: 999px;
  color: #5b3600;
  background: linear-gradient(180deg, #fff8a6, #ffbd4d);
  box-shadow: 0 5px 0 rgba(209, 125, 34, 0.38);
  font-size: 13px;
  font-weight: 1000;
}

.last-play-cards {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
}

.bomb-card {
  animation: bombCardPop 720ms cubic-bezier(.2, 1.35, .38, 1) both;
  transform-style: preserve-3d;
}

.bomb-card:nth-child(2n) {
  animation-delay: 60ms;
}

.bomb-card:nth-child(3n) {
  animation-delay: 110ms;
}

@keyframes tableBoom {
  0% { transform: translate3d(0, 0, 0) scale(1); }
  20% { transform: translate3d(-8px, 4px, 18px) scale(1.04); }
  42% { transform: translate3d(7px, -5px, 22px) scale(1.02); }
  65% { transform: translate3d(-3px, 2px, 8px) scale(1.01); }
  100% { transform: translate3d(0, 0, 0) scale(1); }
}

@keyframes burstPop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.2) rotate(0deg); }
  18% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(7.4) rotate(38deg); }
}

@keyframes bombCardPop {
  0% { transform: translateY(34px) rotateX(0deg) rotateZ(0deg) scale(0.86); filter: brightness(1); }
  45% { transform: translateY(-24px) rotateX(22deg) rotateZ(-5deg) scale(1.16); filter: brightness(1.22) saturate(1.25); }
  100% { transform: translateY(0) rotateX(0deg) rotateZ(0deg) scale(1); filter: brightness(1); }
}

.turn-log {
  width: 100%;
  min-height: 32px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(57, 40, 68, 0.14);
  color: #fff;
  text-align: center;
  font-weight: 1000;
  text-shadow: 0 2px 0 rgba(83, 49, 136, 0.38);
}

.hand {
  display: flex;
  align-items: flex-end;
  min-height: 138px;
  padding: 8px 4px 0;
  overflow-x: auto;
  scrollbar-width: thin;
}

.card {
  position: relative;
  flex: 0 0 64px;
  width: 64px;
  height: 96px;
  margin-right: -16px;
  border-radius: 16px;
  border: 3px solid rgba(255, 255, 255, 0.9);
  color: var(--ink);
  background:
    radial-gradient(circle at 72% 16%, rgba(255, 255, 255, 0.92) 0 8px, transparent 9px),
    linear-gradient(160deg, #ffffff, #fff1c8 58%, #ffe0ee);
  box-shadow: 0 8px 0 rgba(121, 83, 167, 0.28), 0 15px 20px rgba(66, 44, 111, 0.22);
  cursor: pointer;
  transition: transform 150ms ease, box-shadow 150ms ease;
  user-select: none;
}

.card:hover,
.card.selected {
  transform: translateY(-20px) rotateZ(-1.5deg);
  box-shadow: 0 12px 0 rgba(255, 129, 201, 0.38), 0 24px 30px rgba(66, 44, 111, 0.28);
}

.card.selected {
  outline: 4px solid #fff87c;
  outline-offset: 2px;
}

.card.red {
  color: var(--red);
}

.card.wild {
  background:
    radial-gradient(circle at 72% 16%, rgba(255, 255, 255, 0.92) 0 8px, transparent 9px),
    linear-gradient(160deg, #fff, #ffe5f4 52%, #ffc5e5);
}

.card .rank {
  position: absolute;
  top: 8px;
  left: 9px;
  font-weight: 1000;
  font-size: 20px;
}

.card .suit {
  display: none;
}

.card .center {
  height: 100%;
  display: grid;
  place-items: center;
  font-size: 38px;
  font-weight: 1000;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.8);
}

.card.joker .center {
  font-size: 18px;
  writing-mode: vertical-rl;
}

.card:last-child {
  margin-right: 0;
}

.controls {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  padding-bottom: 8px;
}

.controls button {
  min-width: 104px;
}

.rules-panel {
  color: #fff;
  line-height: 1.7;
  text-shadow: 0 1px 0 rgba(86, 48, 129, 0.28);
}

.rules-panel details {
  max-width: 980px;
  margin: 0 auto;
  padding: 12px 16px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.22);
  border: 2px solid rgba(255, 255, 255, 0.26);
}

.rules-panel summary {
  color: #fff;
  cursor: pointer;
  font-weight: 1000;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 30;
  transform: translateX(-50%) translateY(20px);
  max-width: min(520px, calc(100vw - 30px));
  padding: 13px 17px;
  border-radius: 18px;
  color: #5a3900;
  background: linear-gradient(180deg, #fff9b6, #ffca62);
  box-shadow: 0 8px 0 rgba(210, 128, 38, 0.38), 0 20px 42px rgba(73, 45, 116, 0.24);
  opacity: 0;
  pointer-events: none;
  transition: 180ms ease;
  font-weight: 1000;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.settlement-screen {
  position: fixed;
  inset: 0;
  z-index: 24;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(75, 47, 132, 0.36);
  backdrop-filter: blur(8px);
}

.settlement-screen[hidden] {
  display: none;
}

.settlement-panel {
  width: min(680px, 100%);
  padding: 28px;
  border-radius: 28px;
  color: var(--ink);
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.94), rgba(255, 224, 248, 0.9));
  border: 4px solid rgba(255, 255, 255, 0.78);
  box-shadow: 0 18px 0 rgba(124, 86, 203, 0.34), 0 36px 70px rgba(65, 35, 116, 0.32);
}

.settlement-panel h2 {
  margin: 0 0 14px;
  color: #563081;
  font-size: clamp(30px, 5vw, 48px);
  text-shadow: 0 3px 0 rgba(255, 255, 255, 0.85);
}

.settlement-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 16px 0;
}

.settlement-summary div,
.finish-chip {
  padding: 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.58);
  box-shadow: inset 0 0 0 2px rgba(143, 103, 207, 0.12), 0 6px 0 rgba(139, 124, 255, 0.14);
}

.settlement-summary span,
.finish-chip span,
.finish-chip small {
  display: block;
  color: #875d99;
  font-size: 12px;
  font-weight: 1000;
}

.settlement-summary strong {
  display: block;
  margin-top: 4px;
  color: #ff5c9b;
  font-size: 28px;
}

.finish-order {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.finish-chip strong {
  display: block;
  margin: 4px 0;
  color: #563081;
  font-size: 18px;
}

.finish-chip.winner {
  background: linear-gradient(145deg, #fff8ae, #ffd7a3);
}

@media (max-width: 820px) {
  html,
  body {
    min-height: 100dvh;
    overflow: hidden;
  }

  .table-shell {
    width: 100vw;
    height: 100dvh;
    min-height: 0;
    padding:
      max(8px, env(safe-area-inset-top))
      max(8px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom))
      max(8px, env(safe-area-inset-left));
    grid-template-rows: auto 1fr auto;
    gap: 8px;
  }

  .mode-screen {
    align-items: flex-start;
    min-height: 100dvh;
    overflow: auto;
    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));
  }

  .mode-panel {
    padding: 22px;
  }

  .topbar {
    align-items: center;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
  }

  h1 {
    font-size: 26px;
  }

  .eyebrow {
    font-size: 10px;
  }

  .table-actions {
    width: auto;
    margin-left: 0;
    justify-content: flex-start;
  }

  .table-actions button {
    padding: 8px 10px;
    border-radius: 13px;
    font-size: 13px;
  }

  .scoreboard {
    flex: 1 1 100%;
    width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .score-card {
    padding: 8px 10px;
    border-radius: 16px;
  }

  .score-card strong {
    font-size: 20px;
  }

  .mode-options,
  .online-actions,
  .name-row,
  .seat-grid,
  .settlement-summary,
  .finish-order {
    grid-template-columns: 1fr;
  }

  .online-actions #create-room-btn {
    justify-self: stretch;
  }

  .room-code-card {
    align-items: flex-start;
    flex-direction: column;
  }

  .game-table {
    min-height: 0;
    height: 100%;
    border-radius: 30px;
    border-width: 5px;
    transform: none;
  }

  .opponent-left,
  .opponent-right {
    top: 185px;
    width: calc(50% - 32px);
    transform: none;
  }

  .opponent-top {
    width: calc(100% - 28px);
    top: 14px;
  }

  .opponent-left {
    left: 14px;
  }

  .opponent-right {
    right: 14px;
  }

  .center-panel {
    top: 292px;
    width: calc(100% - 28px);
    gap: 9px;
  }

  .last-play {
    min-height: 104px;
    padding: 10px;
  }

  .last-play .card {
    flex-basis: 46px;
    width: 46px;
    height: 70px;
    margin-right: 0;
    border-radius: 13px;
  }

  .last-play .card .rank {
    font-size: 14px;
    top: 7px;
    left: 7px;
  }

  .last-play .card .suit {
    font-size: 14px;
    top: 27px;
    left: 8px;
  }

  .last-play .card .center {
    font-size: 21px;
  }

  .player-area {
    left: 12px;
    right: 12px;
    bottom: 10px;
  }

  .player-card {
    min-height: 66px;
    border-radius: 20px;
  }

  .avatar {
    width: 42px;
    height: 42px;
    border-radius: 14px;
  }

  .card {
    flex-basis: 54px;
    width: 54px;
    height: 82px;
    margin-right: -20px;
  }

  .card .rank {
    font-size: 16px;
  }

  .card .center {
    font-size: 30px;
  }

  .controls {
    gap: 8px;
    padding-bottom: 2px;
  }

  .controls button {
    min-width: 88px;
    padding: 10px 12px;
  }

  .rules-panel {
    display: none;
  }
}

@media (max-width: 820px) and (orientation: landscape) {
  .table-shell {
    grid-template-rows: auto 1fr auto;
  }

  .topbar {
    flex-wrap: nowrap;
  }

  .scoreboard {
    flex: 0 0 230px;
  }

  .game-table {
    min-height: 0;
    height: 100%;
  }

  .opponent-top {
    top: 8px;
  }

  .opponent-left,
  .opponent-right {
    top: 42%;
  }

  .center-panel {
    top: 42%;
    width: min(420px, 46vw);
  }

  .player-card {
    min-height: 54px;
  }

  .hand {
    min-height: 94px;
  }

  .card {
    flex-basis: 46px;
    width: 46px;
    height: 70px;
    border-radius: 13px;
  }

  .card .center {
    font-size: 25px;
  }
}
