/* ===== CSS Variables ===== */
:root {
  --bg: #0a0e17;
  --surface: rgba(255, 255, 255, 0.03);
  --surface-hover: rgba(255, 255, 255, 0.06);
  --border: rgba(255, 255, 255, 0.08);
  --border-active: rgba(255, 255, 255, 0.2);
  --accent: #e3b341;
  --accent-glow: rgba(227, 179, 65, 0.25);
  --accent-secondary: #37b2ff;
  --accent-secondary-glow: rgba(55, 178, 255, 0.25);
  --muted: #6b7a94;
  --light: #f0f4f8;
  --dark-square: #1a2535;
  --light-square: #2a3a50;
  --selection: #5eb5f7;
  --valid-move: #4ade80;
  --capture: #f87171;
  --last-move: rgba(227, 179, 65, 0.3);
  --danger: #ef4444;
  --success: #22c55e;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;
}

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--light);
  font-family: "Space Grotesk", system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ===== Mode Tabs ===== */
.mode-tabs {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
  z-index: 100;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.mode-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.mode-tab:hover {
  color: var(--light);
  background: var(--surface-hover);
}

.mode-tab.active {
  background: var(--accent);
  color: #1a1205;
  box-shadow: 0 4px 16px var(--accent-glow);
}

.mode-tab.active[data-mode="multi"] {
  background: var(--accent-secondary);
  box-shadow: 0 4px 16px var(--accent-secondary-glow);
}

.tab-icon {
  font-size: 16px;
}

/* ===== Game Container ===== */
.game-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 80px 20px 100px;
  width: 100%;
  max-width: 100vw;
  overflow: hidden;
}

/* ===== Status Bar ===== */
.status-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  color: var(--muted);
  font-size: 14px;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
  animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.status-divider {
  opacity: 0.3;
}

/* ===== Board ===== */
.board-wrapper {
  position: relative;
  padding: 12px;
  background: linear-gradient(145deg, rgba(255,255,255,0.04), transparent);
  border-radius: var(--radius-xl);
  border: 1px solid var(--border);
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  width: min(calc(100vw - 48px), calc(100vh - 260px), 600px);
  aspect-ratio: 1;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
}

.square {
  aspect-ratio: 1;
  border: none;
  font-size: clamp(24px, 5vmin, 44px);
  color: var(--light);
  display: grid;
  place-items: center;
  cursor: pointer;
  position: relative;
  transition: transform 0.1s ease, filter 0.1s ease;
  text-shadow: 1px 2px 4px rgba(0,0,0,0.4);
}

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

.square:hover:not(.disabled) {
  filter: brightness(1.15);
  transform: scale(1.02);
  z-index: 1;
}

.square.selected {
  background: rgba(94, 181, 247, 0.4) !important;
  box-shadow: inset 0 0 0 3px var(--selection);
}

.square.last-move-from,
.square.last-move-to {
  background: var(--last-move) !important;
}

.square.valid-move::after {
  content: '';
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: var(--valid-move);
  box-shadow: 0 0 12px var(--valid-move);
  position: absolute;
  opacity: 0.85;
  animation: pulse-move 1.8s ease-in-out infinite;
}

.square.valid-capture::before {
  content: '';
  position: absolute;
  inset: 6px;
  border-radius: 50%;
  border: 4px solid var(--capture);
  box-shadow: 0 0 16px rgba(248, 113, 113, 0.5);
  animation: pulse-capture 1.8s ease-in-out infinite;
}

@keyframes pulse-move {
  0%, 100% { transform: scale(1); opacity: 0.7; }
  50% { transform: scale(1.15); opacity: 1; }
}

@keyframes pulse-capture {
  0%, 100% { transform: scale(1); opacity: 0.6; }
  50% { transform: scale(1.05); opacity: 1; }
}

.board.disabled .square {
  cursor: not-allowed;
}

