:root {
  --forest: #163528;
  --leaf: #2a6b4a;
  --leaf-bright: #3f8f63;
  --mist: #eef3ef;
  --fog: #f7faf7;
  --ink: #142019;
  --muted: #5a6b60;
  --line: rgba(22, 53, 40, 0.12);
  --gold: #c9a227;
  --silver: #8e97a0;
  --bronze: #b87333;
  --star1: #2a6b4a;
  --card: rgba(255, 255, 255, 0.78);
  --shadow: 0 18px 40px rgba(20, 40, 28, 0.08);
  --radius: 18px;
  --font-display: "Syne", sans-serif;
  --font-body: "Manrope", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  font-family: var(--font-body);
  background: var(--fog);
}

.atmosphere {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(63, 143, 99, 0.22), transparent 55%),
    radial-gradient(900px 500px at 95% 5%, rgba(201, 162, 39, 0.12), transparent 50%),
    linear-gradient(180deg, #e7efe9 0%, var(--fog) 42%, #f3f6f2 100%);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.hero {
  max-width: 1100px;
  margin: 0 auto;
  padding: 4.5rem 1.5rem 1.25rem;
  animation: rise 0.7s ease both;
}

.eyebrow {
  margin: 0 0 0.4rem;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--leaf);
}

.hero h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(3rem, 8vw, 5.4rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 0.95;
  color: var(--forest);
}

.lede {
  max-width: 34rem;
  margin: 1rem 0 0;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.5;
}

.view-tabs {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.35rem;
}

.view-tabs .tab {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.7);
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  font-size: 0.92rem;
  padding: 0.55rem 1rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.view-tabs .tab:hover {
  border-color: rgba(42, 107, 74, 0.35);
  color: var(--forest);
}

.view-tabs .tab.active {
  background: var(--forest);
  border-color: var(--forest);
  color: #fff;
}

.hidden { display: none !important; }

.controls {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: grid;
  grid-template-columns: 1.6fr repeat(2, minmax(8rem, 0.7fr)) auto;
  gap: 0.75rem;
  align-items: center;
  animation: rise 0.7s ease 0.08s both;
}

#eventControls {
  grid-template-columns: minmax(7.5rem, 0.65fr) 1.4fr repeat(4, minmax(6.5rem, 0.55fr));
}

@media (max-width: 900px) {
  #eventControls {
    grid-template-columns: 1fr 1fr;
  }
}

.muted-count {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
}

.controls input[type="search"],
.controls select {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.85);
  border-radius: 999px;
  padding: 0.85rem 1.1rem;
  font: inherit;
  color: var(--ink);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.controls input[type="search"]:focus,
.controls select:focus {
  border-color: var(--leaf-bright);
  box-shadow: 0 0 0 3px rgba(63, 143, 99, 0.18);
}

.check {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.92rem;
  color: var(--muted);
  white-space: nowrap;
  user-select: none;
}

.stats {
  max-width: 1100px;
  margin: 1rem auto 0;
  padding: 0 1.5rem;
  color: var(--muted);
  font-size: 0.92rem;
  animation: rise 0.7s ease 0.14s both;
}

.grid {
  max-width: 1100px;
  margin: 1rem auto 4rem;
  padding: 0 1.5rem;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

.card {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card);
  backdrop-filter: blur(10px);
  border-radius: var(--radius);
  padding: 1.15rem 1.2rem 1.2rem;
  text-align: left;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.22s ease, box-shadow 0.22s ease, border-color 0.22s;
  animation: rise 0.45s ease both;
}

.card:hover,
.card:focus-visible {
  transform: translateY(-3px);
  border-color: rgba(42, 107, 74, 0.35);
  box-shadow: 0 22px 44px rgba(20, 40, 28, 0.12);
  outline: none;
}

.card-top {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: flex-start;
}

.grid.events-mode {
  display: block;
  max-width: 1200px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  animation: rise 0.45s ease both;
}

.events-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.events-table th,
.events-table td {
  padding: 0.7rem 0.85rem;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
}

.events-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  background: #eef4f0;
  white-space: nowrap;
}

.events-table thead th.sortable {
  cursor: pointer;
  user-select: none;
}

.events-table thead th.sortable:hover,
.events-table thead th.sorted {
  color: var(--forest);
}

.cal-tag.cal-rts {
  background: rgba(26, 77, 122, 0.12);
  color: #1a4d7a;
}

.events-table tbody tr:hover td {
  background: rgba(42, 107, 74, 0.05);
}

.events-table tbody tr:last-child td {
  border-bottom: 0;
}

.col-date {
  white-space: nowrap;
  color: var(--forest);
  font-weight: 600;
  min-width: 7.5rem;
}

.col-season {
  font-weight: 700;
  color: var(--leaf);
  white-space: nowrap;
}

