/* L2 Pearl — shared Stats pages layout */

.stats-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.stats-main {
  flex: 1;
}

.stats-hero {
  padding: clamp(2.5rem, 5vw, 3.75rem) 0 2rem;
  text-align: center;
  position: relative;
}

.stats-hero::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 55% 70% at 50% 0%, rgba(184, 144, 46, 0.14), transparent 65%);
  pointer-events: none;
}

.stats-hero .container {
  position: relative;
  z-index: 1;
}

.stats-hero .section-eyebrow {
  margin-bottom: 0.75rem;
}

.stats-hero h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(2.25rem, 5vw, 3.5rem);
  line-height: 1.1;
  letter-spacing: 0.02em;
  margin: 0 0 0.85rem;
  color: var(--text);
}

.stats-hero p {
  margin: 0.85rem auto 0;
  max-width: 36rem;
  color: var(--text-secondary);
  font-size: 1.05rem;
  line-height: 1.55;
}

.stats-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  max-width: 32rem;
  margin: 1.75rem auto 0;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.stats-summary-item {
  background: var(--bg-elevated);
  padding: 1rem 0.85rem;
  text-align: center;
}

.stats-summary-label {
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.stats-summary-value {
  font-family: var(--font-display);
  font-size: 1.65rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1;
}

.stats-summary-value.is-alive {
  color: var(--success);
}

.stats-summary-value.is-warn {
  color: #92720d;
}

.stats-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.filter-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 5px;
  flex-wrap: wrap;
}

.filter-tab {
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  padding: 0.5rem 0.95rem;
  font-family: var(--font-sans);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition:
    color var(--duration) var(--ease),
    background var(--duration) var(--ease),
    border-color var(--duration) var(--ease);
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.filter-tab:hover {
  color: var(--text);
  background: rgba(28, 27, 46, 0.05);
}

.filter-tab.active {
  color: var(--text);
  background: var(--accent-soft);
  border-color: rgba(184, 144, 46, 0.35);
}

.badge-count {
  background: rgba(184, 144, 46, 0.25);
  border: 1px solid rgba(184, 144, 46, 0.4);
  color: var(--text);
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0;
}

.stats-sort {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.stats-sort label {
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.stats-select {
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  padding: 0.55rem 0.85rem;
  outline: none;
  min-height: 40px;
}

.stats-select:focus {
  border-color: var(--border-accent);
  box-shadow: 0 0 0 3px rgba(184, 144, 46, 0.14);
}

.stats-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: clamp(1.25rem, 3vw, 1.75rem);
  backdrop-filter: blur(8px);
}

.stats-panel h3 {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 600;
  margin: 0 0 1rem;
  letter-spacing: 0.03em;
  color: var(--text);
}

.stats-panel ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.65rem;
}

.stats-panel li {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.5;
}

.stats-panel strong {
  color: var(--text);
  font-weight: 600;
}

.stats-section {
  padding: 0 0 clamp(3rem, 6vw, 4.5rem);
}

.stats-subnav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin: 1.25rem 0 0;
}

.stats-subnav a {
  padding: 0.45rem 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  transition:
    color var(--duration) var(--ease),
    border-color var(--duration) var(--ease),
    background var(--duration) var(--ease);
}

.stats-subnav a:hover,
.stats-subnav a.is-active {
  color: var(--text);
  border-color: var(--border-accent);
  background: var(--accent-soft);
}

/* Category picker — one table visible at a time instead of every
   leaderboard stacked on the page. */
.stats-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.4rem;
  margin-bottom: 1.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.stats-tab {
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition:
    color var(--duration) var(--ease),
    background var(--duration) var(--ease),
    border-color var(--duration) var(--ease);
}

.stats-tab:hover {
  color: var(--text);
  background: var(--accent-soft);
}

.stats-tab.active {
  color: #fff;
  background: linear-gradient(180deg, #d1ac4c 0%, var(--accent) 100%);
  border-color: rgba(184, 144, 46, 0.4);
  box-shadow: var(--shadow-glow);
}

.stats-tab-panel {
  display: none;
}

.stats-tab-panel.active {
  display: block;
  animation: statsTabFadeIn 0.25s ease;
}

@keyframes statsTabFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* Data tables */
.stats-table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 560px;
}

.stats-table th,
.stats-table td {
  padding: 0.85rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.925rem;
}

.stats-table th {
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
  background: rgba(28, 27, 46, 0.03);
}

.stats-table td {
  color: var(--text-secondary);
}

.stats-table tbody tr:last-child td {
  border-bottom: none;
}

