/* ============================================================
   AI CHESS MASTER — Stylesheet
   Cross-browser compatible with CSS3 prefixes.
   ============================================================ */

/* ----- RESET & BASE ----- */
*, *::before, *::after {
  box-sizing: border-box;
  -webkit-box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

body {
  font-family: Georgia, 'Times New Roman', Times, serif;
  background: #1a1a2e;
  color: #eee;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ----- MENU SCREEN ----- */
#menu-screen {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
  min-height: 100vh;
  background: radial-gradient(ellipse at center, #1a1a2e 0%, #0d0d1a 100%);
}

.menu-container {
  text-align: center;
  max-width: 400px;
  width: 90%;
  padding: 40px 20px;
}

.menu-title {
  font-size: clamp(28px, 6vw, 42px);
  font-weight: 700;
  color: #f0c040;
  letter-spacing: 3px;
  text-shadow: 0 0 30px rgba(240, 192, 64, 0.3);
  margin-bottom: 8px;
}

.menu-subtitle {
  font-size: 14px;
  color: #888;
  margin-bottom: 40px;
}

.menu-buttons {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -ms-flex-direction: column;
  flex-direction: column;
  gap: 12px;
}

.menu-btn {
  padding: 14px 24px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: clamp(14px, 3vw, 16px);
  font-weight: 600;
  -webkit-transition: all 0.2s ease;
  -o-transition: all 0.2s ease;
  transition: all 0.2s ease;
  letter-spacing: 1px;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  font-family: inherit;
}

.menu-btn-primary {
  background: #f0c040;
  color: #1a1a2e;
}

.menu-btn-primary:hover {
  background: #e6b830;
  -webkit-transform: translateY(-2px);
  -ms-transform: translateY(-2px);
  transform: translateY(-2px);
  -webkit-box-shadow: 0 6px 20px rgba(240, 192, 64, 0.3);
  box-shadow: 0 6px 20px rgba(240, 192, 64, 0.3);
}

.menu-btn-secondary {
  background: transparent;
  color: #ccc;
  border: 1px solid #0f3460;
}

.menu-btn-secondary:hover {
  border-color: #f0c040;
  color: #f0c040;
  -webkit-transform: translateY(-2px);
  -ms-transform: translateY(-2px);
  transform: translateY(-2px);
}

.menu-footer {
  margin-top: 40px;
}

/* ----- MUSIC BUTTON ----- */
.music-btn {
  background: rgba(240, 192, 64, 0.1);
  border: 1px solid rgba(240, 192, 64, 0.3);
  color: #f0c040;
  padding: 8px 18px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  -webkit-transition: all 0.2s;
  -o-transition: all 0.2s;
  transition: all 0.2s;
  font-family: inherit;
}

.music-btn:hover {
  background: rgba(240, 192, 64, 0.2);
}

.music-btn.off {
  color: #666;
  border-color: #333;
  background: transparent;
}

/* ----- OVERLAY SCREENS (How to Play, Achievements, Stats) ----- */
.overlay-screen {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
  min-height: 100vh;
  background: radial-gradient(ellipse at center, #1a1a2e 0%, #0d0d1a 100%);
  padding: 20px;
}

.overlay-container {
  max-width: 600px;
  width: 100%;
  background: #16213e;
  border-radius: 16px;
  border: 1px solid #0f3460;
  padding: clamp(16px, 4vw, 30px);
  max-height: 90vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.overlay-header {
  font-size: clamp(20px, 4vw, 26px);
  font-weight: 700;
  color: #f0c040;
  text-align: center;
  margin-bottom: 20px;
  letter-spacing: 2px;
}

.overlay-body {
  font-size: clamp(13px, 2.5vw, 14px);
  line-height: 1.8;
  color: #ccc;
}

.overlay-body h3 {
  color: #f0c040;
  font-size: 15px;
  margin: 16px 0 6px;
}

.overlay-body p {
  margin: 4px 0 8px;
}

.overlay-back {
  margin-top: 20px;
  width: 100%;
}

/* Scrollbar styling */
.overlay-container::-webkit-scrollbar {
  width: 4px;
}
.overlay-container::-webkit-scrollbar-track {
  background: #0d1b2a;
  border-radius: 2px;
}
.overlay-container::-webkit-scrollbar-thumb {
  background: #f0c040;
  border-radius: 2px;
}

/* ----- HEADER CONTROLS ----- */
.header {
  text-align: center;
  padding: 10px 0 12px;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
  gap: 8px;
  -ms-flex-wrap: wrap;
  flex-wrap: wrap;
}

.header h1 {
  font-size: clamp(18px, 3.5vw, 24px);
  font-weight: 700;
  color: #f0c040;
  letter-spacing: 2px;
  text-shadow: 0 0 20px rgba(240, 192, 64, 0.4);
}

.header-controls {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  gap: 6px;
  margin-left: auto;
}

.header-btn {
  background: transparent;
  border: 1px solid #0f3460;
  color: #aaa;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  -webkit-transition: all 0.2s;
  -o-transition: all 0.2s;
  transition: all 0.2s;
  font-family: inherit;
}

.header-btn:hover {
  border-color: #f0c040;
  color: #f0c040;
}

/* ----- ACHIEVEMENT CARDS ----- */
.achievement-card {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  background: #0d1b2a;
  border-radius: 8px;
  margin-bottom: 8px;
  border: 1px solid #0f3460;
  -webkit-transition: all 0.2s;
  -o-transition: all 0.2s;
  transition: all 0.2s;
}

.achievement-card.unlocked {
  border-color: #f0c040;
}

.achievement-card.locked {
  opacity: 0.45;
}

.achievement-icon {
  font-size: 28px;
  width: 44px;
  height: 44px;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
  border-radius: 50%;
  background: #1a1a2e;
  border: 2px solid #0f3460;
  -ms-flex-negative: 0;
  flex-shrink: 0;
}

.achievement-card.unlocked .achievement-icon {
  border-color: #f0c040;
  background: rgba(240, 192, 64, 0.1);
}

.achievement-info {
  -webkit-box-flex: 1;
  -ms-flex: 1;
  flex: 1;
}

.achievement-name {
  font-size: 14px;
  font-weight: 600;
  color: #eee;
}

.achievement-desc {
  font-size: 11px;
  color: #888;
  margin-top: 2px;
}

.achievement-status {
  font-size: 11px;
  color: #f0c040;
  font-weight: 600;
}

/* ----- STATISTICS ROWS ----- */
.stat-row {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-pack: justify;
  -ms-flex-pack: justify;
  justify-content: space-between;
  padding: 10px 14px;
  background: #0d1b2a;
  border-radius: 6px;
  margin-bottom: 6px;
  border: 1px solid #0f3460;
}

.stat-label {
  font-size: 13px;
  color: #aaa;
}

.stat-value {
  font-size: 15px;
  font-weight: 700;
  color: #f0c040;
}

/* ----- AD PLACEHOLDERS ----- */
.ad-banner {
  width: 100%;
  max-width: 728px;
  margin: 0 auto;
  text-align: center;
}

.ad-placeholder {
  background: #0d1b2a;
  border: 1px dashed #0f3460;
  color: #555;
  font-size: 11px;
  padding: 15px;
  text-align: center;
  border-radius: 4px;
}

.ad-placeholder-full {
  padding: 100px 20px;
  font-size: 16px;
}

.ad-interstitial {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  z-index: 2000;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -ms-flex-direction: column;
  flex-direction: column;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
  gap: 16px;
}

.ad-close-btn {
  background: #f0c040;
  color: #1a1a2e;
  border: none;
  padding: 10px 30px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

/* ----- MAIN GAME LAYOUT ----- */
#app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 8px 12px 16px;
}

.main-layout {
  display: -ms-grid;
  display: grid;
  -ms-grid-columns: 1fr 16px 260px;
  grid-template-columns: 1fr 260px;
  gap: 16px;
}

.board-section {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -ms-flex-direction: column;
  flex-direction: column;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  gap: 10px;
}

/* ----- PLAYER INFO BARS ----- */
.player-info {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 480px;
  padding: 8px 12px;
  background: #16213e;
  border-radius: 8px;
  border: 1px solid #0f3460;
}

.player-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  -ms-flex-negative: 0;
  flex-shrink: 0;
}

.player-avatar.ai {
  background: -webkit-linear-gradient(135deg, #e74c3c, #c0392b);
  background: -o-linear-gradient(135deg, #e74c3c, #c0392b);
  background: linear-gradient(135deg, #e74c3c, #c0392b);
}

.player-avatar.human {
  background: -webkit-linear-gradient(135deg, #3498db, #2980b9);
  background: -o-linear-gradient(135deg, #3498db, #2980b9);
  background: linear-gradient(135deg, #3498db, #2980b9);
}

.player-name {
  font-size: clamp(12px, 2vw, 14px);
  font-weight: 600;
  white-space: nowrap;
}

.player-level {
  font-size: clamp(10px, 1.5vw, 11px);
  color: #aaa;
}

.player-clock {
  margin-left: auto;
  font-size: clamp(16px, 3vw, 20px);
  font-weight: 700;
  font-family: 'Courier New', Courier, monospace;
  color: #f0c040;
  -ms-flex-negative: 0;
  flex-shrink: 0;
}

.active-player {
  border-color: #f0c040;
  -webkit-box-shadow: 0 0 10px rgba(240, 192, 64, 0.2);
  box-shadow: 0 0 10px rgba(240, 192, 64, 0.2);
}

/* ----- CHESS BOARD ----- */
.board-wrapper {
  position: relative;
  width: 100%;
  max-width: 480px;
}

#chessboard {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: -ms-grid;
  display: grid;
  -ms-grid-columns: (1fr)[8];
  grid-template-columns: repeat(8, 1fr);
  border: 2px solid #f0c040;
  -webkit-box-shadow: 0 0 30px rgba(0, 0, 0, 0.5), inset 0 0 0 1px rgba(240, 192, 64, 0.1);
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.5), inset 0 0 0 1px rgba(240, 192, 64, 0.1);
  border-radius: 2px;
  overflow: hidden;
}

/* Coordinate labels on board squares */
.square[data-file]::before {
  content: attr(data-file);
  position: absolute;
  bottom: 1px;
  right: 3px;
  font-size: 10px;
  font-weight: 700;
  color: rgba(0,0,0,0.45);
  pointer-events: none;
  line-height: 1;
}

.square[data-rank]::before {
  content: attr(data-rank);
  position: absolute;
  top: 1px;
  left: 3px;
  font-size: 10px;
  font-weight: 700;
  color: rgba(0,0,0,0.45);
  pointer-events: none;
  line-height: 1;
}

.square {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  -webkit-transition: background 0.15s ease;
  -o-transition: background 0.15s ease;
  transition: background 0.15s ease;
  aspect-ratio: 1 / 1;
}

.square.light { background: #f0d9b5; }
.square.dark { background: #b58863; }
.square.selected { background: rgba(20, 200, 20, 0.5) !important; }

.square.valid-move::after {
  content: '';
  position: absolute;
  width: 40%;
  height: 40%;
  border-radius: 50%;
  background: rgba(20, 20, 20, 0.25);
  pointer-events: none;
}

.square.valid-capture::after {
  content: '';
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  border: 4px solid rgba(20, 20, 20, 0.35);
  pointer-events: none;
}

.square.last-move { background: rgba(170, 162, 58, 0.45) !important; }
.square.in-check { background: rgba(220, 30, 30, 0.6) !important; }

/* ----- PIECES ----- */
.piece {
  font-size: clamp(28px, 7vw, 46px);
  line-height: 1;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  cursor: pointer;
  -webkit-transition: -webkit-transform 0.1s ease;
  -o-transition: transform 0.1s ease;
  transition: transform 0.1s ease;
  transition: transform 0.1s ease, -webkit-transform 0.1s ease;
  pointer-events: none;
  z-index: 1;
}

.piece-white {
  color: #fff;
  text-shadow: 0 0 2px #000, 0 0 0 #000, 1px 1px 2px rgba(0, 0, 0, 0.6);
}

.piece-black {
  color: #1a1a1a;
  text-shadow: 0 0 2px #999, 0 0 0 #000, 1px 1px 2px rgba(0, 0, 0, 0.2);
}

.piece:hover {
  -webkit-transform: scale(1.1);
  -ms-transform: scale(1.1);
  transform: scale(1.1);
}

/* ----- RIGHT SIDE PANEL ----- */
.right-panel {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -ms-flex-direction: column;
  flex-direction: column;
  gap: 8px;
}

.panel-card {
  background: #16213e;
  border-radius: 10px;
  border: 1px solid #0f3460;
  padding: 12px;
}

.panel-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #f0c040;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.difficulty-grid {
  display: -ms-grid;
  display: grid;
  -ms-grid-columns: 1fr 5px 1fr;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
}

.diff-btn {
  padding: 7px 4px;
  border-radius: 6px;
  border: 1px solid #0f3460;
  background: #0d1b2a;
  color: #ccc;
  font-size: 11px;
  cursor: pointer;
  text-align: center;
  -webkit-transition: all 0.2s;
  -o-transition: all 0.2s;
  transition: all 0.2s;
  font-family: inherit;
}

.diff-btn:hover {
  border-color: #f0c040;
  color: #f0c040;
}

.diff-btn.active {
  background: #f0c040;
  color: #1a1a2e;
  border-color: #f0c040;
  font-weight: 700;
}

.analysis-box {
  background: #0d1b2a;
  border-radius: 6px;
  padding: 8px;
  min-height: 60px;
  font-size: 12px;
  line-height: 1.6;
  color: #ccc;
  border-left: 3px solid #f0c040;
}

.analysis-loading {
  color: #666;
  font-style: italic;
}

.moves-list {
  max-height: 140px;
  overflow-y: auto;
  font-size: 12px;
}

.moves-list::-webkit-scrollbar { width: 4px; }
.moves-list::-webkit-scrollbar-track { background: #0d1b2a; }
.moves-list::-webkit-scrollbar-thumb { background: #f0c040; border-radius: 2px; }

.move-row {
  display: -ms-grid;
  display: grid;
  -ms-grid-columns: 24px 3px 1fr 3px 1fr;
  grid-template-columns: 24px 1fr 1fr;
  gap: 3px;
  padding: 2px 4px;
  border-radius: 3px;
}

.move-row:hover { background: #0d1b2a; }
.move-num { color: #666; }
.move-white, .move-black { cursor: pointer; color: #ddd; }

.eval-bar-wrap {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.eval-bar {
  -webkit-box-flex: 1;
  -ms-flex: 1;
  flex: 1;
  height: 6px;
  background: #333;
  border-radius: 4px;
  overflow: hidden;
}

.eval-fill {
  height: 100%;
  background: #f0c040;
  border-radius: 4px;
  -webkit-transition: width 0.5s ease;
  -o-transition: width 0.5s ease;
  transition: width 0.5s ease;
}

.eval-score {
  font-size: 12px;
  font-family: 'Courier New', Courier, monospace;
  color: #f0c040;
  min-width: 40px;
  text-align: right;
}

/* ----- BUTTONS ----- */
.btn {
  padding: 8px 14px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  -webkit-transition: all 0.2s;
  -o-transition: all 0.2s;
  transition: all 0.2s;
  font-family: inherit;
}

.btn-primary {
  background: #f0c040;
  color: #1a1a2e;
  width: 100%;
  margin-top: 4px;
}

.btn-primary:hover {
  background: #e6b830;
  -webkit-transform: translateY(-1px);
  -ms-transform: translateY(-1px);
  transform: translateY(-1px);
}

.btn-secondary {
  background: transparent;
  color: #aaa;
  border: 1px solid #0f3460;
  width: 100%;
}

.btn-secondary:hover {
  border-color: #f0c040;
  color: #f0c040;
}

/* ----- STATUS BAR ----- */
.status-bar {
  text-align: center;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: clamp(12px, 2vw, 13px);
  font-weight: 600;
  width: 100%;
  max-width: 480px;
}

.status-playing { background: rgba(52, 152, 219, 0.15); color: #3498db; border: 1px solid rgba(52, 152, 219, 0.3); }
.status-ai { background: rgba(231, 76, 60, 0.15); color: #e74c3c; border: 1px solid rgba(231, 76, 60, 0.3); }
.status-check { background: rgba(231, 76, 60, 0.25); color: #ff6b6b; border: 1px solid rgba(231, 76, 60, 0.5); }
.status-end { background: rgba(240, 192, 64, 0.15); color: #f0c040; border: 1px solid rgba(240, 192, 64, 0.3); }

/* ----- CAPTURED PIECES ----- */
.capture-pieces {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -ms-flex-wrap: wrap;
  flex-wrap: wrap;
  gap: 2px;
  min-height: 24px;
}

.cap-piece { font-size: clamp(14px, 2.5vw, 18px); }

.hint-btn {
  display: block;
  width: 100%;
  padding: 6px;
  background: rgba(240, 192, 64, 0.1);
  border: 1px solid rgba(240, 192, 64, 0.3);
  border-radius: 6px;
  color: #f0c040;
  font-size: 11px;
  cursor: pointer;
  -webkit-transition: all 0.2s;
  -o-transition: all 0.2s;
  transition: all 0.2s;
  font-family: inherit;
}

.hint-btn:hover { background: rgba(240, 192, 64, 0.2); }

.promo-btn:hover {
  border-color: #f0c040 !important;
  background: #1a1a2e !important;
  -webkit-transform: scale(1.1);
  -ms-transform: scale(1.1);
  transform: scale(1.1);
}

/* ============================================================
   RESPONSIVE DESIGN — Mobile, Tablet, Desktop
   ============================================================ */

/* --- Tablet & Small Desktop --- */
@media (max-width: 860px) {
  .main-layout {
    -ms-grid-columns: 1fr;
    grid-template-columns: 1fr;
  }

  .right-panel {
    display: -ms-grid;
    display: grid;
    -ms-grid-columns: 1fr 8px 1fr;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .header h1 { font-size: 18px; }
}

/* --- Mobile --- */
@media (max-width: 520px) {
  #app { padding: 4px 6px 12px; }

  .right-panel {
    -ms-grid-columns: 1fr;
    grid-template-columns: 1fr;
  }

  .player-info {
    padding: 6px 8px;
    gap: 6px;
  }

  .player-avatar { width: 28px; height: 28px; font-size: 11px; }

  .capture-pieces { display: none; }

  .header {
    -webkit-box-pack: justify;
    -ms-flex-pack: justify;
    justify-content: space-between;
  }

  .header-controls { margin-left: 0; }

  .status-bar { font-size: 11px; padding: 5px 8px; }
}

/* --- Very Small Screens --- */
@media (max-width: 360px) {
  .menu-container { padding: 20px 10px; }
  .menu-btn { padding: 12px 16px; font-size: 13px; }

  .overlay-container { padding: 12px; }

  .player-clock { font-size: 14px; }
  .player-name { font-size: 11px; }
}

/* ----- Touch-friendly: larger tap targets on mobile ----- */
@media (pointer: coarse) {
  .square { min-height: 44px; }
  .menu-btn { min-height: 48px; }
  .btn { min-height: 40px; }
  .diff-btn { min-height: 36px; }
  .hint-btn { min-height: 36px; }
}
