/**
 * Chinese Chess (Xiangqi, 中国象棋竞技场) Stylesheet
 * Responsive Traditional Wood / Dark / Classic Themes
 */

:root {
  --bg-color: #0f172a;
  --text-color: #f8fafc;
  --card-bg: #1e293b;
  --border-color: #334155;
  --primary: #dc2626; /* Traditional Chinese Red */
  --primary-hover: #b91c1c;
  --header-bg: #0f172a;
  --header-color: #f8fafc;
  --board-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] {
  --bg-color: #0f172a;
  --text-color: #f8fafc;
  --card-bg: #1e293b;
  --border-color: #334155;
  --header-bg: #0f172a;
  --header-color: #f8fafc;
  --board-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
}

[data-theme="midnight"] {
  --bg-color: #090d16;
  --text-color: #f8fafc;
  --card-bg: #0f172a;
  --border-color: rgba(255, 255, 255, 0.08);
  --header-bg: #090d16;
  --header-color: #f8fafc;
  --board-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
}

[data-theme="wood"] {
  --bg-color: #0f172a;
  --text-color: #f8fafc;
  --card-bg: #1e293b;
  --border-color: #334155;
  --header-bg: #0f172a;
  --header-color: #f8fafc;
  --board-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color 0.25s ease, color 0.25s ease;
  user-select: none;
}

/* Header & Navigation */
header {
  background: var(--header-bg);
  color: var(--header-color);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-container {
  max-width: 1480px;
  margin: 0 auto;
  padding: 8px 16px 4px;
}

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

.brand-zone {
  display: flex;
  align-items: center;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: -0.5px;
}

.brand-icon {
  font-size: 1.5rem;
}

.nav-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.online-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(34, 197, 94, 0.15);
  color: #22c55e;
  border: 1px solid rgba(34, 197, 94, 0.3);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  background-color: #22c55e;
  border-radius: 50%;
  box-shadow: 0 0 8px #22c55e;
}

.player-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-badge.is-guest {
  background: rgba(59, 130, 246, 0.18);
  border: 1px solid rgba(96, 165, 250, 0.5);
  color: #60a5fa;
}

.player-badge.logged-in {
  background: rgba(234, 179, 8, 0.18);
  border: 1px solid rgba(250, 204, 21, 0.5);
  color: #facc15;
}

.player-badge:hover {
  transform: translateY(-1px);
}

.btn {
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 0.88rem;
  font-weight: 600;
  border: 1px solid var(--border-color);
  background: var(--card-bg);
  color: var(--text-color);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.15s ease;
}

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

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff !important;
}

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

.btn-icon {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

.btn-group {
  display: inline-flex;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border-color);
}

.btn-group .btn {
  border: none;
  border-radius: 0;
  border-right: 1px solid var(--border-color);
}

.btn-group .btn:last-child {
  border-right: none;
}

.btn-group .btn.active {
  background: var(--primary);
  color: #ffffff;
}

/* Tabs */
.main-tabs {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  border-bottom: 2px solid rgba(255, 255, 255, 0.1);
}

.tab-btn {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.7);
  padding: 8px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  transition: all 0.2s ease;
}

.tab-btn:hover {
  color: #ffffff;
}

.tab-btn.active {
  color: #ffffff;
  border-bottom-color: var(--primary);
}

/* Main */
main {
  flex: 1;
  max-width: 1480px;
  width: 100%;
  margin: 0 auto;
  padding: 14px 20px;
}

.tab-view {
  display: none;
}

.tab-view.active {
  display: block;
}

.sub-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
  background: var(--card-bg);
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
}

.sub-toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Arena Layout */
.arena-layout {
  display: flex;
  gap: 28px;
  align-items: flex-start;
  justify-content: center;
  width: 100%;
}

#board-container {
  position: relative;
  border-radius: 12px;
  box-shadow: var(--board-shadow);
  overflow: hidden;
  background: #deb887;
  cursor: pointer;
  touch-action: manipulation;
  flex-shrink: 0;
}

#board-canvas {
  display: block;
}

.game-banner {
  display: none;
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: bold;
  font-size: 0.95rem;
  text-align: center;
  margin-bottom: 12px;
  animation: slideDown 0.25s ease-out;
}

.game-banner.is-success {
  background: #22c55e;
  color: #ffffff;
}

.game-banner.is-danger {
  background: #ef4444;
  color: #ffffff;
}

.game-banner.is-info {
  background: #3b82f6;
  color: #ffffff;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.arena-sidebar {
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sidebar-card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 14px;
}

.sidebar-card-title {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.move-history-list {
  max-height: 280px;
  overflow-y: auto;
  font-family: monospace;
  font-size: 0.88rem;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.move-row {
  display: flex;
  padding: 3px 6px;
  border-radius: 4px;
}

.move-row:nth-child(odd) {
  background: rgba(0, 0, 0, 0.04);
}

[data-theme="dark"] .move-row:nth-child(odd),
[data-theme="wood"] .move-row:nth-child(odd) {
  background: rgba(255, 255, 255, 0.05);
}

.move-num {
  width: 36px;
  color: #94a3b8;
}

.move-step {
  flex: 1;
}

.empty-hint {
  text-align: center;
  color: #94a3b8;
  padding: 24px 0;
  font-size: 0.85rem;
}

/* Floating Emotes */
.floating-emote {
  position: absolute;
  top: 40%;
  font-size: 3rem;
  pointer-events: none;
  animation: floatUp 2.2s ease-out forwards;
  z-index: 50;
}

.floating-emote.is-self { right: 15%; }
.floating-emote.is-opp { left: 15%; }

@keyframes floatUp {
  0% { opacity: 0; transform: translateY(20px) scale(0.6); }
  20% { opacity: 1; transform: translateY(0) scale(1.2); }
  80% { opacity: 1; transform: translateY(-30px) scale(1); }
  100% { opacity: 0; transform: translateY(-60px) scale(0.8); }
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
}

.leaderboard-table th,
.leaderboard-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.9rem;
}

.leaderboard-table th {
  background: rgba(0, 0, 0, 0.04);
  font-weight: 700;
}

.elo-badge {
  color: #f59e0b;
  font-weight: 700;
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s ease;
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal-card {
  background: var(--card-bg);
  border-radius: 12px;
  width: 90%;
  max-width: 540px;
  padding: 20px;
  box-shadow: 0 16px 36px rgba(0,0,0,0.35);
  border: 1px solid var(--border-color);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.modal-close-btn {
  background: transparent;
  border: none;
  font-size: 1.4rem;
  color: var(--text-color);
  cursor: pointer;
}

@media (max-width: 820px) {
  .arena-layout {
    flex-direction: column;
    align-items: center;
  }
  .arena-sidebar {
    width: 100%;
    max-width: 500px;
  }
}

@media (max-width: 680px) {
  header { padding: 6px 10px; }
  .brand-text { font-size: 1.05rem; }
  .player-badge { max-width: 110px; font-size: 0.78rem; padding: 4px 8px; }
  .sub-toolbar { padding: 8px 10px; }
  .btn { padding: 5px 9px; font-size: 0.8rem; }
}
