/* Dambrete 8x8 Platform Stylesheet — Visuals Concept from dambrete-platform */

:root {
  --bg-primary: #121418;
  --bg-surface: #1a1e24;
  --bg-surface-elevated: #232832;
  --bg-card: rgba(30, 35, 45, 0.85);
  --border-color: #2e3644;
  --border-highlight: #455268;

  --text-primary: #f0f4f8;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-glow: rgba(59, 130, 246, 0.25);

  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;

  --board-light: #edd6b6;
  --board-dark: #825336;
  --board-border: #4d3324;
  --square-select: rgba(245, 158, 11, 0.6);
  --square-highlight: rgba(16, 185, 129, 0.45);
  --square-last-move: rgba(59, 130, 246, 0.35);

  --piece-white: #fbfbfa;
  --piece-white-rim: #d1d5db;
  --piece-black: #1e1e24;
  --piece-black-rim: #3f3f46;

  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  line-height: 1.45;
}

.hidden {
  display: none !important;
}

/* Reconnecting Banner */
.ws-banner {
  background: var(--warning);
  color: #fff;
  text-align: center;
  padding: 5px 12px;
  font-size: 0.82rem;
  font-weight: 600;
}

/* Header & Navbar */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  padding: 0.6rem clamp(0.75rem, 2.5vw, 1.5rem);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 50;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: #fff;
  cursor: pointer;
  user-select: none;
}

.brand-piece {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffffff, #e2e8f0 70%, #cbd5e1);
  border: 2px solid var(--accent);
  box-shadow: 0 0 10px var(--accent-glow);
  flex-shrink: 0;
}

.brand-title {
  font-weight: 800;
  letter-spacing: 0.5px;
  font-size: 1.15rem;
  color: #fff;
}

.header-nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* Subtle Language Selector */
.lang-selector {
  display: inline-flex;
  align-items: center;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 2px 4px;
  gap: 2px;
}

.lang-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 3px 6px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1;
  transition: all 0.15s ease;
  letter-spacing: 0.5px;
}

.lang-btn:hover {
  color: var(--text-primary);
}

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

.lang-sep {
  color: var(--border-color);
  font-size: 0.7rem;
  user-select: none;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-surface-elevated);
  padding: 0.35rem 0.8rem;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
  color: var(--text-primary);
  background: var(--bg-surface-elevated);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 0 12px var(--accent-glow);
}

.btn-secondary {
  background: var(--bg-surface-elevated);
  border-color: var(--border-color);
  color: var(--text-primary);
}
.btn-secondary:hover {
  border-color: var(--border-highlight);
  background: #2a313d;
}

.btn-accent {
  background: #4f46e5;
  color: #fff;
}
.btn-accent:hover {
  background: #4338ca;
  box-shadow: 0 0 12px rgba(79, 70, 229, 0.35);
}

.btn-success {
  background: rgba(16, 185, 129, 0.2);
  border-color: rgba(16, 185, 129, 0.4);
  color: #34d399;
}
.btn-success:hover {
  background: var(--success);
  color: #fff;
}

.btn-warning {
  background: rgba(245, 158, 11, 0.18);
  border-color: rgba(245, 158, 11, 0.4);
  color: #fbbf24;
}
.btn-warning:hover {
  background: var(--warning);
  color: #fff;
}

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.3);
  color: #f87171;
}
.btn-danger:hover {
  background: var(--danger);
  color: #fff;
}

.btn-ghost {
  background: var(--bg-surface-elevated);
  border-color: var(--border-color);
  color: var(--text-secondary);
}
.btn-ghost:hover {
  border-color: var(--border-highlight);
  color: #fff;
  background: #2a313d;
}

.btn-icon {
  padding: 0.4rem 0.65rem;
  background: var(--bg-surface-elevated);
  border-color: var(--border-color);
  font-size: 1rem;
}

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
}

.btn-xs {
  padding: 0.25rem 0.55rem;
  font-size: 0.76rem;
}

/* Main Workspace */
.main-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(0.6rem, 1.5vh, 1.25rem) clamp(0.75rem, 2.5vw, 1.5rem);
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
}

