/* ==============================================
   QuantumChess — Professional Dark Theme
   ============================================== */

:root {
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  /* Surface palette */
  --bg-body: #1a1a1a;
  --bg-nav: #242424;
  --bg-surface: #2a2a2a;
  --bg-elevated: #333333;
  --bg-hover: #3a3a3a;
  --bg-input: #222222;

  /* Borders */
  --border: #3d3d3d;
  --border-light: #4a4a4a;
  --border-focus: #6d9b4a;

  /* Accent */
  --accent: #81b64c;
  --accent-hover: #96c85d;
  --accent-subtle: rgba(129, 182, 76, 0.12);
  --accent-text: #9ece6a;

  /* Status */
  --danger: #e5534b;
  --danger-bg: rgba(229, 83, 75, 0.1);
  --warning: #d29922;

  /* Text */
  --text-1: #e6e6e6;
  --text-2: #b3b3b3;
  --text-3: #808080;
  --text-4: #5c5c5c;

  /* Board default (green) */
  --sq-light: #ebecd0;
  --sq-dark: #739552;
  --sq-select-light: #f5f682;
  --sq-select-dark: #b9ca43;

  /* Sizing */
  --nav-h: 48px;
  --radius: 6px;
  --radius-lg: 10px;
}

/* Board themes */
[data-board-theme="brown"] {
  --sq-light: #f0d9b5;
  --sq-dark: #b58863;
  --sq-select-light: #f7ec7a;
  --sq-select-dark: #dac34b;
}
[data-board-theme="blue"] {
  --sq-light: #eae9d2;
  --sq-dark: #4b7399;
  --sq-select-light: #e8f07a;
  --sq-select-dark: #6da5c9;
}
[data-board-theme="purple"] {
  --sq-light: #e8dff5;
  --sq-dark: #7b61a4;
  --sq-select-light: #e0d0ff;
  --sq-select-dark: #9b7fd0;
}

/* ============ Reset ============ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-ui);
  background: var(--bg-body);
  color: var(--text-1);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--accent); color: #fff; }
button { font-family: inherit; cursor: pointer; }
a { color: inherit; text-decoration: none; }

/* ============ Navbar ============ */
.navbar {
  height: var(--nav-h);
  background: var(--bg-nav);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
  z-index: 10;
}

.nav-left, .nav-right { display: flex; align-items: center; gap: 8px; }

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-1);
}

.logo-icon { color: var(--accent); }

.logo-text {
  font-size: 0.95rem;
  letter-spacing: -0.01em;
  color: var(--text-2);
}

.logo-text strong {
  color: var(--text-1);
  font-weight: 700;
}

.language-switch {
  display: inline-flex;
  height: 32px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
}

.language-btn {
  min-width: 34px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-3);
  font-size: 0.72rem;
  font-weight: 700;
  transition: background 0.15s, color 0.15s;
}

.language-btn:hover {
  color: var(--text-1);
}

.language-btn.active {
  background: var(--accent);
  color: #fff;
}

.nav-btn {
  height: 32px;
  padding: 0 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-2);
  font-size: 0.8rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
}

.nav-btn:hover {
  background: var(--bg-hover);
  color: var(--text-1);
  border-color: var(--border-light);
}

.nav-btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.nav-btn-accent:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
}

/* ============ Game Layout ============ */
.game-area {
  display: flex;
  height: calc(100vh - var(--nav-h));
  overflow: hidden;
}

.game-area.lobby-mode {
  align-items: center;
  justify-content: center;
  padding: 28px 20px;
  background:
    linear-gradient(135deg, rgba(129, 182, 76, 0.08), transparent 34%),
    var(--bg-body);
}

.game-area.lobby-mode .board-column {
  display: none;
}

.game-area.lobby-mode .sidebar {
  width: min(100%, 460px);
  max-height: calc(100vh - var(--nav-h) - 56px);
  border-left: none;
  background: transparent;
}

.game-area.lobby-mode .lobby-panel {
  height: auto;
  max-height: calc(100vh - var(--nav-h) - 56px);
  background: var(--bg-nav);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 18px 70px rgba(0, 0, 0, 0.28);
}

