:root {
  --ink: #18201d;
  --muted: #64706b;
  --paper: #f6f7f2;
  --panel: #ffffff;
  --line: #dce2dc;
  --green: #17604f;
  --blue: #315f84;
  --gold: #be8b31;
  --red: #b85850;
  --mint: #dff1e9;
  --sky: #e6f0f7;
  --sand: #f8efd9;
  --shadow: 0 14px 34px rgba(24, 32, 29, 0.1);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100svh;
  color: var(--ink);
  background: linear-gradient(180deg, #e8f3ee 0, var(--paper) 320px);
  font-family:
    Inter, "Segoe UI", "Noto Sans SC", "PingFang SC", "Microsoft YaHei",
    sans-serif;
  letter-spacing: 0;
}

button,
select,
input {
  font: inherit;
}

button,
select {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: var(--blue);
  font-weight: 800;
  overflow-wrap: anywhere;
}

.app-shell {
  width: min(100%, 980px);
  margin: 0 auto;
  padding: 16px 14px calc(28px + var(--safe-bottom));
}

.access-shell {
  width: min(100%, 460px);
  margin: 0 auto;
  padding: max(48px, 10vh) 14px calc(28px + var(--safe-bottom));
}

.access-brand {
  margin-bottom: 20px;
}

.access-panel {
  padding: 22px;
  border: 1px solid rgba(23, 96, 79, 0.16);
  border-top: 5px solid var(--green);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.access-panel form {
  display: grid;
  gap: 14px;
  margin-top: 20px;
}

.segmented-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f2f5f1;
}

.segmented-control button {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 900;
}

.segmented-control button[aria-selected="true"] {
  background: #ffffff;
  color: var(--green);
  box-shadow: 0 1px 4px rgba(24, 32, 29, 0.12);
}

.primary-button {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--green);
  border-radius: 8px;
  background: var(--green);
  color: #ffffff;
  font-weight: 900;
}

.primary-button:disabled,
.secondary-button:disabled {
  cursor: wait;
  opacity: 0.62;
}

.form-message {
  min-height: 1.4em;
  margin: 12px 0 0;
  color: var(--red);
  font-size: 0.86rem;
  font-weight: 800;
}

.paywall-panel > p:not(.eyebrow) {
  margin: 14px 0;
  color: var(--muted);
  line-height: 1.5;
}

.paywall-status {
  margin-bottom: 14px;
  padding: 14px;
  border-left: 4px solid var(--gold);
  background: var(--sand);
  color: var(--ink);
  font-weight: 900;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px 0 16px;
}

.topbar-actions {
  display: grid;
  gap: 8px;
  justify-items: end;
}

.account-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
}

.account-actions > span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.55rem, 5vw, 2.5rem);
  line-height: 1.08;
}

h2 {
  margin-bottom: 0;
  font-size: 1.25rem;
  line-height: 1.18;
}

h3 {
  margin-bottom: 0;
  font-size: 1.02rem;
  line-height: 1.25;
}

.tracked-player {
  max-width: 180px;
  padding: 9px 11px;
  border: 1px solid rgba(23, 96, 79, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
  color: var(--green);
  font-size: 0.84rem;
  font-weight: 900;
  text-align: right;
  overflow-wrap: anywhere;
}

.panel {
  margin-top: 14px;
  padding: 16px;
  border: 1px solid rgba(23, 96, 79, 0.13);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.hero-panel {
  border-top: 5px solid var(--green);
}

.section-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(86px, 1fr));
  gap: 8px;
  width: min(100%, 260px);
}

.athlete-query-grid {
  display: grid;
  grid-template-columns: 136px 82px minmax(170px, 1.7fr) 82px 82px;
  gap: 8px;
  width: min(100%, 640px);
}

.ranking-filters {
  grid-template-columns: repeat(2, minmax(78px, 1fr));
}

label {
  display: grid;
  gap: 5px;
}

label span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
}

select,
input {
  width: 100%;
  min-height: 42px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  outline: none;
}

select:focus,
input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(23, 96, 79, 0.14);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 9px;
  margin-bottom: 12px;
}

.summary-card {
  min-height: 70px;
  padding: 11px;
  border-radius: 8px;
  background: var(--sky);
}

.summary-card:nth-child(2) {
  background: var(--mint);
}

.summary-card:nth-child(3) {
  background: var(--sand);
}

.summary-card:nth-child(4) {
  background: #f1eaf0;
}

.summary-card span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
}

.summary-card strong {
  display: block;
  margin-top: 7px;
  font-size: 1.35rem;
  line-height: 1;
}

.coverage-note {
  margin: 10px 0;
  padding: 10px 12px;
  border-left: 3px solid var(--gold);
  background: var(--sand);
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.5;
}

