/* ============================================
   DESIGN SYSTEM - Inspired by Notion & Linear
   Dual theme: Pink-Gold (Light) / Dark
   Auto system preference, warm minimalism
   ============================================ */

/* ============ LIGHT THEME (Pink-Gold) — Default ============ */
:root {
  --bg-primary: #fdf8f5;
  --bg-panel: #ffffff;
  --bg-elevated: #fef1ec;
  --bg-hover: #fde8e0;
  --bg-game: linear-gradient(145deg, #fdf5f0 0%, #f8ece4 50%, #fdf8f5 100%);

  --text-primary: rgba(50, 30, 20, 0.92);
  --text-secondary: rgba(80, 50, 35, 0.72);
  --text-tertiary: rgba(120, 80, 60, 0.52);
  --text-quaternary: rgba(150, 110, 90, 0.38);

  --brand: #c77d5a;
  --brand-rgb: 199, 125, 90;
  --accent: #d4956e;
  --accent-hover: #e0ad88;
  --gold: #c9a96e;
  --gold-glow: rgba(201, 169, 110, 0.25);
  --rose: #d4728a;
  --rose-glow: rgba(212, 114, 138, 0.18);

  --green: #2a9d63;
  --green-bg: rgba(42, 157, 99, 0.1);
  --red: #d94f4f;
  --red-bg: rgba(217, 79, 79, 0.1);
  --yellow: #c89520;
  --orange: #d47830;

  --border-primary: rgba(180, 140, 120, 0.15);
  --border-secondary: rgba(180, 140, 120, 0.25);
  --border-tertiary: rgba(180, 140, 120, 0.35);

  --card-red: #d94f4f;
  --card-black: #2a1f18;
  --card-surface: #ffffff;
  --card-shadow: rgba(120, 60, 30, 0.12);

  --landlord-bg: rgba(217, 79, 79, 0.08);
  --landlord-border: rgba(217, 79, 79, 0.2);
  --selected-glow: rgba(199, 125, 90, 0.35);
  --toast-bg: var(--bg-panel);

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', sans-serif;

  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
  --space-5: 20px; --space-6: 24px; --space-7: 32px; --space-8: 40px;

  --radius-sm: 5px; --radius-md: 8px; --radius-lg: 12px;
  --radius-xl: 16px; --radius-pill: 9999px;

  --shadow-sm: 0 1px 2px rgba(80, 40, 20, 0.06);
  --shadow-md: 0 4px 12px rgba(80, 40, 20, 0.08);
  --shadow-lg: 0 8px 24px rgba(80, 40, 20, 0.10);
  --shadow-card: 0 2px 8px var(--card-shadow);

  color-scheme: light;
}

/* ============ DARK THEME — System Auto ============ */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #0c0a09;
    --bg-panel: #1a1614;
    --bg-elevated: #241e1b;
    --bg-hover: #312923;
    --bg-game: linear-gradient(145deg, #0f0d0b 0%, #1a1512 50%, #0c0a09 100%);

    --text-primary: rgba(248, 242, 236, 0.94);
    --text-secondary: rgba(220, 200, 186, 0.72);
    --text-tertiary: rgba(180, 155, 138, 0.52);
    --text-quaternary: rgba(140, 115, 100, 0.42);

    --brand: #d4956e;
    --brand-rgb: 212, 149, 110;
    --accent: #e0ad88;
    --accent-hover: #ecc5a5;
    --gold: #d4b87a;
    --gold-glow: rgba(212, 184, 122, 0.2);
    --rose: #e08a9e;
    --rose-glow: rgba(224, 138, 158, 0.15);

    --green: #3ec97a;
    --green-bg: rgba(62, 201, 122, 0.12);
    --red: #ef6b6b;
    --red-bg: rgba(239, 107, 107, 0.12);
    --yellow: #e0b040;
    --orange: #e89050;

    --border-primary: rgba(200, 160, 130, 0.1);
    --border-secondary: rgba(200, 160, 130, 0.18);
    --border-tertiary: rgba(200, 160, 130, 0.26);

    --card-red: #ef6b6b;
    --card-black: #2a2420;
    --card-surface: #faf6f2;
    --card-shadow: rgba(0, 0, 0, 0.35);

    --landlord-bg: rgba(239, 107, 107, 0.1);
    --landlord-border: rgba(239, 107, 107, 0.25);
    --selected-glow: rgba(212, 149, 110, 0.45);
    --toast-bg: var(--bg-elevated);

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.25);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.3);
    --shadow-card: 0 2px 10px rgba(0, 0, 0, 0.4);

    color-scheme: dark;
  }
}

/* Force dark theme override */
:root.force-dark {
  --bg-primary: #0c0a09; --bg-panel: #1a1614; --bg-elevated: #241e1b;
  --bg-hover: #312923; --bg-game: linear-gradient(145deg, #0f0d0b 0%, #1a1512 50%, #0c0a09 100%);
  --text-primary: rgba(248, 242, 236, 0.94); --text-secondary: rgba(220, 200, 186, 0.72);
  --text-tertiary: rgba(180, 155, 138, 0.52); --text-quaternary: rgba(140, 115, 100, 0.42);
  --brand: #d4956e; --brand-rgb: 212, 149, 110; --accent: #e0ad88;
  --border-primary: rgba(200, 160, 130, 0.1); --border-secondary: rgba(200, 160, 130, 0.18);
  --card-red: #ef6b6b; --card-black: #2a2420; --card-surface: #faf6f2;
  --card-shadow: rgba(0, 0, 0, 0.5);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.25);
  --green: #3ec97a; --red: #ef6b6b; --gold: #d4b87a;
  color-scheme: dark;
}
:root.force-light {
  color-scheme: light;
}

/* ============ RESET & BASE ============ */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.screen { display: none; width: 100vw; min-height: 100dvh; height: 100dvh; }
.screen.active { display: flex; animation: fadeIn 0.25s ease; }
.hidden { display: none !important; }

/* ============ BUTTONS ============ */
.btn {
  padding: 8px 16px; border: none; border-radius: var(--radius-md);
  font-family: var(--font); font-size: 14px; font-weight: 550;
  cursor: pointer; transition: all 0.18s ease;
  letter-spacing: 0; white-space: nowrap;
}
.btn-primary {
  background: linear-gradient(135deg, var(--brand), var(--accent));
  color: white; box-shadow: 0 2px 8px rgba(var(--brand-rgb), 0.3);
}
.btn-primary:hover {
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  box-shadow: 0 4px 14px rgba(var(--brand-rgb), 0.4);
  transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0) scale(0.98); }
