:root {
  --bg: #10141a;
  --bg-soft: #171c24;
  --panel: #1d2430;
  --line: #2c3646;
  --text: #e8ecf1;
  --text-dim: #9aa5b4;
  --accent: #5fb0ff;
  --danger: #ff5f6d;
  --card-w: 110px;
  --card-h: 154px;
  --opp-card-w: 44px; /* mano de oponentes: 60% más pequeña que --card-w/--card-h */
  --opp-card-h: 62px;
  --radius: 10px;

  /* Overlay de nombre/descripción sobre las cartas — edita libremente estos números. */
  --card-overlay-opacity: 0.6; /* 0 (invisible) a 1 (opaco) */
  --card-name-margin: 5%; /* separación desde arriba/izquierda/derecha */
  --card-name-height: 15%; /* alto de la caja del nombre */
  --card-desc-margin: 5%; /* separación desde abajo/izquierda/derecha */
  --card-desc-height: 30%; /* alto de la caja de la descripción */
}

.lang-switcher {
  position: fixed;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 1100;
  display: flex;
  gap: 2px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
}

.lang-btn {
  border: none;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  cursor: pointer;
}

.lang-btn.selected {
  background: var(--accent);
  color: #0b1522;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: radial-gradient(circle at top, var(--bg-soft), var(--bg) 70%);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

/* --- Menu screen --- */
.menu-screen {
  position: relative;
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2rem;
  text-align: center;
  padding: 1.5rem;
}

.menu-tagline {
  position: absolute;
  bottom: 1rem;
  left: 1.25rem;
  margin: 0;
  font-size: 0.75rem;
  color: var(--text-dim);
}

.footer-block,
.topbar-footer {
  max-width: min(62vw, 320px);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.2rem;
  text-align: right;
}

.footer-block {
  position: absolute;
  bottom: 1rem;
  right: 1.25rem;
}

.site-footer {
  font-size: 0.75rem;
  line-height: 1.3;
  color: var(--text-dim);
  text-decoration: none;
}

.credits-link {
  font-size: 0.68rem;
  color: var(--text-dim);
  text-decoration: none;
}

.site-footer:hover,
.credits-link:hover {
  color: var(--accent);
  text-decoration: underline;
}

.menu-title {
  margin: 0;
  font-size: clamp(2rem, 6vw, 3rem);
  letter-spacing: 0.03em;
  color: var(--accent);
}

.credits-screen {
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  text-align: center;
  padding: 2rem 1.5rem;
}

.credits-screen h2 {
  margin: 0;
  color: var(--text);
  font-size: 1.1rem;
}

.credits-screen p {
  max-width: 480px;
  margin: 0;
  color: var(--text-dim);
  line-height: 1.6;
}

.credits-screen p a {
  color: var(--accent);
}

.menu-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.menu-label {
  color: var(--text-dim);
  font-size: 0.95rem;
}

.opponent-count-picker {
  display: flex;
  gap: 0.6rem;
}

.count-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.15s ease, background 0.15s ease;
}

.count-btn:hover {
  border-color: var(--accent);
}

.count-btn.selected {
  background: var(--accent);
  color: #0a1420;
  border-color: var(--accent);
}

.btn {
  display: inline-block;
  border: none;
  border-radius: 8px;
  padding: 0.7rem 2rem;
  font-size: 1rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.1s ease, filter 0.15s ease;
}

.btn:hover {
  filter: brightness(1.1);
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent);
  color: #0a1420;
}

/* --- Top bar --- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.logo {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: 0.05em;
  color: var(--accent);
}

.turn-indicator {
  font-size: 0.95rem;
  color: var(--text-dim);
}

#active-player-name {
  color: var(--accent);
  font-weight: 600;
}

/* --- Board layout --- */
.board {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem;
  /* Deja hueco para la mano del jugador, que va fija al fondo de la ventana. */
  padding-bottom: calc(var(--card-h) + 5rem);
}