.board-column {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px 20px;
  min-width: 0;
  gap: 4px;
}

/* ============ Player Bars ============ */
.player-bar {
  width: min(100%, 640px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  border-radius: var(--radius);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  transition: border-color 0.2s;
}

.player-bar.active {
  border-color: var(--accent);
}

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

.player-avatar {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
  flex-shrink: 0;
}

.player-avatar.active-avatar {
  background: var(--accent-subtle);
  color: var(--accent);
}

.player-name {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-1);
  white-space: nowrap;
}

.player-captured {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: 8px;
}

.captured-piece {
  font-size: 1.35rem;
  line-height: 1;
  user-select: none;
  margin-right: -3px;
}

.captured-piece.white-piece {
  color: #ffffff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9), 0 0 1px rgba(0, 0, 0, 0.8);
}

.captured-piece.black-piece {
  color: #121212;
  text-shadow: 0 0 2px rgba(255, 255, 255, 0.85), 0 1px 1px rgba(255, 255, 255, 0.5);
}

.player-clock {
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-1);
  background: var(--bg-elevated);
  padding: 4px 12px;
  border-radius: var(--radius);
  letter-spacing: 0.5px;
  min-width: 72px;
  text-align: center;
  flex-shrink: 0;
}

.player-clock.active-clock {
  background: var(--accent);
  color: #fff;
}

/* ============ Board Wrapper ============ */
.board-wrapper {
  position: relative;
  width: min(100%, 640px);
  aspect-ratio: 1;
}

/* Coordinates */
.board-coords {
  position: absolute;
  display: flex;
  z-index: 2;
  pointer-events: none;
}

.board-coords span {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-4);
  display: flex;
  align-items: center;
  justify-content: center;
}

.coords-files {
  bottom: -18px;
  left: 0;
  right: 0;
  flex-direction: row;
}

.coords-files span {
  flex: 1;
  text-transform: lowercase;
}

.coords-ranks {
  top: 0;
  left: -18px;
  bottom: 0;
  flex-direction: column;
}

.coords-ranks span {
  flex: 1;
}

