:root {
  --tile-w: 48px;
  --tile-h: 66px;
  --tile-gap: 4px;
  --tile-font: 24px;
  --tile-mini-font: 9px;
  --color-red: #E53935;
  --color-blue: #1E88E5;
  --color-black: #37474F;
  --color-orange: #FB8C00;
  --color-joker: #8E24AA;
  --felt: #1B5E20;
  --felt-light: #2E7D32;
  --bg-dark: #0D3311;
  --panel-bg: rgba(0, 0, 0, 0.35);
  --gold: #FFD54F;
  --lobby-bg-deep: #12351F;
  --lobby-bg-warm: #8B3E12;
  --lobby-surface: rgba(255, 248, 229, 0.94);
  --lobby-surface-soft: rgba(255, 255, 255, 0.62);
  --lobby-text: #2A1908;
  --lobby-muted: #6B4B2A;
  --lobby-green: #166534;
  --lobby-accent: #F59E0B;
  --lobby-accent-strong: #C2410C;
  --lobby-ring: #FFD166;
  --lobby-shadow: rgba(42, 25, 8, 0.24);
  --game-surface: rgba(255, 248, 229, 0.9);
  --game-surface-strong: rgba(255, 253, 247, 0.96);
  --game-surface-soft: rgba(255, 255, 255, 0.54);
  --game-border: rgba(255, 209, 102, 0.36);
  --game-border-soft: rgba(107, 75, 42, 0.14);
  --game-felt-glow: rgba(46, 125, 50, 0.58);
  --game-shadow: 0 16px 38px rgba(42, 25, 8, 0.22);
  /* 真实视口高度（由 JS 动态设置，解决 iOS 地址栏问题） */
  --vh: 1vh;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  height: 100%;
  /* 防止 iOS Safari 橡皮筋效果 */
  overflow: hidden;
  -webkit-overflow-scrolling: touch;
}

body {
  font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
  background: var(--bg-dark);
  color: #fff;
  overflow: hidden;
  /* 使用固定定位填满整个视口，避免地址栏问题 */
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  user-select: none;
  -webkit-user-select: none;
  /* iOS 全面屏安全区域 - 不要在 body 上加 padding，由子元素处理 */
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.ui-icon {
  width: 1.1em;
  height: 1.1em;
  display: inline-block;
  flex: 0 0 auto;
  color: currentColor;
  vertical-align: -0.15em;
}

.tutorial-link .ui-icon,
.copy-btn .ui-icon,
.ctrl-btn .ui-icon {
  width: 1.15em;
  height: 1.15em;
}

/* ====== LOBBY SCREEN ====== */
#lobby-screen {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: clamp(28px, 5vw, 72px);
  height: 100%;
  overflow-x: hidden;
  overflow-y: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding: clamp(14px, 2.5vw, 32px);
  position: relative;
  background: url("/assets/images/bg.jpg") center / cover no-repeat;
}

#lobby-screen::-webkit-scrollbar {
  display: none;
}

.lobby-hero {
  flex: 0 1 430px;
  max-width: 460px;
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.lobby-title {
  width: clamp(260px, 30vw, 390px);
  margin: 0 0 4px;
}

.lobby-title-img {
  display: block;
  width: 100%;
  height: auto;
  margin: -31% 0 -30%;
  pointer-events: none;
  filter: drop-shadow(0 16px 28px rgba(0, 18, 11, 0.34));
}

.subtitle {
  font-size: 18px;
  color: rgba(255, 248, 229, 0.88);
  margin-bottom: 18px;
  letter-spacing: 2px;
  font-weight: 700;
}

.tutorial-link-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: min(100%, 360px);
  text-align: center;
  margin-bottom: 0;
}

.tutorial-link {
  position: relative;
  display: block;
  width: min(100%, 330px);
  min-height: 44px;
  aspect-ratio: 330 / 74;
  padding: 0;
  border: 0;
  background: transparent;
  border-radius: 999px;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.2s ease, filter 0.2s ease;
}

.tutorial-link-img {
  position: absolute;
  top: 50%;
  left: 0;
  display: block;
  width: 100%;
  height: auto;
  margin: 0;
  pointer-events: none;
  transform: translateY(-50%);
  filter: drop-shadow(0 11px 18px rgba(0, 18, 11, 0.28));
}

.tutorial-link:hover {
  transform: translateY(-2px);
  filter: brightness(1.04);
}

.tutorial-button {
  font-family: inherit;
}

.lobby-form {
  width: min(820px, 100%);
  max-width: none;
  padding: clamp(16px, 2vw, 22px);
  border-radius: 28px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  background: var(--lobby-surface);
  color: var(--lobby-text);
  box-shadow: 0 28px 70px var(--lobby-shadow);
  backdrop-filter: blur(12px);
}

#lobby-screen .form-group {
  margin-bottom: 16px;
  text-align: left;
}

.lobby-name-field {
  padding: 16px 18px;
  margin-bottom: 18px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.58);
  border: 1px solid rgba(107, 75, 42, 0.12);
}

#lobby-screen .form-group label {
  display: block;
  font-size: 15px;
  color: var(--lobby-muted);
  margin-bottom: 8px;
  font-weight: 800;
}

#lobby-screen .form-group input[type="text"] {
  width: 100%;
  max-width: none;
  min-height: 48px;
  padding: 0 16px;
  border-radius: 14px;
  border: 2px solid rgba(107, 75, 42, 0.18);
  background: #FFFDF7;
  color: var(--lobby-text);
  font-size: 18px;
  font-weight: 700;
  text-align: left;
  outline: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

#lobby-screen .form-group input[type="text"]::placeholder {
  color: rgba(107, 75, 42, 0.48);
  font-weight: 600;
}

#lobby-screen .form-group input[type="text"]:focus {
  border-color: var(--lobby-accent);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(255, 209, 102, 0.28);
}

.field-hint {
  min-height: 18px;
  margin-top: 6px;
  color: #B91C1C;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.4;
  opacity: 0;
  transition: opacity 0.18s ease;
}

.field-error .field-hint {
  opacity: 1;
}

#lobby-screen .field-error input[type="text"] {
  border-color: #DC2626;
  background: #FFF7F2;
  box-shadow: 0 0 0 4px rgba(220, 38, 38, 0.16), inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.field-error-shake {
  animation: field-shake 0.36s ease;
}

@keyframes field-shake {
  0%, 100% {
    transform: translateX(0);
  }

  18%, 54%, 90% {
    transform: translateX(-6px);
  }

  36%, 72% {
    transform: translateX(6px);
  }
}

.lobby-cards {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(300px, 0.92fr);
  gap: 16px;
  margin-top: 0;
  align-items: stretch;
}

/* 邀请链接带房间码时，窄屏优先展示加入房间 */
@media (max-width: 900px) {
  .lobby-cards.invite-room-first .join-card {
    order: -1;
  }
}

.lobby-card {
  background: var(--lobby-surface-soft);
  border-radius: 22px;
  padding: clamp(16px, 1.8vw, 22px);
  border: 1px solid rgba(107, 75, 42, 0.12);
  color: var(--lobby-text);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.72);
}

.create-card {
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(255, 243, 214, 0.78));
  border-color: rgba(245, 158, 11, 0.34);
}

.join-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background:
    radial-gradient(circle at 100% 0%, rgba(22, 101, 52, 0.14), transparent 38%),
    rgba(255, 255, 255, 0.58);
}

.join-card-main {
  display: flex;
  flex: 1;
  flex-direction: column;
}

.resume-modal-card {
  background:
    radial-gradient(circle at 0% 0%, rgba(255, 209, 102, 0.34), transparent 34%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(236, 253, 245, 0.9));
}

.resume-session-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.resume-session-meta > div {
  padding: 11px 12px;
  border-radius: 14px;
  background: rgba(255, 253, 247, 0.72);
  border: 1px solid rgba(107, 75, 42, 0.1);
  text-align: left;
}

.resume-session-meta span,
.resume-session-meta strong {
  display: block;
}

.resume-session-meta span {
  color: var(--lobby-muted);
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 4px;
}

.resume-session-meta strong {
  color: var(--lobby-green);
  font-size: 15px;
  font-weight: 900;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.resume-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(140px, 0.42fr);
  gap: 10px;
  align-items: stretch;
}

.lobby-btn.secondary {
  color: var(--lobby-muted);
  background: rgba(255, 253, 247, 0.76);
}

.card-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.card-heading h2 {
  font-size: 20px;
  margin-bottom: 5px;
  color: var(--lobby-green);
  text-align: left;
  letter-spacing: 1px;
}

.card-heading p {
  color: var(--lobby-muted);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.45;
}

.create-heading-main {
  display: flex;
  min-width: 0;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.create-mode-switch {
  display: inline-flex;
  gap: 4px;
  padding: 3px;
  border-radius: 999px;
  background: rgba(218, 195, 151, 0.42);
  box-shadow: inset 0 2px 4px rgba(107, 78, 39, 0.18);
}

.create-mode-switch button {
  min-height: 28px;
  padding: 0 10px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #5d452d;
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
}

.create-mode-switch button.active {
  color: #fff8e8;
  background: linear-gradient(180deg, #ef8728 0%, #e66f14 100%);
  text-shadow: 0 1px 0 rgba(84, 34, 0, 0.32);
  box-shadow: 0 3px 8px rgba(93, 53, 11, 0.24);
}

.card-badge {
  flex-shrink: 0;
  padding: 5px 9px;
  border-radius: 999px;
  background: rgba(245, 158, 11, 0.18);
  border: 1px solid rgba(245, 158, 11, 0.32);
  color: var(--lobby-accent-strong);
  font-size: 12px;
  font-weight: 900;
}

.card-badge.subtle {
  background: rgba(22, 101, 52, 0.1);
  border-color: rgba(22, 101, 52, 0.22);
  color: var(--lobby-green);
}

.create-settings {
  display: grid;
  flex: 1;
  align-content: space-between;
  gap: 8px;
}

.create-settings .form-group {
  margin-bottom: 0 !important;
}

#btn-create {
  margin-top: 16px;
}

.option-btns {
  display: flex;
  gap: 9px;
  justify-content: flex-start;
  flex-wrap: wrap;
}

.option-btns button {
  min-width: 52px;
  min-height: 44px;
  border-radius: 14px;
  border: 1px solid rgba(107, 75, 42, 0.2);
  background: #FFFAF0;
  color: var(--lobby-text);
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.18s ease, background 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
  padding: 0 14px;
}

.option-btns button:hover {
  background: #FFF3D6;
  border-color: rgba(245, 158, 11, 0.55);
  box-shadow: 0 6px 14px rgba(42, 25, 8, 0.12);
}

.option-btns button.active {
  background: linear-gradient(135deg, var(--lobby-ring), var(--lobby-accent));
  color: #3B1D06;
  border-color: rgba(194, 65, 12, 0.35);
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(194, 65, 12, 0.24);
}

.mode-descriptions {
  display: grid;
  gap: 7px;
  margin-top: 12px;
}

.mode-description {
  display: none;
  position: relative;
  padding: 10px 12px;
  border-radius: 10px;
  border: 0;
  background: rgba(210, 190, 147, 0.46);
  color: #4f3922;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.45;
  box-shadow:
    inset 0 1px 0 rgba(255, 252, 225, 0.42),
    0 1px 0 rgba(255, 255, 236, 0.22);
}

.mode-description::before {
  content: '';
  position: absolute;
  top: -8px;
  left: 22%;
  width: 16px;
  height: 9px;
  background: rgba(205, 184, 139, 0.48);
  clip-path: polygon(50% 0, 0 100%, 100% 100%);
}

.mode-description[data-mode="deluxe"]::before {
  left: 72%;
}

.mode-description.active {
  display: block;
}

.mode-description strong {
  color: #5b3519;
}

.join-guide {
  display: grid;
  flex: 1;
  align-content: center;
  gap: 28px;
  margin-top: 0;
}

.join-guide-item {
  position: relative;
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 14px;
  align-items: center;
  padding: 0;
  border-radius: 0;
  background: transparent;
  border: 0;
}

.join-guide-item:not(:last-child)::after {
  content: '';
  position: absolute;
  left: 18px;
  top: 39px;
  bottom: -25px;
  width: 1px;
  background: rgba(126, 92, 50, 0.14);
}

.join-guide-item > .join-guide-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(206, 186, 144, 0.5);
  color: #6a4b26;
  font-size: 16px;
  font-weight: 900;
  box-shadow:
    inset 1px 1px 2px rgba(117, 81, 38, 0.12),
    inset -1px -1px 2px rgba(255, 250, 224, 0.34);
}

.join-guide-item strong,
.join-guide-item small {
  display: block;
  text-align: left;
}

.join-guide-item strong {
  color: var(--lobby-text);
  font-size: 16px;
  line-height: 1.35;
  font-weight: 900;
}

.join-guide-item strong span {
  display: inline;
  margin-right: 8px;
}