/* ===== Toolbar ===== */
.toolbar {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(15, 20, 30, 0.9);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 12px;
  z-index: 100;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.toolbar-group.scores {
  padding: 0 8px;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

.tool-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--light);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
  position: relative;
}

.tool-btn:hover {
  background: var(--surface-hover);
}

.tool-icon {
  font-size: 16px;
}

.tool-btn .badge {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 16px;
  height: 16px;
  border-radius: 999px;
  background: var(--accent-secondary);
  color: #0a0e17;
  font-size: 10px;
  font-weight: 700;
  display: none;
  align-items: center;
  justify-content: center;
}

.tool-btn .badge.visible {
  display: flex;
}

.score-display {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  font-size: 13px;
}

.score-label {
  color: var(--muted);
}

.score-value {
  font-weight: 700;
  color: var(--accent);
}

/* ===== Slide Panels ===== */
.slide-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: min(360px, 90vw);
  height: 100vh;
  background: rgba(12, 16, 24, 0.98);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-left: 1px solid var(--border);
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 200;
  display: flex;
  flex-direction: column;
}

.slide-panel.open {
  transform: translateX(0);
}

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

.panel-header h2 {
  font-size: 18px;
  font-weight: 700;
}

.close-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: var(--surface);
  color: var(--light);
  font-size: 20px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.close-btn:hover {
  background: var(--surface-hover);
}

.panel-body {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
}

.panel-hint {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 20px;
  text-align: center;
}

/* ===== Buttons ===== */
.btn-primary {
  padding: 14px 24px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--accent-secondary);
  color: #0a0e17;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 6px 20px var(--accent-secondary-glow);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px var(--accent-secondary-glow);
}

.btn-secondary {
  padding: 12px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--light);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn-secondary:hover {
  background: var(--surface-hover);
  border-color: var(--border-active);
}

.btn-danger {
  padding: 14px 24px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--danger);
  color: white;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.btn-danger:hover {
  transform: translateY(-1px);
}

.full-width {
  width: 100%;
}

/* ===== Inputs ===== */
.input-group {
  display: flex;
  gap: 8px;
}

.text-input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--light);
  font-family: inherit;
  font-size: 14px;
  letter-spacing: 2px;
  text-transform: uppercase;
  transition: border-color 0.15s ease;
}

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

.text-input::placeholder {
  letter-spacing: normal;
  text-transform: none;
  color: var(--muted);
}

/* ===== Divider ===== */
.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  color: var(--muted);
  font-size: 12px;
}

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

/* ===== Room Info ===== */
.room-code-box {
  text-align: center;
  padding: 24px;
  background: linear-gradient(135deg, var(--accent-secondary-glow), transparent);
  border: 2px dashed var(--accent-secondary);
  border-radius: var(--radius-lg);
  margin-bottom: 20px;
}

.room-code-label {
  display: block;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
}

.room-code {
  display: block;
  font-size: 32px;
  font-weight: 700;
  letter-spacing: 6px;
  color: var(--accent-secondary);
}

.room-code-hint {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 8px;
}

.player-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  background: var(--surface);
  border-radius: var(--radius-md);
  margin-bottom: 16px;
}

.player-label {
  color: var(--muted);
  font-size: 13px;
}

.player-color-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 14px;
}

.player-color-badge.white {
  background: rgba(255, 255, 255, 0.15);
}

.player-color-badge.black {
  background: rgba(0, 0, 0, 0.4);
}

.game-status-box {
  padding: 16px;
  background: var(--surface);
  border-radius: var(--radius-md);
  margin-bottom: 20px;
  text-align: center;
}

.status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

.status-indicator::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-secondary);
  animation: pulse-dot 1.5s ease-in-out infinite;
}

/* ===== Chat ===== */
.chat-drawer {
  display: flex;
  flex-direction: column;
}

.chat-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  padding: 40px;
}

.chat-message {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  background: var(--surface);
  border-left: 3px solid var(--muted);
}

