/* ============ Design tokens — White Art Theme ============ */
:root {
  --bg: #FAFAF7;
  --surface: #FFFFFF;
  --surface-2: #F5F2EC;
  --surface-3: #EBE6DC;
  --border: #E5E1D5;
  --border-strong: #C9C3B5;

  --primary: #B45309;
  --primary-hover: #92400E;
  --primary-soft: #FEF3C7;
  --primary-dim: rgba(180, 83, 9, 0.08);

  --emerald: #059669;
  --red: #DC2626;
  --blue: #2563EB;
  --pink: #DB2777;

  --text: #18181B;
  --text-2: #52525B;
  --text-muted: #8B7E6B;

  --shadow-xs: 0 1px 2px rgba(60, 40, 10, 0.05);
  --shadow-sm: 0 2px 6px rgba(60, 40, 10, 0.07);
  --shadow: 0 6px 20px rgba(60, 40, 10, 0.1);
  --shadow-lg: 0 16px 48px rgba(60, 40, 10, 0.14);

  --radius: 10px;
  --radius-lg: 16px;
  --radius-pill: 999px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Sarabun', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

body {
  background-color: var(--bg);
  background-image:
    radial-gradient(ellipse at top right, rgba(217, 119, 6, 0.06), transparent 55%),
    radial-gradient(ellipse at bottom left, rgba(180, 83, 9, 0.04), transparent 50%),
    url('img/bangkok-street.svg');
  background-repeat: no-repeat, no-repeat, no-repeat;
  background-position: top right, bottom left, center bottom;
  background-size: auto, auto, 1400px auto;
  background-attachment: fixed, fixed, fixed;
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }

button {
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 10px 16px;
  background: var(--surface-2);
  color: var(--text);
  transition: all 0.15s ease;
}
button:hover { background: var(--surface-3); }
button.primary {
  background: var(--primary);
  color: #FFFFFF;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}
button.primary:hover { background: var(--primary-hover); box-shadow: var(--shadow); }
button.ghost {
  background: var(--surface);
  border-color: var(--border);
}
button.ghost:hover { background: var(--surface-2); border-color: var(--border-strong); }

input {
  font-family: inherit;
  font-size: 14px;
  padding: 10px 14px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: all 0.15s;
}
input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-dim);
}
input::placeholder { color: var(--text-muted); }

/* ============ Header ============ */
header {
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
  flex-wrap: wrap;
  box-shadow: var(--shadow-xs);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}
.logo-mark {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, #D97706, #92400E);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: #FFFFFF;
  box-shadow: 0 4px 12px rgba(217, 119, 6, 0.35);
}
.logo-text { display: flex; flex-direction: column; line-height: 1.15; }
.logo-text small { font-size: 11px; color: var(--text-muted); font-weight: 400; }

.header-spacer { flex: 1; }

.user-bar { display: flex; gap: 8px; align-items: center; }
.user-bar input { width: 180px; }

.back-btn {
  padding: 8px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text-2);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.back-btn:hover { background: var(--surface-3); color: var(--text); }

/* ============ Page layout ============ */
main { max-width: 1280px; margin: 0 auto; padding: 24px; }

