/**
 * Estilos para 2048 clásico online
 * Estándar canónico Fijate Tools con soporte tema claro y oscuro
 */

:root {
  --font-main: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-heading: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --bg-body: #0f172a;
  --bg-card: #1e293b;
  --bg-card-secondary: #334155;
  --bg-input: #0f172a;
  --bg-pill: rgba(15, 23, 42, 0.6);
  --border-color: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent-text: #38bdf8;
  --btn-hover-bg: #475569;

  --board-2048-bg: #1e293b;
  --board-2048-frame: #0b1120;
  --slot-2048-bg: #334155;
}

[data-theme="light"] {
  --bg-body: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-secondary: #f1f5f9;
  --bg-input: #ffffff;
  --bg-pill: #f1f5f9;
  --border-color: #cbd5e1;
  --text-main: #0f172a;
  --text-muted: #475569;
  --accent-text: #0284c7;
  --btn-hover-bg: #e2e8f0;

  --board-2048-bg: #bbada0;
  --board-2048-frame: #a39489;
  --slot-2048-bg: rgba(238, 228, 218, 0.45);
}

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

body {
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  background-color: var(--bg-body);
  color: var(--text-main);
  font-family: var(--font-main);
  -webkit-font-smoothing: antialiased;
}

.tool-layout {
  max-width: 1200px;
  margin: 1.5rem auto 3rem;
  padding: 0 1rem;
  flex: 1 0 auto;
  width: 100%;
}

.tool-with-sidebar {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
  width: 100%;
}

.tool-main-content {
  flex: 1 1 0%;
  min-width: 0;
  width: 100%;
}

/* Barra superior de mandos */
.controls-bar-2048 {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 0.85rem 1.25rem;
  margin-bottom: 1.25rem;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
}

.controls-group {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.controls-group label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
}

.game-select {
  background: var(--bg-input);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.45rem 2rem 0.45rem 0.75rem;
  font-size: 0.85rem;
  font-family: var(--font-main);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 0.55rem center;
  background-size: 0.9rem;
}

.game-select option {
  background: var(--bg-input);
  color: var(--text-main);
}

.stat-pill {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--bg-pill);
  padding: 0.35rem 0.8rem;
  border-radius: 20px;
  border: 1px solid var(--border-color);
  font-size: 0.85rem;
}

.stat-label {
  color: var(--text-muted);
}

.stat-value {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--accent-text);
}

.score-delta-badge {
  position: absolute;
  top: -12px;
  right: 8px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  color: #10b981;
  opacity: 0;
  pointer-events: none;
}

.score-delta-badge.pop-delta {
  animation: popScoreDelta 0.75s ease-out;
}

@keyframes popScoreDelta {
  0% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-16px); }
}

.btn-game-action {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: var(--bg-card-secondary);
  color: var(--text-main);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  min-height: 40px;
}

.btn-game-action:hover:not(:disabled) {
  background: var(--btn-hover-bg);
}

.btn-game-action:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-game-action.btn-primary-action {
  background: #0284c7;
  border-color: #0369a1;
  color: #ffffff;
}

.btn-game-action.btn-primary-action:hover {
  background: #0369a1;
}

/* Arena central */
.arena-2048 {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 1.5rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
}

.board-frame-2048 {
  position: relative;
  width: 100%;
  max-width: 460px;
  background: var(--board-2048-frame);
  border: 6px solid var(--board-2048-bg);
  border-radius: 16px;
  padding: 10px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.28);
  touch-action: none;
  user-select: none;
}

.grid-2048 {
  display: grid;
  width: 100%;
  aspect-ratio: 1 / 1;
  gap: 10px;
}

.grid-2048.size-4 {
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
}

.grid-2048.size-5 {
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: 8px;
}

.tile-slot {
  background: var(--slot-2048-bg);
  border-radius: 10px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.tile-2048 {
  width: 100%;
  height: 100%;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: clamp(1.3rem, 4vw, 2.2rem);
  user-select: none;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.15);
}

