/* ════════════════════════════════════════════════════════════════════
   Pupito — sistema de diseño
   Tokens en :root (tema oscuro por defecto) y [data-theme="light"].
   Los juegos deben usar estos tokens y prefijar su CSS con .g-<id>.
   ════════════════════════════════════════════════════════════════════ */

:root {
  color-scheme: dark;
  --bg: #090a17;
  --bg-2: #0f1124;
  --bg-3: #161935;
  --surface: rgba(255, 255, 255, 0.045);
  --surface-2: rgba(255, 255, 255, 0.08);
  --surface-3: rgba(255, 255, 255, 0.13);
  --surface-solid: #14172e;
  --surface-solid-2: #1b1f3d;
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.18);
  --text: #eef0ff;
  --text-2: #b4b8d8;
  --text-3: #767ca3;
  --text-on-accent: #ffffff;

  --accent: #7c5cff;
  --accent-2: #22d3ee;
  --accent-soft: rgba(124, 92, 255, 0.18);
  --pink: #ff4d8d;
  --green: #2ee59d;
  --yellow: #ffd23f;
  --orange: #ff8a3d;
  --red: #ff5470;
  --blue: #4f8cff;

  --success: var(--green);
  --danger: var(--red);
  --warning: var(--yellow);

  --grad-accent: linear-gradient(135deg, #7c5cff 0%, #4f8cff 55%, #22d3ee 100%);
  --grad-warm: linear-gradient(135deg, #ff4d8d 0%, #ff8a3d 100%);

  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 24px;
  --radius-xl: 32px;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.45);
  --glow: 0 0 0 1px rgba(124, 92, 255, 0.4), 0 8px 30px rgba(124, 92, 255, 0.35);

  --font: 'Outfit', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'Cascadia Code', Consolas, monospace;

  --topbar-h: 68px;
  --container: 1840px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);

  /* Tablero genérico (juegos pueden reutilizarlo) */
  --board-bg: #1a1e3d;
  --board-cell: #232850;
  --board-cell-hover: #2d3366;
  --board-line: rgba(255, 255, 255, 0.08);
}

[data-theme='light'] {
  color-scheme: light;
  --bg: #f3f4fb;
  --bg-2: #eaecf8;
  --bg-3: #dfe2f3;
  --surface: rgba(255, 255, 255, 0.7);
  --surface-2: rgba(255, 255, 255, 0.9);
  --surface-3: #ffffff;
  --surface-solid: #ffffff;
  --surface-solid-2: #f6f7fd;
  --border: rgba(30, 35, 90, 0.1);
  --border-strong: rgba(30, 35, 90, 0.2);
  --text: #161a3a;
  --text-2: #4a5078;
  --text-3: #8389ad;
  --accent-soft: rgba(124, 92, 255, 0.12);
  --shadow-sm: 0 2px 8px rgba(30, 35, 90, 0.08);
  --shadow: 0 12px 32px rgba(30, 35, 90, 0.12);
  --shadow-lg: 0 24px 60px rgba(30, 35, 90, 0.18);
  --board-bg: #dfe3f6;
  --board-cell: #ffffff;
  --board-cell-hover: #eef0fd;
  --board-line: rgba(30, 35, 90, 0.12);
}

/* ───────────────────────────── Base ───────────────────────────── */

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

img,
svg {
  display: block;
  max-width: 100%;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

p {
  margin: 0;
}

::selection {
  background: rgba(124, 92, 255, 0.4);
}

:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
}

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

/* Fondo con orbes animados */
.bg-orbs {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(124, 92, 255, 0.16), transparent 60%),
    var(--bg);
}

.bg-orbs span {
  position: absolute;
  width: 46vmax;
  height: 46vmax;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.35;
  animation: orb 26s var(--ease) infinite alternate;
}

.bg-orbs span:nth-child(1) {
  background: #6d4aff;
  top: -18vmax;
  left: -12vmax;
}

.bg-orbs span:nth-child(2) {
  background: #0ea5e9;
  bottom: -22vmax;
  right: -14vmax;
  animation-duration: 32s;
  opacity: 0.25;
}

.bg-orbs span:nth-child(3) {
  background: #ff4d8d;
  top: 40%;
  left: 55%;
  width: 30vmax;
  height: 30vmax;
  animation-duration: 38s;
  opacity: 0.16;
}

[data-theme='light'] .bg-orbs span {
  opacity: 0.18;
}

[data-theme='light'] .bg-orbs span:nth-child(3) {
  opacity: 0.1;
}

@keyframes orb {
  0% {
    transform: translate(0, 0) scale(1);
  }
  50% {
    transform: translate(6vmax, 4vmax) scale(1.1);
  }
  100% {
    transform: translate(-4vmax, 8vmax) scale(0.95);
  }
}

/* Sólo padding lateral: .hero, .section, .footer… ponen el vertical con padding-block
   (con el atajo `padding` se pisaban entre sí y el contenido quedaba pegado al borde). */
.container {
  width: 100%;
  max-width: var(--container);
  margin: 0 auto;
  padding-inline: clamp(20px, 2.6vw, 48px);
}