.btn-ghost {
  background: transparent; color: var(--text-secondary);
  border: 1px solid var(--border-secondary);
}
.btn-ghost:hover {
  background: var(--bg-hover); color: var(--text-primary);
  border-color: var(--border-tertiary);
}
.btn-accent {
  background: linear-gradient(135deg, var(--green), #2ab866);
  color: white; box-shadow: 0 2px 8px rgba(42, 157, 99, 0.25);
}
.btn-accent:hover { box-shadow: 0 4px 14px rgba(42, 157, 99, 0.35); transform: translateY(-1px); }
.btn-danger {
  background: transparent; color: var(--red);
  border: 1px solid rgba(217, 79, 79, 0.25);
}
.btn-danger:hover { background: var(--red-bg); }
.btn-hint {
  background: linear-gradient(135deg, var(--gold), #dabc7e);
  color: #3a2a10; font-weight: 600;
  box-shadow: 0 2px 8px var(--gold-glow);
}
.btn-hint:hover { box-shadow: 0 4px 14px var(--gold-glow); transform: translateY(-1px); }
.btn-block { width: 100%; padding: 11px 16px; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none !important; }

/* ============ AUTH SCREEN ============ */
.auth-container { margin: auto; width: 100%; max-width: 400px; padding: var(--space-6); }
.auth-logo { text-align: center; margin-bottom: var(--space-8); }
.logo-icon {
  font-size: 52px; margin-bottom: var(--space-4);
  filter: drop-shadow(0 4px 16px var(--rose-glow));
}
.auth-logo h1 {
  font-size: 28px; font-weight: 700; letter-spacing: -0.03em;
  background: linear-gradient(135deg, var(--brand), var(--rose));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.subtitle { color: var(--text-tertiary); font-size: 14px; margin-top: var(--space-2); letter-spacing: 0.02em; }
.auth-form {
  background: var(--bg-panel); border: 1px solid var(--border-primary);
  border-radius: var(--radius-xl); padding: var(--space-6); box-shadow: var(--shadow-md);
}
.form-group { margin-bottom: var(--space-4); }
.form-group label { display: block; font-size: 13px; font-weight: 550; color: var(--text-secondary); margin-bottom: var(--space-2); }
.form-group input, .form-group select {
  width: 100%; padding: 10px 12px; background: var(--bg-elevated);
  border: 1px solid var(--border-secondary); border-radius: var(--radius-md);
  color: var(--text-primary); font-size: 14px; font-family: var(--font);
  transition: border-color 0.18s, box-shadow 0.18s;
}
.form-group input:focus, .form-group select:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(var(--brand-rgb), 0.12);
}
.form-group input::placeholder { color: var(--text-quaternary); }
.auth-switch { text-align: center; margin-top: var(--space-4); font-size: 13px; color: var(--text-tertiary); }
.auth-switch a { color: var(--brand); text-decoration: none; font-weight: 550; }
.auth-switch a:hover { text-decoration: underline; }
.error-msg {
  margin-top: var(--space-4); padding: var(--space-3) var(--space-4);
  background: var(--red-bg); border: 1px solid rgba(217, 79, 79, 0.2);
  border-radius: var(--radius-md); color: var(--red); font-size: 13px; text-align: center;
}

/* ============ LOBBY SCREEN ============ */
.lobby-container {
  width: 100%; max-width: 820px; margin: 0 auto; padding: var(--space-6);
  display: flex; flex-direction: column; min-height: 100dvh; height: 100dvh;
  overflow-y: auto;
}
.lobby-header {
  display: flex; justify-content: space-between; align-items: center;
  padding-bottom: var(--space-5); border-bottom: 1px solid var(--border-primary);
}
.header-left { display: flex; align-items: center; gap: var(--space-3); }
.logo-small { font-size: 26px; filter: drop-shadow(0 2px 6px var(--rose-glow)); }
.lobby-header h2 { font-size: 20px; font-weight: 650; letter-spacing: -0.02em; }
.header-right { display: flex; align-items: center; gap: var(--space-3); }
.user-badge {
  padding: 4px 12px; background: var(--bg-elevated);
  border: 1px solid var(--border-primary); border-radius: var(--radius-pill);
  font-size: 13px; font-weight: 510; color: var(--text-secondary);
  display: inline-flex; align-items: center; gap: 6px;
}
.user-badge .badge-name { color: var(--text-primary); font-weight: 650; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-badge small,
.leaderboard-table small {
  display: block;
  color: var(--text-quaternary);
  font-size: 11px;
  font-weight: 500;
}
.leaderboard-table .display-name { display: block; font-weight: 650; color: var(--text-primary); }
.profile-avatar-preview {
  width: 86px; height: 86px; margin: 0 auto var(--space-5);
  border-radius: 22px; display: flex; align-items: center; justify-content: center;
  background: var(--bg-elevated); border: 1px solid var(--border-primary);
  box-shadow: var(--shadow-sm);
}
.form-tip { font-size: 12px; color: var(--text-tertiary); margin-top: var(--space-2); line-height: 1.5; }
.checkbox-row { display: flex; align-items: center; gap: var(--space-2); font-size: 13px; color: var(--text-secondary); cursor: pointer; }
.checkbox-row input { width: auto; accent-color: var(--brand); }
.checkbox-row.compact { margin: 0; white-space: nowrap; }
.pixel-avatar {
  --avatar-hue: 24;
  width: 44px; height: 44px; border-radius: 14px;
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px; padding: 6px;
  background: hsl(var(--avatar-hue), 76%, 92%);
  border: 1px solid hsla(var(--avatar-hue), 65%, 42%, 0.25);
}
.pixel-avatar i { border-radius: 2px; background: transparent; }
.pixel-avatar i.on { background: hsl(var(--avatar-hue), 70%, 42%); box-shadow: inset 0 -1px 0 rgba(0,0,0,0.12); }
.pixel-avatar.small { width: 24px; height: 24px; border-radius: 8px; padding: 4px; gap: 1px; }
.avatar-img {
  width: 44px; height: 44px; border-radius: 14px; object-fit: cover;
  display: block; box-shadow: inset 0 0 0 1px rgba(255,255,255,0.28);
}
.avatar-img.small { width: 24px; height: 24px; border-radius: 8px; }
.ai-avatar { font-size: 13px; font-weight: 800; letter-spacing: 0.04em; }
.seat-avatar .pixel-avatar,
.avatar-circle .pixel-avatar,
.seat-avatar .avatar-img,
.avatar-circle .avatar-img {
  width: 100%; height: 100%; border-radius: 50%;
}
.lobby-actions { display: flex; gap: var(--space-3); padding: var(--space-5) 0; align-items: center; flex-wrap: wrap; }
.join-by-id { display: flex; gap: var(--space-2); align-items: center; }
.join-by-id input {
  width: 140px; padding: 7px 12px; font-size: 13px;
  border: 1px solid var(--border-secondary); border-radius: var(--radius-md);
  background: var(--bg-elevated); color: var(--text-primary);
  font-family: 'Courier New', monospace; letter-spacing: 0.5px;
}
.join-by-id input::placeholder { color: var(--text-quaternary); font-family: var(--font); letter-spacing: 0; }
.user-stats { font-size: 12px; color: var(--text-tertiary); font-weight: 500; }
.room-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: var(--space-2); }
.room-item {
  display: flex; align-items: center; gap: var(--space-4);
  padding: var(--space-4) var(--space-5); background: var(--bg-panel);
  border: 1px solid var(--border-primary); border-radius: var(--radius-lg);
  transition: all 0.18s; box-shadow: var(--shadow-sm);
}
.room-item:hover {
  border-color: var(--border-secondary); background: var(--bg-elevated);
  box-shadow: var(--shadow-md); transform: translateY(-1px);
}
.room-item-info { flex: 1; min-width: 0; }
.room-item-title { display: flex; align-items: center; gap: var(--space-2); margin-bottom: 2px; }
.room-item-info h3 { font-size: 15px; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-item-info p { font-size: 13px; color: var(--text-tertiary); }
.room-id-tag {
  font-size: 11px; color: var(--text-quaternary); font-family: 'Courier New', monospace;
  background: var(--bg-elevated); padding: 1px 6px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-primary); flex-shrink: 0;
}
.room-item-meta { display: flex; align-items: center; gap: var(--space-3); flex-shrink: 0; }
.player-count-badge {
  font-size: 14px; font-weight: 600; color: var(--text-secondary);
  background: var(--bg-elevated); padding: 2px 10px; border-radius: var(--radius-pill);
  border: 1px solid var(--border-primary);
}
.count-sep { color: var(--text-quaternary); margin: 0 1px; }
.status-tag {
  font-size: 11px; font-weight: 550; padding: 2px 8px; border-radius: var(--radius-pill);
  background: var(--green-bg); color: var(--green); border: 1px solid rgba(42,157,99,0.15);
}
.status-tag.playing { background: rgba(200,149,32,0.1); color: var(--yellow); border-color: rgba(200,149,32,0.15); }
.room-item-actions { display: flex; gap: var(--space-2); flex-shrink: 0; }
.room-full-tag { font-size: 11px; color: var(--text-quaternary); font-weight: 500; }
.btn-sm { padding: 5px 14px !important; font-size: 12px !important; }
.btn-icon { font-size: 16px; font-weight: 700; margin-right: 2px; }
.player-count { font-size: 13px; color: var(--text-tertiary); font-weight: 510; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 6px rgba(42,157,99,0.4); }
.status-dot.playing { background: var(--yellow); box-shadow: 0 0 6px rgba(200,149,32,0.4); }
.empty-state { text-align: center; color: var(--text-quaternary); padding: var(--space-8) 0; font-size: 14px; }
.empty-icon { font-size: 48px; margin-bottom: var(--space-3); opacity: 0.6; }

/* Leaderboard */
.modal-wide { max-width: 560px; }
.leaderboard-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.leaderboard-table th {
  text-align: left; padding: 8px 10px; color: var(--text-tertiary);
  border-bottom: 1px solid var(--border-primary); font-weight: 600; font-size: 12px;
}
.leaderboard-table td { padding: 8px 10px; border-bottom: 1px solid var(--border-primary); }
.leaderboard-table tr.is-me { background: rgba(var(--brand-rgb), 0.08); }
.leaderboard-table .score-positive { color: var(--green); font-weight: 600; }
.leaderboard-table .score-negative { color: var(--red); font-weight: 600; }
.modal-overlay { position: absolute; inset: 0; z-index: 0; }

/* Modal */
.modal {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.45); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-content {
  position: relative;
  z-index: 1;
  background: var(--bg-panel); border: 1px solid var(--border-primary);
  border-radius: var(--radius-xl); padding: var(--space-6);
  width: 90%; max-width: 420px; box-shadow: var(--shadow-lg);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
}
.modal-content h3 { font-size: 18px; font-weight: 650; margin-bottom: var(--space-5); }
.modal-actions { display: flex; justify-content: flex-end; gap: var(--space-3); margin-top: var(--space-5); }

/* ============ ROOM SCREEN ============ */
.room-container {
  width: 100%; max-width: 920px; margin: 0 auto; padding: var(--space-6);
  display: flex; flex-direction: column; min-height: 100dvh; height: 100dvh;
  overflow-y: auto;
}
.room-header {
  display: flex; align-items: center; gap: var(--space-4);
  padding-bottom: var(--space-5); border-bottom: 1px solid var(--border-primary);
}
.room-header h2 { flex: 1; font-size: 18px; font-weight: 600; }
.room-status-badge {
  padding: 4px 14px; background: var(--green-bg);
  border: 1px solid rgba(42,157,99,0.2); border-radius: var(--radius-pill);
  font-size: 12px; font-weight: 550; color: var(--green);
}
.seat-grid {
  flex: 1; display: grid; grid-template-columns: repeat(5, 1fr);
  gap: var(--space-4); padding: var(--space-6) 0; align-content: center;
}
.seat-card {
  background: var(--bg-panel); border: 1px solid var(--border-primary);
  border-radius: var(--radius-xl); padding: var(--space-6) var(--space-4);
  text-align: center; transition: all 0.2s; min-height: 170px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--space-3); box-shadow: var(--shadow-sm);
}
.seat-card.occupied { border-color: var(--border-secondary); }
.seat-card.ready { border-color: var(--green); box-shadow: 0 0 0 2px rgba(42,157,99,0.15); }
.seat-card.is-me { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(var(--brand-rgb),0.15); background: var(--bg-elevated); }
.seat-avatar {
  width: 50px; height: 50px; border-radius: 50%;
  background: var(--bg-elevated); border: 2px solid var(--border-secondary);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; color: var(--text-tertiary); transition: all 0.2s;
}
.seat-card.occupied .seat-avatar {
  background: linear-gradient(135deg, var(--brand), var(--accent));
  border-color: var(--brand); color: white; font-weight: 600;
}
.seat-card .seat-name { font-size: 14px; font-weight: 550; color: var(--text-primary); }
.seat-card .seat-status { font-size: 12px; color: var(--text-tertiary); }
.seat-card.ready .seat-status { color: var(--green); font-weight: 550; }
.seat-card .seat-owner {
  font-size: 11px; padding: 2px 10px;
  background: linear-gradient(135deg, rgba(var(--brand-rgb),0.12), var(--rose-glow));
  border-radius: var(--radius-pill); color: var(--brand); font-weight: 550;
}
.room-settings-panel {
  display: flex; justify-content: center; margin: 0 0 var(--space-4);
}
.room-settings-readonly,
.room-settings-editor {
  display: flex; align-items: center; justify-content: center; gap: var(--space-3); flex-wrap: wrap;
  padding: var(--space-3) var(--space-4); border-radius: var(--radius-lg);
  background: var(--bg-panel); border: 1px solid var(--border-primary);
  color: var(--text-secondary); font-size: 13px;
}
.room-settings-readonly strong { color: var(--brand); }
.room-settings-editor select,
.room-settings-score-input {
  padding: 7px 10px; border-radius: var(--radius-md); border: 1px solid var(--border-secondary);
  background: var(--bg-elevated); color: var(--text-primary); font-family: var(--font);
}
.room-settings-score-input { width: 92px; }
.seat-kick { font-size: 12px; color: var(--red); cursor: pointer; opacity: 0.6; transition: opacity 0.15s; }
.seat-kick:hover { opacity: 1; }
.room-controls {
  display: flex; justify-content: center; gap: var(--space-4);
  padding: var(--space-5) 0; border-top: 1px solid var(--border-primary);
}
.room-ready-summary {
  margin-top: calc(var(--space-4) * -1);
  margin-bottom: var(--space-4);
  padding: 12px 16px;
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.6;
  text-align: center;
}

/* ============ GAME SCREEN ============ */
.game-container {
  width: 100%; min-height: 100dvh; height: 100dvh; display: flex; flex-direction: column;
  padding: var(--space-4); padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom, 0px));
  position: relative; background: var(--bg-game);
}
.game-info-bar {
  display: flex; justify-content: space-between; align-items: center;
  padding: var(--space-3) var(--space-5); background: var(--bg-panel);
  border: 1px solid var(--border-primary); border-radius: var(--radius-lg);
  margin-bottom: var(--space-3); box-shadow: var(--shadow-sm);
}
.game-info-left { display: flex; align-items: center; gap: var(--space-3); font-size: 13px; color: var(--text-secondary); }
.game-info-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  justify-content: flex-end;
}
.marked-card-label { color: var(--text-tertiary); font-weight: 510; }
.landlord-label {
  padding: 2px 10px; background: var(--landlord-bg);
  border: 1px solid var(--landlord-border); border-radius: var(--radius-pill);
  color: var(--red); font-size: 12px; font-weight: 550;
}
.landlord-label.hidden-landlord {
  background: var(--gold-glow);
  border-color: rgba(201,169,110,0.3);
  color: var(--gold);
}
.turn-indicator { font-size: 13px; font-weight: 600; color: var(--brand); }
.turn-indicator.my-turn { color: var(--green); }
.turn-indicator.my-turn::before {
  content: ''; display: inline-block; width: 6px; height: 6px;
  border-radius: 50%; background: var(--green); margin-right: 6px;
  animation: pulse 1.5s infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

/* Other players */
.other-players { display: flex; justify-content: center; gap: var(--space-6); padding: var(--space-3) 0; }
.other-player { display: flex; flex-direction: column; align-items: center; gap: var(--space-2); min-width: 125px; }
.player-avatar { display: flex; flex-direction: column; align-items: center; gap: var(--space-1); }
.avatar-circle {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--bg-elevated); border: 2px solid var(--border-secondary);
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s; font-size: 16px;
}
.other-player.current-turn .avatar-circle {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(var(--brand-rgb),0.18), 0 0 26px rgba(var(--brand-rgb),0.68);
  transform: translateY(-2px) scale(1.08);
  animation: activeHalo 1.15s ease-in-out infinite alternate;
}
@keyframes activeHalo {
  from { box-shadow: 0 0 0 4px rgba(var(--brand-rgb),0.16), 0 0 18px rgba(var(--brand-rgb),0.45); }
  to { box-shadow: 0 0 0 8px rgba(var(--brand-rgb),0.08), 0 0 32px rgba(var(--brand-rgb),0.82); }
}
.other-player.is-landlord .avatar-circle { border-color: var(--red); background: var(--landlord-bg); }
.other-player.is-hidden-landlord .avatar-circle { border-color: var(--gold); background: var(--gold-glow); }
.player-name { font-size: 12px; font-weight: 550; color: var(--text-secondary); }
.card-count-badge {
  font-size: 11px; padding: 1px 8px; background: var(--bg-hover);
  border-radius: var(--radius-pill); color: var(--text-tertiary); font-weight: 510;
}
.card-count-badge.hidden-count { display: none; }
.player-last-play {
  font-size: 12px; color: var(--text-tertiary); min-height: 24px;
  text-align: center; display: flex; gap: 3px; flex-wrap: wrap; justify-content: center;
}

