/* ==========================================================
   IVS BOARD GAMES — MOBILE-FIRST CSS ARCHITECTURE
   ========================================================== */

/* Design Tokens & Themes */
:root {
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  color-scheme: light;
  
  --bg: #f8fafc;
  --bg-gradient: linear-gradient(180deg, #f8fafc 0%, #eef2f6 100%);
  --surface: #ffffff;
  --surface-subtle: #f1f5f9;
  --border: #e2e8f0;
  --border-focus: #3b82f6;
  
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;
  
  --primary: #0f172a;
  --primary-hover: #1e293b;
  --primary-text: #ffffff;
  
  --accent: #2563eb;
  --accent-light: #dbeafe;
  --success: #16a34a;
  --success-bg: #dcfce7;
  --warning: #ca8a04;
  --danger: #dc2626;
  
  /* Chess Palette */
  --chess-light: #f0d9b5;
  --chess-dark: #b58863;
  --chess-selected: #facc15;
  --chess-legal: rgba(15, 23, 42, 0.38);
  --chess-capture: rgba(220, 38, 38, 0.65);
  --chess-last-move: rgba(250, 204, 21, 0.45);
  
  /* Xiangqi Palette */
  --xq-board: #e4c290;
  --xq-line: #6b3f20;
  --xq-piece-bg: #fffef7;
  --xq-red: #dc2626;
  --xq-black: #0f172a;
  
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 14px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 36px rgba(15, 23, 42, 0.14);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1120;
  --bg-gradient: linear-gradient(180deg, #0b1120 0%, #060a14 100%);
  --surface: #131d31;
  --surface-subtle: #1e293b;
  --border: #293548;
  --border-focus: #60a5fa;
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-subtle: #64748b;
  
  --primary: #f8fafc;
  --primary-hover: #e2e8f0;
  --primary-text: #0b1120;
  
  --accent: #3b82f6;
  --accent-light: rgba(59, 130, 246, 0.2);
  
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 36px rgba(0, 0, 0, 0.5);
}

/* ==========================================================
   BASE & RESET (Mobile Default)
   ========================================================== */
*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 100vw;
  min-height: 100dvh;
  background: var(--bg);
  background-image: var(--bg-gradient);
  color: var(--text-main);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  flex-direction: column;
  position: relative;
  transition: background-color 0.3s ease;
}

/* ==========================================================
   IN-GAME ATMOSPHERIC BACKDROPS & AMBIENT GRAPHICS
   ========================================================== */
body:has(#gameScreen:not(.hidden) .chess-board-wrap) {
  background:
    radial-gradient(circle at 50% 30%, rgba(245, 158, 11, 0.12) 0%, transparent 65%),
    linear-gradient(rgba(11, 17, 32, 0.9), rgba(6, 10, 20, 0.96)),
    url('assets/chess-bg.jpg') no-repeat center top / cover fixed;
}
body:not([data-theme="dark"]):has(#gameScreen:not(.hidden) .chess-board-wrap) {
  background:
    radial-gradient(circle at 50% 30%, rgba(245, 158, 11, 0.1) 0%, transparent 65%),
    linear-gradient(rgba(248, 250, 252, 0.9), rgba(238, 242, 246, 0.96)),
    url('assets/chess-bg.jpg') no-repeat center top / cover fixed;
}

body:has(#gameScreen:not(.hidden) .xiangqi-board-wrap) {
  background:
    radial-gradient(circle at 50% 30%, rgba(220, 38, 38, 0.12) 0%, transparent 70%),
    linear-gradient(rgba(11, 17, 32, 0.88), rgba(6, 10, 20, 0.96)),
    url('assets/xiangqi-bg.jpg') no-repeat center top / cover fixed;
}
body:not([data-theme="dark"]):has(#gameScreen:not(.hidden) .xiangqi-board-wrap) {
  background:
    radial-gradient(circle at 50% 30%, rgba(220, 38, 38, 0.08) 0%, transparent 70%),
    linear-gradient(rgba(248, 250, 252, 0.88), rgba(238, 242, 246, 0.95)),
    url('assets/xiangqi-bg.jpg') no-repeat center top / cover fixed;
}

body:has(#gameScreen:not(.hidden) .caro-board-wrap) {
  background:
    radial-gradient(circle at 50% 30%, rgba(56, 189, 248, 0.1) 0%, transparent 70%),
    linear-gradient(rgba(11, 17, 32, 0.9), rgba(6, 10, 20, 0.96)),
    url('assets/caro-bg.jpg') no-repeat center top / cover fixed;
}
body:not([data-theme="dark"]):has(#gameScreen:not(.hidden) .caro-board-wrap) {
  background:
    radial-gradient(circle at 50% 30%, rgba(56, 189, 248, 0.08) 0%, transparent 70%),
    linear-gradient(rgba(248, 250, 252, 0.9), rgba(238, 242, 246, 0.96)),
    url('assets/caro-bg.jpg') no-repeat center top / cover fixed;
}

body:has(#tycoonScreen:not(.hidden)) {
  background:
    radial-gradient(circle at 50% 30%, rgba(52, 211, 153, 0.12) 0%, transparent 70%),
    linear-gradient(rgba(11, 17, 32, 0.88), rgba(6, 10, 20, 0.96)),
    url('assets/tycoon-bg.jpg') no-repeat center top / cover fixed;
}
body:not([data-theme="dark"]):has(#tycoonScreen:not(.hidden)) {
  background:
    radial-gradient(circle at 50% 30%, rgba(52, 211, 153, 0.08) 0%, transparent 70%),
    linear-gradient(rgba(248, 250, 252, 0.88), rgba(238, 242, 246, 0.95)),
    url('assets/tycoon-bg.jpg') no-repeat center top / cover fixed;
}

/* Glassmorphism elevation for in-game cards */
body:has(#gameScreen:not(.hidden)) .card,
body:has(#tycoonScreen:not(.hidden)) .card {
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
[data-theme="dark"] body:has(#gameScreen:not(.hidden)) .card,
[data-theme="dark"] body:has(#tycoonScreen:not(.hidden)) .card {
  background: rgba(19, 29, 49, 0.84);
  border-color: rgba(255, 255, 255, 0.1);
}
body:not([data-theme="dark"]):has(#gameScreen:not(.hidden)) .card,
body:not([data-theme="dark"]):has(#tycoonScreen:not(.hidden)) .card {
  background: rgba(255, 255, 255, 0.88);
  border-color: rgba(0, 0, 0, 0.08);
}

.app-shell {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 8px 12px max(24px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  overflow-x: hidden;
}

.hidden {
  display: none !important;
}

/* Typography & Common elements */
h1, h2, h3, p {
  margin: 0;
}

.eyebrow {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--accent);
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

h1 {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

h2 {
  font-size: 1.12rem;
  font-weight: 750;
}

/* Buttons & Touch targets */
button {
  font-family: inherit;
  font-size: inherit;
  border: none;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text-main);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  font-size: 1.25rem;
  transition: transform 0.12s ease, background-color 0.12s ease;
}

.icon-btn:active {
  transform: scale(0.96);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 0.92rem;
  background: var(--surface-subtle);
  color: var(--text-main);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  transition: all 0.15s ease;
}

.btn:active {
  transform: scale(0.97);
}

.btn.primary {
  background: var(--primary);
  color: var(--primary-text);
  border-color: var(--primary);
}

.btn.danger {
  background: var(--danger);
  color: #ffffff;
  border-color: var(--danger);
}

.btn:disabled {
  opacity: 0.52;
  cursor: not-allowed;
  transform: none;
}

.text-btn, .sub-btn {
  padding: 8px 12px;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--accent);
  border-radius: var(--radius-sm);
}

.sub-btn {
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  font-weight: 800;
  background: var(--accent-light);
  color: var(--accent);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.online-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  font-weight: 750;
  background: rgba(34, 197, 94, 0.14);
  color: #16a34a;
  border: 1px solid rgba(34, 197, 94, 0.3);
  transition: all 0.2s ease;
}

.online-pill.connecting,
.online-pill.reconnecting {
  background: rgba(245, 158, 11, 0.14);
  color: #d97706;
  border-color: rgba(245, 158, 11, 0.35);
}

.online-pill.disconnected {
  background: rgba(239, 68, 68, 0.14);
  color: #dc2626;
  border-color: rgba(239, 68, 68, 0.35);
}

.pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
  animation: pulse 1.8s infinite;
  flex-shrink: 0;
}

.online-pill.connecting .pulse-dot,
.online-pill.reconnecting .pulse-dot {
  background: #f59e0b;
  box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.7);
  animation: pulse 1.2s infinite;
}

.online-pill.disconnected .pulse-dot {
  background: #ef4444;
  box-shadow: none;
  animation: none;
}

.reconnect-btn {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  border: 1px solid rgba(239, 68, 68, 0.5);
  background: rgba(239, 68, 68, 0.18);
  color: #dc2626;
  font-size: 0.7rem;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.15s ease;
}

.reconnect-btn:hover {
  background: rgba(239, 68, 68, 0.3);
  transform: scale(1.04);
}

.reconnect-btn.hidden {
  display: none !important;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.7); }
  70% { box-shadow: 0 0 0 6px rgba(22, 163, 74, 0); }
  100% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0); }
}

/* ==========================================================
   TOPBAR & HEADER STATUS INTEGRATION
   ========================================================== */
.topbar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 0 10px;
  width: 100%;
  min-width: 0;
}

.topbar-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 10px;
}

.brand-header {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.app-logo {
  width: 24px;
  height: 24px;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  flex-shrink: 0;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.header-main-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  width: 100%;
  min-width: 0;
}

.header-main-row h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

/* Header-integrated status pill */
.header-status-pill {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 6px 12px;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
  min-width: 0;
  max-width: 100%;
  flex: 1;
}

.status-badge-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.status-info-group {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 8px;
  min-width: 0;
  flex: 1;
}

.header-status-pill.hidden {
  display: none !important;
}

.header-status-pill .badge {
  font-size: 0.7rem;
  padding: 2px 7px;
  flex-shrink: 0;
}

.header-status-pill strong {
  font-size: 0.85rem;
  font-weight: 800;
  line-height: 1.3;
  color: var(--text-main);
  word-break: break-word;
}

.header-status-pill .status-subtext {
  font-size: 0.74rem;
  color: var(--text-muted);
  line-height: 1.3;
  word-break: break-word;
}

.header-status-pill.check-alert {
  border-color: rgba(239, 68, 68, 0.9);
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.2), var(--surface) 75%);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2), 0 2px 10px rgba(239, 68, 68, 0.25);
  animation: check-alert 1.35s ease-in-out infinite;
}

/* ==========================================================
   CARDS & SELECTION SCREENS (Mobile Default)
   ========================================================== */
.view-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
}

.picker-intro {
  text-align: center;
  padding: 10px 0 2px;
}

.picker-kicker {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: 0.12em;
  margin-bottom: 4px;
}

.picker-intro h2 {
  font-size: 1.35rem;
  margin-bottom: 6px;
}

.picker-intro p {
  color: var(--text-muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.game-cards, .mode-cards, .side-cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.game-card, .mode-card, .side-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  text-align: left;
  transition: transform 0.18s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.18s ease, border-color 0.18s ease;
  min-height: 72px;
}

.game-card {
  position: relative;
  overflow: hidden;
  background-size: cover;
  background-position: right center;
  background-repeat: no-repeat;
}

.game-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.game-card:active, .mode-card:active, .side-card:active {
  transform: scale(0.985);
}

/* Chess Card */
.game-card[data-game="chess"] {
  background-image:
    linear-gradient(105deg, var(--surface) 0%, var(--surface) 45%, rgba(28, 18, 12, 0.42) 100%),
    url('assets/chess-bg.jpg');
}
[data-theme="dark"] .game-card[data-game="chess"] {
  background-image:
    linear-gradient(105deg, var(--surface) 0%, rgba(19, 29, 49, 0.94) 48%, rgba(28, 18, 12, 0.55) 100%),
    url('assets/chess-bg.jpg');
}
.game-card[data-game="chess"] .game-symbol {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.18), rgba(217, 119, 6, 0.08));
  color: #f59e0b;
  border: 1.5px solid rgba(245, 158, 11, 0.35);
  box-shadow: 0 0 16px rgba(245, 158, 11, 0.16);
}
.game-card[data-game="chess"]:hover {
  border-color: rgba(245, 158, 11, 0.55);
  box-shadow: 0 8px 24px rgba(245, 158, 11, 0.18);
}

/* Xiangqi Card */
.game-card[data-game="xiangqi"] {
  background-image:
    linear-gradient(105deg, var(--surface) 0%, var(--surface) 45%, rgba(45, 14, 10, 0.4) 100%),
    url('assets/xiangqi-bg.jpg');
}
[data-theme="dark"] .game-card[data-game="xiangqi"] {
  background-image:
    linear-gradient(105deg, var(--surface) 0%, rgba(19, 29, 49, 0.94) 48%, rgba(45, 14, 10, 0.55) 100%),
    url('assets/xiangqi-bg.jpg');
}
.game-card[data-game="xiangqi"] .game-symbol {
  background: linear-gradient(135deg, rgba(220, 38, 38, 0.18), rgba(185, 28, 28, 0.08));
  color: #ef4444;
  border: 1.5px solid rgba(220, 38, 38, 0.35);
  box-shadow: 0 0 16px rgba(220, 38, 38, 0.16);
}
.game-card[data-game="xiangqi"]:hover {
  border-color: rgba(220, 38, 38, 0.55);
  box-shadow: 0 8px 24px rgba(220, 38, 38, 0.18);
}

/* Caro Card */
.game-card[data-game="caro"] {
  background-image:
    linear-gradient(105deg, var(--surface) 0%, var(--surface) 45%, rgba(15, 30, 45, 0.4) 100%),
    url('assets/caro-bg.jpg');
}
[data-theme="dark"] .game-card[data-game="caro"] {
  background-image:
    linear-gradient(105deg, var(--surface) 0%, rgba(19, 29, 49, 0.94) 48%, rgba(15, 30, 45, 0.55) 100%),
    url('assets/caro-bg.jpg');
}
.game-card[data-game="caro"] .game-symbol {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.18), rgba(37, 99, 235, 0.08));
  color: #38bdf8;
  border: 1.5px solid rgba(59, 130, 246, 0.35);
  box-shadow: 0 0 16px rgba(59, 130, 246, 0.16);
}
.game-card[data-game="caro"]:hover {
  border-color: rgba(59, 130, 246, 0.55);
  box-shadow: 0 8px 24px rgba(59, 130, 246, 0.18);
}

