@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=Roboto+Mono:wght@400;500&display=swap');

/* ===== CSS VARIABLES (Chess.com Color Scheme) ===== */
:root {
  --blue: #4B7399;
  --blue-dark: #375a7a;
  --blue-light: #6a96c1;
  --beige: #EBECD0;
  --dark: #2c2a27;
  --grey: #7c7a77;
  --white: #ffffff;
  color-scheme: dark;

  /* Brand Colors (Updated to Blue/Beige) */
  --blue: #4B7399;
  --blue-dark: #375a7a;
  --blue-light: #6a96c1;
  --beige: #EBECD0;
  --orange: #F38D1F;
  --green-accent: #779556;

  --tile-dark: var(--blue);
  --tile-light: var(--beige);
  --bg-main: #1a1816;
  --bg-panel: #272422;
  --bg-card: #2c2a27;
  --border: rgba(235, 236, 208, 0.1);
  --text-primary: #EBECD0;
  --text-secondary: #8B8987;
  --text-accent: var(--blue-light);

  --tile-size: 70px;
  --board-border: 6px;
}

@media (max-width: 1000px) {
  :root {
    --tile-size: 9.5vw;
    /* Scale board for mobile */
  }
}


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

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-main);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ===== BACKGROUND GRADIENT ===== */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background:
    radial-gradient(ellipse at 10% 20%, rgba(115, 149, 82, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 90% 80%, rgba(115, 149, 82, 0.06) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

/* ===== HEADER ===== */
header {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px;
  background: rgba(39, 36, 34, 0.9);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-logo .logo-icon {
  width: 36px;
  height: 36px;
}

.header-logo h1 {
  font-size: 22px;
  font-weight: 800;
  color: var(--blue-light);
  letter-spacing: -0.5px;
}

.header-logo .subtitle {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-secondary);
  letter-spacing: 2px;
  text-transform: uppercase;
  display: block;
  margin-top: -2px;
}

.header-nav {
  display: flex;
  gap: 12px;
  align-items: center;
}

/* ===== BUTTONS ===== */
.btn {
  padding: 8px 20px;
  border-radius: 8px;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
  letter-spacing: 0.3px;
}

.btn-primary {
  background: var(--green);
  color: var(--white);
}

.btn-primary:hover {
  background: var(--green-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(115, 149, 82, 0.35);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: rgba(235, 236, 208, 0.08);
  border-color: rgba(235, 236, 208, 0.2);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid transparent;
  padding: 8px 14px;
}

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

/* Header action buttons (Undo + New Game) */
.header-action-btn {
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-primary);
  background: var(--bg-card);
  transition: all 0.18s ease;
}

.header-action-btn:hover {
  background: var(--blue-dark);
  border-color: var(--blue-light);
  color: #fff;
  box-shadow: 0 2px 12px rgba(75, 115, 153, 0.3);
  transform: translateY(-1px);
}

@media (max-width: 600px) {
  .header-action-btn {
    padding: 7px 12px;
    font-size: 13px;
  }

  /* Hide subtitle on tiny screens */
  .header-logo .subtitle {
    display: none;
  }
}

/* ===== MAIN LAYOUT ===== */
.app-container {
  position: relative;
  z-index: 1;
  display: flex;
  height: calc(100vh - 65px);
  overflow: hidden;
}

@media (max-width: 1000px) {
  .app-container {
    flex-direction: column;
    overflow-y: auto;
    height: auto;
    min-height: calc(100vh - 65px);
  }
}


/* ===== LEFT PANEL ===== */
.left-panel {
  width: 220px;
  min-width: 220px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  gap: 16px;
  overflow-y: auto;
}

@media (max-width: 1000px) {
  .left-panel {
    width: 100%;
    min-width: 100%;
    order: 2;
    border-right: none;
    border-top: 1px solid var(--border);
    height: auto;
    overflow: visible;
  }
}


/* ===== CENTER (BOARD AREA) ===== */
.board-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  padding: 20px 0;
}

@media (max-width: 1000px) {
  .board-area {
    order: 1;
    overflow: visible;
  }
}


/* ===== RIGHT PANEL ===== */
.right-panel {
  width: 260px;
  min-width: 260px;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  gap: 16px;
  overflow-y: auto;
}

@media (max-width: 1000px) {
  .right-panel {
    width: 100%;
    min-width: 100%;
    order: 3;
    border-left: none;
    border-top: 1px solid var(--border);
    height: auto;
    overflow: visible;
  }
}


/* ===== PANEL CARDS ===== */
.panel-card {
  background: var(--bg-card);
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 14px;
}

.panel-card-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

/* ===== TURN INDICATOR ===== */
.turn-indicator {
  background: var(--bg-card);
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 16px;
  text-align: center;
}

.turn-player {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 8px;
}

.turn-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border);
  transition: background 0.3s ease;
}