/* Play area */
.play-area { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 100px; }
.last-play-display { display: flex; gap: 5px; flex-wrap: wrap; justify-content: center; }

/* My hand */
.my-hand-area { display: flex; flex-direction: column; align-items: center; gap: var(--space-3); padding-bottom: var(--space-2); width: 100%; }
.hand-toolbar {
  display: flex; align-items: center; justify-content: center; gap: var(--space-3); flex-wrap: wrap;
  width: min(780px, 100%); padding: 7px 10px; border-radius: var(--radius-lg);
  background: rgba(255,255,255,0.54); border: 1px solid var(--border-primary);
  backdrop-filter: blur(10px);
}
.my-card-count { font-size: 13px; font-weight: 650; color: var(--text-secondary); }
.hand-mode-controls { display: inline-flex; gap: 4px; padding: 3px; border-radius: var(--radius-pill); background: var(--bg-elevated); }
.hand-mode-btn {
  border: 0; border-radius: var(--radius-pill); padding: 5px 10px;
  background: transparent; color: var(--text-tertiary); font: inherit; font-size: 12px; cursor: pointer;
}
.hand-mode-btn.active { background: var(--brand); color: #fff; box-shadow: 0 2px 8px rgba(var(--brand-rgb),0.22); }
.my-hand { display: flex; justify-content: center; flex-wrap: wrap; min-height: 115px; padding: 4px 0; max-width: 100%; width: 100%; touch-action: pan-y; }
.my-hand.hand-mode-stack { align-items: flex-end; gap: 10px; flex-wrap: nowrap; overflow-x: auto; justify-content: flex-start; padding: 8px 12px 18px; }
.hand-stack {
  display: flex; flex-direction: column; justify-content: flex-end;
  min-height: calc(92px + (var(--stack-size) - 1) * 22px);
}
.hand-stack .game-card { margin-left: 0; margin-top: -68px; }
.hand-stack .game-card:first-child { margin-top: 0; }
.my-hand.hand-mode-custom {
  display: grid; grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: var(--space-3); align-items: stretch; justify-content: stretch;
  padding: 6px; touch-action: pan-y;
}
.hand-zone {
  min-height: 128px; border: 1px dashed var(--border-secondary);
  border-radius: var(--radius-lg); background: rgba(255,255,255,0.42);
  padding: 8px; transition: border-color 0.16s, background 0.16s;
}
.hand-zone.drag-over { border-color: var(--brand); background: rgba(var(--brand-rgb),0.08); }
.hand-zone-title { font-size: 11px; color: var(--text-tertiary); margin-bottom: 6px; text-align: left; }
.hand-zone-cards { display: flex; flex-wrap: wrap; justify-content: center; align-items: flex-end; min-height: 90px; }
.hand-zone .game-card { margin-left: -24px; }
.hand-zone .game-card:first-child { margin-left: 0; }
.game-card.dragging { opacity: 0.45; }
.zone-dot {
  position: absolute; right: 5px; bottom: 5px; width: 6px; height: 6px;
  border-radius: 999px; background: var(--brand); opacity: 0.7;
}
.card-selection-hint {
  min-height: 20px;
  font-size: 13px;
  color: var(--text-tertiary);
  text-align: center;
}
.game-card {
  width: 62px; height: 90px; background: var(--card-surface);
  border-radius: var(--radius-md); display: flex; flex-direction: column;
  align-items: center; justify-content: center; font-weight: 700;
  cursor: pointer; transition: all 0.14s ease; margin-left: -20px;
  border: 2px solid transparent; box-shadow: var(--shadow-card);
  user-select: none; position: relative; touch-action: none; -webkit-tap-highlight-color: transparent;
}
.game-card:first-child { margin-left: 0; }
.game-card.red { color: var(--card-red); }
.game-card.black { color: var(--card-black); }
.game-card.joker-small { color: #3b82f6; background: linear-gradient(135deg, var(--card-surface), #e0e7ff); }
.game-card.joker-big { color: var(--card-red); background: linear-gradient(135deg, var(--card-surface), #fee2e2); }
.game-card.selected { transform: translateY(-18px); border-color: var(--brand); box-shadow: 0 6px 20px var(--selected-glow); }
.game-card.hint { border-color: var(--gold); box-shadow: 0 0 12px var(--gold-glow); }
.game-card .card-rank { font-size: 18px; font-weight: 700; line-height: 1; }
.game-card .card-suit { font-size: 14px; line-height: 1; margin-top: 2px; }

/* Mini cards */
.card-mini {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 2px 7px; background: var(--card-surface); border-radius: 4px;
  font-size: 13px; font-weight: 600; min-width: 28px; box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-primary);
}
.card-mini.red { color: var(--card-red); }
.card-mini.black { color: var(--card-black); }

/* Display cards */
.display-card {
  width: 50px; height: 70px; background: var(--card-surface);
  border-radius: var(--radius-sm); display: flex; flex-direction: column;
  align-items: center; justify-content: center; margin-left: -12px;
  box-shadow: var(--shadow-card);
}
.display-card:first-child { margin-left: 0; }
.display-card .card-rank { font-size: 14px; font-weight: 700; line-height: 1; }
.display-card .card-suit { font-size: 11px; line-height: 1; }
.display-card.red { color: var(--card-red); }
.display-card.black { color: var(--card-black); }
.visible-hand-strip {
  width: min(260px, 80vw); display: flex; flex-wrap: wrap; justify-content: center;
  gap: 2px; margin-top: 4px; max-height: 76px; overflow: hidden;
}
.room-multiplier-badge {
  padding: 3px 9px; border-radius: var(--radius-pill);
  background: var(--gold-glow); color: var(--gold); font-size: 12px; font-weight: 650;
}

.game-actions { display: flex; gap: var(--space-3); width: 100%; justify-content: center; }
.game-actions .btn { padding: 9px 30px; font-size: 15px; border-radius: var(--radius-lg); }

@media (hover: hover) and (pointer: fine) {
  .game-card:hover {
    transform: translateY(-10px);
    z-index: 10;
    box-shadow: 0 6px 20px var(--card-shadow);
  }
}
.start-confirm-text {
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.65;
}
.start-confirm-players {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: var(--space-4);
}
.start-confirm-player {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 10px 12px;
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  font-size: 13px;
  color: var(--text-primary);
}
.start-confirm-player.ready {
  border-color: rgba(42,157,99,0.25);
  background: var(--green-bg);
}
.start-confirm-player.ai {
  color: var(--text-secondary);
}
.start-confirm-player span:last-child {
  color: var(--text-tertiary);
  white-space: nowrap;
}

/* Game Over */
.game-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.55); display: flex; align-items: center;
  justify-content: center; z-index: 200; backdrop-filter: blur(8px);
}
.game-over-card {
  background: var(--bg-panel); border: 1px solid var(--border-primary);
  border-radius: var(--radius-xl); padding: var(--space-7); text-align: center;
  width: min(420px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.game-over-card h2 { font-size: 26px; font-weight: 700; margin-bottom: var(--space-5); }
.game-over-card .score-item {
  display: flex; justify-content: space-between; padding: var(--space-2) var(--space-3);
  font-size: 14px; color: var(--text-secondary); border-bottom: 1px solid var(--border-primary);
}
.game-over-card .score-item:last-child { border-bottom: none; }
.game-over-card .score-positive { color: var(--green); font-weight: 600; }
.game-over-card .score-negative { color: var(--red); font-weight: 600; }
.game-over-card .btn { margin-top: var(--space-5); }
.game-over-meta {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 6px;
  margin: -6px 0 var(--space-4);
}
.game-over-meta span {
  padding: 3px 9px; border-radius: var(--radius-pill); background: var(--bg-elevated);
  color: var(--text-tertiary); font-size: 12px;
}
.game-over-final-hands {
  display: flex; flex-direction: column; gap: 8px; margin: var(--space-4) 0;
  text-align: left;
}
.final-hands-title { font-size: 13px; font-weight: 650; color: var(--text-secondary); text-align: center; }
.final-hand-row {
  padding: 8px; border: 1px solid var(--border-primary); border-radius: var(--radius-lg);
  background: var(--bg-elevated);
}
.final-hand-row.winner { border-color: rgba(42,157,99,0.35); background: var(--green-bg); }
.final-hand-head { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; font-size: 12px; color: var(--text-secondary); }
.final-hand-head strong { color: var(--text-primary); }
.final-hand-head em { font-style: normal; color: var(--brand); }
.final-hand-head span:last-child { margin-left: auto; color: var(--text-tertiary); }
.final-hand-cards { display: flex; flex-wrap: wrap; gap: 3px; max-height: 86px; overflow-y: auto; }
.final-empty { font-size: 12px; color: var(--green); }

/* Toast */
.toast {
  position: fixed; top: max(20px, env(safe-area-inset-top, 0px)); left: 50%; transform: translateX(-50%);
  background: var(--toast-bg); color: var(--text-primary);
  padding: 10px 24px; border-radius: var(--radius-lg);
  border: 1px solid var(--border-secondary); font-size: 14px; font-weight: 510;
  z-index: 9999; box-shadow: var(--shadow-md); animation: toastIn 0.25s ease;
  max-width: calc(100vw - 32px);
  text-align: center;
}
@keyframes toastIn { from { opacity:0; transform:translateX(-50%) translateY(-10px); } to { opacity:1; transform:translateX(-50%) translateY(0); } }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-secondary); border-radius: 3px; }

/* Animations */
@keyframes fadeIn { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:translateY(0); } }