/* Tycoon Card */
.game-card[data-game="tycoon"] {
  background-image:
    linear-gradient(105deg, var(--surface) 0%, var(--surface) 45%, rgba(8, 28, 22, 0.42) 100%),
    url('assets/tycoon-bg.jpg');
}
[data-theme="dark"] .game-card[data-game="tycoon"] {
  background-image:
    linear-gradient(105deg, var(--surface) 0%, rgba(19, 29, 49, 0.94) 48%, rgba(8, 28, 22, 0.58) 100%),
    url('assets/tycoon-bg.jpg');
}
.game-card[data-game="tycoon"] .game-symbol {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.18), rgba(5, 150, 105, 0.08));
  color: #34d399;
  border: 1.5px solid rgba(16, 185, 129, 0.35);
  box-shadow: 0 0 16px rgba(16, 185, 129, 0.16);
}
.game-card[data-game="tycoon"]:hover {
  border-color: rgba(16, 185, 129, 0.55);
  box-shadow: 0 8px 24px rgba(16, 185, 129, 0.18);
}

.game-symbol, .mode-icon, .side-symbol {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: var(--radius-md);
  background: var(--surface-subtle);
  font-size: 2rem;
  flex-shrink: 0;
}

.xq-symbol {
  font-family: "Noto Serif CJK SC", "Microsoft YaHei", "SimSun", serif;
  color: var(--xq-red);
}

.game-card-copy, .mode-card-copy, .side-copy {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
}

.game-card-copy strong, .mode-card-copy strong, .side-copy strong {
  font-size: 1.05rem;
  font-weight: 750;
}

.game-card-copy small, .mode-card-copy small, .side-copy small {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.arrow {
  font-size: 1.3rem;
  color: var(--text-subtle);
}

.spectator-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  justify-content: center;
  padding: 6px 0;
}

.tycoon-live-lobby-actions {
  display: grid;
  gap: 10px;
  width: min(100%, 760px);
  margin: 14px auto 0;
  text-align: center;
}

.tycoon-live-lobby-actions small {
  color: var(--text-muted);
  font-size: 0.78rem;
}

.tycoon-seat-card[aria-pressed="true"] {
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent), var(--shadow-sm);
}

.tycoon-online-room-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.tycoon-online-room-actions > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.tycoon-online-room-actions strong {
  letter-spacing: 0.08em;
}

.room-grid {
  display: grid;
  gap: 16px;
  width: min(100%, 880px);
  margin: 0 auto;
}

.room-form {
  display: grid;
  gap: 16px;
  padding: 20px;
}

.room-form h3 { margin: 0; }

.room-form label:not(.check-row) {
  display: grid;
  gap: 7px;
  font-size: 0.88rem;
  font-weight: 700;
}

.text-input {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0 13px;
  color: var(--text-main);
  background: var(--surface);
  font: inherit;
}

.text-input:focus {
  outline: 3px solid color-mix(in srgb, var(--primary) 22%, transparent);
  border-color: var(--primary);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  cursor: pointer;
}

.check-row input {
  width: 20px;
  height: 20px;
  accent-color: var(--primary);
}

.form-error {
  min-height: 24px;
  margin: 14px auto 0;
  color: #dc2626;
  text-align: center;
  font-weight: 700;
}

.room-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  width: min(100%, 760px);
  margin: 0 auto 16px;
  padding: 14px 16px;
}

.room-toolbar > div {
  display: grid;
  gap: 2px;
}

.room-toolbar strong {
  font-size: 1.35rem;
  letter-spacing: 0.12em;
}

.muted-label,
#spectatorStatus {
  color: var(--text-muted);
  font-size: 0.78rem;
}

/* ==========================================================
   GAME BOARD AREA (Mobile Layout & Geometry Invariant)
   ========================================================== */
.game-layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-width: 0;
}

.board-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: min(100%, 75dvh, 600px);
  margin: 0 auto;
}

.player-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 6px 4px 8px;
  font-size: 0.88rem;
  font-weight: 700;
}

.player-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-subtle);
}

.status-dot.active {
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.2);
}

.player-badge {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--surface-subtle);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

/* CHESS BOARD WRAP & EXACT 1:1 RATIO */
.board-wrap {
  position: relative;
  width: 100%;
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  border: 4px solid var(--surface);
  user-select: none;
  touch-action: manipulation;
}

.chess-board-wrap {
  width: 100%;
  aspect-ratio: 1 / 1;
  border: 6px solid #2e1a12;
  box-shadow:
    0 20px 48px rgba(0, 0, 0, 0.55),
    inset 0 0 14px rgba(0, 0, 0, 0.4);
}

.board {
  width: 100%;
  height: 100%;
  display: grid;
}

.chess-board {
  aspect-ratio: 1 / 1;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
}

/* CHESS SQUARES & ABSOLUTE SQUARE GUARRANTEE */
.square {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  aspect-ratio: 1 / 1;
  padding: 0;
  margin: 0;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  line-height: 1;
  background: transparent;
}

.chess-board .square.light {
  background: var(--chess-light);
}

.chess-board .square.dark {
  background: var(--chess-dark);
}

/* ULTRA-CRISP CHESS PIECES (Vector SVG) */
.chess-svg {
  display: block;
  width: 84%;
  height: 84%;
  pointer-events: none;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.35));
}

.chess-svg.white-piece {
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.45));
}

.chess-svg.black-piece {
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.6));
}

/* Selected, Legal, Capture, Last Move Indicators */
.square.selected {
  outline: 4px solid var(--chess-selected);
  outline-offset: -4px;
  z-index: 5;
}

/* Base last-move square highlight */
.square.last::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--chess-last-move);
  z-index: 1;
  pointer-events: none;
}

/* Origin square (from): subtle dashed border & warm tint */
.square.last-from::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(250, 204, 21, 0.28);
  box-shadow: inset 0 0 0 2px rgba(245, 158, 11, 0.7);
  z-index: 1;
  pointer-events: none;
}

/* Destination square (to): prominent golden border & inner glow */
.square.last-to::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(250, 204, 21, 0.45);
  box-shadow: inset 0 0 0 3.5px #f59e0b, inset 0 0 16px rgba(245, 158, 11, 0.5);
  z-index: 1;
  pointer-events: none;
}

/* Prominent highlight on the piece that just moved */
.square.last-to .piece,
.square.last-to .chess-svg {
  position: relative;
  z-index: 3;
  filter: drop-shadow(0 0 5px rgba(245, 158, 11, 0.95)) drop-shadow(0 0 10px rgba(245, 158, 11, 0.65)) drop-shadow(0 2px 4px rgba(0, 0, 0, 0.6));
}

.square.legal::after {
  content: "";
  position: absolute;
  width: 26%;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  background: var(--chess-legal);
  z-index: 4;
}

.square.capture::after {
  content: "";
  position: absolute;
  inset: 7%;
  border: 4px solid var(--chess-capture);
  border-radius: 50%;
  z-index: 4;
}

.square.capture-event {
  box-shadow: inset 0 0 0 4px #f97316, inset 0 0 22px rgba(249, 115, 22, 0.5);
  animation: capture-alert 900ms ease-out;
}

.square.checking-move {
  box-shadow: inset 0 0 0 4px #f59e0b, inset 0 0 24px rgba(245, 158, 11, 0.42);
}

.square.in-check {
  box-shadow: inset 0 0 0 5px #dc2626, inset 0 0 28px rgba(220, 38, 38, 0.62);
  animation: check-alert 1.35s ease-in-out infinite;
}

.square.in-check .chess-svg {
  filter: drop-shadow(0 0 6px rgba(220, 38, 38, 0.95));
}

.board-wrap.board-in-check {
  border-color: #ef4444;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.25), 0 12px 32px rgba(127, 29, 29, 0.35);
}

.status-card.check-alert {
  border-color: rgba(239, 68, 68, 0.8);
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.16), var(--surface) 58%);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.12);
}

@keyframes capture-alert {
  0% { transform: scale(0.92); filter: saturate(1.6); }
  55% { transform: scale(1.035); }
  100% { transform: scale(1); filter: none; }
}

@keyframes check-alert {
  0%, 100% { filter: saturate(1); }
  50% { filter: saturate(1.45) brightness(1.06); }
}

/* Chess Coordinates */
.coord {
  position: absolute;
  font-size: 8px;
  font-weight: 800;
  opacity: 0.65;
  z-index: 2;
  pointer-events: none;
}

.coord.file {
  right: 3px;
  bottom: 2px;
}

.coord.rank {
  left: 3px;
  top: 2px;
}

/* XIANGQI BOARD & PIECES — Intersection-based layout */
.xiangqi-board-wrap {
  width: 100%;
  max-width: min(100%, 80dvh, 600px);
  aspect-ratio: 9 / 10;
  background:
    linear-gradient(rgba(255,255,255,0.08), rgba(255,255,255,0.08)),
    var(--xq-board);
  overflow: hidden;
  border: 7px solid #4a2108;
  border-radius: 4px;
  box-shadow:
    0 18px 45px rgba(35, 12, 4, 0.5),
    inset 0 0 16px rgba(92, 44, 16, 0.35);
}

.xiangqi-board {
  position: relative;
  aspect-ratio: 9 / 10;
  display: block !important;          /* override grid layout from .board */
  background: var(--xq-board);
  /* Padding so pieces at edges are not clipped:
     Each intersection unit = board / 8 col or / 9 row
     We add half-a-piece clearance at each border side   */
  padding: 0;
}

/* SVG grid fills entire board div */
.xq-svg-board {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

/* River text inside SVG */
.xq-river-label text {
  font-family: "Noto Serif CJK SC", "Microsoft YaHei", "SimSun", serif;
  font-size: 0.58px;
  font-weight: 800;
  letter-spacing: 0.04px;
  fill: rgba(74, 38, 18, 0.96);
  dominant-baseline: central;
  text-anchor: start;
}

/* Hit-area button at each intersection */
.xq-intersection {
  position: absolute;
  z-index: 3;
  /* Touch area centered on each of the 90 true intersections. */
  width: calc(100% / 9);
  height: calc(100% / 10);
  /* Center the button ON the intersection point */
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
  border-radius: 50%;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.xq-intersection:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Last-move highlights */
.xq-intersection.last::before {
  content: "";
  position: absolute;
  inset: 10%;
  border-radius: 50%;
  background: rgba(250, 204, 21, 0.45);
  z-index: 0;
}

/* Last-move origin intersection (from): dashed amber ring */
.xq-intersection.last-from::before {
  content: "";
  position: absolute;
  inset: 12%;
  border-radius: 50%;
  border: 2px dashed rgba(245, 158, 11, 0.85);
  background: rgba(250, 204, 21, 0.25);
  z-index: 0;
}

/* Last-move destination intersection (to): strong amber glow ring */
.xq-intersection.last-to::before {
  content: "";
  position: absolute;
  inset: 6%;
  border-radius: 50%;
  box-shadow: 0 0 0 3px #f59e0b, 0 0 14px rgba(245, 158, 11, 0.85);
  z-index: 0;
}

/* Prominent golden border on the Xiangqi piece that just moved */
.xq-intersection.last-to .xq-piece {
  border-color: #f59e0b !important;
  box-shadow: 0 0 0 2.5px #f59e0b, 0 0 16px rgba(245, 158, 11, 0.9), inset 0 0 0 2px var(--xq-piece-bg) !important;
}

/* Legal move: small dot */
.xq-intersection.legal::after {
  content: "";
  position: absolute;
  width: 28%;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.38);
  z-index: 4;
}

/* Capture move: ring around intersection */
.xq-intersection.capture::after {
  content: "";
  position: absolute;
  inset: 8%;
  border: 3px solid rgba(220, 38, 38, 0.65);
  border-radius: 50%;
  z-index: 4;
}

/* Selected intersection */
.xq-intersection.selected::before {
  content: "";
  position: absolute;
  inset: 6%;
  border-radius: 50%;
  box-shadow: 0 0 0 3px var(--chess-selected) inset;
  z-index: 5;
}

/* Capture animation */
.xq-intersection.capture-event .xq-piece {
  animation: capture-alert 900ms ease-out;
}

/* In-check: pulsing red ring */
.xq-intersection.in-check::before {
  content: "";
  position: absolute;
  inset: 4%;
  border-radius: 50%;
  box-shadow: 0 0 0 4px #dc2626 inset, 0 0 22px rgba(220, 38, 38, 0.55);
  animation: check-alert 1.35s ease-in-out infinite;
  z-index: 5;
}

/* Piece token */
.xq-piece {
  position: relative;
  z-index: 3;
  display: grid;
  place-items: center;
  width: min(88%, 56px);
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  background:
    radial-gradient(circle at 36% 28%, #fffef9 0%, #f7ecd7 76%, #ead7b8 100%);
  border: 2.5px solid var(--xq-line);
  font-family: "Noto Serif CJK SC", "Microsoft YaHei", "SimSun", serif;
  font-size: clamp(16px, 5vw, 36px);
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 0 0 currentColor;
  box-shadow:
    inset 0 0 0 2px rgba(255,255,255,0.72),
    inset 0 -2px 3px rgba(90, 54, 28, 0.12),
    0 2px 5px rgba(0, 0, 0, 0.28);
  pointer-events: none;
  transition: transform 0.1s ease;
}

.xq-intersection:active .xq-piece {
  transform: scale(0.93);
}

.xq-piece.red {
  color: #c51f1f;
  border-color: #b91c1c;
  box-shadow:
    inset 0 0 0 2px rgba(255,255,255,0.72),
    inset 0 -2px 3px rgba(130, 30, 30, 0.10),
    0 2px 6px rgba(120, 20, 20, 0.26);
}

.xq-piece.black {
  color: #111827;
  border-color: #4b2d18;
}

/* Old geometry elements — now hidden always */
.xiangqi-geometry,
.river-label {
  display: none !important;
}

/* ==========================================================
   LIVE PIECE GUIDE CARD (In Side Panel)
   ========================================================== */
.piece-guide-card {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: all 0.2s ease;
}

.guide-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.guide-icon {
  font-size: 1.1rem;
}

.guide-header strong {
  font-size: 0.92rem;
  font-weight: 750;
  color: var(--accent);
}

.guide-text {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.45;
}

/* ==========================================================
   SIDE PANEL & INFORMATION CARDS
   ========================================================== */
.side-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: min(100%, 75dvh, 600px);
  margin: 0 auto;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  box-shadow: var(--shadow-sm);
}

/* Status Card */
.status-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.status-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.status-body strong {
  font-size: 1.1rem;
  font-weight: 800;
  display: block;
}

.status-subtext {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Bot Card */
.bot-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bot-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.88rem;
  font-weight: 700;
}

.select-input {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  color: var(--text-main);
  font-size: 0.88rem;
  font-weight: 600;
}

.difficulty-note {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Actions Card */
.actions-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  order: -1;
}

.action-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.action-buttons .btn.primary {
  grid-column: 1 / -1;
}

.live-decision-actions {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.live-decision-actions .btn {
  min-height: 46px;
}

.live-decision-actions #declineDrawBtn {
  grid-column: 1 / -1;
}

.draw-btn {
  background: #fff7ed;
  color: #9a3412;
  border-color: #fdba74;
}

[data-theme="dark"] .draw-btn {
  background: rgba(154, 52, 18, 0.22);
  color: #fdba74;
  border-color: rgba(253, 186, 116, 0.5);
}

.btn.danger-outline {
  background: transparent;
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 50%, var(--border));
}

