/* =====================================================================
   Migajero - estilos coloridos, animados y responsivos
   ===================================================================== */
:root {
  --pink: #ff5c7c; --blue: #4dd0ff; --yellow: #ffd23f; --green: #7be060;
  --purple: #b06cff; --dark: #1a1140; --card: rgba(30, 20, 70, 0.72);
}
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  height: 100%; width: 100%; overflow: hidden;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: #fff; user-select: none; touch-action: manipulation;
}
body {
  background: linear-gradient(-45deg, #2a1560, #4b2b8a, #b23a2a, #1c5fa8, #1f8a5b);
  background-size: 400% 400%;
  animation: bgshift 22s ease infinite;
}
@keyframes bgshift { 0%{background-position:0% 50%} 50%{background-position:100% 50%} 100%{background-position:0% 50%} }

.screen { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; padding: 16px; }
.screen.active { display: flex; }

/* ---------- Tarjetas ---------- */
.card {
  background: var(--card); backdrop-filter: blur(14px);
  border: 1px solid rgba(255,255,255,0.18); border-radius: 24px;
  padding: 28px 26px; width: 100%; max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4); text-align: center; z-index: 2;
  animation: pop 0.4s cubic-bezier(.2,1.3,.4,1);
}
@keyframes pop { from{transform:scale(.85);opacity:0} to{transform:scale(1);opacity:1} }