/* Responsive */
@media (max-width: 1024px) {
  .lobby-container,
  .room-container,
  .game-container {
    padding: var(--space-4);
  }

  .lobby-header,
  .room-header,
  .game-info-bar {
    gap: var(--space-3);
  }

  .room-item {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .room-item-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .other-players {
    flex-wrap: wrap;
  }

  .game-actions,
  .marked-selection-area {
    position: sticky;
    bottom: env(safe-area-inset-bottom, 0px);
    z-index: 30;
  }
}

@media (max-width: 768px) {
  .lobby-container,
  .room-container {
    padding: var(--space-3);
  }
  .lobby-header {
    flex-wrap: wrap;
    gap: var(--space-3);
  }
  .header-right {
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
  }
  .lobby-actions {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-2);
    padding: var(--space-3) 0;
  }
  .join-by-id {
    width: 100%;
  }
  .join-by-id input {
    flex: 1;
    width: auto;
  }
  .room-item-actions {
    justify-content: stretch;
  }
  .room-item-actions .btn {
    flex: 1;
  }
  .modal-content {
    width: calc(100vw - 24px);
    padding: var(--space-5);
  }
  .game-over-card {
    padding: var(--space-6) var(--space-5);
  }
  .room-header { flex-wrap: wrap; }
  .seat-grid { grid-template-columns: repeat(3, 1fr); }
  .room-controls { flex-wrap: wrap; }
  #gameScreen {
    --mobile-action-height: 70px;
  }
  .game-container {
    gap: 6px;
    padding: 8px;
    padding-bottom: calc(var(--mobile-action-height) + 22px + env(safe-area-inset-bottom, 0px));
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .game-info-bar {
    position: sticky;
    top: 0;
    z-index: 40;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    gap: 7px 8px;
    padding: 8px 10px;
    margin-bottom: 0;
    border-radius: var(--radius-lg);
    background: color-mix(in srgb, var(--bg-panel) 88%, transparent);
    backdrop-filter: blur(14px);
  }
  .game-info-left {
    flex: 1 1 172px;
    min-width: 0;
    flex-wrap: wrap;
    gap: 6px;
    font-size: 12px;
  }
  .game-info-right {
    flex: 1 1 148px;
    justify-content: flex-end;
    gap: 6px;
  }
  .game-info-right .btn {
    min-height: 34px;
    padding: 6px 11px;
    border-radius: var(--radius-md);
    font-size: 12px;
  }
  .marked-card-label { display: none; }
  .landlord-label,
  .room-multiplier-badge {
    padding: 3px 8px;
    font-size: 12px;
    white-space: nowrap;
  }
  .turn-indicator {
    flex-basis: 100%;
    font-size: 13px;
  }
  .card-mini {
    min-width: 25px;
    padding: 1px 6px;
    font-size: 12px;
  }
  .other-players {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
    padding: 6px 0 0;
  }
  .other-player {
    min-width: 0;
    gap: 3px;
  }
  .avatar-circle {
    width: 38px;
    height: 38px;
    font-size: 14px;
  }
  .other-player.current-turn .avatar-circle {
    box-shadow: 0 0 0 5px rgba(var(--brand-rgb),0.2), 0 0 30px rgba(var(--brand-rgb),0.78);
    transform: translateY(-1px) scale(1.1);
  }
  .player-name {
    max-width: 96px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 11px;
  }
  .card-count-badge {
    padding: 1px 6px;
    font-size: 10px;
  }
  .player-last-play {
    min-height: 18px;
    max-height: 38px;
    overflow: hidden;
    gap: 2px;
  }
  .player-last-play .card-mini {
    min-width: 20px;
    padding: 1px 4px;
    font-size: 10px;
  }
  .play-area {
    min-height: 52px;
    flex: 0 0 auto;
    padding: 1px 0;
  }
  .last-play-display {
    max-width: 100%;
    padding: 0 6px;
  }
  .display-card {
    width: 40px;
    height: 56px;
    margin-left: -10px;
    border-radius: 8px;
  }
  .display-card .card-rank { font-size: 13px; }
  .display-card .card-suit { font-size: 10px; }
  .my-hand-area {
    align-items: stretch;
    gap: 6px;
    padding-bottom: calc(var(--mobile-action-height) + 14px + env(safe-area-inset-bottom, 0px));
  }
  .game-actions {
    position: fixed;
    left: max(10px, env(safe-area-inset-left, 0px));
    right: max(10px, env(safe-area-inset-right, 0px));
    bottom: max(10px, env(safe-area-inset-bottom, 0px));
    z-index: 120;
    width: auto;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    padding: 10px;
    min-height: var(--mobile-action-height);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-xl);
    background: var(--bg-panel);
    background: color-mix(in srgb, var(--bg-panel) 92%, transparent);
    backdrop-filter: blur(16px);
    box-shadow: var(--shadow-md);
  }
  .card-selection-hint {
    order: 1;
    min-height: 16px;
    padding: 0 6px;
    font-size: 12px;
    line-height: 1.35;
  }
  .hand-toolbar {
    order: 0;
    display: grid;
    grid-template-columns: auto minmax(160px, 1fr) auto;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    padding: 6px;
    border-radius: var(--radius-lg);
    background: var(--bg-panel);
    background: color-mix(in srgb, var(--bg-panel) 86%, transparent);
    box-shadow: var(--shadow-sm);
  }
  .my-card-count {
    white-space: nowrap;
    font-size: 12px;
  }
  .hand-mode-controls {
    width: 100%;
    justify-content: space-between;
  }
  .hand-mode-btn {
    flex: 1;
    min-height: 32px;
    padding: 6px 8px;
  }
  #revealHandBtn {
    min-height: 32px;
    padding: 6px 10px;
    font-size: 12px;
  }
  .my-hand {
    order: 2;
    min-height: 0;
    justify-content: center;
    align-content: flex-start;
    row-gap: 12px;
    padding: 8px 8px 12px;
  }
  .my-hand.hand-mode-stack {
    justify-content: flex-start;
    min-height: 112px;
    padding: 8px 10px 14px;
    scroll-snap-type: x proximity;
  }
  .hand-stack {
    min-height: calc(70px + (var(--stack-size) - 1) * 15px);
    scroll-snap-align: start;
  }
  .hand-stack .game-card { margin-top: -55px; }
  .my-hand.hand-mode-custom {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
    max-height: 42dvh;
    overflow-y: auto;
    padding: 6px;
  }
  .hand-zone { min-height: 98px; padding: 6px; }
  .hand-zone-title { margin-bottom: 4px; font-size: 10px; }
  .hand-zone .game-card { margin-left: -18px; }
  .game-card {
    width: 48px;
    height: 70px;
    margin-left: -12px;
    border-radius: 10px;
  }
  .game-card .card-rank { font-size: 15px; }
  .game-card .card-suit { font-size: 11px; }
  .game-card.selected {
    transform: translateY(-11px);
    z-index: 20;
  }
  .game-actions .btn {
    min-width: 0;
    min-height: 46px;
    padding: 8px 10px;
    border-radius: var(--radius-lg);
    font-size: 14px;
    font-weight: 650;
  }
  .marked-selection-area {
    position: fixed;
    left: max(10px, env(safe-area-inset-left, 0px));
    right: max(10px, env(safe-area-inset-right, 0px));
    bottom: max(10px, env(safe-area-inset-bottom, 0px));
    z-index: 121;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin: 0;
    padding: 10px;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
    backdrop-filter: blur(16px);
  }
  .marked-selection-hint {
    flex: 1 1 100%;
    font-size: 12px;
    line-height: 1.45;
    text-align: center;
  }
  .marked-selection-area .btn {
    flex: 1;
    min-height: 44px;
    padding: 8px 10px;
  }
  .chat-panel {
    left: var(--space-3);
    right: var(--space-3);
    bottom: calc(var(--mobile-action-height) + 24px + env(safe-area-inset-bottom, 0px));
    width: auto;
    max-height: 52dvh;
  }
  .chat-badge {
    bottom: calc(var(--mobile-action-height) + 22px + env(safe-area-inset-bottom, 0px));
    right: var(--space-3);
  }
}