.sub-actions {
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.sub-actions .sub-btn {
  flex: 1;
  text-align: center;
}

/* History Card */
.history-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.counter {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 600;
}

.captured-card {
  width: 100%;
  margin-top: 10px;
  display: grid;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  box-shadow: var(--shadow-sm);
}

.captured-row {
  display: grid;
  grid-template-columns: 76px 1fr;
  align-items: center;
  gap: 8px;
  min-height: 34px;
}

.captured-label {
  color: var(--text-muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.captured-pieces {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px;
  min-width: 0;
}

.captured-piece {
  display: inline-grid;
  place-items: center;
  width: 25px;
  height: 25px;
}

.captured-piece svg {
  width: 23px;
  height: 23px;
}

.captured-piece.xq-piece {
  border-width: 1px;
  font-size: 0.78rem;
}

.captured-empty {
  color: var(--text-subtle);
  font-size: 0.8rem;
}

.event-toast {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 120;
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(calc(100% - 24px), 440px);
  min-height: 58px;
  padding: 10px 14px;
  transform: translateX(-50%);
  border: 1px solid rgba(249, 115, 22, 0.7);
  border-radius: 15px;
  color: #fff;
  background: rgba(67, 34, 13, 0.96);
  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.35);
  font-weight: 750;
  animation: toast-in 220ms ease-out;
}

.event-toast-icon {
  display: grid;
  place-items: center;
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  font-size: 1.4rem;
}

.event-toast-icon .chess-svg {
  width: 36px;
  height: 36px;
}

.event-toast-icon .xq-piece {
  width: 36px;
  height: 36px;
  color: #fff;
  border-color: currentColor;
}

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 16px) scale(0.97); }
  to { opacity: 1; transform: translate(-50%, 0) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .square.capture-event,
  .square.in-check,
  .event-toast,
  .pulse-dot {
    animation: none;
  }
}

.history-list {
  max-height: 160px;
  overflow-y: auto;
  font-variant-numeric: tabular-nums;
  display: flex;
  flex-direction: column;
}

.move-row {
  display: grid;
  grid-template-columns: 36px 1fr 1fr;
  padding: 6px 4px;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.move-row .num {
  color: var(--text-subtle);
  font-weight: 600;
}

.empty-state {
  color: var(--text-subtle);
  font-size: 0.85rem;
  text-align: center;
  padding: 12px 0;
}

/* ==========================================================
   FULLSCREEN MODE (Clean / No HUD)
   ========================================================== */
.fullscreen-hud {
  position: fixed;
  top: 14px;
  left: 14px;
  right: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 100;
  pointer-events: none;
}

.fs-turn-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: var(--radius-full);
  background: rgba(15, 23, 42, 0.85);
  color: #ffffff;
  backdrop-filter: blur(8px);
  font-size: 0.84rem;
  font-weight: 700;
  box-shadow: var(--shadow-md);
  pointer-events: auto;
}

.fs-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
}

.fs-btn {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.85);
  color: #ffffff;
  backdrop-filter: blur(8px);
  font-size: 1.2rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: var(--shadow-md);
  cursor: pointer;
}

.fs-btn:active {
  transform: scale(0.94);
}

.fs-btn.exit-btn {
  background: rgba(220, 38, 38, 0.88);
}

/* When Fullscreen is Active */
body.fullscreen-active {
  background: #000000 !important;
  overflow: hidden;
}

body.fullscreen-active .topbar,
body.fullscreen-active .side-panel,
body.fullscreen-active .piece-guide-card {
  display: none !important;
}

body.fullscreen-active .app-shell {
  padding: 0;
  max-width: 100vw;
  height: 100dvh;
  justify-content: center;
  align-items: center;
}

body.fullscreen-active .game-layout {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 6px;
  padding: 10px;
}

body.fullscreen-active .board-panel {
  height: 100%;
  justify-content: center;
}

body.fullscreen-active .board-wrap {
  max-width: min(94vw, 86dvh);
  border-width: 4px;
}

body.fullscreen-active .player-bar {
  max-width: min(94vw, 86dvh);
  color: #ffffff;
}

body.fullscreen-active .player-badge {
  background: rgba(255, 255, 255, 0.15);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.25);
}

/* Leave room confirmation */
.leave-room-box {
  width: min(88vw, 420px);
  padding: 24px;
  display: grid;
  gap: 12px;
  text-align: center;
}

.leave-room-icon {
  width: 52px;
  height: 52px;
  margin: 0 auto 2px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: color-mix(in srgb, var(--danger) 12%, var(--surface));
  color: var(--danger);
  font-size: 1.45rem;
  font-weight: 800;
}

.leave-room-box p {
  color: var(--text-muted);
  line-height: 1.5;
  font-size: 0.9rem;
}

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

/* Dialogs */
dialog {
  border: none;
  border-radius: var(--radius-lg);
  padding: 0;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  color: var(--text-main);
  max-width: 90vw;
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
}

.promotion-box {
  padding: 20px;
}

.promotion-box h3 {
  margin-bottom: 14px;
  text-align: center;
}

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

.promotion-choices button {
  width: 60px;
  height: 60px;
  padding: 6px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  box-shadow: var(--shadow-sm);
  display: grid;
  place-items: center;
}

/* ==========================================================
   MEDIA QUERY: TABLET ENHANCEMENT (min-width: 768px)
   ========================================================== */
@media (min-width: 768px) {
  .tycoon-seat-cards {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tycoon-live-lobby-actions {
    grid-template-columns: auto auto;
    align-items: center;
    justify-content: center;
  }

  .tycoon-live-lobby-actions small {
    grid-column: 1 / -1;
  }

  .tycoon-online-room-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tycoon-online-room-actions > div {
    grid-column: 1 / -1;
  }

  .topbar {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
  }

  .topbar-nav {
    width: auto;
  }

  .header-main-row {
    width: auto;
    flex: 1;
    justify-content: flex-start;
  }

  .header-main-row h1 {
    font-size: 1.45rem;
  }

  .header-status-pill {
    flex: initial;
    max-width: max-content;
    padding: 5px 14px;
    gap: 8px;
  }

  .header-status-pill strong {
    font-size: 0.92rem;
  }

  .room-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .app-shell {
    padding: 16px 20px 28px;
  }
  
  h1 {
    font-size: 1.45rem;
  }
  
  .game-cards, .mode-cards, .side-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
  }
  
  .mode-cards {
    grid-template-columns: repeat(3, 1fr);
  }
  
  .game-card, .mode-card, .side-card {
    padding: 20px;
  }
  
  .game-symbol, .mode-icon, .side-symbol {
    width: 60px;
    height: 60px;
    font-size: 2.3rem;
  }
  
  .side-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
  
  .history-card {
    grid-column: 1 / -1;
  }
}

/* ==========================================================
   MEDIA QUERY: DESKTOP OPTIMIZATION (min-width: 1024px)
   ========================================================== */
@media (min-width: 1024px) {
  .topbar {
    margin-bottom: 6px;
  }
  
  .game-picker, .mode-picker, .side-picker {
    max-width: 860px;
    margin: 36px auto 0;
  }
  
  .picker-intro h2 {
    font-size: 2rem;
  }
  
  /* Two-column layout: Board left, Sidebar right */
  .game-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 32px;
    align-items: start;
    margin-top: 8px;
  }
  
  .board-panel {
    width: 100%;
  }
  
  .side-panel {
    display: flex;
    flex-direction: column;
    gap: 14px;
  }

  .actions-card {
    order: initial;
  }
  
  .history-card {
    grid-column: auto;
    min-height: 220px;
  }
  
  .history-list {
    max-height: 260px;
  }
  
  .board-wrap {
    border-width: 8px;
  }
  
  .chess-board-wrap {
    max-width: min(75dvh, 660px);
  }
  
  .xiangqi-board-wrap {
    max-width: min(80dvh, 594px);
  }
  
  .coord {
    font-size: 10px;
  }
}

/* ==========================================================
   MEDIA QUERY: LARGE DESKTOP (min-width: 1440px)
   ========================================================== */
@media (min-width: 1440px) {
  .app-shell {
    max-width: 1360px;
  }
  
  .game-layout {
    grid-template-columns: minmax(0, 1fr) 380px;
    gap: 40px;
  }
  
  .chess-board-wrap {
    max-width: min(78dvh, 720px);
  }
  
  .xiangqi-board-wrap {
    max-width: min(82dvh, 648px);
  }
}


/* Network-pending interaction lock */
.board.pending,
.xiangqi-board.pending {
  pointer-events: none;
  cursor: progress;
  opacity: 0.985;
}

@media (max-width: 767px) {
  .player-bar {
    max-width: 100%;
  }

  .sub-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .sub-actions .sub-btn {
    min-width: 0;
    min-height: 42px;
    padding-inline: 6px;
    white-space: normal;
  }
}


.board-error {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  color: var(--danger);
  background: var(--surface);
  font-weight: 800;
}


/* ==========================================================
   CARO + TYCOON EXTENSIONS
   ========================================================== */
.game-card:disabled,
.mode-card:disabled,
.game-card.is-disabled,
.mode-card.is-disabled {
  opacity: 0.52;
  cursor: not-allowed;
  box-shadow: none;
}

.game-card:disabled .arrow,
.mode-card:disabled .arrow {
  display: none;
}

.caro-symbol {
  font-weight: 900;
  color: var(--accent);
}

.tycoon-symbol {
  font-size: 1.6rem;
}

/* Caro: exact square geometry, full 15 x 15 board visible on mobile. */
.caro-board-wrap {
  width: 100%;
  max-width: min(100%, 75dvh, 640px);
  aspect-ratio: 1 / 1;
  background: #e7c99b;
  border: 7px solid #5c3818;
  border-radius: 4px;
  box-shadow:
    0 18px 45px rgba(0, 0, 0, 0.45),
    inset 0 0 14px rgba(0, 0, 0, 0.22);
}

.caro-board {
  aspect-ratio: 1 / 1;
  grid-template-columns: repeat(15, minmax(0, 1fr));
  grid-template-rows: repeat(15, minmax(0, 1fr));
  background: #e7c99b;
}

.caro-cell {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border-right: 1px solid rgba(92, 59, 28, 0.52);
  border-bottom: 1px solid rgba(92, 59, 28, 0.52);
  background: transparent;
  line-height: 1;
}

.caro-cell:nth-child(15n) {
  border-right: 0;
}

.caro-cell.last {
  background: rgba(250, 204, 21, 0.35);
}

.caro-cell.winning {
  background: rgba(34, 197, 94, 0.28);
}

.caro-stone {
  display: grid;
  place-items: center;
  width: 78%;
  height: 78%;
  font-size: clamp(0.78rem, 4.6vw, 1.9rem);
  font-weight: 900;
  pointer-events: none;
}

.caro-stone.x {
  color: #1d4ed8;
}

.caro-stone.o {
  width: 68%;
  height: 68%;
  border: clamp(2px, 0.5vw, 4px) solid #dc2626;
  border-radius: 50%;
  color: transparent;
}

[data-theme="dark"] .caro-board-wrap,
[data-theme="dark"] .caro-board {
  background: #bd9869;
}

.player-bar.caro-player-bar {
  max-width: min(100%, 75dvh, 640px);
}

/* Tycoon: 40-tile Vietnam board, inspired by classic printed property-trading boards. */
.tycoon-layout {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.tycoon-board-panel,
.tycoon-side-panel {
  width: 100%;
  min-width: 0;
}

.tycoon-side-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tycoon-topbar {
  display: grid;
  grid-template-columns: 1.5fr 1fr 0.7fr;
  gap: 10px;
  margin-bottom: 10px;
}

.tycoon-topbar > div {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 3px;
}

.muted-label {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.tycoon-topbar strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tycoon-board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(11, minmax(0, 1fr));
  grid-template-rows: repeat(11, minmax(0, 1fr));
  width: 100%;
  max-width: min(100%, 900px);
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  overflow: hidden;
  border: clamp(3px, 0.7vw, 7px) solid #202020;
  border-radius: 3px;
  background: #ffdc27;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.24);
  isolation: isolate;
}

.tycoon-center {
  position: relative;
  grid-row: 2 / span 9;
  grid-column: 2 / span 9;
  display: grid;
  place-items: center;
  align-content: center;
  gap: clamp(3px, 1vw, 10px);
  padding: clamp(10px, 3vw, 34px);
  overflow: hidden;
  text-align: center;
  color: #172033;
  background:
    radial-gradient(ellipse at 50% 50%, rgba(255, 255, 255, 0.6) 0%, rgba(255, 225, 45, 0.88) 100%),
    linear-gradient(rgba(255, 232, 59, 0.72), rgba(255, 201, 27, 0.82)),
    url('assets/tycoon-bg.jpg') center/cover no-repeat;
  border: 1px solid #2d2d2d;
  pointer-events: none;
}

.tycoon-center::before,
.tycoon-center::after {
  content: '';
  position: absolute;
  border: clamp(2px, 0.35vw, 4px) dashed rgba(90, 57, 20, 0.42);
  border-radius: 50%;
  pointer-events: none;
}

.tycoon-center::before {
  width: 52%;
  height: 24%;
  top: 16%;
  left: -8%;
  transform: rotate(12deg);
}

.tycoon-center::after {
  width: 44%;
  height: 20%;
  right: -5%;
  bottom: 11%;
  transform: rotate(-14deg);
}

.tycoon-center-sky {
  position: absolute;
  inset: 8% 8% auto;
  display: flex;
  justify-content: space-between;
  color: #7b4317;
  font-size: clamp(0.8rem, 3.6vw, 2.6rem);
  opacity: 0.8;
}

.tycoon-center-title {
  position: relative;
  z-index: 2;
  padding: clamp(4px, 1.1vw, 12px) clamp(8px, 2.1vw, 24px);
  transform: rotate(-2deg);
  border: clamp(2px, 0.45vw, 5px) solid #202020;
  background: #e32629;
  color: #fff;
  box-shadow:
    inset 0 0 0 clamp(1px, 0.25vw, 3px) #fff,
    0 clamp(3px, 0.65vw, 7px) 0 #8b171a;
  font-size: clamp(1.05rem, 6vw, 4.4rem);
  font-weight: 1000;
  letter-spacing: -0.055em;
  line-height: 1;
  text-shadow: 0 2px 0 #741013;
}

.tycoon-center-brand {
  position: relative;
  z-index: 2;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.86);
  color: #17375e;
  font-size: clamp(0.44rem, 1.5vw, 0.88rem);
  font-weight: 900;
  letter-spacing: 0.12em;
}