.join-guide-item small {
  margin-top: 2px;
  color: var(--lobby-muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
}

.lobby-btn {
  display: block;
  width: 100%;
  min-height: 48px;
  margin-top: 16px;
  padding: 0 24px;
  font-size: 16px;
  font-weight: 900;
  border: 2px solid rgba(107, 75, 42, 0.18);
  border-radius: 16px;
  cursor: pointer;
  transition: transform 0.22s ease, box-shadow 0.22s ease, background 0.22s ease, border-color 0.22s ease;
  background: #FFFDF7;
  color: var(--lobby-green);
}

.lobby-btn:hover {
  background: #FFF7D6;
  border-color: rgba(245, 158, 11, 0.4);
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(42, 25, 8, 0.16);
}

#lobby-screen .lobby-btn.primary {
  background: linear-gradient(135deg, var(--lobby-ring), var(--lobby-accent) 58%, #FB923C);
  border-color: rgba(194, 65, 12, 0.36);
  color: #3B1D06;
  box-shadow: 0 14px 28px rgba(194, 65, 12, 0.26);
}

#lobby-screen .lobby-btn.primary:hover {
  box-shadow: 0 18px 36px rgba(194, 65, 12, 0.34);
}

#btn-join {
  color: var(--lobby-green);
  border-color: rgba(22, 101, 52, 0.28);
}

#btn-join.invite-pulse {
  border-color: rgba(22, 101, 52, 0.52);
  background: linear-gradient(135deg, rgba(236, 253, 245, 0.98), rgba(209, 250, 229, 0.94));
  animation: invite-join-pulse 1.3s ease-in-out 4;
}

@keyframes invite-join-pulse {
  0%, 100% {
    transform: translateY(0) scale(1);
    box-shadow: 0 0 0 rgba(22, 101, 52, 0);
  }

  50% {
    transform: translateY(-2px) scale(1.025);
    box-shadow:
      0 14px 30px rgba(22, 101, 52, 0.22),
      0 0 0 8px rgba(22, 101, 52, 0.08);
  }
}

.lobby-btn.danger {
  border-color: rgba(244, 67, 54, 0.5);
  color: #EF5350;
}

.lobby-btn.danger:hover {
  background: rgba(244, 67, 54, 0.15);
}

#room-code-input {
  text-transform: uppercase;
  letter-spacing: 6px;
  font-weight: 800;
  text-align: center;
}

#lobby-screen :is(a, button, input):focus-visible {
  outline: 3px solid var(--lobby-ring);
  outline-offset: 3px;
}

/* Stitch V4 lobby restyle: tactile claymorphism, scoped to homepage only. */
#lobby-screen {
  --lobby-surface: rgba(255, 244, 218, 0.97);
  --lobby-surface-soft: rgba(255, 251, 239, 0.82);
  --lobby-text: #3b2a19;
  --lobby-muted: #715b43;
  --lobby-green: #0d4d3a;
  --lobby-accent: #ff7a1a;
  --lobby-accent-strong: #a94300;
  --lobby-ring: #fabd00;
  --lobby-shadow: rgba(0, 18, 11, 0.42);
  --lobby-cream: #fff2d7;
  --lobby-cream-deep: #e8cfaa;
  --lobby-mint: #bbedd7;
  --lobby-raised-shadow: 0 26px 58px rgba(0, 18, 11, 0.34), 0 8px 0 rgba(84, 34, 0, 0.16), inset 0 2px 0 rgba(255, 255, 255, 0.78);
  --lobby-raised-soft: 0 14px 26px rgba(0, 18, 11, 0.18), 0 4px 0 rgba(84, 34, 0, 0.12), inset 0 2px 0 rgba(255, 255, 255, 0.72);
  --lobby-recessed: inset 4px 5px 12px rgba(74, 60, 42, 0.15);
  font-family: 'Plus Jakarta Sans', 'Segoe UI', 'Microsoft YaHei', sans-serif;
}

#lobby-screen .lobby-hero {
  color: var(--lobby-mint);
  text-shadow: 0 16px 40px rgba(0, 18, 11, 0.36);
}

#lobby-screen .lobby-title {
  text-shadow: none;
}

#lobby-screen .subtitle {
  color: #f4ddb3;
  text-shadow: 0 1px 0 rgba(92, 56, 22, 0.58), 0 8px 18px rgba(0, 18, 11, 0.34);
}

#lobby-screen .tutorial-link:hover {
  transform: translateY(-2px);
}

#lobby-screen .lobby-form {
  border-radius: 34px;
  border: 1px solid rgba(255, 250, 228, 0.82);
  background:
    radial-gradient(circle at 10% 0%, rgba(255, 254, 232, 0.68), rgba(255, 254, 232, 0) 34%),
    radial-gradient(circle at 100% 100%, rgba(231, 151, 34, 0.14), rgba(231, 151, 34, 0) 38%),
    linear-gradient(160deg, rgba(239, 229, 197, 0.98) 0%, rgba(225, 207, 164, 0.97) 100%);
  color: var(--lobby-text);
  box-shadow:
    0 24px 44px rgba(0, 18, 11, 0.22),
    0 9px 0 rgba(151, 110, 55, 0.24),
    10px 18px 28px rgba(169, 116, 45, 0.18),
    inset 0 2px 0 rgba(255, 255, 236, 0.82),
    inset -2px -2px 0 rgba(189, 143, 70, 0.14);
  backdrop-filter: blur(16px);
}

#lobby-screen .lobby-name-field {
  display: grid;
  grid-template-columns: auto minmax(220px, 0.48fr);
  justify-content: center;
  align-items: center;
  column-gap: 14px;
  row-gap: 6px;
  padding: 0;
  margin-bottom: clamp(16px, 2vw, 22px);
  border: 0;
  background: transparent;
  box-shadow: none;
}

#lobby-screen .lobby-name-field label {
  margin-bottom: 0;
  color: var(--lobby-text);
  font-size: 16px;
  font-weight: 900;
}

#lobby-screen .lobby-name-field .field-hint {
  display: none;
  grid-column: 2;
}

#lobby-screen .lobby-name-field.field-error .field-hint {
  display: block;
}

#lobby-screen .form-group label {
  color: var(--lobby-muted);
  letter-spacing: 0.03em;
}

#lobby-screen .form-group input[type="text"] {
  border-radius: 18px;
  border: 0;
  background: rgba(218, 195, 151, 0.42);
  color: var(--lobby-text);
  line-height: 1;
  padding-top: 2px;
  box-shadow:
    inset 5px 0 7px rgba(107, 78, 39, 0.2),
    inset 0 5px 8px rgba(107, 78, 39, 0.22),
    inset 2px 2px 3px rgba(97, 69, 34, 0.12),
    inset -1px 0 1px rgba(255, 253, 227, 0.68),
    inset -3px 0 4px rgba(255, 239, 195, 0.34),
    inset 0 -1px 1px rgba(255, 253, 227, 0.72),
    inset 0 -3px 4px rgba(255, 239, 195, 0.38),
    0 1px 0 rgba(255, 255, 236, 0.28);
}

#lobby-screen .form-group input[type="text"]::placeholder {
  color: rgba(113, 91, 67, 0.58);
}

#lobby-screen .form-group input[type="text"]:focus {
  background: rgba(225, 202, 158, 0.5);
  box-shadow:
    inset 5px 0 7px rgba(107, 78, 39, 0.22),
    inset 0 5px 8px rgba(107, 78, 39, 0.24),
    inset 2px 2px 3px rgba(97, 69, 34, 0.14),
    inset -1px 0 1px rgba(255, 253, 227, 0.72),
    inset -3px 0 4px rgba(255, 239, 195, 0.38),
    inset 0 -1px 1px rgba(255, 253, 227, 0.76),
    inset 0 -3px 4px rgba(255, 239, 195, 0.42),
    0 0 0 4px rgba(250, 189, 0, 0.14);
}

#lobby-screen .field-hint {
  color: var(--lobby-muted);
  opacity: 0.78;
}

#lobby-screen .field-hint:empty {
  display: none;
}

#lobby-screen .field-error .field-hint {
  color: #b42318;
  opacity: 1;
}

#lobby-screen .field-error input[type="text"] {
  border-color: #d92d20;
  background: #fff1ea;
  box-shadow: var(--lobby-recessed), 0 0 0 4px rgba(217, 45, 32, 0.18);
}

#lobby-screen .lobby-card {
  border-radius: 28px;
  border: 1px solid rgba(255, 251, 230, 0.74);
  background:
    radial-gradient(circle at 0% 0%, rgba(255, 254, 235, 0.72), rgba(255, 254, 235, 0) 36%),
    linear-gradient(180deg, rgba(243, 233, 202, 0.92) 0%, rgba(224, 205, 162, 0.86) 100%);
  box-shadow:
    0 18px 26px rgba(94, 60, 25, 0.18),
    0 7px 0 rgba(129, 83, 36, 0.2),
    inset 0 2px 0 rgba(255, 255, 236, 0.82),
    inset -2px -2px 0 rgba(184, 136, 62, 0.14);
}

#lobby-screen .create-card {
  border-color: rgba(255, 251, 230, 0.76);
  background:
    radial-gradient(circle at 12% 0%, rgba(255, 254, 235, 0.68), rgba(255, 254, 235, 0) 34%),
    linear-gradient(180deg, rgba(244, 234, 204, 0.94) 0%, rgba(225, 207, 165, 0.88) 100%);
}

#lobby-screen .join-card {
  border-color: rgba(255, 251, 230, 0.74);
  background:
    radial-gradient(circle at 100% 0%, rgba(255, 254, 235, 0.64), rgba(255, 254, 235, 0) 34%),
    linear-gradient(180deg, rgba(242, 232, 201, 0.92) 0%, rgba(223, 205, 163, 0.86) 100%);
}

#lobby-screen .card-heading h2 {
  color: var(--lobby-green);
  letter-spacing: 0.03em;
}


#lobby-screen .mode-description,
#lobby-screen .join-guide-item small {
  color: var(--lobby-muted);
}

#lobby-screen .card-badge {
  min-width: 38px;
  padding: 5px 8px;
  border-radius: 9px;
  border-color: rgba(101, 63, 20, 0.18);
  background: linear-gradient(180deg, #b98d52 0%, #9d6d34 100%);
  color: #fff7da;
  text-align: center;
  letter-spacing: 0.04em;
  box-shadow:
    0 3px 5px rgba(92, 56, 22, 0.18),
    inset 0 1px 0 rgba(255, 241, 196, 0.32),
    inset 0 -1px 1px rgba(78, 43, 10, 0.16);
}

#lobby-screen .card-badge.subtle {
  border-color: rgba(101, 63, 20, 0.16);
  background: linear-gradient(180deg, #b98d52 0%, #9d6d34 100%);
  color: #fff7da;
}

#lobby-screen .option-btns {
  --option-count: 3;
  --active-index: 0;
  display: flex;
  width: 100%;
  max-width: 100%;
  min-height: 36px;
  gap: 0;
  flex-wrap: nowrap;
  align-items: center;
  position: relative;
  overflow: visible;
  padding: 3px;
  border-radius: 999px;
  border: 0;
  background: rgba(218, 195, 151, 0.42);
  box-shadow:
    inset 5px 0 7px rgba(107, 78, 39, 0.2),
    inset 0 5px 8px rgba(107, 78, 39, 0.22),
    inset 2px 2px 3px rgba(97, 69, 34, 0.12),
    inset -1px 0 1px rgba(255, 253, 227, 0.68),
    inset -3px 0 4px rgba(255, 239, 195, 0.34),
    inset 0 -1px 1px rgba(255, 253, 227, 0.72),
    inset 0 -3px 4px rgba(255, 239, 195, 0.38),
    0 1px 0 rgba(255, 255, 236, 0.28);
}

#lobby-screen .option-btns button {
  flex: 1 1 0;
  min-width: 0;
  min-height: 30px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: #4b3825;
  box-shadow: none;
  white-space: nowrap;
  position: relative;
  z-index: 1;
}

#lobby-screen .option-btns::before {
  content: '';
  position: absolute;
  z-index: 0;
  top: 1px;
  bottom: 2px;
  left: 3px;
  box-sizing: border-box;
  width: calc((100% - 6px) / var(--option-count));
  border: 1px solid rgba(129, 48, 0, 0.22);
  border-radius: 999px;
  background: linear-gradient(180deg, #ef8728 0%, #e66f14 100%);
  box-shadow:
    0 5px 8px rgba(93, 53, 11, 0.32),
    0 2px 0 rgba(100, 43, 0, 0.24),
    0 1px 1px rgba(93, 53, 11, 0.24),
    inset 0 1px 1px rgba(255, 232, 183, 0.42),
    inset 0 -2px 2px rgba(111, 32, 0, 0.18);
  transform: translateX(calc(var(--active-index) * 100%));
  transform-origin: left center;
  transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1), width 0.2s ease, box-shadow 0.2s ease;
}

#lobby-screen .option-btns button:hover {
  background: rgba(255, 255, 255, 0.24);
  border-color: rgba(255, 122, 26, 0.12);
  box-shadow: none;
}

#lobby-screen .option-btns button.active {
  background: transparent;
  color: #fff8e8;
  border-color: transparent;
  text-shadow: 0 1px 0 rgba(84, 34, 0, 0.32);
  transform: none;
  box-shadow: none;
}

#lobby-screen .mode-description {
  border-color: transparent;
  background: rgba(205, 184, 139, 0.48);
  box-shadow:
    inset 0 1px 0 rgba(255, 252, 225, 0.44),
    0 1px 0 rgba(255, 255, 236, 0.22);
}

#lobby-screen .join-guide-item {
  border-color: transparent;
  background: transparent;
  box-shadow: none;
}

#lobby-screen .mode-description strong {
  color: #5b3519;
}

#lobby-screen .join-guide-item strong {
  color: #2f2114;
}