/* ============ Chessboard ============ */
.chessboard {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 3px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.square-2d {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
}

.square-2d.white-sq { background: var(--sq-light); }
.square-2d.black-sq { background: var(--sq-dark); }

.square-2d.highlighted.white-sq { background: var(--sq-select-light) !important; }
.square-2d.highlighted.black-sq { background: var(--sq-select-dark) !important; }

.square-2d.last-move { box-shadow: inset 0 0 0 3.5px #f59e0b !important; }
.square-2d.check-highlight { box-shadow: inset 0 0 0 3.5px var(--danger) !important; }
.square-2d.highlighted { background: var(--sq-select-light) !important; }

.piece-2d {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  pointer-events: none;
  transition: transform 0.1s ease;
  --piece-stroke: 1.65px;
  --piece-detail-stroke: 1.8px;
}

.piece-svg-img {
  width: 84%;
  height: 84%;
  display: block;
  overflow: visible;
  filter: drop-shadow(0 2px 1px rgba(0, 0, 0, 0.32));
}

.piece-svg-shape > * {
  fill: currentColor;
  stroke: var(--piece-outline);
  stroke-width: var(--piece-stroke, 1.65px);
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.piece-svg-detail {
  fill: none !important;
  stroke: var(--piece-detail, var(--piece-outline)) !important;
  stroke-width: var(--piece-detail-stroke, 1.6px) !important;
}

.piece-svg-eye {
  fill: var(--piece-outline) !important;
  stroke: none !important;
}

.piece-2d.piece-w.piece-style-classic {
  color: #f8fafc;
  --piece-outline: #1f2937;
  --piece-detail: #d7dee9;
}

.piece-2d.piece-b.piece-style-classic {
  color: #111827;
  --piece-outline: #dbe3ef;
  --piece-detail: #3b4658;
}

.piece-2d.piece-style-solid {
  --piece-stroke: 2.2px;
  --piece-detail-stroke: 2px;
}

.piece-2d.piece-style-solid .piece-svg-img {
  width: 82%;
  height: 82%;
  filter: drop-shadow(0 0 5px var(--piece-glow)) drop-shadow(0 2px 2px rgba(0, 0, 0, 0.45));
}

.piece-2d.piece-style-solid .piece-svg-shape > * {
  fill: var(--piece-fill);
  stroke: var(--piece-outline);
  stroke-width: var(--piece-stroke);
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.piece-2d.piece-style-solid .piece-svg-eye {
  fill: var(--piece-outline) !important;
  stroke: none !important;
}

.piece-2d.piece-w.piece-style-solid {
  --piece-fill: #ffffff;
  --piece-outline: #0284c7; /* sleek modern cyan-blue */
  --piece-glow: rgba(2, 132, 199, 0.35);
  color: #0284c7;
}

.piece-2d.piece-b.piece-style-solid {
  --piece-fill: #1e293b; /* deep space slate */
  --piece-outline: #10b981; /* quantum neon green */
  --piece-glow: rgba(16, 185, 129, 0.35);
  color: #10b981;
}

.piece-2d.piece-style-wood {
  --piece-stroke: 1.85px;
  --piece-detail-stroke: 1.6px;
}

.piece-2d.piece-w.piece-style-wood {
  color: #f4d39b;
  --piece-outline: #6b3f18;
  --piece-detail: #8b5a2b;
}

.piece-2d.piece-b.piece-style-wood {
  color: #5a3014;
  --piece-outline: #e1b873;
  --piece-detail: #b87937;
}

.square-2d:hover .piece-2d {
  transform: scale(1.06);
}

.square-2d .valid-dot {
  width: 30%;
  height: 30%;
  background: rgba(0, 0, 0, 0.15);
  border-radius: 50%;
  position: absolute;
  z-index: 3;
  pointer-events: none;
}

.square-2d .valid-capture {
  width: 100%;
  height: 100%;
  position: absolute;
  z-index: 3;
  pointer-events: none;
  background: radial-gradient(transparent 50%, rgba(0, 0, 0, 0.15) 51%);
}

/* ============ Sidebar ============ */
.sidebar {
  width: 340px;
  background: var(--bg-nav);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-tab {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-3);
  padding: 10px 0;
  font-size: 0.78rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
}

.sidebar-tab:hover { color: var(--text-2); }

.sidebar-tab.active {
  color: var(--accent-text);
  border-bottom-color: var(--accent);
}

.sidebar-content {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.sidebar-pane {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.sidebar-pane.active {
  opacity: 1;
  pointer-events: auto;
}

/* Moves table */
.moves-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}

.moves-table {
  width: 100%;
  border-collapse: collapse;
}

.moves-table th {
  position: sticky;
  top: 0;
  background: var(--bg-nav);
  padding: 8px 12px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-4);
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.moves-table th.move-num { width: 36px; text-align: center; }

.moves-table td {
  padding: 6px 12px;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
}

.moves-table td:first-child {
  color: var(--text-4);
  text-align: center;
  font-size: 0.75rem;
}

.moves-table tr:hover td { background: var(--bg-hover); }
.moves-table tr:nth-child(even) { background: rgba(255,255,255,0.015); }

.sidebar-actions {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-actions .btn { flex: 1; }

/* Chat */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sys-msg {
  font-size: 0.72rem;
  color: var(--text-4);
  text-align: center;
  padding: 4px 0;
}

.chat-message {
  max-width: 82%;
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 0.82rem;
  line-height: 1.35;
}

.chat-message.self {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 3px;
}

.chat-message.opponent {
  align-self: flex-start;
  background: var(--bg-elevated);
  border-bottom-left-radius: 3px;
}

.chat-message .sender {
  font-weight: 600;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  opacity: 0.7;
  display: block;
  margin-bottom: 2px;
}

.chat-form {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* Settings */
.settings-group {
  padding: 14px 14px 0;
}

.setting-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-3);
  margin-bottom: 6px;
}

.setting-select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-1);
  padding: 8px 10px;
  border-radius: var(--radius);
  font-family: var(--font-ui);
  font-size: 0.82rem;
  font-weight: 500;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s;
}

.setting-select:focus { border-color: var(--border-focus); }
.setting-select option { background: var(--bg-surface); }

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

.swatch {
  width: 100%;
  min-height: 70px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 6px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s, background 0.15s;
}

.swatch-label {
  display: block;
  color: var(--text-3);
  font-size: 0.66rem;
  font-weight: 700;
  line-height: 1;
}

.mini-board {
  --mini-light: #ebecd0;
  --mini-dark: #739552;
  width: 100%;
  max-width: 54px;
  aspect-ratio: 1;
  display: block;
  border-radius: 4px;
  background-color: var(--mini-light);
  background-image: conic-gradient(var(--mini-dark) 25%, var(--mini-light) 0 50%, var(--mini-dark) 0 75%, var(--mini-light) 0);
  background-size: 50% 50%;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.22);
}

.mini-board-green { --mini-light: #ebecd0; --mini-dark: #739552; }
.mini-board-brown { --mini-light: #f0d9b5; --mini-dark: #b58863; }
.mini-board-blue { --mini-light: #eae9d2; --mini-dark: #4b7399; }
.mini-board-purple { --mini-light: #e8dff5; --mini-dark: #7b61a4; }

.swatch:hover {
  background: var(--bg-hover);
  transform: translateY(-1px);
}

.swatch.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.swatch.active .swatch-label {
  color: var(--text-1);
}

/* ============ Buttons ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 8px 14px;
  border-radius: var(--radius);
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid transparent;
  transition: all 0.15s;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

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

.btn-outline {
  background: transparent;
  border-color: var(--border);
  color: var(--text-2);
}

.btn-outline:hover {
  background: var(--bg-hover);
  border-color: var(--border-light);
  color: var(--text-1);
}

.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); border-color: rgba(229,83,75,0.3); }

.btn-sm { padding: 5px 10px; font-size: 0.75rem; }
.btn-full { width: 100%; }

.input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  color: var(--text-1);
  font-family: var(--font-ui);
  font-size: 0.82rem;
  outline: none;
  transition: border-color 0.15s;
}

.input:focus { border-color: var(--border-focus); }
.input-mono { font-family: var(--font-mono); letter-spacing: 1px; }

.online-status-message {
  min-height: 18px;
  color: var(--text-3);
  font-size: 0.76rem;
  line-height: 1.35;
}

.online-status-message.error {
  color: var(--danger);
}

.online-status-message.success {
  color: var(--accent-text);
}

/* ============ Sidebar Lobby Panel ============ */
.lobby-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  overflow-y: auto;
  padding: 18px 16px;
  gap: 20px;
}

.lobby-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
}

.lobby-tab {
  min-width: 0;
  height: 32px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-3);
  font-size: 0.76rem;
  font-weight: 700;
  transition: color 0.15s, background 0.15s;
}

.lobby-tab:hover {
  color: var(--text-1);
}

.lobby-tab.active {
  background: var(--accent);
  color: #fff;
}

.lobby-tab-panel {
  display: none;
  flex-direction: column;
  gap: 16px;
}

.lobby-tab-panel.active {
  display: flex;
}

.lobby-header {
  text-align: center;
}

.lobby-logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 1.45rem;
  font-weight: 500;
  color: var(--text-2);
}

.lobby-logo strong {
  color: var(--text-1);
  font-weight: 800;
}

.lobby-logo-icon {
  color: var(--accent);
}

.lobby-tagline {
  margin-top: 6px;
  font-size: 0.8rem;
  color: var(--text-3);
  line-height: 1.4;
}

/* Lobby menu buttons */
.lobby-menu {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lobby-menu-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: left;
  transition: all 0.15s ease;
  color: var(--text-1);
  width: 100%;
}

.lobby-menu-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-light);
  transform: translateY(-1px);
}