.size-5 .tile-2048 {
  font-size: clamp(1.05rem, 3.2vw, 1.65rem);
}

.tile-2048.tile-new {
  animation: tileAppear 0.18s ease-out;
}

.tile-2048.tile-merged {
  animation: tilePop 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes tileAppear {
  0% { transform: scale(0.3); opacity: 0.2; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes tilePop {
  0% { transform: scale(0.85); }
  50% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

/* Paleta de colores clásica 2048 */
.tile-2 { background: #eee4da; color: #776e65; }
.tile-4 { background: #ede0c8; color: #776e65; }
.tile-8 { background: #f2b179; color: #ffffff; }
.tile-16 { background: #f59563; color: #ffffff; }
.tile-32 { background: #f67c5f; color: #ffffff; }
.tile-64 { background: #f65e3b; color: #ffffff; }
.tile-128 { background: #edcf72; color: #ffffff; font-size: clamp(1.1rem, 3.4vw, 1.85rem); box-shadow: 0 0 12px rgba(237, 207, 114, 0.4); }
.tile-256 { background: #edcc61; color: #ffffff; font-size: clamp(1.1rem, 3.4vw, 1.85rem); box-shadow: 0 0 14px rgba(237, 204, 97, 0.5); }
.tile-512 { background: #edc850; color: #ffffff; font-size: clamp(1.1rem, 3.4vw, 1.85rem); box-shadow: 0 0 16px rgba(237, 200, 80, 0.6); }
.tile-1024 { background: #edc53f; color: #ffffff; font-size: clamp(0.95rem, 2.8vw, 1.55rem); box-shadow: 0 0 18px rgba(237, 197, 63, 0.7); }
.tile-2048 { background: #eab308; color: #ffffff; font-size: clamp(0.95rem, 2.8vw, 1.55rem); box-shadow: 0 0 22px rgba(234, 179, 8, 0.85); }
.tile-super { background: #7c3aed; color: #ffffff; font-size: clamp(0.85rem, 2.5vw, 1.35rem); box-shadow: 0 0 24px rgba(124, 58, 237, 0.75); }

/* Cruceta direccional móvil / accesibilidad */
.dpad-2048 {
  display: grid;
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(2, 52px);
  gap: 8px;
  margin-top: 1.25rem;
}

.dpad-2048 .pad-empty {
  visibility: hidden;
}

.pad-btn {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  background: var(--bg-card-secondary);
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease;
}

.pad-btn:active {
  transform: scale(0.94);
  background: #0284c7;
  color: #ffffff;
}

/* Modal fin de partida */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  backdrop-filter: blur(4px);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-card {
  background: var(--bg-card);
  border: 2px solid var(--accent-text);
  border-radius: 16px;
  padding: 2rem;
  max-width: 400px;
  width: 90%;
  text-align: center;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.45);
}

.modal-card h2 {
  font-family: var(--font-heading);
  font-size: 1.65rem;
  margin: 0 0 0.5rem;
  color: var(--accent-text);
}

.modal-card p {
  color: var(--text-muted);
  margin: 0 0 1.5rem;
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

/* Guía de juego */
.game-guide-section {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 1.75rem;
  margin-top: 2rem;
}

.game-guide-section h2 {
  font-family: var(--font-heading);
  font-size: 1.35rem;
  margin-top: 0;
  margin-bottom: 1rem;
}

.guide-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.5rem;
}

.guide-item h3 {
  font-size: 1.05rem;
  margin-top: 0;
  margin-bottom: 0.4rem;
  color: var(--accent-text);
}

.guide-item p {
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text-muted);
  margin: 0;
}

@media (max-width: 640px) {
  .controls-bar-2048 {
    padding: 0.75rem;
  }
  .arena-2048 {
    padding: 1rem;
  }
}