#lobby-screen .join-guide-item > .join-guide-icon {
  background: rgba(198, 176, 132, 0.5);
  color: #6a4b26;
  box-shadow:
    inset 1px 1px 2px rgba(117, 81, 38, 0.14),
    inset -1px -1px 2px rgba(255, 250, 224, 0.34);
}

#lobby-screen .join-guide-item .ui-icon {
  width: 18px;
  height: 18px;
}

#lobby-screen .join-guide-item small {
  display: none;
}

#lobby-screen .lobby-btn {
  min-height: 50px;
  border-radius: 999px;
  border: 1px solid rgba(148, 104, 43, 0.24);
  background: linear-gradient(180deg, #f7f1dc 0%, #e9ddbe 58%, #d8c49b 100%);
  color: #2f2114;
  box-shadow:
    0 9px 14px rgba(95, 61, 24, 0.2),
    0 3px 0 rgba(137, 91, 34, 0.16),
    inset 0 2px 0 rgba(255, 255, 242, 0.82),
    inset 0 -2px 3px rgba(150, 101, 40, 0.12);
}

#lobby-screen .lobby-btn:hover {
  background: linear-gradient(180deg, #fff8e7 0%, #efe2bf 58%, #ddc99f 100%);
  border-color: rgba(184, 120, 35, 0.32);
  transform: translateY(-2px);
  box-shadow:
    0 12px 18px rgba(95, 61, 24, 0.23),
    0 3px 0 rgba(137, 91, 34, 0.16),
    inset 0 2px 0 rgba(255, 255, 242, 0.88),
    inset 0 -2px 3px rgba(150, 101, 40, 0.12);
}

#lobby-screen .lobby-btn.primary {
  border-color: rgba(116, 49, 0, 0.24);
  background: linear-gradient(180deg, #f59a32 0%, #f07816 56%, #d85b00 100%);
  color: #fff7dc;
  text-shadow: 0 1px 0 rgba(84, 34, 0, 0.32);
  box-shadow:
    0 10px 15px rgba(130, 61, 0, 0.3),
    0 3px 0 rgba(89, 37, 0, 0.22),
    inset 0 2px 0 rgba(255, 230, 174, 0.44),
    inset 0 -2px 3px rgba(111, 32, 0, 0.14);
}

#lobby-screen .lobby-btn.primary:hover {
  box-shadow:
    0 13px 18px rgba(130, 61, 0, 0.34),
    0 3px 0 rgba(89, 37, 0, 0.22),
    inset 0 2px 0 rgba(255, 230, 174, 0.52),
    inset 0 -2px 3px rgba(111, 32, 0, 0.14);
}

#lobby-screen #btn-join {
  border-color: rgba(148, 104, 43, 0.24);
  background: linear-gradient(180deg, #f7f1dc 0%, #e9ddbe 58%, #d8c49b 100%);
  color: #2f2114;
}

#lobby-screen #btn-join.invite-pulse {
  border-color: rgba(13, 77, 58, 0.44);
  background: linear-gradient(180deg, #edfff7 0%, #bfead5 100%);
}

#lobby-screen .lobby-btn:disabled,
#lobby-screen .option-btns button:disabled {
  cursor: not-allowed;
  opacity: 0.56;
  transform: none;
  box-shadow: inset 3px 4px 10px rgba(74, 60, 42, 0.16);
}

#lobby-screen .option-btns button:active,
#lobby-screen .lobby-btn:active {
  transform: translateY(2px);
  box-shadow: inset 3px 4px 10px rgba(74, 60, 42, 0.2), inset -4px -4px 10px rgba(255, 255, 255, 0.55);
}

#lobby-screen .tutorial-link:active {
  transform: translateY(2px);
  filter: brightness(0.96);
}

#lobby-screen .lobby-btn:disabled:active,
#lobby-screen .option-btns button:disabled:active {
  transform: none;
}

#lobby-screen :is(a, button, input):focus-visible {
  outline: 3px solid var(--lobby-ring);
  outline-offset: 4px;
  box-shadow: 0 0 0 7px rgba(250, 189, 0, 0.2), var(--lobby-raised-soft);
}

#lobby-screen .form-group input[type="text"]:focus-visible {
  box-shadow:
    inset 5px 0 7px rgba(107, 78, 39, 0.22),
    inset 0 5px 8px rgba(107, 78, 39, 0.24),
    inset 2px 2px 3px rgba(97, 69, 34, 0.14),
    inset -1px 0 1px rgba(255, 253, 227, 0.72),
    inset -3px 0 4px rgba(255, 239, 195, 0.38),
    inset 0 -1px 1px rgba(255, 253, 227, 0.76),
    inset 0 -3px 4px rgba(255, 239, 195, 0.42),
    0 0 0 4px rgba(250, 189, 0, 0.14),
    0 0 0 8px rgba(250, 189, 0, 0.08);
}

@media (max-width: 480px) {
  #lobby-screen .option-btns {
    width: 100%;
    padding: 3px;
    border-radius: 999px;
  }
}

/* ====== WAITING SCREEN ====== */
#waiting-screen {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  overflow-y: auto;
  background:
    radial-gradient(circle at 28% 18%, rgba(255, 209, 102, 0.36), rgba(255, 209, 102, 0) 32%),
    radial-gradient(circle at 78% 20%, rgba(249, 115, 22, 0.28), rgba(249, 115, 22, 0) 30%),
    linear-gradient(135deg, var(--lobby-bg-deep), #245B2F 52%, var(--lobby-bg-warm));
  padding: 20px;
}

#waiting-screen h1 {
  font-size: clamp(40px, 6vw, 64px);
  font-weight: 900;
  letter-spacing: 6px;
  margin-bottom: 8px;
  background: linear-gradient(135deg, #FFF7C2, var(--lobby-ring), #FF9F1C);
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 4px 14px rgba(58, 22, 0, 0.38));
}

.waiting-card {
  background: var(--lobby-surface);
  color: var(--lobby-text);
  border-radius: 24px;
  padding: 36px 48px;
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.7);
  min-width: 320px;
  box-shadow: 0 24px 60px var(--lobby-shadow);
  backdrop-filter: blur(12px);
}

.room-code-display label {
  display: block;
  font-size: 14px;
  color: var(--lobby-muted);
  margin-bottom: 8px;
  font-weight: 800;
}

.room-code-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 24px;
}

.room-code {
  font-size: 48px;
  font-weight: 900;
  letter-spacing: 12px;
  color: var(--lobby-accent-strong);
  font-family: monospace;
}

.copy-btn {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 12px;
  border: 2px solid rgba(22, 101, 52, 0.24);
  background: #FFFDF7;
  color: var(--lobby-green);
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.copy-btn:hover {
  background: #FFF7D6;
  border-color: var(--lobby-accent);
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(42, 25, 8, 0.14);
}

.copy-btn:active {
  transform: translateY(0);
}

.copy-btn.copied {
  background: rgba(76, 175, 80, 0.16);
  border-color: #2E7D32;
  color: #1B5E20;
}

.room-invite-qr {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin: -6px 0 20px;
  padding: 12px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(107, 75, 42, 0.1);
  box-shadow: 0 10px 24px rgba(42, 25, 8, 0.08);
}

#invite-qr-code {
  display: block;
  width: 168px;
  height: 168px;
  border-radius: 10px;
  background: #FFFFFF;
}

#invite-qr-code[hidden],
#room-settings-panel[hidden],
#ai-settings-panel[hidden] {
  display: none;
}

.room-invite-qr-caption,
.room-invite-qr-fallback {
  font-size: 12px;
  font-weight: 800;
  color: var(--lobby-muted);
}

.room-invite-qr-fallback {
  max-width: 168px;
  line-height: 1.4;
}

.room-access-status {
  display: inline-flex;
  align-items: center;
  margin-left: 8px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(22, 101, 52, 0.12);
  color: #285638;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
}

.room-access-status.locked {
  background: rgba(183, 50, 50, 0.12);
  color: #A12F2F;
}

.room-management {
  margin: 0 0 12px;
  text-align: left;
}

.room-management[hidden] {
  display: none;
}

.management-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.modal-kicker.danger {
  display: block;
  color: #A84220;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.04em;
}

.management-disclosure {
  display: flex;
  width: 100%;
  min-height: 44px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 12px;
  border: 1px solid rgba(22, 101, 52, 0.2);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.74);
  color: var(--lobby-text);
  font: inherit;
  font-size: 14px;
  font-weight: 900;
  cursor: pointer;
}

.management-disclosure:hover {
  border-color: rgba(22, 101, 52, 0.42);
  background: #FFFDF7;
}

.management-disclosure-title,
.management-disclosure-status,
.management-lock-btn {
  display: inline-flex;
  align-items: center;
}

.management-disclosure-title {
  gap: 7px;
}

.management-disclosure-title .ui-icon {
  color: var(--lobby-green);
}

.management-disclosure-status {
  gap: 7px;
  color: var(--lobby-muted);
  font-size: 12px;
}

.management-disclosure-caret {
  width: 7px;
  height: 7px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg) translateY(-2px);
  transition: transform 0.18s ease;
}

.room-management.is-expanded .management-disclosure {
  border-bottom-color: transparent;
  border-radius: 13px 13px 0 0;
}

.room-management.is-expanded .management-disclosure-caret {
  transform: rotate(-135deg) translate(-2px, -1px);
}

#room-management-body {
  padding: 12px;
  border: 1px solid rgba(22, 101, 52, 0.2);
  border-top: 0;
  border-radius: 0 0 13px 13px;
  background: #FFFDF7;
  box-shadow: 0 14px 24px -16px rgba(22, 101, 52, 0.4);
}

.room-management.is-expanded .management-disclosure {
  box-shadow: 0 -1px 0 rgba(22, 101, 52, 0.06);
}

.management-lock-btn,
.waiting-player-action {
  min-height: 44px;
  border: 1px solid rgba(22, 101, 52, 0.25);
  border-radius: 10px;
  background: #FFFDF7;
  color: var(--lobby-green);
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.management-lock-btn {
  justify-content: center;
  gap: 5px;
  padding: 0 8px;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.management-lock-btn[aria-pressed="false"]:hover {
  border-color: var(--lobby-green);
  background: rgba(22, 101, 52, 0.08);
}

.management-lock-btn[aria-pressed="true"] {
  border-color: rgba(194, 65, 12, 0.42);
  background: rgba(194, 65, 12, 0.1);
  color: var(--lobby-accent-strong);
}

.management-lock-btn[aria-pressed="true"] .ui-icon {
  color: var(--lobby-accent-strong);
}

.management-lock-btn[aria-pressed="true"]:hover {
  border-color: rgba(194, 65, 12, 0.6);
  background: rgba(194, 65, 12, 0.16);
}

.room-settings-form {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
  border: 0;
}

.management-field {
  display: grid;
  gap: 6px;
}

.management-field-label {
  display: flex;
  align-items: baseline;
  gap: 6px;
  color: var(--lobby-muted);
  font-size: 12px;
  font-weight: 800;
}

.management-field-label small {
  color: #8A5A00;
  font-size: 10px;
  font-weight: 800;
  white-space: nowrap;
}

.management-option-btns {
  display: flex;
  gap: 5px;
}

.management-option-btns button {
  flex: 1 1 0;
  min-width: 0;
  min-height: 38px;
  padding: 0 4px;
  border: 1px solid rgba(22, 101, 52, 0.25);
  border-radius: 9px;
  background: #FFFDF7;
  color: var(--lobby-muted);
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.management-option-btns button:hover {
  border-color: rgba(22, 101, 52, 0.5);
  background: #FFFFFF;
}

.management-option-btns button.active {
  border-color: var(--lobby-green);
  box-shadow: inset 0 0 0 1px var(--lobby-green);
  background: var(--lobby-green);
  color: #FFFFFF;
}

.room-management-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed rgba(22, 101, 52, 0.2);
}

.room-management-actions .management-lock-btn,
.room-management-actions .lobby-btn {
  width: 100%;
  min-height: 44px;
  margin: 0;
  padding: 0 8px;
  font-size: 13px;
}

.room-management-actions .lobby-btn.primary {
  border-color: rgba(194, 65, 12, 0.36);
  background: linear-gradient(135deg, var(--lobby-ring), var(--lobby-accent) 58%, #FB923C);
  color: #3B1D06;
  box-shadow: 0 6px 14px rgba(194, 65, 12, 0.2);
}

.room-management-actions .lobby-btn.primary:hover {
  box-shadow: 0 8px 18px rgba(194, 65, 12, 0.28);
}

.room-management :is(button):disabled {
  cursor: not-allowed;
  opacity: 0.52;
  transform: none;
  box-shadow: none;
}

.waiting-players {
  margin-bottom: 16px;
}

.waiting-player {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 16px;
  margin-bottom: 6px;
  background: rgba(255, 255, 255, 0.66);
  border: 1px solid rgba(107, 75, 42, 0.1);
  border-radius: 12px;
  font-size: 16px;
}

.waiting-player-identity,
.waiting-player-actions,
.waiting-host-badge {
  display: inline-flex;
  align-items: center;
}

.waiting-player-identity {
  min-width: 0;
  gap: 8px;
}

.waiting-player-actions {
  flex: 0 0 auto;
  gap: 6px;
}

.waiting-player-action {
  min-height: 36px;
  padding: 0 9px;
}

.waiting-player-action.danger {
  border-color: rgba(183, 50, 50, 0.34);
  color: #A12F2F;
}

.waiting-host-badge {
  gap: 3px;
  padding: 3px 7px;
  border-radius: 999px;
  background: #FFF0B8;
  color: #8A5A00;
  font-size: 12px;
  font-weight: 900;
}

.waiting-player.disconnected {
  background: rgba(244, 67, 54, 0.12);
  opacity: 0.75;
}

.waiting-player .player-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #2E7D32;
}

.waiting-player .disconnected-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.waiting-hint {
  color: var(--lobby-muted);
  font-size: 14px;
  margin-bottom: 20px;
}

.waiting-hint .dots::after {
  content: '';
  animation: dots 1.5s infinite;
}

@keyframes dots {
  0% {
    content: '';
  }

  33% {
    content: '.';
  }

  66% {
    content: '..';
  }

  100% {
    content: '...';
  }
}

.waiting-settings {
  font-size: 13px;
  color: var(--lobby-muted);
  margin-bottom: 16px;
}

#waiting-screen :is(button, select):focus-visible {
  outline: 3px solid var(--lobby-ring);
  outline-offset: 3px;
}

@media (max-width: 480px) {
  .waiting-card {
    min-width: 0;
    width: min(100%, 420px);
    padding: 24px 18px;
  }

  .waiting-player {
    align-items: stretch;
    flex-direction: column;
  }

  .waiting-player-actions {
    width: 100%;
  }

  .waiting-player-action {
    flex: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }

  .player-tab.ice-shattering .ice-shard {
    animation: none !important;
    opacity: 0;
  }

  #win-confetti-canvas {
    display: none !important;
  }

}