.tycoon-center-copy {
  position: relative;
  z-index: 2;
  max-width: 32rem;
  color: #4f3718;
  font-size: clamp(0.4rem, 1.6vw, 0.9rem);
  font-weight: 750;
}

.tycoon-center-card {
  position: absolute;
  z-index: 1;
  display: grid;
  place-items: center;
  width: clamp(28px, 10vw, 96px);
  aspect-ratio: 0.72;
  border: clamp(1px, 0.3vw, 3px) solid #fff;
  border-radius: clamp(3px, 0.7vw, 9px);
  color: #fff;
  font-size: clamp(1rem, 5vw, 3.6rem);
  font-weight: 1000;
  box-shadow: 0 4px 10px rgba(0,0,0,0.24);
}

.tycoon-center-card.chance {
  left: 10%;
  top: 25%;
  transform: rotate(-15deg);
  background: #1688d4;
}

.tycoon-center-card.community {
  right: 10%;
  top: 23%;
  transform: rotate(14deg);
  background: #e64a32;
}

.tycoon-tile {
  --owner-color: transparent;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  gap: 1px;
  min-width: 0;
  min-height: 0;
  padding: clamp(2px, 0.4vw, 4px);
  overflow: hidden;
  appearance: none;
  border: 1px solid #202020;
  border-radius: 0;
  background: #f9f8e8;
  color: #161616;
  font: inherit;
  font-size: clamp(0.34rem, 1.35vw, 0.68rem);
  line-height: 1.02;
  text-align: center;
  cursor: pointer;
  touch-action: manipulation;
}

.tycoon-tile:hover {
  filter: brightness(0.98);
}

.tycoon-tile:focus-visible {
  outline: 3px solid #2563eb;
  outline-offset: -3px;
  z-index: 5;
}

.tycoon-tile.corner {
  background: #fff4a9;
  font-weight: 900;
}

.tycoon-tile.start {
  background: #fff7c7;
}

.tycoon-tile.jail {
  background: #ffe5a5;
}

.tycoon-tile.free {
  background: #e1f3d6;
}

.tycoon-tile.goto-jail {
  background: #ffe2ab;
}

.tycoon-tile.chance {
  background: #fff5d2;
}

.tycoon-tile.community {
  background: #ecf8ff;
}

.tycoon-tile.tax {
  background: #e8f4fa;
}

.tycoon-tile.railroad {
  background: #f7f3e4;
}

.tycoon-tile.utility {
  background: #eaf8d8;
}

.tycoon-color-band {
  display: block;
  width: calc(100% + clamp(4px, 0.8vw, 8px));
  height: clamp(4px, 0.75vw, 8px);
  margin: calc(clamp(2px, 0.4vw, 4px) * -1) calc(clamp(2px, 0.4vw, 4px) * -1) 1px;
  flex: 0 0 auto;
  border-bottom: 1px solid rgba(0,0,0,0.5);
}

.tycoon-tile-icon {
  display: block;
  min-height: 0.9em;
  color: #111;
  font-size: clamp(0.48rem, 1.8vw, 1rem);
  font-weight: 900;
  line-height: 1;
}

.tycoon-tile.chance .tycoon-tile-icon {
  color: #e4312b;
  font-size: clamp(0.9rem, 4vw, 2.3rem);
}

.tycoon-tile.community .tycoon-tile-icon {
  color: #1677bd;
}

.tycoon-tile-name {
  display: -webkit-box;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  font-weight: 850;
  line-height: 1;
  text-transform: uppercase;
  line-clamp: 4;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
}

.tycoon-tile.property .tycoon-tile-name {
  text-transform: none;
}

.tycoon-tile.name-long .tycoon-tile-name {
  font-size: 0.9em;
  letter-spacing: -0.01em;
}

.tycoon-tile.name-xlong .tycoon-tile-name {
  font-size: 0.82em;
  letter-spacing: -0.02em;
}

.tycoon-tile-meta {
  flex: 0 0 auto;
  margin-top: auto;
  overflow: hidden;
  color: #373737;
  font-size: 0.74em;
  font-weight: 750;
  line-height: 1;
  white-space: nowrap;
  text-overflow: clip;
}

.tycoon-tile.current {
  outline: clamp(2px, 0.5vw, 5px) solid #ff9f00;
  outline-offset: calc(clamp(2px, 0.5vw, 5px) * -1);
  z-index: 4;
  box-shadow: inset 0 0 0 2px #fff;
}

.tycoon-tile.selected {
  box-shadow: inset 0 0 0 3px rgba(37, 99, 235, 0.72);
  z-index: 3;
}

.tycoon-owner {
  position: absolute;
  inset: auto 0 0;
  height: clamp(3px, 0.55vw, 6px);
  background: var(--owner-color);
  box-shadow: 0 -1px 0 rgba(0,0,0,0.22);
}

.tycoon-development {
  overflow: hidden;
  min-height: 0.9em;
  color: #165d23;
  font-size: clamp(0.35rem, 1.4vw, 0.72rem);
  line-height: 1;
  white-space: nowrap;
}

.tycoon-token-row {
  position: absolute;
  right: 2px;
  bottom: clamp(4px, 0.8vw, 8px);
  left: 2px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1px;
  pointer-events: none;
}

.tycoon-token {
  display: grid;
  place-items: center;
  width: clamp(11px, 2.7vw, 24px);
  height: clamp(11px, 2.7vw, 24px);
  border: 1.5px solid #fff;
  border-radius: 50%;
  background: var(--token-color);
  color: #fff;
  font-size: 0.72em;
  font-weight: 1000;
  box-shadow: 0 1px 3px rgba(0,0,0,0.38);
}

.tycoon-dice {
  display: grid;
  place-items: center;
  min-height: 70px;
  margin: 10px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 214, 39, 0.18), transparent 65%),
    var(--surface-subtle);
  font-size: 2.4rem;
  letter-spacing: 0.22em;
}

.tycoon-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.tycoon-setup-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: end;
  gap: 8px;
  margin-top: 10px;
}

.tycoon-setup-row label,
.tycoon-asset-picker {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.78rem;
  font-weight: 700;
}

.tycoon-event-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: center;
  border-left: 5px solid #f59e0b;
}

.tycoon-event-card strong {
  color: #b45309;
  font-size: 0.78rem;
}

.tycoon-event-card span {
  color: var(--text);
  font-size: 0.84rem;
  line-height: 1.45;
}

.tycoon-management-card {
  display: grid;
  gap: 10px;
}

.tycoon-asset-detail {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-subtle);
  color: var(--text-muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.tycoon-asset-detail strong {
  color: var(--text);
  font-size: 0.88rem;
}

.tycoon-manage-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 7px;
}

.tycoon-build-hint {
  margin: 0;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
  color: var(--text-muted);
  font-size: 0.76rem;
  font-weight: 650;
  line-height: 1.45;
}

.tycoon-build-hint.is-ready {
  border-color: color-mix(in srgb, var(--success) 42%, var(--border));
  background: color-mix(in srgb, var(--success-bg) 68%, var(--surface));
  color: color-mix(in srgb, var(--success) 82%, var(--text-main));
}

.tycoon-build-hint.is-blocked {
  border-color: color-mix(in srgb, var(--warning) 34%, var(--border));
}

.tycoon-rule-note {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.72rem;
  line-height: 1.45;
}

.tycoon-player-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.tycoon-player {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: var(--surface-subtle);
}

.tycoon-player.active {
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}

.tycoon-player.bankrupt {
  opacity: 0.5;
  text-decoration: line-through;
}

.tycoon-player-token {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 2px solid rgba(255,255,255,0.9);
  border-radius: 50%;
  background: var(--token-color);
  color: #fff;
  font-weight: 1000;
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
}

.tycoon-player-copy {
  min-width: 0;
}

.tycoon-player-copy strong,
.tycoon-player-copy small {
  display: block;
}

.tycoon-player-copy small {
  margin-top: 2px;
  overflow: hidden;
  color: var(--text-muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tycoon-player-cash {
  font-weight: 850;
  white-space: nowrap;
}

.tycoon-log-card .history-list {
  --tycoon-log-row-height: 44px;
  max-height: calc(var(--tycoon-log-row-height) * 5);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.tycoon-log-entry {
  box-sizing: border-box;
  min-height: var(--tycoon-log-row-height);
  height: var(--tycoon-log-row-height);
  padding: 5px 2px;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.8rem;
  line-height: 1.35;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

@media (min-width: 520px) {
  .tycoon-actions,
  .tycoon-manage-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tycoon-setup-row {
    grid-template-columns: minmax(0, 1fr) auto auto;
  }
}

@media (min-width: 768px) {
  .tycoon-tile {
    padding: 4px;
  }

  .tycoon-color-band {
    width: calc(100% + 8px);
    margin: -4px -4px 2px;
  }
}

@media (min-width: 1024px) {
  .tycoon-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 380px;
    gap: 28px;
    align-items: start;
  }

  .tycoon-board-panel {
    position: sticky;
    top: 82px;
  }

  .tycoon-board {
    max-width: min(84dvh, 900px);
  }

  .tycoon-log-card .history-list {
    max-height: calc(var(--tycoon-log-row-height) * 5);
  }
}



/* ==========================================================
   LIVE LOBBY UX HARDENING — v2.4.2
   ========================================================== */
.tycoon-seat-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.tycoon-seat-card {
  min-width: 0;
  min-height: 88px;
  padding: 12px;
  gap: 10px;
}

.tycoon-seat-card .side-symbol {
  width: 42px;
  height: 42px;
  font-size: 1.35rem;
}

.tycoon-seat-card .side-copy {
  min-width: 0;
}

.tycoon-seat-card .side-copy strong {
  font-size: 0.92rem;
}

.tycoon-seat-card .side-copy small {
  font-size: 0.74rem;
}

.tycoon-seat-card.is-pending {
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent), var(--shadow-md);
}

button[aria-busy="true"] {
  cursor: progress;
}

button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 3px solid var(--border-focus);
  outline-offset: 2px;
}

@media (max-width: 767px) {
  .tycoon-live-lobby-actions {
    position: sticky;
    z-index: 20;
    bottom: max(8px, env(safe-area-inset-bottom));
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-md);
  }

  .tycoon-live-lobby-actions .btn {
    width: 100%;
  }
}

