:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #1f2937;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2563eb;
  --accent-contrast: #ffffff;
  --header-bg: #111827;
  --header-link: #e5e7eb;
  --footer-bg: #0f172a;
  --footer-text: #cbd5e1;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

html[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #111827;
  --surface-2: #0f172a;
  --text: #e5e7eb;
  --text-muted: #94a3b8;
  --border: #243244;
  --accent: #60a5fa;
  --accent-contrast: #0b1220;
  --header-bg: #030712;
  --header-link: #d1d5db;
  --footer-bg: #020617;
  --footer-text: #94a3b8;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

html,
body {
  height: 100dvh;
  overflow: hidden;
}

body {
  background: linear-gradient(180deg, var(--bg) 0%, var(--surface-2) 100%);
  color: var(--text);
  margin: 0;
}

.app-shell {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.app-header {
  flex-shrink: 0;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 4px 16px rgba(2, 6, 23, 0.18);
}

.app-header .navbar {
  padding-top: 0.45rem;
  padding-bottom: 0.45rem;
}

.brand-logo {
  height: 44px;
  width: auto;
  display: block;
}

.app-header .nav-link {
  color: var(--header-link) !important;
  font-weight: 500;
}

.app-header .nav-link:hover {
  color: #ffffff !important;
}

.app-main {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
}

.app-footer {
  flex-shrink: 0;
  background: var(--footer-bg);
  color: var(--footer-text);
  border-top: 1px solid var(--border);
}

.footer-link {
  color: var(--footer-text);
  text-decoration: none;
}

.footer-link:hover {
  color: #ffffff;
}

.card,
.table,
.alert,
.form-control,
.form-select,
textarea {
  border-color: var(--border);
}

.form-control,
.form-select,
textarea {
  background: var(--surface);
  color: var(--text);
}

.form-control::placeholder {
  color: var(--text-muted);
}

.form-control:focus,
.form-select:focus,
textarea:focus {
  background: var(--surface);
  color: var(--text);
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
}

.card {
  background: var(--surface);
  box-shadow: var(--shadow);
  border-radius: 12px;
}

.text-muted,
.small {
  color: var(--text-muted) !important;
}

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

.table thead th {
  border-bottom-color: var(--border);
}

.table tbody tr td {
  border-color: var(--border);
}

.btn-primary {
  background-color: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}

.btn-outline-secondary,
.btn-outline-primary,
.btn-outline-danger,
.btn-outline-warning {
  border-color: var(--border);
}

html {
  font-size: 14px;
}

@media (min-width: 768px) {
  html {
    font-size: 16px;
  }
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
  box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
}

html {
  position: relative;
  min-height: 100%;
}

body {
  margin-bottom: 60px;
}

.form-floating > .form-control-plaintext::placeholder, .form-floating > .form-control::placeholder {
  color: var(--bs-secondary-color);
  text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder, .form-floating > .form-control:focus::placeholder {
  text-align: start;
}

.dashboard-header {
  padding: 0.5rem 0;
}

.dashboard-stat {
  border: 1px solid #e9ecef;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.dashboard-stat:hover {
  transform: translateY(-2px);
  box-shadow: 0 0.375rem 1rem rgba(0, 0, 0, 0.08);
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1.2;
}

.quick-action {
  border: 1px solid #e9ecef;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.quick-action:hover {
  transform: translateY(-2px);
  box-shadow: 0 0.5rem 1.25rem rgba(0, 0, 0, 0.08);
}

.live-scoreboard {
  background: #101010;
  color: #f8f9fa;
  min-height: 60vh;
}

.live-player-card {
  background: #1f1f1f;
  border: 1px solid #2d2d2d;
  border-radius: 12px;
  padding: 1rem;
}

.live-player-name {
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
}

.live-player-score {
  font-size: 3rem;
  line-height: 1.1;
  font-weight: 700;
  margin-bottom: 1rem;
}

.timer-value {
  font-size: 2rem;
  font-weight: 700;
}

/* Final overrides against scaffold defaults */
body {
  margin-bottom: 0 !important;
}

.dashboard-stat,
.quick-action {
  border-color: var(--border) !important;
  background: var(--surface) !important;
}

.live-scoreboard {
  background: var(--surface-2) !important;
  color: var(--text) !important;
  border: 1px solid var(--border);
}

.live-player-card {
  background: var(--surface) !important;
  border-color: var(--border) !important;
}

html[data-theme="dark"] .stat-value,
html[data-theme="dark"] .h6 {
  color: #ffffff;
}

.home-hero {
  background: linear-gradient(135deg, var(--surface) 0%, var(--surface-2) 100%);
  box-shadow: var(--shadow);
}

.page-card {
  border: 1px solid var(--border);
}

.auth-card {
  border: 1px solid var(--border);
  backdrop-filter: blur(2px);
}

.auth-card .form-label {
  font-weight: 600;
}

.section-title {
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.kpi-card .card-body {
  padding: 0.9rem 1rem;
}

.live-item {
  background: color-mix(in srgb, var(--surface) 88%, transparent);
}

.touch-select {
  min-height: 2.35rem;
}

@media (max-width: 991.98px) {
  .home-hero h1 {
    font-size: clamp(1.45rem, 6vw, 2rem);
  }

  .stat-value {
    font-size: 1.35rem;
  }
}

@media (max-width: 767.98px) {
  .home-hero .card-body,
  .card .card-body {
    padding: 0.95rem;
  }

  .list-group-item {
    padding-top: 0.6rem;
    padding-bottom: 0.6rem;
  }
}

.home-banner {
  display: block;
  width: 100%;
  height: 100px;
  object-fit: cover;
  object-position: center;
  background: linear-gradient(135deg, var(--surface) 0%, var(--surface-2) 100%);
}

.dropdown-menu {
  border-color: var(--border);
}

.dropdown-item,
.dropdown-item:focus,
.dropdown-item:hover {
  color: var(--text);
}

.dropdown-item:active {
  color: var(--accent-contrast);
  background-color: var(--accent);
}

.user-avatar-img,
.user-avatar {
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 999px;
  object-fit: cover;
}

.user-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  background: color-mix(in srgb, #ffffff 25%, var(--accent));
  color: #ffffff;
}

.avatar-picker {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.6rem;
}

.avatar-option {
  min-width: 0;
}

.avatar-tile {
  width: 100%;
  border: 2px solid var(--border);
  border-radius: 12px;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0.35rem;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease;
  background: var(--surface);
}

.avatar-tile-img {
  width: 52px;
  height: 52px;
}

.btn-check:checked + .avatar-tile {
  border-color: var(--accent);
  transform: translateY(-1px);
}

html[data-theme="dark"] .user-avatar {
  background: color-mix(in srgb, var(--accent) 65%, #ffffff 10%);
  color: #ffffff;
}

html[data-theme="dark"] .text-muted,
html[data-theme="dark"] .small,
html[data-theme="dark"] .form-label,
html[data-theme="dark"] .table,
html[data-theme="dark"] .table > :not(caption) > * > *,
html[data-theme="dark"] .list-group-item,
html[data-theme="dark"] .card,
html[data-theme="dark"] .card-title,
html[data-theme="dark"] .card-text,
html[data-theme="dark"] .dropdown-menu,
html[data-theme="dark"] .dropdown-item,
html[data-theme="dark"] .alert {
  color: var(--text) !important;
}

html[data-theme="dark"] .dropdown-menu,
html[data-theme="dark"] .list-group-item,
html[data-theme="dark"] .table,
html[data-theme="dark"] .table > :not(caption) > * > *,
html[data-theme="dark"] .alert,
html[data-theme="dark"] .form-control,
html[data-theme="dark"] .form-select,
html[data-theme="dark"] .btn-outline-secondary,
html[data-theme="dark"] .btn-outline-primary,
html[data-theme="dark"] .btn-outline-danger {
  border-color: var(--border) !important;
}

html[data-theme="dark"] .dropdown-menu,
html[data-theme="dark"] .list-group-item,
html[data-theme="dark"] .alert,
html[data-theme="dark"] .table,
html[data-theme="dark"] .form-control,
html[data-theme="dark"] .form-select {
  background-color: var(--surface) !important;
}

html[data-theme="dark"] a,
html[data-theme="dark"] .btn-link {
  color: #93c5fd;
}

html[data-theme="dark"] a:hover,
html[data-theme="dark"] .btn-link:hover {
  color: #bfdbfe;
}

html[data-theme="dark"] .section-title,
html[data-theme="dark"] .h1,
html[data-theme="dark"] .h2,
html[data-theme="dark"] .h3,
html[data-theme="dark"] .h4,
html[data-theme="dark"] .h5,
html[data-theme="dark"] .h6,
html[data-theme="dark"] h1,
html[data-theme="dark"] h2,
html[data-theme="dark"] h3,
html[data-theme="dark"] h4,
html[data-theme="dark"] h5,
html[data-theme="dark"] h6,
html[data-theme="dark"] .stat-value {
  color: #fff !important;
}

@media (min-width: 1200px) {
  .home-primary-grid {
    /* Keep cards inside visible app area; avoid pushing into footer zone */
    height: calc(100dvh - 250px);
    min-height: 0;
  }

  .home-primary-grid > [class*="col-"] {
    display: flex;
    min-height: 0;
  }

  .home-primary-grid .card {
    flex: 1;
    min-height: 0;
  }

  .home-primary-grid .card .card-body {
    overflow-y: auto;
    overflow-x: hidden;
  }
}

.loading-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(3, 7, 18, 0.72);
  z-index: 2000;
  pointer-events: none;
}

.loading-overlay.is-visible {
  display: flex;
  pointer-events: all;
  cursor: not-allowed;
}

.loading-overlay-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem 2.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

.loading-overlay-gif {
  width: 192px;
  height: 192px;
  object-fit: contain;
}

.loading-overlay-label {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.03em;
}

.live-score-card {
  border: 1px solid var(--border);
}

.live-meta-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 0.9rem;
  padding: 0.75rem 0.9rem;
  height: 100%;
}

.match-create-shell {
  max-width: 980px;
  margin: 0 auto;
}

.match-create-card {
  border: 1px solid var(--border);
}

.player-picker-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.85rem 0.95rem;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

#playerSearchList .list-group-item {
  border-color: var(--border);
}

html[data-theme="dark"] .player-picker-box {
  background: var(--surface);
}