.app {
  min-height: calc(100vh - var(--topbar-h));
  padding-bottom: 48px;
}

.page {
  animation: page-in 0.45s var(--ease) backwards; /* sin «both»: no deja transform y no rompe position: fixed */
}

@keyframes page-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ───────────────────────────── Topbar ───────────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--topbar-h);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  border-bottom: 1px solid var(--border);
}

.topbar .container {
  height: 100%;
  display: flex;
  align-items: center;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.35rem;
  letter-spacing: -0.03em;
}

.brand-logo {
  width: 36px;
  height: 36px;
  flex: none;
  filter: drop-shadow(0 4px 14px rgba(124, 92, 255, 0.5));
  transition: transform 0.4s var(--ease-bounce);
}

.brand:hover .brand-logo {
  transform: rotate(-10deg) scale(1.08);
}

.brand-name span {
  background: var(--grad-accent);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.nav {
  display: flex;
  gap: 4px;
  margin-left: 12px;
}

.nav a {
  padding: 8px 14px;
  border-radius: 999px;
  color: var(--text-2);
  font-weight: 500;
  transition: background 0.2s, color 0.2s;
}

.nav a:hover {
  color: var(--text);
  background: var(--surface);
}

.nav a.active {
  color: var(--text);
  background: var(--surface-2);
}

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.online-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-2);
  background: var(--surface);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 0 rgba(46, 229, 157, 0.6);
  animation: ping 2s infinite;
  flex: none;
}

.dot.off {
  background: var(--text-3);
  animation: none;
}

.dot.warn {
  background: var(--yellow);
  animation: none;
}

@keyframes ping {
  0% {
    box-shadow: 0 0 0 0 rgba(46, 229, 157, 0.55);
  }
  70% {
    box-shadow: 0 0 0 8px rgba(46, 229, 157, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(46, 229, 157, 0);
  }
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  transition: background 0.2s, color 0.2s, transform 0.15s;
}

.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.icon-btn:active {
  transform: scale(0.94);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

.profile-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 14px 4px 4px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-weight: 600;
  transition: background 0.2s, border-color 0.2s;
  max-width: 220px;
}

.profile-chip:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
}

.profile-chip .name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.avatar {
  --c: var(--accent);
  width: 34px;
  height: 34px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 1.15rem;
  line-height: 1;
  background: radial-gradient(circle at 30% 25%, color-mix(in srgb, var(--c) 55%, white 10%), color-mix(in srgb, var(--c) 70%, black 30%));
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--c) 60%, transparent), inset 0 -2px 6px rgba(0, 0, 0, 0.25);
}

.avatar.lg {
  width: 64px;
  height: 64px;
  font-size: 2rem;
}

.avatar.sm {
  width: 26px;
  height: 26px;
  font-size: 0.9rem;
}

/* ───────────────────────────── Botones ───────────────────────────── */

.btn {
  --btn-bg: var(--surface-2);
  --btn-fg: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 18px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  user-select: none;
  transition: transform 0.15s var(--ease), background 0.2s, box-shadow 0.25s, border-color 0.2s, opacity 0.2s;
}

.btn:hover {
  background: var(--surface-3);
  border-color: var(--border-strong);
}

.btn:active {
  transform: translateY(1px) scale(0.98);
}

.btn:disabled,
.btn[aria-disabled='true'] {
  opacity: 0.45;
  pointer-events: none;
}

.btn svg {
  width: 18px;
  height: 18px;
  flex: none;
}