.menu-btn-icon {
  width: 34px;
  height: 34px;
  border-radius: var(--radius);
  background: var(--accent-subtle);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.menu-btn-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.menu-btn-text strong {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-1);
}

.menu-btn-text span {
  font-size: 0.72rem;
  color: var(--text-3);
}

/* Sub-views */
.lobby-sub-view {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  animation: fadeInSubView 0.2s ease;
}

@keyframes fadeInSubView {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.lobby-back-btn {
  background: transparent;
  border: none;
  color: var(--text-3);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 0;
  align-self: flex-start;
  transition: color 0.15s;
}

.lobby-back-btn:hover {
  color: var(--text-1);
}

/* Sections */
.lobby-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lobby-section h4 {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-3);
  margin-bottom: 2px;
}

.lobby-settings-section {
  gap: 12px;
}

.lobby-setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0 2px;
}

.lobby-setting-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.pulse-dot {
  width: 6px;
  height: 6px;
  background-color: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(129, 182, 76, 0.7);
  animation: onlinePulse 1.8s infinite;
}

@keyframes onlinePulse {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(129, 182, 76, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 5px rgba(129, 182, 76, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(129, 182, 76, 0); }
}

/* Challenge list */
.challenge-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.challenge-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.78rem;
}

.challenge-user {
  font-weight: 600;
  color: var(--text-1);
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.challenge-icon {
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  flex-shrink: 0;
}

.challenge-mode {
  font-family: var(--font-mono);
  color: var(--text-3);
  font-size: 0.72rem;
}

/* Leaderboard */
.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.leaderboard-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}