/* ============ Hero (lobby) ============ */
.hero {
  background-color: #FFFCF6;
  background-image:
    radial-gradient(circle at 100% 0%, rgba(217, 119, 6, 0.18), transparent 55%),
    radial-gradient(circle at 0% 100%, rgba(180, 83, 9, 0.1), transparent 50%),
    url('img/chess-pattern.svg');
  background-repeat: no-repeat, no-repeat, repeat;
  background-size: auto, auto, 280px 280px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 40px;
  margin-bottom: 24px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 28px;
  align-items: center;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.hero::after {
  content: '';
  position: absolute;
  top: -20px; right: -20px;
  width: 180px; height: 180px;
  background: radial-gradient(circle, rgba(217, 119, 6, 0.15), transparent 70%);
  pointer-events: none;
}

.hero-text { position: relative; z-index: 1; }

.hero-title {
  font-size: 30px;
  font-weight: 700;
  margin: 0 0 10px;
  background: linear-gradient(135deg, #18181B 30%, #B45309);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  letter-spacing: -0.02em;
}
.hero-sub {
  color: var(--text-2);
  margin: 0 0 18px;
  font-size: 15px;
  max-width: 540px;
}

.hero-stats {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.stat-chip {
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--border);
  padding: 7px 14px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  color: var(--text-2);
  display: flex;
  align-items: center;
  gap: 8px;
  backdrop-filter: blur(6px);
}
.stat-chip strong { color: var(--text); font-weight: 600; }
.stat-chip .live-dot {
  width: 8px; height: 8px;
  background: var(--red);
  border-radius: 50%;
  animation: pulse 1.6s ease-in-out infinite;
}

.hero-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 280px;
  position: relative;
  z-index: 1;
}
.hero-actions input { font-size: 15px; background: rgba(255, 255, 255, 0.9); }
.hero-actions button { padding: 12px 20px; font-size: 15px; }

@media (max-width: 720px) {
  .hero { grid-template-columns: 1fr; padding: 28px 24px; }
  .hero-actions { min-width: 0; }
  .hero-title { font-size: 24px; }
}

/* ============ Lobby grid ============ */
.lobby-grid {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 24px;
}
@media (max-width: 980px) {
  .lobby-grid { grid-template-columns: 1fr; }
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 16px;
}
.section-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}
.section-header .live-dot {
  width: 8px; height: 8px;
  background: var(--red);
  border-radius: 50%;
  animation: pulse 1.6s ease-in-out infinite;
}

.rooms-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.room-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: all 0.2s;
  cursor: pointer;
  box-shadow: var(--shadow-xs);
}
.room-card:hover {
  border-color: var(--primary);
  transform: translateY(-3px);
  box-shadow: var(--shadow);
}

