:root {
  --bg:#f7f8fb;
  --card:#ffffff;
  --muted:#4b5563;
  --text:#222222;
  --text-strong:#111111;
  --text-invert:#ffffff;
  --accent:#2563eb;
  --border: rgba(0,0,0,.08);

  /* House palette */
  --house-red:#E63946;
  --house-blue:#1D3557;
  --house-green:#2A9D8F;
  --house-yellow:#E9C46A;
  --house-purple:#9B5DE5;
  --house-orange:#F4A261;

  /* Glass effect */
  --glass-bg: rgba(255,255,255,0.75);
  --glass-bg-strong: rgba(255,255,255,0.9);
  --glass-border: rgba(0,0,0,0.12);
  --glass-shadow: 0 10px 40px rgba(0,0,0,.12);
  --glass-blur: 12px;

  /* Layout tokens */
  --header-h: 64px;   /* NEW: fixed header height */
  --footer-h: 56px;   /* sticky footer height */

  /* Optional extra breathing room for spacer (used by JS toggle) */
  --footer-safe-gap: 88px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  min-height: 100%;
  font-family: "Inter", "Nunito Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
  font-weight: 400;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  color: var(--text);
  font-size: 1.05rem;
}

/* === Background image === */
body {
  background: url("../images/background.png") center/cover no-repeat fixed;
  position: relative;
  z-index: 0;
  isolation: isolate;
}

/* === Full-page fixed overlays (UNIFIED for all pages) === */
@keyframes overlayIn { from { opacity: 0 } to { opacity: 1 } }
@keyframes overlayPulse { 0% { opacity:.65 } 100% { opacity:0 } }

body::after {
  content: "";
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  min-height: 100vh;
  z-index: 0; /* gradient base layer */
  pointer-events: none;
  background: linear-gradient(
    180deg,
    rgba(255,255,255,0.55) 0%,
    rgba(255,255,255,0.40) 60%,
    rgba(255,255,255,0.60) 100%
  );
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;  /* mobile Safari-safe viewport */
  min-height: 100vh;
  z-index: 1;      /* above gradient, below content */
  pointer-events: none;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur)) saturate(140%);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(140%);
  animation: overlayIn .35s ease both;
}

/* Dedicated overlay element (inserted by JS) for consistent fade on toggle */
.bg-overlay,
.site-overlay{
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  min-height: 100vh;
  z-index: 1; /* sits with body::before */
  pointer-events: none;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur)) saturate(140%);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(140%);
  /* IMPORTANT: visible by default so it can pulse, do NOT force opacity:0 */
  opacity: 1;
}
.overlay-pulse{ animation: overlayPulse .35s ease; }

/* Lock background scroll globally when needed */
html.overlay-locked, body.overlay-locked { height: 100%; overflow: hidden; }

/* ============================= */
/* Fixed, clean header + nav     */
/* ============================= */
.site-header{
  position: fixed; inset: 0 0 auto 0; height: var(--header-h);
  z-index: 60;
  background: rgba(255,255,255,.42);
  backdrop-filter: blur(12px) saturate(140%);
  -webkit-backdrop-filter: blur(12px) saturate(140%);
  border-bottom: 1px solid rgba(0,0,0,.06);
  transition: background .25s ease, box-shadow .25s ease, border-color .25s ease;
}
.site-header.is-scrolled{
  background: rgba(255,255,255,.92);
  border-bottom: 1px solid rgba(0,0,0,.12);
  box-shadow: 0 8px 24px rgba(0,0,0,.08);
}
.nav-inner{
  max-width: 1100px; margin: 0 auto; height: 100%;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 16px;
}
.site-header .brand{
  display:inline-flex; align-items:center; gap:.6rem; text-decoration:none;
  color:#0f172a; font-weight:900; letter-spacing:.25px;
}
.site-header .brand > span:last-child{ font-size: clamp(.95rem,.84rem + .6vw,1.35rem); line-height:1; }
.nav-bar{ display:flex; align-items:center; gap:8px; }
.nav-link{
  display:inline-flex; align-items:center; gap:.45rem;
  padding:.55rem .8rem; border-radius:10px; text-decoration:none;
  color:#0f172a; font-weight:750; border:1px solid transparent;
  transition: background .15s ease, transform .1s ease;
}
.nav-link:hover{ background: rgba(0,0,0,.05); transform: translateY(-1px); }
.nav-link:focus-visible{ outline:3px solid rgba(37,99,235,.25); outline-offset:2px; }

