/* ==========================================
   Damas Online - Styles
   ========================================== */

:root {
  /* Colors */
  --bg-dark: #1a1a2e;
  --bg-medium: #16213e;
  --bg-light: #0f3460;
  --accent: #e94560;
  --accent-hover: #ff6b6b;
  --text-primary: #ffffff;
  --text-secondary: #a0a0a0;
  --success: #4ecdc4;
  --warning: #f7d354;

  /* Board colors */
  --board-light: #f0d9b5;
  --board-dark: #b58863;
  --board-highlight: rgba(255, 255, 0, 0.4);
  --board-selected: rgba(0, 255, 0, 0.4);
  --board-legal-move: rgba(0, 255, 0, 0.3);

  /* Piece colors */
  --piece-red: #c0392b;
  --piece-red-king: #e74c3c;
  --piece-black: #2c3e50;
  --piece-black-king: #34495e;

  /* Spacing */
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 16px;
  --spacing-lg: 24px;
  --spacing-xl: 32px;

  /* Border radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 16px;
  --radius-round: 50%;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: linear-gradient(135deg, var(--bg-dark) 0%, var(--bg-medium) 100%);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

#app {
  width: 100%;
  max-width: 500px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ==========================================
   Screens
   ========================================== */

.screen {
  display: none;
  flex-direction: column;
  align-items: center;
  padding: var(--spacing-lg);
  flex: 1;
}

.screen.active {
  display: flex;
}

/* ==========================================
   Header
   ========================================== */

header {
  text-align: center;
  margin-bottom: var(--spacing-lg);
}

h1 {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--text-primary);
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

h2 {
  font-size: 1.5rem;
  font-weight: 600;
}

.subtitle {
  color: var(--text-secondary);
  margin-top: var(--spacing-xs);
}

/* ==========================================
   Buttons
   ========================================== */

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-sm);
  padding: var(--spacing-md) var(--spacing-xl);
  border: none;
  border-radius: var(--radius-md);
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 200px;
}

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

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(233, 69, 96, 0.4);
}

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

.btn-secondary:hover {
  background: var(--bg-medium);
  border-color: var(--text-primary);
}

.btn-small {
  padding: var(--spacing-sm) var(--spacing-md);
  min-width: auto;
  font-size: 0.9rem;
}

.btn-icon {
  font-size: 1.2rem;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-md);
  margin: var(--spacing-lg) 0;
}

/* ==========================================
   Ads
   ========================================== */

.ad-container {
  width: 100%;
  min-height: 100px;
  background: var(--bg-medium);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: var(--spacing-md) 0;
  overflow: hidden;
}

.ad-container ins {
  width: 100%;
}

.ad-home, .ad-lobby, .ad-invite, .ad-result {
  max-width: 100%;
}

.ad-game {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  border-radius: 0;
  margin: 0;
  min-height: 60px;
}

/* ==========================================
   Invite Section
   ========================================== */

.join-invite-section {
  margin-top: var(--spacing-xl);
  text-align: center;
}

.join-invite-section p {
  color: var(--text-secondary);
  margin-bottom: var(--spacing-sm);
}

.invite-input-group {
  display: flex;
  gap: var(--spacing-sm);
}

.invite-input-group input {
  flex: 1;
  padding: var(--spacing-sm) var(--spacing-md);
  border: 1px solid var(--text-secondary);
  border-radius: var(--radius-md);
  background: var(--bg-medium);
  color: var(--text-primary);
  font-size: 1rem;
}

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

/* ==========================================
   Lobby
   ========================================== */

.lobby-content {
  text-align: center;
  padding: var(--spacing-xl);
}

.loading-spinner {
  width: 50px;
  height: 50px;
  border: 4px solid var(--bg-light);
  border-top-color: var(--accent);
  border-radius: var(--radius-round);
  animation: spin 1s linear infinite;
  margin: var(--spacing-lg) auto;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.lobby-hint {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-top: var(--spacing-md);
}

/* ==========================================
   Invite Screen
   ========================================== */

.invite-content {
  text-align: center;
  width: 100%;
}

.invite-link-box {
  display: flex;
  gap: var(--spacing-sm);
  margin: var(--spacing-md) 0;
}

.invite-link-box input {
  flex: 1;
  padding: var(--spacing-sm) var(--spacing-md);
  border: 1px solid var(--text-secondary);
  border-radius: var(--radius-md);
  background: var(--bg-medium);
  color: var(--text-primary);
  font-size: 0.9rem;
}

.invite-hint {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* ==========================================
   Game Board
   ========================================== */

.game-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  padding-bottom: 80px; /* Space for ad */
}

#board-container {
  padding: var(--spacing-sm);
  background: var(--board-dark);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

#board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: min(90vw, 400px);
  height: min(90vw, 400px);
}

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

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

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

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

