/* ===== Guofeng theme tokens ===== */
:root {
  --ink: #2a1c12;
  --ink-soft: #5a4030;
  --paper: #f0e2c4;
  --paper-deep: #e4d0a8;
  --board: #d9b57a;
  --line: #5a3a22;
  --red: #a31d16;
  --black: #1a1a1a;
  --bronze: #8a6a3a;
  --bronze-light: #c4a574;
  --accent: #7a4e1e;
  --accent-2: #a8451c;
  --panel: rgba(246, 236, 214, 0.88);
  --panel-border: rgba(90, 58, 34, 0.28);
  --shadow: 0 14px 40px rgba(40, 20, 8, 0.28);
  --radius: 14px;
  --font: "Be Vietnam Pro", sans-serif;
  --piece: "Noto Serif SC", "Songti SC", serif;
  --display: "Ma Shan Zheng", "Noto Serif SC", serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: #dcc9a0;
}

.app-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
  background-color: #dcc9a0;
}

.app-bg::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(1200px, 100%);
  height: 100%;
  background: url("/assets/background.png") top center / 120% auto no-repeat;
}

.app {
  width: min(1200px, 100%);
  margin: 0 auto;
  padding: 18px 16px 48px;
  position: relative;
  z-index: 1;
}

.app:has(#table:not([hidden])) .top {
  opacity: 0.92;
  margin-bottom: 10px;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  padding: 10px 14px;
  border-radius: 14px;
  background: rgba(246, 236, 214, 0.72);
  border: 1px solid var(--panel-border);
  box-shadow: 0 8px 24px rgba(40, 20, 8, 0.12);
  backdrop-filter: blur(6px);
  position: relative;
  z-index: 100;
  overflow: visible;
}

.brand-link {
  display: flex;
  gap: 14px;
  align-items: center;
  color: inherit;
  text-decoration: none;
}

a.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

a.home-opt {
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: var(--display);
  font-size: 30px;
  color: #f8ecd2;
  background:
    radial-gradient(circle at 30% 25%, #c45c3a, transparent 45%),
    linear-gradient(145deg, var(--red), #6e100c);
  border: 2px solid var(--bronze-light);
  box-shadow: var(--shadow);
}

.brand h1 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(1.7rem, 3.5vw, 2.2rem);
  font-weight: 400;
  letter-spacing: 0.04em;
  color: var(--ink);
  line-height: 1.1;
}

.brand p {
  margin: 2px 0 0;
  opacity: 0.72;
  font-size: 0.88rem;
}

@media (max-width: 640px) {
  .brand-link > div {
    display: none;
  }

  .brand-link {
    gap: 0;
  }
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(255,255,255,0.45);
  border: 1px solid rgba(90,58,34,0.2);
  font-size: 0.85rem;
  font-weight: 600;
}

.pill.warn { color: #8a4b00; background: #ffe8b8; }
.pill.ok { color: #0f5132; background: #d1e7dd; }

#connStatus {
  position: fixed;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(10px, env(safe-area-inset-bottom));
  left: auto;
  z-index: 40;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent !important;
  box-shadow: none;
  color: inherit !important;
  opacity: 0.3;
  font-size: 0.78rem;
  font-weight: 500;
  text-align: right;
  pointer-events: none;
}

.panel, .meta {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  position: relative;
}

.panel-seal {
  position: absolute;
  top: 14px;
  right: 14px;
  opacity: 0.85;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

.home, .lobby {
  max-width: 480px;
  margin: 40px auto 0;
  padding: 28px;
  animation: rise 0.55s ease both;
}

.home-shell {
  max-width: 480px;
  width: 100%;
  margin: 40px auto 0;
  animation: rise 0.55s ease both;
}

.home-shell .home {
  margin: 0;
  max-width: none;
  width: 100%;
  animation: none;
}

.home {
  padding: 36px 32px 40px;
  min-height: 560px;
}

.lobby-wrap {
  display: grid;
  grid-template-columns: minmax(280px, 420px) minmax(260px, 1fr);
  gap: 18px;
  align-items: start;
  margin: 40px auto 0;
  width: min(900px, 100%);
  animation: rise 0.55s ease both;
}

.lobby-wrap .lobby {
  margin: 0;
  max-width: none;
  width: 100%;
}

.room-list-panel {
  padding: 22px;
  min-height: 280px;
}

.room-list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.room-list-head h2 {
  margin: 0;
  font-size: 1.2rem;
  font-family: var(--piece);
}

.room-refresh-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  flex-shrink: 0;
}

.room-refresh-btn .icon-refresh {
  display: block;
}

.room-list {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  display: grid;
  gap: 8px;
  max-height: 420px;
  overflow: auto;
}

.room-list-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  align-items: center;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid rgba(90, 58, 34, 0.22);
  background: rgba(255, 247, 230, 0.85);
  cursor: pointer;
  text-align: left;
  font: inherit;
  width: 100%;
}

.room-list-item:hover {
  border-color: rgba(168, 69, 28, 0.45);
  background: #fffaf0;
}

.room-list-item:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.room-list-owner { font-weight: 700; }

.room-list-meta {
  font-size: 0.85rem;
  opacity: 0.75;
}

.room-list-code {
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--accent-2);
}

.room-list-empty {
  margin: 16px 0 0;
  opacity: 0.7;
  font-size: 0.92rem;
}

.room-list-empty[hidden] { display: none; }

@media (max-width: 760px) {
  .lobby-wrap { grid-template-columns: 1fr; }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

.home h2, .lobby h2 {
  margin: 0 0 8px;
  font-size: 1.45rem;
  font-family: var(--piece);
}

.home-lead {
  margin: 0 0 28px;
  opacity: 0.75;
  font-size: 0.95rem;
}

.home-options { display: grid; gap: 14px; }

.home-opt {
  display: grid;
  gap: 4px;
  text-align: left;
  border: 1px solid rgba(90,58,34,0.25);
  background:
    linear-gradient(145deg, rgba(255,250,236,0.95), rgba(240,220,180,0.9));
  border-radius: 12px;
  padding: 22px 18px;
  font: inherit;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.35);
}

.home-opt:hover {
  transform: translateY(-2px);
  border-color: rgba(168,69,28,0.5);
  box-shadow: 0 10px 24px rgba(90, 40, 10, 0.16);
}

.home-opt-title {
  font-weight: 700;
  font-size: 1.45rem;
  line-height: 1.25;
  font-family: var(--piece);
}

.home-opt-desc {
  font-size: 0.9rem;
  opacity: 0.7;
}

.home-opt-elo {
  margin-top: 4px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--accent-2);
}

.home-opt-elo[hidden] { display: none !important; }

.home-online {
  margin: 28px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--panel-border);
  text-align: center;
  font-size: 0.95rem;
  color: var(--muted, #6b5c50);
}

.home-online strong {
  color: var(--ink);
  font-weight: 700;
}

.home-donate {
  margin: 10px 4px 0 0;
  text-align: right;
}

.home-donate-link {
  border: 0;
  background: transparent;
  padding: 0;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--accent-2);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.home-donate-link:hover {
  filter: brightness(1.08);
}

.donate-modal-card {
  text-align: center;
  max-width: 360px;
}

.donate-qr {
  display: block;
  width: min(280px, 72vw);
  height: auto;
  margin: 8px auto 0;
  border-radius: 12px;
  background: #fff;
}

.leaderboard {
  max-width: 640px;
  margin: 40px auto 0;
  padding: 32px 28px 36px;
  animation: rise 0.55s ease both;
}

.leader-boards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 8px 0 0;
}

.leader-col h3 {
  margin: 0 0 10px;
  font-size: 1.05rem;
  font-family: var(--piece);
}

.leader-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
  max-height: min(520px, 58vh);
  overflow: auto;
}

.leader-item {
  display: grid;
  grid-template-columns: 28px 36px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 250, 236, 0.85);
  border: 1px solid rgba(90, 58, 34, 0.16);
}

.leader-item.is-clickable {
  cursor: pointer;
}

.leader-item.is-clickable:hover {
  filter: brightness(1.03);
  border-color: rgba(168, 69, 28, 0.35);
}

.leader-rank {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--accent-2);
}

.leader-item .avatar {
  width: 36px;
  height: 36px;
  font-size: 0.8rem;
}