.nav-toggle{
  display:none; align-items:center; justify-content:center;
  width:40px; height:40px; border-radius:10px; border:1px solid rgba(0,0,0,.1);
  background: rgba(255,255,255,.85); cursor:pointer;
}
.nav-toggle .bars{ width:20px; height:14px; position:relative; }
.nav-toggle .bars::before, .nav-toggle .bars::after, .nav-toggle .bar{
  content:""; position:absolute; left:0; right:0; height:2px; background:#111; border-radius:2px; transition:.2s;
}
.nav-toggle .bars::before{ top:0; } .nav-toggle .bar{ top:6px; } .nav-toggle .bars::after{ bottom:0; }
.site-header.open .nav-toggle .bars::before{ transform: translateY(6px) rotate(45deg); }
.site-header.open .nav-toggle .bar{ opacity:0; }
.site-header.open .nav-toggle .bars::after{ transform: translateY(-6px) rotate(-45deg); }

.nav-drawer{
  position: fixed; left:0; right:0; top: var(--header-h);
  background: rgba(255,255,255,.97);
  border-bottom: 1px solid rgba(0,0,0,.12);
  box-shadow: 0 24px 48px rgba(0,0,0,.12);
  padding: 10px; display: grid; gap: 8px;
  opacity: 0; visibility: hidden; transform: translateY(-8px);
  transition: opacity .2s, transform .2s, visibility .2s;
  z-index: 59;
}
.site-header.open + .nav-drawer{ opacity:1; visibility:visible; transform: translateY(0); }

@media (max-width: 900px){
  .nav-bar{ display:none; }
  .nav-toggle{ display:inline-flex; }
}

/* ============================= */
/* Scroll container between bars */
/* ============================= */
.site-content{
  /* FIX: make the content pane fixed between header & footer (no “upper background”) */
  position: fixed;
  left: 0;
  right: 0;
  top: var(--header-h);
  bottom: calc(var(--footer-h) + env(safe-area-inset-bottom));
  z-index: 2; /* above overlays */

  /* Scrolling only inside this pane */
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;

  /* FIX: smaller breathing room */
  padding-bottom: 16px;
}

.container { 
  max-width: 1100px; 
  margin: 0 auto; 
  /* FIX: tighter top padding so login sits closer to the header */
  padding: 8px 24px 16px; 
  position: relative;
  z-index: 2;
}

/* Cards */
.card {
  border-radius: 16px;
  overflow: hidden;
  background: var(--glass-bg-strong);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  backdrop-filter: blur(calc(var(--glass-blur) * 0.6)) saturate(120%);
  -webkit-backdrop-filter: blur(calc(var(--glass-blur) * 0.6)) saturate(120%);
}

/* Old in-page header (still used elsewhere) */
.header { display:flex; align-items:center; justify-content:space-between; gap:16px; margin-bottom:20px; }
.brand {
  font-family: 'Nunito Sans', 'Inter', sans-serif;
  font-weight: 800;
  font-size: 2rem;
  letter-spacing:.5px;
  color: var(--text-strong);
}

/* Ensure last block doesn't push extra space */
.container > :last-child { margin-bottom: 0 !important; }