.view-section {
  width: 100%;
}

/* Auth View */
.auth-card {
  width: 100%;
  max-width: 420px;
  margin: clamp(1rem, 4vh, 2.5rem) auto;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: clamp(1.25rem, 3vw, 2rem);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.4);
}

.auth-card h2 {
  font-size: 1.35rem;
  margin-bottom: 0.25rem;
  color: #fff;
}

.auth-subtitle {
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-bottom: 1.25rem;
}

.auth-tabs {
  display: flex;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-color);
}

.auth-tab {
  flex: 1;
  padding: 0.75rem;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  text-align: center;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.92rem;
}

.auth-tab.active {
  color: #fff;
  border-bottom-color: var(--accent);
}

.form-group {
  margin-bottom: 1.15rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 0.4rem;
  color: var(--text-secondary);
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="number"] {
  width: 100%;
  padding: 0.65rem 0.85rem;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  color: #fff;
  font-size: 0.95rem;
  transition: border-color 0.15s;
}

.form-group input:focus {
  outline: none;
  border-color: var(--accent);
}

.divider {
  text-align: center;
  margin: 1.25rem 0;
  position: relative;
}

.divider::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  border-top: 1px solid var(--border-color);
}

.divider span {
  position: relative;
  background: var(--bg-surface);
  padding: 0 10px;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
}

.dev-btn-row {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
}

/* Lobby Layout */
.lobby-grid {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 1.5rem;
}

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

.lobby-main-col,
.lobby-side-col {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.action-bar-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.action-bar-text h3 {
  font-size: 1.05rem;
  color: #fff;
  margin-bottom: 0.2rem;
}

.action-bar-text p {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.action-bar-buttons {
  display: flex;
  gap: 0.65rem;
}

#btn-open-bot-modal {
  background: #4f46e5;
  border-color: #4f46e5;
  color: #fff;
}
#btn-open-bot-modal:hover {
  background: #4338ca;
}

.panel-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-header {
  padding: 0.85rem 1.2rem;
  background: var(--bg-surface-elevated);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.panel-header h3 {
  font-size: 0.98rem;
  font-weight: 700;
  color: #fff;
}

.badge {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 0.75rem;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-weight: 700;
}

.badge-success {
  background: rgba(16, 185, 129, 0.18);
  border-color: rgba(16, 185, 129, 0.4);
  color: var(--success);
}

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

.list-container {
  max-height: clamp(160px, 24vh, 260px);
  overflow-y: auto;
  padding: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.empty-placeholder {
  color: var(--text-muted);
  font-size: 0.86rem;
  padding: 1.2rem;
  text-align: center;
}

.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.85rem;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 0.88rem;
  gap: 0.65rem;
  transition: border-color 0.15s;
}

.list-row:hover {
  border-color: var(--border-highlight);
}

.list-row-info {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #334155;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: #e2e8f0;
  flex-shrink: 0;
}

.clickable-user {
  background: none;
  border: none;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.92rem;
}

.clickable-user:hover {
  color: #93c5fd;
  text-decoration: underline;
}

/* Chat Panel (dambrete-platform chat bubble styling) */
.chat-panel {
  flex: 1;
  min-height: 260px;
  display: flex;
  flex-direction: column;
}

.chat-messages {
  flex: 1;
  height: clamp(180px, 26vh, 260px);
  overflow-y: auto;
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  background: var(--bg-surface);
}

.chat-item {
  display: flex;
  flex-direction: column;
  background: var(--bg-surface-elevated);
  padding: 0.55rem 0.85rem;
  border-radius: 8px;
  max-width: 88%;
  align-self: flex-start;
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.chat-item.mine {
  align-self: flex-end;
  background: #1e3a5f;
  border-color: rgba(59, 130, 246, 0.25);
}

.chat-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.2rem;
}

.chat-author {
  font-size: 0.8rem;
  font-weight: 700;
  color: #93c5fd;
  cursor: pointer;
}

.chat-text {
  font-size: 0.9rem;
  line-height: 1.4;
  word-break: break-word;
  color: var(--text-primary);
}

.chat-form {
  display: flex;
  padding: 0.65rem 0.9rem;
  background: var(--bg-surface-elevated);
  border-top: 1px solid var(--border-color);
  gap: 0.55rem;
  flex-shrink: 0;
}

.chat-form input {
  flex: 1;
  min-width: 0;
  padding: 0.55rem 0.8rem;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  color: #fff;
  font-size: 0.9rem;
}

.chat-form input:focus {
  outline: none;
  border-color: var(--accent);
}

/* Active Game Layout — Viewport-Adaptive Sizing */
.game-layout {
  --board-size: clamp(280px, min(560px, calc(100vh - 190px), calc(100vw - 400px)), 560px);
  display: flex;
  gap: clamp(1rem, 2.2vw, 2rem);
  align-items: stretch;
  justify-content: center;
  width: 100%;
}

@supports (height: 100dvh) {
  .game-layout {
    --board-size: clamp(280px, min(560px, calc(100dvh - 190px), calc(100vw - 400px)), 560px);
  }
}

.game-board-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(0.4rem, 1vh, 0.7rem);
  flex-shrink: 0;
}