.leader-meta {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.leader-name {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leader-level {
  font-size: 0.75rem;
  font-weight: 650;
  opacity: 0.72;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leader-elo {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.leader-empty {
  margin: 0;
  opacity: 0.65;
  font-size: 0.9rem;
}

.leader-lookup {
  margin: 4px 0 16px;
}

.leader-lookup-result {
  margin: -4px 0 16px;
  padding: 14px 16px;
  border-radius: 12px;
  background: rgba(255, 250, 236, 0.9);
  border: 1px solid rgba(90, 58, 34, 0.18);
  display: grid;
  gap: 8px;
}

.leader-lookup-result[hidden] {
  display: none !important;
}

.leader-lookup-user {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
}

.leader-lookup-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.leader-lookup-stat {
  display: grid;
  gap: 2px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.45);
  border: 1px solid rgba(90, 58, 34, 0.12);
  font-size: 0.92rem;
}

.leader-lookup-stat strong {
  color: var(--accent-2);
  font-variant-numeric: tabular-nums;
}

.leader-lookup-stat small {
  opacity: 0.72;
  font-size: 0.78rem;
  font-weight: 600;
}

.leader-lookup-level {
  color: var(--accent-2);
  opacity: 0.9 !important;
}

@media (max-width: 640px) {
  .leader-boards {
    grid-template-columns: 1fr;
  }
}

.back-link {
  border: 0;
  background: transparent;
  color: var(--accent-2);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  padding: 0;
  margin: 0 0 14px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.back-link img {
  width: 36px;
  height: 36px;
  object-fit: contain;
  filter: drop-shadow(0 2px 4px rgba(40, 20, 8, 0.25));
}

.back-link.auth-back {
  margin: 10px 0 0;
}

.back-link.auth-back img {
  width: 28px;
  height: 28px;
}

.lobby-title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 18px;
}

.lobby h2 {
  margin: 0;
}

.lobby-user-name {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted, #6b5c50);
  max-width: 45%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lobby-user-name[hidden] {
  display: none;
}

label {
  display: grid;
  gap: 8px;
  font-size: 0.92rem;
  font-weight: 600;
  margin-bottom: 16px;
}

input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid rgba(90,58,34,0.28);
  background: rgba(255, 250, 240, 0.92);
  font: inherit;
  color: inherit;
}

input:focus {
  outline: 2px solid rgba(168, 69, 28, 0.35);
  border-color: var(--accent-2);
}

.mode-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 18px;
}

.mode {
  border: 1px solid rgba(90,58,34,0.22);
  background: #fff7e6;
  border-radius: 12px;
  padding: 14px 10px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}

.mode:hover { transform: translateY(-1px); }
.mode.active {
  background: linear-gradient(145deg, var(--accent-2), #7a2a10);
  color: #fff8ef;
  border-color: transparent;
}

.actions { display: grid; gap: 12px; }
.play-actions-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.match-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--panel) 88%, var(--accent, #b4532a) 12%);
}
.match-status[hidden] { display: none; }
.match-status p {
  margin: 0;
  font-size: 0.95rem;
}

.match-overlay {
  z-index: 320;
}
.match-overlay[hidden] {
  display: none !important;
}
.match-overlay-card {
  width: min(360px, calc(100vw - 40px));
  text-align: center;
  display: grid;
  gap: 18px;
  justify-items: center;
  padding: 28px 24px 24px;
}
.match-overlay-text {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  font-family: var(--piece);
  color: var(--ink);
}
.match-overlay-card .btn {
  min-width: 140px;
}
.join-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }

.btn {
  border: 1px solid rgba(90,58,34,0.28);
  background: linear-gradient(180deg, #fff6e4, #edd7ad);
  color: var(--ink);
  border-radius: 10px;
  padding: 12px 16px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.45);
}

.btn:hover:not(:disabled) { filter: brightness(1.03); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn.primary {
  background: linear-gradient(145deg, var(--accent-2), #7a2410);
  color: #fff8ef;
  border-color: rgba(90, 30, 10, 0.35);
}

.btn.danger {
  background: linear-gradient(145deg, #c0392b, #8e1e14);
  color: #fff5f3;
  border-color: transparent;
}

.btn.ghost {
  background: rgba(255, 248, 230, 0.55);
}

.error {
  color: #9b1c1c;
  background: #fde8e8;
  border: 1px solid #f5c2c2;
  border-radius: 10px;
  padding: 10px 12px;
  margin: 12px 0 0;
  font-size: 0.92rem;
}

.rules {
  margin-top: 18px;
  font-size: 0.9rem;
  opacity: 0.9;
}

.rules ul { padding-left: 18px; margin: 8px 0 0; }

/* ===== Game table ===== */
.table {
  display: grid;
  gap: 12px;
  width: min(1100px, 100%);
  margin: 0 auto;
  animation: rise 0.45s ease both;
}

.table-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px 14px;
  text-align: center;
  padding: 4px 8px 2px;
}

.table-title-zh {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(2rem, 5vw, 2.8rem);
  font-weight: 400;
  letter-spacing: 0.12em;
  color: var(--ink);
  line-height: 1;
}

.table-seal {
  filter: drop-shadow(0 2px 4px rgba(120, 20, 10, 0.35));
}

.table-title-sub {
  width: 100%;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 0.92rem;
  color: var(--ink-soft);
}

.viewer-count {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
  background: rgba(90, 58, 34, 0.08);
  border: 1px solid rgba(90, 58, 34, 0.14);
}

.viewer-count[hidden] {
  display: none !important;
}

.viewer-eye {
  flex-shrink: 0;
  opacity: 0.85;
}

.table-stage {
  display: grid;
  grid-template-columns: minmax(120px, 156px) minmax(0, 620px) minmax(220px, 280px);
  gap: 14px;
  align-items: stretch;
  justify-content: center;
}

.table-players {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-self: start;
  height: var(--board-h, 100%);
  min-height: var(--board-h, 100%);
  gap: 18px;
  padding-top: 34px;
  padding-bottom: 0;
}

.table-players .player-rail {
  width: 100%;
}

.table-players .seat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  padding: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
  color: #f3e6c8;
}

.table-players .seat-card {
  position: relative;
  display: flex;
  width: 100%;
  max-width: 156px;
  height: 128px;
  box-sizing: border-box;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 2px;
  padding: 34px 8px 8px;
  border-radius: 0 0 14px 14px;
  border: 1px solid rgba(196, 165, 116, 0.4);
  box-shadow: 0 12px 28px rgba(20, 10, 4, 0.38);
  text-align: center;
  overflow: visible;
}

.table-players .seat[data-color="black"] .seat-card {
  background:
    linear-gradient(180deg, rgba(58, 52, 48, 0.98), rgba(32, 28, 26, 0.98));
}

.table-players .seat[data-color="red"] .seat-card {
  background:
    linear-gradient(180deg, rgba(110, 42, 32, 0.96), rgba(62, 22, 16, 0.98));
  border-color: rgba(196, 120, 90, 0.45);
}

.table-players .seat-info {
  text-align: center !important;
  width: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1px;
}

.table-players .seat strong {
  color: #fff8e8;
  font-size: 0.95rem;
  line-height: 1.2;
}

.table-players .seat-elo {
  color: #d8c09a;
  min-height: 0;
  font-size: 0.8rem;
}

.table-players .seat-elo.elo-up {
  color: #8fd4a0;
}

.table-players .seat-elo.elo-down {
  color: #e8a090;
}

.table-players .seat-elo[hidden] {
  display: none !important;
}

.table-players .seat-timer-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  margin-top: auto;
  padding: 4px 6px;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(20, 14, 10, 0.75), rgba(10, 8, 6, 0.88));
  border: 1px solid rgba(196, 165, 116, 0.35);
  box-shadow: inset 0 1px 0 rgba(255, 240, 200, 0.08);
  flex-shrink: 0;
}

.table-players .seat-timer-row.active {
  border-color: rgba(196, 165, 116, 0.35);
  box-shadow: inset 0 1px 0 rgba(255, 240, 200, 0.08);
}

.table-players .seat-timer-row.urgent {
  border-color: rgba(220, 60, 40, 0.65);
}

.table-players .seat.turn-glow .seat-timer {
  color: #f3e0b8;
  background: transparent;
  border: 0;
}

.table-players .seat-timer.urgent {
  color: #ffb4a4;
  background: transparent !important;
  border: 0 !important;
  animation: timer-pulse 0.7s ease infinite;
}

.table-players .seat-timer-icon {
  display: block;
  width: 20px;
  height: 20px;
  object-fit: contain;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.4));
  flex-shrink: 0;
}

.table-players .seat-timer {
  margin: 0;
  min-width: 2.6em;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #f3e0b8;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: 0.98rem;
  letter-spacing: 0.02em;
}

.table-players .seat-timer.urgent {
  color: #ffb4a4;
  animation: timer-pulse 0.7s ease infinite;
}

.table-players .seat-hang {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: -2px;
}

.table-players .seat-chain {
  display: block;
  width: 2px;
  height: 14px;
  background: linear-gradient(180deg, #c4a574, #6a5230);
  border-radius: 1px;
  box-shadow: 0 0 0 1px rgba(40, 20, 8, 0.25);
}

.table-players .seat-banner {
  width: 72px;
  height: auto;
  margin-top: 0;
  filter: drop-shadow(0 8px 12px rgba(0, 0, 0, 0.4));
}

.table-players .seat.turn-glow .seat-card {
  border-color: #e0b000;
  box-shadow:
    0 0 0 2px rgba(224, 176, 0, 0.35),
    0 14px 30px rgba(0, 0, 0, 0.4);
  animation: seat-turn-pulse 2.8s ease-in-out infinite;
}

.table-players .seat.mine .seat-card {
  outline: 1px solid rgba(224, 176, 0, 0.28);
}

.table-players #playerRailTop .seat,
.table-players #playerRailBottom .seat {
  flex-direction: column;
}

.table-players .seat-avatar-wrap {
  position: absolute;
  top: -32px;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
}

.table-players .seat-avatar,
.table-players .seat-avatar-wrap {
  width: 64px;
  height: 64px;
}

.table-players .seat-avatar {
  font-size: 1rem;
  border-width: 2px;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.45);
}

.board-column {
  display: grid;
  justify-items: center;
  align-content: start;
  align-items: start;
  width: 100%;
  min-width: 0;
}

.table-side {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-self: start;
  box-sizing: border-box;
  height: var(--board-h, auto);
  min-height: 0;
  max-height: var(--board-h, none);
  min-width: 0;
  overflow: hidden;
}

.meta-status {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.meta {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-self: stretch;
  box-sizing: border-box;
  height: 0;
  min-height: 100%;
  max-height: 100%;
  overflow: hidden;
  order: initial;
}

.hint {
  margin: 0;
  font-size: 0.82rem;
  opacity: 0.78;
  line-height: 1.4;
}

.tool-rail {
  display: grid;
  gap: 10px;
  justify-items: center;
}

.tool-btn {
  width: 72px;
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
  display: grid;
  gap: 4px;
  justify-items: center;
  font: inherit;
  color: var(--ink-soft);
}

.tool-btn img {
  width: 56px;
  height: 56px;
  object-fit: contain;
  filter: drop-shadow(0 4px 8px rgba(40,20,8,0.28));
  transition: transform 0.15s ease;
}

.tool-btn:hover img { transform: translateY(-2px) scale(1.04); }

.tool-btn span {
  font-size: 0.75rem;
  font-weight: 700;
}

.table-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 16px;
  padding: 20px 0 72px;
}

.btn-art {
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
  line-height: 0;
}

.btn-art img {
  display: block;
  height: 48px;
  width: auto;
  filter: drop-shadow(0 6px 12px rgba(40, 20, 8, 0.3));
  transition: transform 0.15s ease, filter 0.15s ease;
}

#btnDraw.offer-incoming img {
  filter:
    drop-shadow(0 6px 12px rgba(40, 20, 8, 0.3))
    drop-shadow(0 0 10px rgba(224, 176, 0, 0.65));
  animation: draw-offer-pulse 1.1s ease-in-out infinite;
}

#btnDraw.pending-offer {
  opacity: 0.55;
}

.btn-switch-color {
  min-height: 48px;
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  border: 2px solid rgba(90, 58, 34, 0.55);
  background:
    linear-gradient(180deg, #f0d7a8 0%, #d4a86a 55%, #c08a4a 100%);
  box-shadow:
    0 6px 12px rgba(40, 20, 8, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.35);
  font-family: var(--piece);
  font-size: 1rem;
  font-weight: 700;
  color: #5a2e12;
  letter-spacing: 0.02em;
  line-height: 1;
  transition: transform 0.15s ease, filter 0.15s ease, opacity 0.15s ease;
}

.btn-switch-color span {
  pointer-events: none;
  white-space: nowrap;
}

.btn-switch-color:hover:not(:disabled) {
  transform: translateY(-2px);
  filter: brightness(1.05);
}

.btn-switch-color.pending-offer {
  opacity: 0.55;
}

.btn-switch-color.offer-incoming {
  animation: draw-offer-pulse 1.1s ease-in-out infinite;
  box-shadow:
    0 6px 12px rgba(40, 20, 8, 0.28),
    0 0 10px rgba(224, 176, 0, 0.65),
    inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

@keyframes draw-offer-pulse {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-2px) scale(1.06); }
}

