:root {
  --green-900: #0d2f21;
  --green-700: #1f5f3a;
  --green-500: #2f8f5a;
  --sand-100: #f4eedf;
  --sand-200: #e7ddc7;
  --ink-900: #17201b;
  --ink-700: #2f3b35;
  --mist: #dceadf;
  --warning: #b55d3d;
  --shadow: 0 16px 34px rgba(13, 47, 33, 0.14);
  --radius-lg: 16px;
  --radius-md: 12px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink-900);
  font-family: Manrope, "Segoe UI", sans-serif;
  background: radial-gradient(circle at 15% 5%, #fef8eb, #f2ebdb 35%, #e4ebdf 100%);
}

.bg-noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.09;
  background-image: linear-gradient(120deg, rgba(47, 143, 90, 0.4) 15%, transparent 15%),
    linear-gradient(120deg, transparent 85%, rgba(13, 47, 33, 0.4) 85%);
  background-size: 22px 22px;
}

h1,
h2,
h3,
th {
  font-family: "Playfair Display", Georgia, serif;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.2rem;
  background: rgba(13, 47, 33, 0.92);
  backdrop-filter: blur(5px);
  color: #fff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.brand-mark {
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-weight: 800;
  color: var(--green-900);
  background: linear-gradient(145deg, #ecf8d2, #d9f0ae);
}

.eyebrow {
  margin: 0;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  opacity: 0.8;
}

h1 {
  margin: 0;
  font-size: 1.35rem;
}

.layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  padding: 1rem;
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
}

.panel {
  border-radius: var(--radius-lg);
  border: 1px solid rgba(31, 95, 58, 0.16);
  background: rgba(255, 255, 255, 0.83);
  box-shadow: var(--shadow);
  padding: 1rem;
  width: 100%;
}

.auth-panel {
  animation: fadeIn 350ms ease;
}

.toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.toolbar .filters {
  min-width: min(280px, 100%);
}

.filters select,
input,
select {
  width: 100%;
  padding: 0.7rem 0.8rem;
  border-radius: var(--radius-md);
  border: 1px solid rgba(31, 95, 58, 0.25);
  background: #fff;
  font: inherit;
  color: var(--ink-900);
}

label {
  display: grid;
  gap: 0.4rem;
  font-size: 0.92rem;
  color: var(--ink-700);
}

.stack {
  display: grid;
  gap: 0.8rem;
}

.btn {
  border: 0;
  border-radius: 999px;
  padding: 0.6rem 1rem;
  font-weight: 700;
  font: inherit;
  cursor: pointer;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  color: white;
  background: linear-gradient(120deg, var(--green-700), var(--green-500));
}

.btn-secondary {
  color: var(--green-900);
  background: linear-gradient(120deg, #d6edc6, #c4e1b3);
}

.btn-ghost {
  color: white;
  background: rgba(255, 255, 255, 0.16);
}

.content {
  display: grid;
  gap: 1rem;
}

.tab-bar {
  display: flex;
  gap: 0.5rem;
}

.tab-btn {
  border: 1px solid rgba(31, 95, 58, 0.25);
  background: rgba(255, 255, 255, 0.92);
  color: var(--green-900);
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.tab-btn.active {
  color: white;
  background: linear-gradient(120deg, var(--green-700), var(--green-500));
  border-color: transparent;
}

.tab-panel {
  display: grid;
  gap: 1rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
}

.stat {
  border-radius: var(--radius-md);
  padding: 0.8rem;
  background: linear-gradient(165deg, #f6fbf6 10%, #dceadf 100%);
}

.stat p {
  margin: 0;
}

.stat .label {
  font-size: 0.82rem;
  color: var(--ink-700);
}

.stat .value {
  font-size: 1.2rem;
  font-weight: 800;
}

.table-wrap {
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead {
  background: rgba(31, 95, 58, 0.12);
}

th,
td {
  padding: 0.72rem 0.55rem;
  text-align: left;
  border-bottom: 1px solid rgba(31, 95, 58, 0.14);
}

tbody tr:hover {
  background: rgba(47, 143, 90, 0.08);
}

.mobile-cards {
  display: none;
  gap: 0.75rem;
}

.mobile-card {
  border-radius: var(--radius-md);
  border: 1px solid rgba(31, 95, 58, 0.14);
  background: #fff;
  padding: 0.8rem;
}

.match-modal {
  width: min(940px, 96vw);
  border: 0;
  border-radius: var(--radius-lg);
  padding: 0;
  background: transparent;
}

.match-modal::backdrop {
  background: rgba(13, 47, 33, 0.4);
}

.modal-head,
.players-head,
.modal-actions,
.admin-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.modal-head .btn-ghost {
  color: var(--green-900);
  background: rgba(13, 47, 33, 0.12);
  border: 1px solid rgba(13, 47, 33, 0.22);
}

.modal-head .btn-ghost:hover {
  background: rgba(13, 47, 33, 0.2);
}

.match-grid,
.season-form,
.default-season-form {
  display: grid;
  gap: 0.8rem;
  margin-bottom: 0.9rem;
}

.admin-list-wrap {
  display: grid;
  gap: 0.7rem;
}

#adminPlayersTable,
#adminMatchesTable {
  width: 100%;
  border-collapse: collapse;
}

.actions-cell {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.actions-cell .btn {
  padding: 0.4rem 0.7rem;
  font-size: 0.85rem;
}

.btn-danger {
  color: #fff;
  background: linear-gradient(120deg, #b55d3d, #9f3f2e);
}

.player-rows {
  display: grid;
  gap: 0.8rem;
}

.player-row {
  display: grid;
  gap: 0.55rem;
  border-radius: var(--radius-md);
  border: 1px solid rgba(31, 95, 58, 0.17);
  padding: 0.7rem;
  background: rgba(244, 251, 244, 0.7);
}

.player-row .row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.muted {
  margin: 0;
  color: var(--ink-700);
}

.hint {
  margin: 0;
  color: var(--ink-700);
  font-size: 0.85rem;
}

.hidden {
  display: none !important;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  max-width: min(460px, 90vw);
  padding: 0.8rem 1rem;
  border-radius: 12px;
  color: #fff;
  background: rgba(13, 47, 33, 0.94);
  transform: translateY(140%);
  transition: transform 260ms ease;
  z-index: 30;
}

.toast.show {
  transform: translateY(0);
}

.toast.error {
  background: rgba(181, 93, 61, 0.95);
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (min-width: 900px) {
  .layout {
    grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
    gap: 1.2rem;
    padding: 1.1rem 1.3rem;
  }

  .layout.auth-hidden {
    grid-template-columns: minmax(0, 1fr);
  }

  .layout.auth-hidden .content {
    max-width: none;
  }

  #leaderboardTab .stats-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .match-grid,
  .season-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .player-row {
    grid-template-columns: 1.4fr repeat(4, minmax(0, 1fr));
    align-items: end;
  }

  .player-row .row-head {
    grid-column: 1 / -1;
  }
}

@media (min-width: 1200px) {
  #leaderboardTab {
    grid-template-columns: repeat(12, minmax(0, 1fr));
    align-items: start;
  }

  #leaderboardTab .toolbar,
  #leaderboardTab .stats-grid,
  #leaderboardTab .table-wrap {
    grid-column: 1 / -1;
  }

  #leaderboardTab .table-wrap {
    min-height: 420px;
  }
}

@media (max-width: 820px) {
  #leaderboardTable {
    display: none;
  }

  .mobile-cards {
    display: grid;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