.btn-primary {
  border: 0;
  color: var(--text-on-accent);
  background: var(--grad-accent);
  background-size: 160% 160%;
  background-position: 0% 50%;
  box-shadow: 0 6px 22px rgba(124, 92, 255, 0.38), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.btn-primary:hover {
  background: var(--grad-accent);
  background-size: 160% 160%;
  background-position: 100% 50%;
  box-shadow: 0 10px 30px rgba(124, 92, 255, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.btn-warm {
  border: 0;
  color: #fff;
  background: var(--grad-warm);
  box-shadow: 0 6px 22px rgba(255, 77, 141, 0.35);
}

.btn-warm:hover {
  background: var(--grad-warm);
  filter: brightness(1.08);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-2);
}

.btn-ghost:hover {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-danger {
  --btn-fg: var(--red);
  background: rgba(255, 84, 112, 0.1);
  border-color: rgba(255, 84, 112, 0.25);
}

.btn-danger:hover {
  background: rgba(255, 84, 112, 0.18);
  border-color: rgba(255, 84, 112, 0.4);
}

.btn-sm {
  min-height: 34px;
  padding: 0 12px;
  font-size: 0.85rem;
  border-radius: 10px;
}

.btn-lg {
  min-height: 52px;
  padding: 0 26px;
  font-size: 1.05rem;
  border-radius: 14px;
}

.btn-block {
  width: 100%;
}

.btn-icon {
  padding: 0;
  width: 42px;
}

.btn-icon.btn-sm {
  width: 34px;
}

/* Control segmentado */
.seg {
  display: inline-flex;
  padding: 4px;
  gap: 2px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  flex-wrap: wrap;
}

.seg button {
  border: 0;
  background: transparent;
  color: var(--text-2);
  padding: 7px 14px;
  border-radius: 9px;
  font-weight: 600;
  font-size: 0.9rem;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s;
}

.seg button:hover {
  color: var(--text);
}

.seg button.active {
  color: var(--text);
  background: var(--surface-3);
  box-shadow: var(--shadow-sm);
}

[data-theme='light'] .seg button.active {
  background: #fff;
}

/* Inputs */
.input {
  width: 100%;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

.input::placeholder {
  color: var(--text-3);
}

.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
  background: var(--surface-2);
}

.field {
  display: grid;
  gap: 6px;
}

.field > label,
.label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.kbd {
  display: inline-block;
  min-width: 22px;
  padding: 1px 6px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  text-align: center;
  color: var(--text-2);
  background: var(--surface);
}

/* ───────────────────────────── Superficies ───────────────────────────── */

.panel {
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow-sm);
}

.panel-pad {
  padding: 20px;
}

.panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.chip svg {
  width: 14px;
  height: 14px;
}

.chip.accent {
  color: #cdbfff;
  background: rgba(124, 92, 255, 0.16);
  border-color: rgba(124, 92, 255, 0.3);
}

.chip.cyan {
  color: #a5f3fc;
  background: rgba(34, 211, 238, 0.12);
  border-color: rgba(34, 211, 238, 0.28);
}

.chip.pink {
  color: #ffc2d8;
  background: rgba(255, 77, 141, 0.12);
  border-color: rgba(255, 77, 141, 0.28);
}

.chip.green {
  color: #a7f3d0;
  background: rgba(46, 229, 157, 0.12);
  border-color: rgba(46, 229, 157, 0.28);
}

[data-theme='light'] .chip.accent {
  color: #5b3fd9;
}

[data-theme='light'] .chip.cyan {
  color: #0e7490;
}

[data-theme='light'] .chip.pink {
  color: #be185d;
}

[data-theme='light'] .chip.green {
  color: #047857;
}

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

.faint {
  color: var(--text-3);
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.row.wrap {
  flex-wrap: wrap;
}

.col {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.grow {
  flex: 1 1 auto;
  min-width: 0;
}

.spacer {
  flex: 1;
}

.center {
  display: grid;
  place-items: center;
  text-align: center;
}

.hidden {
  display: none !important;
}

.mono {
  font-family: var(--font-mono);
}

/* ───────────────────────────── Modal ───────────────────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(5, 6, 18, 0.62);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: fade-in 0.2s ease both;
}

.modal-backdrop.closing {
  animation: fade-out 0.18s ease both;
}

.modal {
  width: min(520px, 100%);
  max-height: min(86vh, 900px);
  overflow: auto;
  border-radius: var(--radius-lg);
  background: var(--surface-solid);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.35s var(--ease-bounce) both;
}

.modal.wide {
  width: min(760px, 100%);
}

.modal-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 22px 6px;
}

.modal-head h2 {
  font-size: 1.35rem;
}

.modal-body {
  padding: 12px 22px 18px;
  color: var(--text-2);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 0 22px 22px;
  flex-wrap: wrap;
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

@keyframes fade-out {
  to {
    opacity: 0;
  }
}

.howto-list {
  display: grid;
  gap: 10px;
  padding: 0;
  margin: 0;
  list-style: none;
  counter-reset: step;
}

.howto-list li {
  position: relative;
  padding-left: 40px;
  color: var(--text-2);
}

.howto-list li::before {
  counter-increment: step;
  content: counter(step);
  position: absolute;
  left: 0;
  top: -1px;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 700;
  color: #fff;
  background: var(--grad-accent);
}

/* ───────────────────────────── Toasts ───────────────────────────── */

.toasts {
  position: fixed;
  z-index: 300;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  display: grid;
  gap: 8px;
  justify-items: center;
  pointer-events: none;
  width: min(92vw, 420px);
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-radius: 14px;
  background: var(--surface-solid-2);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow);
  font-weight: 500;
  animation: toast-in 0.35s var(--ease-bounce) both;
}

.toast.leaving {
  animation: toast-out 0.25s ease both;
}

.toast .t-icon {
  font-size: 1.1rem;
}

.toast.success {
  border-color: rgba(46, 229, 157, 0.4);
}

.toast.error {
  border-color: rgba(255, 84, 112, 0.45);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.95);
  }
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(8px);
  }
}

/* ───────────────────────────── Portada ───────────────────────────── */

.hero {
  position: relative;
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  align-items: center;
  gap: 32px;
  padding-block: 56px 36px;
}

.hero-kicker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px 6px 8px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-2);
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 20px;
}

.hero-kicker b {
  padding: 2px 8px;
  border-radius: 999px;
  color: #fff;
  font-size: 0.75rem;
  background: var(--grad-warm);
}

.hero-title {
  font-size: clamp(2.6rem, 6vw, 4.6rem);
  font-weight: 800;
  letter-spacing: -0.045em;
  line-height: 1.02;
}