/* ====== GAME SCREEN ====== */
#game-screen {
  display: none;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  position: relative;
  isolation: isolate;
  color: var(--lobby-text);
  background:
    radial-gradient(circle at 16% 12%, rgba(255, 209, 102, 0.34) 0, rgba(255, 209, 102, 0) 28%),
    radial-gradient(circle at 84% 10%, rgba(249, 115, 22, 0.28) 0, rgba(249, 115, 22, 0) 30%),
    radial-gradient(ellipse at 50% 50%, var(--game-felt-glow) 0, rgba(27, 94, 32, 0.62) 43%, rgba(18, 53, 31, 0) 72%),
    linear-gradient(135deg, var(--lobby-bg-deep) 0%, #245B2F 48%, var(--lobby-bg-warm) 100%);
}

#game-screen::before {
  content: '';
  position: absolute;
  inset: 14px;
  z-index: 0;
  pointer-events: none;
  border-radius: 30px;
  border: 1px solid rgba(255, 248, 229, 0.16);
  background:
    linear-gradient(90deg, rgba(255, 248, 229, 0.055) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255, 248, 229, 0.045) 1px, transparent 1px);
  background-size: 42px 42px;
  -webkit-mask-image: radial-gradient(ellipse at center, #000 0%, transparent 76%);
  mask-image: radial-gradient(ellipse at center, #000 0%, transparent 76%);
}

#game-screen > * {
  position: relative;
  z-index: 1;
}

/* Header */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 14px 8px;
  background: linear-gradient(135deg, rgba(255, 253, 247, 0.92), rgba(255, 240, 198, 0.76));
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--game-border);
  box-shadow: 0 10px 26px rgba(42, 25, 8, 0.18);
  min-height: 52px;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
  /* iOS 全面屏适配 - 顶部安全区域 */
  padding-top: max(14px, calc(env(safe-area-inset-top) + 10px));
  padding-left: max(14px, env(safe-area-inset-left));
  padding-right: max(14px, env(safe-area-inset-right));
}

.player-tabs {
  display: flex;
  align-items: center;
  gap: 8px;
}

.player-tab {
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 800;
  background: rgba(255, 255, 255, 0.62);
  border: 2px solid rgba(107, 75, 42, 0.1);
  color: var(--lobby-text);
  transition: transform 0.2s ease, background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
  isolation: isolate;
  box-shadow:
    0 6px 16px rgba(42, 25, 8, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.76);
}

.player-tab > * {
  position: relative;
  z-index: 2;
}

.player-tab.active {
  background: linear-gradient(135deg, rgba(255, 250, 225, 0.98), rgba(255, 228, 153, 0.88));
  box-shadow:
    0 0 0 3px rgba(255, 213, 79, 0.32),
    0 10px 24px rgba(194, 65, 12, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.92);
  transform: translateY(-1px);
}

.player-tab.me {
  position: relative;
  /* 移除"(我)"标记，通过其他方式突出自己 */
}

.player-tab.disconnected {
  opacity: 0.72;
  background: rgba(255, 232, 226, 0.86);
  border-color: rgba(244, 67, 54, 0.42) !important;
  box-shadow: inset 0 0 0 1px rgba(244, 67, 54, 0.14);
}

.player-tab .player-name-wrapper {
  position: relative;
  display: inline-block;
  padding-right: 28px;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.58);
}

.player-tab .tile-count-badge {
  position: absolute;
  top: -9px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  background: linear-gradient(135deg, #FF6B6B, #FF5252);
  color: white;
  font-size: 11px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  border-radius: 10px;
  padding: 0 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 2px 6px rgba(42, 25, 8, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.34);
  border: 2px solid rgba(255, 255, 255, 0.96);
  line-height: 1;
  transition: background 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.player-tab.active .tile-count-badge {
  background: linear-gradient(135deg, var(--gold), #FFC107);
  color: #3B1D06;
  border-color: #FFF;
  box-shadow:
    0 3px 8px rgba(255, 193, 7, 0.42),
    inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

.player-tab .disconnect-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  opacity: 0.82;
  color: #D32F2F;
  animation: blink 1.5s ease-in-out infinite;
}

.disconnect-status .ui-icon,
.waiting-player .disconnected-icon .ui-icon {
  width: 1.15em;
  height: 1.15em;
}

.player-tab.ice-locked {
  background:
    linear-gradient(135deg, rgba(226, 248, 255, 0.94), rgba(170, 221, 255, 0.74)),
    rgba(255, 255, 255, 0.68);
  border-color: rgba(73, 169, 227, 0.42);
  box-shadow:
    0 0 0 2px rgba(168, 225, 255, 0.38),
    0 8px 20px rgba(30, 108, 168, 0.16),
    inset 0 1px 0 rgba(255, 255, 255, 0.86);
}

.player-tab.ice-locked::before {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  pointer-events: none;
  z-index: 1;
  background:
    linear-gradient(112deg, transparent 0 22%, rgba(255, 255, 255, 0.58) 23% 25%, transparent 26% 100%),
    linear-gradient(34deg, transparent 0 54%, rgba(52, 132, 199, 0.2) 55% 56%, transparent 57% 100%),
    radial-gradient(circle at 18% 28%, rgba(255, 255, 255, 0.92) 0 2px, transparent 3px),
    radial-gradient(circle at 78% 70%, rgba(255, 255, 255, 0.74) 0 1px, transparent 2px),
    linear-gradient(135deg, rgba(255, 255, 255, 0.5), rgba(93, 184, 235, 0.24));
  opacity: 0.9;
  box-shadow:
    inset 0 0 12px rgba(255, 255, 255, 0.82),
    inset 0 -6px 12px rgba(60, 157, 216, 0.22);
}

.player-tab.ice-locked::after {
  content: '';
  position: absolute;
  inset: 4px 10px;
  border-radius: inherit;
  pointer-events: none;
  z-index: 1;
  background:
    linear-gradient(72deg, transparent 0 44%, rgba(15, 93, 157, 0.24) 45% 46%, transparent 47% 100%),
    linear-gradient(146deg, transparent 0 58%, rgba(255, 255, 255, 0.68) 59% 60%, transparent 61% 100%);
  opacity: 0.7;
}

.player-tab .ice-shatter {
  position: absolute;
  inset: -4px -8px;
  border-radius: inherit;
  pointer-events: none;
  z-index: 4;
}

.player-tab .ice-shard {
  position: absolute;
  width: 18px;
  height: 14px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.95), rgba(114, 204, 245, 0.62));
  border: 1px solid rgba(255, 255, 255, 0.82);
  box-shadow: 0 3px 8px rgba(33, 117, 178, 0.22);
  clip-path: polygon(16% 6%, 96% 26%, 68% 100%, 0 68%);
  opacity: 0;
}

.player-tab.ice-shattering .ice-shard {
  animation: ice-shard-burst 0.32s ease-out forwards;
}

.player-tab .shard-1 {
  left: 12%;
  top: 8%;
  --tx: -18px;
  --ty: -14px;
  --rot: -34deg;
}

.player-tab .shard-2 {
  left: 34%;
  top: -2px;
  --tx: -5px;
  --ty: -20px;
  --rot: 22deg;
  animation-delay: 0.02s;
}

.player-tab .shard-3 {
  right: 28%;
  top: 14%;
  --tx: 12px;
  --ty: -18px;
  --rot: 40deg;
  animation-delay: 0.04s;
}

.player-tab .shard-4 {
  right: 8%;
  bottom: 14%;
  --tx: 20px;
  --ty: 10px;
  --rot: 32deg;
  animation-delay: 0.03s;
}

.player-tab .shard-5 {
  left: 24%;
  bottom: -1px;
  --tx: -12px;
  --ty: 16px;
  --rot: -20deg;
  animation-delay: 0.05s;
}

.player-tab .shard-6 {
  right: 40%;
  bottom: 6%;
  --tx: 8px;
  --ty: 18px;
  --rot: 18deg;
  animation-delay: 0.01s;
}

@keyframes ice-shard-burst {
  0% {
    opacity: 0.95;
    transform: translate3d(0, 0, 0) rotate(0deg) scale(0.86);
  }

  100% {
    opacity: 0;
    transform: translate3d(var(--tx), var(--ty), 0) rotate(var(--rot)) scale(0.72);
  }
}

.player-tab .timer-badge {
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  background: rgba(42, 25, 8, 0.08);
  color: var(--lobby-muted);
  min-width: 40px;
  text-align: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.player-tab .timer-badge .ui-icon {
  width: 1em;
  height: 1em;
}

.player-tab.active .timer-badge {
  background: rgba(76, 175, 80, 0.18);
  color: #1B5E20;
  border: 1px solid rgba(76, 175, 80, 0.32);
}

.player-tab.active .timer-badge.warning {
  background: rgba(255, 152, 0, 0.2);
  color: #A84400;
  border-color: rgba(251, 140, 0, 0.42);
  animation: timer-pulse 1s ease-in-out infinite;
}

.player-tab.active .timer-badge.danger {
  background: rgba(244, 67, 54, 0.18);
  color: #B71C1C;
  border-color: rgba(244, 67, 54, 0.44);
  animation: timer-pulse 0.5s ease-in-out infinite;
}

@keyframes timer-pulse {

  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.08);
  }
}

/* Timer progress bar */
#timer-bar-container {
  height: 6px;
  margin: 0;
  background: rgba(107, 75, 42, 0.12);
  border: none;
  border-radius: 0;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  overflow: hidden;
  box-shadow: inset 0 -1px 2px rgba(42, 25, 8, 0.16);
}

#timer-bar {
  height: 100%;
  background: linear-gradient(90deg, #66BB6A, #43A047);
  transition: width 1s linear, background 0.5s;
  width: 100%;
  box-shadow: 0 0 12px rgba(67, 160, 71, 0.32);
}

#timer-bar.warning {
  background: linear-gradient(90deg, #FFA726, #FB8C00);
  box-shadow: 0 0 12px rgba(251, 140, 0, 0.36);
}

#timer-bar.danger {
  background: linear-gradient(90deg, #EF5350, #E53935);
  box-shadow: 0 0 12px rgba(229, 57, 53, 0.38);
}

.game-info {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  color: var(--lobby-muted);
  font-weight: 800;
}

.pool-count {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 40px;
  padding: 4px 10px 4px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.66);
  border: 1px solid rgba(107, 75, 42, 0.14);
  box-shadow:
    0 6px 16px rgba(42, 25, 8, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.78);
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.pool-count.empty {
  background: linear-gradient(135deg, rgba(255, 248, 225, 0.96), rgba(255, 229, 180, 0.9));
  border-color: rgba(249, 115, 22, 0.54);
  box-shadow:
    0 0 0 3px rgba(249, 115, 22, 0.14),
    0 8px 18px rgba(194, 65, 12, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.82);
}