.leaderboard-table td:first-child {
  width: 24px;
  text-align: center;
  color: var(--text-3);
  font-weight: bold;
}

.leaderboard-table td:last-child {
  text-align: right;
  color: var(--accent-text);
  font-weight: bold;
}

.leaderboard-table tr:last-child td {
  border-bottom: none;
}

/* Star Rating Selector Widget */
.star-rating-selector {
  display: flex;
  flex-direction: row-reverse;
  justify-content: center;
  gap: 8px;
  font-size: 2.3rem;
  cursor: pointer;
  margin-top: 4px;
}

.star-btn {
  color: var(--text-4);
  transition: all 0.15s ease;
}

.star-btn.active,
.star-btn.active ~ .star-btn {
  color: var(--accent);
  text-shadow: 0 0 8px rgba(129, 182, 76, 0.4);
}

.star-rating-selector:hover .star-btn {
  color: var(--text-4) !important;
  text-shadow: none !important;
}

.star-rating-selector .star-btn:hover,
.star-rating-selector .star-btn:hover ~ .star-btn {
  color: var(--accent) !important;
  text-shadow: 0 0 10px rgba(129, 182, 76, 0.6) !important;
}

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

.setting-label-inline {
  margin-bottom: 2px;
}

.setting-note {
  font-size: 0.72rem;
  color: var(--text-4);
  line-height: 1.35;
}

.switch {
  position: relative;
  display: inline-flex;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch span {
  width: 100%;
  height: 100%;
  border-radius: 999px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  transition: background 0.15s, border-color 0.15s;
}

.switch span::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  top: 3px;
  left: 3px;
  border-radius: 50%;
  background: var(--text-2);
  transition: transform 0.15s, background 0.15s;
}

.switch input:checked + span {
  background: var(--accent);
  border-color: var(--accent);
}

.switch input:checked + span::before {
  transform: translateX(20px);
  background: #fff;
}

.piece-style-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.piece-style-btn {
  min-width: 0;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-2);
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.piece-style-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-light);
  color: var(--text-1);
}

.piece-style-btn.active {
  border-color: var(--accent);
  background: var(--accent-subtle);
  color: var(--text-1);
}

.piece-preview-set {
  width: 100%;
  min-height: 38px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 3px;
  align-items: center;
}

.piece-preview-set span {
  min-width: 0;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.piece-preview-set .piece-svg-img {
  width: 25px;
  height: 25px;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.45));
}

.piece-preview-classic span {
  color: #fff;
  --piece-outline: #111827;
  --piece-detail: #e5edf8;
}

.piece-preview-solid span {
  --piece-fill: #ffffff;
  --piece-outline: #0284c7;
  --piece-glow: rgba(2, 132, 199, 0.35);
  color: #0284c7;
}

