/* ¿Quién soy? — estilos responsive (mobile-first) */

:root {
  --bg: #0b1020;
  --bg-2: #131a30;
  --card: #1a2340;
  --card-2: #212c50;
  --border: #2c3765;
  --text: #eef1fb;
  --muted: #97a1c4;
  --primary: #ff5470;
  --primary-2: #ff7d54;
  --accent: #4dd4ff;
  --ok: #45d483;
  --warn: #ffcf5c;
  --danger: #ff5470;
  --radius: 16px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

/* El atributo [hidden] debe ganarle a los display: flex/grid/etc. del autor.
   Sin esto, las pantallas, formularios y modales ocultos se muestran igual. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(1200px 600px at 50% -10%, #1c2547 0%, var(--bg) 60%);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100dvh;
  -webkit-text-size-adjust: 100%;
}

.screen {
  max-width: 1100px;
  margin: 0 auto;
  padding: max(env(safe-area-inset-top), 16px) 16px 40px;
}

h1, h2, h3 { line-height: 1.15; }

/* ------------------------------- Botones ------------------------------- */
.btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 12px 16px;
  cursor: pointer;
  color: var(--text);
  background: var(--card-2);
  transition: transform 0.06s ease, filter 0.15s ease, background 0.15s ease;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff;
  border: none;
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.05); }
.btn-ghost { background: transparent; border: 1px solid var(--border); }
.btn-ok { background: linear-gradient(135deg, #2fbf71, var(--ok)); color: #04231a; border: none; }
.btn-danger { background: transparent; border: 1px solid var(--danger); color: var(--danger); }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 12px; font-size: 0.85rem; border-radius: 10px; }

/* -------------------------------- Inicio ------------------------------- */
#screen-home { display: flex; align-items: center; min-height: 100dvh; }
.home-card {
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 22px;
}
.logo { font-size: 2rem; margin: 0 0 4px; text-align: center; }
.flag { filter: saturate(1.2); }
.tagline { color: var(--muted); text-align: center; margin: 0 0 22px; font-size: 0.95rem; }
.tabs { display: flex; gap: 8px; background: var(--bg-2); padding: 6px; border-radius: 12px; margin-bottom: 18px; }
.tab {
  flex: 1; padding: 10px; border: none; border-radius: 8px; background: transparent;
  color: var(--muted); font: inherit; font-weight: 600; cursor: pointer;
}
.tab.is-active { background: var(--card-2); color: var(--text); }

.panel { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; color: var(--muted); font-weight: 600; }
input[type="text"] {
  font: inherit; font-size: 1.05rem; color: var(--text);
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 13px 14px; outline: none;
}
input[type="text"]:focus { border-color: var(--accent); }

.modes { border: 1px solid var(--border); border-radius: 12px; padding: 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.modes legend { padding: 0 6px; color: var(--muted); font-size: 0.82rem; font-weight: 700; }
.mode-opt { flex-direction: row; align-items: center; gap: 8px; background: var(--bg-2); padding: 10px; border-radius: 10px; cursor: pointer; color: var(--text); font-weight: 600; }
.mode-opt input { accent-color: var(--primary); }
.hint { color: var(--muted); font-size: 0.82rem; text-align: center; margin-top: 18px; }

/* -------------------------------- Topbar ------------------------------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 18px; flex-wrap: wrap;
}
.room-code { display: flex; align-items: center; gap: 10px; }
.room-code .label { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; }
.code { font-size: 1.6rem; letter-spacing: 0.18em; font-variant-numeric: tabular-nums; }
.pill { background: var(--card-2); border: 1px solid var(--border); border-radius: 999px; padding: 4px 12px; font-size: 0.85rem; color: var(--muted); }
.pill-score { color: var(--text); }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

/* -------------------------------- Lobby -------------------------------- */
.lobby-body h2 { display: flex; align-items: center; gap: 10px; }
.player-list { list-style: none; padding: 0; margin: 12px 0 24px; display: grid; gap: 10px; }
.player-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px;
}
.player-row .avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--card-2); display: grid; place-items: center; font-weight: 700; }
.player-row .p-name { font-weight: 600; flex: 1; }
.player-row .tag-host { color: var(--warn); font-size: 0.8rem; }
.player-row .tag-off { color: var(--muted); font-size: 0.8rem; }
.host-panel { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.host-panel h3 { margin-top: 0; }
.warn { color: var(--warn); font-size: 0.88rem; }

/* ------------------------------ Carta propia --------------------------- */
.self-card {
  background: linear-gradient(135deg, var(--card), var(--card-2));
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 22px; text-align: center; margin-bottom: 16px;
}
.self-card .qmark { font-size: 3.4rem; line-height: 1; }
.self-card .self-name { font-size: 1.2rem; font-weight: 700; margin-top: 6px; }
.self-card .self-hint { color: var(--muted); font-size: 0.9rem; margin-top: 4px; }
.self-card.solved { border-style: solid; border-color: var(--ok); }
.self-card .reveal-img { width: 100%; max-width: 320px; border-radius: 12px; margin: 12px auto 0; display: block; }

/* --------------------------- Acción de adivinar ------------------------ */
.guess-action { margin-bottom: 22px; }
.guess-action .waiting {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--card); border: 1px solid var(--accent); border-radius: 12px; padding: 12px 16px;
}
.guess-action .votes-count { font-weight: 700; color: var(--accent); }