.pool-icon {
  width: 34px;
  height: 38px;
  position: relative;
  display: grid;
  place-items: center;
  color: #5B3518;
  font-size: 14px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(170deg, #FFFDF7 0%, #FAF3E4 45%, #EBDDC5 100%);
  border-radius: 7px;
  border: 1px solid rgba(160, 140, 110, 0.44);
  box-shadow:
    0 5px 8px rgba(42, 25, 8, 0.18),
    inset 0 1px 1px rgba(255, 255, 255, 0.82);
}

.pool-icon::before,
.pool-icon::after {
  content: '';
  position: absolute;
  inset: 3px;
  border-radius: 6px;
  background: inherit;
  border: 1px solid rgba(160, 140, 110, 0.28);
  z-index: -1;
}

.pool-icon::before {
  transform: translate(4px, -3px) rotate(4deg);
}

.pool-icon::after {
  transform: translate(2px, 3px) rotate(-3deg);
}

#pool-count-num {
  position: relative;
  z-index: 1;
  line-height: 1;
  max-width: 30px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pool-count-label {
  font-size: 12px;
  color: var(--lobby-muted);
}

.pool-count.empty .pool-icon {
  color: #B45309;
  border-color: rgba(249, 115, 22, 0.62);
  background: linear-gradient(170deg, #FFF7ED 0%, #FED7AA 100%);
}

.pool-count.empty .pool-count-label {
  color: #9A3412;
}

/* Table area */
#table-area {
  flex: 1;
  overflow: hidden;
  padding: 10px 14px;
  position: relative;
  display: flex;
  flex-direction: column;
  margin: 0;
  border-radius: 0;
  background:
    radial-gradient(circle at 18% 12%, rgba(255, 213, 79, 0.16), transparent 30%),
    radial-gradient(circle at 80% 0%, rgba(255, 248, 229, 0.1), transparent 28%),
    linear-gradient(145deg, rgba(46, 125, 50, 0.76), rgba(27, 94, 32, 0.82) 54%, rgba(18, 53, 31, 0.72));
  border-top: 1px solid rgba(255, 248, 229, 0.24);
  border-bottom: 1px solid rgba(255, 248, 229, 0.18);
  box-shadow:
    inset 0 1px 0 rgba(255, 248, 229, 0.2),
    inset 0 -18px 36px rgba(0, 0, 0, 0.1);
  /* iOS 全面屏适配 - 横屏时左右安全区域 */
  padding-left: max(14px, env(safe-area-inset-left));
  padding-right: max(14px, env(safe-area-inset-right));
}

/* PC 超宽屏：仅牌桌区域左右留出比例边距，不限制最大宽度 */
@media (min-width: 1921px) {
  #table-area {
    padding-left: 10vw;
    padding-right: 10vw;
  }
}

.first-turn-hint {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  padding: 10px 12px;
  border-radius: 16px;
  background: rgba(255, 253, 247, 0.92);
  border: 1px solid rgba(255, 209, 102, 0.42);
  color: var(--lobby-text);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.45;
  box-shadow: 0 8px 20px rgba(42, 25, 8, 0.18);
}

.first-turn-hint.show {
  display: flex;
}

.initial-meld-hint {
  display: none;
  align-self: flex-start;
  align-items: center;
  gap: 8px;
  width: fit-content;
  max-width: 100%;
  margin-bottom: 8px;
  padding: 8px 12px 8px 9px;
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(236, 252, 255, 0.96), rgba(255, 253, 247, 0.96));
  border: 1px solid rgba(73, 169, 227, 0.48);
  color: #17445F;
  font-size: 13px;
  font-weight: 850;
  line-height: 1.4;
  box-shadow: 0 8px 18px rgba(18, 53, 31, 0.18);
}

.initial-meld-hint::before {
  content: '破冰';
  flex: 0 0 auto;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(73, 169, 227, 0.16);
  border: 1px solid rgba(73, 169, 227, 0.28);
  color: #0E7490;
  font-size: 12px;
  font-weight: 950;
  line-height: 1;
}

.initial-meld-hint.show {
  display: inline-flex;
}

.initial-meld-hint.needs-points {
  border-color: rgba(73, 169, 227, 0.5);
}

.initial-meld-hint.ready {
  border-color: rgba(22, 163, 74, 0.52);
  background: linear-gradient(135deg, rgba(240, 253, 244, 0.96), rgba(255, 253, 247, 0.96));
  color: #14532D;
}

.initial-meld-hint.ready::before {
  content: '已破冰';
  background: rgba(22, 163, 74, 0.14);
  border-color: rgba(22, 163, 74, 0.28);
  color: #15803D;
}

.first-turn-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.first-turn-actions button {
  min-height: 44px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid rgba(22, 101, 52, 0.24);
  background: #FFFDF7;
  color: var(--lobby-green);
  font-weight: 900;
  cursor: pointer;
}

#melds-container {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 8px;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

.meld-row {
  display: inline-flex;
  align-items: center;
  gap: var(--tile-gap);
  padding: 6px 6px 9px 6px;
  border-radius: 12px;
  background: rgba(255, 248, 229, 0.12);
  border: 1px solid rgba(255, 248, 229, 0.1);
  position: relative;
  transition: background 0.2s, box-shadow 0.2s, border-color 0.2s;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.meld-row::-webkit-scrollbar {
  display: none;
}

.meld-row.valid {
  box-shadow: inset 0 0 0 2px rgba(76, 175, 80, 0.5);
}

.meld-row.invalid {
  box-shadow: inset 0 0 0 2px rgba(244, 67, 54, 0.5);
}

/* 本回合修改过的组 */
.meld-row.modified {
  background: rgba(255, 213, 79, 0.7);
}

/* 本回合修改过的组，同时保留 valid 的内边框，加强颜色 */
.meld-row.modified.valid {
  box-shadow: inset 0 0 0 2px rgba(51, 245, 58, 1);
}

/* 本回合修改过的组，同时保留 invalid 的内边框，加强颜色 */
.meld-row.modified.invalid {
  box-shadow: inset 0 0 0 2px rgba(244, 67, 54, 1);
}

.meld-row.drag-over {
  background: rgba(255, 248, 229, 0.2);
  box-shadow: inset 0 0 0 2px rgba(255, 213, 79, 0.62), 0 0 18px rgba(255, 213, 79, 0.16);
}

.empty-table-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  color: rgba(255, 248, 229, 0.52);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 1px;
}

/* Controls */
#controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 14px;
  margin: 0;
  background: linear-gradient(135deg, rgba(255, 253, 247, 0.94), rgba(255, 241, 204, 0.84));
  backdrop-filter: blur(14px);
  border: none;
  border-top: 1px solid var(--game-border);
  border-bottom: 1px solid rgba(107, 75, 42, 0.1);
  border-radius: 0;
  box-shadow: 0 -8px 20px rgba(42, 25, 8, 0.1);
  flex-shrink: 0;
  /* iOS 全面屏适配 - 横屏时左右安全区域 */
  padding-left: max(14px, env(safe-area-inset-left));
  padding-right: max(14px, env(safe-area-inset-right));
}

.ctrl-btn {
  min-height: 44px;
  min-width: 44px;
  padding: 8px 18px;
  border-radius: 999px;
  border: 2px solid rgba(107, 75, 42, 0.12);
  background: rgba(255, 255, 255, 0.72);
  color: var(--lobby-text);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
  display: flex;
  align-items: center;
  gap: 5px;
  box-shadow:
    0 6px 14px rgba(42, 25, 8, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.78);
}

.ctrl-btn:hover:not(:disabled) {
  background: #FFF7D6;
  border-color: rgba(245, 158, 11, 0.52);
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(42, 25, 8, 0.16);
}

.ctrl-btn:active:not(:disabled) {
  transform: translateY(0);
}

.ctrl-btn:focus-visible {
  outline: 3px solid var(--lobby-ring);
  outline-offset: 3px;
}

.ctrl-btn.primary {
  background: linear-gradient(135deg, #43A047, #66BB6A);
  border-color: #2E7D32;
  color: #FFFFFF;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.24);
}

.ctrl-btn.primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #388E3C, #43A047);
  box-shadow: 0 8px 18px rgba(67, 160, 71, 0.32);
}

.ctrl-btn.danger {
  border-color: rgba(244, 67, 54, 0.46);
  color: #C62828;
  background: rgba(255, 245, 243, 0.78);
}

.ctrl-btn.danger:hover:not(:disabled) {
  background: rgba(244, 67, 54, 0.15);
  border-color: rgba(244, 67, 54, 0.62);
}

.ctrl-btn:disabled {
  opacity: 0.46;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none;
}

.reaction-control {
  position: relative;
  display: flex;
  align-items: center;
}

.reaction-palette {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 10px);
  width: min(360px, calc(100vw - 20px));
  padding: 12px;
  border-radius: 20px;
  border: 1px solid rgba(255, 209, 102, 0.42);
  background: linear-gradient(135deg, rgba(255, 253, 247, 0.98), rgba(255, 242, 205, 0.96));
  color: var(--lobby-text);
  box-shadow:
    0 18px 42px rgba(42, 25, 8, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.88);
  transform: translateX(-50%);
  z-index: 40;
}

.reaction-palette[hidden] {
  display: none;
}

.reaction-palette-section + .reaction-palette-section {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(107, 75, 42, 0.12);
}

.reaction-palette-title {
  margin-bottom: 7px;
  color: var(--lobby-muted);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 1px;
}

.reaction-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.reaction-option {
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid rgba(107, 75, 42, 0.14);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.7);
  color: var(--lobby-text);
  font: inherit;
  font-size: 15px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.74);
  transition: transform 0.18s ease, background 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.reaction-option:hover {
  background: #FFF7D6;
  border-color: rgba(245, 158, 11, 0.5);
  transform: translateY(-1px);
  box-shadow: 0 8px 16px rgba(42, 25, 8, 0.14);
}

.emoji-option {
  min-height: 52px;
  padding: 4px;
  border-color: transparent;
  background: transparent;
  font-size: 30px;
  line-height: 1;
  box-shadow: none;
}

.emoji-option:hover {
  border-color: transparent;
  background: transparent;
  transform: translateY(-1px) scale(1.12);
  box-shadow: none;
}

.reaction-option:focus-visible {
  outline: 3px solid var(--lobby-ring);
  outline-offset: 2px;
}

.chat-composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(107, 75, 42, 0.12);
}

.chat-composer-label {
  grid-column: 1 / -1;
  color: var(--lobby-muted);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 1px;
}

.chat-composer-input {
  min-width: 0;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid rgba(107, 75, 42, 0.22);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.86);
  color: var(--lobby-text);
  font: inherit;
  font-size: 16px;
}

.chat-composer-input::placeholder {
  color: rgba(107, 75, 42, 0.58);
}

.chat-composer-input:focus-visible,
.chat-composer-send:focus-visible {
  outline: 3px solid var(--lobby-ring);
  outline-offset: 2px;
}

.chat-composer-send {
  min-width: 52px;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid #2E7D32;
  border-radius: 13px;
  background: linear-gradient(135deg, #43A047, #66BB6A);
  color: #FFFFFF;
  font: inherit;
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(67, 160, 71, 0.24);
}

.chat-composer-send:hover {
  background: linear-gradient(135deg, #388E3C, #43A047);
}

#reaction-layer {
  position: absolute;
  inset: 0;
  z-index: 8;
  pointer-events: none;
  overflow: hidden;
}

.reaction-bubble {
  position: absolute;
  top: calc(18px + var(--reaction-offset, 0px));
  left: max(28px, env(safe-area-inset-left));
  display: inline-flex;
  align-items: center;
  gap: 10px;
  max-width: min(330px, 48vw);
  color: var(--lobby-text);
  transform: translateX(-14px) translateY(10px) scale(0.96);
  animation: reaction-pop 2.8s ease forwards;
}

.reaction-bubble-avatar {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 3px solid #FFF7EA;
  background:
    radial-gradient(circle at 50% 45%, rgba(255, 255, 255, 0.28) 0 18%, transparent 19%),
    linear-gradient(145deg, var(--reaction-color, #FFD54F), #183620 64%);
  color: #FFF7EA;
  font-size: 16px;
  font-weight: 950;
  line-height: 1;
  box-shadow:
    0 0 0 2px rgba(16, 35, 23, 0.42),
    0 7px 16px rgba(10, 29, 18, 0.34);
}

.reaction-bubble-content {
  min-width: 0;
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  transform: translateY(-8px);
}

.reaction-bubble-name {
  min-width: 0;
  max-width: 150px;
  color: #FFD7A0;
  font-size: 13px;
  font-weight: 950;
  line-height: 1;
  text-shadow: 0 1px 2px rgba(16, 35, 23, 0.55);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reaction-bubble-label {
  min-width: 0;
  max-width: 240px;
  padding: 14px 17px;
  border-radius: 18px;
  background: #FFFDF7;
  color: #6E2B00;
  font-size: 18px;
  font-weight: 850;
  line-height: 1.25;
  overflow-wrap: anywhere;
  box-shadow:
    3px 3px 0 #E8DACB,
    0 4px 8px rgba(232, 218, 203, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.95);
}

.reaction-bubble.emoji-reaction .reaction-bubble-label {
  padding: 10px 15px;
  font-size: 28px;
  line-height: 1;
}

.reaction-bubble.text-chat .reaction-bubble-label {
  font-size: 16px;
  font-weight: 750;
  white-space: pre-wrap;
}

.reaction-bubble-exit {
  animation: reaction-exit 0.18s ease forwards;
}

@keyframes reaction-pop {
  0% {
    opacity: 0;
    transform: translateX(-14px) translateY(12px) scale(0.94);
  }
  12%, 100% {
    opacity: 1;
    transform: translateX(0) translateY(0) scale(1);
  }
}

@keyframes reaction-exit {
  to {
    opacity: 0;
    transform: translateX(-10px) translateY(-8px) scale(0.96);
  }
}

@media (prefers-reduced-motion: reduce) {
  .reaction-bubble,
  .reaction-bubble-exit {
    animation-duration: 0.01ms;
  }
}

/* Rack */
#rack-area {
  padding: 8px 14px 10px;
  background: linear-gradient(180deg, rgba(255, 253, 247, 0.78), rgba(255, 235, 185, 0.68));
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--game-border);
  box-shadow: 0 -12px 28px rgba(42, 25, 8, 0.14);
  flex-shrink: 0;
  /* iOS 全面屏适配 - 底部安全区域 */
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  padding-left: max(14px, env(safe-area-inset-left));
  padding-right: max(14px, env(safe-area-inset-right));
}

#rack {
  display: flex;
  gap: var(--tile-gap);
  padding: 7px 10px;
  min-height: calc(var(--tile-h) + 12px);
  background:
    linear-gradient(180deg, rgba(255, 248, 229, 0.86), rgba(232, 194, 125, 0.32)),
    rgba(255, 255, 255, 0.42);
  border: 1px solid rgba(107, 75, 42, 0.12);
  border-radius: 16px;
  overflow-x: auto;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  box-shadow:
    inset 0 2px 8px rgba(42, 25, 8, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.72);
}

.rack-touch-hint {
  display: none;
  margin-top: 6px;
  color: rgba(42, 25, 8, 0.66);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.35;
  text-align: center;
}

#rack::-webkit-scrollbar {
  height: 4px;
}