.stats-table tbody tr:hover td {
  background: rgba(28, 27, 46, 0.03);
  color: var(--text);
}

/* Castle name paired with its portrait. The tile carries two background
   layers: the castle photo on top, a faint crest underneath. If the photo is
   missing the crest shows through instead of a broken-image icon. */
.castle-cell {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  white-space: nowrap;
}

.castle-thumb {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background-color: rgba(28, 27, 46, 0.04);
  background-image: var(--castle-img, none),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23b8902e' stroke-opacity='0.55' stroke-width='1.4' stroke-linejoin='round'%3E%3Cpath d='M3 21V8l2.5 1.6V6.2l3 1.9V5.1L12 3l3.5 2.1v3l3-1.9v3.4L21 8v13z'/%3E%3Cpath d='M10.5 21v-4a1.5 1.5 0 0 1 3 0v4'/%3E%3C/svg%3E");
  background-size: cover, 55%;
  background-position: center, center;
  background-repeat: no-repeat, no-repeat;
}

.stats-table .rank {
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--accent-hover);
  width: 3rem;
}

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

.stats-placeholder {
  text-align: center;
  padding: clamp(2.5rem, 6vw, 4rem) 1.5rem;
  color: var(--text-secondary);
}

.stats-placeholder strong {
  display: block;
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.stats-card-title {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 600;
  margin: 0 0 1rem;
  letter-spacing: 0.02em;
}

.nav-dropdown a.is-active {
  color: var(--text);
  background: rgba(184, 144, 46, 0.12);
}

.site-footer.compact {
  padding: 1.5rem 0;
  margin-top: auto;
}

.site-footer.compact .footer-bottom {
  border-top: none;
  padding-top: 0;
}

/* Mobile stats layout — fit tables to the screen (no clipped columns) */
@media (max-width: 767px) {
  .stats-hero {
    padding: 1.75rem 0 1.15rem;
  }

  .stats-hero h1 {
    font-size: clamp(1.85rem, 9vw, 2.45rem);
    margin-bottom: 0.65rem;
  }

  .stats-hero .section-eyebrow {
    margin-bottom: 0.55rem;
  }

  .stats-hero .container,
  .stats-section > .container {
    width: min(100% - 1.5rem, var(--container));
  }

  .stats-section {
    padding-bottom: 2.75rem;
  }

  .stats-card-title {
    font-size: 1.15rem;
    margin-bottom: 0.75rem;
  }

  .stats-tabs {
    gap: 0.3rem;
    padding: 0.3rem;
  }

  .stats-tab {
    padding: 0.55rem 0.9rem;
    font-size: 0.82rem;
  }

  .stats-table-wrap {
    border-radius: var(--radius-md);
    overflow-x: visible;
  }

  .stats-table {
    min-width: 0;
    width: 100%;
    table-layout: fixed;
  }

  .stats-table th,
  .stats-table td {
    padding: 0.65rem 0.4rem;
    font-size: 0.8rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
  }

  .stats-table th {
    font-size: 0.58rem;
    letter-spacing: 0.05em;
  }

  .stats-table .rank {
    width: 1.7rem;
    padding-inline: 0.3rem;
    text-align: center;
  }

  /* Rankings: keep kills/PK readable on the right */
  .stats-table th:last-child,
  .stats-table td:last-child {
    width: 3.1rem;
    text-align: right;
    padding-right: 0.55rem;
    font-variant-numeric: tabular-nums;
  }

  /* Castles / longer last cells can wrap */
  .stats-table td:last-child:not(.rank) {
    white-space: normal;
    line-height: 1.25;
    font-size: 0.72rem;
  }

  #pvp .stats-table td:last-child,
  #pk .stats-table td:last-child {
    white-space: nowrap;
    font-size: 0.8rem;
  }

  .stats-summary {
    grid-template-columns: 1fr;
    max-width: 16rem;
  }

  .site-footer.compact {
    padding: 1.25rem 0 1.75rem;
  }

  .site-footer.compact .footer-bottom {
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    text-align: center;
    font-size: 0.8rem;
  }

  .site-footer.compact .footer-legal {
    justify-content: center;
    flex-wrap: wrap;
  }
}

@media (max-width: 420px) {
  .stats-table th,
  .stats-table td {
    padding: 0.55rem 0.3rem;
    font-size: 0.75rem;
  }

  .stats-table th {
    font-size: 0.54rem;
    letter-spacing: 0.04em;
  }

  .stats-table th:last-child,
  .stats-table td:last-child {
    width: 2.75rem;
  }
}