.turn-dot.white {
  background: var(--light);
  border-color: var(--grey);
}

.turn-dot.dark {
  background: var(--dark);
  border-color: var(--grey);
}

.turn-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}

.action-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(115, 149, 82, 0.15);
  border: 1px solid rgba(115, 149, 82, 0.3);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--green-light);
  transition: all 0.3s ease;
}

.action-badge.action-2 {
  background: rgba(115, 149, 82, 0.3);
  border-color: var(--green);
  color: var(--green);
  animation: pulse-badge 1s ease-in-out infinite;
}

@keyframes pulse-badge {

  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(115, 149, 82, 0.4);
  }

  50% {
    box-shadow: 0 0 0 6px rgba(115, 149, 82, 0);
  }
}

/* ===== CAPTURED PIECES ===== */
.captured-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.captured-row {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  min-height: 24px;
}

.captured-piece-icon {
  width: 22px;
  height: 22px;
  opacity: 0.75;
}

/* ===== MOVE LOG ===== */
.move-log {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.move-log-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 300px;
}

.move-log-list::-webkit-scrollbar {
  width: 4px;
}

.move-log-list::-webkit-scrollbar-track {
  background: transparent;
}

.move-log-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.move-entry {
  display: grid;
  grid-template-columns: 24px 1fr 1fr;
  gap: 4px;
  font-size: 12px;
  font-family: 'Roboto Mono', monospace;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.15s;
}

.move-entry:hover {
  background: rgba(235, 236, 208, 0.05);
}

.move-num {
  color: var(--text-secondary);
  font-weight: 500;
}

.move-white {
  color: var(--light);
}

.move-dark {
  color: var(--grey);
}

/* ===== CHESS BOARD ===== */
.board-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  user-select: none;
}

.board-with-coords {
  display: flex;
  gap: 0;
}

.rank-labels {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  padding: 0 8px 0 0;
  height: calc(var(--tile-size) * 10);
}

.rank-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  width: 14px;
  text-align: center;
  line-height: var(--tile-size);
  height: var(--tile-size);
}

.file-labels {
  display: flex;
  justify-content: space-around;
  width: calc(var(--tile-size) * 6);
  padding: 6px 0 0 0;
  margin-left: 22px;
}

.file-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  width: var(--tile-size);
  text-align: center;
}

#chess-board {
  width: calc(var(--tile-size) * 6);
  height: calc(var(--tile-size) * 10);
  display: grid;
  grid-template-columns: repeat(6, var(--tile-size));
  grid-template-rows: repeat(10, var(--tile-size));
  border: var(--board-border) solid var(--dark);
  border-radius: 4px;
  box-shadow:
    0 0 0 1px rgba(235, 236, 208, 0.1),
    0 20px 60px rgba(0, 0, 0, 0.6),
    0 0 40px rgba(115, 149, 82, 0.08);
  overflow: hidden;
  forced-color-adjust: none;
}

/* ===== TILES ===== */
.tile {
  width: var(--tile-size);
  height: var(--tile-size);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: filter 0.15s ease;
}

.tile.light {
  background-color: var(--tile-light);
}

.tile.dark-tile {
  background-color: var(--tile-dark);
}

.tile:hover {
  filter: brightness(1.08);
}

/* ===== PIECE HIGHLIGHTING (PHASE 3: CIRCULAR INSET) ===== */
.tile.selected {
  box-shadow: inset 0 0 0 4px var(--blue-light);
}

/* Intermediate position (after Action 1, before Action 2) */
.tile.step1-pos {
  box-shadow: inset 0 0 0 3px var(--orange);
  animation: step1-pulse 0.8s ease-in-out infinite;
}