/* ============================= */
/* Tables                        */
/* ============================= */
.table {
  width: 100%; border-collapse: collapse;
  border: 1px solid var(--glass-border); border-radius: 12px; overflow: hidden;
  background: var(--glass-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.table th, .table td {
  padding: 14px 16px; text-align:left;
  border-bottom: 1.5px solid rgba(0,0,0,.12);
  font-weight: 500;
}
.table thead th {
  font-size:.92rem; text-transform:uppercase; letter-spacing:.06em;
  background: rgba(255,255,255,.55);
  color:#111;
  font-weight: 700;
}
.table tr:hover { background: rgba(0,0,0,.035); }

/* Rank & points */
.rank, .points {
  font-variant-numeric: tabular-nums;
  font-size: 1.25rem;
  font-weight: 800;
}

/* Badges */
.house-badge {
  display:inline-flex; align-items:center; gap:8px;
  padding:.35rem .7rem;
  border-radius:999px;
  font-weight:700;
  letter-spacing:.2px;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,.5);
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
  min-width: 96px; justify-content:center;
  font-size: 1.02rem;
}
.house-red{ background: var(--house-red); }
.house-blue{ background: var(--house-blue); }
.house-green{ background: var(--house-green); }
.house-yellow{ background: var(--house-yellow); color:#222 !important; text-shadow:none; }
.house-purple{ background: var(--house-purple); }
.house-orange{ background: var(--house-orange); }

/* Emoji column */
th.emoji-col, td.emoji-col { width: 44px; text-align: center; }
td.emoji-col { font-size: 1.15rem; line-height: 1; }

/* Buttons */
.btn {
  display:inline-flex; align-items:center; gap:.55rem; padding:.6rem 1rem;
  border-radius: 12px; text-decoration:none; font-weight:700;
  border:1px solid rgba(0,0,0,.06);
  background: linear-gradient(180deg, #2e6df0, #235ad1);
  color: var(--text-invert);
  transition: transform .15s ease, box-shadow .25s ease, filter .2s ease;
  box-shadow: 0 8px 20px rgba(37, 99, 235, .22);
}
.btn:hover { transform: translateY(-1px); filter: brightness(1.02); box-shadow: 0 12px 26px rgba(37,99,235,.28); }
.btn:active { transform: translateY(0); }
.btn.danger {
  background: linear-gradient(180deg, #e14b4b, #c93737);
  box-shadow: 0 8px 20px rgba(225,75,75,.22);
}

/* ============================= */
/* Accordions                    */
/* ============================= */
.accordion { border-radius:12px; overflow:hidden; border:1px solid var(--border); }
.accordion-item + .accordion-item { border-top:1px solid var(--border); }
.accordion-header {
  display:flex; align-items:center; justify-content:space-between;
  padding:14px 16px;
  background: var(--glass-bg);
  cursor:pointer; user-select:none;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.accordion-header:hover { background: linear-gradient(0deg, rgba(255,255,255,.35), rgba(255,255,255,0)); }
.accordion-title{font-weight:800; letter-spacing:.2px; font-family:"Nunito Sans","Inter",sans-serif; }
.accordion-chevron{transition: transform .25s ease}

.accordion-content {
  height: 0;
  overflow: hidden;
  transition: height 0.35s ease, padding 0.25s ease;
  background: linear-gradient(180deg, rgba(255,255,255,.5), rgba(255,255,255,.3));
  padding: 0 16px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.accordion-item.open .accordion-content { padding: 10px 16px 14px; }
.accordion-item.open .accordion-chevron { transform: rotate(180deg); }

/* Animations */
@keyframes fadeUp { from {opacity:0; transform: translateY(12px)} to {opacity:1; transform:none} }
.page-enter { opacity:0 }
.page-enter-active { animation: fadeUp .45s ease forwards }

/* Inputs */
.input, select {
  background: rgba(255,255,255,.9);
  border:1px solid rgba(0,0,0,.12);
  color:#222;
  padding:10px 12px; border-radius:10px; width:100%;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.input:focus, select:focus {
  outline: none;
  border-color: rgba(37,99,235,.6);
  box-shadow: 0 0 0 4px rgba(37,99,235,.15);
}

/* Section headings */
h3 {
  font-family: 'Nunito Sans', 'Inter', sans-serif;
  font-weight: 800;
  font-size: 1.75rem;
  margin: 24px 0 12px;
  color: var(--text-strong);
}

/* === Leaderboard Toggle Buttons === */
.toggle-group {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 20px;
}

.toggle-btn {
  padding: 0.55rem 1.2rem;
  border-radius: 999px;
  border: 1px solid rgba(0,0,0,.08);
  background: rgba(255,255,255,0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-weight: 700;
  cursor: pointer;
  transition: all 0.25s ease;
}

.toggle-btn.active {
  background: var(--accent);
  color: var(--text-invert);
  box-shadow: 0 4px 12px rgba(37,99,235,.25);
  transform: translateY(-1px);
}

/* === Leaderboard containers with fade + slide animation === */
.leaderboard {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  transition: opacity 0.45s ease, transform 0.45s ease, visibility 0.45s ease;
}
.leaderboard.hidden {
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px);
  position: absolute;
  pointer-events: none;
  width: 100%;
}

/* Events list mirrors leaderboard behaviour */
.events {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  transition: opacity 0.45s ease, transform 0.45s ease, visibility 0.45s ease;
}
.events.hidden {
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px);
  position: absolute;
  pointer-events: none;
  width: 100%;
}

/* Section toggle */
.section-toggle { margin-bottom: 12px; }
.section-toggle .toggle {
  display: inline-flex; border: 1px solid rgba(0,0,0,.15); border-radius: 999px; overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
}
.section-toggle .toggle-seg {
  padding: 8px 14px; background: #f3f4f6; border: none; cursor: pointer; font-weight: 600;
  transition: all .2s ease; outline: none;
}
.section-toggle .toggle-seg.active { background: white; }
.section-badge { display:inline-block; padding:.2rem .5rem; border-radius: 999px; font-size:.8rem; font-weight:700; }
.badge-primary { background:#d1fae5; color:#065f46; }
.badge-high { background:#dbeafe; color:#1e40af; }
.muted { color:#6b7280; }

@media (min-width: 1280px) {
  .section-toggle .toggle-seg { font-size: 1.05rem; padding: 10px 16px; }
}

/* 3-way spacing */
.section-toggle .toggle-seg{min-width:160px;text-align:center}

/* ============================= */
/* Sticky footer (global, safe)  */
/* ============================= */
.footer{
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: var(--footer-h);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  padding: 0 16px;
  background: var(--glass-bg-strong);
  border-top: 1px solid var(--glass-border);
  box-shadow: 0 -8px 24px rgba(0,0,0,.08);
  backdrop-filter: blur(8px) saturate(120%);
  -webkit-backdrop-filter: blur(8px) saturate(120%);
  z-index: 4; /* Above overlays and content */
  color: var(--muted);
  font-weight: 600;
  text-align: center;
  padding-bottom: max(0px, env(safe-area-inset-bottom));
}

@media (max-width: 480px){
  :root { --footer-h: 64px; }
  .footer { font-size: .95rem; }
}

/* For rare full-bleed sections that need guaranteed clearance */
.fullbleed-bottom-safe {
  padding-bottom: calc(var(--footer-h) + env(safe-area-inset-bottom));
}

/* ============================= */
/* Events table specifics        */
/* ============================= */
.events .table thead th:nth-child(4),
.events .table thead th:nth-child(5),
.events .table thead th:nth-child(6),
.events .table thead th:nth-child(7),
.events .table tbody td:nth-child(4),
.events .table tbody td:nth-child(5),
.events .table tbody td:nth-child(6),
.events .table tbody td:nth-child(7) {
  text-align: center !important;
  vertical-align: middle;
}

/* Date column */
.col-updated { white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ============================= */
/* Mobile table scroller + fades */
/* ============================= */
.table-wrap{
  position: relative;
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  scrollbar-gutter: stable both-edges;
}
.table-wrap::-webkit-scrollbar{ height:10px; }
.table-wrap::-webkit-scrollbar-thumb{ background: rgba(0,0,0,.15); border-radius:8px; }
.table-wrap::-webkit-scrollbar-track{ background: transparent; }

.table-wrap::before,
.table-wrap::after{
  content:"";
  position:absolute;
  top:0; bottom:0;
  width:24px;
  pointer-events:none;
  opacity:0;
  transition:opacity .2s ease;
  z-index: 1;
}
.table-wrap::before{
  left:0;
  background: linear-gradient(to right, rgba(0,0,0,.08), rgba(0,0,0,0));
}
.table-wrap::after{
  right:0;
  background: linear-gradient(to left, rgba(0,0,0,.08), rgba(0,0,0,0));
}
.table-wrap.can-scroll.at-start::after   { opacity:.6; }
.table-wrap.can-scroll.at-middle::before,
.table-wrap.can-scroll.at-middle::after  { opacity:.6; }
.table-wrap.can-scroll.at-end::before    { opacity:.6; }

@media (max-width: 900px){
  .events .table { min-width: 720px; }
  [data-leaderboard]  { min-width: 520px; }
}
@media (max-width: 420px){
  .table th, .table td { font-size: 1rem; }
  .rank, .points { font-size: 1.15rem; }
}

/* ============================= */
/* Safe global spacer (JS-toggled) */
/* ============================= */
.footer-spacer {
  block-size: 0;
  inline-size: 100%;
  transition: block-size .25s ease;
  pointer-events: none;
}
.footer-spacer.is-active {
  block-size: var(--footer-safe-gap);
}

@media (max-width: 640px){
  :root { --footer-safe-gap: 96px; }
}

/* ============================= */
/* FIX: Login page specific lift */
/* ============================= */
.login-card .card{
  /* Pull the login card closer to the header */
  margin: 24px auto;
}
@media (max-width: 640px){
  .login-card .card{ margin: 16px auto; }
}