.hero-title .grad {
  background: linear-gradient(120deg, #a78bfa 0%, #60a5fa 40%, #22d3ee 70%, #f472b6 100%);
  background-size: 200% auto;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: shine 8s linear infinite;
}

@keyframes shine {
  to {
    background-position: 200% center;
  }
}

.hero-sub {
  margin-top: 18px;
  max-width: 520px;
  font-size: 1.15rem;
  color: var(--text-2);
}

.hero-cta {
  display: flex;
  gap: 12px;
  margin-top: 30px;
  flex-wrap: wrap;
}

.hero-stats {
  display: flex;
  gap: 28px;
  margin-top: 36px;
  flex-wrap: wrap;
}

.hero-stat b {
  display: block;
  font-size: 1.7rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.hero-stat span {
  color: var(--text-3);
  font-size: 0.9rem;
}

.hero-art {
  position: relative;
  aspect-ratio: 1 / 1;
  max-width: 460px;
  width: 100%;
  justify-self: center;
}

.hero-art .tile {
  position: absolute;
  display: grid;
  place-items: center;
  border-radius: 26px;
  box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255, 255, 255, 0.3);
  animation: float 7s ease-in-out infinite;
  color: #fff;
}

.hero-art .tile svg {
  width: 56%;
  height: 56%;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.25));
}

@keyframes float {
  0%,
  100% {
    transform: translateY(0) rotate(var(--r, 0deg));
  }
  50% {
    transform: translateY(-14px) rotate(calc(var(--r, 0deg) + 3deg));
  }
}

.section {
  padding-block: 28px;
}

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.section-title {
  font-size: 1.7rem;
  font-weight: 800;
}

.section-sub {
  color: var(--text-2);
  margin-top: 4px;
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 18px;
}

.game-card {
  --g1: #7c5cff;
  --g2: #22d3ee;
  position: relative;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  overflow: hidden;
  isolation: isolate;
  transition: transform 0.35s var(--ease), box-shadow 0.35s var(--ease), border-color 0.3s;
  animation: card-in 0.5s var(--ease) both;
}

.game-card::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background: radial-gradient(400px 200px at 50% 0%, color-mix(in srgb, var(--g1) 22%, transparent), transparent 70%);
  opacity: 0;
  transition: opacity 0.35s;
}

.game-card:hover {
  transform: translateY(-6px);
  border-color: color-mix(in srgb, var(--g1) 45%, transparent);
  box-shadow: 0 20px 50px -12px color-mix(in srgb, var(--g1) 50%, transparent);
}

.game-card:hover::before {
  opacity: 1;
}

@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
}

.game-card-art {
  position: relative;
  height: 150px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--g1), var(--g2));
  overflow: hidden;
}

.game-card-art::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 20% 15%, rgba(255, 255, 255, 0.35), transparent 40%),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.05) 0 12px, transparent 12px 24px);
}

.game-card-art > svg {
  position: relative;
  z-index: 1;
  width: 84px;
  height: 84px;
  color: #fff;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.3));
  transition: transform 0.5s var(--ease-bounce);
}

.game-card:hover .game-card-art > svg {
  transform: scale(1.12) rotate(-6deg);
}

.game-card-badges {
  position: absolute;
  z-index: 2;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  gap: 6px;
}

.badge-glass {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #fff;
  background: rgba(10, 10, 30, 0.32);
  border: 1px solid rgba(255, 255, 255, 0.25);
  backdrop-filter: blur(8px);
}

.badge-glass svg {
  width: 13px;
  height: 13px;
}

.game-card-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px 18px 18px;
  flex: 1;
}

.game-card-body h3 {
  font-size: 1.2rem;
  font-weight: 700;
}

.game-card-body p {
  color: var(--text-2);
  font-size: 0.93rem;
}

.game-card-foot {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: auto;
  padding-top: 10px;
}

.game-card-stat {
  margin-left: auto;
  font-size: 0.78rem;
  color: var(--text-3);
  align-self: center;
}

.filters {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.search {
  position: relative;
  width: 240px;
  max-width: 100%;
}

.search svg {
  position: absolute;
  left: 12px;
  top: 50%;
  width: 18px;
  height: 18px;
  transform: translateY(-50%);
  color: var(--text-3);
}

.search .input {
  padding-left: 38px;
  min-height: 42px;
}

.rooms-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.room-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  animation: card-in 0.4s var(--ease) both;
}

.room-row .mini-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  flex: none;
  color: #fff;
}

.room-row .mini-icon svg {
  width: 24px;
  height: 24px;
}

.room-row .meta {
  min-width: 0;
  flex: 1;
}

.room-row .meta b {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.room-row .meta span {
  font-size: 0.85rem;
  color: var(--text-3);
}

.empty-note {
  padding: 22px;
  border-radius: var(--radius);
  border: 1px dashed var(--border-strong);
  color: var(--text-3);
  text-align: center;
}

.feature-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.feature {
  display: flex;
  gap: 14px;
  padding: 18px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
}

.feature-icon {
  width: 44px;
  height: 44px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 14px;
  color: #fff;
}

.feature-icon svg {
  width: 22px;
  height: 22px;
}

.feature b {
  display: block;
  margin-bottom: 2px;
}

.feature p {
  color: var(--text-2);
  font-size: 0.92rem;
}

.footer {
  margin-top: 40px;
  padding-block: 28px;
  border-top: 1px solid var(--border);
  color: var(--text-3);
  font-size: 0.9rem;
}

/* ───────────────────────────── Cabecera de juego ───────────────────────────── */

.game-head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 22px 0 18px;
  flex-wrap: wrap;
}