@media (max-width: 768px) and (max-height: 760px) {
  #gameScreen { --mobile-action-height: 64px; }
  .game-container { padding-top: 6px; gap: 4px; }
  .game-info-bar { padding: 7px 9px; gap: 5px 7px; }
  .other-players { gap: 5px; padding-top: 4px; }
  .avatar-circle { width: 34px; height: 34px; }
  .player-name { font-size: 10px; }
  .play-area { min-height: 42px; }
  .hand-toolbar { padding: 5px; }
  .hand-mode-btn { min-height: 30px; padding: 5px 7px; }
  .my-hand { row-gap: 9px; padding-top: 5px; }
  .game-card { width: 45px; height: 66px; margin-left: -13px; }
  .game-actions { min-height: var(--mobile-action-height); padding: 8px; }
  .game-actions .btn { min-height: 42px; }
}

@media (max-width: 420px) {
  .hand-toolbar {
    grid-template-columns: 1fr auto;
  }
  .hand-mode-controls {
    grid-column: 1 / -1;
    order: 2;
  }
  .my-card-count {
    min-width: 0;
  }
  .game-card {
    width: 44px;
    height: 66px;
    margin-left: -13px;
  }
  .game-actions .btn {
    font-size: 13px;
  }
}

/* ============ SPECTATOR ============ */
.spectator-badge {
  position: fixed; top: 12px; right: 12px; z-index: 100;
  background: var(--rose); color: #fff;
  padding: 6px 16px; border-radius: 20px;
  font-size: 13px; font-weight: 600;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.spectator-controls {
  display: flex; align-items: center; gap: var(--space-3);
  justify-content: center; margin: var(--space-3) 0;
}

.spectator-all-players {
  display: flex; flex-direction: column; gap: var(--space-4);
  padding: var(--space-3); max-height: calc(100dvh - 260px); overflow-y: auto;
}

.spectator-player {
  background: var(--bg-panel); border: 1px solid var(--border-primary);
  border-radius: var(--radius-l); padding: var(--space-3) var(--space-4);
  transition: border-color 0.2s;
}
.spectator-player.current-turn {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(var(--brand-rgb), 0.18), 0 0 28px rgba(var(--brand-rgb), 0.34);
}
.spectator-player.is-landlord {
  background: var(--landlord-bg);
  border-color: var(--landlord-border);
}
.spectator-player.is-hidden-landlord {
  border-left: 3px solid var(--gold);
}

.spectator-player-header {
  display: flex; align-items: center; gap: var(--space-2);
  margin-bottom: var(--space-2); font-size: 14px;
}
.spectator-player-name { font-weight: 600; color: var(--text-primary); }
.spectator-card-count { color: var(--text-tertiary); font-size: 12px; }
.spectator-turn-badge {
  background: var(--brand); color: #fff;
  padding: 2px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 600;
}

.spectator-last-play {
  min-height: 24px; margin-bottom: var(--space-2);
  display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
}
.spectator-pass {
  color: var(--text-tertiary); font-size: 12px; font-style: italic;
}

.spectator-hand {
  display: flex; flex-wrap: wrap; gap: 3px;
}
.spectator-card {
  width: 36px; height: 52px;
  background: var(--card-surface);
  border: 1px solid var(--border-primary);
  border-radius: 4px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600;
  box-shadow: 0 1px 2px var(--card-shadow);
}
.spectator-card.red { color: var(--card-red); }
.spectator-card.black { color: var(--card-black); }
.spectator-card.joker-big { background: linear-gradient(135deg, #ffe0e0, #fff); }
.spectator-card.joker-small { background: linear-gradient(135deg, #e0ffe0, #fff); }
.spectator-card .card-rank { font-size: 12px; line-height: 1.1; }
.spectator-card .card-suit { font-size: 9px; line-height: 1; }

/* Card Counter Panel */
.card-counter-panel {
  background: var(--bg-panel); border: 1px solid var(--border-primary);
  border-radius: var(--radius-l); padding: var(--space-3) var(--space-4);
  margin: var(--space-3) 0;
}
.card-counter-panel h4 {
  margin: 0 0 var(--space-2) 0; font-size: 13px;
  color: var(--text-secondary); font-weight: 600;
}
.card-counter-grid {
  display: flex; flex-wrap: wrap; gap: 6px;
}
.counter-item {
  display: flex; flex-direction: column; align-items: center;
  padding: 4px 8px; border-radius: 6px;
  background: var(--bg-elevated); min-width: 40px;
  border: 1px solid var(--border-primary);
  transition: background 0.2s;
}
.counter-item.counter-empty {
  opacity: 0.35; background: var(--bg-hover);
}
.counter-item.counter-low {
  background: var(--red-bg); border-color: rgba(217, 79, 79, 0.25);
}
.counter-rank { font-weight: 700; font-size: 13px; color: var(--text-primary); }
.counter-value { font-size: 11px; color: var(--text-tertiary); }

/* Room list spectate elements */

/* Marked card selection */
.marked-selection-area {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--landlord-bg); border: 1px solid var(--landlord-border);
  border-radius: var(--radius-lg); margin-bottom: var(--space-2);
}
.marked-selection-hint {
  font-size: 14px; font-weight: 550; color: var(--red);
}

/* Game History & Replay */
.history-content { max-height: 400px; overflow-y: auto; }
.replay-content { max-height: 400px; overflow-y: auto; }
.modal-replay { max-width: 1080px; }
.replay-toolbar {
  display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap;
  margin-bottom: var(--space-4); padding: var(--space-3);
  background: var(--bg-elevated); border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
}
.replay-range { flex: 1; min-width: 140px; }
.replay-jump-box { display: flex; align-items: center; gap: var(--space-2); }
.replay-jump-input {
  width: 72px; padding: 7px 10px; border-radius: var(--radius-md);
  border: 1px solid var(--border-secondary); background: var(--bg-panel);
  color: var(--text-primary); font-family: var(--font);
}
.replay-summary-card {
  margin-bottom: var(--space-4); padding: var(--space-4);
  background: var(--bg-elevated); border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
}
.replay-summary-line {
  display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap;
  font-size: 13px; color: var(--text-secondary);
}
.replay-summary-line + .replay-summary-line { margin-top: var(--space-2); }
.replay-round-tip { color: var(--text-tertiary); }
.replay-turns { display: flex; flex-direction: column; gap: 4px; }
.replay-turn {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 4px 8px; border-radius: 6px; font-size: 13px;
}
.replay-turn:nth-child(odd) { background: var(--bg-elevated); }
.replay-player { font-weight: 600; color: var(--brand); min-width: 60px; }
.replay-step { font-size: 13px; color: var(--text-secondary); font-weight: 510; }
.replay-empty {
  padding: var(--space-4); text-align: center; color: var(--text-tertiary);
  background: var(--bg-elevated); border-radius: var(--radius-lg);
  margin-bottom: var(--space-4);
}
.replay-hands-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3); margin-top: var(--space-4);
}
.replay-player-panel { min-height: 170px; }
.replay-final-scores {
  margin-top: var(--space-4); padding: var(--space-3);
  background: var(--bg-elevated); border-radius: var(--radius-lg); font-size: 13px;
}
.btn-spectate {
  background: var(--gold); color: #fff;
  border: none; padding: 4px 12px; border-radius: 12px;
  font-size: 12px; cursor: pointer; font-weight: 600;
  transition: background 0.15s;
}
.btn-spectate:hover { background: var(--orange); }
.spectator-count {
  font-size: 11px; color: var(--text-tertiary);
  margin-left: 4px;
}

/* Spectate Request Modal */
.spectate-request-modal {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.4);
}
.spectate-request-modal.hidden { display: none; }
.spectate-request-content {
  background: var(--bg-panel); border-radius: var(--radius-l);
  padding: var(--space-5); text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2); max-width: 340px;
}
.spectate-request-content p { margin: 0 0 var(--space-4) 0; font-size: 15px; color: var(--text-primary); }
.spectate-request-content .btn { margin: 0 var(--space-2); }

