/* ============================================================
   CHESS ROYALE — Stylesheet (Actualizado)
   ============================================================ */

:root {
  --gold:       #c9a84c;
  --gold-light: #e8c97a;
  --gold-dim:   #7a6230;
  --dark:       #0d0d0f;
  --dark2:      #141418;
  --dark3:      #1c1c22;
  --dark4:      #242430;
  --surface:    #1e1e26;
  --surface2:   #28283a;
  --text:       #e8e4d8;
  --text-muted: #888074;
  --sq-light:   #f0d9b5;
  --sq-dark:    #b58863;
  --sq-sel:     rgba(106, 176, 76, 0.7);
  --sq-move:    rgba(106, 176, 76, 0.45);
  --sq-check:   rgba(200, 50, 50, 0.7);
  --sq-last:    rgba(205, 210, 106, 0.5);
  --border-r:   8px;
  --shadow:     0 8px 40px rgba(0,0,0,0.6);
}

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

body {
  font-family: 'Crimson Pro', serif;
  background-color: var(--dark);
  color: var(--text);
  overflow: hidden;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* SCREENS */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
  z-index: 10;
}
.screen.active { opacity: 1; pointer-events: auto; }

/* MENU */
.menu-bg { position: absolute; inset: 0; z-index: 1; }
.menu-particles { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.particle {
  position: absolute; color: var(--gold-dim); opacity: 0.15;
  animation: floatUp linear infinite; pointer-events: none;
}
@keyframes floatUp {
  0% { transform: translateY(0) rotate(0); opacity: 0; }
  10% { opacity: 0.15; }
  90% { opacity: 0.15; }
  100% { transform: translateY(-110vh) rotate(360deg); opacity: 0; }
}

.menu-content { position: relative; z-index: 2; display: flex; flex-direction: column; align-items: center; gap: 40px; }

.logo-wrap { text-align: center; }
.logo-crown { font-size: 3.5rem; color: var(--gold); margin-bottom: 5px; text-shadow: 0 0 20px rgba(201,168,76,0.3); }
.logo-title { font-family: 'Playfair Display', serif; font-size: 4rem; font-weight: 900; letter-spacing: -1px; background: linear-gradient(to bottom, #fff, var(--gold)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.logo-sub { font-size: 1.1rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 4px; font-weight: 300; }

.menu-card { background: var(--surface); padding: 30px; border-radius: 12px; border: 1px solid var(--dark4); width: 340px; box-shadow: var(--shadow); }
.option-group { margin-bottom: 25px; }
.option-label { display: block; color: var(--text-muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 12px; font-weight: 700; }
.toggle-row { display: flex; background: var(--dark2); border-radius: 8px; padding: 4px; }
.toggle-btn { flex: 1; border: none; background: transparent; color: var(--text-muted); padding: 10px; border-radius: 6px; cursor: pointer; font-size: 0.9rem; font-weight: 700; transition: all 0.2s; display: flex; align-items: center; justify-content: center; gap: 8px; }
.toggle-btn.active { background: var(--surface2); color: var(--gold); box-shadow: 0 4px 10px rgba(0,0,0,0.3); }
.toggle-btn:hover:not(.active) { color: var(--text); }

.play-btn { width: 100%; padding: 16px; border: none; border-radius: 8px; background: linear-gradient(135deg, var(--gold), var(--gold-dim)); color: #000; font-weight: 900; font-size: 1.1rem; text-transform: uppercase; letter-spacing: 1px; cursor: pointer; transition: all 0.3s; box-shadow: 0 4px 20px rgba(201,168,76,0.2); }
.play-btn:hover { transform: translateY(-2px); box-shadow: 0 8px 25px rgba(201,168,76,0.4); }

/* GAME SCREEN */
.game-container { display: flex; gap: 40px; align-items: flex-start; }
.board-wrap { position: relative; padding: 12px; background: var(--surface); border-radius: var(--border-r); box-shadow: var(--shadow); border: 1px solid var(--dark4); }
#board { display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); width: 560px; height: 560px; position: relative; border-radius: 4px; overflow: hidden; }

/* Inversión del tablero si el jugador es negras */
#board.inverted { transform: rotate(180deg); }
#board.inverted .piece { transform: rotate(180deg); }

.sq { position: relative; display: flex; justify-content: center; align-items: center; }
.sq.light { background-color: var(--sq-light); }
.sq.dark { background-color: var(--sq-dark); }
.sq.selected { background-color: var(--sq-sel) !important; }
.sq.valid-move::after { content: ''; width: 22px; height: 22px; background: var(--sq-move); border-radius: 50%; }
.sq.valid-capture::after { content: ''; width: 85%; height: 85%; border: 4px solid var(--sq-move); border-radius: 50%; }
.sq.check { background-color: var(--sq-check) !important; }


/* ACTUALIZACIÓN DE PIEZAS */
.piece {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: grab;
  user-select: none;
  transition: transform 0.2s;
  background-size: 85%;
  background-repeat: no-repeat;
  background-position: center;
}
.piece.w { filter: drop-shadow(0 2px 2px rgba(0,0,0,0.3)); }
.piece.b { filter: brightness(0) saturate(100%) invert(12%) sepia(9%) saturate(1500%) hue-rotate(200deg); }
.piece:active { cursor: grabbing; transform: scale(1.15); }

/* SIDE PANEL */
.side-panel { width: 180px; display: flex; flex-direction: column; gap: 20px; }
.player-card { background: var(--surface); border-radius: 10px; padding: 15px; border: 1px solid var(--dark4); }
.player-info { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.player-avatar { width: 32px; height: 32px; background: var(--dark2); border-radius: 6px; display: flex; align-items: center; justify-content: center; font-size: 1.1rem; border: 1px solid var(--dark4); }
.player-name { font-weight: 700; font-size: 0.9rem; }
.player-timer { font-family: 'Playfair Display', serif; font-size: 1.4rem; font-weight: 900; color: var(--gold-light); }
.player-timer.low { color: #f55; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0.4; } }

.captured-box { display: flex; flex-wrap: wrap; gap: 2px; height: 40px; margin-top: 8px; font-size: 1.2rem; line-height: 1; }
.status-card { background: var(--dark3); border-radius: 8px; padding: 12px; border: 1px solid var(--dark4); margin-bottom: 20px; }
.status-label { font-size: 0.7rem; text-transform: uppercase; color: var(--text-muted); margin-bottom: 4px; }
.status-val { font-weight: 700; font-size: 0.85rem; color: var(--gold); }

.game-controls { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.ctrl-btn { border: none; background: var(--surface2); color: var(--text); height: 40px; border-radius: 6px; cursor: pointer; transition: all 0.2s; font-size: 1.1rem; }
.ctrl-btn:hover { background: var(--dark4); color: var(--gold); }

.move-history-wrap { width: 220px; background: var(--surface); border-radius: 12px; height: 580px; border: 1px solid var(--dark4); display: flex; flex-direction: column; }
.move-history-title { padding: 15px; border-bottom: 1px solid var(--dark4); font-weight: 700; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); }
.move-history { flex: 1; overflow-y: auto; padding: 10px; font-family: monospace; font-size: 0.85rem; }
.move-row { display: grid; grid-template-columns: 30px 1fr 1fr; gap: 5px; padding: 6px 0; border-bottom: 1px solid var(--dark2); }
.move-num { color: var(--text-muted); text-align: right; padding-right: 5px; }

/* OVERLAYS */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.85); backdrop-filter: blur(8px); z-index: 100; display: flex; align-items: center; justify-content: center; }
.hidden { display: none; }
.end-card { background: var(--surface); width: 360px; padding: 40px; border-radius: 16px; border: 1px solid var(--gold-dim); text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,0.8); }
.end-icon { font-size: 4rem; color: var(--gold); margin-bottom: 20px; }
.end-title { font-family: 'Playfair Display', serif; font-size: 2.2rem; margin-bottom: 10px; }
.end-sub { color: var(--text-muted); margin-bottom: 30px; }
.end-actions { display: flex; flex-direction: column; gap: 12px; }
.end-btn { padding: 14px; border: none; border-radius: 8px; font-weight: 700; cursor: pointer; transition: all 0.2s; font-size: 1rem; }
.end-btn.primary { background: var(--gold); color: #000; }
.end-btn:not(.primary) { background: var(--dark2); color: var(--text); }

/* THINKING INDICATOR */
.thinking-dots { display: inline-flex; gap: 4px; align-items: center; }
.thinking-dots span { width: 5px; height: 5px; border-radius: 50%; background: var(--gold-dim); animation: thinkBounce 1.2s ease-in-out infinite; }
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes thinkBounce { 0%, 80%, 100% { transform: scale(0.7); opacity: 0.4; } 40% { transform: scale(1.2); opacity: 1; } }

.piece-moved { animation: pieceMove 0.18s ease-out; }
@keyframes pieceMove { 0% { transform: scale(1.15); } 100% { transform: scale(1); } }

/* ============================================================
   RESPONSIVE & MOBILE OPTIMIZATION
   ============================================================ */
@media (max-width: 900px) {
  body {
    overflow-y: auto; /* Permitir scroll si el contenido es largo */
    padding: 10px;
    height: auto;
    min-height: 100vh;
  }

  .game-container {
    flex-direction: column; /* Apilar elementos verticalmente */
    align-items: center;
    gap: 20px;
    width: 100%;
  }

  /* Ajustar tablero al ancho de la pantalla */
  #board {
    width: 95vw;
    height: 95vw;
    max-width: 500px;
    max-height: 500px;
  }

  /* Paneles laterales ahora ocupan el ancho completo */
  .side-panel {
    width: 95vw;
    max-width: 500px;
    flex-direction: row; /* Poner tarjetas de jugador de lado a lado */
    justify-content: space-between;
    order: 2; /* El panel de control va debajo del tablero */
  }

  .player-card {
    flex: 1;
    padding: 10px;
  }

  .move-history-wrap {
    width: 95vw;
    max-width: 500px;
    height: 120px; /* Más bajo en móvil */
    order: 3;
  }

  .logo-title {
    font-size: 2.5rem;
  }

  /* Hacer los botones de control más grandes para dedos */
  .game-controls {
    width: 100%;
    margin-top: 10px;
  }
  
  .ctrl-btn {
    height: 50px;
    font-size: 1.4rem;
  }
}