.btn-art:hover:not(:disabled) img {
  transform: translateY(-2px);
  filter: drop-shadow(0 10px 16px rgba(40, 20, 8, 0.38)) brightness(1.05);
}

.btn-art:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-art[hidden] { display: none !important; }

.room-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.linkish {
  border: 0;
  background: transparent;
  color: var(--accent-2);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  text-decoration: underline;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid rgba(90, 58, 34, 0.22);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.45);
  color: var(--accent-2);
  cursor: pointer;
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    color 0.15s ease,
    transform 0.15s ease;
}

.icon-btn:hover {
  background: rgba(168, 69, 28, 0.12);
  border-color: rgba(168, 69, 28, 0.4);
  transform: translateY(-1px);
}

.icon-btn:focus-visible {
  outline: 2px solid rgba(168, 69, 28, 0.4);
  outline-offset: 2px;
}

.icon-btn.copied {
  color: #0f5132;
  background: #d1e7dd;
  border-color: #a3cfbb;
}

.icon-btn .icon-check[hidden],
.icon-btn .icon-copy[hidden] {
  display: none !important;
}

.room-chat {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  gap: 8px;
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
  max-height: none;
  box-sizing: border-box;
  padding: 0;
  border-radius: 0;
  background: transparent;
  border: 0;
  min-width: 0;
  overflow: hidden;
}

.room-chat-toolbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.room-chat-title {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.room-chat-close {
  border: 0;
  background: rgba(90, 58, 34, 0.1);
  color: inherit;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

.room-chat-close:hover {
  background: rgba(90, 58, 34, 0.18);
}

.seat-chat-btn,
.chat-popup-backdrop {
  display: none;
}

.room-chat-log {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  padding: 8px;
  padding-right: 2px;
  border-radius: 10px;
  background: rgba(255, 252, 245, 0.72);
  border: 1px solid rgba(90, 58, 34, 0.12);
}

.chat-empty {
  margin: auto 0;
  font-size: 0.85rem;
  opacity: 0.55;
  text-align: center;
}

.chat-msg {
  display: grid;
  gap: 2px;
  padding: 4px 0;
  border-radius: 0;
  background: transparent;
  border: 0;
  font-size: 0.88rem;
  word-break: break-word;
}

.chat-msg.mine {
  background: transparent;
  border: 0;
}

.chat-msg .chat-name { font-weight: 700; }
.chat-msg[data-color="red"] .chat-name { color: var(--red); }
.chat-msg[data-color="black"] .chat-name { color: var(--black); }
.chat-msg[data-color="spectator"] .chat-name { color: #5a4a38; }

.chat-msg .chat-text {
  line-height: 1.35;
  white-space: pre-wrap;
  color: var(--ink);
}

.chat-msg .chat-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.72rem;
  opacity: 0.85;
  color: var(--ink-soft);
}

.chat-msg.icons-only .chat-text {
  font-size: 1.65rem;
  line-height: 1.2;
  letter-spacing: 0.04em;
}

.room-chat-compose {
  display: grid;
  gap: 6px;
  min-width: 0;
  position: relative;
}

.chat-icon-panel {
  max-height: 132px;
  overflow-y: auto;
  padding: 6px;
  border-radius: 12px;
  background: rgba(255, 248, 230, 0.95);
  border: 1px solid rgba(90, 58, 34, 0.16);
  box-shadow: 0 8px 20px rgba(40, 20, 8, 0.12);
  color: var(--ink);
}

.chat-icon-panel[hidden] { display: none !important; }

.chat-quick-panel {
  max-height: 168px;
  overflow-y: auto;
  padding: 6px;
  border-radius: 12px;
  background: rgba(255, 248, 230, 0.95);
  border: 1px solid rgba(90, 58, 34, 0.16);
  box-shadow: 0 8px 20px rgba(40, 20, 8, 0.12);
  color: var(--ink);
}

.chat-quick-panel[hidden] { display: none !important; }

.chat-icon-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 2px;
}

.chat-quick-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.chat-icon-pick {
  appearance: none;
  border: 0;
  background: transparent;
  border-radius: 8px;
  padding: 4px 0;
  font-size: 1.25rem;
  line-height: 1.2;
  color: var(--ink);
  cursor: pointer;
}

.chat-quick-pick {
  appearance: none;
  border: 1px solid rgba(90, 58, 34, 0.14);
  background: rgba(255, 252, 245, 0.96);
  border-radius: 8px;
  padding: 7px 8px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.25;
  text-align: left;
  color: var(--ink);
  cursor: pointer;
}

.chat-icon-pick:hover,
.chat-icon-pick:focus-visible,
.chat-quick-pick:hover,
.chat-quick-pick:focus-visible {
  background: rgba(168, 69, 28, 0.12);
  outline: none;
}

.chat-quick-pick:hover,
.chat-quick-pick:focus-visible {
  border-color: rgba(168, 69, 28, 0.35);
}

.room-chat-form {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  gap: 6px;
  min-width: 0;
  align-items: center;
}

.room-chat-form input {
  width: 100%;
  min-width: 0;
  margin: 0;
  padding: 8px 10px;
  font-size: 0.9rem;
  color: var(--ink);
  background: rgba(255, 250, 240, 0.96);
  caret-color: var(--ink);
}

.room-chat-form input::placeholder {
  color: var(--ink-soft);
  opacity: 0.72;
}

.room-chat-form #btnChatSend {
  grid-column: 1 / -1;
  width: 100%;
  padding: 8px 12px;
}

.room-chat-form .btn {
  padding: 8px 12px;
  white-space: nowrap;
}

.chat-icon-btn {
  min-width: 38px;
  padding: 8px 0;
  font-size: 1.15rem;
  line-height: 1;
}

.chat-quick-btn {
  font-size: 0.92rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.player-rail { width: 100%; }

.seat {
  display: flex;
  gap: 12px;
  align-items: center;
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(255, 248, 230, 0.88);
  border: 2px solid rgba(90, 58, 34, 0.14);
  box-shadow: 0 8px 22px rgba(40, 20, 8, 0.12);
  transition:
    border-color 0.2s ease,
    background 0.2s ease,
    box-shadow 0.2s ease,
    transform 0.2s ease;
}

.seat.mine { border-color: rgba(168, 69, 28, 0.35); }

.seat.turn-glow {
  border-color: #e0b000;
  transform: translateY(-1px);
}

@keyframes seat-turn-pulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(224, 176, 0, 0.22), 0 10px 28px rgba(0,0,0,0.28); }
  50% { box-shadow: 0 0 0 3px rgba(224, 176, 0, 0.4), 0 12px 30px rgba(0,0,0,0.32); }
}

.seat-info { flex: 1; min-width: 0; }

.seat small {
  display: block;
  opacity: 0.65;
  font-size: 0.78rem;
  letter-spacing: 0.02em;
}

.seat strong {
  display: block;
  font-size: 1.05rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.seat-elo {
  display: block;
  margin-top: 2px;
  font-size: 0.8rem;
  font-weight: 600;
  opacity: 0.75;
}

.seat-elo[hidden] { display: none !important; }

.seat-timer {
  flex-shrink: 0;
  min-width: 3.2em;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--accent-2);
  background: rgba(168, 69, 28, 0.12);
  border: 1px solid rgba(168, 69, 28, 0.28);
  border-radius: 10px;
  padding: 8px 10px;
  line-height: 1;
}

.seat.turn-glow .seat-timer {
  color: #8a6500;
  background: rgba(255, 230, 100, 0.55);
  border-color: #e0b000;
}

.seat-timer.urgent {
  color: #9b1c1c !important;
  background: rgba(253, 232, 232, 0.98) !important;
  border-color: #f5c2c2 !important;
  animation: timer-pulse 0.7s ease infinite;
}

.seat-timer[hidden] { display: none !important; }

.seat-card,
.seat-hang {
  display: contents;
}

.seat-chain,
.seat-timer-icon {
  display: none;
}

.seat-timer-row {
  display: contents;
}

@keyframes timer-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

.dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.35);
}
.dot.red { background: var(--red); }
.dot.black { background: var(--black); }

.seat-avatar-wrap {
  position: relative;
  flex-shrink: 0;
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  overflow: visible;
  --turn-progress: 1;
}

.seat-avatar-ring {
  display: none;
  position: absolute;
  inset: 0;
  border-radius: 50%;
  pointer-events: none;
  z-index: 2;
}

.seat.turn-glow .seat-avatar-ring { display: block; }

.seat.turn-glow .seat-avatar-ring::before {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: 50%;
  background: conic-gradient(
    from -90deg,
    #f0c419 0deg,
    #ffe566 calc(var(--turn-progress) * 360deg),
    rgba(90, 58, 34, 0.1) calc(var(--turn-progress) * 360deg)
  );
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3px));
  transition: background 0.2s linear;
}

.seat.turn-glow .seat-avatar-ring::after {
  content: "";
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  background: conic-gradient(
    from 0deg,
    transparent 0deg,
    transparent 200deg,
    rgba(240, 196, 25, 0.2) 250deg,
    #f0c419 300deg,
    #ffe566 335deg,
    transparent 360deg
  );
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2px));
  filter: drop-shadow(0 0 4px rgba(240, 196, 25, 0.45));
  animation: avatar-border-spin 3.8s linear infinite;
}

.seat.turn-glow.urgent-turn .seat-avatar-ring::before {
  background: conic-gradient(
    from -90deg,
    #d9480f 0deg,
    #ff922b calc(var(--turn-progress) * 360deg),
    rgba(90, 58, 34, 0.1) calc(var(--turn-progress) * 360deg)
  );
}

.seat.turn-glow.urgent-turn .seat-avatar-ring::after {
  background: conic-gradient(
    from 0deg,
    transparent 0deg,
    transparent 200deg,
    rgba(255, 146, 43, 0.2) 250deg,
    #ff922b 300deg,
    #d9480f 335deg,
    transparent 360deg
  );
  filter: drop-shadow(0 0 5px rgba(217, 72, 15, 0.5));
  animation-duration: 2.2s;
}

@keyframes avatar-border-spin {
  to { transform: rotate(360deg); }
}

@keyframes avatar-turn-pulse {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 0 0 rgba(240, 196, 25, 0)); }
  50% { transform: scale(1.06); filter: drop-shadow(0 0 8px rgba(240, 196, 25, 0.55)); }
}

.seat-avatar,
.avatar {
  position: relative;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 50%;
  background: linear-gradient(145deg, #c45c26, #8a3a12);
  color: #fff8e7;
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 0.02em;
  background-size: cover;
  background-position: center;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.35);
  z-index: 1;
}

