:root {
  --bg: #eef2f6;
  --ink: #17212b;
  --ink-soft: #5b6978;
  --panel: rgba(255, 255, 255, 0.84);
  --line: rgba(23, 33, 43, 0.1);
  --primary: #0a9d75;
  --primary-strong: #0a6f56;
  --warning: #b91c1c;
  --required-bg: #fff9cf;
  --shadow: 0 14px 38px rgba(15, 23, 33, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Space Grotesk", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 10%, rgba(72, 94, 116, 0.16) 0%, transparent 42%),
    radial-gradient(circle at 88% 14%, rgba(10, 157, 117, 0.12) 0%, transparent 36%),
    linear-gradient(160deg, #f6f8fb 0%, #e9eef4 52%, #eef2f6 100%);
  overflow-x: hidden;
}

.bg-aurora {
  position: fixed;
  inset: -10% -20% auto -20%;
  height: 56vh;
  background: linear-gradient(108deg, rgba(98, 122, 148, 0.2), rgba(10, 157, 117, 0.16));
  filter: blur(42px);
  pointer-events: none;
  z-index: 0;
}

.bg-grid {
  position: fixed;
  inset: 0;
  background-image: linear-gradient(to right, rgba(23, 33, 43, 0.035) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(23, 33, 43, 0.035) 1px, transparent 1px);
  background-size: 52px 52px;
  mask-image: radial-gradient(circle at center, black, transparent 78%);
  pointer-events: none;
  z-index: 0;
}

.shell {
  width: min(1100px, 94vw);
  margin: 36px auto 48px;
  display: grid;
  gap: 18px;
  position: relative;
  z-index: 1;
  animation: rise 550ms ease-out;
}

.shell > * {
  min-width: 0;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3rem);
  letter-spacing: -0.03em;
}

.topbar p {
  margin: 8px 0 0;
  color: var(--ink-soft);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  min-width: 0;
}

.tab-panel {
  min-width: 0;
}

h2,
h3 {
  margin: 0 0 10px;
}

.muted {
  color: var(--ink-soft);
}

.passcode-form {
  display: flex;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
}

input,
select,
button {
  border-radius: 12px;
  border: 1px solid var(--line);
  font-family: inherit;
  font-size: 0.95rem;
}

input,
select {
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.9);
  min-width: 220px;
}

button {
  padding: 10px 14px;
  background: var(--primary);
  color: white;
  border-color: transparent;
  cursor: pointer;
  font-weight: 600;
}

button:hover {
  background: var(--primary-strong);
}

button.ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}

.portal-header {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
}

.filters h3 {
  margin-bottom: 8px;
}

.filter-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: end;
}

.filter-row label {
  display: grid;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.tab-btn {
  background: rgba(255, 255, 255, 0.74);
  color: var(--ink);
  border: 1px solid var(--line);
}

.tab-btn.active {
  background: var(--primary);
  color: white;
  border-color: transparent;
}

.tab-panel h3 {
  margin-bottom: 8px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

#refreshGamesBtn {
  padding: 7px 12px;
}

#gamesAccordion {
  display: grid;
  gap: 10px;
}

.round-group {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.7);
  overflow: hidden;
}

.round-group > summary {
  cursor: pointer;
  padding: 10px 12px;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.86);
}

.round-group > summary::marker {
  color: var(--primary-strong);
}

.round-content {
  padding: 6px 10px 10px;
}

.games-cards {
  display: none;
}

.game-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.82);
  display: grid;
  gap: 8px;
}

.game-card-match {
  font-weight: 700;
  color: var(--ink);
  line-height: 1.35;
}

.game-card-match span {
  color: var(--ink-soft);
  font-weight: 500;
}

.game-card-meta {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 8px;
  align-items: start;
  font-size: 0.84rem;
}

.game-card-meta strong {
  color: var(--ink-soft);
}

.winner-tag {
  margin-left: 6px;
}

.comment-pop {
  position: relative;
  display: inline-block;
}

.comment-pop > summary {
  list-style: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
}

.comment-pop > summary::-webkit-details-marker {
  display: none;
}

.comment-popover {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 10;
  width: min(260px, 70vw);
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-soft);
  box-shadow: var(--shadow);
  font-size: 0.82rem;
  line-height: 1.35;
}

.pending-submit-btn {
  margin-left: 8px;
  padding: 4px 9px;
  font-size: 0.78rem;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  border: none;
}

.detail-head {
  margin-top: 18px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.metric-toggle {
  display: inline-flex;
  gap: 12px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.78);
}

.metric-toggle label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.88rem;
  color: var(--ink-soft);
}

.table-wrap {
  overflow-x: auto;
  max-width: 100%;
}

.leaderboard-cards {
  display: grid;
  gap: 10px;
}

.leaderboard-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.82);
  padding: 10px 12px;
  display: grid;
  gap: 10px;
  min-width: 0;
}

.leaderboard-card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.leaderboard-card-head strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.leaderboard-rank {
  display: inline-flex;
  min-width: 52px;
  justify-content: center;
  align-items: center;
  border-radius: 999px;
  border: 1px solid rgba(10, 111, 86, 0.45);
  background: rgba(10, 157, 117, 0.18);
  color: #07523f;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.96rem;
  font-weight: 800;
  padding: 5px 10px;
}

.leaderboard-card-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.72);
  min-width: 0;
  font-size: 0.86rem;
  color: var(--ink-soft);
}

.leaderboard-card-metrics span {
  white-space: nowrap;
}

.leaderboard-card-metrics strong {
  color: var(--ink);
}

.leaderboard-card-metrics .points-positive,
.leaderboard-card-metrics .points-negative {
  font-weight: 700;
}

.leaderboard-chart {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.82);
  padding: 10px;
}

