/* Últimas partidas y Mis partidas con la composición de la portada: cabecera
   sobre madera, modalidades como accesos de latón y fichas de pergamino que
   cierran con la matriz de un billete. Las plantillas cargan antes home.css y
   reutilizan de él home-eyebrow, home-course, home-medal y las líneas de rumbo. */

.recent-container {
  --recent-parchment:
    radial-gradient(40% 30% at 12% 88%, rgba(90, 58, 34, 0.1), rgba(0, 0, 0, 0) 70%),
    radial-gradient(30% 24% at 88% 10%, rgba(90, 58, 34, 0.12), rgba(0, 0, 0, 0) 70%),
    repeating-linear-gradient(0deg, rgba(62, 95, 112, 0.07) 0 1px, rgba(0, 0, 0, 0) 1px 52px),
    repeating-linear-gradient(90deg, rgba(62, 95, 112, 0.07) 0 1px, rgba(0, 0, 0, 0) 1px 52px),
    linear-gradient(158deg, var(--parchment-100) 0%, var(--parchment-300) 100%);
  --recent-winner: #2d7357;
  position: relative;
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 clamp(1rem, 2.5vw, 2rem) clamp(2.5rem, 5vw, 3.5rem);
}

/* --- Cabecera --- */
.recent-hero {
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 0.7fr);
  column-gap: clamp(2rem, 5vw, 4.5rem);
  row-gap: 1.75rem;
  align-items: start;
  padding: clamp(2rem, 4.5vw, 3.25rem) 0 clamp(1.6rem, 3vw, 2.2rem);
}

.recent-intro-block {
  min-width: 0;
}

.recent-hero h1 {
  margin: 0.9rem 0 0;
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 4.6vw, 3.6rem);
  font-weight: 600;
  line-height: 1.02;
  letter-spacing: -0.02em;
  color: var(--parchment-100);
  text-wrap: balance;
  overflow-wrap: anywhere;
  text-shadow: 0 2px 28px rgba(0, 0, 0, 0.35);
}

.recent-intro-block .home-course {
  margin: 1.25rem 0 1.1rem;
}

.recent-intro {
  margin: 0;
  max-width: 52ch;
  font-size: 1.05rem;
  line-height: 1.65;
  color: rgba(242, 231, 204, 0.8);
  text-wrap: pretty;
}

/* Mismo rótulo que «Última actualización» en Privacidad y Condiciones. */
.recent-updated {
  margin: 1.2rem 0 0;
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.recent-hero-side {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  min-width: 0;
}

.recent-home {
  align-self: flex-end;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.4rem 0.85rem;
  border: 1px solid rgba(224, 194, 102, 0.32);
  border-radius: 999px;
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 600;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.recent-home:hover {
  border-color: rgba(224, 194, 102, 0.65);
  color: var(--parchment-100);
}

/* Las modalidades son los accesos de latón de la portada; la activa pasa a
   pergamino, como las tarjetas de juego. */
.recent-modes {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.recent-mode {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  min-width: 0;
  padding: 0.55rem 1rem 0.55rem 0.6rem;
  border: 1px solid rgba(224, 194, 102, 0.26);
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(196, 154, 58, 0.13), rgba(90, 58, 34, 0.24));
  box-shadow: 0 12px 26px -16px rgba(0, 0, 0, 0.8), inset 0 1px 0 rgba(242, 231, 204, 0.1);
  color: var(--parchment-100);
  transition: transform 0.15s ease, border-color 0.15s ease, filter 0.15s ease;
}

.recent-mode:hover {
  transform: translateY(-2px);
  border-color: rgba(224, 194, 102, 0.6);
  filter: brightness(1.1);
  color: var(--parchment-100);
}

.recent-mode-title {
  flex: 1;
  min-width: 0;
  font-family: var(--font-display);
  font-size: 1.08rem;
  font-weight: 600;
  line-height: 1.2;
}

.recent-mode-mark {
  flex: none;
  width: 1.05rem;
  height: 1.05rem;
  border: 1.5px solid rgba(224, 194, 102, 0.5);
  border-radius: 50%;
}

.recent-mode.is-selected {
  border-color: rgba(90, 58, 34, 0.55);
  background: var(--recent-parchment);
  box-shadow:
    0 22px 40px -22px rgba(0, 0, 0, 0.92),
    inset 0 0 40px rgba(90, 58, 34, 0.16),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
  color: var(--ink-950);
}

.recent-mode.is-selected:hover {
  filter: none;
  color: var(--ink-950);
}

.recent-mode.is-selected .recent-mode-mark {
  border-color: var(--lacquer);
  background: radial-gradient(circle, var(--lacquer) 0 40%, rgba(0, 0, 0, 0) 45%);
}

.recent-home:focus-visible,
.recent-mode:focus-visible,
.recent-leader:focus-visible,
.recent-filter-chip:focus-visible,
.recent-match:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

/* Aviso de privacidad sobre la madera. */
.recent-privacy-info {
  display: inline-block;
  position: relative;
  vertical-align: middle;
}

.recent-privacy-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: rgba(242, 231, 204, 0.7);
  font-size: 18px;
  cursor: pointer;
}

.recent-privacy-trigger:hover,
.recent-privacy-trigger[aria-expanded="true"] {
  background: rgba(224, 194, 102, 0.14);
  color: var(--gold-300);
}

.recent-privacy-trigger:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.recent-privacy-tip {
  position: absolute;
  z-index: 20;
  top: 100%;
  left: 0;
  width: min(22rem, calc(100vw - 40px));
  padding: 0.8rem 0.95rem;
  border: 1px solid rgba(90, 58, 34, 0.55);
  border-radius: 10px;
  background: var(--parchment-100);
  box-shadow: 0 18px 34px -16px rgba(0, 0, 0, 0.9);
  color: var(--ink-900);
  font-size: 0.83rem;
  line-height: 1.6;
}

.recent-privacy-tip a {
  color: var(--wood-700);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* --- Líderes más jugados: franja de latón con scroll horizontal --- */
.recent-ranking {
  padding: 1rem 1.2rem 0.35rem;
  border: 1px solid rgba(224, 194, 102, 0.24);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(62, 43, 26, 0.72), rgba(30, 21, 13, 0.88));
  box-shadow: 0 26px 50px -30px rgba(0, 0, 0, 0.95), inset 0 1px 0 rgba(242, 231, 204, 0.08);
}

.recent-section-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.9rem;
}

