/* main.css – shared site styling (2025‑06‑12) */

/* ─── Color variables & reset ─────────────────────────────────────────────── */
:root {
  /* All red shades consolidated to a single tone */
  --color-primary: #9a0007;
  --color-primary-dark: #9a0007;
  --color-bg: #ffffff;
  --color-text: #0d0f11;
  --color-subtle: #6b7280;
  --table-bg: #ffffff;
  --stripe-bg: #f2f2f2;
  --hover-bg: #e5e7eb;
  --color-green: #16a34a;
  --color-red: #dc2626;
  --color-yellow: #fbbf24;
  --col-width: 4.5rem;
  --name-width: 8rem;
  --wl-width: 3.5rem;
}

/* Responsive base font size scales with viewport width */
html {
  font-size: clamp(14px, 3.5vw, 16px);
}

@media (min-width: 1024px) {
  html {
    font-size: 18px;
  }
}

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

/* Generic page container */
.container {
  width: min(100%, 680px);
  margin-left: auto;
  margin-right: auto;
  padding-left: 1rem;
  padding-right: 1rem;
}

@media (max-width: 480px) {
  .container {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }
}

/* ─── Base typography & background ──────────────────────────────────────────── */
body {
  font-family: "Montserrat", sans-serif;
  background-color: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding-bottom: calc(0.5rem + env(safe-area-inset-bottom));
  overscroll-behavior-y: contain;
}

/* Prevent extra scroll space on shorter leaderboard page */
body.leaderboard-page {
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(3.5rem + env(safe-area-inset-bottom));
}
body.leaderboard-page main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body.preload {
  visibility: hidden;
}

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

/* ─── Layout & header ───────────────────────────────────────────────────────── */
main {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  flex: 1 0 auto;
  max-width: 1000px;
  margin: 0 auto;
  padding: 0.5rem 1rem 0; /* reduced bottom space */
}
header {
  text-align: center;
  margin-bottom: 0;
}
.leaderboard-header {
  max-width: calc(var(--name-width) + 4 * var(--col-width));
  margin: 0 auto;
  text-align: center;
}

.hero-banner {
  padding: 0.5rem 0.5rem;
  background: var(--color-bg);
  margin-bottom: 0.5rem;
}

@media (min-width: 1024px) {
  .leaderboard-header {
    max-width: none;
  }
}
.header__title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-top: 0.25rem; /* slight breathing room above title */
}
.header__title .primary {
  color: var(--color-primary);
}

/* Generic class for primary accent text */
.primary {
  color: var(--color-primary);
}

/* ─── Payouts info ─────────────────────────────────────────────────────────── */
.payouts-inline {
  font-family: "Roboto", sans-serif;
  font-size: 0.875rem;
  color: var(--color-subtle);
  margin: 0.25rem 0 0;
  text-align: center;
  line-height: 1.2;
}
.season-label {
  font-family: "Roboto", sans-serif;
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0;
  text-align: center;
}

.season-label .season-text {
  color: var(--color-primary);
}

.season-label .season-number {
  color: var(--color-text);
}
.tagline {
  font-size: 0.875rem;
  color: var(--color-subtle);
  margin: 0.25rem 0 0;
  text-align: center;
}

/* Layout for leaderboard and countdown */
.leaderboard-layout {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
body.leaderboard-page .leaderboard-layout {
  margin-block: 0.5rem;
  flex: 1;
  overflow: hidden;
}
@media (min-width: 768px) {
  .leaderboard-layout {
    flex-direction: row;
    justify-content: center;
  }
  .table-wrapper {
    max-width: none;
  }
}

/* ─── Table wrapper & base table ───────────────────────────────────────────── */
.table-wrapper {
  overflow: auto;
  width: 100%;
  margin: 0 auto;
  flex: 1;
}
table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid #e5e7eb;
  background-color: var(--table-bg);
  font-size: 1rem;
}

@media (max-width: 480px) {
  body.leaderboard-page table {
    font-size: 0.9rem;
  }
}

@media (min-width: 1024px) {
  body.leaderboard-page .table-wrapper {
    overflow-x: visible;
    max-width: none;
  }
  body.leaderboard-page table {
    width: 100%;
  }
}

caption {
  caption-side: top;
  text-align: left;
  font-family: "Roboto", sans-serif;
  font-size: 1rem;
  margin-bottom: 0.5rem;
}
th,
td {
  padding: 0.6rem 0.5rem;
  text-align: center;
  border-bottom: 1px solid #e5e7eb;
  white-space: nowrap;
  vertical-align: middle;
  min-width: var(--col-width);
}
.sortable-header {
  cursor: pointer;
}

/* Divider after rank column */
th:nth-child(1),
td:nth-child(1) {
  border-right: 1px solid #e5e7eb;
}
th:nth-child(2),
td:nth-child(2) {
  min-width: var(--name-width);
}
th:nth-child(4),
td:nth-child(4),
th:nth-child(5),
td:nth-child(5) {
  min-width: var(--wl-width);
}

/* Sticky headers */
thead th {
  position: sticky;
  top: 0;
  background-color: var(--table-bg);
  color: var(--color-subtle);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-family: "Roboto", sans-serif;
  font-weight: 500;
  z-index: 4;
}

/* Zebra striping & hover */
tbody tr:hover {
  background-color: var(--hover-bg);
}

/* ─── Standard white & gray zebra striping ───────────────────────────────── */
tbody tr:nth-of-type(odd) > * {
  background-color: #ffffff;
}
tbody tr:nth-of-type(even) > * {
  background-color: #f0f4f8;
}
tbody tr:hover > * {
  background-color: #e5e7eb; /* keeps your subtle hover */
}