#rack::-webkit-scrollbar-track {
  background: transparent;
}

#rack::-webkit-scrollbar-thumb {
  background: rgba(107, 75, 42, 0.26);
  border-radius: 2px;
}

/* ====== TILE ====== */
.tile {
  width: var(--tile-w);
  height: var(--tile-h);
  /* 多层渐变模拟象牙质感 */
  background:
    /* 顶部高光 */
    linear-gradient(175deg,
      rgba(255, 255, 252, 0.85) 0%,
      rgba(255, 255, 250, 0.3) 15%,
      transparent 40%),
    /* 底部阴影过渡 */
    linear-gradient(0deg,
      rgba(190, 175, 150, 0.25) 0%,
      transparent 30%),
    /* 主体象牙色基底 */
    linear-gradient(170deg,
      #FBF8F1 0%,
      #F5F0E6 25%,
      #EDE6D8 50%,
      #E8DFCE 75%,
      #E2D8C6 100%);
  border-radius: 7px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: var(--tile-font);
  cursor: grab;
  touch-action: none;
  position: relative;
  /* 多层阴影打造3D厚实感 */
  box-shadow:
    /* 外部投影 - 牌的落影 */
    0 3px 6px rgba(0, 0, 0, 0.2),
    0 1px 2px rgba(0, 0, 0, 0.15),
    /* 底部厚边 - 模拟牌的厚度 */
    0 4px 0 0 #C9BDA8,
    0 5px 0 0 #B8AC96,
    0 6px 3px rgba(0, 0, 0, 0.2),
    /* 内部高光 - 顶边 */
    inset 0 2px 3px rgba(255, 255, 255, 0.9),
    /* 内部高光 - 左边 */
    inset 2px 0 3px rgba(255, 255, 255, 0.5),
    /* 内部阴影 - 底边 */
    inset 0 -2px 4px rgba(180, 165, 140, 0.3),
    /* 内部阴影 - 右边 */
    inset -2px 0 3px rgba(180, 165, 140, 0.15);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  flex-shrink: 0;
  /* 边框模拟牌边缘的微妙接缝 */
  border: 1px solid rgba(175, 160, 135, 0.45);
  border-top-color: rgba(220, 210, 195, 0.6);
  border-left-color: rgba(200, 190, 170, 0.5);
  /* 字体渲染优化 */
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.tile:hover {
  transform: translateY(-4px);
  box-shadow:
    0 8px 16px rgba(0, 0, 0, 0.18),
    0 3px 6px rgba(0, 0, 0, 0.12),
    0 4px 0 0 #C9BDA8,
    0 5px 0 0 #B8AC96,
    0 6px 3px rgba(0, 0, 0, 0.15),
    inset 0 2px 3px rgba(255, 255, 255, 0.9),
    inset 2px 0 3px rgba(255, 255, 255, 0.5),
    inset 0 -2px 4px rgba(180, 165, 140, 0.3),
    inset -2px 0 3px rgba(180, 165, 140, 0.15);
}

.tile:active {
  cursor: grabbing;
}


.tile .number {
  line-height: 1;
  /* 数字浮雕效果 - 上方亮光+下方暗影 */
  filter: drop-shadow(0 1px 0 rgba(255, 255, 255, 0.7));
}

.tile .mini-num {
  position: absolute;
  font-size: var(--tile-mini-font);
  font-weight: 700;
}

.tile .mini-num.top-left {
  top: 3px;
  left: 5px;
}

.tile .mini-num.bottom-right {
  bottom: 3px;
  right: 5px;
}

.tile.color-red .number,
.tile.color-red .mini-num {
  color: var(--color-red);
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.5),
    0 -1px 1px rgba(180, 30, 30, 0.15);
}

.tile.color-blue .number,
.tile.color-blue .mini-num {
  color: var(--color-blue);
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.5),
    0 -1px 1px rgba(20, 80, 160, 0.15);
}

.tile.color-black .number,
.tile.color-black .mini-num {
  color: var(--color-black);
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.5),
    0 -1px 1px rgba(30, 40, 50, 0.15);
}

.tile.color-orange .number,
.tile.color-orange .mini-num {
  color: var(--color-orange);
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.5),
    0 -1px 1px rgba(180, 100, 0, 0.15);
}

/* 最新摸的牌 - 添加非常明显的绿色发光效果 */
.tile.newly-drawn {
  animation: tile-glow 1s ease-in-out infinite;
  position: relative;
}

.tile.newly-drawn::before {
  content: '新';
  position: absolute;
  top: -8px;
  right: -8px;
  background: linear-gradient(135deg, #4CAF50, #66BB6A);
  color: white;
  font-size: 10px;
  font-weight: 900;
  padding: 2px 6px;
  border-radius: 10px;
  box-shadow: 0 2px 6px rgba(76, 175, 80, 0.8);
  z-index: 10;
}

@keyframes tile-glow {

  0%,
  100% {
    box-shadow:
      0 0 16px rgba(76, 175, 80, 0.9),
      0 0 8px rgba(76, 175, 80, 0.7),
      0 3px 6px rgba(0, 0, 0, 0.2),
      0 4px 0 0 #C9BDA8,
      0 5px 0 0 #B8AC96,
      0 6px 3px rgba(0, 0, 0, 0.2),
      inset 0 2px 3px rgba(255, 255, 255, 0.9),
      inset 0 0 20px rgba(76, 175, 80, 0.15);
    transform: scale(1);
  }

  50% {
    box-shadow:
      0 0 24px rgba(76, 175, 80, 1),
      0 0 12px rgba(76, 175, 80, 0.9),
      0 6px 12px rgba(0, 0, 0, 0.2),
      0 4px 0 0 #C9BDA8,
      0 5px 0 0 #B8AC96,
      0 6px 3px rgba(0, 0, 0, 0.2),
      inset 0 2px 3px rgba(255, 255, 255, 0.95),
      inset 0 0 30px rgba(76, 175, 80, 0.2);
    transform: scale(1.05);
  }
}

.tile.joker .number {
  font-size: 0;
  width: 80%;
  height: 80%;
  max-width: var(--tile-w);
  max-height: var(--tile-h);
  background-image: url('/assets/images/joker.png');
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  display: inline-block;
}

/* 特殊百搭牌 */
.tile.joker-double .number {
  background-image: url('/assets/images/joker-double.png');
}

.tile.joker-color-change .number {
  background-image: url('/assets/images/joker-color-change.png');
}

.tile.joker-mirror .number {
  background-image: url('/assets/images/joker-mirror.png');
}

.tile.new-this-turn {
  background: white;
}

.tile.not-my-turn {
  cursor: default;
}

.tile.not-my-turn:hover {
  transform: none;
}

/* 拖拽期间锁定触摸手势并禁用牌区鼠标事件，提升手机拖牌稳定性 */
body.is-dragging {
  touch-action: none;
  overscroll-behavior: none;
}

body.is-dragging #table-area,
body.is-dragging #rack-area {
  pointer-events: none !important;
}

/* ====== OVERLAYS ====== */

#win-screen,
#resume-session-modal,
#rules-modal,
#disconnect-screen,
#kick-player-modal,
#transfer-host-modal {
  display: none;
}

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9000;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background:
    radial-gradient(circle at 18% 16%, rgba(255, 209, 102, 0.24), transparent 34%),
    radial-gradient(circle at 82% 12%, rgba(249, 115, 22, 0.2), transparent 30%),
    rgba(42, 25, 8, 0.62);
  backdrop-filter: blur(14px);
}

.modal-card {
  position: relative;
  width: min(520px, 100%);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  padding: clamp(22px, 4vw, 34px);
  border-radius: 26px;
  text-align: center;
  color: var(--lobby-text);
  background:
    radial-gradient(circle at 20% 0%, rgba(255, 213, 79, 0.28), transparent 30%),
    linear-gradient(135deg, rgba(255, 253, 247, 0.98), rgba(255, 243, 214, 0.94));
  border: 1px solid rgba(255, 209, 102, 0.36);
  box-shadow:
    0 28px 80px rgba(42, 25, 8, 0.34),
    inset 0 1px 0 rgba(255, 255, 255, 0.88);
}

.modal-card::before {
  content: '';
  position: absolute;
  top: 16px;
  right: 22px;
  width: 64px;
  height: 64px;
  border-radius: 999px;
  pointer-events: none;
  background: radial-gradient(circle, rgba(245, 158, 11, 0.22) 0 28%, transparent 64%);
}

.modal-kicker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  margin-bottom: 12px;
  padding: 4px 11px;
  border-radius: 999px;
  background: rgba(245, 158, 11, 0.14);
  border: 1px solid rgba(245, 158, 11, 0.24);
  color: var(--lobby-accent-strong);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 1px;
}

.modal-card h2 {
  color: var(--lobby-green);
  font-size: clamp(26px, 4vw, 36px);
  line-height: 1.15;
  margin-bottom: 10px;
}

.modal-card p {
  color: var(--lobby-muted);
  margin-bottom: 0;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.6;
}

#disconnect-msg {
  white-space: pre-line;
}

.rules-modal-card {
  width: min(720px, 100%);
  text-align: left;
}

.rules-content {
  display: grid;
  gap: 14px;
}

.rules-section {
  padding: 14px;
  border-radius: 16px;
  background: rgba(255, 253, 247, 0.66);
  border: 1px solid rgba(107, 75, 42, 0.1);
}

.rules-section h3 {
  margin-bottom: 8px;
  color: var(--lobby-green);
  font-size: 17px;
}

.rules-steps,
.rules-list {
  display: grid;
  gap: 8px;
  padding-left: 20px;
  color: var(--lobby-muted);
  font-size: 14px;
  font-weight: 750;
  line-height: 1.5;
}

.rules-steps li span {
  display: block;
  margin-top: 2px;
}

.rules-callout {
  background: rgba(255, 246, 221, 0.82);
  border-color: rgba(245, 158, 11, 0.28);
}

.rules-joker-gallery {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 10px 0 12px;
}

.rules-joker-card {
  display: grid;
  justify-items: center;
  gap: 8px;
  margin: 0;
  padding: 12px 10px;
  border-radius: 14px;
  background: rgba(255, 253, 247, 0.72);
  border: 1px solid rgba(107, 75, 42, 0.12);
  text-align: center;
}

.rules-joker-card img {
  width: 48px;
  height: auto;
  object-fit: contain;
  filter: drop-shadow(0 4px 8px rgba(42, 25, 8, 0.22));
}

.rules-joker-card figcaption {
  display: grid;
  gap: 3px;
}

.rules-joker-card strong {
  color: var(--lobby-green);
  font-size: 13px;
}

.rules-joker-card span {
  color: var(--lobby-muted);
  font-size: 12px;
  font-weight: 750;
  line-height: 1.35;
}

@media (max-width: 600px) {
  .rules-joker-gallery {
    grid-template-columns: 1fr;
  }

  .rules-joker-card {
    grid-template-columns: auto 1fr;
    justify-items: start;
    text-align: left;
  }

  .rules-joker-card img {
    width: 44px;
  }

  .first-turn-hint {
    align-items: stretch;
    flex-direction: column;
  }

  .initial-meld-hint {
    padding: 8px 10px;
    font-size: 12px;
    border-radius: 14px;
  }
}

.modal-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(140px, 0.42fr);
  gap: 10px;
  align-items: stretch;
  margin-top: 22px;
}

.modal-actions.single-action {
  grid-template-columns: 1fr;
}

.modal-actions .lobby-btn {
  margin-top: 0;
}

.modal-card :is(button):focus-visible {
  outline: 3px solid var(--lobby-ring);
  outline-offset: 3px;
}

/* Toast */
#toast {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px) scale(0.98);
  background: linear-gradient(135deg, rgba(255, 253, 247, 0.97), rgba(255, 242, 205, 0.94));
  color: var(--lobby-text);
  padding: 12px 28px;
  border-radius: 999px;
  border: 1px solid rgba(107, 75, 42, 0.14);
  font-size: 15px;
  font-weight: 800;
  z-index: 9500;
  opacity: 0;
  transition: opacity 0.24s ease, transform 0.24s ease;
  pointer-events: none;
  backdrop-filter: blur(14px);
  white-space: normal;
  line-height: 1.45;
  max-width: min(520px, calc(100vw - 24px));
  overflow-wrap: anywhere;
  text-align: center;
  box-shadow:
    0 14px 34px rgba(42, 25, 8, 0.24),
    inset 0 1px 0 rgba(255, 255, 255, 0.82);
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0) scale(1);
}

#toast.error {
  --toast-accent: #E53935;
  color: #8A1C12;
  background: linear-gradient(135deg, rgba(255, 248, 247, 0.98), rgba(255, 225, 220, 0.94));
}

#toast.success {
  --toast-accent: #43A047;
  color: #1B5E20;
  background: linear-gradient(135deg, rgba(248, 255, 246, 0.98), rgba(220, 245, 214, 0.94));
}