.game-icon {
  width: 52px;
  height: 52px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 16px;
  color: #fff;
  box-shadow: 0 8px 24px -6px var(--g1, rgba(0, 0, 0, 0.4)), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.game-icon svg {
  width: 30px;
  height: 30px;
}

.game-head h1 {
  font-size: 1.7rem;
  font-weight: 800;
}

.game-head .sub {
  color: var(--text-2);
  font-size: 0.95rem;
}

.game-head .actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Barra de herramientas estándar para juegos */
.game-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.stat-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.stat {
  display: flex;
  flex-direction: column;
  min-width: 86px;
  padding: 8px 14px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.stat .k {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
}

.stat .v {
  font-size: 1.15rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.solo-stage {
  position: relative;
}

.stage-loading {
  min-height: 320px;
  display: grid;
  place-items: center;
  gap: 12px;
  color: var(--text-3);
}

.spinner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid var(--surface-3);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Panel de fin de partida reutilizable (juegos en solitario) */
.end-card {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 16px;
  border-radius: inherit;
  background: color-mix(in srgb, var(--bg) 55%, transparent);
  backdrop-filter: blur(4px);
  animation: fade-in 0.3s ease both;
}

.end-card .inner {
  display: grid;
  gap: 12px;
  justify-items: center;
  text-align: center;
  padding: 26px 30px;
  border-radius: var(--radius-lg);
  background: var(--surface-solid);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.45s var(--ease-bounce) both;
  max-width: 360px;
}

.end-card .emoji {
  font-size: 3rem;
  line-height: 1;
}

.end-card h2 {
  font-size: 1.6rem;
}

/* ───────────────────────────── Lobby ───────────────────────────── */

.lobby-hero {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 24px;
  align-items: center;
  padding: 26px;
  margin: 8px 0 22px;
  border-radius: var(--radius-xl);
  overflow: hidden;
  isolation: isolate;
  background: var(--surface);
  border: 1px solid var(--border);
}

.lobby-hero::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background: radial-gradient(600px 300px at 0% 0%, color-mix(in srgb, var(--g1) 35%, transparent), transparent 70%),
    radial-gradient(500px 300px at 100% 100%, color-mix(in srgb, var(--g2) 25%, transparent), transparent 70%);
}

.lobby-hero .game-icon {
  width: 96px;
  height: 96px;
  border-radius: 28px;
}

.lobby-hero .game-icon svg {
  width: 58px;
  height: 58px;
}

.lobby-hero h1 {
  font-size: clamp(2rem, 4vw, 2.8rem);
  font-weight: 800;
}

.lobby-hero p {
  color: var(--text-2);
  margin-top: 6px;
  max-width: 640px;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.mode-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  transition: transform 0.3s var(--ease), border-color 0.3s, box-shadow 0.3s;
}

.mode-card:hover {
  transform: translateY(-3px);
  border-color: var(--border-strong);
  box-shadow: var(--shadow);
}

.mode-card.featured {
  border-color: rgba(124, 92, 255, 0.45);
  background: linear-gradient(160deg, rgba(124, 92, 255, 0.16), rgba(34, 211, 238, 0.06)), var(--surface);
}

.mode-card .mode-icon {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  color: #fff;
}

.mode-card .mode-icon svg {
  width: 24px;
  height: 24px;
}

.mode-card h3 {
  font-size: 1.15rem;
}

.mode-card p {
  color: var(--text-2);
  font-size: 0.92rem;
  flex: 1;
}

.code-input {
  text-transform: uppercase;
  letter-spacing: 0.3em;
  font-family: var(--font-mono);
  font-weight: 700;
  text-align: center;
}

.options-bar {
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

/* ───────────────────────────── Partida (marco multijugador) ───────────────────────────── */

.match-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 20px;
  align-items: start;
}

.match-grid.no-side {
  grid-template-columns: minmax(0, 1fr);
}

.players-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.player-chip {
  --c: var(--accent);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  min-width: 0;
  transition: border-color 0.3s, box-shadow 0.3s, background 0.3s;
}

.player-chip.right {
  flex-direction: row-reverse;
  text-align: right;
}

.player-chip.active {
  border-color: color-mix(in srgb, var(--c) 70%, transparent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 22%, transparent), 0 10px 30px -10px color-mix(in srgb, var(--c) 60%, transparent);
  background: color-mix(in srgb, var(--c) 8%, var(--surface));
}

.player-chip .info {
  min-width: 0;
}

.player-chip .pname {
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-chip .pside {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-3);
}

.player-chip.right .pside {
  justify-content: flex-end;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid rgba(127, 127, 127, 0.5);
  flex: none;
}

.thinking-dots {
  display: inline-flex;
  gap: 3px;
}

.thinking-dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  animation: blink 1.2s infinite;
}

.thinking-dots i:nth-child(2) {
  animation-delay: 0.2s;
}

.thinking-dots i:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes blink {
  0%,
  80%,
  100% {
    opacity: 0.25;
  }
  40% {
    opacity: 1;
  }
}

.turn-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.92rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.turn-pill.mine {
  color: #fff;
  border-color: transparent;
  background: var(--grad-accent);
  box-shadow: 0 6px 20px rgba(124, 92, 255, 0.4);
  animation: pulse-soft 2s ease-in-out infinite;
}

.turn-pill.win {
  color: #062b1d;
  background: var(--green);
  border-color: transparent;
}

.turn-pill.lose {
  color: #fff;
  background: var(--red);
  border-color: transparent;
}

@keyframes pulse-soft {
  50% {
    box-shadow: 0 6px 28px rgba(124, 92, 255, 0.65);
  }
}

.stage {
  position: relative;
  min-height: 360px;
}

.stage-overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  /* Si la tarjeta no cabe sobre un tablero bajo, se desplaza dentro en vez de tapar lo de debajo. */
  place-items: safe center;
  overflow-y: auto;
  padding: 16px;
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--bg) 50%, transparent);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  animation: fade-in 0.3s ease both;
}