.room-thumb {
  aspect-ratio: 16/9;
  background: linear-gradient(135deg, #5A3A1A, #3E2A12);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.mini-board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  height: 100%;
  aspect-ratio: 1/1;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}
.mb-sq {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  line-height: 1;
}
.mb-light { background: #F0D9B5; }
.mb-dark { background: #B58863; }
.mb-w {
  color: #FFFFFF;
  text-shadow: 0 0 1px #000, 1px 0 0 #000, -1px 0 0 #000, 0 1px 0 #000, 0 -1px 0 #000;
}
.mb-b { color: #1A1A1A; }
.mini-board-empty { font-size: 56px; opacity: 0.5; color: #FFF; }

.thumb-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 10px;
  z-index: 2;
}
.thumb-overlay-top { display: flex; justify-content: space-between; align-items: flex-start; }
.thumb-overlay-bottom { display: flex; justify-content: space-between; align-items: flex-end; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: var(--radius-pill);
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(8px);
  color: white;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge.live { background: var(--red); }
.badge.live .live-dot { background: white; }
.badge.waiting { background: var(--primary); }
.badge.ended { background: rgba(0, 0, 0, 0.55); }

.thumb-pill {
  font-size: 12px;
  padding: 4px 9px;
  border-radius: var(--radius-pill);
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(8px);
  color: white;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.room-card-body { padding: 14px; }
.room-name {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.room-meta {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--text-muted);
}

.empty {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  grid-column: 1 / -1;
}
.empty-icon { font-size: 40px; margin-bottom: 12px; opacity: 0.5; color: var(--primary); }

/* ============ Lobby sidebar ============ */
.lobby-sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.info-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-xs);
}
.info-card h3 {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}
.info-card p { margin: 0 0 8px; font-size: 13px; color: var(--text-2); }
.info-card ol { margin: 8px 0 0; padding-left: 20px; font-size: 13px; color: var(--text-2); line-height: 1.8; }
.info-card a { color: var(--primary); font-weight: 500; }
.info-card a:hover { text-decoration: underline; }

/* ============ Ad slots ============ */
.ad-slot {
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  color: var(--text-muted);
  position: relative;
  font-size: 12px;
  text-align: center;
  overflow: hidden;
}
.ad-slot::before {
  content: 'ADVERTISEMENT';
  position: absolute;
  top: 6px;
  left: 10px;
  font-size: 9px;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  opacity: 0.7;
}
.ad-slot .ad-size { font-size: 11px; opacity: 0.6; margin-top: 4px; }

.ad-leaderboard { width: 100%; max-width: 728px; height: 90px; margin: 0 auto 24px; }
.ad-rectangle { width: 100%; max-width: 300px; height: 250px; margin: 0 auto; }
.ad-skyscraper { width: 100%; max-width: 300px; height: 600px; margin: 0 auto; }
.ad-banner-mobile { width: 100%; max-width: 320px; height: 50px; margin: 12px auto; }

@media (max-width: 728px) {
  .ad-leaderboard { height: 50px; max-width: 320px; }
}

/* ============ Room page ============ */
.room-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 20px;
}
@media (max-width: 980px) { .room-grid { grid-template-columns: 1fr; } }

.role-badge {
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
}
.role-badge.w { background: #FFFFFF; color: var(--text); }
.role-badge.b { background: #18181B; color: #FFFFFF; }
.role-badge.viewer { background: var(--primary-soft); color: var(--primary-hover); border-color: #FCD34D; }

.game-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
}

.players-bar {
  width: 100%;
  max-width: 520px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  box-shadow: var(--shadow-xs);
}

.player-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-radius: var(--radius);
  transition: all 0.2s;
  min-width: 0;
}
.player-info.right { justify-content: flex-end; flex-direction: row-reverse; }
.player-info.active {
  background: var(--primary-soft);
  box-shadow: inset 0 0 0 1px var(--primary);
}

.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}
.avatar.white { background: #F8F6F1; color: var(--text); border: 1px solid var(--border-strong); }
.avatar.black { background: #18181B; color: white; }
.avatar.empty { background: var(--surface-2); color: var(--text-muted); border: 1px dashed var(--border-strong); }

.player-name {
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.player-name.empty { color: var(--text-muted); font-style: italic; font-weight: 400; }

.status-pill {
  background: var(--surface-2);
  border-radius: var(--radius-pill);
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  white-space: nowrap;
  border: 1px solid var(--border);
}
.status-pill.check { background: #FEE2E2; color: var(--red); border-color: #FCA5A5; }
.status-pill.playing { background: #D1FAE5; color: var(--emerald); border-color: #6EE7B7; }
.status-pill.waiting { background: var(--primary-soft); color: var(--primary-hover); border-color: #FCD34D; }

/* Chess board */
.board-wrapper {
  padding: 14px;
  background: linear-gradient(135deg, #5A3A1A, #3E2A12);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 56px);
  grid-template-rows: repeat(8, 56px);
  border-radius: 4px;
  overflow: hidden;
}

@media (max-width: 600px) {
  .board { grid-template-columns: repeat(8, 40px); grid-template-rows: repeat(8, 40px); }
  .square { font-size: 26px !important; }
}

.square {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 38px;
  cursor: pointer;
  position: relative;
  user-select: none;
  transition: background 0.1s;
}
.light { background: var(--sq-light, #F0D9B5); }
.dark { background: var(--sq-dark, #B58863); }
.selected { background: var(--sq-sel, #F7D774) !important; box-shadow: inset 0 0 0 3px var(--sq-sel-edge, #D49A00); }

/* Board themes — applied via body[data-board-theme] */
body[data-board-theme="wood"] { --sq-light: #F0D9B5; --sq-dark: #B58863; --sq-sel: #F7D774; --sq-sel-edge: #D49A00; --board-frame: linear-gradient(135deg, #5A3A1A, #3E2A12); }
body[data-board-theme="green"] { --sq-light: #EEEED2; --sq-dark: #769656; --sq-sel: #F7EC74; --sq-sel-edge: #BABA00; --board-frame: linear-gradient(135deg, #4F6B36, #2F4520); }
body[data-board-theme="blue"] { --sq-light: #DEE3E6; --sq-dark: #8CA2AD; --sq-sel: #C7E6FF; --sq-sel-edge: #5BA3D9; --board-frame: linear-gradient(135deg, #495860, #2E3A40); }
body[data-board-theme="purple"] { --sq-light: #F0E0F5; --sq-dark: #9F84BF; --sq-sel: #FBD3FF; --sq-sel-edge: #B05FCC; --board-frame: linear-gradient(135deg, #5A3D74, #3A2350); }
body[data-board-theme="gray"] { --sq-light: #FFFFFF; --sq-dark: #B8B8B8; --sq-sel: #FFE48A; --sq-sel-edge: #C9A300; --board-frame: linear-gradient(135deg, #555, #2A2A2A); }
.board-wrapper { background: var(--board-frame, linear-gradient(135deg, #5A3A1A, #3E2A12)) !important; }
.valid-move::after {
  content: ''; position: absolute;
  width: 22px; height: 22px;
  background: rgba(5, 150, 105, 0.55);
  border-radius: 50%;
  pointer-events: none;
}
.valid-capture::after {
  content: ''; position: absolute;
  inset: 6px;
  border: 4px solid rgba(220, 38, 38, 0.7);
  border-radius: 50%;
  box-sizing: border-box;
  pointer-events: none;
}
.check { background: #FCA5A5 !important; box-shadow: inset 0 0 0 3px var(--red); }

.piece-w {
  color: #FFFFFF;
  text-shadow: 0 0 2px #000, 1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000;
}
.piece-b {
  color: #1A1A1A;
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.3);
}
.square.checker-piece {
  font-size: 44px;
  line-height: 1;
}
.square.checker-piece.piece-w { color: #FFFFFF; text-shadow: 0 2px 4px rgba(0,0,0,0.5); }
.square.checker-piece.piece-b { color: #1A1A1A; text-shadow: 0 2px 4px rgba(255,255,255,0.4); }
@media (max-width: 600px) {
  .square.checker-piece { font-size: 32px; }
}

.thumb-pill.game-type { background: rgba(180, 83, 9, 0.85); }

.game-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  width: 100%;
  max-width: 520px;
}
.game-controls .viewer-count {
  margin-left: auto;
  color: var(--text-2);
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: var(--radius-pill);
}

.rules {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 18px;
  font-size: 13px;
  width: 100%;
  max-width: 520px;
  color: var(--text-2);
  box-shadow: var(--shadow-xs);
}
.rules summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}
.rules summary::-webkit-details-marker { display: none; }
.rules summary::before {
  content: '▸';
  transition: transform 0.2s;
  display: inline-block;
}
.rules[open] summary::before { transform: rotate(90deg); }
.rules ul { margin: 12px 0 0; padding-left: 20px; line-height: 1.9; }
.rules a { color: var(--primary); font-weight: 500; }
.rules a:hover { text-decoration: underline; }

/* ============ Viewers card ============ */
.room-sidebar { display: flex; flex-direction: column; gap: 16px; }

.viewers-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  box-shadow: var(--shadow-xs);
}
.viewers-header {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 12px;
  color: var(--text);
}
.viewers-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 130px;
  overflow-y: auto;
  scrollbar-width: thin;
}
.viewer-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px 3px 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font-size: 12px;
  color: var(--text-2);
}
.viewer-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100px;
}
.viewer-avatar {
  width: 22px; height: 22px;
  border-radius: 50%;
  color: white;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.viewers-empty {
  color: var(--text-muted);
  font-size: 13px;
  font-style: italic;
  padding: 4px 0;
}

/* ============ Reaction bar ============ */
.reaction-bar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  width: 100%;
  max-width: 520px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px;
  justify-content: center;
  box-shadow: var(--shadow-xs);
}
.reaction-btn {
  font-size: 22px;
  padding: 6px 14px;
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: var(--radius);
  transition: all 0.15s ease;
  line-height: 1;
}
.reaction-btn:hover {
  background: var(--primary-soft);
  transform: scale(1.15) translateY(-2px);
  border-color: var(--primary);
}
.reaction-btn.reacted { transform: scale(1.4); background: var(--primary-soft); }

/* ============ Chat ============ */
.chat-area {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  height: 540px;
  overflow: hidden;
  box-shadow: var(--shadow-xs);
}
@media (max-width: 980px) { .chat-area { height: 380px; } }

.chat-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  background: var(--surface-2);
}
.chat-header .chat-live {
  width: 8px; height: 8px;
  background: var(--red);
  border-radius: 50%;
  animation: pulse 1.6s ease-in-out infinite;
}
.chat-header .chat-count {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scrollbar-width: thin;
}
.msg {
  font-size: 14px;
  line-height: 1.45;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.msg.system {
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
  font-size: 12px;
  padding: 6px 10px;
  background: var(--surface-2);
  border-radius: var(--radius);
  align-self: center;
  max-width: 90%;
}
.msg-user { font-weight: 600; }
.msg.w .msg-user { color: var(--text); }
.msg.b .msg-user { color: var(--text-2); }
.msg.viewer .msg-user { color: var(--blue); }
.msg-text { color: var(--text); }

.chat-form {
  display: flex;
  border-top: 1px solid var(--border);
  padding: 8px;
  gap: 8px;
}
.chat-form input { flex: 1; }
.chat-form button { padding: 10px 16px; }

/* ============ Floating reactions ============ */
.reaction-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  overflow: hidden;
}
.floating-reaction {
  position: absolute;
  bottom: 80px;
  font-size: 36px;
  animation: floatUp 3s ease-out forwards;
  pointer-events: none;
  user-select: none;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.25));
  will-change: transform, opacity;
}

@keyframes floatUp {
  0% { opacity: 0; transform: translateY(0) scale(0.4) rotate(0deg); }
  15% { opacity: 1; transform: translateY(-30px) scale(1.3) rotate(8deg); }
  50% { opacity: 1; transform: translateY(-220px) scale(1.1) rotate(-6deg); }
  100% { opacity: 0; transform: translateY(-450px) scale(0.7) rotate(10deg); }
}

/* ============ SEO content section (lobby) ============ */
.seo-intro {
  margin-top: 32px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 720px) {
  .seo-intro { grid-template-columns: 1fr; }
}
.seo-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px 28px;
  box-shadow: var(--shadow-xs);
}
.seo-card h2 {
  margin: 0 0 12px;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}
.seo-card p {
  margin: 0 0 12px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-2);
}
.seo-card a {
  color: var(--primary);
  font-weight: 600;
}
.seo-card a:hover { text-decoration: underline; }
.seo-card ul {
  margin: 0;
  padding-left: 0;
  list-style: none;
}
.seo-card ul li {
  margin-bottom: 8px;
  font-size: 14px;
  color: var(--text-2);
  line-height: 1.6;
}
.seo-features { grid-column: 1 / -1; }

/* ============ FAQ items (rules page) ============ */
.faq-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 10px;
}
.faq-item summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::before {
  content: '▸';
  transition: transform 0.2s;
  color: var(--primary);
  flex-shrink: 0;
}
.faq-item[open] summary::before { transform: rotate(90deg); }
.faq-item p {
  margin: 12px 0 0;
  padding-left: 24px;
  color: var(--text-2);
  line-height: 1.7;
  font-size: 14px;
}

/* ============ Footer ============ */
footer {
  margin-top: 48px;
  padding: 28px 24px;
  border-top: 1px solid var(--border);
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(8px);
}
.footer-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 16px;
  margin-bottom: 10px;
  align-items: center;
}
.footer-row a { color: var(--primary); font-weight: 500; }
.footer-row a:hover { text-decoration: underline; }
.footer-divider {
  width: 4px; height: 4px;
  background: var(--border-strong);
  border-radius: 50%;
}
.footer-stats {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-muted);
}
.footer-stats strong { color: var(--text-2); }

/* ============ Toast ============ */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: #FFFFFF;
  padding: 12px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: all 0.3s;
  z-index: 1000;
  font-size: 14px;
  font-weight: 500;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============ Rules page ============ */
.rules-nav {
  max-width: 820px;
  margin: 0 auto 20px;
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}
.rules-nav a {
  padding: 8px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-2);
  transition: all 0.15s;
}
.rules-nav a:hover {
  background: var(--primary-soft);
  color: var(--primary-hover);
  border-color: var(--primary);
}

.rules-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 40px;
  max-width: 820px;
  margin: 0 auto;
  box-shadow: var(--shadow-sm);
  line-height: 1.75;
}
.rules-content h1 {
  font-size: 32px;
  font-weight: 700;
  margin: 0 0 8px;
  background: linear-gradient(135deg, var(--text) 30%, var(--primary));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.rules-content .subtitle {
  color: var(--text-muted);
  font-size: 15px;
  margin-bottom: 32px;
  font-style: italic;
}
.rules-content h2 {
  font-size: 22px;
  font-weight: 600;
  margin: 36px 0 12px;
  color: var(--text);
  padding-bottom: 8px;
  border-bottom: 2px solid var(--primary-soft);
  display: inline-block;
}
.rules-content h3 {
  font-size: 17px;
  font-weight: 600;
  margin: 24px 0 8px;
  color: var(--primary-hover);
  display: flex;
  align-items: center;
  gap: 10px;
}
.rules-content h3 .piece-glyph {
  font-size: 28px;
  color: var(--text);
}
.rules-content p { margin: 8px 0 12px; color: var(--text-2); }
.rules-content ul { padding-left: 22px; color: var(--text-2); }
.rules-content ul li { margin-bottom: 6px; }
.rules-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 14px;
}
.rules-content th, .rules-content td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.rules-content th {
  background: var(--surface-2);
  font-weight: 600;
  color: var(--text);
}
.rules-content td { color: var(--text-2); }
.rules-content .callout {
  background: var(--primary-soft);
  border-left: 4px solid var(--primary);
  padding: 12px 16px;
  border-radius: var(--radius);
  margin: 16px 0;
  color: var(--primary-hover);
}
.rules-content .callout strong { color: var(--text); }
@media (max-width: 720px) { .rules-content { padding: 24px 20px; } }

/* ============ Time control selector (lobby) ============ */
.time-control-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.tc-label {
  font-size: 13px;
  color: var(--text-2);
  font-weight: 500;
}
.tc-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.tc-btn {
  padding: 6px 12px;
  font-size: 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-2);
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: all 0.15s;
}
.tc-btn:hover {
  border-color: var(--primary);
  color: var(--text);
}
.tc-btn.active {
  background: var(--primary);
  color: #FFFFFF;
  border-color: var(--primary);
  font-weight: 600;
}

/* ============ Player meta + clock ============ */
.player-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.player-info.right .player-meta { align-items: flex-end; }
.clock {
  font-family: 'Inter', monospace;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-2);
  background: var(--surface-2);
  padding: 1px 8px;
  border-radius: var(--radius);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}
.clock.active {
  background: var(--primary-soft);
  color: var(--primary-hover);
  box-shadow: inset 0 0 0 1px var(--primary);
}
.clock.low {
  background: #FEE2E2;
  color: var(--red);
  animation: pulse 1s ease-in-out infinite;
}

/* ============ Theme picker (room) ============ */
.theme-picker {
  position: relative;
  display: inline-block;
}
.theme-picker summary {
  cursor: pointer;
  list-style: none;
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text);
  user-select: none;
}
.theme-picker summary::-webkit-details-marker { display: none; }
.theme-picker summary:hover { background: var(--surface-2); border-color: var(--border-strong); }
.theme-picker[open] summary { background: var(--primary-soft); border-color: var(--primary); }
.theme-options {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 140px;
}
.theme-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  width: 100%;
}
.theme-btn:hover { background: var(--surface-2); }
.theme-btn.active { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-hover); font-weight: 600; }
.swatch {
  display: inline-block;
  width: 24px;
  height: 16px;
  border-radius: 3px;
  border: 1px solid var(--border-strong);
  flex-shrink: 0;
}
.sw-wood { background: linear-gradient(135deg, #F0D9B5 50%, #B58863 50%); }
.sw-green { background: linear-gradient(135deg, #EEEED2 50%, #769656 50%); }
.sw-blue { background: linear-gradient(135deg, #DEE3E6 50%, #8CA2AD 50%); }
.sw-purple { background: linear-gradient(135deg, #F0E0F5 50%, #9F84BF 50%); }
.sw-gray { background: linear-gradient(135deg, #FFFFFF 50%, #B8B8B8 50%); }

/* ============ Time control hint ============ */
.tc-hint { color: var(--text-muted); font-weight: 400; font-size: 12px; }
.thumb-pill.private { background: rgba(180, 83, 9, 0.85); }

/* ============ Move history ============ */
.move-history {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  font-size: 13px;
  width: 100%;
  max-width: 520px;
  color: var(--text-2);
  box-shadow: var(--shadow-xs);
}
.move-history summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}
.move-history summary::-webkit-details-marker { display: none; }
.move-history summary::before {
  content: '▸';
  transition: transform 0.2s;
  display: inline-block;
}
.move-history[open] summary::before { transform: rotate(90deg); }
.move-count { color: var(--text-muted); font-weight: 400; font-size: 12px; }

.moves-list {
  margin-top: 12px;
  max-height: 200px;
  overflow-y: auto;
  font-family: 'Inter', monospace;
  font-size: 13px;
  display: grid;
  gap: 4px;
  padding-right: 4px;
  scrollbar-width: thin;
}
.move-row {
  display: grid;
  grid-template-columns: 36px 1fr 1fr;
  gap: 8px;
  padding: 4px 8px;
  border-radius: 4px;
}
.move-row:hover { background: var(--surface-2); }
.move-num { color: var(--text-muted); }
.move-w, .move-b { color: var(--text); font-variant-numeric: tabular-nums; }
.moves-empty { color: var(--text-muted); font-style: italic; padding: 8px 0; }

/* ============ Animations ============ */
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.15); }
}