/* ------------------------------ Grilla cartas -------------------------- */
.section-title { font-size: 1.05rem; color: var(--muted); margin: 8px 0 12px; }
.players-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
.pcard {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; display: flex; flex-direction: column;
}
.pcard.solved { border-color: var(--ok); }
.pcard.disconnected { opacity: 0.55; }
.pcard .img-wrap { position: relative; aspect-ratio: 4 / 3; background: var(--bg-2); }
.pcard .img-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pcard .img-missing { width: 100%; height: 100%; display: grid; place-items: center; color: var(--muted); font-size: 0.85rem; text-align: center; padding: 12px; }
.pcard .status-badge {
  position: absolute; top: 8px; left: 8px; font-size: 0.72rem; font-weight: 700;
  padding: 3px 9px; border-radius: 999px; background: rgba(0,0,0,0.55); backdrop-filter: blur(4px);
}
.badge-playing { color: var(--accent); }
.badge-solved { color: var(--ok); }
.badge-off { color: var(--muted); }
.pcard .body { padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.pcard .who { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.pcard .who .player-name { color: var(--muted); font-size: 0.82rem; }
.pcard .who .score { font-weight: 700; font-size: 0.9rem; }
.pcard .identity-name { font-size: 1.15rem; font-weight: 700; line-height: 1.2; }
.pcard .actions { margin-top: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.pcard .actions .btn { flex: 1; }
.pcard .host-tools { display: flex; gap: 6px; border-top: 1px dashed var(--border); padding-top: 8px; }
.pcard .host-tools .btn { flex: 1; font-size: 0.78rem; padding: 6px; }

/* -------------------------------- Menú --------------------------------- */
.menu {
  position: absolute; right: 16px; top: 64px; z-index: 20;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); padding: 6px; display: flex; flex-direction: column; min-width: 190px;
}
.menu-item { text-align: left; background: transparent; border: none; color: var(--text); font: inherit; padding: 11px 12px; border-radius: 8px; cursor: pointer; }
.menu-item:hover { background: var(--card-2); }

/* ------------------------------- Modal --------------------------------- */
.modal { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 20px; }
.modal-box { width: 100%; max-width: 420px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
.scoreboard { padding-left: 0; list-style: none; margin: 12px 0 20px; display: grid; gap: 8px; }
.scoreboard li { display: flex; align-items: center; gap: 10px; background: var(--bg-2); padding: 10px 14px; border-radius: 10px; }
.scoreboard .rank { width: 26px; font-weight: 800; color: var(--muted); }
.scoreboard .sb-name { flex: 1; font-weight: 600; }
.scoreboard .sb-score { font-weight: 800; color: var(--accent); }
.scoreboard li:first-child .sb-score { color: var(--warn); }

.overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 30; }

/* ------------------------------- Toast --------------------------------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--card-2); border: 1px solid var(--border); color: var(--text);
  padding: 12px 18px; border-radius: 12px; box-shadow: var(--shadow); z-index: 60;
  max-width: 90vw; text-align: center; font-weight: 600;
}
.toast.err { border-color: var(--danger); }
.toast.ok { border-color: var(--ok); }

/* --------------------------- Animación acierto ------------------------- */
@keyframes pop { 0% { transform: scale(0.9); opacity: 0; } 60% { transform: scale(1.04); } 100% { transform: scale(1); opacity: 1; } }
.solved-anim { animation: pop 0.4s ease; }

/* ------------------------------ Responsive ----------------------------- */
.emoji-controls {
  position: fixed; right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom)); z-index: 25;
  display: flex; flex-direction: column; align-items: flex-end; gap: 12px;
}
.emoji-toggle { border-radius: 999px; box-shadow: var(--shadow); }
.emoji-picker {
  width: min(390px, calc(100vw - 32px)); padding: 16px;
  max-height: calc(100dvh - 100px); overflow-y: auto;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 20px; box-shadow: var(--shadow);
}
.emoji-picker-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.emoji-picker h2 { margin: 0; font-size: 1.05rem; }
.emoji-picker p { margin: 0 0 14px; font-size: .82rem; color: var(--muted); }
.emoji-selector-host { border-radius: 12px; overflow: hidden; }
.emoji-selector-host[inert] { opacity: .65; }
.emoji-loading { padding: 24px 8px; text-align: center; }
emoji-picker {
  width: 100%; height: min(410px, calc(100dvh - 260px)); min-height: 220px;
  --background: var(--bg-2); --border-color: var(--border); --border-radius: 12px;
  --button-active-background: var(--card-2); --button-hover-background: var(--card-2);
  --input-border-color: var(--border); --input-font-color: var(--text);
  --input-placeholder-color: var(--muted); --input-padding: 8px 10px;
  --category-font-color: var(--text); --indicator-color: var(--primary);
  --outline-color: var(--accent); --emoji-size: 1.65rem; --emoji-padding: .45rem;
  --num-columns: 8; --category-emoji-size: 1.2rem; --category-emoji-padding: .4rem;
}
@media (max-width: 400px) { emoji-picker { --num-columns: 7; --emoji-padding: .4rem; --category-emoji-size: 1rem; --category-emoji-padding: .35rem; } }
@media (max-width: 350px) { emoji-picker { --num-columns: 6; --category-emoji-size: .9rem; --category-emoji-padding: .25rem; } }
body:has(#emoji-controls:not([hidden])) .screen { padding-bottom: 100px; }
.emoji-floats { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 45; }
.emoji-float {
  position: absolute; bottom: 94px; display: flex; flex-direction: column; align-items: center;
  gap: 6px; width: min(180px, 42vw); animation: emoji-rise 4s ease-out both;
}
.floating-emoji { font-size: 3.4rem; line-height: 1.2; filter: drop-shadow(0 4px 12px #0006); }
.floating-name {
  max-width: 100%; padding: 5px 12px; border-radius: 999px; color: var(--text);
  background: #1a2340ed; border: 1px solid var(--accent); box-shadow: var(--shadow);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .85rem; font-weight: 700;
}
@keyframes emoji-rise {
  0% { opacity: 0; transform: translate(-50%, 20px) scale(.7); }
  12% { opacity: 1; }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translate(calc(-50% + var(--drift)), calc(-1 * min(60dvh, 520px))) scale(1.1); }
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (prefers-reduced-motion: reduce) {
  .emoji-float { animation: emoji-still 4s linear both; }
  @keyframes emoji-still { 0%, 85% { opacity: 1; transform: translateX(-50%); } 100% { opacity: 0; transform: translateX(-50%); } }
}

@media (min-width: 620px) {
  .players-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 900px) {
  .players-grid { grid-template-columns: repeat(3, 1fr); }
  .code { font-size: 1.9rem; }
}
@media (prefers-reduced-motion: reduce) {
  .solved-anim { animation: none; }
  .btn:active { transform: none; }
}