.seat-avatar {
  width: 56px;
  height: 56px;
  font-size: 0.9rem;
  border: 2px solid var(--bronze-light);
}

.seat-avatar-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.seat-avatar-img[hidden],
.seat-avatar-initials[hidden] {
  display: none !important;
}

.seat-avatar-initials {
  position: relative;
  z-index: 1;
  line-height: 1;
}

.seat[data-color="red"] .seat-avatar {
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.2), 0 0 0 2px rgba(180, 35, 24, 0.45);
}

.seat[data-color="black"] .seat-avatar {
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.2), 0 0 0 2px rgba(26, 26, 26, 0.45);
  background: linear-gradient(145deg, #3a3a3a, #1a1a1a);
}

.seat.turn-glow .seat-avatar {
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.35), 0 0 0 2px rgba(224, 176, 0, 0.65);
  animation: avatar-turn-pulse 1.6s ease-in-out infinite;
}

.seat.turn-glow.urgent-turn .seat-avatar {
  animation-duration: 0.7s;
}

.avatar {
  width: 36px;
  height: 36px;
}

.avatar-lg {
  width: 88px;
  height: 88px;
  font-size: 1.4rem;
}

.avatar.has-image,
.seat-avatar.has-image {
  color: transparent;
}

.sound-menu {
  position: relative;
  z-index: 1;
}

.lang-menu {
  position: relative;
  z-index: 1;
}

.lang-popover {
  width: min(200px, 70vw);
  gap: 8px;
}

.lang-popover-title {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink, #3a2415);
  opacity: 0.75;
}

.lang-option {
  display: flex;
  align-items: center;
  width: 100%;
  border: 1px solid rgba(90, 58, 34, 0.18);
  background: rgba(255, 248, 230, 0.9);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  font-weight: 600;
  color: var(--ink, #3a2415);
  cursor: pointer;
  text-align: left;
}

.lang-option:hover {
  background: rgba(168, 69, 28, 0.1);
}

.lang-option[aria-pressed="true"] {
  border-color: rgba(168, 69, 28, 0.45);
  background: rgba(168, 69, 28, 0.14);
  box-shadow: inset 0 0 0 1px rgba(168, 69, 28, 0.2);
}

.lang-menu.open .lang-btn {
  background: rgba(168, 69, 28, 0.1);
}

.sound-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(90, 58, 34, 0.22);
  background: rgba(255, 248, 230, 0.75);
  border-radius: 999px;
  color: var(--ink, #3a2415);
  cursor: pointer;
  padding: 0;
}

a.sound-btn {
  text-decoration: none;
  box-sizing: border-box;
}

.sound-btn:hover,
.sound-menu.open .sound-btn {
  background: rgba(168, 69, 28, 0.1);
}

.sound-btn-icon {
  display: block;
}

.sound-menu.is-muted .sound-icon-wave {
  display: none;
}

.sound-menu.is-muted .sound-icon-mute {
  display: block;
}

.sound-menu:not(.is-muted) .sound-icon-mute {
  display: none;
}

.sound-menu.vol-low .sound-icon-wave-2 {
  opacity: 0.28;
}

.sound-popover {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: min(240px, 72vw);
  display: grid;
  gap: 14px;
  padding: 14px;
  background: rgba(246, 236, 214, 0.98);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 200;
}

.sound-popover[hidden] {
  display: none !important;
}

.sound-popover-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.sound-popover-volume {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}

.sound-popover-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink);
}

.sound-switch {
  position: relative;
  display: inline-flex;
  width: 44px;
  height: 26px;
  cursor: pointer;
  flex-shrink: 0;
}

.sound-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.sound-switch-ui {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: rgba(90, 58, 34, 0.28);
  transition: background 0.15s ease;
}

.sound-switch-ui::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff8e6;
  box-shadow: 0 1px 3px rgba(40, 20, 8, 0.25);
  transition: transform 0.15s ease;
}

.sound-switch input:checked + .sound-switch-ui {
  background: var(--accent-2, #a8451c);
}

.sound-switch input:checked + .sound-switch-ui::after {
  transform: translateX(18px);
}

.sound-switch input:focus-visible + .sound-switch-ui {
  outline: 2px solid var(--accent, #7a4e1e);
  outline-offset: 2px;
}

.sound-volume-wrap {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
}

.sound-volume-wrap input[type="range"] {
  width: 100%;
  accent-color: var(--accent-2, #a8451c);
  cursor: pointer;
}

.sound-volume-value {
  min-width: 3.2em;
  text-align: right;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.sound-popover-volume.is-disabled {
  opacity: 0.45;
  pointer-events: none;
}

.friends-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(90, 58, 34, 0.22);
  background: rgba(255, 248, 230, 0.75);
  border-radius: 999px;
  color: var(--ink, #3a2415);
  cursor: pointer;
  padding: 0;
}

.friends-btn:hover {
  background: rgba(168, 69, 28, 0.1);
}

.friends-btn-icon {
  display: block;
}

.friends-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--red, #a8451c);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

#friendsModal {
  place-items: start center;
  align-content: start;
  padding-top: 56px;
  padding-bottom: 16px;
  overflow: auto;
}

.modal-card.friends-modal-card {
  width: min(720px, 96vw);
  min-height: min(72vh, 640px);
  max-height: min(88vh, 780px);
  display: flex;
  flex-direction: column;
  margin-top: 0;
}

.modal-card.friends-modal-card .friends-tab-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.modal-card.friends-modal-card #friendsList,
.modal-card.friends-modal-card #friendsRequestsList {
  max-height: none;
  flex: 1;
  min-height: 180px;
  align-content: start;
}

.modal-card.friends-modal-card .friends-list-compact {
  flex: 0 1 auto;
  min-height: 0;
  max-height: min(28vh, 220px);
  align-content: start;
}

.friends-tabs {
  display: flex;
  gap: 6px;
  margin: 0 0 14px;
}

.friends-tab {
  flex: 1;
  border: 1px solid rgba(90, 58, 34, 0.18);
  background: rgba(255, 248, 230, 0.55);
  border-radius: 10px;
  padding: 8px 6px;
  font: inherit;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  color: inherit;
}

.friends-tab.active {
  background: rgba(168, 69, 28, 0.14);
  border-color: rgba(168, 69, 28, 0.35);
}

.friends-tab-count {
  display: inline-block;
  min-width: 1.2em;
  margin-left: 2px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--red, #a8451c);
  color: #fff;
  font-size: 0.72rem;
  line-height: 1.35;
}

.friends-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  max-height: min(46vh, 360px);
  overflow: auto;
}

.friends-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid rgba(90, 58, 34, 0.14);
  border-radius: 12px;
  background: rgba(255, 248, 230, 0.45);
  flex: 0 0 auto;
}

.friends-row-main {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 2px;
}

.friends-row-name {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.friends-row-meta {
  font-size: 0.78rem;
  opacity: 0.75;
}

.friends-row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.friends-row-actions .btn {
  padding: 6px 10px;
  font-size: 0.82rem;
}

.friends-online-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #8a8a8a;
  flex-shrink: 0;
}

.friends-online-dot.on {
  background: #2f9e44;
}

.friends-empty {
  margin: 12px 0 0;
  opacity: 0.75;
  font-size: 0.92rem;
}

.friends-section-label {
  margin: 4px 0 8px;
  font-size: 0.82rem;
  font-weight: 700;
  opacity: 0.75;
}

.friends-search-section {
  flex: 0 0 auto;
  margin-bottom: 14px;
}

.friends-search-form {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

.friends-search-form > label {
  font-size: 0.88rem;
  font-weight: 600;
}

.friends-search-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.friends-search-row input {
  flex: 1;
  min-width: 0;
  height: 42px;
  box-sizing: border-box;
  font: inherit;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid rgba(90, 58, 34, 0.22);
  background: rgba(255, 252, 245, 0.95);
}

.friends-search-row .btn {
  height: 42px;
  box-sizing: border-box;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.friend-chat-card {
  width: min(420px, 100%);
  display: flex;
  flex-direction: column;
  max-height: min(80vh, 640px);
}

.friend-chat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.friend-chat-head h2 {
  margin: 0;
  font-size: 1.15rem;
}

.friend-chat-status {
  margin: 2px 0 0;
  font-size: 0.8rem;
  opacity: 0.75;
}

.friend-chat-log {
  flex: 1;
  min-height: 220px;
  max-height: 40vh;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid rgba(90, 58, 34, 0.14);
  background: rgba(255, 248, 230, 0.4);
  margin-bottom: 10px;
}

.friend-chat-bubble {
  max-width: 85%;
  padding: 8px 10px;
  border-radius: 12px;
  font-size: 0.92rem;
  line-height: 1.35;
  word-break: break-word;
}

.friend-chat-bubble.mine {
  align-self: flex-end;
  background: rgba(168, 69, 28, 0.16);
}

.friend-chat-bubble.theirs {
  align-self: flex-start;
  background: rgba(255, 252, 245, 0.95);
  border: 1px solid rgba(90, 58, 34, 0.12);
}

.friend-chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-bottom: 8px;
}

.friend-chat-form input {
  font: inherit;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(90, 58, 34, 0.22);
  background: rgba(255, 252, 245, 0.95);
}

.friend-chat-actions {
  display: flex;
  justify-content: flex-end;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(90, 58, 34, 0.22);
  background: rgba(255, 248, 230, 0.75);
  border-radius: 999px;
  padding: 4px 12px 4px 4px;
  font: inherit;
  cursor: pointer;
  color: inherit;
}

.user-chip-name {
  font-weight: 700;
  font-size: 0.92rem;
}

@media (max-width: 640px) {
  .user-chip {
    width: 42px;
    height: 42px;
    padding: 0;
    gap: 0;
    justify-content: center;
  }

  .user-chip .avatar {
    width: 34px;
    height: 34px;
  }

  .user-chip-name {
    display: none;
  }
}

.user-menu { position: relative; z-index: 1; }

.user-menu-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 240px;
  display: grid;
  gap: 4px;
  padding: 8px;
  background: rgba(246, 236, 214, 0.98);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 200;
}

.user-menu-dropdown[hidden] { display: none !important; }

.user-menu-item {
  border: 0;
  background: transparent;
  text-align: left;
  padding: 10px 12px;
  border-radius: 10px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  color: inherit;
}

.user-menu-item:hover { background: rgba(168, 69, 28, 0.1); }
.user-menu-item.danger { color: var(--red); }

.board-wrap {
  position: relative;
  width: min(100%, 600px);
  height: fit-content;
  align-self: start;
  border-radius: 12px;
  padding: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
  display: grid;
  place-items: center;
}