@keyframes step1-pulse {

  0%,
  100% {
    box-shadow: inset 0 0 0 3px var(--orange), 0 0 0 0 rgba(243, 141, 31, 0);
  }

  50% {
    box-shadow: inset 0 0 0 3px var(--orange), 0 0 8px 2px rgba(243, 141, 31, 0.45);
  }
}

.tile.avail-1::after,
.tile.avail-2::after,
.tile.avail-cap::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  z-index: 4;
  pointer-events: none;
}

/* Action 1 (Blue Aura) */
.tile.avail-1::after {
  width: 28%;
  height: 28%;
  background: var(--blue-light);
  box-shadow: 0 0 15px var(--blue-light);
  opacity: 0.9;
}

/* Action 2 (Orange Aura) */
.tile.avail-2::after {
  width: 25%;
  height: 25%;
  background: var(--orange);
  box-shadow: 0 0 12px var(--orange);
  opacity: 0.8;
}

/* Captures (Green Aura) */
.tile.avail-cap::after {
  width: 38%;
  height: 38%;
  border: 4px solid var(--green-accent);
  background: rgba(119, 149, 82, 0.2);
  box-shadow: 0 0 10px var(--green-accent);
}

.unselect-btn {
  position: absolute;
  top: -42px;
  right: 0;
  background: var(--blue-dark);
  color: white;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  display: none;
  z-index: 10;
  border: 1px solid var(--blue-light);
  transition: all 0.2s;
}

.unselect-btn.active {
  display: block;
}

.unselect-btn:hover {
  background: var(--blue);
  transform: translateY(-1px);
}

/* LAST MOVE highlights */
/* Ensure piece sits above aura overlays */
.piece-img {
  z-index: 5;
}

.tile.last-move {
  background-color: rgba(246, 246, 105, 0.4) !important;
}

/* ===== PIECES ===== */
.piece-img {
  width: 82%;
  height: 82%;
  position: relative;
  z-index: 3;
  pointer-events: none;
  transition: transform 0.1s ease;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.5));
  forced-color-adjust: none;
}

.tile:hover .piece-img {
  transform: scale(1.06);
}

.tile.selected .piece-img {
  transform: scale(1.12);
}

/* ===== ACTION INDICATOR on board ===== */
.action-indicator-bar {
  display: flex;
  gap: 6px;
  margin: 10px 0 4px;
}

.action-pip {
  width: 32px;
  height: 6px;
  border-radius: 3px;
  background: var(--border);
  transition: background 0.3s ease;
}

.action-pip.active {
  background: var(--green);
  box-shadow: 0 0 8px rgba(115, 149, 82, 0.5);
}

/* ===== MULTIPLAYER PANEL ===== */
.mp-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: rgba(115, 149, 82, 0.1);
  border: 1px solid rgba(115, 149, 82, 0.2);
  border-radius: 8px;
  font-size: 13px;
  color: var(--green-light);
}

.mp-badge .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  animation: blink 1.5s ease-in-out infinite;
}

@keyframes blink {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.3;
  }
}

.room-id-display {
  font-family: 'Roboto Mono', monospace;
  font-size: 22px;
  font-weight: 700;
  color: var(--green);
  letter-spacing: 6px;
  text-align: center;
  padding: 8px 0;
}

.room-input {
  width: 100%;
  background: var(--bg-main);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text-primary);
  font-family: 'Roboto Mono', monospace;
  font-size: 16px;
  letter-spacing: 4px;
  text-align: center;
  outline: none;
  transition: border-color 0.2s;
  text-transform: uppercase;
}

.room-input:focus {
  border-color: var(--green);
}

.room-input::placeholder {
  letter-spacing: 2px;
  color: var(--text-secondary);
  font-size: 12px;
  text-transform: none;
}

/* ===== MODALS ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

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

.modal {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 36px 40px;
  text-align: center;
  max-width: 420px;
  width: 90%;
  transform: scale(0.9);
  transition: transform 0.3s ease;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}

.modal-overlay.active .modal {
  transform: scale(1);
}

.modal-title {
  font-size: 28px;
  font-weight: 800;
  color: var(--green);
  margin-bottom: 8px;
}

.modal-sub {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 24px;
}

.modal-pieces {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-bottom: 28px;
}

.modal-piece-btn {
  width: 72px;
  height: 72px;
  padding: 6px;
  border-radius: 12px;
  background: var(--bg-card);
  border: 2px solid var(--border);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-piece-btn:hover {
  border-color: var(--green);
  background: rgba(115, 149, 82, 0.12);
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(115, 149, 82, 0.2);
}

.modal-piece-btn img {
  width: 52px;
  height: 52px;
}

/* ===== GAME OVER ===== */
.gameover-trophy {
  font-size: 64px;
  margin-bottom: 12px;
}