.player-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: var(--board-size);
  max-width: 94vw;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: clamp(0.35rem, 0.8vh, 0.55rem) clamp(0.65rem, 1.5vw, 1rem);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.player-bar.active-turn {
  border-color: var(--accent);
  box-shadow: 0 0 14px rgba(59, 130, 246, 0.3);
}

.player-identity {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
}

.conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.conn-dot.online {
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
}

.conn-dot.offline {
  background: var(--danger);
}

.color-chip {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: inline-block;
  border: 1px solid #777;
  flex-shrink: 0;
}

.color-chip.white {
  background: var(--piece-white);
}

.color-chip.black {
  background: var(--piece-black);
}

.player-name-btn {
  background: none;
  border: none;
  color: #fff;
  font-weight: 700;
  font-size: clamp(0.88rem, 1.5vw, 1rem);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-name-btn:hover {
  color: #93c5fd;
  text-decoration: underline;
}

.player-elo {
  color: var(--text-secondary);
  font-size: 0.82rem;
  flex-shrink: 0;
}

.grace-badge {
  background: var(--danger);
  color: #fff;
  font-size: 0.72rem;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
  flex-shrink: 0;
}

.player-metrics {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-shrink: 0;
}

.piece-count-badge {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.digital-clock {
  font-family: var(--font-mono);
  font-size: clamp(1.05rem, 2vh, 1.3rem);
  font-weight: 700;
  padding: 0.2rem 0.65rem;
  border-radius: 6px;
  background: #000;
  border: 1px solid #333;
  letter-spacing: 1px;
  min-width: 80px;
  text-align: center;
  color: var(--text-primary);
}

.digital-clock.active-turn {
  border-color: var(--accent);
  color: #fff;
}

.digital-clock.low-time {
  color: var(--danger);
  border-color: var(--danger);
  animation: pulse-red 1s infinite;
}

@keyframes pulse-red {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
  50% { box-shadow: 0 0 12px 4px rgba(239, 68, 68, 0.6); }
}

.game-substatus-banner {
  width: var(--board-size);
  max-width: 94vw;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--warning);
  color: var(--warning);
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  font-size: 0.82rem;
  text-align: center;
  font-weight: 600;
}

/* The 8x8 Dambrete Board (dambrete-platform styling) */
.board-stage {
  width: var(--board-size);
  height: var(--board-size);
  max-width: 94vw;
  max-height: 94vw;
  flex-shrink: 0;
}

.board-container {
  width: 100%;
  height: 100%;
  aspect-ratio: 1 / 1;
  border: clamp(5px, 1vw, 8px) solid var(--board-border);
  border-radius: 8px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6), inset 0 0 10px rgba(0, 0, 0, 0.5);
  position: relative;
  user-select: none;
  touch-action: manipulation;
  overflow: hidden;
}

.board-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  height: 100%;
}

.board-square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}

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

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

.board-square.last-move-sq {
  background-color: var(--square-last-move) !important;
}

.board-square.selected-sq {
  background-color: var(--square-select) !important;
}