/* Sala en espera: la tarjeta es el único contenido del escenario y define su altura
   (superpuesta no cabe en los 360 px del móvil y tapaba el chat). */
.stage-overlay[data-waiting] {
  position: relative;
  inset: auto;
  min-height: 360px;
}

.overlay-card {
  display: grid;
  gap: 14px;
  justify-items: center;
  text-align: center;
  width: min(420px, 100%);
  padding: 28px;
  border-radius: var(--radius-lg);
  background: var(--surface-solid);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.45s var(--ease-bounce) both;
}

.overlay-card .big-emoji {
  font-size: 3.4rem;
  line-height: 1;
}

.overlay-card h2 {
  font-size: 1.8rem;
  font-weight: 800;
}

.overlay-card .actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.room-code {
  display: flex;
  gap: 6px;
  justify-content: center;
}

.room-code span {
  width: 46px;
  height: 56px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  font-family: var(--font-mono);
  font-size: 1.6rem;
  font-weight: 700;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
}

.waiting-anim {
  position: relative;
  width: 80px;
  height: 80px;
}

.waiting-anim::before,
.waiting-anim::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid var(--accent);
  opacity: 0;
  animation: radar 2s ease-out infinite;
}

.waiting-anim::after {
  animation-delay: 1s;
  border-color: var(--accent-2);
}

.waiting-anim .avatar {
  position: absolute;
  inset: 18px;
  width: auto;
  height: auto;
}

@keyframes radar {
  0% {
    transform: scale(0.4);
    opacity: 1;
  }
  100% {
    transform: scale(1.3);
    opacity: 0;
  }
}

.side {
  display: grid;
  gap: 16px;
  position: sticky;
  top: calc(var(--topbar-h) + 16px);
}

.chat {
  display: flex;
  flex-direction: column;
  height: 460px;
}

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
}

.chat-msg {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  animation: card-in 0.25s var(--ease) both;
}

/* El ancho máximo va en el contenedor: un % en la burbuja (cuyo padre se ajusta al
   contenido) la partía en líneas aunque hubiera sitio. */
.chat-msg > div:last-child {
  min-width: 0;
  max-width: 85%;
}

.chat-msg .bubble {
  max-width: 100%;
  padding: 8px 12px;
  border-radius: 14px 14px 14px 4px;
  background: var(--surface-2);
  font-size: 0.92rem;
  overflow-wrap: anywhere;
}

.chat-msg .who {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-3);
  margin-bottom: 2px;
}

.chat-msg.mine {
  flex-direction: row-reverse;
}

.chat-msg.mine .bubble {
  border-radius: 14px 14px 4px 14px;
  background: var(--accent-soft);
  border: 1px solid rgba(124, 92, 255, 0.3);
}

.chat-msg.system {
  justify-content: center;
}

.chat-msg.system .bubble {
  background: transparent;
  color: var(--text-3);
  font-size: 0.8rem;
  padding: 2px 8px;
  text-align: center;
}

.chat-msg.big .bubble {
  font-size: 1.8rem;
  background: transparent;
  border: 0;
  padding: 0 4px;
}

.chat-form {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
}

.reactions {
  display: flex;
  gap: 4px;
  padding: 8px 12px 0;
  flex-wrap: wrap;
}

.reactions button {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  padding: 3px 8px;
  font-size: 1rem;
  transition: transform 0.15s var(--ease-bounce), background 0.2s;
}

.reactions button:hover {
  transform: scale(1.15);
  background: var(--surface-2);
}

.info-list {
  display: grid;
  gap: 10px;
  padding: 16px 20px;
  color: var(--text-2);
  font-size: 0.92rem;
}

.info-list .row {
  justify-content: space-between;
}

/* ───────────────────────────── Perfil ───────────────────────────── */

.avatar-picker {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 8px;
}