.col-name {
  font-weight: 650;
  color: var(--ink);
  min-width: 11rem;
}

.col-place,
.col-dist {
  color: var(--muted);
  white-space: nowrap;
}

.col-cal {
  white-space: nowrap;
}

.col-links {
  white-space: nowrap;
}

.col-links a {
  margin-right: 0.45rem;
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--leaf);
  text-decoration: none;
}

.col-links a:hover {
  text-decoration: underline;
}

.cal-tag {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 0.18rem 0.5rem;
  border-radius: 6px;
  background: rgba(22, 53, 40, 0.08);
  color: var(--forest);
}

.cal-tag.cal-championship {
  background: rgba(201, 162, 39, 0.18);
  color: #7a5f10;
}

.cal-tag.cal-grandmaster {
  background: rgba(42, 107, 74, 0.14);
  color: var(--leaf);
}

.cal-tag.cal-candidate {
  background: rgba(90, 107, 96, 0.12);
  color: var(--muted);
}

.status-pill {
  display: inline-block;
  margin-left: 0.45rem;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #8a4b1f;
  background: rgba(184, 115, 51, 0.15);
  padding: 0.12rem 0.4rem;
  border-radius: 4px;
  vertical-align: middle;
}

.name {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #1a4d7a;
  line-height: 1.15;
}

.stars {
  font-size: 1rem;
  letter-spacing: 0.05em;
  line-height: 1;
  white-space: nowrap;
}
.stars.s4 { color: var(--gold); }
.stars.s3 { color: var(--silver); }
.stars.s2 { color: var(--bronze); }
.stars.s1 { color: var(--star1); }

.meta {
  margin: 0.55rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.details {
  margin: 0.7rem 0 0;
  font-size: 0.95rem;
  line-height: 1.45;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.95rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.28rem 0.65rem;
  font-size: 0.75rem;
  font-weight: 600;
  background: rgba(22, 53, 40, 0.07);
  color: var(--forest);
}

.badge.profile {
  background: rgba(42, 107, 74, 0.14);
  color: var(--leaf);
}

.drawer {
  width: min(520px, calc(100vw - 2rem));
  max-height: min(860px, calc(100vh - 2rem));
  border: none;
  border-radius: 24px;
  padding: 0;
  background: #fff;
  box-shadow: 0 30px 80px rgba(10, 20, 14, 0.28);
}
.drawer::backdrop {
  background: rgba(16, 28, 22, 0.45);
  backdrop-filter: blur(3px);
}

.drawer-close {
  position: sticky;
  top: 0;
  display: flex;
  justify-content: flex-end;
  padding: 0.75rem 0.85rem 0;
  background: linear-gradient(#fff, rgba(255,255,255,0.85));
}
.drawer-close button {
  border: none;
  background: transparent;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 999px;
}
.drawer-close button:hover { background: var(--mist); color: var(--ink); }

#drawerBody {
  padding: 0 1.5rem 1.75rem;
}

.drawer h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 2rem;
  letter-spacing: -0.03em;
  color: var(--forest);
}

.drawer .sub {
  margin: 0.45rem 0 0;
  color: var(--muted);
}

.drawer .metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
  margin: 1.2rem 0;
}
.metric {
  background: var(--mist);
  border-radius: 14px;
  padding: 0.8rem;
}
.metric b {
  display: block;
  font-family: var(--font-display);
  font-size: 1.25rem;
  color: var(--forest);
}
.metric span {
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.race-list {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
}
.race-list li {
  padding: 0.65rem 0;
  border-top: 1px solid var(--line);
  font-size: 0.92rem;
  line-height: 1.4;
}
.race-list li:first-child { border-top: none; }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1.1rem;
}
.actions a {
  text-decoration: none;
  color: #fff;
  background: var(--leaf);
  border-radius: 999px;
  padding: 0.55rem 0.9rem;
  font-size: 0.85rem;
  font-weight: 600;
  transition: background 0.2s, transform 0.2s;
}
.actions a:hover {
  background: var(--forest);
  transform: translateY(-1px);
}
.actions a.secondary {
  background: transparent;
  color: var(--leaf);
  border: 1px solid rgba(42, 107, 74, 0.35);
}

.empty {
  grid-column: 1 / -1;
  padding: 3rem 1rem;
  text-align: center;
  color: var(--muted);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 900px) {
  .grid { grid-template-columns: repeat(2, 1fr); }
  .controls {
    grid-template-columns: 1fr 1fr;
  }
  .search { grid-column: 1 / -1; }
}

@media (max-width: 560px) {
  .hero { padding-top: 3rem; }
  .grid { grid-template-columns: 1fr; }
  .controls { grid-template-columns: 1fr; }
  .drawer .metrics { grid-template-columns: 1fr; }
}