.board-square.valid-target-sq {
  cursor: pointer;
}

.board-square.drag-hover-sq {
  box-shadow: inset 0 0 0 4px #10b981 !important;
  background-color: rgba(16, 185, 129, 0.45) !important;
}

/* Coordinate notations on squares */
.coord-label {
  position: absolute;
  font-size: 0.65rem;
  font-weight: 700;
  pointer-events: none;
  opacity: 0.6;
}

.light-sq .coord-label {
  color: var(--board-dark);
}

.dark-sq .coord-label {
  color: var(--board-light);
}

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

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

/* Draughts Pieces (dambrete-platform styling) */
.piece {
  width: 82%;
  height: 82%;
  border-radius: 50%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.5), inset 0 2px 4px rgba(255, 255, 255, 0.4);
  transition: transform 0.15s ease, filter 0.15s ease, opacity 0.15s ease;
  z-index: 10;
}

.piece:hover {
  transform: scale(1.05);
}

.piece-white {
  background: radial-gradient(circle at 35% 35%, #ffffff, #e2e8f0 70%, #cbd5e1);
  border: 3px solid var(--piece-white-rim);
}

.piece-white::after {
  content: "";
  position: absolute;
  width: 60%;
  height: 60%;
  border-radius: 50%;
  border: 1px dashed rgba(0, 0, 0, 0.15);
  pointer-events: none;
}

.piece-black {
  background: radial-gradient(circle at 35% 35%, #475569, #1e293b 70%, #0f172a);
  border: 3px solid var(--piece-black-rim);
}

.piece-black::after {
  content: "";
  position: absolute;
  width: 60%;
  height: 60%;
  border-radius: 50%;
  border: 1px dashed rgba(255, 255, 255, 0.15);
  pointer-events: none;
}

.piece.movable-piece {
  cursor: grab;
}

.piece.movable-piece:active {
  cursor: grabbing;
}

.piece.draggable-piece {
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.piece.touch-dragging-source {
  opacity: 0.35;
}

.piece.touch-drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  transform: translate(-50%, -50%) scale(1.12);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.65);
  transition: none;
}

.piece.must-capture {
  animation: pulse-capture 1.2s infinite;
}

@keyframes pulse-capture {
  0%, 100% { filter: drop-shadow(0 0 3px #f59e0b); }
  50% { filter: drop-shadow(0 0 8px #f59e0b) brightness(1.1); }
}

/* Crown Icon on Kings */
.crown-icon {
  width: 52%;
  height: 52%;
  fill: #f59e0b;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.6));
  position: relative;
  z-index: 2;
  pointer-events: none;
}

/* Deferred Jump Removal Ghost (§7.3) */
.piece.captured-ghost {
  opacity: 0.35;
  filter: grayscale(60%);
  pointer-events: none;
}

/* Target indicators for legal moves */
.target-dot {
  position: absolute;
  width: 34%;
  height: 34%;
  max-width: 22px;
  max-height: 22px;
  border-radius: 50%;
  background: rgba(16, 185, 129, 0.65);
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.85);
  pointer-events: none;
  z-index: 5;
}

.board-square.capture-target-sq .target-dot {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  border-radius: 0;
  background: rgba(239, 68, 68, 0.35);
  box-shadow: inset 0 0 0 3px #ef4444;
}

/* Game Side Column */
.game-side-col {
  width: clamp(300px, 28vw, 360px);
  max-width: 92vw;
  height: calc(var(--board-size) + 108px);
  max-height: calc(var(--board-size) + 108px);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.game-info-panel {
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  flex: 0 1 auto;
  min-height: 0;
}

.game-meta-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.6rem;
}

.spectator-count {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.action-prompt-banner {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  margin-bottom: 0.6rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
}

.prompt-actions {
  display: flex;
  gap: 0.4rem;
}

.move-history-list {
  height: clamp(80px, 16vh, 170px);
  flex: 0 1 auto;
  min-height: 64px;
  max-height: 180px;
  overflow-y: auto;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.45rem 0.7rem;
  margin-bottom: 0.65rem;
  font-family: var(--font-mono);
  font-size: 0.84rem;
}

.move-turn-row {
  display: grid;
  grid-template-columns: 36px 1fr 1fr;
  padding: 0.3rem 0.4rem;
  border-radius: 4px;
}

.move-turn-row:hover {
  background: rgba(255, 255, 255, 0.03);
}

.move-num {
  color: var(--text-muted);
}

.move-ply {
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}

.move-ply:hover,
.move-ply.active-ply {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.game-controls-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.post-game-panel {
  margin-top: 0.65rem;
  padding: 0.75rem 0.85rem;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--accent);
  border-radius: 8px;
  text-align: center;
}

.post-game-panel h4 {
  font-size: 1.02rem;
  color: #fff;
  margin-bottom: 0.2rem;
}

.post-game-panel p {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-bottom: 0.65rem;
}

.post-game-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  justify-content: center;
}

.game-side-col .chat-panel {
  flex: 1 1 0;
  min-height: 180px;
}

.game-side-col .chat-messages {
  flex: 1 1 0;
  height: auto;
  min-height: 60px;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.6);
}

.modal-lg {
  max-width: 680px;
}

.modal-xl {
  max-width: 920px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
}

.btn-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.btn-close:hover {
  color: #fff;
}

.modal-body {
  padding: 1.25rem;
  overflow-y: auto;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.65rem;
  margin-top: 1.25rem;
}

/* Presets & Color Picker */
.preset-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.6rem;
}

.preset-btn {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.7rem 0.4rem;
  color: var(--text-primary);
  font-weight: 700;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: border-color 0.15s, background 0.15s;
}

.preset-btn span {
  font-size: 0.72rem;
  font-weight: 400;
  color: var(--text-muted);
}

.preset-btn.active {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.18);
  box-shadow: 0 0 10px var(--accent-glow);
}

.custom-tc-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.color-picker-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
}