.chat-message.white {
  border-left-color: rgba(255, 255, 255, 0.6);
}

.chat-message.black {
  border-left-color: rgba(100, 100, 100, 0.8);
  background: rgba(0, 0, 0, 0.2);
}

.chat-message.own {
  border-left-color: var(--accent-secondary);
  background: rgba(55, 178, 255, 0.1);
}

.chat-message-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}

.chat-sender {
  font-weight: 600;
  font-size: 12px;
  color: var(--accent);
}

.chat-timestamp {
  font-size: 10px;
  color: var(--muted);
}

.chat-text {
  font-size: 13px;
  line-height: 1.5;
  word-break: break-word;
}

.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 16px;
  border-top: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.2);
}

.chat-input {
  flex: 1;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--light);
  font-family: inherit;
  font-size: 13px;
}

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

.chat-send {
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--accent-secondary);
  color: #0a0e17;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.chat-send:hover {
  transform: translateY(-1px);
}

.chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ===== Info Popover ===== */
.popover {
  position: fixed;
  bottom: 90px;
  right: 50%;
  transform: translateX(calc(50% + 120px));
  width: 280px;
  background: rgba(12, 16, 24, 0.98);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
  z-index: 150;
}

.popover.open {
  opacity: 1;
  visibility: visible;
}

.popover-arrow {
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%) rotate(45deg);
  width: 16px;
  height: 16px;
  background: rgba(12, 16, 24, 0.98);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.info-row {
  margin-bottom: 12px;
}

.info-row:last-child {
  margin-bottom: 0;
}

.info-label {
  display: block;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.info-value {
  font-size: 14px;
  font-weight: 600;
}

.log-box {
  padding: 10px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: var(--radius-sm);
  font-size: 12px;
  line-height: 1.5;
  max-height: 80px;
  overflow-y: auto;
  white-space: pre-wrap;
  color: var(--muted);
}

.scores-detail {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.score-card {
  padding: 12px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  text-align: center;
}

.card-label {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 4px;
}

.card-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
}

/* ===== Backdrop ===== */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  z-index: 150;
}

.backdrop.visible {
  opacity: 1;
  visibility: visible;
}

/* ===== Toast ===== */
.toast-container {
  position: fixed;
  top: 80px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 300;
  pointer-events: none;
}

.toast {
  min-width: 220px;
  max-width: 300px;
  padding: 14px 18px;
  background: rgba(12, 16, 24, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--light);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  font-size: 13px;
  opacity: 0;
  transform: translateX(20px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: auto;
}

.toast.show {
  opacity: 1;
  transform: translateX(0);
}

.toast.success { border-color: rgba(34, 197, 94, 0.5); }
.toast.accent { border-color: var(--accent-glow); }
.toast.secondary { border-color: var(--accent-secondary-glow); }

/* ===== Mode Visibility ===== */
body.mode-single .single-player-only { display: flex; }
body.mode-single .multiplayer-only { display: none !important; }
body.mode-multi .single-player-only { display: none !important; }
body.mode-multi .multiplayer-only { display: flex; }

.hidden {
  display: none !important;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* ===== Responsive ===== */
@media (max-width: 640px) {
  .mode-tabs {
    top: 12px;
  }

  .mode-tab {
    padding: 8px 14px;
  }

  .tab-label {
    display: none;
  }

  .game-container {
    padding: 70px 12px 90px;
  }

  .toolbar {
    padding: 6px 10px;
    gap: 4px;
  }

  .tool-btn {
    padding: 8px 10px;
  }

  .tool-text {
    display: none;
  }

  .toolbar-group.scores {
    padding: 0 6px;
  }

  .score-display {
    padding: 4px 6px;
    font-size: 12px;
  }

  .slide-panel {
    width: 100vw;
  }

  .popover {
    right: 10px;
    left: 10px;
    transform: none;
    width: auto;
  }
}