.recent-section-heading h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--parchment-100);
}

.recent-section-heading > span {
  color: var(--text-secondary);
  font-size: 0.78rem;
}

.recent-section-heading > span::before {
  content: "";
  display: inline-block;
  width: 1.4rem;
  height: 1px;
  margin-right: 0.6rem;
  vertical-align: middle;
  background: linear-gradient(90deg, rgba(196, 154, 58, 0), var(--gold-500));
}

.recent-ranking-empty {
  margin: 0.6rem 0 0.9rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* El fundido final indica que la franja sigue con scroll. */
.recent-leaders {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.6rem;
  margin: 0 -0.35rem;
  padding: 1.05rem 0.35rem 0.85rem;
  overflow-x: auto;
  scroll-padding-inline: 0.35rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(196, 154, 58, 0.55) transparent;
  -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 3rem), rgba(0, 0, 0, 0.15));
  mask-image: linear-gradient(90deg, #000 calc(100% - 3rem), rgba(0, 0, 0, 0.15));
}

.recent-leader {
  position: relative;
  flex: 0 0 auto;
  padding: 4px;
  border: 1px solid transparent;
  border-radius: 9px;
  transition: transform 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
}

.recent-leader img {
  display: block;
  width: 58px;
  height: 81px;
  object-fit: fill;
  border-radius: 5px;
  box-shadow: 0 8px 14px -8px rgba(0, 0, 0, 0.85);
}

.recent-leader:hover {
  transform: translateY(-3px);
  border-color: rgba(224, 194, 102, 0.45);
  background: rgba(224, 194, 102, 0.08);
}

/* El líder filtrado queda clavado con la chincheta de la portada. */
.recent-leader.is-selected {
  border-color: var(--gold-300);
  background: rgba(224, 194, 102, 0.16);
  box-shadow: 0 0 0 1px rgba(224, 194, 102, 0.4), 0 0 22px -4px rgba(224, 194, 102, 0.45);
}

.recent-leader.is-selected::before {
  content: "";
  position: absolute;
  z-index: 1;
  top: -7px;
  left: 50%;
  width: 13px;
  height: 13px;
  margin-left: -6.5px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #c2543f, var(--lacquer) 65%, #7e2b22);
  box-shadow: 0 3px 5px rgba(21, 14, 8, 0.5);
}

/* --- Resultados --- */
.recent-results {
  margin-top: 1.6rem;
}

.recent-filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  max-width: 100%;
  margin: 0 0 1.1rem;
  padding: 0.35rem 0.85rem 0.35rem 0.4rem;
  border: 1px solid rgba(90, 58, 34, 0.55);
  border-radius: 10px;
  background: var(--recent-parchment);
  box-shadow: 0 12px 22px -14px rgba(0, 0, 0, 0.85);
  color: var(--ink-950);
  font-size: 0.85rem;
}