.player-area {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* La mano del jugador se queda siempre fija abajo del todo: no debe moverse
   por el contenido de encima (log, oponentes...), solo al redimensionar. */
#player-area {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  background: var(--bg);
  border-top: 1px solid var(--line);
  padding: 0.5rem 1rem calc(0.5rem + env(safe-area-inset-bottom, 0px));
}

.opponents {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
}

.opponents .player-area.opponent {
  flex: 1 1 220px;
  min-width: 0; /* evita que el ancho mínimo del contenido (la mano) fuerce el panel a desbordar */
  border-radius: var(--radius);
  transition: box-shadow 0.15s ease;
}

.opponents .player-area.opponent.selectable {
  cursor: pointer;
  box-shadow: 0 0 0 2px var(--accent);
}

.opponents .player-area.opponent.selectable:hover {
  box-shadow: 0 0 0 2px var(--accent), 0 4px 14px rgba(0, 0, 0, 0.4);
}

.player-info {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0.4rem 0.75rem;
  background: var(--panel);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  font-size: 0.9rem;
  transition: background 0.2s ease, border-color 0.2s ease;
}

/* Se marca en rojo brevemente cuando a este jugador le afecta una explosión. */
.player-info.fx-affected {
  background: rgba(255, 95, 109, 0.18);
  border-color: var(--danger);
}

.player-name {
  font-weight: 700;
}

.player-stat {
  color: var(--text-dim);
}

.hand {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem;
  min-height: calc(var(--card-h) + 0.5rem);
  min-width: 0;
  justify-content: center;
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.hand::-webkit-scrollbar {
  display: none;
}

.hand .card {
  flex-shrink: 0;
}

.hand.overflowing {
  justify-content: flex-start;
}

.player-area.opponent .hand {
  --card-w: var(--opp-card-w);
  --card-h: var(--opp-card-h);
  gap: 0;
}

.player-area.opponent .hand .card:not(:first-child) {
  margin-left: calc(var(--opp-card-w) * -0.55);
}

/* --- Center strip: shared table stacks + log --- */
.center-strip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.piles {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1.5rem;
}

.pile {
  position: relative;
  width: var(--card-w);
  height: var(--card-h);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.02);
}

.pile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: var(--radius);
  display: block;
}

.pile-count {
  position: absolute;
  bottom: -8px;
  right: -8px;
  min-width: 22px;
  height: 22px;
  padding: 0 5px;
  border-radius: 11px;
  background: var(--accent);
  color: #0a1420;
  font-weight: 700;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg);
  z-index: 1;
}

/* En pantallas de escritorio, el mazo de robo y el descarte se fijan a los
   bordes de la ventana en vez de ir junto a las pilas de la mesa. */
@media (min-width: 721px) {
  #draw-pile {
    position: fixed;
    left: 1.5rem;
    top: 50%;
    transform: translateY(-50%);
  }

  #discard-pile {
    position: fixed;
    right: 1.5rem;
    top: 50%;
    transform: translateY(-50%);
  }
}

.log {
  display: none; /* oculto de momento (solo visual, el registro sigue funcionando) */
  width: min(600px, 100%);
  max-height: 4.5rem;
  overflow-y: auto;
  font-size: 0.8rem;
  color: var(--text-dim);
  text-align: center;
  padding: 0.25rem;
}

.log p {
  margin: 0.15rem 0;
}

/* --- Cards --- */
.card {
  position: relative;
  width: var(--card-w);
  height: var(--card-h);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  user-select: none;
}

.card-overlay-name,
.card-overlay-description {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: rgba(0, 0, 0, var(--card-overlay-opacity));
  color: #fff;
  border-radius: 3px;
  overflow: hidden;
  pointer-events: none;
}

.card-overlay-name {
  top: var(--card-name-margin);
  left: var(--card-name-margin);
  right: var(--card-name-margin);
  height: var(--card-name-height);
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 1.05;
  white-space: nowrap;
  text-overflow: ellipsis;
  padding: 0 3px;
}