.leaderboard-chart h4 {
  margin: 0 0 8px;
  font-size: 0.94rem;
}

.chart-wrap {
  overflow-x: auto;
}

.leaderboard-chart svg {
  display: block;
  width: 100%;
  min-width: 0;
  height: auto;
}

.chart-axis {
  stroke: rgba(20, 19, 17, 0.45);
  stroke-width: 1;
}

.chart-grid {
  stroke: rgba(20, 19, 17, 0.14);
  stroke-width: 1;
}

.chart-axis-label {
  fill: #5e5a54;
  font-size: 11px;
  font-family: "IBM Plex Mono", monospace;
}

.chart-point-rank {
  fill: #4f5d6b;
  font-size: 9px;
  font-family: "IBM Plex Mono", monospace;
  font-weight: 600;
}

.chart-end-label {
  fill: #2f2b27;
  font-size: 10px;
  font-weight: 500;
  font-family: "Space Grotesk", sans-serif;
}

.chart-end-label-strong {
  font-weight: 700;
}

.leaderboard-chart-ribbon {
  margin-top: 10px;
}

.leaderboard-expand {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.72);
  overflow: hidden;
}

.leaderboard-expand > summary {
  list-style: none;
  cursor: pointer;
  padding: 8px 10px;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.leaderboard-expand > summary::-webkit-details-marker {
  display: none;
}

.leaderboard-expand > summary::after {
  content: "Show";
  float: right;
  font-weight: 500;
}

.leaderboard-expand[open] {
  background: rgba(10, 157, 117, 0.08);
}

.leaderboard-expand[open] > summary {
  background: rgba(10, 157, 117, 0.12);
}

.leaderboard-expand[open] > summary::after {
  content: "Hide";
}

.leaderboard-expand-body {
  display: grid;
  border-top: 1px solid var(--line);
  background: rgba(10, 157, 117, 0.04);
}

.leaderboard-round-row {
  display: grid;
  grid-template-columns: minmax(72px, 110px) minmax(0, 1fr) auto;
  gap: 8px;
  padding: 8px 10px;
  font-size: 0.82rem;
}

.leaderboard-round-row + .leaderboard-round-row {
  border-top: 1px solid var(--line);
}

.winner-inline-icon {
  font-size: 0.84rem;
  line-height: 1;
  margin-left: 2px;
}

.points-positive {
  color: #166534;
  font-weight: 700;
}

.points-negative {
  color: #b91c1c;
  font-weight: 700;
}

table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.82rem;
}

th,
td {
  text-align: left;
  border-bottom: 1px solid var(--line);
  padding: 8px 4px;
  white-space: nowrap;
}

th {
  width: 1%;
}

.leaderboard-detail-table th,
.leaderboard-detail-table td {
  padding-right: 10px;
}

.error {
  color: var(--warning);
}

.hidden {
  display: none !important;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(12, 15, 14, 0.55);
}

.modal-panel {
  position: relative;
  width: min(640px, 94vw);
  max-height: 88vh;
  overflow-y: auto;
  margin: 5vh auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 14px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.modal-form {
  display: grid;
  gap: 10px;
}

.modal-form label {
  display: grid;
  gap: 6px;
  font-size: 0.88rem;
  color: var(--ink-soft);
}

.field-label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.required-mark {
  color: #b45309;
  font-weight: 700;
}

.required-field input:not([type="hidden"]),
.required-field select,
.required-field textarea,
.required-field .matchup-display {
  background: var(--required-bg);
}

.matchup-display {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--ink);
  font-weight: 600;
}

.score-entry {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.score-row {
  display: flex;
  flex-direction: column;
  justify-content: center;
  flex: 1 1 102px;
  min-width: 102px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.78);
  gap: 8px;
}

.score-row.required-score {
  background: var(--required-bg);
}

.score-row span {
  font-size: 0.82rem;
  color: var(--ink-soft);
  font-weight: 600;
}

.score-row input {
  min-width: 0;
  width: 100%;
}

textarea {
  border-radius: 12px;
  border: 1px solid var(--line);
  font-family: inherit;
  font-size: 0.95rem;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.9);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 6px;
}

.modal-actions button {
  min-height: 42px;
}

.confirm-box {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: rgba(245, 245, 245, 0.7);
}

.confirm-grid {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 6px 10px;
  font-size: 0.88rem;
}

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

@media (max-width: 900px) {
  .tabs {
    flex-wrap: wrap;
  }

  .tab-btn {
    flex: 1 1 auto;
  }

  table {
    font-size: 0.78rem;
  }

  .confirm-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  .modal-panel {
    width: 100vw;
    max-height: 100dvh;
    margin: 0;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
    padding: 12px;
  }

  .modal-header {
    position: sticky;
    top: -12px;
    z-index: 2;
    background: #fff;
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .modal-form input,
  .modal-form select,
  .modal-form textarea {
    width: 100%;
    min-width: 0;
    font-size: 16px;
  }

  .score-row {
    min-width: calc(50% - 8px);
  }

  .games-table-wrap {
    display: none;
  }

  .games-cards {
    display: grid;
    gap: 8px;
  }

  .game-card-meta {
    grid-template-columns: 64px 1fr;
  }

  .leaderboard-card-metrics {
    font-size: 0.82rem;
  }

  .leaderboard-card-metrics span {
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .leaderboard-round-row {
    grid-template-columns: minmax(62px, 92px) minmax(0, 1fr) auto;
  }

  .modal-actions {
    position: sticky;
    bottom: -12px;
    background: #fff;
    padding: 10px 0 2px;
    justify-content: stretch;
  }

  .modal-actions button {
    flex: 1 1 0;
  }

  .comment-popover {
    right: auto;
    left: 0;
    width: min(280px, 78vw);
  }
}
