:root {
  --bg: #ffffff;
  --bg-card: #ffffff;
  --bg-header: #ebebeb;
  --bg-tab: #e0e0e0;
  --bg-tab-active: #004b00;
  --color-text: #1a1a1a;
  --color-muted: #666666;
  --color-subtle: #999999;
  --color-tab: #555555;
  --color-tab-active: #ffffff;
  --color-km: #004b00;
  --color-total: #b45309;
  --color-zero: #aaaaaa;
  --color-border: #e0e0e0;
  --color-title: #111111;
}

[data-theme='dark'] {
  --bg: #0f0f0f;
  --bg-card: #1a1a1a;
  --bg-header: #222222;
  --bg-tab: #222222;
  --bg-tab-active: #6ee7b7;
  --color-text: #e8e8e8;
  --color-muted: #aaaaaa;
  --color-subtle: #666666;
  --color-tab: #888888;
  --color-tab-active: #0f0f0f;
  --color-km: #6ee7b7;
  --color-total: #fcd34d;
  --color-zero: #555555;
  --color-border: #222222;
  --color-title: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #0f0f0f;
    --bg-card: #1a1a1a;
    --bg-header: #222222;
    --bg-tab: #222222;
    --bg-tab-active: #6ee7b7;
    --color-text: #e8e8e8;
    --color-muted: #aaaaaa;
    --color-subtle: #666666;
    --color-tab: #888888;
    --color-tab-active: #0f0f0f;
    --color-km: #6ee7b7;
    --color-total: #fcd34d;
    --color-zero: #555555;
    --color-border: #222222;
    --color-title: #ffffff;
  }
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--color-text);
  min-height: 100vh;
  padding: 1.5rem 1rem 0;
}

h1 {
  font-size: 1.1rem;
  font-weight: 700;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-title);
  flex: 1;
}

.container {
  max-width: 480px;
  margin: 0 auto;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.theme-toggle {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition:
    background 0.2s,
    color 0.2s;
}

.theme-toggle:hover {
  color: var(--color-text);
}

.tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  background: var(--bg-tab);
  border: none;
  border-radius: 999px;
  color: var(--color-tab);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.45rem 1rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  transition:
    background 0.2s,
    color 0.2s;
}

.tab.active {
  background: var(--bg-tab-active);
  color: var(--color-tab-active);
}

.month-content {
  display: none;
}

.month-content.active {
  display: block;
}

.section {
  margin-bottom: 0.5rem;
  background: var(--bg-card);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  overflow: hidden;
}

.section-header {
  padding: 0.75rem 1rem;
  background: var(--bg-header);
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-muted);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.runner-list {
  list-style: none;
  padding: 0.25rem 0;
}

.runner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--color-border);
}

.runner:last-child {
  border-bottom: none;
}

.runner.no-km {
  opacity: 0.45;
}

.pos {
  min-width: 1.4rem;
  font-size: 0.8rem;
  color: var(--color-subtle);
  font-variant-numeric: tabular-nums;
}

.medal {
  font-size: 1rem;
  min-width: 1.4rem;
}

.name,
.total-label {
  flex: 1;
  font-size: 0.95rem;
  color: var(--color-text);
}

.km {
  font-size: 0.85rem;
  color: var(--color-km);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.zero {
  font-size: 0.85rem;
  color: var(--color-zero);
}

.copy-btn {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: #25d366;
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 0.8rem 2rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(37, 211, 102, 0.3);
  white-space: nowrap;
}

.copy-btn:active {
  background: #1da851;
}

.toast {
  position: fixed;
  bottom: 5rem;
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  padding: 0.5rem 1.2rem;
  border-radius: 999px;
  font-size: 0.85rem;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
}

.loading {
  text-align: center;
  color: var(--color-subtle);
  padding: 3rem 0;
  font-size: 0.9rem;
}

.total {
  display: flex;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  border-top: 1px solid var(--color-border);
}

.total-value {
  color: var(--color-total);
}

#annual-section {
  display: none;
}
#annual-section.show {
  display: block;
}

.winner-cards {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.winner-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
}

.winner-row .name {
  flex: 1;
  font-weight: 700;
}

@media (min-width: 768px) {
  .container {
    max-width: 960px;
  }

  .month-content.active {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: stretch;
    margin-bottom: 1.5rem;
  }

  .month-content.active .section {
    flex: 1;
    margin-bottom: 0;
    display: flex;
    flex-direction: column;
  }

  .month-content.active .section .runner-list {
    flex: 1;
  }

  .month-content.active .winner-cards {
    flex: none;
    width: 100%;
    display: flex;
    flex-direction: row;
    gap: 1rem;
    margin-bottom: 0;
  }

  .month-content.active .winner-cards .section {
    flex: 1;
    margin-bottom: 0;
  }
}