.square.legal-move {
  cursor: pointer;
}

.square.legal-move::after {
  content: '';
  width: 30%;
  height: 30%;
  background: var(--board-legal-move);
  border-radius: var(--radius-round);
}

.square.legal-capture::after {
  width: 80%;
  height: 80%;
  background: rgba(255, 0, 0, 0.3);
  border: 3px solid rgba(255, 0, 0, 0.6);
}

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

/* ==========================================
   Pieces
   ========================================== */

.piece {
  width: 80%;
  height: 80%;
  border-radius: var(--radius-round);
  cursor: pointer;
  transition: transform 0.1s ease;
  position: relative;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

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

.piece-red {
  background: radial-gradient(circle at 30% 30%, var(--piece-red-king), var(--piece-red));
  border: 3px solid #922b21;
}

.piece-black {
  background: radial-gradient(circle at 30% 30%, var(--piece-black-king), var(--piece-black));
  border: 3px solid #1a252f;
}

.piece.king::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 50%;
  height: 50%;
  border-radius: 50%;
  background: radial-gradient(circle, gold 0%, #daa520 50%, transparent 70%);
  box-shadow: 0 0 8px gold, inset 0 0 4px rgba(255, 215, 0, 0.8);
}

.piece.king::after {
  content: '👑';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.2rem;
}

.piece.disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

.piece.animating {
  position: absolute;
  z-index: 10;
  transition: transform 0.25s ease-in-out;
}

.piece.captured {
  animation: captureAnim 0.3s ease-out forwards;
}

@keyframes captureAnim {
  0% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.2); opacity: 0.5; }
  100% { transform: scale(0); opacity: 0; }
}

/* ==========================================
   Player Info
   ========================================== */

.game-header {
  width: 100%;
  margin-bottom: var(--spacing-sm);
}

.player-info {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  padding: var(--spacing-sm) var(--spacing-md);
  background: var(--bg-medium);
  border-radius: var(--radius-md);
}

.player-top {
  justify-content: flex-start;
}

.player-bottom {
  justify-content: flex-end;
  margin-top: var(--spacing-sm);
}

.turn-indicator {
  width: 12px;
  height: 12px;
  border-radius: var(--radius-round);
  background: var(--text-secondary);
  transition: background 0.3s ease;
}

.turn-indicator.active {
  background: var(--success);
  animation: pulse 1s infinite;
}

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

.player-pieces {
  display: flex;
  gap: 2px;
}

.captured-piece {
  width: 16px;
  height: 16px;
  border-radius: var(--radius-round);
}

.captured-red {
  background: var(--piece-red);
}

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

.game-status {
  text-align: center;
  padding: var(--spacing-sm);
  font-weight: 600;
  color: var(--success);
  min-height: 2rem;
}

/* ==========================================
   Result Screen
   ========================================== */

.result-content {
  text-align: center;
  padding: var(--spacing-xl);
}

.result-icon {
  font-size: 5rem;
  margin-bottom: var(--spacing-md);
  line-height: 1;
}

.result-buttons {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-md);
}

/* ==========================================
   Modal
   ========================================== */

.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--bg-medium);
  padding: var(--spacing-xl);
  border-radius: var(--radius-lg);
  text-align: center;
  max-width: 90%;
  width: 300px;
}

.modal-content h3 {
  margin-bottom: var(--spacing-md);
  color: var(--accent);
}

.modal-content p {
  margin-bottom: var(--spacing-lg);
  color: var(--text-secondary);
}

/* ==========================================
   Footer
   ========================================== */

.home-footer {
  margin-top: auto;
  text-align: center;
  padding: var(--spacing-md);
}

.home-footer p {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* ==========================================
   Responsive
   ========================================== */

@media (max-width: 400px) {
  h1 {
    font-size: 2rem;
  }

  .btn {
    min-width: 180px;
    padding: var(--spacing-sm) var(--spacing-lg);
  }

  #board {
    width: 95vw;
    height: 95vw;
  }

  .piece.king::after {
    font-size: 1rem;
  }
}

@media (min-height: 800px) {
  .ad-container {
    min-height: 120px;
  }
}