.piece-preview-solid .piece-svg-img {
  width: 24px;
  height: 24px;
  filter: drop-shadow(0 0 3px var(--piece-glow)) drop-shadow(0 1px 1px rgba(0, 0, 0, 0.45));
}

.piece-preview-solid .piece-svg-shape > * {
  fill: var(--piece-fill);
  stroke: var(--piece-outline);
  stroke-width: 2.2px;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.piece-preview-solid .piece-svg-eye {
  fill: var(--piece-outline) !important;
  stroke: none !important;
}

.piece-preview-wood span {
  color: #f0c987;
  --piece-outline: #6b3f18;
  --piece-detail: #8b5a2b;
}

/* ============ Modal Overlays ============ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
  backdrop-filter: blur(4px);
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 420px;
  max-width: 92vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  animation: modalPop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  overflow: hidden;
}

@keyframes modalPop {
  from { transform: scale(0.95) translateY(8px); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}

.modal-card-sm { width: 360px; }

.modal-header {
  padding: 24px 24px 16px;
  text-align: center;
}

.modal-header h2 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.modal-header p {
  font-size: 0.85rem;
  color: var(--text-3);
}

/* Mode list items */
.mode-list {
  padding: 0 12px 12px;
}

.mode-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-1);
  margin-bottom: 6px;
  text-align: left;
  transition: all 0.15s;
}

.mode-item:hover {
  background: var(--bg-hover);
  border-color: var(--border-light);
}

.mode-item:active {
  background: var(--bg-elevated);
}

.mode-icon {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--accent-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  flex-shrink: 0;
}

.mode-text {
  flex: 1;
  min-width: 0;
}

.mode-text strong {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 2px;
}

.mode-text span {
  font-size: 0.78rem;
  color: var(--text-3);
}

.mode-arrow {
  color: var(--text-4);
  flex-shrink: 0;
  transition: transform 0.15s;
}

.mode-item:hover .mode-arrow {
  transform: translateX(3px);
  color: var(--text-2);
}

/* Sub-panels */
.sub-panel {
  padding: 16px 24px 24px;
  border-top: 1px solid var(--border);
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0;
}

.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.divider span {
  font-size: 0.72rem;
  color: var(--text-4);
  white-space: nowrap;
}

.join-row {
  display: flex;
  gap: 6px;
}

.join-row .input { flex: 1; text-align: center; text-transform: uppercase; }

.waiting-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-left-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto 10px;
}

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

.waiting-text {
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-2);
  margin-bottom: 10px;
}

.share-row {
  display: flex;
  gap: 6px;
}

.share-row .input {
  flex: 1;
  font-size: 0.78rem;
  color: var(--accent-text);
}

/* Game over modal */
.result-icon {
  text-align: center;
  font-size: 3rem;
  padding: 20px 0 8px;
}

.modal-card-sm h2 {
  text-align: center;
  font-size: 1.3rem;
  font-weight: 700;
  padding: 0 24px;
}

.result-msg {
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-3);
  padding: 6px 24px 20px;
}

.modal-btns {
  display: flex;
  gap: 8px;
  padding: 0 20px 20px;
}

.modal-btns .btn { flex: 1; }

/* ============ Scrollbar ============ */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.06); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.12); }

/* ============ Utility ============ */
.hidden { display: none !important; }

/* Backward compat for old class names used by app.js */
.system-message { font-size: 0.72rem; color: var(--text-4); text-align: center; }
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.65); z-index: 100; }

/* ============ Responsive ============ */
@media (max-width: 900px) {
  .game-area {
    flex-direction: column;
    overflow-y: auto;
    height: auto;
  }

  .sidebar {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border);
    max-height: 400px;
  }

  .board-column {
    padding: 8px 12px;
  }

  body { overflow-y: auto; height: auto; }
}

/* ============ Full-Fledged Lobby Enhancements ============ */