#toast.info {
  --toast-accent: #1E88E5;
  color: #0D47A1;
  background: linear-gradient(135deg, rgba(247, 252, 255, 0.98), rgba(219, 237, 255, 0.94));
}

/* 连接状态指示器 */
#connection-status {
  position: fixed;
  top: max(10px, env(safe-area-inset-top, 10px));
  right: max(10px, env(safe-area-inset-right, 10px));
  min-width: 190px;
  max-width: min(340px, calc(100vw - 24px));
  padding: 10px 12px;
  border-radius: 18px;
  font-size: 12px;
  font-weight: 900;
  z-index: 9600;
  display: none;
  flex-direction: column;
  gap: 8px;
  backdrop-filter: blur(16px);
  background: linear-gradient(135deg, rgba(255, 253, 247, 0.96), rgba(255, 242, 205, 0.92));
  border: 1px solid rgba(245, 158, 11, 0.26);
  color: var(--lobby-text);
  box-shadow:
    0 12px 30px rgba(42, 25, 8, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.82);
}

#connection-status.show {
  display: flex;
}

#connection-status.connected {
  background: linear-gradient(135deg, rgba(248, 255, 246, 0.97), rgba(220, 245, 214, 0.94));
  border-color: rgba(67, 160, 71, 0.28);
}

.connection-status-main {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

#connection-status-text {
  min-width: 0;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

#connection-status .status-dot {
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--lobby-accent);
  box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.16);
  animation: blink 1s ease-in-out infinite;
}

#connection-status.connected .status-dot {
  background: #43A047;
  box-shadow: 0 0 0 4px rgba(67, 160, 71, 0.16);
  animation: none;
}

#connection-status-progress {
  display: none;
  height: 5px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(107, 75, 42, 0.12);
}

#connection-status.has-progress #connection-status-progress {
  display: block;
}

#connection-status-progress-bar {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  transform: scaleX(0);
  transform-origin: left center;
  background: linear-gradient(90deg, var(--lobby-accent), #FB923C);
}

@keyframes blink {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.3;
  }
}

@media (max-width: 600px) {
  #connection-status {
    font-size: 11px;
    padding: 6px 12px;
    top: max(8px, env(safe-area-inset-top, 8px));
    right: max(8px, env(safe-area-inset-right, 8px));
  }
}

/* Win screen */
#win-screen.overlay {
  isolation: isolate;
  background:
    radial-gradient(circle at 18% 16%, rgba(255, 213, 79, 0.3), transparent 30%),
    radial-gradient(circle at 82% 18%, rgba(249, 115, 22, 0.24), transparent 28%),
    rgba(42, 25, 8, 0.58);
  backdrop-filter: blur(8px);
}

#win-confetti-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

#win-screen .overlay-content {
  position: relative;
  z-index: 1;
  overflow: hidden;
  width: min(520px, 100%);
  max-height: calc(100dvh - 32px);
  padding: clamp(28px, 4vw, 48px) clamp(32px, 5vw, 64px);
  border-radius: 24px;
  text-align: center;
  color: var(--lobby-text);
  background:
    radial-gradient(circle at 20% 0%, rgba(255, 213, 79, 0.32), transparent 28%),
    linear-gradient(135deg, rgba(255, 253, 247, 0.98), rgba(255, 239, 198, 0.94));
  border: 1px solid var(--game-border);
  box-shadow:
    0 24px 70px rgba(42, 25, 8, 0.34),
    inset 0 1px 0 rgba(255, 255, 255, 0.88);
}

#win-screen .overlay-content::before {
  content: '✦';
  position: absolute;
  top: 16px;
  right: 24px;
  color: rgba(245, 158, 11, 0.34);
  font-size: 64px;
  line-height: 1;
  pointer-events: none;
}

#win-screen h2 {
  font-size: 48px;
  margin-bottom: 8px;
  background: linear-gradient(135deg, #F59E0B, #D97706 48%, #43A047);
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.winner-name {
  font-size: 28px;
  color: var(--winner-color, var(--gold));
  margin-bottom: 16px;
  font-weight: 900;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.68);
}

.final-scores {
  text-align: left;
  margin: 20px 0;
  padding: 14px;
  background: rgba(255, 255, 255, 0.52);
  border: 1px solid rgba(107, 75, 42, 0.12);
  border-radius: 18px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.78);
}

.final-scores .score-row {
  display: flex;
  justify-content: space-between;
  padding: 9px 12px;
  border-bottom: none;
  border-radius: 12px;
  font-size: 16px;
  gap: 10px;
  align-items: center;
  color: var(--lobby-text);
}

.final-scores .score-row + .score-row {
  margin-top: 6px;
}

.final-scores .score-row.winner {
  color: #1B5E20;
  font-weight: 900;
  background: linear-gradient(135deg, rgba(255, 213, 79, 0.34), rgba(200, 230, 201, 0.62));
  box-shadow: inset 0 0 0 1px rgba(67, 160, 71, 0.24);
}

.final-scores .winner-result {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.final-scores .winner-result .ui-icon {
  width: 1.15em;
  height: 1.15em;
  color: #D97706;
}

#rematch-status {
  min-height: 22px;
  margin: -4px 0 16px;
  color: var(--lobby-muted);
  font-size: 14px;
  font-weight: 800;
  line-height: 1.5;
}

.win-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(120px, 0.55fr);
  gap: 10px;
}

#win-screen #btn-rematch,
#win-screen #btn-restart {
  min-height: 48px;
  padding: 0 24px;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  font-size: 18px;
  font-weight: 900;
  transition: transform 0.22s ease, box-shadow 0.22s ease, opacity 0.22s ease;
}

#win-screen #btn-rematch {
  background: linear-gradient(135deg, #43A047, #66BB6A);
  color: #FFFFFF;
  box-shadow: 0 10px 22px rgba(67, 160, 71, 0.28);
}

#win-screen #btn-restart {
  background: rgba(255, 253, 247, 0.82);
  color: var(--lobby-muted);
  box-shadow: inset 0 0 0 2px rgba(107, 75, 42, 0.14);
}

#win-screen #btn-rematch:hover:not(:disabled),
#win-screen #btn-restart:hover {
  transform: translateY(-2px);
}

#win-screen #btn-rematch:hover:not(:disabled) {
  box-shadow: 0 14px 28px rgba(67, 160, 71, 0.34);
}

#win-screen #btn-restart:hover {
  box-shadow: inset 0 0 0 2px rgba(245, 158, 11, 0.28), 0 10px 22px rgba(42, 25, 8, 0.12);
}

#win-screen #btn-rematch:disabled {
  cursor: wait;
  opacity: 0.72;
}

#win-screen #btn-rematch:focus-visible,
#win-screen #btn-restart:focus-visible {
  outline: 3px solid var(--lobby-ring);
  outline-offset: 3px;
}

/* Animations */
@keyframes tile-appear {
  from {
    transform: scale(0.5);
    opacity: 0;
  }

  to {
    transform: scale(1);
    opacity: 1;
  }
}

.tile-animate-in {
  animation: tile-appear 0.2s ease-out;
}

/* ====== MOBILE: "YOUR TURN" BANNER ====== */
#my-turn-banner {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 8500;
  background: linear-gradient(135deg, var(--gold), #FFF176);
  color: #333;
  text-align: center;
  font-size: 16px;
  font-weight: 800;
  padding: 10px 16px;
  letter-spacing: 2px;
  animation: banner-slide-in 0.3s ease-out;
  /* iOS 全面屏适配 - 顶部安全区域（刘海/横屏） */
  padding-top: max(10px, env(safe-area-inset-top));
  padding-left: env(safe-area-inset-left, 16px);
  padding-right: env(safe-area-inset-right, 16px);
}

@keyframes banner-slide-in {
  from {
    transform: translateY(-100%);
  }

  to {
    transform: translateY(0);
  }
}

/* ====== RESPONSIVE ====== */

/* iOS 安全区域 - 大厅和等待室 */
#lobby-screen,
#waiting-screen {
  padding-top: max(clamp(14px, 2.5vw, 32px), env(safe-area-inset-top));
  padding-bottom: max(clamp(14px, 2.5vw, 32px), env(safe-area-inset-bottom));
  padding-left: max(clamp(14px, 2.5vw, 32px), env(safe-area-inset-left));
  padding-right: max(clamp(14px, 2.5vw, 32px), env(safe-area-inset-right));
}

@media (max-width: 1100px) {
  #lobby-screen {
    gap: 28px;
  }

  .lobby-form {
    width: min(760px, 100%);
  }

  .lobby-cards {
    grid-template-columns: minmax(0, 1fr) minmax(280px, 0.9fr);
  }
}

/* Tablet */
@media (max-width: 900px) {
  #lobby-screen {
    flex-direction: column;
    justify-content: flex-start;
    overflow-y: auto;
  }

  .lobby-hero {
    max-width: 720px;
    text-align: center;
  }

  .tutorial-link-row {
    text-align: center;
  }

  .lobby-form {
    width: min(720px, 100%);
  }

  .lobby-cards {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .lobby-title {
    width: clamp(240px, 62vw, 350px);
  }

  .waiting-card {
    padding: 24px;
  }

  .room-code {
    font-size: 36px;
    letter-spacing: 8px;
  }
}

/* Phone */
@media (max-width: 480px) {
  #lobby-screen,
  #waiting-screen {
    padding-top: max(10px, env(safe-area-inset-top));
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }

  #lobby-screen {
    gap: 18px;
  }

  .lobby-title {
    width: clamp(220px, 78vw, 320px);
  }

  .tutorial-link-row {
    width: min(100%, 300px);
    gap: 8px;
  }

  .tutorial-link {
    width: min(100%, 280px);
  }

  .subtitle {
    font-size: 14px;
    margin-bottom: 14px;
  }

  .lobby-form {
    width: 100%;
    padding: 16px;
    border-radius: 22px;
  }

  .lobby-name-field {
    padding: 14px;
  }

  .resume-session-meta,
  .resume-actions {
    grid-template-columns: 1fr;
  }

  .resume-actions .lobby-btn.secondary {
    margin-top: 0;
  }

  .lobby-card {
    padding: 16px;
    border-radius: 18px;
  }

  .card-heading {
    margin-bottom: 14px;
  }

  .card-heading h2 {
    font-size: 18px;
  }

  .card-heading p {
    font-size: 12px;
  }

  .card-badge {
    padding: 4px 8px;
    font-size: 11px;
  }

  #lobby-screen .form-group {
    margin-bottom: 14px;
  }

  #lobby-screen .lobby-name-field {
    grid-template-columns: 1fr;
    justify-content: stretch;
    gap: 6px;
    padding: 0;
    margin-bottom: 8px;
  }

  #lobby-screen .lobby-name-field .field-hint {
    grid-column: 1;
  }

  #lobby-screen .form-group label {
    font-size: 14px;
    margin-bottom: 6px;
  }

  #lobby-screen .form-group input[type="text"] {
    font-size: 16px;
    min-height: 46px;
    padding: 2px 12px 0;
  }

  .option-btns {
    gap: 7px;
  }

  .option-btns button {
    min-width: 44px;
    min-height: 44px;
    font-size: 13px;
    padding: 0 10px;
  }

  .lobby-btn {
    min-height: 48px;
    padding: 0 16px;
    font-size: 15px;
  }

  #room-code-input {
    letter-spacing: 4px;
  }

  .waiting-card {
    padding: 20px 16px;
    min-width: auto;
    width: 100%;
  }

  .room-code {
    font-size: 28px;
    letter-spacing: 6px;
  }

  .room-code-wrapper {
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
  }

  .copy-btn {
    font-size: 13px;
    padding: 0 14px;
  }

  .room-invite-qr {
    margin: -2px 0 14px;
    padding: 10px;
    gap: 6px;
  }

  #invite-qr-code {
    width: 136px;
    height: 136px;
  }

  .room-invite-qr-caption,
  .room-invite-qr-fallback {
    font-size: 11px;
  }

  .room-invite-qr-fallback {
    max-width: 136px;
  }

  .waiting-settings {
    font-size: 12px;
  }
}