.recent-filter-chip:hover {
  border-color: var(--wood-700);
  color: var(--ink-950);
}

.recent-filter-chip img {
  flex: none;
  width: 26px;
  height: 36px;
  object-fit: fill;
  border-radius: 3px;
}

.recent-filter-name {
  min-width: 0;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.recent-filter-clear {
  flex: none;
  padding-left: 0.7rem;
  border-left: 1px solid rgba(90, 58, 34, 0.25);
  color: var(--lacquer);
  font-size: 0.78rem;
  font-weight: 700;
}

.recent-match-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1.2rem;
}

/* --- Ficha de partida --- */
.recent-match {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  border: 1px solid rgba(90, 58, 34, 0.55);
  border-radius: 14px;
  background: var(--recent-parchment);
  box-shadow:
    0 24px 44px -26px rgba(0, 0, 0, 0.95),
    inset 0 0 50px rgba(90, 58, 34, 0.14),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
  color: var(--ink-950);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

a.recent-match:hover {
  transform: translateY(-3px);
  border-color: var(--gold-500);
  box-shadow:
    0 30px 50px -24px rgba(0, 0, 0, 0.95),
    0 0 0 1px rgba(224, 194, 102, 0.45),
    inset 0 0 50px rgba(90, 58, 34, 0.14),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
  color: var(--ink-950);
}

.recent-duel {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 0.45rem;
  padding: 1rem 0.95rem 0.95rem;
}

.recent-vs {
  display: block;
  width: 32px;
  height: 40px;
  object-fit: contain;
}

.recent-player {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
}

.recent-player:last-child {
  flex-direction: row-reverse;
  text-align: right;
}

.recent-player > img {
  flex-shrink: 0;
  width: 54px;
  height: 75px;
  object-fit: fill;
  border: 1px solid rgba(90, 58, 34, 0.45);
  border-radius: 6px;
  box-shadow: 0 8px 14px -8px rgba(21, 14, 8, 0.75);
}

/* El resultado nunca depende solo del color: la etiqueta lleva el texto. */
.recent-player.is-winner > img {
  border-color: var(--recent-winner);
  box-shadow: 0 0 0 2px var(--recent-winner), 0 8px 14px -8px rgba(21, 14, 8, 0.75);
}

/* Solo se apaga el perdedor explícito; sin resultado no hay perdedor. */
.recent-player:not(.is-winner):has(.recent-result) > img {
  filter: saturate(0.55) brightness(0.97);
}

.recent-player-info {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.16rem;
  min-width: 0;
}

.recent-player:last-child .recent-player-info {
  align-items: flex-end;
}

.recent-role {
  max-width: 100%;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  line-height: 1.3;
  text-transform: uppercase;
}

.recent-role.is-human {
  color: var(--map-blue);
}

.recent-role.is-ai {
  color: var(--lacquer);
}

.recent-player-info strong {
  font-family: var(--font-display);
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.15;
  color: var(--ink-950);
  overflow-wrap: break-word;
}

.recent-player-code {
  color: var(--ink-600);
  font: 600 0.64rem ui-monospace, "SFMono-Regular", Menlo, monospace;
  letter-spacing: 0.02em;
}

.recent-result {
  margin-top: 0.3rem;
  padding: 0.2rem 0.45rem;
  border: 1px solid #bd6758;
  border-radius: 4px;
  color: #a22f25;
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  line-height: 1.2;
  text-transform: uppercase;
}

.recent-player.is-winner .recent-result {
  border-color: var(--recent-winner);
  background: var(--recent-winner);
  color: #fffaf0;
}

/* Matriz del billete, como los contadores de las tarjetas de la portada. */
.recent-match-meta {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.68rem 0.95rem;
  border-top: 1.5px dashed rgba(90, 58, 34, 0.32);
  background: rgba(90, 58, 34, 0.08);
  color: var(--ink-600);
  font-size: 0.78rem;
}

.recent-match-meta time {
  flex-shrink: 0;
  color: var(--ink-950);
  font-weight: 600;
}

.recent-match-turns {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
}

.recent-match-turns::before {
  content: "";
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: rgba(90, 58, 34, 0.45);
}

.recent-match-action {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-left: auto;
  color: var(--wood-700);
  font-weight: 700;
  white-space: nowrap;
}

.recent-match-action > span:first-child {
  transition: transform 0.15s ease;
}

a.recent-match:hover .recent-match-action {
  color: var(--lacquer);
}

a.recent-match:hover .recent-match-action > span:first-child {
  transform: translate(2px, -2px);
}

.recent-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* --- Vacío y error --- */
.recent-empty {
  padding: clamp(2rem, 5vw, 3.25rem) 1.5rem;
  border: 1px solid rgba(90, 58, 34, 0.55);
  border-radius: 14px;
  background: var(--recent-parchment);
  box-shadow: 0 34px 70px -24px rgba(10, 6, 2, 0.85), inset 0 0 90px rgba(90, 58, 34, 0.16);
  color: var(--ink-950);
  text-align: center;
}

.recent-empty .recent-empty-course {
  width: min(16rem, 70%);
  margin: 0 auto 1.4rem;
}

.recent-empty .home-x {
  color: var(--lacquer);
}

.recent-empty h3 {
  margin: 0 0 0.6rem;
  font: 600 1.75rem/1.15 var(--font-display);
  text-wrap: balance;
}

.recent-empty p {
  max-width: 50ch;
  margin: 0 auto 1.4rem;
  color: var(--ink-600);
  font-size: 0.98rem;
  line-height: 1.65;
}

/* --- Mis partidas: estado y rival sobre la matriz; hora y paginación --- */
.account-game-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0 0.95rem 0.8rem;
  color: var(--ink-600);
  font-size: 0.76rem;
}