/* Wide screen desktop split layout override */
@media (min-width: 901px) {
  .game-area.lobby-mode {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 40px !important;
    padding: 24px 40px !important;
    background:
      radial-gradient(circle at 10% 20%, rgba(129, 182, 76, 0.08) 0%, transparent 40%),
      radial-gradient(circle at 90% 80%, rgba(129, 182, 76, 0.05) 0%, transparent 40%),
      var(--bg-body) !important;
  }

  .game-area.lobby-mode .board-column {
    display: flex !important;
    flex: 1.2 !important;
    max-width: 580px !important;
    position: relative;
  }

  .game-area.lobby-mode .sidebar {
    width: 400px !important;
    max-height: calc(100vh - var(--nav-h) - 48px) !important;
    background: transparent !important;
    border-left: none !important;
  }

  .game-area.lobby-mode .lobby-panel {
    height: 100% !important;
    max-height: calc(100vh - var(--nav-h) - 48px) !important;
    background: var(--bg-nav) !important;
    border: 1px solid var(--border) !important;
    border-radius: var(--radius-lg) !important;
    box-shadow: 0 18px 70px rgba(0, 0, 0, 0.35) !important;
  }
}

/* Glassmorphic Board Overlay in Lobby mode */
.lobby-board-overlay {
  position: absolute;
  inset: 0;
  background: rgba(20, 20, 20, 0.65);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  animation: fadeInOverlay 0.35s ease;
  padding: 20px;
}

@keyframes fadeInOverlay {
  from { opacity: 0; }
  to { opacity: 1; }
}

.lobby-board-overlay .overlay-card {
  background: rgba(42, 42, 42, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-lg);
  padding: 30px 24px;
  text-align: center;
  max-width: 320px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  backdrop-filter: blur(10px);
}

.lobby-board-overlay .overlay-logo {
  font-size: 2.8rem;
  line-height: 1;
  filter: drop-shadow(0 0 12px rgba(129, 182, 76, 0.3));
  margin-bottom: 4px;
}

.lobby-board-overlay h2 {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-1);
  letter-spacing: -0.2px;
}

.lobby-board-overlay p {
  font-size: 0.82rem;
  color: var(--text-2);
  line-height: 1.45;
}

.btn-accent-glow {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 600;
  box-shadow: 0 0 14px rgba(129, 182, 76, 0.3);
  transition: all 0.2s ease;
}

.btn-accent-glow:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  box-shadow: 0 0 20px rgba(129, 182, 76, 0.5);
  transform: translateY(-1px);
}

/* User Profile Card */
.lobby-profile-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 2px;
}

.profile-avatar-wrapper {
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  flex-shrink: 0;
}

.profile-details {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.profile-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.profile-username {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.profile-badge {
  font-size: 0.6rem;
  font-weight: 800;
  color: #fff;
  background: var(--accent);
  padding: 2px 5px;
  border-radius: 3px;
  letter-spacing: 0.5px;
}

.profile-stats {
  display: flex;
  gap: 16px;
}

.profile-stats .stat-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.profile-stats .stat-label {
  font-size: 0.65rem;
  color: var(--text-3);
  text-transform: uppercase;
  font-weight: 600;
}

.profile-stats .stat-value {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--text-2);
}

#lobby-rating {
  color: var(--accent-text);
}

/* Presets Time Control Selection */
.presets-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lobby-section-title {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-3);
}

.presets-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.preset-btn {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-2);
  transition: all 0.15s ease;
}

.preset-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-light);
  color: var(--text-1);
  transform: translateY(-1px);
}

.preset-btn.active {
  background: var(--accent-subtle);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 0 8px rgba(129, 182, 76, 0.15);
}

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

.preset-time {
  font-size: 0.8rem;
  font-weight: 700;
}

.preset-name {
  font-size: 0.65rem;
  color: var(--text-3);
}

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

/* Bot Profile Card */
.bot-profile-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  animation: fadeInBotCard 0.25s ease;
}

@keyframes fadeInBotCard {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: translateY(0); }
}

.bot-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}

.bot-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.bot-name-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.bot-name {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-1);
}

.bot-rating {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent-text);
}

.bot-description {
  font-size: 0.7rem;
  color: var(--text-3);
  line-height: 1.3;
}