.gameover-title {
  font-size: 36px;
  font-weight: 900;
  background: linear-gradient(135deg, var(--green), var(--green-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 6px;
}

.gameover-sub {
  color: var(--text-secondary);
  font-size: 16px;
  margin-bottom: 28px;
}

/* ===== START SCREEN ===== */
.start-screen {
  position: fixed;
  inset: 0;
  background: var(--bg-main);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 999;
  transition: opacity 0.5s ease;
}

.start-screen.hidden {
  opacity: 0;
  pointer-events: none;
}

.start-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 48px 52px;
  max-width: 480px;
  width: 90%;
  text-align: center;
  box-shadow: 0 40px 100px rgba(0, 0, 0, 0.5);
}

.start-logo svg {
  width: 64px;
  height: 64px;
  margin-bottom: 20px;
}

.start-title {
  font-size: 42px;
  font-weight: 900;
  color: var(--green);
  letter-spacing: -1px;
  margin-bottom: 4px;
}

.start-subtitle {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 3px;
  text-transform: uppercase;
  margin-bottom: 36px;
}

.start-divider {
  height: 1px;
  background: var(--border);
  margin: 24px 0;
  position: relative;
}

.start-divider::after {
  content: 'or';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg-panel);
  padding: 0 12px;
  color: var(--text-secondary);
  font-size: 12px;
}

.start-mode-btns {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ===== STATUS FLASH ===== */
.status-flash {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 30px;
  padding: 10px 20px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  z-index: 500;
  opacity: 0;
  transition: all 0.3s ease;
  pointer-events: none;
  white-space: nowrap;
}

.status-flash.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== RULES SECTION ===== */
.rules-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.rules-pill.rook {
  background: rgba(239, 68, 68, 0.12);
  color: #f87171;
}

.rules-pill.double {
  background: rgba(115, 149, 82, 0.12);
  color: var(--green-light);
}

.rules-pill.king {
  background: rgba(234, 179, 8, 0.12);
  color: #facc15;
}

.rule-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
  padding: 6px 0;
  border-bottom: 1px solid rgba(235, 236, 208, 0.05);
}

.rule-item:last-child {
  border-bottom: none;
}

.rule-icon {
  font-size: 14px;
  flex-shrink: 0;
  line-height: 1.5;
}

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

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

::-webkit-scrollbar-thumb {
  background: rgba(235, 236, 208, 0.1);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(235, 236, 208, 0.2);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1000px) {
  :root {
    --tile-size: 9.5vw;
  }

  .rank-labels,
  .file-labels {
    display: none;
    /* Hide coords on mobile to save space */
  }
}

@media (max-width: 620px) {
  :root {
    --tile-size: 15vw;
    /* Larger tiles on very small screens */
  }

  .start-card {
    padding: 30px 24px;
  }

  .start-title {
    font-size: 32px;
  }
}

/* Matchmaking Modal */
.matchmaking-modal {
  max-width: 420px;
}

.mm-options {
  margin: 20px 0;
}

.btn-lg {
  padding: 16px;
  font-size: 16px;
  background: linear-gradient(135deg, var(--blue-light), var(--blue-dark));
  box-shadow: 0 4px 15px rgba(75, 115, 153, 0.4);
}

/* Searching Spinner */
.searching-spinner {
  width: 80px;
  height: 80px;
  margin: 20px auto;
  border-radius: 50%;
  position: relative;
}

.searching-spinner::after,
.searching-spinner::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border: 4px solid var(--blue-light);
  border-radius: 50%;
  animation: mm-pulse 2s linear infinite;
}

.searching-spinner::before {
  animation-delay: 1s;
}

@keyframes mm-pulse {
  0% {
    transform: scale(0.5);
    opacity: 0;
  }

  50% {
    opacity: 0.5;
  }

  100% {
    transform: scale(1.5);
    opacity: 0;
  }
}