#board {
  width: 100%;
  height: auto;
  aspect-ratio: 992 / 1000;
  touch-action: none;
  border-radius: 12px;
  display: block;
  cursor: pointer;
  background: transparent;
  filter: drop-shadow(0 16px 28px rgba(40, 20, 8, 0.35));
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 24px;
  border-radius: 12px;
  background: rgba(28, 20, 16, 0.55);
  color: #fff8e7;
  font-size: 1.35rem;
  font-weight: 700;
  white-space: pre-line;
  backdrop-filter: blur(2px);
  animation: rise 0.35s ease both;
  pointer-events: none;
}

.overlay.game-over {
  pointer-events: auto;
  background: rgba(28, 20, 16, 0.62);
}

.overlay-end {
  display: grid;
  justify-items: center;
  gap: 18px;
  max-width: min(90%, 22rem);
}

.overlay-end-msg {
  margin: 0;
  font-size: clamp(1.15rem, 3.2vw, 1.45rem);
  font-weight: 700;
  line-height: 1.35;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
  white-space: pre-line;
}

.overlay-end-elo {
  margin: 0;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: clamp(1rem, 2.8vw, 1.2rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  background: rgba(255, 250, 236, 0.92);
  color: var(--ink);
  border: 1px solid rgba(90, 58, 34, 0.22);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
}

.overlay-end-elo.elo-up {
  color: #0f6b3a;
  border-color: rgba(15, 107, 58, 0.35);
  background: rgba(220, 245, 230, 0.95);
}

.overlay-end-elo.elo-down {
  color: #9b1c1c;
  border-color: rgba(155, 28, 28, 0.35);
  background: rgba(255, 230, 230, 0.95);
}

.overlay-end-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
  pointer-events: auto;
}

.overlay-end-actions .btn-art img {
  height: 52px;
}

.overlay.waiting {
  background: rgba(28, 20, 16, 0.42);
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1.45;
  letter-spacing: 0.01em;
  align-content: center;
  justify-items: center;
  gap: 4px;
}

.overlay.waiting .waiting-msg {
  display: block;
  max-width: 16em;
}

.overlay.waiting .waiting-elapsed {
  display: block;
  margin-top: 0;
  font-size: clamp(2.2rem, 7vw, 3.2rem);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: #ffe7a8;
  text-shadow: 0 4px 18px rgba(0, 0, 0, 0.45);
}

.overlay.countdown {
  background: rgba(28, 20, 16, 0.58);
  gap: 10px;
}

.overlay.countdown .countdown-title {
  display: block;
  font-size: clamp(1.2rem, 3.2vw, 1.7rem);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.overlay.countdown .countdown-num {
  display: block;
  font-size: clamp(3.2rem, 10vw, 5rem);
  font-weight: 800;
  line-height: 1;
  color: #ffe7a8;
  text-shadow: 0 4px 18px rgba(0, 0, 0, 0.45);
  animation: countdown-pop 0.35s ease both;
}

.overlay.countdown .countdown-num.go {
  font-size: clamp(2.2rem, 7vw, 3.4rem);
  color: #ffd36a;
}

@keyframes countdown-pop {
  from { transform: scale(0.7); opacity: 0.35; }
  to { transform: scale(1); opacity: 1; }
}

.overlay.matchup {
  background: rgba(18, 12, 8, 0.72);
  padding: 24px 18px;
  animation: matchup-veil 1.6s ease both;
}

.matchup-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: clamp(0.65rem, 2.5vw, 1.25rem);
  max-width: min(96%, 40rem);
  line-height: 1.15;
}

.matchup-name {
  font-family: var(--font);
  font-size: clamp(1.85rem, 6.5vw, 3.25rem);
  font-weight: 800;
  letter-spacing: 0.01em;
  -webkit-text-stroke: 0.5px rgba(0, 0, 0, 0.35);
  paint-order: stroke fill;
  text-shadow:
    0 1px 0 rgba(0, 0, 0, 0.85),
    0 2px 4px rgba(0, 0, 0, 0.75),
    0 6px 20px rgba(0, 0, 0, 0.55);
  max-width: 10.5em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.matchup-name-red {
  color: #ffe0d8;
  animation: matchup-slide-left 0.55s cubic-bezier(0.2, 1.2, 0.35, 1) both;
}

.matchup-name-black {
  color: #fffaf0;
  animation: matchup-slide-right 0.55s cubic-bezier(0.2, 1.2, 0.35, 1) both;
}

.matchup-vs {
  font-family: var(--font);
  font-size: clamp(2.4rem, 8vw, 4rem);
  font-weight: 900;
  line-height: 1;
  color: #ffe082;
  -webkit-text-stroke: 1px rgba(80, 40, 0, 0.45);
  paint-order: stroke fill;
  text-shadow:
    0 1px 0 rgba(0, 0, 0, 0.9),
    0 3px 8px rgba(0, 0, 0, 0.7),
    0 0 22px rgba(255, 211, 106, 0.4);
  animation: matchup-vs-pop 0.7s cubic-bezier(0.2, 1.35, 0.4, 1) both;
}

@keyframes matchup-veil {
  0% { opacity: 0; }
  8% { opacity: 1; }
  82% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes matchup-slide-left {
  from { transform: translateX(-42%) scale(0.88); opacity: 0; }
  to { transform: translateX(0) scale(1); opacity: 1; }
}

@keyframes matchup-slide-right {
  from { transform: translateX(42%) scale(0.88); opacity: 0; }
  to { transform: translateX(0) scale(1); opacity: 1; }
}

@keyframes matchup-vs-pop {
  0% { transform: scale(2.1) rotate(-8deg); opacity: 0; }
  35% { transform: scale(0.9) rotate(2deg); opacity: 1; }
  55% { transform: scale(1.08) rotate(0deg); }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

.check-fx {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  border-radius: 12px;
  pointer-events: none;
  overflow: hidden;
  background: transparent;
  animation: check-fx-veil 1.35s ease both;
}

.check-fx-img {
  display: block;
  width: min(92%, 420px);
  height: auto;
  max-height: 70%;
  object-fit: contain;
  /* Knock out the solid black plate so the burst sits on the board. */
  mix-blend-mode: screen;
  animation: check-fx-pop 1.35s cubic-bezier(0.2, 1.35, 0.4, 1) both;
}

@keyframes check-fx-veil {
  0% { opacity: 0; }
  12% { opacity: 1; }
  72% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes check-fx-pop {
  0% { transform: scale(1.55); opacity: 0; }
  18% { transform: scale(0.94); opacity: 1; }
  30% { transform: scale(1.04); }
  42% { transform: scale(1); }
  78% { transform: scale(1); opacity: 1; }
  100% { transform: scale(1.08); opacity: 0; }
}

.board-chat-float {
  position: absolute;
  left: 50%;
  top: 10%;
  z-index: 6;
  max-width: min(88%, 22rem);
  padding: 0.55rem 0.95rem;
  border-radius: 12px;
  background: rgba(28, 18, 12, 0.82);
  color: #fff8e7;
  font-family: var(--font);
  font-size: clamp(0.95rem, 2.8vw, 1.15rem);
  font-weight: 650;
  line-height: 1.3;
  text-align: center;
  word-break: break-word;
  pointer-events: none;
  transform: translate(-50%, -8px);
  opacity: 0;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35);
}

.board-chat-float.is-visible {
  animation: board-chat-float 1s ease both;
}

.board-chat-float.from-red {
  border: 1px solid rgba(255, 160, 140, 0.55);
  color: #ffe8e2;
}

.board-chat-float.from-black {
  border: 1px solid rgba(230, 220, 200, 0.45);
  color: #fffaf0;
}

@keyframes board-chat-float {
  0% { opacity: 0; transform: translate(-50%, -14px); }
  12% { opacity: 1; transform: translate(-50%, 0); }
  78% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, -8px); }
}

.overlay[hidden],
.check-fx[hidden],
.board-chat-float[hidden],
.table[hidden],
.actions[hidden],
.rules[hidden],
.auth-panel[hidden],
.auth-form[hidden],
.auth-bar[hidden],
.user-bar[hidden],
.modal[hidden],
.lobby-wrap[hidden],
.home[hidden],
.home-shell[hidden],
#table[hidden],
#modeLabel[hidden],
#roomChat[hidden],
#profileModal[hidden],
#changePasswordModal[hidden],
#friendsModal[hidden],
#friendChatModal[hidden],
#gameInviteModal[hidden] {
  display: none !important;
}