/* Champion belt icon */
.belt-icon {
  height: 2rem;
  display: inline-block;
  vertical-align: middle;
  margin-right: 0.25rem;
}

/* Badge showing back-to-back champion */
.b2b-badge {
  margin-left: 0.1rem;
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--color-primary);
}

/* Align belt, player name and badge on the same line */
.name-cell {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  justify-content: center;
  background-color: inherit;
}

/* Highlight the logged-in player's row */
.current-user > * {
  background-color: #fff9bf !important;
  font-weight: 600;
}

/* Bottom navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  display: flex;
  justify-content: space-around;
  background: #fff;
  border-top: 1px solid #e5e7eb;
  height: calc(3.5rem + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  align-items: center;
  z-index: 1000;
  touch-action: none;
  overflow: hidden;
}
.bottom-nav::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  width: calc(100% / 3);
  height: 3px;
  background: var(--color-primary);
  transform: translateX(calc(var(--active-index, 0) * 100%));
  transition: transform 0.3s ease;
}
.bottom-nav .nav-item {
  position: relative;
  z-index: 1;
  flex: 1;
  text-align: center;
  text-decoration: none;
  font-family: "Roboto", sans-serif;
  color: var(--color-text);
  padding: 0.75rem 0;
  transition:
    color 0.2s,
    transform 0.1s;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  cursor: pointer;
}
.bottom-nav .nav-item i {
  font-size: 1.4rem;
}
.bottom-nav .nav-label {
  font-size: 0.65rem;
  margin-top: 0.1rem;
}
.bottom-nav .nav-item:active {
  transform: scale(0.9);
}
.bottom-nav .nav-item:not(:last-child) {
  border-right: 1px solid #e5e7eb;
}
.bottom-nav .nav-item.active {
  color: var(--color-primary);
  font-weight: 600;
}

/* Desktop navigation */
.desktop-nav {
  display: none;
}

@media (min-width: 1024px) {
  body {
    padding-top: 0;
  }
  .desktop-nav {
    display: none;
  }
}

body {
  opacity: 1;
  transition: opacity 0.3s ease;
}
body.fade-out {
  opacity: 0;
}

/* Profile summary */
.profile-summary {
  background: var(--stripe-bg);
  padding: 1rem;
  border-radius: 0.5rem;
  margin-bottom: 1rem;
}
.profile-summary ul {
  list-style: none;
  padding: 0;
}
.profile-summary li {
  margin: 0.25rem 0;
}

.history summary {
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 0.5rem;
}
.history-controls {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}
.history-controls label {
  font-size: 0.875rem;
}

/* Season collapsibles */
.season > summary {
  font-weight: 600;
  cursor: pointer;
  margin: 1rem 0 0.5rem;
  color: var(--color-primary);
}

/* Profile page layout */
.profile-content {
  max-width: none;
  margin: 0 0 7rem;
  padding: 0.5rem 1rem;
}
.profile-content header {
  text-align: center;
}

/* Win/Loss row colors */
.history table tbody tr.win td {
  /* Green highlighter effect */
  background-image: linear-gradient(
    rgba(108, 212, 149, 0.8),
    rgba(108, 212, 149, 0.8)
  );
  background-repeat: no-repeat;
  background-size: 100% 60%;
  background-position: 0 65%;
  color: inherit;
  font-weight: 600;
}
.history table tbody tr.loss td {
  /* Red highlighter effect */
  background-image: linear-gradient(
    rgba(248, 113, 113, 0.8),
    rgba(248, 113, 113, 0.8)
  );
  background-repeat: no-repeat;
  background-size: 100% 60%;
  background-position: 0 65%;
  color: inherit;
  font-weight: 600;
}

/* Constrain Event column */

.history th.event-col,
.history td.event-col {
  max-width: none;
  width: auto;
}

.profile-content .table-wrapper {
  max-width: none;
}

/* Compact history tables for mobile */
.history table {
  width: auto;
  min-width: 0;
  table-layout: auto;
}
.history th,
.history td {
  padding: 0.25rem;
  font-size: 0.7rem;
  min-width: auto;
  text-align: left;
  white-space: nowrap;
}

/* Row showing cumulative season total */
.history .total-row td {
  font-weight: 600;
}
.history .total-label {
  text-align: right;
}

@media (min-width: 1024px) {
  .bottom-nav {
    display: none;
  }
  .profile-content {
    margin: 0 auto 2rem;
    max-width: 960px;
  }
}

/* Offline banner displayed when navigator.offline */
.offline-banner {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  background: #fdecea;
  color: #b91c1c;
  text-align: center;
  font-weight: 600;
  padding: 0.25rem 0.5rem;
  font-size: 0.875rem;
  z-index: 1000;
}
.offline-banner.hidden { display: none; }

.last-updated {
  text-align: center;
  font-size: 0.875rem;
  margin-top: 0.25rem;
  color: var(--color-subtle);
}

/* Update notice popup */
.update-popup {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 3.5rem; /* keep bottom nav visible */
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 950;
  transform: translateY(20%);
  opacity: 0;
  pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
  .update-popup {
    transition: transform 0.3s ease, opacity 0.3s ease;
  }
}

.update-popup.show {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
  backdrop-filter: blur(5px);
  background: rgba(0, 0, 0, 0.3);
}

.popup-card {
  pointer-events: auto;
  width: 100%;
  max-width: 20rem;
  background: var(--color-bg);
  border: 2px solid var(--color-primary);
  border-radius: 12px;
  padding: 1.25rem;
  text-align: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  position: relative;
}

.close-btn {
  position: absolute;
  top: 0.25rem;
  right: 0.25rem;
  font-size: 1.25rem;
  background: transparent;
  border: none;
  color: var(--color-text);
}

.hidden {
  display: none !important;
}