/* Phone landscape lobby */
@media (orientation: landscape) and (max-height: 500px) and (max-width: 1024px) {
  #lobby-screen,
  #waiting-screen {
    padding-top: max(6px, env(safe-area-inset-top));
    padding-bottom: max(6px, env(safe-area-inset-bottom));
    padding-left: max(8px, env(safe-area-inset-left));
    padding-right: max(8px, env(safe-area-inset-right));
  }

  #lobby-screen {
    flex-direction: row;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 10px;
    height: calc(var(--vh) * 100);
    /* 取较小的稳定视口高度，避免横竖屏切换时旧的竖屏 --vh 撑高布局 */
    height: min(100svh, calc(var(--vh) * 100));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  #waiting-screen {
    justify-content: flex-start;
    gap: 4px;
  }

  #waiting-screen h1 {
    font-size: clamp(24px, 9vh, 34px);
    letter-spacing: 3px;
    margin-bottom: 4px;
  }

  #waiting-screen .subtitle {
    display: none;
  }

  .waiting-card {
    padding: 10px 18px;
    border-radius: 18px;
  }

  .room-code-display label {
    margin-bottom: 4px;
    font-size: 12px;
  }

  .room-code {
    font-size: clamp(24px, 9vh, 34px);
    letter-spacing: 6px;
  }

  #waiting-screen .room-code-display {
    display: grid;
    grid-template-columns: auto auto;
    gap: 6px 14px;
    align-items: center;
    justify-content: center;
  }

  #waiting-screen .room-code-display label {
    grid-column: 1 / -1;
  }

  #waiting-screen .room-code-wrapper {
    margin-bottom: 0;
  }

  #waiting-screen .room-invite-qr {
    margin: 0;
  }

  .waiting-players {
    margin-bottom: 8px;
  }

  .waiting-player {
    padding: 5px 12px;
    margin-bottom: 4px;
    font-size: 14px;
  }

  .waiting-settings {
    margin-bottom: 8px;
  }

  .waiting-hint {
    margin-bottom: 10px;
  }

  .room-management {
    margin-bottom: 8px;
  }

  .lobby-hero {
    flex: 0 0 clamp(140px, 24vw, 220px);
    max-width: clamp(140px, 24vw, 220px);
    min-height: calc(var(--vh) * 100 - 12px);
    min-height: calc(min(100svh, calc(var(--vh) * 100)) - 12px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    text-align: left;
  }

  .lobby-title {
    width: clamp(130px, 23vw, 210px);
    margin-bottom: 2px;
  }

  .subtitle {
    font-size: 12px;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
  }

  .tutorial-link-row {
    width: min(100%, 180px);
    gap: 6px;
    justify-content: center;
    text-align: center;
  }

  .tutorial-link {
    width: min(100%, 170px);
  }

  .lobby-form {
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
    padding: 8px;
    border-radius: 18px;
    overflow: hidden;
  }

  #lobby-screen .lobby-name-field {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    justify-content: stretch;
    gap: 4px 10px;
    align-items: center;
    padding: 2px 0 6px;
    margin-bottom: 6px;
  }

  #lobby-screen .lobby-name-field .field-hint {
    grid-column: 2;
  }

  .lobby-name-field:not(.field-error) .field-hint,
  .join-card .field-hint:empty {
    display: none;
  }

  #lobby-screen .field-hint {
    min-height: 0;
    margin-top: 2px;
  }

  #lobby-screen .form-group {
    margin-bottom: 6px;
  }

  #lobby-screen .form-group label {
    font-size: 13px;
    margin-bottom: 3px;
  }

  #lobby-screen .form-group input[type="text"] {
    min-height: 42px;
    padding: 2px 12px 0;
    font-size: 16px;
    border-radius: 12px;
  }

  .lobby-cards {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 8px;
    align-items: start;
  }

  .lobby-cards.invite-room-first .join-card {
    order: -1;
  }

  .lobby-card {
    padding: 8px 10px;
    border-radius: 14px;
    min-height: 0;
  }

  .card-heading {
    margin-bottom: 6px;
    gap: 8px;
  }

  .card-heading h2 {
    font-size: 16px;
    margin-bottom: 0;
  }

  .card-heading p,
  .card-badge,
  .mode-descriptions,
  .join-guide {
    display: none;
  }

  .join-card-main {
    flex: initial;
  }

  .create-settings {
    align-content: start;
    gap: 4px;
  }

  .create-settings .form-group {
    padding-bottom: 4px;
  }

  .option-btns {
    gap: 6px;
  }

  .option-btns button {
    min-width: 44px;
    min-height: 40px;
    padding: 0 9px;
    border-radius: 12px;
    font-size: 12px;
    white-space: nowrap;
  }

  .lobby-btn {
    min-height: 44px;
    margin-top: 6px;
    padding: 0 12px;
    border-radius: 12px;
    font-size: 14px;
  }

  #room-code-input {
    letter-spacing: 4px;
  }

  .room-invite-qr {
    margin-bottom: 10px;
    padding: 6px;
    gap: 4px;
  }

  #invite-qr-code {
    width: 96px;
    height: 96px;
  }

  .room-invite-qr-caption,
  .room-invite-qr-fallback {
    font-size: 10px;
  }

  .room-invite-qr-fallback {
    max-width: 96px;
  }
}

@media (orientation: landscape) and (max-height: 500px) and (max-width: 760px) {
  #lobby-screen {
    gap: 0;
  }

  .lobby-hero {
    display: none;
  }

  .lobby-form {
    width: 100%;
  }
}

@media (orientation: landscape) and (max-height: 500px) and (max-width: 600px) {
  .lobby-form {
    padding: 6px;
  }

  #lobby-screen .lobby-name-field {
    padding: 2px 0 4px;
    margin-bottom: 4px;
  }

  #lobby-screen .lobby-name-field input[type="text"] {
    min-height: 40px;
  }

  .lobby-card {
    padding: 6px 8px;
  }

  .card-heading {
    display: none;
  }

  .create-settings {
    align-content: start;
    gap: 3px;
  }

  #lobby-screen .create-card .form-group > label {
    display: none;
  }

  .create-settings .form-group {
    padding-bottom: 3px;
  }

  .option-btns {
    gap: 4px;
    flex-wrap: wrap;
  }

  .option-btns button {
    min-width: 44px;
    min-height: 44px;
    padding: 0 4px;
  }

  .lobby-btn {
    min-height: 44px;
    margin-top: 4px;
  }

  #room-code-input {
    letter-spacing: 2px;
  }
}

/* Game screen mobile */
@media (max-width: 600px) {
  #game-screen::before {
    inset: 8px;
    border-radius: 22px;
  }

  #header {
    padding: 4px 8px;
    min-height: 38px;
    gap: 4px;
    padding-top: max(4px, env(safe-area-inset-top));
    padding-left: max(8px, env(safe-area-inset-left));
    padding-right: max(8px, env(safe-area-inset-right));
  }

  .player-tabs {
    gap: 4px;
    flex: 1;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
    -webkit-overflow-scrolling: touch;
  }

  .player-tabs::-webkit-scrollbar {
    display: none;
  }

  .player-tab {
    padding: 4px 8px;
    font-size: 11px;
    gap: 4px;
    flex-shrink: 0;
    border-radius: 999px;
  }

  .player-tab .player-name-wrapper {
    padding-right: 24px;
  }

  .player-tab .tile-count-badge {
    min-width: 18px;
    height: 18px;
    font-size: 10px;
    padding: 0 4px;
    top: -7px;
    right: -3px;
  }

  .player-tab .timer-badge {
    font-size: 10px;
    padding: 1px 5px;
    min-width: 32px;
  }

  .player-tab.me::after {
    font-size: 9px;
  }

  .game-info {
    gap: 8px;
    font-size: 12px;
  }

  .pool-icon {
    width: 30px;
    height: 34px;
    font-size: 12px;
  }

  .pool-count-label {
    display: none;
  }

  #timer-bar-container {
    height: 4px;
    margin: 0;
  }

  #controls {
    padding: 5px 8px;
    gap: 8px;
    margin: 0;
    border-radius: 0;
    flex-wrap: wrap;
    align-content: center;
  }

  .reaction-control {
    position: static;
  }

  .reaction-palette {
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: max(96px, calc(env(safe-area-inset-bottom) + 86px));
    width: auto;
    max-height: min(64vh, 400px);
    overflow-y: auto;
    transform: none;
  }

  .emoji-option {
    min-height: 48px;
    font-size: 28px;
  }

  .chat-composer {
    padding-bottom: 2px;
  }

  .reaction-bubble {
    left: max(14px, env(safe-area-inset-left));
    max-width: calc(100vw - 28px);
  }

  .reaction-bubble-avatar {
    width: 38px;
    height: 38px;
    border-width: 2px;
    font-size: 14px;
  }

  .reaction-bubble-name {
    max-width: 128px;
    font-size: 12px;
  }

  .reaction-bubble-label {
    max-width: min(226px, calc(100vw - 90px));
    padding: 12px 14px;
    font-size: 16px;
  }

  .reaction-bubble.emoji-reaction .reaction-bubble-label {
    font-size: 26px;
  }

  .ctrl-btn {
    padding: 8px 10px;
    font-size: 12px;
    gap: 3px;
    border-radius: 999px;
    white-space: nowrap;
    /* 确保手机上足够大的点击区域 */
    min-height: 44px;
    min-width: 44px;
  }

  .ctrl-btn .ui-icon {
    display: none;
  }

  #table-area {
    padding: 6px 8px;
    margin: 0;
    border-radius: 0;
  }

  #melds-container {
    gap: 5px;
    overflow-y: auto;
  }

  .meld-row {
    padding: 5px 5px 8px 5px;
    border-radius: 6px;
  }

  /* 手机端增加底部空间，防止触发系统手势 */
  #rack-area {
    padding: 6px 8px;
    padding-bottom: max(40px, calc(env(safe-area-inset-bottom) + 30px));
  }

  #rack {
    padding: 4px 6px;
    border-radius: 12px;
    gap: 3px;
  }

  .rack-touch-hint {
    display: block;
  }

  .empty-table-hint {
    font-size: 13px;
  }

  /* Overlay dialogs */
  .overlay {
    padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  }

  .modal-card {
    max-width: 100%;
    max-height: calc(100dvh - 24px);
    padding: 24px 18px;
    border-radius: 22px;
  }

  #win-screen .overlay-content {
    max-width: 100%;
    max-height: calc(100dvh - 24px);
    padding: 28px 24px;
    border-radius: 16px;
  }

  .modal-card::before {
    top: 12px;
    right: 16px;
    width: 48px;
    height: 48px;
  }

  .modal-card h2,
  #win-screen .overlay-content h2 {
    font-size: 24px;
  }

  .modal-card p {
    font-size: 14px;
  }

  .modal-actions,
  .resume-actions {
    grid-template-columns: 1fr;
    gap: 8px;
    margin-top: 18px;
  }

  .resume-session-meta {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  #win-screen h2 {
    font-size: 32px;
  }

  .winner-name {
    font-size: 22px;
  }

  .final-scores .score-row {
    font-size: 14px;
    padding: 6px 0;
  }

  .win-actions {
    grid-template-columns: 1fr;
  }

  #win-screen #btn-rematch,
  #win-screen #btn-restart {
    min-height: 44px;
    padding: 0 28px;
    font-size: 16px;
  }

  #toast {
    font-size: 13px;
    padding: 10px 20px;
    max-width: calc(100vw - 40px);
    white-space: normal;
    text-align: center;
  }
}

/* Very small phones (iPhone SE etc.) */
@media (max-width: 375px) {
  .player-tab {
    padding: 3px 6px;
    font-size: 10px;
  }

  .player-tab .player-name-wrapper {
    padding-right: 20px;
  }

  .player-tab .tile-count-badge {
    min-width: 16px;
    height: 16px;
    font-size: 9px;
    padding: 0 3px;
    top: -6px;
    right: -2px;
  }

  .ctrl-btn {
    padding: 6px 8px;
    font-size: 11px;
    min-height: 44px;
    min-width: 44px;
  }

  .ctrl-btn .ui-icon {
    display: none;
  }

  /* hide icons to save space */
}

/* Landscape phone */
@media (max-height: 500px) {
  :root {
    --tile-w: 42px;
    --tile-h: 58px;
    --tile-gap: 3px;
    --tile-font: 21px;
    --tile-mini-font: 8px;
  }

  #game-screen::before {
    inset: 4px;
    border-radius: 16px;
  }

  #header {
    padding: 5px 8px 2px;
    min-height: 34px;
    gap: 6px;
    padding-top: max(5px, env(safe-area-inset-top));
    padding-left: max(8px, env(safe-area-inset-left));
    padding-right: max(8px, env(safe-area-inset-right));
  }

  .player-tabs {
    flex: 1;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
    -webkit-overflow-scrolling: touch;
  }

  .player-tabs::-webkit-scrollbar {
    display: none;
  }

  .player-tab {
    padding: 3px 6px;
    font-size: 10px;
  }

  .player-tab .player-name-wrapper {
    padding-right: 20px;
  }

  .player-tab .tile-count-badge {
    min-width: 16px;
    height: 16px;
    font-size: 9px;
    padding: 0 3px;
    top: -6px;
    right: -2px;
  }

  .game-info {
    gap: 6px;
    font-size: 11px;
  }

  .pool-count {
    min-height: 34px;
    padding: 2px 8px 2px 6px;
    gap: 5px;
  }

  .pool-icon {
    width: 28px;
    height: 32px;
    font-size: 12px;
  }

  .pool-count-label {
    font-size: 11px;
  }

  #timer-bar-container {
    height: 3px;
    margin: 0;
  }

  #controls {
    padding: 2px 8px;
    gap: 6px;
    margin: 0;
    border-radius: 0;
  }

  .ctrl-btn {
    padding: 5px 9px;
    font-size: 11px;
    white-space: nowrap;
    min-height: 44px;
    min-width: 44px;
  }

  .ctrl-btn .ui-icon {
    display: none;
  }

  /* 横屏手机以两行紧凑手牌展示，避免横向滚动不明显，也减少挤占牌桌高度 */
  #rack-area {
    padding: 3px 8px 6px;
    padding-bottom: max(6px, env(safe-area-inset-bottom));
  }

  #rack {
    flex-wrap: wrap;
    justify-content: center;
    align-content: center;
    overflow: hidden;
    padding: 3px 6px;
    min-height: calc(var(--tile-h) + 8px);
    max-height: calc(var(--tile-h) * 2 + var(--tile-gap) + 8px);
  }

  .rack-touch-hint {
    display: none;
  }

  #table-area {
    min-height: 0;
    padding: 3px 8px;
    margin: 0;
    border-radius: 0;
  }
}