.logo { font-size: 34px; font-weight: 900; margin-bottom: 6px; }
.logo span {
  background: linear-gradient(90deg, var(--yellow), var(--pink), var(--blue));
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.logo.small { font-size: 26px; }
.tagline, .welcome { opacity: 0.85; margin-bottom: 18px; font-size: 15px; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 8px; background: rgba(0,0,0,0.25); border-radius: 14px; padding: 5px; margin-bottom: 16px; }
.tab { flex: 1; padding: 11px; border: none; border-radius: 10px; background: transparent; color: #fff; font-weight: 700; font-size: 14px; cursor: pointer; transition: .2s; }
.tab.active { background: linear-gradient(90deg, var(--pink), var(--purple)); box-shadow: 0 4px 14px rgba(176,108,255,.4); }

/* ---------- Inputs ---------- */
input {
  width: 100%; padding: 14px 16px; margin-bottom: 12px; border-radius: 13px;
  border: 2px solid rgba(255,255,255,0.2); background: rgba(0,0,0,0.28);
  color: #fff; font-size: 16px; outline: none; transition: .2s;
}
input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(77,208,255,.25); }
input::placeholder { color: rgba(255,255,255,0.5); }
.hint { display: block; opacity: 0.6; font-size: 12px; margin: -6px 0 10px; }

/* ---------- Botones ---------- */
.btn {
  width: 100%; padding: 14px; border: none; border-radius: 14px; font-size: 16px;
  font-weight: 800; color: #fff; cursor: pointer; transition: transform .12s, box-shadow .2s;
}
.btn:active { transform: scale(0.96); }
.btn.primary { background: linear-gradient(90deg, var(--pink), var(--purple)); box-shadow: 0 6px 18px rgba(176,108,255,.45); }
.btn.ghost { background: transparent; border: 2px solid rgba(255,255,255,0.25); margin-top: 10px; }
.btn.big { display: flex; flex-direction: column; align-items: center; gap: 3px; margin-bottom: 12px; padding: 18px; font-size: 19px; }
.btn.big small { font-size: 12px; font-weight: 500; opacity: 0.85; }
.btn.create { background: linear-gradient(120deg, var(--pink), #ff8f4d); box-shadow: 0 6px 20px rgba(255,92,124,.4); }
.btn.solo { background: linear-gradient(120deg, var(--blue), #3ff0c0); box-shadow: 0 6px 20px rgba(77,208,255,.4); }
.btn.join { background: linear-gradient(120deg, var(--yellow), #ff8f4d); color: #3a1500; width: auto; padding: 14px 22px; }
.error { color: #ffd0d0; font-size: 14px; min-height: 18px; margin-top: 6px; }

.join-box { display: flex; gap: 8px; margin: 6px 0; }
.join-box input { text-transform: uppercase; letter-spacing: 4px; text-align: center; font-weight: 800; margin: 0; }

/* ---------- Lobby ---------- */
.lobby-card h2 { margin-bottom: 16px; }
.code-box { background: rgba(0,0,0,0.3); border-radius: 16px; padding: 16px; margin-bottom: 14px; }
.code-label { font-size: 12px; opacity: 0.7; text-transform: uppercase; letter-spacing: 2px; }
.code-value { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 6px 0; }
.code-value span { font-size: 42px; font-weight: 900; letter-spacing: 8px;
  background: linear-gradient(90deg, var(--yellow), var(--green)); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
#btn-copy-code { background: rgba(255,255,255,0.15); border: none; border-radius: 10px; padding: 8px 10px; font-size: 18px; cursor: pointer; }
.code-box small { opacity: 0.6; font-size: 12px; }
.count { font-size: 13px; opacity: 0.75; margin-bottom: 10px; }
.players { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 16px; min-height: 40px; }
.player-chip { background: rgba(0,0,0,0.3); padding: 8px 14px; border-radius: 20px; font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 7px; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; box-shadow: 0 0 8px currentColor; }
.wait { opacity: 0.7; font-style: italic; margin: 8px 0; }

/* ---------- Floaty deco ---------- */
.floaty { position: absolute; font-size: 46px; opacity: 0.5; z-index: 1; animation: float 6s ease-in-out infinite; }
.f1 { top: 12%; left: 12%; } .f2 { bottom: 16%; right: 14%; animation-delay: 1.5s; } .f3 { top: 22%; right: 18%; animation-delay: 3s; }
@keyframes float { 0%,100%{transform:translateY(0) rotate(-6deg)} 50%{transform:translateY(-22px) rotate(6deg)} }

/* ---------- Juego ---------- */
#screen-game { padding: 0; }
.game-wrap { position: relative; width: 100%; height: 100%; overflow: hidden; }
#game-canvas { display: block; width: 100%; height: 100%; }

.hud { position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: flex-start; padding: 10px 12px; gap: 8px; pointer-events: none; }
.hud > div { display: flex; flex-direction: column; gap: 4px; }
.hud-center { align-items: center; }
.hud-right { align-items: flex-end; flex-direction: row !important; gap: 8px; }
.hud-pill { background: rgba(0,0,0,0.5); backdrop-filter: blur(6px); padding: 7px 13px; border-radius: 12px; font-weight: 800; font-size: 14px; border: 1px solid rgba(255,255,255,0.15); }
.hud-pill.big { font-size: 18px; color: var(--yellow); }
.hud-pill.power { color: var(--green); }
.hud-pill.coins { color: #ffcf33; margin-top: 2px; }
.hud-theme { font-size: 11px; opacity: 0.8; padding-left: 4px; }
.hud-small { font-size: 11px; opacity: 0.8; }
.hud-exit { pointer-events: auto; background: rgba(255,60,90,0.85); border: none; color: #fff; width: 34px; height: 34px; border-radius: 10px; font-size: 18px; font-weight: 900; cursor: pointer; }

.leaderboard { position: absolute; top: 100px; right: 10px; background: rgba(0,0,0,0.5); backdrop-filter: blur(6px); border-radius: 12px; padding: 8px 10px; font-size: 12px; min-width: 120px; pointer-events: none; border: 1px solid rgba(255,255,255,0.12); transition: opacity .2s, transform .2s; }
.leaderboard.hidden { opacity: 0; transform: translateX(20px); pointer-events: none; }
.lb-title { font-weight: 800; opacity: 0.7; font-size: 10px; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 5px; }
.lb-row { display: flex; align-items: center; gap: 6px; padding: 2px 0; }
.lb-lvl { margin-left: auto; opacity: 0.85; font-weight: 700; }
.lb-toggle { position: absolute; top: 62px; right: 10px; z-index: 5; pointer-events: auto; width: 34px; height: 34px; border-radius: 10px; border: 1px solid rgba(255,255,255,0.2); background: rgba(0,0,0,0.5); backdrop-filter: blur(6px); color: #fff; font-size: 16px; cursor: pointer; }

/* Mejores jugadores (lobby) */
.best-box { background: rgba(0,0,0,0.28); border-radius: 16px; padding: 12px; margin: 12px 0; }
.best-title { font-weight: 800; margin-bottom: 8px; font-size: 14px; }
.best-list { display: flex; flex-direction: column; gap: 4px; max-height: 190px; overflow-y: auto; }
.best-row { display: flex; align-items: center; gap: 8px; background: rgba(255,255,255,0.06); padding: 6px 9px; border-radius: 10px; font-size: 13px; }
.best-rank { width: 22px; text-align: center; }
.best-name { font-weight: 700; }
.best-stats { margin-left: auto; opacity: 0.85; font-size: 11px; }
.best-empty { opacity: 0.6; font-size: 13px; padding: 6px; }

/* ---------- Controles móviles ---------- */
.mobile-controls { position: absolute; bottom: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: flex-end; padding: 18px 20px calc(18px + env(safe-area-inset-bottom)); pointer-events: none; }
.move-pad { display: flex; gap: 14px; pointer-events: auto; }
.action-pad { display: flex; align-items: flex-end; gap: 12px; pointer-events: none; }
.ctrl.attack { width: 74px; height: 74px; font-size: 30px; background: linear-gradient(135deg, #ff5c7c, #ff8f4d); border-color: rgba(255,255,255,0.5); }
.ctrl {
  pointer-events: auto; width: 74px; height: 74px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.35); background: rgba(0,0,0,0.4); backdrop-filter: blur(4px);
  color: #fff; font-size: 28px; font-weight: 900; cursor: pointer; transition: transform .08s, background .1s;
}
.ctrl:active { transform: scale(0.9); background: rgba(255,255,255,0.25); }
.ctrl.jump { width: 96px; height: 96px; font-size: 17px; background: linear-gradient(135deg, var(--pink), var(--purple)); border-color: rgba(255,255,255,0.5); }
@media (pointer: fine) and (hover: hover) { .mobile-controls { display: none; } }

/* ---------- Overlay ---------- */
.overlay { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(10,5,25,0.6); backdrop-filter: blur(4px); z-index: 20; }
.overlay.show { display: flex; }
.ov-card { background: var(--card); border: 1px solid rgba(255,255,255,0.2); border-radius: 24px; padding: 34px 30px; text-align: center; animation: pop .4s cubic-bezier(.2,1.3,.4,1); max-width: 340px; }
.ov-card h2 { font-size: 30px; margin-bottom: 12px; background: linear-gradient(90deg, var(--yellow), var(--pink)); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.ov-time { font-size: 20px; font-weight: 800; }
.ov-sub { opacity: 0.85; margin: 8px 0; }
.ov-next { opacity: 0.6; font-style: italic; margin-top: 10px; }
.ov-card.win { box-shadow: 0 0 60px rgba(255,210,63,.4); }
.ov-card .btn { margin-top: 16px; }

/* ---------- Toast ---------- */
.toast { position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%) translateY(30px); background: rgba(0,0,0,0.82); padding: 12px 22px; border-radius: 14px; font-weight: 700; opacity: 0; transition: .3s; z-index: 50; pointer-events: none; border: 1px solid rgba(255,255,255,0.15); max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 480px) {
  .card { padding: 22px 18px; }
  .code-value span { font-size: 34px; letter-spacing: 5px; }
  .leaderboard { font-size: 11px; min-width: 100px; top: 58px; }
}
@media (min-width: 700px) and (pointer: fine) {
  .game-wrap { max-width: 560px; margin: 0 auto; box-shadow: 0 0 80px rgba(0,0,0,.5); }
}