.event-list {
  display: grid;
  gap: 10px;
}

.event-card {
  display: grid;
  gap: 11px;
  width: 100%;
  padding: 14px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--green);
  border-radius: 8px;
  background: #ffffff;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.event-card.pending {
  border-left-color: var(--gold);
}

.event-card header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.event-card header > * {
  min-width: 0;
}

.event-card p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.42;
  overflow-wrap: anywhere;
}

.badge-row,
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.badge,
.chip {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  padding: 0 9px;
  border-radius: 999px;
  background: #eef4ef;
  color: var(--green);
  font-size: 0.74rem;
  font-weight: 900;
}

.badge.warn {
  background: #fff5dc;
  color: var(--gold);
}

.event-detail-section {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
}

.section-count {
  color: var(--muted);
  font-size: 0.78rem;
}

.matches-table table {
  min-width: 760px;
}

.badge.danger {
  background: #fae6e3;
  color: var(--red);
}

.chip {
  border: 1px solid var(--line);
  background: #ffffff;
  cursor: pointer;
}

.chip.active {
  border-color: var(--green);
  background: var(--green);
  color: #ffffff;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.fact {
  min-height: 68px;
  padding: 10px;
  border-radius: 8px;
  background: #f4f6f2;
}

.fact span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
}

.fact strong {
  display: block;
  margin-top: 6px;
  overflow-wrap: anywhere;
  line-height: 1.2;
}

.table-wrap {
  overflow-x: auto;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  background: #ffffff;
}

th,
td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

th {
  background: #f2f5f1;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 900;
}

tr:last-child td {
  border-bottom: 0;
}

.ranking-event-details {
  margin-top: 18px;
}

.ranking-event-details > h3 {
  margin-bottom: 10px;
}

.ranking-event-details details {
  border-top: 1px solid var(--line);
}

.ranking-event-details details:last-child {
  border-bottom: 1px solid var(--line);
}

.ranking-event-details summary {
  display: flex;
  min-height: 46px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 2px;
  cursor: pointer;
}

.ranking-event-details summary span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.ranking-event-details details .table-wrap {
  margin: 0 0 12px;
}

button:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(23, 96, 79, 0.22);
  outline-offset: 2px;
}

.empty-state {
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  color: var(--muted);
  line-height: 1.45;
}

.secondary-button {
  min-height: 42px;
  padding: 0 13px;
  border: 1px solid rgba(23, 96, 79, 0.2);
  border-radius: 8px;
  background: var(--mint);
  color: var(--green);
  font-weight: 900;
}

.compact-button {
  min-height: 34px;
  padding: 0 10px;
  font-size: 0.78rem;
}

.admin-panel {
  border-top: 5px solid var(--blue);
}

.admin-table table {
  min-width: 860px;
}

.table-control {
  min-height: 38px;
  min-width: 128px;
}

.admin-table input[type="date"] {
  min-width: 150px;
}

.active-toggle {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 7px;
  min-height: 38px;
}

.active-toggle input {
  width: 18px;
  min-height: 18px;
  margin: 0;
}

.active-toggle span,
.cell-note {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

.source-list,
.pending-list {
  display: grid;
  gap: 9px;
  margin-top: 10px;
}

.source-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.source-card p {
  margin-bottom: 8px;
  color: var(--muted);
  line-height: 1.45;
}

.split-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 12px;
}

@media (max-width: 720px) {
  .app-shell {
    padding-right: 12px;
    padding-left: 12px;
  }

  .topbar,
  .section-title,
  .split-grid {
    grid-template-columns: 1fr;
  }

  .section-title {
    display: grid;
  }

  .tracked-player {
    max-width: 100%;
    text-align: left;
  }

  .topbar-actions {
    justify-items: stretch;
  }

  .account-actions {
    justify-content: flex-start;
  }

  .filter-grid,
  .ranking-filters,
  .athlete-query-grid {
    width: 100%;
  }

  .athlete-query-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .athlete-query-grid label[for="athleteScope"] {
    grid-column: 1 / -1;
  }

  .athlete-query-grid label[for="athleteCategory"] {
    grid-column: 1;
    grid-row: 2;
  }

  .athlete-query-grid label[for="yearSelect"] {
    grid-column: 2;
    grid-row: 2;
  }

  .athlete-query-grid label[for="monthSelect"] {
    grid-column: 3;
    grid-row: 2;
  }

  .athlete-query-grid label[for="athleteSelect"] {
    grid-column: 1 / -1;
    grid-row: 3;
  }

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

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

  .event-card header {
    display: grid;
  }

  .event-card header .badge {
    max-width: 100%;
    justify-self: start;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .panel {
    padding: 14px;
  }
}

@media (max-width: 390px) {
  .summary-grid,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .event-detail-section {
    display: grid;
  }

}