.card-overlay-description {
  bottom: var(--card-desc-margin);
  left: var(--card-desc-margin);
  right: var(--card-desc-margin);
  height: var(--card-desc-height);
  font-size: 0.55rem;
  line-height: 1.15;
  padding: 3px 5px;
}

.card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}

.card.clickable {
  cursor: pointer;
}

.card.clickable:active {
  transform: scale(0.96);
}

/* Solo aplica el "levitar" en dispositivos con hover real (ratón); en
   táctil evita que una carta se quede con el estilo de :hover pegado. */
@media (hover: hover) {
  .card.clickable:hover {
    transform: translateY(-8px);
    border-color: var(--accent);
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.4);
  }
}

/* --- Responsive --- */
@media (max-width: 720px) {
  :root {
    --card-w: 78px;
    --card-h: 109px;
    --opp-card-w: 31px;
    --opp-card-h: 44px;
  }

  .board {
    padding: 0.6rem;
    gap: 0.5rem;
  }

  .topbar {
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
  }

  .player-info {
    flex-wrap: wrap;
    gap: 0.6rem;
  }

  .opponents {
    gap: 0.5rem;
  }

  .opponents .player-area.opponent {
    flex-basis: 140px;
  }

  .piles {
    gap: 0.75rem;
  }

  .card-overlay-name {
    font-size: 0.5rem;
  }

  .card-overlay-description {
    font-size: 0.42rem;
    padding: 2px 3px;
  }
}

@media (max-width: 420px) {
  :root {
    --card-w: 64px;
    --card-h: 90px;
    --opp-card-w: 26px;
    --opp-card-h: 36px;
  }

  .opponents .player-area.opponent {
    flex-basis: 110px;
  }

  .menu-title {
    font-size: clamp(1.6rem, 9vw, 2.2rem);
  }
}

/* --- Animaciones --- */
#fx-layer {
  position: fixed;
  inset: 0;
  z-index: 1000;
  pointer-events: none;
}

.fx-flying-card {
  position: fixed;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.5);
  will-change: transform;
}

.fx-flying-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.fx-backdrop {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  background: rgba(0, 0, 0, 0);
  opacity: 0;
  transition: opacity 0.25s ease, background 0.25s ease, backdrop-filter 0.25s ease;
}

.fx-backdrop.fx-visible {
  opacity: 1;
  background: rgba(0, 0, 0, 0.78);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.fx-big-card {
  width: min(46vw, 260px);
  height: min(64vw, 364px);
  transform: scale(0.85);
  transition: transform 0.25s ease;
}

.fx-backdrop.fx-visible .fx-big-card {
  transform: scale(1);
}

.fx-big-card .card-overlay-name {
  font-size: 1.1rem;
}

.fx-big-card .card-overlay-description {
  font-size: 0.9rem;
}

.fx-explosion-text {
  font-size: clamp(2rem, 8vw, 3.5rem);
  font-weight: 800;
  color: var(--danger);
  text-shadow: 0 0 18px rgba(255, 95, 109, 0.6);
  transform: scale(0.6);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.fx-backdrop.fx-visible .fx-explosion-text {
  transform: scale(1);
}

.fx-take-that {
  position: fixed;
  transform: translate(-50%, -100%) scale(0.6);
  font-size: clamp(1.4rem, 6vw, 2.4rem);
  font-weight: 800;
  color: var(--accent);
  text-shadow: 0 0 18px rgba(95, 176, 255, 0.6);
  opacity: 0;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s ease;
  pointer-events: none;
  white-space: nowrap;
  z-index: 1001;
}

.fx-take-that.fx-visible {
  opacity: 1;
  transform: translate(-50%, -100%) scale(1);
}

.fx-draw-counter {
  font-size: clamp(1.1rem, 3.5vw, 1.6rem);
  font-weight: 700;
  color: var(--text);
}

.fx-draw-counter-value {
  color: var(--danger);
}

/* El indicador n/capacidad se pone en rojo justo antes de que su montón explote. */
.pile-count.fx-danger {
  background: var(--danger);
}