.avatar-picker button {
  aspect-ratio: 1;
  border-radius: 12px;
  border: 2px solid transparent;
  background: var(--surface-2);
  font-size: 1.4rem;
  transition: transform 0.15s var(--ease-bounce), border-color 0.2s;
}

.avatar-picker button:hover {
  transform: scale(1.08);
}

.avatar-picker button.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.color-picker {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.color-picker button {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid transparent;
  box-shadow: 0 0 0 1px var(--border-strong);
  transition: transform 0.15s var(--ease-bounce);
}

.color-picker button.active {
  border-color: var(--surface-solid);
  box-shadow: 0 0 0 2px var(--text);
  transform: scale(1.1);
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.stats-table th,
.stats-table td {
  padding: 8px 6px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.stats-table th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
}

.stats-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ───────────────────────────── Animaciones utilitarias ───────────────────────────── */

.anim-pop {
  animation: pop 0.35s var(--ease-bounce) both;
}

.anim-shake {
  animation: shake 0.4s ease both;
}

@keyframes pop {
  0% {
    transform: scale(0.6);
    opacity: 0;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes shake {
  20%,
  60% {
    transform: translateX(-6px);
  }
  40%,
  80% {
    transform: translateX(6px);
  }
}

.confetti-canvas {
  position: fixed;
  inset: 0;
  z-index: 400;
  pointer-events: none;
}

/* ───────────────────────────── Responsive ───────────────────────────── */

@media (max-width: 980px) {
  .match-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .side {
    position: static;
  }

  .chat {
    height: 360px;
  }
}

@media (max-width: 860px) {
  .hero {
    grid-template-columns: 1fr;
    padding-top: 32px;
  }

  .hero-art {
    max-width: 320px;
    order: -1;
  }

  .nav {
    display: none;
  }
}

@media (max-width: 640px) {
  :root {
    --topbar-h: 60px;
  }

  .container {
    padding-inline: 14px;
  }

  .hero-stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px 20px;
  }

  .online-pill .pill-text {
    display: none;
  }

  .profile-chip {
    padding: 3px;
  }

  .profile-chip .name {
    display: none;
  }

  .brand-name {
    font-size: 1.15rem;
  }

  .players-bar {
    grid-template-columns: 1fr 1fr;
  }

  .players-bar .turn-pill {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-self: center;
  }

  .lobby-hero {
    grid-template-columns: 1fr;
    padding: 20px;
  }

  .lobby-hero .game-icon {
    width: 72px;
    height: 72px;
  }

  .game-head .actions {
    margin-left: 0;
    width: 100%;
  }

  .avatar-picker {
    grid-template-columns: repeat(6, 1fr);
  }

  .game-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
  }

  .game-card-art {
    height: 110px;
  }

  .game-card-art > svg {
    width: 60px;
    height: 60px;
  }

  .game-card-body {
    padding: 12px 14px 14px;
  }

  .game-card-body p {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Iconos dentro de cabeceras de panel */
.panel-head > svg {
  width: 18px;
  height: 18px;
  flex: none;
  color: var(--text-3);
}

.chat-msg.system > div {
  flex: 1;
  display: grid;
  justify-items: center;
}

.chat-msg.system .bubble {
  max-width: 100%;
}

.badge-glass {
  white-space: nowrap;
}

@media (max-width: 640px) {
  .badge-glass {
    padding: 3px 8px;
    font-size: 0.66rem;
  }

  .badge-glass .bt {
    display: none;
  }

  .game-card-foot .chip:nth-child(n + 2) {
    display: none;
  }
}

.stats-table th:not(:first-child) {
  text-align: right;
}

.toasts.top {
  top: calc(var(--topbar-h) + 12px);
  bottom: auto;
}

.seg.disabled {
  opacity: 0.5;
}

.seg button:disabled {
  cursor: default;
  opacity: 0.45;
}

/* Cabecera de juego compacta en móvil */
@media (max-width: 640px) {
  .game-head {
    gap: 8px 10px;
    padding: 12px 0 12px;
  }

  .game-head > .btn-icon {
    width: 36px;
    min-height: 36px;
  }

  .game-head > :nth-child(3) {
    flex: 1;
    min-width: 0;
  }

  .game-head .game-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
  }

  .game-head .game-icon svg {
    width: 24px;
    height: 24px;
  }

  .game-head h1 {
    font-size: 1.3rem;
  }

  .game-head .sub {
    display: none;
  }

  .game-head .actions {
    gap: 6px;
  }

  .game-head .actions .btn {
    min-height: 34px;
    padding: 0 10px;
    font-size: 0.85rem;
  }

  .overlay-card {
    padding: 20px 16px;
    gap: 10px;
  }

  .overlay-card .big-emoji {
    font-size: 2.6rem;
  }

  .overlay-card h2 {
    font-size: 1.5rem;
  }
}

/* Solitario en móvil: acciones de la cabecera en la misma fila que el título */
@media (max-width: 640px) {
  .solo .game-head {
    flex-wrap: nowrap;
  }

  .solo .game-head h1 {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .solo .game-head .actions {
    width: auto;
    margin-left: auto;
    flex: none;
  }

  .solo .game-head .actions .chip {
    display: none;
  }

  .solo .game-head .actions .btn {
    width: 36px;
    padding: 0;
    gap: 0;
    font-size: 0;
  }
}

.stat .k {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 640px) {
  .stat .k {
    font-size: 0.62rem;
    letter-spacing: 0.03em;
  }
}

/* ───────── Ajustes finales tras la revisión ───────── */

.player-chip .pname {
  display: flex;
  min-width: 0;
}

.player-chip.right .pname {
  justify-content: flex-end;
}

.player-chip .pname .nm {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.player-chip .pname .you {
  flex: none;
  font-weight: 500;
  white-space: pre;
}

.player-chip .pside {
  white-space: nowrap;
  min-width: 0;
}

.stat .k {
  max-width: 100%;
}

.end-card .inner {
  max-width: 420px;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

/* Partida en móvil: acciones como iconos en la fila del título */
@media (max-width: 640px) {
  .match .game-head {
    flex-wrap: nowrap;
  }

  .match .game-head h1 {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .match .game-head .actions {
    width: auto;
    margin-left: auto;
    flex: none;
    flex-wrap: nowrap;
  }

  .match .game-head .actions .btn {
    width: 36px;
    padding: 0;
    gap: 0;
    font-size: 0;
  }

  .players-bar {
    gap: 8px;
    margin-bottom: 12px;
  }

  .player-chip {
    padding: 8px 10px;
    gap: 8px;
  }

  .player-chip .avatar {
    width: 30px;
    height: 30px;
    font-size: 1rem;
  }

  .toasts.top {
    top: calc(var(--topbar-h) + 60px);
  }
}

/* Partidas de 3–4 jugadores */
.players-bar.multi {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}

.players-bar.multi .turn-pill {
  align-self: center;
}

.players-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
}

.player-chip.is-out {
  opacity: 0.5;
  filter: grayscale(0.6);
}

.waiting-players {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

.waiting-players .chip {
  padding: 3px 10px 3px 3px;
  font-size: 0.85rem;
}

.waiting-players .waiting-slot {
  padding: 5px 12px;
  border-style: dashed;
  opacity: 0.6;
}

@media (max-width: 640px) {
  .players-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .players-bar.multi .player-chip.right {
    flex-direction: row;
    text-align: left;
  }
}

/* Pantallas bajas (portátiles): marco de partida más compacto para que el tablero quepa */
@media (min-width: 641px) and (max-height: 820px) {
  .match .game-head {
    padding: 10px 0 10px;
  }

  .match .game-head .game-icon {
    width: 42px;
    height: 42px;
    border-radius: 13px;
  }

  .match .game-head .game-icon svg {
    width: 26px;
    height: 26px;
  }

  .match .game-head h1 {
    font-size: 1.4rem;
  }

  .players-bar {
    margin-bottom: 10px;
  }

  .player-chip {
    padding: 6px 12px;
  }

  .player-chip .avatar {
    width: 30px;
    height: 30px;
  }
}

/* Pantallas anchas: aprovechar más el ancho total */
@media (min-width: 1400px) {
  .hero-art {
    max-width: 580px;
  }

  .hero-sub {
    max-width: 620px;
    font-size: 1.22rem;
  }

  .game-grid {
    grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
    gap: 22px;
  }

  .match-grid {
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: 28px;
  }

  .mode-grid {
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  }
}

/* Logo según el tema activo */
.logo-brutal {
  display: none;
}

:root[data-style='brutal'] .logo-retro {
  display: none;
}

:root[data-style='brutal'] .logo-brutal {
  display: block;
}

/* Barra superior en móvil: que nunca desborde */
@media (max-width: 640px) {
  .hide-sm {
    display: none !important;
  }

  .topbar .container {
    gap: 8px;
  }

  .topbar-right {
    gap: 6px;
  }
}

@media (max-width: 480px) {
  .online-pill {
    display: none;
  }
}

@media (max-width: 380px) {
  .brand {
    gap: 6px;
  }

  .brand-logo {
    width: 30px !important;
    height: 30px !important;
  }

  .topbar .icon-btn {
    width: 36px;
    height: 36px;
  }
}

/* Barra superior en anchos de portátil: compactar antes de que desborde */
@media (max-width: 1200px) {
  .online-pill .pill-text,
  .profile-chip .name {
    display: none;
  }

  .profile-chip {
    padding: 3px !important;
  }
}

@media (max-width: 1040px) {
  .nav {
    gap: 6px !important;
    margin-left: 4px !important;
  }

  .nav a {
    padding-inline: 9px !important;
  }

  :root[data-style='retro'] .nav a {
    font-size: 0.68rem;
  }
}

.player-chip .pside .lbl {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

/* Moneda según el tema activo */
.coin-brutal {
  display: none;
}

:root[data-style='brutal'] .coin-retro {
  display: none;
}

:root[data-style='brutal'] .coin-brutal {
  display: block;
}

/* Fichas de jugador: el estado («pensando», «Fuera») nunca empuja la ficha fuera de la pantalla */
.player-chip {
  overflow: hidden;
}

.player-chip .pside {
  overflow: hidden;
}

.player-chip .thinking-dots {
  flex: none;
}