.top-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.user-bar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.auth-bar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.success {
  color: #0f5132;
  background: #d1e7dd;
  border: 1px solid #a3cfbb;
  border-radius: 10px;
  padding: 10px 12px;
  margin: 12px 0 0;
  font-size: 0.92rem;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal[hidden] { display: none !important; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(28, 20, 16, 0.5);
}

.modal-card {
  position: relative;
  width: min(440px, 100%);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  animation: rise 0.3s ease both;
}

.modal-card h2 {
  margin: 0 0 16px;
  font-size: 1.25rem;
  font-family: var(--piece);
}

.modal-hint {
  margin: -8px 0 16px;
  font-size: 0.92rem;
  color: var(--muted, #6b5c50);
  line-height: 1.4;
}

.room-list-lock {
  display: inline-block;
  width: 0.7em;
  height: 0.85em;
  margin-left: 6px;
  vertical-align: -0.05em;
  border: 1.5px solid currentColor;
  border-radius: 2px;
  position: relative;
  opacity: 0.75;
}

.room-list-lock::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -0.45em;
  width: 0.45em;
  height: 0.4em;
  border: 1.5px solid currentColor;
  border-bottom: 0;
  border-radius: 0.45em 0.45em 0 0;
  transform: translateX(-50%);
  box-sizing: border-box;
}

.modal-close {
  position: absolute;
  top: 8px;
  right: 10px;
  z-index: 2;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
  font-size: 2.1rem;
  line-height: 1;
  cursor: pointer;
  color: var(--ink);
  opacity: 0.75;
  pointer-events: auto;
}

.modal-close:hover {
  opacity: 1;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}

.auth-tab {
  border: 1px solid rgba(90, 58, 34, 0.22);
  background: #fff7e6;
  border-radius: 10px;
  padding: 10px 8px;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
}

.auth-tab.active {
  background: linear-gradient(145deg, var(--accent-2), #7a2410);
  color: #f4fff8;
  border-color: transparent;
}

.auth-form { display: grid; gap: 12px; }

.password-field {
  position: relative;
  display: block;
}

.password-field input {
  padding-right: 44px;
}

.password-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: rgba(90, 58, 34, 0.72);
  cursor: pointer;
}

.password-toggle:hover {
  color: var(--accent-2);
  background: rgba(168, 69, 28, 0.08);
}

.password-toggle:focus-visible {
  outline: 2px solid rgba(168, 69, 28, 0.35);
  outline-offset: 1px;
}

.auth-footer-link {
  margin: 0;
  text-align: center;
}

.auth-footer-link .linkish {
  font-size: 0.9rem;
  font-weight: 600;
}

.auth-hint {
  margin: 0;
  font-size: 0.9rem;
  opacity: 0.85;
}

.auth-hint-spam {
  color: var(--accent-2);
  opacity: 0.95;
  font-weight: 600;
  font-size: 0.86rem;
}

input:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.profile-preview-wrap {
  display: grid;
  justify-items: center;
  gap: 10px;
  margin-bottom: 16px;
  text-align: center;
  padding: 14px 12px 18px;
  border-radius: 16px;
  border: 1px solid transparent;
  transition: background 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

.profile-rank-frame {
  position: relative;
  width: 124px;
  height: 124px;
  display: grid;
  place-items: center;
  margin-bottom: 6px;
}

.profile-rank-frame .avatar-lg {
  width: 88px;
  height: 88px;
  font-size: 1.35rem;
  z-index: 2;
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.35),
    0 4px 14px rgba(40, 20, 8, 0.28);
}

.profile-rank-ring {
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  border: 3px solid rgba(90, 58, 34, 0.4);
  pointer-events: none;
  z-index: 1;
}

.profile-rank-ring--inner {
  inset: 14px;
  border-width: 1.5px;
  border-color: rgba(90, 58, 34, 0.22);
  border-style: dashed;
}

.profile-rank-corner {
  position: absolute;
  width: 18px;
  height: 18px;
  pointer-events: none;
  z-index: 3;
  opacity: 0.75;
  color: var(--bronze);
}

.profile-rank-corner--tl { top: 0; left: 0; border-top: 3px solid currentColor; border-left: 3px solid currentColor; }
.profile-rank-corner--tr { top: 0; right: 0; border-top: 3px solid currentColor; border-right: 3px solid currentColor; }
.profile-rank-corner--bl { bottom: 0; left: 0; border-bottom: 3px solid currentColor; border-left: 3px solid currentColor; }
.profile-rank-corner--br { bottom: 0; right: 0; border-bottom: 3px solid currentColor; border-right: 3px solid currentColor; }

.profile-rank-level {
  position: absolute;
  left: 50%;
  bottom: -2px;
  transform: translateX(-50%);
  z-index: 4;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 0;
  pointer-events: none;
}

.profile-rank-frame.has-rank .profile-rank-level {
  display: flex;
}

.profile-rank-frame .profile-rank-seal {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: var(--piece);
  font-size: 1.05rem;
  font-weight: 700;
  color: #fff8e7;
  background: linear-gradient(145deg, var(--accent-2), #7a2410);
  border: 2px solid #f6ecd6;
  box-shadow:
    0 3px 10px rgba(40, 20, 8, 0.35),
    inset 0 0 0 1px rgba(255, 255, 255, 0.28);
}

.profile-rank-tier {
  margin-top: -6px;
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  color: #fff8e7;
  background: #5a3a22;
  border: 1px solid #f6ecd6;
  box-shadow: 0 2px 6px rgba(40, 20, 8, 0.3);
}

.profile-rank-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 6px 16px;
  border-radius: 999px;
  border: 1px solid rgba(90, 58, 34, 0.22);
  background: rgba(255, 250, 236, 0.9);
  max-width: 100%;
}

.profile-rank-badge[hidden] {
  display: none !important;
}

.profile-rank-text {
  display: grid;
  gap: 1px;
  text-align: center;
  min-width: 0;
}

.profile-rank-name {
  font-family: var(--display);
  font-size: 1.2rem;
  line-height: 1.1;
  color: var(--ink);
}

.profile-rank-en {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  opacity: 0.68;
  text-transform: uppercase;
}

.profile-mode-rank {
  display: block;
  margin-top: 2px;
  font-family: var(--piece);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent-2);
}

.profile-elo {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 4px;
}

.profile-elo-row {
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 247, 230, 0.8);
  border: 1px solid rgba(90, 58, 34, 0.16);
  display: grid;
  gap: 2px;
  text-align: left;
}

.profile-elo-row span {
  font-size: 0.78rem;
  opacity: 0.7;
}

.profile-elo-row strong {
  font-size: 1.15rem;
}

.profile-record {
  display: block;
  margin-top: 2px;
  font-size: 0.78rem;
  font-weight: 600;
  opacity: 0.75;
}