@media (max-width: 768px) {
  .replay-hands-grid { grid-template-columns: 1fr; }
  .replay-toolbar { align-items: stretch; }
  .replay-jump-box { width: 100%; justify-content: space-between; }
  .replay-range { width: 100%; flex-basis: 100%; }
}

/* Chat Panel */
.chat-panel {
  position: fixed; bottom: var(--space-4); right: var(--space-4);
  width: 300px; max-height: 400px; z-index: 150;
  background: var(--bg-panel); border-radius: var(--radius-l);
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.chat-panel.collapsed { transform: translateX(calc(100% + 16px)); opacity: 0; pointer-events: none; }
.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  user-select: none;
}
.chat-header h4 { margin: 0; font-size: 13px; color: var(--text-primary); }
.chat-toggle-btn { background: none; border: none; color: var(--text-tertiary); cursor: pointer; font-size: 16px; padding: 0 4px; }
.chat-messages {
  flex: 1; overflow-y: auto; padding: var(--space-2);
  min-height: 120px; max-height: 260px;
  display: flex; flex-direction: column; gap: var(--space-1);
}
.chat-message { font-size: 12px; line-height: 1.4; }
.chat-message .chat-user { font-weight: 600; color: var(--brand); }
.chat-message .chat-user.system { color: var(--text-tertiary); }
.chat-message .chat-text { color: var(--text-primary); }
.chat-input-row {
  display: flex; padding: var(--space-1) var(--space-2);
  border-top: 1px solid var(--border-light);
}
.chat-input-row input {
  flex: 1; border: none; background: var(--bg-hover);
  padding: 6px 10px; border-radius: var(--radius-m);
  font-size: 12px; color: var(--text-primary); outline: none;
}
.chat-input-row input::placeholder { color: var(--text-quaternary); }
.chat-input-row button {
  margin-left: var(--space-1); padding: 4px 10px;
  border: none; background: var(--brand); color: #fff;
  border-radius: var(--radius-m); font-size: 12px; cursor: pointer;
}
.chat-badge {
  position: fixed; bottom: var(--space-4); right: var(--space-4);
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--brand); color: #fff; font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; z-index: 151;
  box-shadow: var(--shadow-md);
}
.chat-badge.hidden { display: none; }
.chat-badge .unread-dot {
  position: absolute; top: -2px; right: -2px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--rose); border: 2px solid #fff;
}
.chat-badge .unread-dot.hidden { display: none; }