@media (hover: hover) and (pointer: fine) {
  .game-card:not(:disabled):hover,
  .mode-card:not(:disabled):hover,
  .side-card:not(:disabled):hover {
    transform: translateY(-1px);
    border-color: var(--border-focus);
    box-shadow: var(--shadow-md);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}


/* ==========================================================
   LIVE ROOM DIRECTORY / MANAGEMENT
   ========================================================== */
.room-directory {
  width: min(100%, 880px);
  margin: 18px auto 0;
  padding: 16px;
  display: grid;
  gap: 14px;
}

.room-directory-head {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.room-directory-head > div {
  display: grid;
  gap: 4px;
}

.room-directory-head h3,
.room-directory-head p {
  margin: 0;
}

.room-directory-head p,
.room-directory-summary span {
  color: var(--text-muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.room-directory-toolbar {
  display: grid;
  gap: 12px;
}

.room-scope-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-subtle);
}

.room-scope-tab {
  min-height: 42px;
  border: 0;
  border-radius: 10px;
  padding: 8px 10px;
  color: var(--text-muted);
  background: transparent;
  font: inherit;
  font-size: 0.84rem;
  font-weight: 750;
  cursor: pointer;
}

.room-scope-tab.active {
  color: var(--text-main);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.room-directory-filters {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.room-directory-filters label {
  display: grid;
  gap: 6px;
  color: var(--text-muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.room-directory-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 2px;
}

.room-directory-summary strong {
  white-space: nowrap;
  font-size: 0.86rem;
}

.room-directory-list {
  display: grid;
  gap: 10px;
}

.room-directory-state {
  display: grid;
  place-items: center;
  min-height: 116px;
  padding: 20px;
  border: 1px dashed var(--border);
  border-radius: 14px;
  color: var(--text-muted);
  text-align: center;
  font-size: 0.86rem;
}

.room-directory-state.error {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 42%, var(--border));
}

.room-list-card {
  display: grid;
  gap: 11px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.room-list-card.status-active {
  border-color: color-mix(in srgb, var(--success) 45%, var(--border));
}

.room-list-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.room-list-identity {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.room-game-name {
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 700;
}

.room-code {
  overflow: hidden;
  font-size: 1.05rem;
  letter-spacing: 0.08em;
  text-overflow: ellipsis;
}

.room-status-badge,
.room-owner-chip {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-subtle);
  font-size: 0.72rem;
  font-weight: 800;
  white-space: nowrap;
}

.room-status-badge.status-active {
  color: var(--success);
  border-color: color-mix(in srgb, var(--success) 38%, var(--border));
  background: color-mix(in srgb, var(--success) 8%, var(--surface));
}

.room-status-badge.status-waiting {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 38%, var(--border));
}

.room-status-badge.status-finished,
.room-status-badge.status-abandoned {
  color: var(--text-muted);
}

.room-list-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  color: var(--text-muted);
  font-size: 0.76rem;
}

.room-owner-chip {
  min-height: 22px;
  padding-block: 2px;
  color: var(--primary);
}

.room-list-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.room-list-actions .room-card-action {
  min-height: 42px;
  padding: 8px 10px;
}

.room-list-actions .danger-outline {
  grid-column: 1 / -1;
}

@media (min-width: 640px) {
  .room-directory {
    padding: 20px;
  }

  .room-directory-head {
    flex-direction: row;
    align-items: flex-start;
    justify-content: space-between;
  }

  .room-directory-filters {
    grid-template-columns: 1fr 1fr;
  }

  .room-list-card {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
  }

  .room-list-card-top,
  .room-list-meta {
    grid-column: 1;
  }

  .room-list-actions {
    grid-column: 2;
    grid-row: 1 / span 2;
    grid-template-columns: repeat(2, minmax(112px, auto));
  }

  .room-list-actions .danger-outline {
    grid-column: 1 / -1;
  }
}

@media (min-width: 900px) {
  .room-directory-toolbar {
    grid-template-columns: minmax(300px, 1fr) minmax(360px, 1fr);
    align-items: end;
  }
}


/* ==========================================================
   HOME LIVE DIRECTORY — GLOBAL ROOM DISCOVERY
   ========================================================== */
.home-room-directory {
  margin-top: 10px;
}

.home-room-directory .room-directory-head h3 {
  font-size: 1.05rem;
}

.room-directory-notice {
  min-height: 20px;
  margin: 0;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 650;
  line-height: 1.4;
}

.room-list-freshness {
  color: var(--text-subtle);
}

.home-room-directory .room-list-card {
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

@media (hover: hover) and (pointer: fine) {
  .home-room-directory .room-list-card:hover {
    border-color: color-mix(in srgb, var(--accent) 32%, var(--border));
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
  }
}

@media (min-width: 1024px) {
  /* Keep the four game choices compact while letting the LIVE directory use
     the wider area directly below them, matching the dashboard hierarchy. */
  .game-picker {
    max-width: 980px;
  }

  .game-picker > .picker-intro,
  .game-picker > .game-cards {
    width: min(100%, 860px);
    margin-inline: auto;
  }

  .home-room-directory {
    width: 100%;
    max-width: 980px;
  }
}


/* ==========================================================
   UX/UI RESPONSIVE SYSTEM — v2.9.0
   Mobile-first ergonomics + desktop density optimization.
   ========================================================== */
:root {
  --touch-target: 44px;
  --control-height: 46px;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

.app-shell {
  padding-top: max(8px, env(safe-area-inset-top));
  padding-left: max(12px, env(safe-area-inset-left));
  padding-right: max(12px, env(safe-area-inset-right));
}

.text-btn,
.sub-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch-target);
}

.text-input,
.select-input {
  min-height: var(--control-height);
}

.select-input {
  width: 100%;
  min-width: 0;
}

.room-scope-tab,
.room-list-actions .room-card-action {
  min-height: var(--touch-target);
}

.fs-btn {
  width: var(--touch-target);
  height: var(--touch-target);
}

.game-card,
.mode-card,
.side-card,
.game-card-copy,
.mode-card-copy,
.side-copy {
  min-width: 0;
}

.room-list-meta > span:not(.room-owner-chip) {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 7px;
  border-radius: var(--radius-full);
  background: var(--surface-subtle);
}

.room-owner-chip {
  background: var(--accent-light);
  border-color: color-mix(in srgb, var(--accent) 28%, var(--border));
  color: var(--accent);
}

.room-status-badge {
  min-height: 28px;
}

@media (max-width: 767px) {
  input,
  select,
  textarea {
    font-size: 16px !important;
  }

  .picker-intro {
    padding: 8px 2px 0;
    text-align: left;
  }

  .picker-intro h2 {
    font-size: clamp(1.25rem, 5.5vw, 1.5rem);
    line-height: 1.16;
  }

  .picker-intro p {
    font-size: 0.86rem;
    line-height: 1.5;
  }

  .game-card,
  .mode-card,
  .side-card {
    min-height: 78px;
    gap: 12px;
    padding: 14px;
  }

  .game-symbol,
  .mode-icon,
  .side-symbol {
    width: 48px;
    height: 48px;
    font-size: 1.8rem;
  }

  .game-card-copy strong,
  .mode-card-copy strong,
  .side-copy strong {
    font-size: 1rem;
  }

  .arrow {
    font-size: 1.15rem;
  }

  .room-grid {
    gap: 12px;
  }

  .room-form {
    gap: 14px;
    padding: 16px;
  }

  .room-directory {
    gap: 12px;
    margin-top: 10px;
    padding: 14px;
    border-radius: 18px;
  }

  .room-directory-head {
    gap: 10px;
  }

  .room-directory-head .sub-btn {
    width: 100%;
  }

  .room-directory-filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .room-directory-summary {
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
  }

  .room-list-card {
    gap: 10px;
    padding: 12px;
  }

  .room-list-meta {
    gap: 6px;
  }

  .room-list-actions {
    gap: 8px;
  }

  .room-list-actions .room-card-action {
    min-width: 0;
  }

  .room-toolbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
    margin-bottom: 12px;
    padding: 12px 14px;
  }

  .room-toolbar > div,
  .room-toolbar > .sub-btn,
  .room-toolbar > .check-row {
    width: 100%;
  }

  .room-toolbar .sub-btn {
    justify-content: center;
  }

  .board-panel {
    max-width: min(100%, 86dvh, 620px);
  }

  .side-panel {
    max-width: min(100%, 620px);
  }

  .captured-card {
    margin-top: 8px;
    padding-inline: 12px;
  }

  .sub-actions .sub-btn {
    min-height: 48px;
    font-size: 0.78rem;
    line-height: 1.25;
  }

  .event-toast {
    width: min(calc(100% - 20px), 440px);
    bottom: max(10px, env(safe-area-inset-bottom));
  }

  .leave-room-box {
    width: min(calc(100vw - 28px), 420px);
    padding: 20px;
  }

  .tycoon-topbar {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
  }

  .tycoon-topbar > div:first-child {
    grid-column: 1 / -1;
  }

  .tycoon-topbar strong {
    font-size: 0.9rem;
  }

  .tycoon-player-cash {
    font-size: 0.82rem;
  }
}

@media (max-width: 380px) {
  .room-directory-filters {
    grid-template-columns: 1fr;
  }

  .tycoon-center-copy {
    display: none;
  }

  .tycoon-center-brand {
    padding: 2px 6px;
    font-size: 0.38rem;
  }

  .tycoon-seat-card {
    min-height: 82px;
    padding: 10px;
  }

  .captured-row {
    grid-template-columns: 68px minmax(0, 1fr);
  }
}

@media (min-width: 768px) and (max-width: 1023px) {
  .board-panel,
  .side-panel {
    max-width: min(100%, 80dvh, 680px);
  }

  .room-directory {
    max-width: 920px;
  }
}

@media (orientation: landscape) and (max-width: 1023px) and (max-height: 600px) {
  .game-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(250px, 300px);
    align-items: start;
    gap: 14px;
  }

  .board-panel {
    max-width: min(86dvh, 100%);
    margin: 0 auto;
  }

  .side-panel {
    max-width: none;
    max-height: calc(100dvh - 88px);
    margin: 0;
    padding-right: 2px;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .history-list {
    max-height: 120px;
  }
}

@media (min-width: 1024px) {
  .game-picker {
    max-width: 1080px;
  }

  .game-picker > .picker-intro,
  .game-picker > .game-cards {
    width: min(100%, 900px);
  }

  .home-room-directory {
    max-width: 1080px;
    padding: 22px 24px;
  }

  .home-room-directory .room-directory-list {
    grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  }

  .home-room-directory .room-list-card {
    grid-template-columns: minmax(0, 1fr);
    align-items: start;
  }

  .home-room-directory .room-list-card-top,
  .home-room-directory .room-list-meta,
  .home-room-directory .room-list-actions {
    grid-column: 1;
    grid-row: auto;
  }

  .home-room-directory .room-list-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .game-layout {
    width: 100%;
    max-width: 1180px;
    margin: 10px auto 0;
    grid-template-columns: minmax(520px, 1fr) minmax(320px, 360px);
    gap: 28px;
  }

  .board-panel {
    max-width: min(100%, 82dvh, 720px);
    margin: 0 auto;
  }

  .side-panel {
    max-width: none;
    margin: 0;
  }

  .chess-board-wrap {
    max-width: min(82dvh, 720px);
  }
}

@media (min-width: 1440px) {
  .game-layout {
    max-width: 1280px;
    grid-template-columns: minmax(620px, 1fr) 380px;
    gap: 36px;
  }

  .board-panel {
    max-width: min(100%, 84dvh, 760px);
  }

  .chess-board-wrap {
    max-width: min(84dvh, 760px);
  }
}


/* ==========================================================
   HOME QUICK CREATE + HOST GAME SWITCH — v3.0.0
   ========================================================== */
.room-directory-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.home-toggle-create-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 6px 14px;
  font-weight: 750;
  white-space: nowrap;
  font-size: 0.84rem;
  box-shadow: 0 2px 8px color-mix(in srgb, var(--primary) 28%, transparent);
  transition: all 0.18s ease;
}

.home-toggle-create-btn.active {
  background: var(--surface-subtle);
  color: var(--text-main);
  border-color: var(--border);
  box-shadow: none;
}

.home-quick-create {
  width: min(100%, 1080px);
  margin: 0 auto;
  padding: 18px;
  display: grid;
  gap: 14px;
}

.home-quick-create:not(.hidden) {
  animation: quickCreateEnter 0.24s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.home-quick-create-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

#homeCloseQuickCreateBtn {
  min-height: 34px;
  padding: 4px 12px;
  font-size: 0.8rem;
  border-radius: 999px;
  color: var(--text-muted);
}

#homeCloseQuickCreateBtn:hover {
  color: var(--text-main);
  background: var(--surface-subtle);
}

.home-quick-create-head > div {
  display: grid;
  gap: 4px;
}

.home-quick-create-head h3 {
  font-size: 1.05rem;
}