.radio-card {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.6rem;
  text-align: center;
  cursor: pointer;
  font-size: 0.88rem;
}

/* Profile Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(105px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.stat-box {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.75rem;
  text-align: center;
}

.stat-value {
  font-size: 1.35rem;
  font-weight: 800;
  color: #fff;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-top: 0.2rem;
}

/* Replay Modal */
.replay-layout {
  display: grid;
  grid-template-columns: minmax(240px, 420px) 1fr;
  gap: 1.25rem;
  align-items: start;
}

.replay-board-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

#replay-board {
  width: min(100%, calc(100vh - 250px), 420px);
  width: min(100%, calc(100dvh - 250px), 420px);
}

.replay-controls {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.replay-meta-info {
  margin-bottom: 0.75rem;
  font-size: 0.88rem;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  padding: 0.6rem 0.85rem;
  border-radius: 8px;
}

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

/* Admin Modal */
.admin-section {
  margin-bottom: 1.5rem;
}

.admin-section h4 {
  margin-bottom: 0.6rem;
  color: #fff;
}

.settings-toggle-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.65rem;
}

.toggle-item {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  padding: 0.7rem 0.85rem;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  cursor: pointer;
  font-size: 0.88rem;
}

.admin-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.6rem;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.admin-search-bar {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.admin-search-bar input {
  padding: 0.4rem 0.7rem;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  color: #fff;
}

.table-wrap {
  overflow-x: auto;
  max-height: 280px;
  overflow-y: auto;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}

.admin-table th,
.admin-table td {
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border-color);
  text-align: left;
}

.admin-table th {
  color: var(--text-muted);
}

.admin-in-game-bar {
  margin-top: 0.6rem;
  padding: 0.55rem 0.75rem;
  background: rgba(239, 68, 68, 0.1);
  border: 1px dashed rgba(239, 68, 68, 0.45);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.admin-bar-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: #fca5a5;
  letter-spacing: 0.5px;
}

