/* =====================================================================
   AMIGOS DE MIERDA — estilos base (mobile first)
   ===================================================================== */
:root {
  --bg: #100b1f;
  --bg-2: #1a1230;
  --surface: rgba(255, 255, 255, 0.05);
  --surface-2: rgba(255, 255, 255, 0.1);
  --border: rgba(255, 255, 255, 0.12);
  --text: #f4f0ff;
  --text-dim: #b7aee0;
  --accent: #7c5cff;
  --accent-strong: #6a45ff;
  --accent-2: #ff5c8a;
  --success: #2fd48a;
  --error: #ff5c6c;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

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

body {
  min-height: 100vh;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(124, 92, 255, 0.35), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(255, 92, 138, 0.25), transparent 55%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 24px 16px 48px;
  min-height: 100vh;
}

/* ---- Botones ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 14px 22px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--border);
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease, opacity .12s ease;
}
.btn:focus-visible { outline: 3px solid rgba(124, 92, 255, .6); outline-offset: 2px; }
.btn:active { transform: translateY(1px) scale(.99); }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn--lg { width: 100%; padding: 16px 22px; font-size: 1.05rem; }
.btn--primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  border-color: transparent;
  box-shadow: 0 8px 24px rgba(124, 92, 255, .35);
}
.btn--primary:hover { box-shadow: 0 10px 30px rgba(124, 92, 255, .5); transform: translateY(-1px); }
.btn--secondary { background: var(--surface-2); border-color: var(--border); }
.btn--secondary:hover { background: var(--surface); transform: translateY(-1px); }
.btn.is-loading { opacity: .7; pointer-events: none; }

/* ---- Inputs ---- */
.input {
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font-size: 1rem;
}
.input::placeholder { color: var(--text-dim); opacity: .7; }
.input:focus-visible { outline: 3px solid rgba(124, 92, 255, .5); border-color: var(--accent); }
.input--lg { padding: 16px; font-size: 1.05rem; letter-spacing: 1px; text-transform: uppercase; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.error-box {
  padding: 16px; border-radius: var(--radius);
  background: rgba(255, 92, 108, .12); border: 1px solid rgba(255, 92, 108, .4);
  color: var(--error);
}

/* ---- Toast ---- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  max-width: 90vw; padding: 12px 18px; border-radius: 999px;
  background: var(--bg-2); border: 1px solid var(--border);
  color: var(--text); font-size: .95rem; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity .25s ease, transform .25s ease; z-index: 100;
}
.toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast--error { border-color: rgba(255, 92, 108, .5); }
.toast--success { border-color: rgba(47, 212, 138, .5); }

/* ---- Spinner ---- */
.spinner {
  width: 40px; height: 40px; margin: 0 auto 12px; border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, .15); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Home ---- */
.home { display: flex; flex-direction: column; justify-content: center; gap: 28px; padding-top: 4vh; }
.home__brand { text-align: center; }
.home__logo { font-size: 64px; line-height: 1; animation: float 3s ease-in-out infinite; }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
.home__title { font-size: clamp(2rem, 8vw, 3rem); font-weight: 900; margin: 12px 0 8px; letter-spacing: -.5px; }
.home__title-accent {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.home__subtitle { color: var(--text-dim); font-size: 1.05rem; margin: 0; }
.home__actions { display: flex; flex-direction: column; gap: 14px; }
.home__join { display: flex; flex-direction: column; gap: 10px; }
.home__hint { text-align: center; color: var(--text-dim); font-size: .9rem; margin: 0; }

/* ---- Páginas de formulario ---- */
.form-page { padding-top: 8px; }
.back { color: var(--text-dim); text-decoration: none; font-size: .95rem; display: inline-block; margin-bottom: 12px; }
.back:hover { color: var(--text); }
.form-page__title { font-size: 1.6rem; font-weight: 800; margin: 0 0 16px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); backdrop-filter: blur(10px);
}
.form { display: flex; flex-direction: column; gap: 18px; }
.field { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.field__label { font-weight: 700; font-size: .95rem; color: var(--text); }

/* ---- Selector de avatares ---- */
.avatar-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.avatar-option { position: relative; cursor: pointer; }
.avatar-option input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.avatar-option__img {
  display: block; width: 100%; aspect-ratio: 1; object-fit: cover;
  border-radius: 14px; border: 2px solid var(--border); background: var(--surface-2);
  transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease;
}
.avatar-option:hover .avatar-option__img { transform: scale(1.03); }
.avatar-option input:focus-visible + .avatar-option__img { outline: 3px solid rgba(124, 92, 255, .6); outline-offset: 2px; }
.avatar-option input:checked + .avatar-option__img {
  border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124, 92, 255, .35); transform: scale(1.04);
}

/* Avatares (imágenes) en listas, votaciones y resultados */
.avatar-img { display: block; width: 40px; height: 40px; border-radius: 4px; object-fit: cover; background: var(--surface-2); flex: 0 0 auto; }
.avatar-img--xs { width: 24px; height: 24px; }
.avatar-img--md { width: 48px; height: 48px; }
.avatar-img--lg { width: 56px; height: 56px; }
.avatar-img--xl { width: 80px; height: 80px; }
.avatar-img--xxl { width: 96px; height: 96px; }

/* ---- Chips de rondas ---- */
.chip-group { display: flex; flex-wrap: wrap; gap: 10px; }
.chip { cursor: pointer; }
.chip input { position: absolute; opacity: 0; }
.chip span {
  display: inline-block; padding: 10px 18px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-weight: 700; transition: background .12s ease, border-color .12s ease, transform .12s ease;
}
.chip:hover span { transform: translateY(-1px); }
.chip input:focus-visible + span { outline: 3px solid rgba(124, 92, 255, .6); outline-offset: 2px; }
.chip input:checked + span { background: rgba(124, 92, 255, .2); border-color: var(--accent); }

/* ---- Sala ---- */
.room { min-height: 70vh; display: flex; flex-direction: column; }
.room__loading { margin: auto; text-align: center; color: var(--text-dim); }

/* ---- Responsive ---- */
@media (min-width: 640px) {
  .home__join { flex-direction: row; }
  .home__join .input { flex: 1; }
  .home__join .btn { width: auto; }
  .avatar-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ---- Lobby ---- */
.btn--small { padding: 9px 14px; font-size: .9rem; }
.lobby { display: flex; flex-direction: column; gap: 16px; }
.lobby__header { display: flex; flex-direction: column; gap: 12px; }
.lobby__code-box { text-align: center; padding: 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); }
.lobby__code-label { display: block; color: var(--text-dim); font-size: .8rem; text-transform: uppercase; letter-spacing: 1px; }
.lobby__code { font-size: 2.2rem; letter-spacing: 6px; font-weight: 900; }
.lobby__share { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.lobby__body { display: flex; flex-direction: column; gap: 12px; }
.lobby__count { color: var(--text-dim); text-align: center; font-size: .95rem; }
.lobby__empty { text-align: center; color: var(--text-dim); padding: 12px; }
.lobby__waiting { color: var(--text-dim); margin: 0; padding: 14px; }
.lobby__note { color: var(--text-dim); font-size: .85rem; margin: 0; }

.player-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.player-row {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  animation: row-in .35s ease both;
}
@keyframes row-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.player-row__name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-row__status { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.player-row__status.is-on { background: var(--success); box-shadow: 0 0 8px rgba(47, 212, 138, .6); }
.player-row__status.is-off { background: var(--error); opacity: .5; }
.lobby__footer { display: flex; flex-direction: column; gap: 10px; text-align: center; }

/* ---- Game: votación / resultados / final ---- */
.game { display: flex; flex-direction: column; gap: 18px; }
.game__header { text-align: center; display: flex; flex-direction: column; gap: 6px; }
.game__round-tag { color: var(--text-dim); font-size: .9rem; text-transform: uppercase; letter-spacing: 1px; }
.game__title { margin: 0; font-size: 1.8rem; font-weight: 900; }
.game__waiting { color: var(--text-dim); text-align: center; margin: 0; padding: 12px; }

.question-card { perspective: 1200px; }
.question-card__inner {
  position: relative; width: 100%; min-height: 260px;
  transform-style: preserve-3d; transition: transform .7s cubic-bezier(.4, .2, .2, 1);
}
.question-card.is-flipped .question-card__inner { transform: rotateY(180deg); }
.question-card__face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  border-radius: var(--radius); padding: 24px; text-align: center;
}
.question-card__back {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  font-size: 4rem; box-shadow: var(--shadow);
}
.question-card__front {
  background: var(--surface); border: 1px solid var(--border);
  transform: rotateY(180deg); box-shadow: var(--shadow); backdrop-filter: blur(10px);
}
.question-card__category { font-size: .8rem; padding: 4px 12px; border-radius: 999px; background: rgba(124, 92, 255, .2); border: 1px solid rgba(124, 92, 255, .4); color: var(--text-dim); }
.question-card__text { font-size: 1.3rem; font-weight: 800; margin: 0; line-height: 1.35; }

.vote-area { display: flex; flex-direction: column; gap: 14px; transition: opacity .3s ease; }
.vote-area.is-hidden { opacity: 0; pointer-events: none; }
.vote-hint { color: var(--text-dim); text-align: center; margin: 0; }
.vote-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.vote-card {
  display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 16px 10px;
  background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius);
  cursor: pointer; color: var(--text); font: inherit;
  transition: transform .12s ease, border-color .12s ease, background .12s ease;
}
.vote-card:hover { transform: translateY(-2px); }
.vote-card:focus-visible { outline: 3px solid rgba(124, 92, 255, .6); outline-offset: 2px; }
.vote-card.is-selected { border-color: var(--accent); background: rgba(124, 92, 255, .16); }
.vote-card__name { font-weight: 700; }
.vote-done { text-align: center; font-size: 1.1rem; font-weight: 700; padding: 16px; color: var(--success); }

/* ---- Tablero en vivo (durante votación) ---- */
.live-board { display: flex; flex-direction: column; gap: 10px; }
.live-board__header { display: flex; justify-content: space-between; align-items: center; color: var(--text-dim); font-size: .9rem; }
.live-board__count { font-weight: 800; }
.live-board__list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.live-board__empty { text-align: center; color: var(--text-dim); padding: 8px; }
.live-board__row {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  animation: row-in .3s ease both;
}
.live-board__row.is-you { border-color: rgba(124, 92, 255, .4); }
.live-board__name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live-board__votes { font-weight: 800; color: var(--text); min-width: 24px; text-align: center; }

/* ---- Votantes (resultados) ---- */
.result-row__voters { display: flex; flex-wrap: wrap; gap: 6px; }
.voter-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px 3px 3px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: .8rem; color: var(--text-dim);
  animation: voter-in .35s ease both;
}
.voter-chip__name { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@keyframes voter-in { from { opacity: 0; transform: translateX(-8px) scale(.9); } to { opacity: 1; transform: none; } }

.result-question { text-align: center; color: var(--text-dim); font-size: .95rem; }
.result-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.result-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.result-row__body { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.result-row__top { display: flex; justify-content: space-between; align-items: center; }
.result-row__name { font-weight: 700; }
.result-row__votes { color: var(--text-dim); font-size: .9rem; }
.result-row__bar { height: 8px; border-radius: 999px; background: rgba(255, 255, 255, .08); overflow: hidden; }
.result-row__fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 999px; transition: width .5s ease; }

.final { display: flex; flex-direction: column; gap: 20px; text-align: center; }
.final__title { margin: 0; font-size: 1.7rem; font-weight: 900; }
.podium { display: flex; justify-content: center; align-items: flex-end; gap: 10px; }
.podium-card {
  flex: 1; max-width: 170px; display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 14px 8px; border-radius: var(--radius); background: var(--surface);
  border: 1px solid var(--border); animation: rise .5s ease both;
}
.podium-card--1 { order: 2; padding-top: 26px; max-width: 200px; border-color: rgba(255, 215, 0, .55); }
.podium-card--2 { order: 1; }
.podium-card--3 { order: 3; }
.podium-card__medal { font-size: 1.8rem; line-height: 1; }
.podium-card__name { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.podium-card__votes { color: var(--text-dim); font-size: .85rem; }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.rest-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.rest-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.rest-row__pos { color: var(--text-dim); font-weight: 800; width: 28px; }
.rest-row__name { flex: 1; font-weight: 600; text-align: left; }
.rest-row__votes { color: var(--text-dim); }

@media (min-width: 640px) {
  .vote-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ---- Sonido / utilidades ---- */
.btn--ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn--ghost:hover { color: var(--text); background: var(--surface); }
.sound-toggle {
  position: fixed; top: 12px; right: 12px; z-index: 90;
  width: 44px; height: 44px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 1.2rem; cursor: pointer; color: var(--text);
}
.sound-toggle:hover { background: var(--surface); }