.home-quick-create-head p {
  color: var(--text-muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

.home-quick-create-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.home-quick-create-form > label:not(.check-row) {
  display: grid;
  gap: 6px;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.home-quick-create-options {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px 10px;
}

.home-quick-create .form-error.compact,
.change-room-game-box .form-error.compact {
  min-height: 18px;
  margin: 0;
  text-align: left;
  font-size: 0.78rem;
}

.change-room-game-box {
  width: min(calc(100vw - 28px), 480px);
  padding: 22px;
  display: grid;
  gap: 12px;
}

.change-room-game-box > p {
  color: var(--text-muted);
  font-size: 0.88rem;
  line-height: 1.5;
  text-align: center;
}

.change-room-game-form {
  display: grid;
  gap: 12px;
}

.change-room-game-form > label:not(.check-row) {
  display: grid;
  gap: 6px;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 700;
}

@media (min-width: 640px) {
  .home-quick-create {
    padding: 20px 22px;
  }

  .home-quick-create-form {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: end;
  }

  .home-quick-create-options {
    grid-column: 1 / span 2;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .home-quick-create-form > .btn.primary {
    grid-column: 3;
  }

  .home-quick-create-form > .form-error {
    grid-column: 1 / -1;
  }
}

@media (min-width: 1024px) {
  .home-quick-create {
    max-width: 1080px;
    padding: 22px 24px;
  }
}

@media (max-width: 767px) {
  .home-quick-create {
    padding: 14px;
    border-radius: 18px;
  }

  .home-quick-create-form > .btn.primary {
    width: 100%;
    min-height: 48px;
  }

  .change-room-game-box {
    padding: 18px;
  }
}


/* ==========================================================
   IVS DESIGN SYSTEM — v3.1.0
   Semantic light/dark contrast + adaptive layouts.
   This layer intentionally comes last so every game inherits the
   same accessibility, surface, control and responsive contracts.
   ========================================================== */
:root {
  --bg: #f4f7fb;
  --bg-gradient: linear-gradient(180deg, #f7f9fc 0%, #edf2f7 100%);
  --surface: #ffffff;
  --surface-elevated: #ffffff;
  --surface-subtle: #eef2f7;
  --surface-glass: rgba(255, 255, 255, 0.96);
  --surface-hover: #e8eef6;

  --border: #cbd5e1;
  --border-strong: #94a3b8;
  --border-focus: #2563eb;

  --text-main: #0f172a;
  --text-muted: #475569;
  --text-subtle: #64748b;
  --text-on-action: #ffffff;

  --action-primary: #111827;
  --action-primary-hover: #1f2937;
  --action-danger: #dc2626;
  --action-danger-hover: #b91c1c;

  --success: #15803d;
  --success-bg: #dcfce7;
  --warning: #92400e;
  --warning-bg: #fef3c7;
  --warning-border: #f59e0b;
  --danger: #b91c1c;
  --danger-bg: #fee2e2;

  --disabled-bg: #e2e8f0;
  --disabled-text: #64748b;
  --disabled-border: #cbd5e1;

  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.08);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.10);
  --shadow-lg: 0 20px 50px rgba(15, 23, 42, 0.16);
  --panel-shadow: 0 10px 30px rgba(15, 23, 42, 0.10);

  --content-max: 1440px;
  --game-max: 1320px;
  --panel-gap: clamp(14px, 2vw, 28px);
}

[data-theme="dark"] {
  --bg: #08111f;
  --bg-gradient: linear-gradient(180deg, #0b1525 0%, #060c16 100%);
  --surface: #111c2f;
  --surface-elevated: #16233a;
  --surface-subtle: #1b2940;
  --surface-glass: rgba(17, 28, 47, 0.96);
  --surface-hover: #24344d;

  --border: #334155;
  --border-strong: #64748b;
  --border-focus: #60a5fa;

  --text-main: #f8fafc;
  --text-muted: #cbd5e1;
  --text-subtle: #94a3b8;
  --text-on-action: #ffffff;

  --action-primary: #2563eb;
  --action-primary-hover: #1d4ed8;
  --action-danger: #dc2626;
  --action-danger-hover: #b91c1c;

  --success: #4ade80;
  --success-bg: rgba(22, 101, 52, 0.34);
  --warning: #fbbf24;
  --warning-bg: rgba(120, 53, 15, 0.42);
  --warning-border: #d97706;
  --danger: #f87171;
  --danger-bg: rgba(127, 29, 29, 0.34);

  --disabled-bg: #1e293b;
  --disabled-text: #94a3b8;
  --disabled-border: #334155;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.34);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.34);
  --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.48);
  --panel-shadow: 0 12px 34px rgba(0, 0, 0, 0.36);
}

/* Reduce decorative image competition with gameplay and controls. */
body:has(#gameScreen:not(.hidden) .chess-board-wrap) {
  background:
    radial-gradient(circle at 48% 24%, rgba(245, 158, 11, 0.08), transparent 58%),
    linear-gradient(rgba(8, 17, 31, 0.95), rgba(6, 12, 22, 0.985)),
    url('assets/chess-bg.jpg') no-repeat center top / cover fixed;
}

body:not([data-theme="dark"]):has(#gameScreen:not(.hidden) .chess-board-wrap) {
  background:
    radial-gradient(circle at 48% 24%, rgba(245, 158, 11, 0.045), transparent 58%),
    linear-gradient(rgba(247, 249, 252, 0.965), rgba(237, 242, 247, 0.985)),
    url('assets/chess-bg.jpg') no-repeat center top / cover fixed;
}

body:has(#gameScreen:not(.hidden) .xiangqi-board-wrap) {
  background:
    radial-gradient(circle at 48% 24%, rgba(220, 38, 38, 0.07), transparent 60%),
    linear-gradient(rgba(8, 17, 31, 0.95), rgba(6, 12, 22, 0.985)),
    url('assets/xiangqi-bg.jpg') no-repeat center top / cover fixed;
}

body:not([data-theme="dark"]):has(#gameScreen:not(.hidden) .xiangqi-board-wrap) {
  background:
    radial-gradient(circle at 48% 24%, rgba(220, 38, 38, 0.04), transparent 60%),
    linear-gradient(rgba(247, 249, 252, 0.965), rgba(237, 242, 247, 0.985)),
    url('assets/xiangqi-bg.jpg') no-repeat center top / cover fixed;
}

body:has(#gameScreen:not(.hidden) .caro-board-wrap) {
  background:
    radial-gradient(circle at 48% 24%, rgba(56, 189, 248, 0.06), transparent 60%),
    linear-gradient(rgba(8, 17, 31, 0.95), rgba(6, 12, 22, 0.985)),
    url('assets/caro-bg.jpg') no-repeat center top / cover fixed;
}

body:not([data-theme="dark"]):has(#gameScreen:not(.hidden) .caro-board-wrap) {
  background:
    radial-gradient(circle at 48% 24%, rgba(56, 189, 248, 0.04), transparent 60%),
    linear-gradient(rgba(247, 249, 252, 0.965), rgba(237, 242, 247, 0.985)),
    url('assets/caro-bg.jpg') no-repeat center top / cover fixed;
}

body:has(#tycoonScreen:not(.hidden)) {
  background:
    radial-gradient(circle at 48% 24%, rgba(52, 211, 153, 0.07), transparent 60%),
    linear-gradient(rgba(8, 17, 31, 0.95), rgba(6, 12, 22, 0.985)),
    url('assets/tycoon-bg.jpg') no-repeat center top / cover fixed;
}

body:not([data-theme="dark"]):has(#tycoonScreen:not(.hidden)) {
  background:
    radial-gradient(circle at 48% 24%, rgba(52, 211, 153, 0.04), transparent 60%),
    linear-gradient(rgba(247, 249, 252, 0.965), rgba(237, 242, 247, 0.985)),
    url('assets/tycoon-bg.jpg') no-repeat center top / cover fixed;
}

body:has(#gameScreen:not(.hidden)) .card,
body:has(#tycoonScreen:not(.hidden)) .card,
[data-theme="dark"] body:has(#gameScreen:not(.hidden)) .card,
[data-theme="dark"] body:has(#tycoonScreen:not(.hidden)) .card,
body:not([data-theme="dark"]):has(#gameScreen:not(.hidden)) .card,
body:not([data-theme="dark"]):has(#tycoonScreen:not(.hidden)) .card {
  background: var(--surface-glass);
  border-color: var(--border);
  box-shadow: var(--panel-shadow);
}

/* Shared surface hierarchy across home, lobby and all games. */
.card,
.game-card,
.mode-card,
.side-card,
.room-form,
.room-directory,
.room-list-card,
.home-quick-create,
.change-room-game-box {
  border-color: var(--border);
}

.card,
.room-form,
.room-directory,
.home-quick-create,
.change-room-game-box {
  background: var(--surface-elevated);
}

.room-list-card {
  background: var(--surface);
}

.card h2,
.card h3,
.room-directory h3,
.room-list-card strong {
  color: var(--text-main);
}

.picker-intro p,
.room-directory-head p,
.room-directory-notice,
.difficulty-note,
.guide-text,
.tycoon-rule-note,
.tycoon-log-entry,
.status-subtext,
.counter {
  color: var(--text-muted);
}

/* High-contrast controls and deterministic component states. */
.btn {
  background: var(--surface-subtle);
  color: var(--text-main);
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}

.btn.primary {
  background: var(--action-primary);
  color: var(--text-on-action);
  border-color: var(--action-primary);
}

.btn.danger {
  background: var(--action-danger);
  color: #ffffff;
  border-color: var(--action-danger);
}

.btn.danger-outline {
  background: transparent;
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 58%, var(--border));
}

.draw-btn {
  background: var(--warning-bg);
  color: var(--warning);
  border-color: var(--warning-border);
}

.btn:disabled,
.btn.primary:disabled,
.btn.danger:disabled,
.draw-btn:disabled,
.sub-btn:disabled,
.text-btn:disabled {
  opacity: 1;
  background: var(--disabled-bg);
  color: var(--disabled-text);
  border-color: var(--disabled-border);
  box-shadow: none;
  cursor: not-allowed;
  filter: none;
  transform: none;
}

.sub-btn,
.text-btn,
.icon-btn,
.select-input,
.text-input {
  border-color: var(--border);
}

.sub-btn {
  background: var(--surface-subtle);
  color: var(--text-main);
}

.text-btn {
  color: var(--accent);
}

.icon-btn {
  background: var(--surface-elevated);
  color: var(--text-main);
}

.select-input,
.text-input {
  background: var(--surface);
  color: var(--text-main);
}

.select-input::placeholder,
.text-input::placeholder {
  color: var(--text-subtle);
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
[role="button"]:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--border-focus);
  outline-offset: 2px;
}

@media (hover: hover) and (pointer: fine) {
  .btn:not(:disabled):hover,
  .sub-btn:not(:disabled):hover,
  .icon-btn:not(:disabled):hover {
    background: var(--surface-hover);
    border-color: var(--border-strong);
  }

  .btn.primary:not(:disabled):hover {
    background: var(--action-primary-hover);
    border-color: var(--action-primary-hover);
  }

  .btn.danger:not(:disabled):hover {
    background: var(--action-danger-hover);
    border-color: var(--action-danger-hover);
  }

  .game-card:not(:disabled):hover,
  .mode-card:not(:disabled):hover,
  .side-card:not(:disabled):hover,
  .room-list-card:hover {
    border-color: var(--border-strong);
    box-shadow: var(--shadow-md);
  }
}

/* Header is compact, readable and stable across route changes. */
.app-shell {
  max-width: var(--content-max);
}

.topbar {
  color: var(--text-main);
}

.header-status-pill {
  background: var(--surface-elevated);
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}

.header-status-pill .status-subtext {
  color: var(--text-muted);
}

.player-bar {
  color: var(--text-main);
  text-shadow: 0 1px 2px color-mix(in srgb, var(--bg) 72%, transparent);
}

.player-badge {
  color: var(--text-main);
  background: var(--surface-elevated);
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}

.status-dot {
  background: var(--text-subtle);
}

.status-dot.active {
  background: var(--success);
}

/* Chess/Xiangqi/Caro board framing remains game-specific but theme-aware. */
.board-wrap {
  border-color: var(--surface-elevated);
}

[data-theme="dark"] .chess-board-wrap {
  border-color: #4b2d20;
}

[data-theme="dark"] .xiangqi-board-wrap,
[data-theme="dark"] .caro-board-wrap {
  box-shadow: var(--shadow-lg);
}

/* Gameplay control hierarchy: primary actions first, support content second. */
.side-panel,
.tycoon-side-panel {
  min-width: 0;
}

.side-panel > .card,
.tycoon-side-panel > .card {
  min-width: 0;
}

.actions-card {
  gap: 12px;
}

.action-buttons,
.live-decision-actions,
.sub-actions,
.tycoon-actions,
.tycoon-manage-actions {
  gap: 8px;
}

.action-buttons .btn,
.live-decision-actions .btn,
.sub-actions .sub-btn {
  min-width: 0;
}

.bot-card,
.guide-card,
.history-card,
.captured-card {
  border-color: var(--border);
}

.history-list {
  scrollbar-color: var(--border-strong) transparent;
}

.empty-state,
.captured-empty {
  color: var(--text-muted);
}

/* Room discovery and lobby readability. */
.room-scope-tab {
  color: var(--text-muted);
  border-color: var(--border);
}

.room-scope-tab.active {
  color: var(--text-main);
  background: var(--surface-elevated);
  border-color: var(--border-strong);
}

.room-list-meta > span:not(.room-owner-chip) {
  color: var(--text-muted);
  background: var(--surface-subtle);
  border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
}

.room-owner-chip {
  font-weight: 750;
}

.room-status-badge.status-active {
  color: var(--success);
}

.room-list-actions .room-card-action {
  border-color: var(--border);
}

/* Tycoon panels use the same hierarchy while preserving the printed board. */
.tycoon-topbar,
.tycoon-control-card,
.tycoon-management-card,
.tycoon-players-card,
.tycoon-log-card {
  border-color: var(--border);
}

.tycoon-dice,
.tycoon-asset-detail {
  border-color: var(--border);
  background-color: var(--surface-subtle);
}

.tycoon-player {
  border-color: var(--border);
}

.tycoon-player.active {
  border-color: var(--border-focus);
  box-shadow: inset 3px 0 0 var(--border-focus);
}

/* Mobile-first: board is the focus; controls remain reachable and legible. */
@media (max-width: 767px) {
  .app-shell {
    padding-top: max(8px, env(safe-area-inset-top));
    padding-right: max(10px, env(safe-area-inset-right));
    padding-bottom: max(20px, env(safe-area-inset-bottom));
    padding-left: max(10px, env(safe-area-inset-left));
  }

  .topbar {
    gap: 8px;
    padding-bottom: 8px;
  }

  .brand-header .eyebrow {
    max-width: min(42vw, 190px);
  }

  .top-actions {
    gap: 6px;
  }

  .icon-btn {
    min-width: 44px;
    min-height: 44px;
    border-radius: 12px;
  }

  .header-main-row {
    gap: 7px;
  }

  .header-main-row h1 {
    font-size: clamp(1.02rem, 4.8vw, 1.24rem);
  }

  .header-status-pill {
    width: 100%;
    max-width: 100%;
    padding: 7px 10px;
  }

  .game-layout {
    gap: 12px;
  }

  .board-panel {
    max-width: min(100%, 86dvh, 640px);
  }

  .side-panel {
    display: flex;
    max-width: min(100%, 640px);
    gap: 10px;
  }

  .side-panel .card {
    border-radius: 16px;
    padding: 12px;
  }

  /* Mobile hierarchy: captured pieces must sit immediately below the board,
     before gameplay controls and supporting cards. */
  .captured-card {
    order: -2;
    margin-top: 0;
    padding: 10px 12px;
  }

  .actions-card {
    order: -1;
  }

  .action-buttons .btn,
  .live-decision-actions .btn,
  .sub-actions .sub-btn {
    min-height: 48px;
  }

  .sub-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .room-directory-head-actions {
    width: 100%;
  }

  .room-directory-head-actions .btn,
  .room-directory-head-actions .sub-btn {
    flex: 1 1 150px;
  }

  .room-list-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tycoon-layout {
    gap: 12px;
  }

  .tycoon-side-panel {
    gap: 10px;
  }
}

/* Tablet: use available width without forcing a cramped desktop split. */
@media (min-width: 768px) and (max-width: 1023px) {
  .app-shell {
    padding-inline: 20px;
  }

  .game-layout {
    gap: 18px;
  }

  .board-panel {
    max-width: min(100%, 80dvh, 700px);
  }

  .side-panel {
    width: min(100%, 920px);
    max-width: 920px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .actions-card,
  .history-card {
    grid-column: 1 / -1;
  }

  .tycoon-layout {
    gap: 18px;
  }
}

/* Desktop: board + sticky control rail with balanced density. */
@media (min-width: 1024px) {
  .app-shell {
    max-width: var(--content-max);
    padding: 14px 22px 30px;
  }

  .game-layout {
    max-width: var(--game-max);
    grid-template-columns: minmax(560px, 1fr) minmax(340px, 380px);
    gap: var(--panel-gap);
    align-items: start;
    margin-top: 8px;
  }

  .board-panel {
    max-width: min(100%, 84dvh, 760px);
  }

  .chess-board-wrap {
    max-width: min(84dvh, 760px);
  }

  .side-panel {
    position: sticky;
    top: 14px;
    display: flex;
    max-width: none;
    max-height: calc(100dvh - 28px);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-right: 3px;
    gap: 12px;
  }

  .side-panel .card {
    border-radius: 18px;
    padding: 14px;
  }

  .tycoon-layout {
    width: 100%;
    max-width: 1360px;
    margin-inline: auto;
    grid-template-columns: minmax(620px, 1fr) minmax(340px, 390px);
    gap: var(--panel-gap);
  }

  .tycoon-board-panel {
    top: 14px;
  }

  .tycoon-side-panel {
    position: sticky;
    top: 14px;
    max-height: calc(100dvh - 28px);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-right: 3px;
  }

  .game-picker,
  .home-room-directory,
  .home-quick-create {
    width: 100%;
    max-width: 1120px;
  }
}

@media (min-width: 1440px) {
  .game-layout {
    max-width: 1380px;
    grid-template-columns: minmax(650px, 1fr) 390px;
    gap: 34px;
  }

  .board-panel,
  .chess-board-wrap {
    max-width: min(84dvh, 780px);
  }

  .tycoon-layout {
    max-width: 1400px;
    grid-template-columns: minmax(700px, 1fr) 400px;
    gap: 34px;
  }
}

/* Keep motion optional for users who request reduced motion. */
@media (prefers-reduced-motion: reduce) {
  .card,
  .btn,
  .sub-btn,
  .icon-btn,
  .game-card,
  .mode-card,
  .side-card {
    transition: none !important;
  }
}


/* ==========================================================
   IVS BOARD EXPERIENCE UPGRADE — Chess + Xiangqi v3.1
   Visual-only enhancement: preserves engine, room and LIVE logic.
   ========================================================== */

/* Shared board stage: stronger separation from surrounding controls. */
#gameScreen:not(.hidden) .board-panel {
  isolation: isolate;
}

#gameScreen:not(.hidden) .board-wrap {
  transition:
    box-shadow 180ms ease,
    border-color 180ms ease,
    transform 180ms ease;
}

#gameScreen:not(.hidden) .chess-board-wrap,
#gameScreen:not(.hidden) .xiangqi-board-wrap {
  margin-inline: auto;
}

/* ---------- CHESS ---------- */
.chess-board-wrap {
  border-width: clamp(4px, 1.35vw, 8px);
  border-color: #3b2417;
  border-radius: clamp(8px, 2.2vw, 14px);
  background:
    linear-gradient(135deg, rgba(255,255,255,0.16), transparent 28%),
    linear-gradient(145deg, #6f472c 0%, #3b2417 48%, #25150f 100%);
  box-shadow:
    0 20px 48px rgba(15, 10, 6, 0.34),
    0 4px 12px rgba(15, 10, 6, 0.22),
    inset 0 0 0 1px rgba(255,255,255,0.16);
}

.chess-board {
  overflow: hidden;
  border-radius: max(2px, calc(clamp(8px, 2.2vw, 14px) - 5px));
  background: #b58863;
  box-shadow:
    inset 0 0 0 1px rgba(40, 24, 14, 0.22),
    inset 0 0 24px rgba(69, 39, 21, 0.09);
}

.chess-board .square.light {
  background:
    linear-gradient(145deg, rgba(255,255,255,0.10), transparent 62%),
    #ead7b0;
}

.chess-board .square.dark {
  background:
    linear-gradient(145deg, rgba(255,255,255,0.055), rgba(35,20,11,0.04)),
    #9f714c;
}

.square {
  border: 0;
  cursor: pointer;
  transition:
    filter 120ms ease,
    box-shadow 120ms ease,
    transform 90ms ease;
}

.square:focus-visible {
  outline: 3px solid #2563eb;
  outline-offset: -3px;
  z-index: 8;
}

@media (hover: hover) and (pointer: fine) {
  .square:hover {
    filter: brightness(1.055) saturate(1.04);
  }

  .square:active {
    transform: scale(0.975);
  }
}

.chess-svg {
  width: 88%;
  height: 88%;
  position: relative;
  z-index: 3;
  transform: translateZ(0);
  filter:
    drop-shadow(0 1px 0 rgba(255,255,255,0.16))
    drop-shadow(0 2px 3px rgba(35,20,12,0.32));
  transition:
    transform 120ms ease,
    filter 120ms ease;
}

.chess-svg.white-piece {
  filter:
    drop-shadow(0 1px 0 rgba(255,255,255,0.28))
    drop-shadow(0 2px 3px rgba(29,20,14,0.42));
}

.chess-svg.black-piece {
  filter:
    drop-shadow(0 1px 0 rgba(255,255,255,0.10))
    drop-shadow(0 2px 3px rgba(0,0,0,0.58));
}

.square.selected {
  outline: 0;
  box-shadow:
    inset 0 0 0 clamp(3px, 0.8vw, 5px) #facc15,
    inset 0 0 18px rgba(250,204,21,0.28);
  z-index: 6;
}

.square.selected .chess-svg {
  transform: scale(1.055);
}

.square.legal::after {
  width: clamp(10px, 28%, 22px);
  background: rgba(15, 23, 42, 0.52);
  box-shadow:
    0 0 0 2px rgba(255,255,255,0.40),
    0 1px 5px rgba(15,23,42,0.28);
}

.square.capture::after {
  inset: 7%;
  border-width: clamp(3px, 0.75vw, 5px);
  border-color: rgba(220, 38, 38, 0.78);
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,0.32),
    0 0 10px rgba(220,38,38,0.22);
}

.square.last-from::before {
  background: rgba(250, 204, 21, 0.20);
  box-shadow: inset 0 0 0 2px rgba(180, 120, 0, 0.58);
}

.square.last-to::before {
  background: rgba(250, 204, 21, 0.34);
  box-shadow:
    inset 0 0 0 3px rgba(245, 158, 11, 0.88),
    inset 0 0 16px rgba(245, 158, 11, 0.26);
}

.square.in-check {
  box-shadow:
    inset 0 0 0 clamp(4px, 0.9vw, 6px) #dc2626,
    inset 0 0 30px rgba(220,38,38,0.56);
}

.coord {
  font-size: clamp(7px, 1.65vw, 11px);
  font-weight: 850;
  opacity: 0.82;
  letter-spacing: -0.02em;
  text-shadow: 0 1px 0 rgba(255,255,255,0.18);
}

.chess-board .square.light .coord {
  color: rgba(76, 49, 29, 0.84);
}

.chess-board .square.dark .coord {
  color: rgba(255, 248, 235, 0.84);
  text-shadow: 0 1px 1px rgba(43,24,13,0.38);
}

/* ---------- XIANGQI ---------- */
.xiangqi-board-wrap {
  border-width: clamp(5px, 1.5vw, 9px);
  border-color: #5a2d12;
  border-radius: clamp(8px, 2vw, 13px);
  background:
    linear-gradient(135deg, rgba(255,255,255,0.16), transparent 26%),
    linear-gradient(145deg, #8a5128 0%, #572b13 52%, #35180b 100%);
  box-shadow:
    0 20px 48px rgba(55, 24, 8, 0.34),
    0 4px 12px rgba(55, 24, 8, 0.24),
    inset 0 0 0 1px rgba(255,255,255,0.15);
}

.xiangqi-board {
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 15%, rgba(255,255,255,0.12), transparent 28%),
    repeating-linear-gradient(
      0deg,
      rgba(102, 57, 26, 0.028) 0,
      rgba(102, 57, 26, 0.028) 1px,
      transparent 1px,
      transparent 5px
    ),
    linear-gradient(135deg, #edce9c 0%, #e4bd83 48%, #d9ad72 100%);
  box-shadow:
    inset 0 0 26px rgba(91,46,18,0.12),
    inset 0 0 0 1px rgba(88,45,19,0.16);
}

.xq-svg-board {
  filter: drop-shadow(0 0.5px 0 rgba(255,255,255,0.26));
}

.xq-river-label text {
  font-size: 0.62px;
  fill: rgba(75, 38, 18, 0.90);
  letter-spacing: 0.06px;
}

.xq-intersection {
  touch-action: manipulation;
}

.xq-intersection:focus-visible {
  outline: 3px solid #2563eb;
  outline-offset: -2px;
  z-index: 9;
}

.xq-piece {
  width: min(92%, 58px);
  border-width: clamp(2px, 0.62vw, 3px);
  background:
    radial-gradient(circle at 34% 25%, #fffefa 0%, #f9eedb 62%, #ead3ad 100%);
  font-size: clamp(17px, 5.15vw, 37px);
  font-family: "Noto Serif CJK SC", "Microsoft YaHei", "SimSun", serif;
  font-weight: 950;
  text-rendering: geometricPrecision;
  box-shadow:
    inset 0 0 0 2px rgba(255,255,255,0.78),
    inset 0 -3px 4px rgba(87, 51, 25, 0.12),
    0 2px 0 rgba(82,44,20,0.25),
    0 4px 8px rgba(62,32,14,0.24);
  transition:
    transform 110ms ease,
    box-shadow 140ms ease,
    filter 140ms ease;
}

.xq-piece::after {
  content: "";
  position: absolute;
  inset: 10%;
  border: 1px solid currentColor;
  border-radius: 50%;
  opacity: 0.24;
  pointer-events: none;
}

.xq-piece.red {
  color: #bd1f1f;
  border-color: #a71919;
}

.xq-piece.black {
  color: #16181d;
  border-color: #4d2a15;
}

@media (hover: hover) and (pointer: fine) {
  .xq-intersection:hover .xq-piece {
    transform: translateY(-1px) scale(1.025);
    filter: brightness(1.03);
  }
}

.xq-intersection.selected::before {
  inset: 3%;
  box-shadow:
    0 0 0 clamp(3px, 0.7vw, 4px) #facc15 inset,
    0 0 14px rgba(250,204,21,0.52);
}

.xq-intersection.selected .xq-piece {
  transform: scale(1.045);
}

.xq-intersection.legal::after {
  width: clamp(10px, 30%, 18px);
  background: rgba(19, 31, 24, 0.58);
  box-shadow:
    0 0 0 2px rgba(255,255,255,0.46),
    0 1px 4px rgba(0,0,0,0.24);
}

.xq-intersection.capture::after {
  inset: 5%;
  border-width: clamp(3px, 0.72vw, 5px);
  border-color: rgba(200, 30, 30, 0.78);
  box-shadow:
    0 0 0 1px rgba(255,255,255,0.32),
    0 0 12px rgba(200,30,30,0.24);
}

.xq-intersection.last-from::before {
  inset: 9%;
  border: 2px dashed rgba(184, 112, 5, 0.82);
  background: rgba(250,204,21,0.20);
}

.xq-intersection.last-to::before {
  inset: 3%;
  box-shadow:
    0 0 0 3px #f59e0b,
    0 0 16px rgba(245,158,11,0.60);
}

.xq-intersection.last-to .xq-piece {
  border-color: #e29b16 !important;
  box-shadow:
    0 0 0 2px #f59e0b,
    0 0 14px rgba(245,158,11,0.60),
    inset 0 0 0 2px rgba(255,255,255,0.78),
    0 3px 7px rgba(63,31,11,0.25) !important;
}

/* Phone-specific density: maximize board legibility without crowding controls. */
@media (max-width: 480px) {
  .chess-board-wrap,
  .xiangqi-board-wrap {
    box-shadow:
      0 12px 30px rgba(15, 10, 6, 0.28),
      0 3px 8px rgba(15, 10, 6, 0.18);
  }

  .chess-svg {
    width: 90%;
    height: 90%;
  }

  .coord.file {
    right: 2px;
    bottom: 1px;
  }

  .coord.rank {
    left: 2px;
    top: 1px;
  }

  .xq-piece {
    width: min(94%, 56px);
    font-size: clamp(16px, 5.6vw, 26px);
  }

  .xq-river-label text {
    font-size: 0.58px;
  }
}

/* Keep board materials bright and readable in dark mode; only the stage is dark. */
[data-theme="dark"] .chess-board-wrap {
  border-color: #2f1c13;
  box-shadow:
    0 20px 48px rgba(0,0,0,0.52),
    0 4px 14px rgba(0,0,0,0.38),
    inset 0 0 0 1px rgba(255,255,255,0.10);
}

[data-theme="dark"] .xiangqi-board-wrap {
  border-color: #46200d;
  box-shadow:
    0 20px 48px rgba(0,0,0,0.50),
    0 4px 14px rgba(0,0,0,0.36),
    inset 0 0 0 1px rgba(255,255,255,0.09);
}

@media (prefers-contrast: more) {
  .chess-board .square.light { background: #f2dfbd; }
  .chess-board .square.dark { background: #8f5f39; }
  .xq-piece { border-width: 3px; }
  .xq-piece.red { color: #a91313; border-color: #8f1010; }
  .xq-piece.black { color: #090b0f; border-color: #351c0d; }
  .square.legal::after,
  .xq-intersection.legal::after { background: rgba(0,0,0,0.72); }
}


/* ==========================================================
   TYCOON BOARD ASSET VISIBILITY — v3.1.1
   Ownership, buildings, hotels and mortgages stay legible
   without competing with turn/selection indicators.
   ========================================================== */

.tycoon-tile.owned {
  border-color: color-mix(in srgb, var(--owner-color) 82%, #202020);
  box-shadow: inset 0 0 0 clamp(1px, 0.22vw, 2px) color-mix(in srgb, var(--owner-color) 72%, transparent);
}

.tycoon-tile.owned.selected {
  box-shadow:
    inset 0 0 0 3px rgba(37, 99, 235, 0.78),
    inset 0 0 0 5px color-mix(in srgb, var(--owner-color) 72%, transparent);
}

.tycoon-tile.owned.current {
  box-shadow:
    inset 0 0 0 2px #fff,
    inset 0 0 0 4px color-mix(in srgb, var(--owner-color) 78%, transparent);
}

.tycoon-owner {
  position: absolute;
  top: clamp(5px, 0.85vw, 10px);
  right: 2px;
  bottom: auto;
  z-index: 5;
  display: grid;
  place-items: center;
  width: clamp(14px, 2.15vw, 22px);
  height: clamp(14px, 2.15vw, 22px);
  border: 1.5px solid #fff;
  border-radius: 999px;
  background: var(--owner-color);
  color: #fff;
  font-size: clamp(0.42rem, 1.05vw, 0.68rem);
  font-weight: 1000;
  line-height: 1;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.36);
  pointer-events: none;
}

.tycoon-asset-status {
  position: relative;
  z-index: 2;
  display: inline-flex;
  align-self: center;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  min-height: 1.25em;
  padding: 1px clamp(2px, 0.35vw, 5px);
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.22);
  border-radius: 999px;
  font-size: clamp(0.32rem, 1.05vw, 0.62rem);
  font-weight: 1000;
  line-height: 1.1;
  letter-spacing: -0.02em;
  white-space: nowrap;
  text-overflow: ellipsis;
  pointer-events: none;
}

.tycoon-asset-status.is-house {
  border-color: #18733a;
  background: #e9f8ee;
  color: #125a2e;
}

.tycoon-asset-status.is-hotel {
  border-color: #a61b1b;
  background: #fff0ef;
  color: #8d1717;
}

.tycoon-asset-status.is-mortgaged {
  border-color: #6b4e2e;
  background: #f6ead9;
  color: #5d3e21;
  font-size: clamp(0.29rem, 0.9vw, 0.56rem);
}

.tycoon-tile.mortgaged {
  background-image:
    repeating-linear-gradient(
      -45deg,
      rgba(107, 78, 46, 0.08) 0,
      rgba(107, 78, 46, 0.08) 4px,
      transparent 4px,
      transparent 8px
    );
}

.tycoon-tile.mortgaged .tycoon-tile-name {
  text-decoration: underline dashed #7b5c3d 1px;
  text-underline-offset: 2px;
}

.tycoon-center-legend {
  position: relative;
  z-index: 2;
  display: grid;
  gap: clamp(3px, 0.55vw, 7px);
  width: min(92%, 34rem);
  padding: clamp(4px, 0.65vw, 8px) clamp(6px, 1vw, 12px);
  border: 1px solid rgba(79, 55, 24, 0.28);
  border-radius: clamp(5px, 0.8vw, 10px);
  background: rgba(255, 255, 255, 0.76);
  color: #493519;
  font-size: clamp(0.38rem, 1.15vw, 0.72rem);
  font-weight: 800;
  line-height: 1.2;
  backdrop-filter: blur(2px);
}

.tycoon-center-player-key,
.tycoon-center-status-key {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: clamp(3px, 0.65vw, 8px);
}

.tycoon-center-player-key-item {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: 3px;
}

.tycoon-center-player-key-token {
  display: inline-grid;
  place-items: center;
  width: clamp(13px, 1.8vw, 20px);
  height: clamp(13px, 1.8vw, 20px);
  flex: 0 0 auto;
  border: 1.5px solid #fff;
  border-radius: 50%;
  background: var(--token-color);
  color: #fff;
  font-size: 0.82em;
  font-weight: 1000;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.28);
}

.tycoon-center-player-key-name {
  max-width: 8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tycoon-center-status-key b {
  display: inline-block;
  padding: 0 3px;
  border: 1px solid #6b4e2e;
  border-radius: 999px;
  background: #f6ead9;
  color: #5d3e21;
  font-size: 0.88em;
}

@media (max-width: 519px) {
  .tycoon-owner {
    top: 4px;
    right: 1px;
    width: clamp(11px, 3vw, 15px);
    height: clamp(11px, 3vw, 15px);
    border-width: 1px;
    font-size: clamp(0.34rem, 1.55vw, 0.46rem);
  }

  .tycoon-asset-status {
    min-height: 1.15em;
    padding: 1px 2px;
    font-size: clamp(0.28rem, 1.45vw, 0.4rem);
  }

  .tycoon-asset-status.is-mortgaged {
    font-size: clamp(0.25rem, 1.25vw, 0.36rem);
  }

  .tycoon-tile.has-development .tycoon-tile-meta,
  .tycoon-tile.mortgaged .tycoon-tile-meta {
    display: none;
  }

  .tycoon-center-legend {
    width: 94%;
    padding: 3px 4px;
    gap: 2px;
    font-size: clamp(0.32rem, 1.55vw, 0.45rem);
  }

  .tycoon-center-player-key-name {
    display: none;
  }

  .tycoon-center-player-key-token {
    width: clamp(11px, 3vw, 15px);
    height: clamp(11px, 3vw, 15px);
  }

  .tycoon-center-status-key {
    gap: 4px;
  }
}

@media (min-width: 768px) {
  .tycoon-tile.owned {
    box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--owner-color) 72%, transparent);
  }

  .tycoon-owner {
    right: 3px;
  }

  .tycoon-asset-status {
    min-height: 1.4em;
  }
}


/* ==========================================================
   TYCOON ANIMAL AVATARS — v3.2.0
   Movement tokens are visually distinct from ownership badges.
   ========================================================== */

.tycoon-avatar-svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.tycoon-token {
  width: clamp(17px, 2.6vw, 28px);
  height: clamp(17px, 2.6vw, 28px);
  padding: 1px;
  border: clamp(2px, 0.28vw, 3px) solid var(--token-color);
  background: #fff;
  box-shadow:
    0 2px 5px rgba(0, 0, 0, 0.34),
    0 0 0 1px rgba(255, 255, 255, 0.88);
}

.tycoon-token .tycoon-avatar-svg {
  border-radius: 50%;
}

.tycoon-token-row {
  z-index: 7;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.tycoon-owner {
  top: clamp(5px, 0.85vw, 10px);
  right: 2px;
  width: auto;
  min-width: clamp(18px, 2.8vw, 30px);
  height: clamp(13px, 1.8vw, 19px);
  padding: 0 clamp(2px, 0.35vw, 5px);
  border-radius: 999px;
  font-size: clamp(0.34rem, 0.9vw, 0.58rem);
  letter-spacing: -0.02em;
}

.tycoon-player-token {
  width: 38px;
  height: 38px;
  padding: 2px;
  border: 3px solid var(--token-color);
  background: #fff;
  overflow: hidden;
}

.tycoon-center-player-key-token {
  width: clamp(18px, 2.3vw, 25px);
  height: clamp(18px, 2.3vw, 25px);
  padding: 1px;
  border: 2px solid var(--token-color);
  background: #fff;
  overflow: hidden;
}

.tycoon-seat-avatar {
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 3px;
  border: 2px solid var(--seat-avatar-color, var(--accent));
  border-radius: 50%;
  background: #fff;
}

.tycoon-seat-card:nth-child(1) { --seat-avatar-color: #e53935; }
.tycoon-seat-card:nth-child(2) { --seat-avatar-color: #1565c0; }
.tycoon-seat-card:nth-child(3) { --seat-avatar-color: #2e7d32; }
.tycoon-seat-card:nth-child(4) { --seat-avatar-color: #7b1fa2; }

.tycoon-avatar-picker-card {
  display: grid;
  gap: 10px;
}

.tycoon-avatar-picker-card.hidden {
  display: none;
}

.tycoon-avatar-note {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.76rem;
  line-height: 1.45;
}

.tycoon-avatar-options {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.tycoon-avatar-option {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 4px;
  min-width: 0;
  min-height: 78px;
  padding: 7px 4px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-subtle);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

.tycoon-avatar-option:hover:not(:disabled) {
  border-color: color-mix(in srgb, var(--accent) 52%, var(--border));
  transform: translateY(-1px);
}

.tycoon-avatar-option:focus-visible {
  outline: 3px solid var(--border-focus);
  outline-offset: 2px;
}

.tycoon-avatar-option.is-selected {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 9%, var(--surface));
  box-shadow:
    inset 0 0 0 2px color-mix(in srgb, var(--accent) 56%, transparent),
    var(--shadow-sm);
}

.tycoon-avatar-option.is-selected::after {
  content: '✓';
  position: absolute;
  top: 4px;
  right: 5px;
  display: grid;
  place-items: center;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.66rem;
  font-weight: 1000;
}

.tycoon-avatar-option.is-used:disabled {
  cursor: not-allowed;
  filter: grayscale(0.65);
  opacity: 0.5;
}

.tycoon-avatar-option-art {
  display: block;
  width: 42px;
  height: 42px;
  padding: 2px;
  border: 1px solid color-mix(in srgb, var(--border) 82%, transparent);
  border-radius: 50%;
  background: #fff;
  overflow: hidden;
}

.tycoon-avatar-option-label {
  display: block;
  width: 100%;
  overflow: hidden;
  font-size: 0.67rem;
  font-weight: 800;
  line-height: 1.15;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tycoon-player.active .tycoon-player-token {
  box-shadow:
    0 0 0 2px var(--surface),
    0 0 0 4px var(--accent);
}

@media (max-width: 519px) {
  .tycoon-token {
    width: clamp(15px, 4.5vw, 22px);
    height: clamp(15px, 4.5vw, 22px);
    border-width: 2px;
  }

  .tycoon-owner {
    top: 4px;
    right: 1px;
    min-width: clamp(17px, 4.6vw, 22px);
    height: clamp(11px, 3.2vw, 15px);
    padding: 0 2px;
    font-size: clamp(0.28rem, 1.35vw, 0.38rem);
  }

  .tycoon-avatar-options {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 5px;
  }

  .tycoon-avatar-option {
    min-height: 64px;
    padding: 5px 2px;
  }

  .tycoon-avatar-option-art {
    width: 34px;
    height: 34px;
  }

  .tycoon-avatar-option-label {
    font-size: 0.58rem;
  }

  .tycoon-seat-avatar {
    padding: 2px;
  }
}

@media (min-width: 768px) {
  .tycoon-token {
    width: clamp(22px, 2.3vw, 30px);
    height: clamp(22px, 2.3vw, 30px);
  }

  .tycoon-player-token {
    width: 40px;
    height: 40px;
  }
}


/* ==========================================================
   PLAYER IDENTITY — Guest-first profile & account linking
   ========================================================== */
.player-profile-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 44px;
  max-width: 190px;
  padding: 5px 10px 5px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--surface);
  color: var(--text-main);
  box-shadow: var(--shadow-sm);
}

.player-profile-btn:active {
  transform: scale(0.98);
}

.player-profile-avatar {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  border-radius: 50%;
  background: var(--surface-subtle);
  font-size: 1.2rem;
  line-height: 1;
}

.player-profile-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.82rem;
  font-weight: 750;
}

.player-profile-dialog {
  width: min(94vw, 560px);
  max-height: min(90dvh, 760px);
  overflow: auto;
}

.player-profile-box {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.player-profile-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.player-profile-head h3 {
  margin: 3px 0 4px;
  font-size: 1.2rem;
}

.player-profile-head p,
.player-account-summary p,
.player-account-link p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

.player-account-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-subtle);
}

.player-account-summary > div {
  min-width: 0;
}

.player-account-summary .badge {
  margin-bottom: 5px;
}

.player-profile-form {
  display: grid;
  gap: 14px;
}

.player-profile-form > label {
  display: grid;
  gap: 6px;
  font-size: 0.84rem;
  font-weight: 700;
}

.player-avatar-fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.player-avatar-fieldset legend {
  margin-bottom: 8px;
  font-size: 0.84rem;
  font-weight: 700;
}

.player-avatar-picker {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.player-avatar-option {
  display: grid;
  place-items: center;
  gap: 3px;
  min-width: 0;
  min-height: 66px;
  padding: 7px 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text-main);
  box-shadow: var(--shadow-sm);
}

.player-avatar-option > span {
  font-size: 1.55rem;
  line-height: 1;
}

.player-avatar-option small {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
  font-size: 0.68rem;
}

.player-avatar-option.active {
  border-color: var(--accent);
  background: var(--accent-light);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.player-profile-status {
  min-height: 1.2em;
  margin: 0;
}

.player-account-link {
  display: grid;
  gap: 10px;
  padding-top: 15px;
  border-top: 1px solid var(--border);
}

.google-signin-mount {
  min-height: 44px;
  overflow: hidden;
}

.google-signin-mount:empty {
  min-height: 0;
}

@media (hover: hover) and (pointer: fine) {
  .player-profile-btn:hover,
  .player-avatar-option:hover {
    border-color: var(--border-focus);
  }
}

@media (max-width: 640px) {
  .player-profile-btn {
    width: 44px;
    min-width: 44px;
    max-width: 44px;
    padding: 5px;
    justify-content: center;
  }

  .player-profile-label {
    display: none;
  }

  .player-profile-head {
    align-items: center;
  }

  .player-profile-head > div {
    min-width: 0;
  }

  .player-profile-box {
    padding: 15px;
  }
}

@media (max-width: 380px) {
  .player-avatar-picker {
    grid-template-columns: repeat(4, minmax(58px, 1fr));
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .player-profile-head p {
    font-size: 0.78rem;
  }
}


/* ==========================================================
   IVS COMMUNITY — Competitive stats, leaderboard & social
   ========================================================== */
.community-dialog {
  width: min(96vw, 880px);
  max-height: 92dvh;
  overflow: auto;
}

.community-shell {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.community-head,
.community-section-head,
.community-friend-code,
.community-social-row,
.community-history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.community-head {
  align-items: flex-start;
}

.community-head h3,
.community-panel h4,
.community-subsection h5 {
  margin: 0;
}

.community-head p,
.community-section-head small,
.community-social-person small,
.community-history-row > small {
  margin: 0;
  color: var(--text-muted);
}

.community-head-actions,
.community-inline-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
}

.community-panel {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.community-stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.community-stat-card {
  display: grid;
  gap: 3px;
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-subtle);
}

.community-stat-game,
.community-stat-record {
  overflow: hidden;
  color: var(--text-muted);
  font-size: 0.72rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.community-stat-rating {
  font-size: 1.22rem;
  line-height: 1.1;
}

.community-list {
  display: grid;
  gap: 7px;
}

.community-rank-row,
.community-history-row,
.community-social-row {
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-subtle);
}

.community-rank-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.community-rank-number,
.community-rank-rating {
  font-variant-numeric: tabular-nums;
}

.community-rank-player,
.community-social-person {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.community-rank-player strong,
.community-social-person strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.community-rank-player small {
  color: var(--text-muted);
}

.community-friend-code {
  padding: 10px 12px;
  border: 1px dashed var(--border-focus);
  border-radius: var(--radius-md);
  background: var(--surface-subtle);
}

.community-friend-code > div {
  display: grid;
  gap: 3px;
}

#communityFriendCode {
  font-size: 1.05rem;
  letter-spacing: 0.08em;
}

.community-friend-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.community-subsection {
  display: grid;
  gap: 7px;
}

.community-subsection h5 {
  color: var(--text-muted);
  font-size: 0.77rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.community-social-row {
  align-items: center;
}

.community-social-row.is-muted {
  opacity: 0.78;
}

.community-history-row {
  display: grid;
  gap: 4px;
}

.community-history-row.outcome-win {
  border-inline-start: 3px solid var(--success, #15803d);
}

.community-history-row.outcome-draw {
  border-inline-start: 3px solid var(--warning, #a16207);
}

.community-history-row.outcome-loss {
  border-inline-start: 3px solid var(--danger, #b91c1c);
}

.community-rating-delta {
  flex: 0 0 auto;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.community-history-reason {
  line-height: 1.35;
}

.community-empty {
  padding: 12px;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-align: center;
}

.community-status {
  min-height: 1.25em;
  margin: 0;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.community-status.is-error {
  color: var(--danger, #b91c1c);
}

.compact-select {
  min-width: 130px;
}

@media (max-width: 640px) {
  .community-shell {
    padding: 12px;
  }

  .community-head {
    display: grid;
  }

  .community-head-actions {
    justify-content: stretch;
  }

  .community-head-actions > button {
    flex: 1 1 0;
  }

  .community-panel {
    padding: 11px;
  }

  .community-section-head {
    align-items: flex-end;
  }

  .community-social-row {
    display: grid;
    align-items: stretch;
  }

  .community-inline-actions > button {
    flex: 1 1 auto;
    min-height: 40px;
  }

  .community-friend-form {
    grid-template-columns: 1fr;
  }

  .community-friend-form .btn {
    width: 100%;
  }
}

@media (min-width: 720px) {
  .community-stats-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}


/* ==========================================================
   TYCOON ASSET INSPECTOR + COMPACT LOG — v3.3.1
   Purchased assets are inspectable without changing turn state.
   ========================================================== */
.tycoon-tile.inspectable {
  cursor: pointer;
}

.tycoon-tile.inspectable:hover {
  filter: brightness(1.03);
}

.tycoon-tile.inspectable:focus-visible {
  outline: 3px solid var(--border-focus);
  outline-offset: -3px;
  z-index: 9;
}

.tycoon-asset-dialog {
  width: min(94vw, 520px);
  max-height: min(88dvh, 720px);
  overflow: auto;
}

.tycoon-asset-dialog-box {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.tycoon-asset-dialog-head,
.tycoon-asset-dialog-owner,
.tycoon-asset-dialog-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.tycoon-asset-dialog-head {
  align-items: flex-start;
}

.tycoon-asset-dialog-head h3 {
  margin: 3px 0 0;
  font-size: 1.22rem;
}

.tycoon-asset-dialog-close {
  min-width: var(--touch-target);
  min-height: var(--touch-target);
}

.tycoon-asset-dialog-owner {
  justify-content: flex-start;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-subtle);
}

.tycoon-asset-dialog-owner-badge {
  display: grid;
  place-items: center;
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  border: 2px solid #fff;
  border-radius: 999px;
  background: var(--owner-color);
  color: #fff;
  font-weight: 900;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.25);
}

.tycoon-asset-dialog-owner-badge.unowned {
  background: var(--surface-elevated);
  color: var(--text-muted);
  border-color: var(--border);
  box-shadow: none;
}

.tycoon-asset-dialog-owner div {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.tycoon-asset-dialog-owner small {
  color: var(--text-muted);
}

.tycoon-asset-dialog-owner strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tycoon-asset-dialog-detail {
  display: grid;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.tycoon-asset-dialog-row {
  padding: 9px 11px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.tycoon-asset-dialog-row:last-child {
  border-bottom: 0;
}

.tycoon-asset-dialog-row span {
  color: var(--text-muted);
}

.tycoon-asset-dialog-row strong {
  max-width: 58%;
  text-align: right;
}

.tycoon-asset-dialog-hint {
  margin: 0;
  padding: 10px 11px;
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
  color: var(--text-muted);
  font-size: 0.8rem;
  line-height: 1.45;
}

@media (max-width: 519px) {
  .tycoon-asset-dialog-box {
    padding: 14px;
  }

  .tycoon-asset-dialog-row {
    align-items: flex-start;
  }

  .tycoon-asset-dialog-row strong {
    max-width: 62%;
  }
}