.admin-bar-btns {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.admin-create-user-form {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.admin-create-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.75rem;
}

.admin-create-grid .form-group {
  margin-bottom: 0;
}

.admin-create-grid label {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
  display: block;
}

.admin-create-grid input,
.admin-create-grid select {
  width: 100%;
  padding: 0.45rem 0.65rem;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  color: #fff;
  font-size: 0.85rem;
}

.auth-info-note {
  font-size: 0.82rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 0.75rem;
}

/* Toasts */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.toast {
  background: #1e293b;
  border: 1px solid var(--accent);
  color: var(--text-primary);
  padding: 0.8rem 1.1rem;
  border-radius: 10px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  font-size: 0.88rem;
}

.toast.toast-error {
  border-color: var(--danger);
}

.invite-toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 210;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.invite-card {
  background: #1e293b;
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 1rem 1.25rem;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.55);
  font-size: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: 300px;
}

/* ==========================================
   Responsive Breakpoints (Laptops, Tablets, Mobile)
   ========================================== */

/* Short desktop/laptop viewports (e.g., 1366x768, 1280x720, browser toolbars) */
@media (max-height: 760px) and (min-width: 921px) {
  .app-header {
    padding: 0.4rem 1.25rem;
  }

  .main-container {
    padding: 0.45rem 1rem;
  }

  .game-layout {
    --board-size: clamp(260px, min(520px, calc(100vh - 155px), calc(100vw - 380px)), 520px);
    --board-size: clamp(260px, min(520px, calc(100dvh - 155px), calc(100vw - 380px)), 520px);
    gap: 1rem;
  }

  .game-board-col {
    gap: 0.35rem;
  }

  .player-bar {
    padding: 0.4rem 0.75rem;
  }

  .clock-box {
    font-size: 1.05rem;
    padding: 0.25rem 0.55rem;
  }

  .game-side-col {
    height: calc(var(--board-size) + 84px);
    max-height: calc(var(--board-size) + 84px);
    gap: 0.55rem;
  }

  .game-info-panel {
    padding: 0.65rem 0.85rem;
  }

  .move-history-list {
    margin-bottom: 0.5rem;
  }
}

/* Tablet and mobile stacked layout */
@media (max-width: 920px) {
  .game-layout {
    --board-size: clamp(260px, min(94vw, calc(100vh - 185px), 520px), 520px);
    --board-size: clamp(260px, min(94vw, calc(100dvh - 185px), 520px), 520px);
    flex-direction: column;
    align-items: center;
    gap: 1rem;
  }

  .game-side-col {
    width: var(--board-size);
    max-width: 94vw;
    height: auto;
    max-height: none;
  }

  .move-history-list {
    height: 130px;
    max-height: 150px;
    flex: none;
  }

  .game-side-col .chat-panel {
    flex: none;
    height: auto;
    min-height: 0;
  }

  .game-side-col .chat-messages {
    flex: none;
    height: 180px;
    min-height: 140px;
  }
}

/* Mobile phones */
@media (max-width: 600px) {
  .app-header {
    padding: 0.5rem 0.75rem;
  }

  .brand-title {
    font-size: 1.05rem;
  }

  .header-nav {
    gap: 0.35rem;
  }

  .header-nav .btn-sm {
    padding: 0.28rem 0.5rem;
    font-size: 0.75rem;
  }

  .user-pill {
    padding: 0.2rem 0.5rem;
    font-size: 0.78rem;
  }

  .main-container {
    padding: 0.5rem;
  }

  .player-bar {
    padding: 0.45rem 0.65rem;
  }

  .player-name {
    font-size: 0.88rem;
  }

  .clock-box {
    font-size: 1rem;
    padding: 0.25rem 0.5rem;
    min-width: 68px;
  }

  .coord-rank {
    font-size: 0.58rem;
  }

  .coord-file {
    font-size: 0.58rem;
  }

  .game-controls-bar .btn {
    flex: 1 1 auto;
  }

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

  .custom-tc-row {
    grid-template-columns: 1fr;
  }

  .modal-backdrop {
    padding: 0.5rem;
  }

  .modal-header {
    padding: 0.85rem 1rem;
  }

  .modal-body {
    padding: 1rem;
  }

  .toast-container,
  .invite-toast-container {
    left: 0.75rem;
    right: 0.75rem;
    bottom: 0.75rem;
  }

  .invite-card {
    min-width: 0;
    width: 100%;
  }
}