.account-game-summary .account-games-status {
  flex-shrink: 0;
  font-size: 0.7rem;
}

.account-game-opponent {
  min-width: 0;
  overflow-wrap: anywhere;
  text-align: right;
}

.account-recent .recent-match-meta {
  flex-wrap: wrap;
  row-gap: 0.3rem;
}

.account-game-date {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.45rem;
}

.account-game-date [data-account-time] {
  color: var(--ink-600);
  font-weight: 500;
}

.account-recent .account-games-pager {
  margin-top: 1.6rem;
}

.account-recent .account-games-pager .account-hint {
  color: var(--text-secondary);
}

/* CJK sin glifos de Fraunces: sin tracking negativo. */
html:lang(ja) .recent-hero h1,
html:lang(zh-Hans) .recent-hero h1 {
  letter-spacing: normal;
}

/* Tres fichas estrechas: miniaturas y nombres más compactos. */
@media (min-width: 1024px) and (max-width: 1220px), (min-width: 701px) and (max-width: 820px), (max-width: 380px) {
  .recent-duel {
    gap: 0.35rem;
    padding: 0.9rem 0.75rem 0.85rem;
  }

  .recent-player {
    gap: 0.5rem;
  }

  .recent-player > img {
    width: 44px;
    height: 61px;
  }

  .recent-player-info strong {
    font-size: 0.82rem;
  }

  .recent-vs {
    width: 26px;
    height: 34px;
  }

  .recent-match-meta,
  .account-game-summary {
    padding-right: 0.75rem;
    padding-left: 0.75rem;
  }
}

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

  .recent-home {
    position: absolute;
    top: clamp(2rem, 4.5vw, 3.25rem);
    right: 0;
  }

  .recent-modes {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .recent-mode-mark {
    display: none;
  }
}

@media (min-width: 701px) and (max-width: 1023px) {
  .recent-match-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 700px) {
  .recent-match-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 0.9rem;
  }

  /* «Tú · Humano» cabe en una línea junto a la miniatura. */
  .recent-duel {
    gap: 0.3rem;
    padding-right: 0.8rem;
    padding-left: 0.8rem;
  }

  .recent-player {
    gap: 0.5rem;
  }

  .recent-role {
    letter-spacing: 0.08em;
  }

  .recent-modes {
    gap: 0.5rem;
  }

  .recent-mode {
    flex-direction: column;
    justify-content: center;
    gap: 0.45rem;
    padding: 0.7rem 0.4rem 0.65rem;
    text-align: center;
  }

  .recent-mode .home-medal--small {
    width: 2.2rem;
    height: 2.2rem;
  }

  .recent-mode .home-medal--small .home-icon {
    width: 1.05rem;
    height: 1.05rem;
  }

  .recent-mode-title {
    flex: none;
    font-family: var(--font-body);
    font-size: 0.76rem;
    font-weight: 700;
  }

  .recent-hero h1 {
    font-size: 2.35rem;
  }

  .recent-intro {
    font-size: 0.98rem;
  }

  .recent-ranking {
    padding: 0.9rem 0.9rem 0.25rem;
  }

  .recent-section-heading h2 {
    font-size: 1.15rem;
  }

  .recent-leaders {
    gap: 0.4rem;
  }

  .recent-leader img {
    width: 48px;
    height: 67px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .recent-home,
  .recent-mode,
  .recent-mode:hover,
  .recent-leader,
  .recent-leader:hover,
  .recent-match,
  a.recent-match:hover,
  .recent-match-action > span:first-child,
  a.recent-match:hover .recent-match-action > span:first-child {
    transform: none;
    transition: none;
  }
}