/* ===== Rank themes (Chinese chess cultural) ===== */
.profile-preview-wrap[data-rank="1"] {
  background: linear-gradient(180deg, rgba(210, 205, 195, 0.45), rgba(190, 185, 175, 0.2));
  border-color: rgba(90, 90, 90, 0.28);
  color: #5a5a5a;
}
.profile-preview-wrap[data-rank="1"] .profile-rank-ring:not(.profile-rank-ring--inner) {
  border-color: #8a8680;
  border-style: dashed;
}
.profile-preview-wrap[data-rank="1"] .profile-rank-ring--inner {
  border-color: rgba(90, 90, 90, 0.35);
}
.profile-preview-wrap[data-rank="1"] .profile-rank-corner { color: #8a8680; }
.profile-preview-wrap[data-rank="1"] .profile-rank-seal {
  background: linear-gradient(145deg, #8a8680, #5c5854);
}
.profile-preview-wrap[data-rank="1"] .profile-rank-tier { background: #5c5854; }
.profile-preview-wrap[data-rank="1"] .profile-rank-badge {
  background: rgba(236, 234, 228, 0.95);
  border-color: rgba(90, 90, 90, 0.25);
}
.profile-elo-row[data-rank="1"] { border-color: rgba(90, 90, 90, 0.28); }
.profile-elo-row[data-rank="1"] .profile-mode-rank { color: #5c5854; }

.profile-preview-wrap[data-rank="2"] {
  background: linear-gradient(180deg, rgba(210, 230, 200, 0.5), rgba(186, 210, 170, 0.22));
  border-color: rgba(70, 110, 55, 0.28);
  color: #3f6b34;
}
.profile-preview-wrap[data-rank="2"] .profile-rank-ring:not(.profile-rank-ring--inner) {
  border-color: #6f9a55;
  box-shadow: inset 0 0 0 4px rgba(120, 160, 90, 0.15);
}
.profile-preview-wrap[data-rank="2"] .profile-rank-ring--inner { border-color: rgba(70, 110, 55, 0.35); }
.profile-preview-wrap[data-rank="2"] .profile-rank-corner { color: #6f9a55; }
.profile-preview-wrap[data-rank="2"] .profile-rank-seal {
  background: linear-gradient(145deg, #6f9a55, #3f6b34);
}
.profile-preview-wrap[data-rank="2"] .profile-rank-tier { background: #3f6b34; }
.profile-preview-wrap[data-rank="2"] .profile-rank-badge {
  background: rgba(235, 245, 225, 0.95);
  border-color: rgba(70, 110, 55, 0.28);
}
.profile-elo-row[data-rank="2"] { border-color: rgba(70, 110, 55, 0.28); }
.profile-elo-row[data-rank="2"] .profile-mode-rank { color: #3f6b34; }

.profile-preview-wrap[data-rank="3"] {
  background: linear-gradient(180deg, rgba(230, 205, 165, 0.55), rgba(200, 160, 100, 0.2));
  border-color: rgba(140, 95, 40, 0.35);
  color: #8a5a22;
}
.profile-preview-wrap[data-rank="3"] .profile-rank-ring:not(.profile-rank-ring--inner) {
  border-color: #b07a35;
  border-width: 3px;
}
.profile-preview-wrap[data-rank="3"] .profile-rank-ring--inner { border-color: rgba(140, 95, 40, 0.4); border-style: solid; }
.profile-preview-wrap[data-rank="3"] .profile-rank-corner { color: #b07a35; opacity: 0.95; }
.profile-preview-wrap[data-rank="3"] .profile-rank-seal {
  background: linear-gradient(145deg, #c4893a, #8a5a22);
}
.profile-preview-wrap[data-rank="3"] .profile-rank-tier { background: #8a5a22; }
.profile-preview-wrap[data-rank="3"] .profile-rank-badge {
  background: rgba(250, 236, 210, 0.95);
  border-color: rgba(140, 95, 40, 0.3);
}
.profile-elo-row[data-rank="3"] { border-color: rgba(140, 95, 40, 0.3); }
.profile-elo-row[data-rank="3"] .profile-mode-rank { color: #8a5a22; }

.profile-preview-wrap[data-rank="4"] {
  background: linear-gradient(180deg, rgba(210, 220, 230, 0.55), rgba(170, 185, 200, 0.22));
  border-color: rgba(70, 90, 115, 0.35);
  color: #4a5f78;
}
.profile-preview-wrap[data-rank="4"] .profile-rank-ring:not(.profile-rank-ring--inner) {
  border-color: #7a90a8;
  border-width: 3px;
  box-shadow: 0 0 0 3px rgba(122, 144, 168, 0.2);
}
.profile-preview-wrap[data-rank="4"] .profile-rank-corner { color: #7a90a8; opacity: 0.95; }
.profile-preview-wrap[data-rank="4"] .profile-rank-seal {
  background: linear-gradient(145deg, #8ea3b8, #4a5f78);
}
.profile-preview-wrap[data-rank="4"] .profile-rank-tier { background: #4a5f78; }
.profile-preview-wrap[data-rank="4"] .profile-rank-badge {
  background: rgba(232, 238, 245, 0.95);
  border-color: rgba(70, 90, 115, 0.3);
}
.profile-elo-row[data-rank="4"] { border-color: rgba(70, 90, 115, 0.3); }
.profile-elo-row[data-rank="4"] .profile-mode-rank { color: #4a5f78; }

.profile-preview-wrap[data-rank="5"] {
  background: linear-gradient(180deg, rgba(185, 225, 205, 0.55), rgba(120, 180, 150, 0.2));
  border-color: rgba(30, 110, 80, 0.35);
  color: #1f6e52;
}
.profile-preview-wrap[data-rank="5"] .profile-rank-ring:not(.profile-rank-ring--inner) {
  border-color: #2f8f6a;
  border-width: 3px;
  background: radial-gradient(circle, rgba(80, 170, 130, 0.12), transparent 70%);
}
.profile-preview-wrap[data-rank="5"] .profile-rank-corner { color: #2f8f6a; opacity: 0.95; }
.profile-preview-wrap[data-rank="5"] .profile-rank-seal {
  background: linear-gradient(145deg, #3aa882, #1f6e52);
}
.profile-preview-wrap[data-rank="5"] .profile-rank-tier { background: #1f6e52; }
.profile-preview-wrap[data-rank="5"] .profile-rank-badge {
  background: rgba(225, 245, 235, 0.95);
  border-color: rgba(30, 110, 80, 0.3);
}
.profile-elo-row[data-rank="5"] { border-color: rgba(30, 110, 80, 0.3); }
.profile-elo-row[data-rank="5"] .profile-mode-rank { color: #1f6e52; }

.profile-preview-wrap[data-rank="6"] {
  background: linear-gradient(180deg, rgba(170, 210, 190, 0.55), rgba(210, 185, 120, 0.25));
  border-color: rgba(160, 120, 40, 0.4);
  color: #0f5a42;
}
.profile-preview-wrap[data-rank="6"] .profile-rank-ring:not(.profile-rank-ring--inner) {
  border: 3px solid #c9a227;
  box-shadow: inset 0 0 0 3px rgba(20, 110, 80, 0.35), 0 0 12px rgba(201, 162, 39, 0.25);
}
.profile-preview-wrap[data-rank="6"] .profile-rank-corner { opacity: 0.9; color: #c9a227; }
.profile-preview-wrap[data-rank="6"] .profile-rank-seal {
  background: linear-gradient(145deg, #c9a227, #0f5a42);
}
.profile-preview-wrap[data-rank="6"] .profile-rank-tier { background: #0f5a42; }
.profile-preview-wrap[data-rank="6"] .profile-rank-badge {
  background: linear-gradient(90deg, rgba(230, 245, 235, 0.95), rgba(250, 240, 210, 0.95));
  border-color: rgba(160, 120, 40, 0.35);
}
.profile-elo-row[data-rank="6"] { border-color: rgba(160, 120, 40, 0.35); }
.profile-elo-row[data-rank="6"] .profile-mode-rank { color: #8a6a18; }

.profile-preview-wrap[data-rank="7"] {
  background: linear-gradient(180deg, rgba(240, 190, 175, 0.55), rgba(170, 50, 40, 0.15));
  border-color: rgba(150, 35, 30, 0.4);
  color: #8f1f18;
}
.profile-preview-wrap[data-rank="7"] .profile-rank-ring:not(.profile-rank-ring--inner) {
  border: 3px solid #a31d16;
  box-shadow: 0 0 0 4px rgba(30, 20, 16, 0.18);
}
.profile-preview-wrap[data-rank="7"] .profile-rank-corner { opacity: 0.95; color: #1a1a1a; }
.profile-preview-wrap[data-rank="7"] .profile-rank-seal {
  background: linear-gradient(145deg, #c42a20, #5a100c);
  box-shadow: inset 0 0 0 1px rgba(255, 220, 160, 0.35);
}
.profile-preview-wrap[data-rank="7"] .profile-rank-tier { background: #5a100c; }
.profile-preview-wrap[data-rank="7"] .profile-rank-badge {
  background: rgba(255, 236, 228, 0.95);
  border-color: rgba(150, 35, 30, 0.35);
}
.profile-elo-row[data-rank="7"] { border-color: rgba(150, 35, 30, 0.35); }
.profile-elo-row[data-rank="7"] .profile-mode-rank { color: #8f1f18; }

.profile-preview-wrap[data-rank="8"] {
  background: linear-gradient(180deg, rgba(250, 225, 150, 0.6), rgba(200, 150, 40, 0.2));
  border-color: rgba(180, 130, 20, 0.45);
  color: #8a6408;
  box-shadow: inset 0 0 0 1px rgba(255, 230, 150, 0.45);
}
.profile-preview-wrap[data-rank="8"] .profile-rank-ring:not(.profile-rank-ring--inner) {
  border: 3px solid #e0b000;
  box-shadow: 0 0 16px rgba(224, 176, 0, 0.35), inset 0 0 8px rgba(255, 230, 140, 0.4);
}
.profile-preview-wrap[data-rank="8"] .profile-rank-corner { opacity: 1; color: #e0b000; width: 16px; height: 16px; }
.profile-preview-wrap[data-rank="8"] .profile-rank-seal {
  background: linear-gradient(145deg, #f0d060, #a87800);
  color: #3a2800;
}
.profile-preview-wrap[data-rank="8"] .profile-rank-tier { background: #8a6408; }
.profile-preview-wrap[data-rank="8"] .profile-rank-badge {
  background: linear-gradient(90deg, #fff4cc, #ffe9a0);
  border-color: rgba(180, 130, 20, 0.4);
}
.profile-preview-wrap[data-rank="8"] .profile-rank-name { color: #7a5800; }
.profile-elo-row[data-rank="8"] { border-color: rgba(180, 130, 20, 0.4); background: rgba(255, 246, 210, 0.85); }
.profile-elo-row[data-rank="8"] .profile-mode-rank { color: #8a6408; }

.profile-preview-wrap[data-rank="9"] {
  background:
    linear-gradient(135deg, rgba(180, 30, 25, 0.18), transparent 45%),
    linear-gradient(180deg, rgba(250, 220, 140, 0.65), rgba(160, 40, 30, 0.18));
  border-color: rgba(160, 40, 25, 0.5);
  color: #9a1c12;
  box-shadow: 0 0 0 1px rgba(224, 176, 0, 0.35), inset 0 0 20px rgba(224, 176, 0, 0.12);
}
.profile-preview-wrap[data-rank="9"] .profile-rank-ring:not(.profile-rank-ring--inner) {
  border: 3px solid #e0b000;
  box-shadow: 0 0 0 4px rgba(163, 29, 22, 0.45), 0 0 18px rgba(224, 176, 0, 0.4);
}
.profile-preview-wrap[data-rank="9"] .profile-rank-corner { opacity: 1; color: #a31d16; width: 18px; height: 18px; }
.profile-preview-wrap[data-rank="9"] .profile-rank-seal {
  background: linear-gradient(145deg, #e0b000, #a31d16);
}
.profile-preview-wrap[data-rank="9"] .profile-rank-tier { background: #9a1c12; }
.profile-preview-wrap[data-rank="9"] .profile-rank-badge {
  background: linear-gradient(90deg, #fff0c8, #ffd8c8);
  border-color: rgba(160, 40, 25, 0.4);
}
.profile-elo-row[data-rank="9"] { border-color: rgba(160, 40, 25, 0.4); background: rgba(255, 240, 220, 0.9); }
.profile-elo-row[data-rank="9"] .profile-mode-rank { color: #9a1c12; }

.profile-preview-wrap[data-rank="10"] {
  background: linear-gradient(180deg, rgba(200, 185, 230, 0.55), rgba(90, 60, 140, 0.18));
  border-color: rgba(90, 55, 140, 0.45);
  color: #4b2f7a;
  box-shadow: inset 0 0 24px rgba(120, 80, 180, 0.12);
}
.profile-preview-wrap[data-rank="10"] .profile-rank-ring:not(.profile-rank-ring--inner) {
  border: 3px solid #7a55b8;
  box-shadow: 0 0 18px rgba(120, 80, 180, 0.35), inset 0 0 10px rgba(180, 160, 220, 0.35);
}
.profile-preview-wrap[data-rank="10"] .profile-rank-corner { opacity: 1; color: #7a55b8; }
.profile-preview-wrap[data-rank="10"] .profile-rank-seal {
  background: linear-gradient(145deg, #8f6fd0, #3d246e);
}
.profile-preview-wrap[data-rank="10"] .profile-rank-tier { background: #4b2f7a; }
.profile-preview-wrap[data-rank="10"] .profile-rank-badge {
  background: linear-gradient(90deg, #efe8ff, #e4d8f8);
  border-color: rgba(90, 55, 140, 0.35);
}
.profile-elo-row[data-rank="10"] { border-color: rgba(90, 55, 140, 0.35); background: rgba(240, 232, 252, 0.9); }
.profile-elo-row[data-rank="10"] .profile-mode-rank { color: #4b2f7a; }

.profile-preview-wrap[data-rank="11"] {
  background:
    radial-gradient(circle at 50% 20%, rgba(180, 240, 255, 0.45), transparent 55%),
    linear-gradient(180deg, rgba(210, 235, 245, 0.6), rgba(120, 170, 200, 0.2));
  border-color: rgba(60, 130, 160, 0.45);
  color: #1f6f8a;
  box-shadow: 0 0 24px rgba(120, 200, 230, 0.2);
}
.profile-preview-wrap[data-rank="11"] .profile-rank-ring:not(.profile-rank-ring--inner) {
  border: 3px solid #7ec8e0;
  box-shadow: 0 0 20px rgba(126, 200, 224, 0.55), inset 0 0 12px rgba(255, 255, 255, 0.45);
  animation: rank-immortal-pulse 2.8s ease-in-out infinite;
}
.profile-preview-wrap[data-rank="11"] .profile-rank-corner { opacity: 1; color: #7ec8e0; }
.profile-preview-wrap[data-rank="11"] .profile-rank-seal {
  background: linear-gradient(145deg, #a8e4f5, #2f7f9a);
  color: #063442;
}
.profile-preview-wrap[data-rank="11"] .profile-rank-tier { background: #1f6f8a; }
.profile-preview-wrap[data-rank="11"] .profile-rank-badge {
  background: linear-gradient(90deg, #e8f8ff, #d8eff8);
  border-color: rgba(60, 130, 160, 0.35);
}
.profile-elo-row[data-rank="11"] { border-color: rgba(60, 130, 160, 0.35); background: rgba(232, 246, 252, 0.92); }
.profile-elo-row[data-rank="11"] .profile-mode-rank { color: #1f6f8a; }

.profile-preview-wrap[data-rank="12"] {
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 220, 120, 0.55), transparent 50%),
    linear-gradient(135deg, rgba(180, 25, 20, 0.28), rgba(40, 20, 10, 0.12) 50%, rgba(224, 176, 0, 0.28));
  border-color: rgba(180, 30, 20, 0.55);
  color: #7a120c;
  box-shadow:
    0 0 0 1px rgba(224, 176, 0, 0.55),
    0 0 28px rgba(180, 30, 20, 0.25),
    inset 0 0 30px rgba(224, 176, 0, 0.15);
}
.profile-preview-wrap[data-rank="12"] .profile-rank-ring:not(.profile-rank-ring--inner) {
  border: 3px solid #e0b000;
  box-shadow:
    0 0 0 5px rgba(163, 29, 22, 0.55),
    0 0 24px rgba(224, 176, 0, 0.55),
    inset 0 0 14px rgba(255, 230, 140, 0.4);
  animation: rank-heaven-pulse 2.4s ease-in-out infinite;
}
.profile-preview-wrap[data-rank="12"] .profile-rank-corner {
  opacity: 1;
  color: #e0b000;
  width: 20px;
  height: 20px;
  border-width: 3px;
}
.profile-preview-wrap[data-rank="12"] .profile-rank-seal {
  background: linear-gradient(145deg, #ffe08a, #a31d16 55%, #5a100c);
  box-shadow: 0 0 12px rgba(224, 176, 0, 0.45), inset 0 0 0 1px rgba(255, 240, 180, 0.55);
}
.profile-preview-wrap[data-rank="12"] .profile-rank-tier { background: #7a120c; }
.profile-preview-wrap[data-rank="12"] .profile-rank-badge {
  background: linear-gradient(90deg, #fff0c0, #ffd0c0 50%, #ffe9a8);
  border-color: rgba(180, 30, 20, 0.45);
}
.profile-preview-wrap[data-rank="12"] .profile-rank-name {
  font-size: 1.28rem;
  background: linear-gradient(90deg, #8a120c, #a87800, #8a120c);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.profile-elo-row[data-rank="12"] {
  border-color: rgba(180, 30, 20, 0.45);
  background: linear-gradient(180deg, rgba(255, 245, 210, 0.95), rgba(255, 230, 220, 0.9));
}
.profile-elo-row[data-rank="12"] .profile-mode-rank { color: #8a120c; }

@keyframes rank-immortal-pulse {
  0%, 100% { box-shadow: 0 0 14px rgba(126, 200, 224, 0.4), inset 0 0 10px rgba(255, 255, 255, 0.35); }
  50% { box-shadow: 0 0 24px rgba(126, 200, 224, 0.7), inset 0 0 14px rgba(255, 255, 255, 0.55); }
}

@keyframes rank-heaven-pulse {
  0%, 100% {
    box-shadow:
      0 0 0 5px rgba(163, 29, 22, 0.45),
      0 0 18px rgba(224, 176, 0, 0.4),
      inset 0 0 12px rgba(255, 230, 140, 0.35);
  }
  50% {
    box-shadow:
      0 0 0 6px rgba(163, 29, 22, 0.6),
      0 0 30px rgba(224, 176, 0, 0.7),
      inset 0 0 16px rgba(255, 230, 140, 0.55);
  }
}

.seat-card.is-clickable {
  cursor: pointer;
}

.seat-card.is-clickable .seat-avatar-wrap,
.seat-card.is-clickable .seat-avatar {
  cursor: pointer;
}

.seat-card.is-clickable:hover {
  filter: brightness(1.05);
}

.seat-card.is-clickable:hover .seat-avatar {
  filter: brightness(1.08);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.55);
}

.seat-card.is-clickable:focus-visible {
  outline: 2px solid rgba(224, 176, 0, 0.85);
  outline-offset: 2px;
}

.file-label input[type="file"] {
  padding: 8px 0;
  border: 0;
  background: transparent;
}

.profile-privacy-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 4px 0 0;
}

.profile-privacy-hint {
  margin: 6px 0 12px;
  font-size: 0.82rem;
}

.profile-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 4px;
}

.profile-actions .btn {
  width: 100%;
  min-width: 0;
}

.profile-actions .btn[hidden] {
  display: none;
}

.profile-actions:has(#btnAvatarRemove[hidden]) {
  grid-template-columns: 1fr;
}

.profile-preview-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
}

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

  .app-bg::before {
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: top center;
  }

  .table-stage {
    grid-template-columns: 1fr;
    grid-template-areas:
      "top"
      "board"
      "bottom"
      "side";
    justify-items: stretch;
    gap: 10px;
  }

  .table-title {
    gap: 6px;
    padding: 0 4px;
  }

  .table-title-zh,
  .table-seal {
    display: none;
  }

  .table-title-sub {
    font-size: 0.85rem;
  }

  /* Let rails participate in table-stage grid (above / below board). */
  .table-players {
    display: contents;
  }

  #playerRailTop {
    grid-area: top;
    width: min(620px, 100%);
    justify-self: center;
  }

  .board-column {
    grid-area: board;
    width: min(620px, 100%);
    justify-self: center;
    justify-items: center;
  }

  .board-wrap {
    margin-inline: auto;
    scroll-margin-block: 12vh;
  }

  #playerRailBottom {
    grid-area: bottom;
    width: min(620px, 100%);
    justify-self: center;
  }

  #playerRailTop,
  #playerRailBottom {
    display: block;
  }

  #playerRailTop .seat,
  #playerRailBottom .seat {
    width: 100%;
    box-sizing: border-box;
  }

  .table-side {
    grid-area: side;
    width: min(620px, 100%);
    justify-self: center;
    height: auto;
    min-height: 0;
    max-height: none;
    overflow: visible;
  }

  .meta {
    grid-area: side;
    width: min(620px, 100%);
    justify-self: center;
    height: auto;
    min-height: 0;
    max-height: none;
    overflow: visible;
  }

  .room-chat {
    display: none;
    position: fixed;
    inset: 0;
    width: auto;
    height: auto;
    max-height: none;
    z-index: 90;
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    gap: 10px;
    padding: 14px 14px calc(14px + env(safe-area-inset-bottom, 0px));
    border-radius: 0;
    background: rgba(28, 18, 12, 0.55);
    border: 0;
    box-shadow: none;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    overflow: hidden;
    /* Dark ink for chat content; toolbar keeps light text below. */
    color: var(--ink);
  }

  .room-chat.is-open {
    display: grid;
  }

  .room-chat-toolbar {
    display: flex;
  }

  .room-chat-title {
    color: #fff8e7;
  }

  .room-chat-close {
    background: rgba(255, 248, 230, 0.14);
    color: #fff8e7;
  }

  .room-chat-close:hover {
    background: rgba(255, 248, 230, 0.22);
  }

  .room-chat-log {
    min-height: 0;
    background: rgba(255, 252, 245, 0.96);
    border-color: rgba(90, 58, 34, 0.18);
    color: var(--ink);
  }

  .room-chat .chat-empty {
    color: var(--ink-soft);
  }

  .room-chat .chat-msg,
  .room-chat .chat-msg .chat-meta,
  .room-chat .chat-msg .chat-text,
  .room-chat .chat-msg .chat-name {
    color: var(--ink);
  }

  .room-chat .chat-msg .chat-meta {
    opacity: 0.9;
    color: var(--ink-soft);
  }

  .room-chat .chat-msg[data-color="red"] .chat-name {
    color: var(--red);
  }

  .room-chat .chat-msg[data-color="black"] .chat-name {
    color: var(--black);
  }

  .room-chat .chat-msg[data-color="spectator"] .chat-name {
    color: #5a4a38;
  }

  .room-chat-compose {
    color: var(--ink);
  }

  .room-chat .chat-quick-panel,
  .room-chat .chat-icon-panel {
    color: var(--ink);
  }

  .room-chat .chat-quick-pick {
    color: var(--ink);
    background: rgba(255, 252, 245, 0.98);
  }

  .room-chat-form input,
  .room-chat-form input:focus,
  .room-chat-form input:disabled {
    background: rgba(255, 252, 245, 0.98);
    color: var(--ink) !important;
    -webkit-text-fill-color: var(--ink);
    caret-color: var(--ink);
  }

  .room-chat-form input::placeholder {
    color: var(--ink-soft) !important;
    -webkit-text-fill-color: var(--ink-soft);
    opacity: 0.8;
  }

  .chat-popup-backdrop:not([hidden]) {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 85;
    background: rgba(12, 8, 4, 0.25);
  }

  .seat-chat-btn:not([hidden]) {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
    flex-shrink: 0;
    align-self: center;
    order: 5;
    width: 36px;
    height: 36px;
    margin: 0;
    padding: 0;
    border: 1px solid rgba(255, 232, 196, 0.28);
    border-radius: 10px;
    cursor: pointer;
    color: #fff8e7;
    background: rgba(255, 248, 230, 0.12);
  }

  .table-players #playerRailBottom .seat-info {
    margin-right: 0;
  }

  .table-players #playerRailBottom .seat-timer-row {
    margin-left: auto;
  }

  .seat-chat-btn:hover {
    background: rgba(255, 248, 230, 0.22);
  }

  .seat-chat-icon {
    display: block;
  }

  .seat-chat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    border-radius: 999px;
    background: #c62828;
    color: #fff;
    font-size: 0.68rem;
    font-weight: 800;
    line-height: 18px;
    text-align: center;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  }

  .seat-chat-badge[hidden] {
    display: none !important;
  }

  /* Compact horizontal player cards on small screens */
  #playerRailBottom .seat,
  .table-players .seat,
  .table-players #playerRailBottom .seat {
    flex-direction: row !important;
    justify-content: flex-start;
    align-items: stretch;
    text-align: left;
    gap: 8px;
    padding: 0;
    border-radius: 0;
    background: transparent;
    border: 0;
    box-shadow: none;
  }

  /* Opponent (top): flag first, profile on the right */
  #playerRailTop .seat,
  .table-players #playerRailTop .seat {
    flex-direction: row-reverse !important;
    justify-content: flex-start;
    align-items: stretch;
    text-align: right;
    gap: 8px;
    padding: 0;
    border-radius: 0;
    background: transparent;
    border: 0;
    box-shadow: none;
  }

  .table-players .seat-card {
    flex: 1 1 auto;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    text-align: left;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 12px;
    min-width: 0;
    max-width: none;
    width: 100%;
    height: 72px;
    overflow: visible;
  }

  .table-players .seat-avatar-wrap {
    position: relative;
    top: auto;
    left: auto;
    transform: none;
    flex-shrink: 0;
    margin: 0;
  }

  .table-players .seat-avatar,
  .table-players .seat-avatar-wrap {
    width: 60px;
    height: 60px;
  }

  .table-players .seat-info {
    text-align: left !important;
    flex: 1 1 auto;
    width: auto !important;
    min-width: 0;
    min-height: 0;
    margin-right: auto;
  }

  .table-players .seat-elo[hidden] {
    display: none !important;
  }

  .table-players .seat-timer-row {
    width: auto;
    margin-top: 0;
    margin-left: auto;
    flex-shrink: 0;
    padding: 5px 8px;
  }

  .table-players .seat-hang {
    display: flex;
    flex-direction: column;
    justify-content: center;
    margin-top: 0;
  }

  .table-players .seat-chain {
    display: none;
  }

  .table-players .seat-banner {
    width: 40px;
    margin-top: 0;
    flex-shrink: 0;
  }

  #playerRailTop .seat-card,
  .table-players #playerRailTop .seat-card {
    flex-direction: row-reverse;
    justify-content: flex-start;
    text-align: right;
  }

  #playerRailTop .seat-info,
  .table-players #playerRailTop .seat-info {
    text-align: right !important;
    margin-right: 0;
    margin-left: auto;
  }

  #playerRailTop .seat-timer-row,
  .table-players #playerRailTop .seat-timer-row {
    margin-left: 0;
    margin-right: auto;
  }
}

@media (max-width: 760px) {
  .lobby-wrap { grid-template-columns: 1fr; }

  .table-players .seat-banner,
  .table-players .seat-hang {
    display: none;
  }
}
