:root {
  --bg: #0f172a;
  --surface: #111827;
  --surface-alt: #1f2937;
  --card: #1b2437;
  --panel: #0b1120;
  --muted: #94a3b8;
  --text: #e5eefb;
  --text-soft: #cbd5e1;
  --primary: #60a5fa;
  --primary-strong: #2563eb;
  --accent: #34d399;
  --warning: #fbbf24;
  --danger: #f87171;
  --border: rgba(148, 163, 184, 0.18);
  --shadow: 0 18px 40px rgba(15, 23, 42, 0.45);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(180deg, #0b1120 0%, #111827 100%);
  color: var(--text);
}

body {
  min-height: 100vh;
}

h1, h2, h3, p {
  margin: 0;
}

button, input, select {
  font: inherit;
}

.auth-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 1.5rem;
}

.auth-shell {
  width: min(960px, 100%);
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 1.5rem;
}

.brand-panel,
.card {
  background: rgba(17, 24, 39, 0.9);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.brand-panel {
  padding: 2.5rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 460px;
  background: linear-gradient(160deg, rgba(37, 99, 235, 0.18), rgba(16, 185, 129, 0.12));
}

.brand-badge {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1.5rem;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  margin-bottom: 1.25rem;
}

.brand-panel h1 {
  font-size: clamp(2.1rem, 4vw, 3.1rem);
  margin-bottom: 0.75rem;
}

.brand-panel p {
  color: var(--text-soft);
  max-width: 28rem;
  line-height: 1.6;
}

.login-panel {
  padding: 2rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 2rem;
  border-bottom: 1px solid var(--border);
  background: rgba(11, 17, 32, 0.8);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.title-wrap {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  font-weight: 700;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.7rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.nav-link {
  color: var(--text-soft);
  text-decoration: none;
  padding: 0.65rem 0.9rem;
  border-radius: 999px;
  border: 1px solid transparent;
  transition: 0.2s ease;
}

.nav-link.active,
.nav-link:hover {
  border-color: var(--border);
  background: rgba(96, 165, 250, 0.12);
  color: var(--text);
}

.page-shell {
  width: min(1200px, calc(100% - 2rem));
  margin: 2rem auto 3rem;
  display: grid;
  gap: 1.25rem;
}

.narrow-shell {
  width: min(1100px, calc(100% - 2rem));
}

.card {
  padding: 1.4rem;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.inline-head {
  align-items: end;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.9rem;
}

.primary-button,
.ghost-button {
  border: none;
  border-radius: 12px;
  padding: 0.85rem 1.1rem;
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.primary-button:hover,
.ghost-button:hover {
  transform: translateY(-1px);
}

.primary-button {
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  color: white;
}

.primary-button.secondary {
  background: linear-gradient(135deg, #10b981, #059669);
}

.primary-button.muted {
  background: linear-gradient(135deg, #64748b, #475569);
}

.ghost-button {
  background: rgba(148, 163, 184, 0.12);
  color: var(--text);
  border: 1px solid var(--border);
}

.stacked-form {
  display: grid;
  gap: 1rem;
}

.compact-form {
  max-width: 760px;
}

label {
  display: grid;
  gap: 0.45rem;
  color: var(--text-soft);
}

input, select {
  width: 100%;
  background: rgba(15, 23, 42, 0.75);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.8rem 0.85rem;
}

.field-row {
  display: grid;
  gap: 1rem;
}

.two-up {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.toolbar {
  display: flex;
  align-items: end;
  gap: 1rem;
  flex-wrap: wrap;
}

.select-wrap {
  min-width: min(280px, 100%);
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 14px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th, td {
  text-align: left;
  padding: 0.9rem 0.85rem;
  border-bottom: 1px solid var(--border);
}

th {
  background: rgba(148, 163, 184, 0.06);
  font-size: 0.74rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

tbody tr:hover {
  background: rgba(96, 165, 250, 0.04);
}

.summary-chip {
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  background: rgba(52, 211, 153, 0.12);
  color: #a7f3d0;
  border: 1px solid rgba(52, 211, 153, 0.25);
  font-size: 0.8rem;
}

.collection-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.collection-card {
  background: rgba(15, 23, 42, 0.82);
  border: 1px solid var(--border);
  border-radius: 18px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 280px;
}

.collection-thumb {
  height: 140px;
  background: linear-gradient(120deg, rgba(96, 165, 250, 0.2), rgba(52, 211, 153, 0.15));
  display: grid;
  place-items: center;
  color: var(--text-soft);
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.collection-body {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  flex: 1;
}

.collection-title {
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.35;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.32rem 0.6rem;
  border-radius: 999px;
  font-size: 0.72rem;
  border: 1px solid var(--border);
  color: var(--text-soft);
  background: rgba(148, 163, 184, 0.08);
}

.badge.positive {
  background: rgba(52, 211, 153, 0.1);
  border-color: rgba(52, 211, 153, 0.2);
  color: #a7f3d0;
}

.badge.warning {
  background: rgba(251, 191, 36, 0.08);
  border-color: rgba(251, 191, 36, 0.22);
  color: #fef3c7;
}

.meta-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-soft);
}

.meta-label {
  color: var(--muted);
}

.card-actions {
  margin-top: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.link-button {
  background: rgba(96, 165, 250, 0.12);
  border: 1px solid rgba(96, 165, 250, 0.2);
  color: #dbeafe;
  border-radius: 10px;
  padding: 0.5rem 0.75rem;
  font-size: 0.78rem;
}

.inline-message {
  margin-top: 1rem;
  padding: 0.8rem 1rem;
  border-radius: 12px;
  border: 1px solid transparent;
}

.inline-message.info {
  background: rgba(96, 165, 250, 0.12);
  border-color: rgba(96, 165, 250, 0.25);
  color: #dbeafe;
}

.inline-message.success {
  background: rgba(52, 211, 153, 0.08);
  border-color: rgba(52, 211, 153, 0.25);
  color: #d1fae5;
}

.inline-message.error {
  background: rgba(248, 113, 113, 0.08);
  border-color: rgba(248, 113, 113, 0.25);
  color: #fecaca;
}

.hidden {
  display: none;
}

.analytics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.metric-card {
  background: rgba(15, 23, 42, 0.82);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.metric-card span {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.metric-card strong {
  font-size: 1.8rem;
}

.bar-row {
  display: grid;
  grid-template-columns: 120px 1fr 40px;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 0.8rem;
}

.chart-wrap {
  display: grid;
  gap: 0.8rem;
}

.chart-row {
  display: grid;
  grid-template-columns: 140px 1fr 32px;
  align-items: center;
  gap: 0.75rem;
}

.chart-label {
  color: var(--text-soft);
  font-size: 0.8rem;
}

.bar-track {
  position: relative;
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.12);
  overflow: hidden;
}

.bar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
}

.analytics-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.8rem;
}

.analytics-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.85rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.72);
}

.analytics-list li div {
  display: grid;
  gap: 0.2rem;
}

.analytics-list small {
  color: var(--muted);
}

@media (max-width: 760px) {
  .auth-shell {
    grid-template-columns: 1fr;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
    padding: 0.9rem 1rem;
  }

  .title-wrap {
    min-width: 0;
  }

  .title-wrap h1 {
    font-size: 1.35rem;
    overflow-wrap: anywhere;
  }

  .nav-actions {
    width: 100%;
    gap: 0.35rem;
    overflow-x: auto;
    padding-bottom: 0.15rem;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
  }

  .nav-link,
  .nav-actions .ghost-button {
    flex: 0 0 auto;
    min-height: 42px;
  }

  .nav-link {
    padding: 0.6rem 0.75rem;
  }

  .page-shell,
  .narrow-shell {
    width: calc(100% - 1.25rem);
    margin-top: 1rem;
    margin-bottom: 2rem;
    gap: 0.85rem;
  }

  .card {
    padding: 1rem;
    border-radius: 14px;
  }

  .section-head {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .two-up {
    grid-template-columns: 1fr;
  }

  .filter-grid {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.75rem;
  }

  .toolbar {
    align-items: stretch;
  }

  .toolbar > *,
  .action-grid > *,
  .stacked-form > button {
    width: 100%;
  }

  input,
  select,
  button {
    min-height: 44px;
  }

  .stacked-form input[type="checkbox"] {
    width: auto;
    min-height: 0;
  }

  .collection-grid {
    grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
    gap: 0.65rem;
  }

  .collection-card {
    min-height: 0;
    border-radius: 12px;
  }

  .collection-thumb {
    height: 112px;
  }

  .collection-body {
    padding: 0.75rem;
    gap: 0.65rem;
  }

  .analytics-grid {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.65rem;
  }

  .metric-card {
    padding: 0.8rem;
  }

  .metric-card strong {
    font-size: 1.5rem;
  }

  .bar-row,
  .chart-row {
    grid-template-columns: minmax(0, 1fr) 2.5rem;
    gap: 0.45rem 0.65rem;
  }

  .chart-label {
    grid-column: 1 / -1;
    overflow-wrap: anywhere;
  }

  .analytics-list li {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .analytics-list li > div {
    min-width: 0;
    overflow-wrap: anywhere;
  }
}

@media (max-width: 380px) {
  .auth-body {
    padding: 0.75rem;
  }

  .brand-panel,
  .login-panel {
    padding: 1.25rem;
  }

  .page-shell,
  .narrow-shell {
    width: calc(100% - 1rem);
  }

  .collection-grid {
    grid-template-columns: 1fr;
  }

  .field-row,
  .filter-grid {
    gap: 0.65rem;
  }
}

/* Event invitee picker */
.invitee-options {
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.5rem 0.75rem;
  background: rgba(15, 23, 42, 0.75);
}
.invitee-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0;
  cursor: pointer;
}
.invitee-option input { width: auto; }
#inviteeChips button.badge { border: none; cursor: pointer; }
.collection-title a { color: inherit; }

/* Collection page: images, grid/list toggle, list view */
.collection-thumb a { display: grid; place-items: center; width: 100%; height: 100%; }
.collection-thumb .card-image { max-width: 100%; max-height: 140px; object-fit: contain; }
.collection-thumb .placeholder, .list-thumb.placeholder { font-size: 2rem; }
.view-toggle { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.view-toggle .ghost-button.active { background: var(--primary-strong); color: #fff; }
.collection-list table { width: 100%; }
.collection-list td { vertical-align: middle; }
.list-thumb { width: 48px; height: 48px; object-fit: contain; display: inline-block; text-align: center; }
.sort-button { background: none; border: none; color: inherit; font: inherit; cursor: pointer; padding: 0; }
.collection-list a, .collection-thumb a { color: var(--text); text-decoration: none; }
.collection-list a:hover { text-decoration: underline; }
.sort-button { text-transform: inherit; letter-spacing: inherit; font-size: inherit; font-weight: inherit; }
.checkbox-label { display: flex; align-items: center; gap: 0.5rem; align-self: end; padding-bottom: 0.6rem; }
.checkbox-label input { width: auto; }
/* Collection grouping */
.group-head { grid-column: 1 / -1; font-weight: 700; font-size: 1.05rem; padding: 0.6rem 0 0.2rem; border-bottom: 1px solid var(--border); }
.group-head small, .group-row small { color: var(--muted); font-weight: 400; }
.group-row td { font-weight: 700; background: rgba(96, 165, 250, 0.08); }
.expansion-row td:nth-child(2) { padding-left: 1.5rem; }
.expansion-mark { color: var(--muted); }
.expansion-card { border-left: 3px solid var(--primary); }
.detail-lines { display: grid; gap: 0.25rem; font-size: 0.85rem; color: var(--text-soft); margin-top: 0.5rem; }
.detail-lines .meta-label { margin-right: 0.25rem; }
.range-filters { display: flex; flex-wrap: wrap; gap: 1rem 1.5rem; align-items: end; margin-top: 1rem; }
.range-filter { display: grid; gap: 0.35rem; }
.range-filter small { color: var(--muted); }
.range-filter div { display: flex; align-items: center; gap: 0.4rem; }
.range-filter input { width: 5.5rem; }
.group-head, .group-row { cursor: pointer; user-select: none; }
.group-head:hover, .group-row:hover td { color: var(--primary); }
.group-head-toolbar { grid-column: 1 / -1; }
.group-toolbar { display: flex; gap: 0.75rem; margin-bottom: 0.5rem; }
/* Collapsible panels */
.card[data-collapsible] > .section-head { cursor: pointer; user-select: none; }
.panel-toggle { background: none; border: 1px solid var(--border); color: var(--text-soft); border-radius: 999px; width: 2rem; height: 2rem; cursor: pointer; flex-shrink: 0; }
.card.collapsed > :not(.section-head) { display: none !important; }
.card.collapsed > .section-head { margin-bottom: 0; }

/* Collections page: sticky filter sidebar beside the results */
.collection-layout {
  width: min(1600px, calc(100% - 2rem));
  margin: 1.5rem auto 3rem;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 1.25rem;
  align-items: start;
}
.collection-sidebar {
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  display: grid;
  gap: 1rem;
  padding-right: 0.25rem;
}
.collection-main { display: grid; gap: 1.25rem; min-width: 0; }
.collection-sidebar .card { padding: 1rem; }
.collection-sidebar .section-head { margin-bottom: 0.75rem; }
.collection-sidebar h2 { font-size: 1.1rem; }
.collection-sidebar .toolbar, .collection-sidebar .filter-grid { display: grid; grid-template-columns: 1fr; gap: 0.75rem; }
.collection-sidebar .select-wrap, .collection-sidebar select, .collection-sidebar input[type="text"], .collection-sidebar input[type="search"] { width: 100%; }
.collection-sidebar .checkbox-label { align-self: start; padding-bottom: 0; }
.collection-sidebar .range-filters { flex-direction: column; align-items: stretch; gap: 0.75rem; }
.collection-sidebar .range-filter input { width: 100%; }
.collection-sidebar .range-filter div { display: grid; grid-template-columns: 1fr auto 1fr; }
.collection-sidebar .range-filter div:has(> input:only-child) { grid-template-columns: 1fr; }
.collection-sidebar #clearRangeFilters { justify-self: start; }
@media (max-width: 900px) {
  .collection-layout { grid-template-columns: 1fr; width: calc(100% - 1.25rem); }
  .collection-sidebar { position: static; max-height: none; overflow: visible; }
}
.collection-sidebar { top: calc(var(--topbar-height, 92px) + 1rem); max-height: calc(100vh - var(--topbar-height, 92px) - 2rem); }
/* Compare: who matched */
.match-lines { display: grid; gap: 0.2rem; font-size: 0.9rem; margin: 0.5rem 0; }
.match-lines .meta-label { margin-right: 0.25rem; }
.collection-sidebar .invitee-options { max-height: 260px; }
/* Game page */
.game-hero { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 1.5rem; align-items: start; }
.game-hero-image { display: grid; place-items: center; background: rgba(96, 165, 250, 0.08); border-radius: 16px; min-height: 220px; }
.game-hero-image img { max-width: 100%; max-height: 320px; object-fit: contain; border-radius: 12px; }
.game-hero-image .placeholder { font-size: 4rem; }
.status-block { padding: 0.6rem 0; border-bottom: 1px solid var(--border); }
.status-block:last-child { border-bottom: none; }
.status-block h3 { margin: 0 0 0.3rem; font-size: 1rem; }
.status-block h3 small { color: var(--muted); font-weight: 400; }
.status-block p { margin: 0; line-height: 1.7; }
.status-block a, .match-lines a, #eventSummary a { color: var(--primary); }
@media (max-width: 700px) { .game-hero { grid-template-columns: 1fr; } }
/* Sign in with Google */
.google-signin { margin-top: 1rem; display: grid; gap: 0.75rem; justify-items: center; }
.google-signin .divider { width: 100%; display: flex; align-items: center; gap: 0.75rem; color: var(--muted); font-size: 0.85rem; }
.google-signin .divider::before, .google-signin .divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
