:root {
  --bg: #0b1210;
  --bg-elev: #121a17;
  --bg-panel: rgba(18, 26, 23, 0.92);
  --ink: #e8f0ea;
  --muted: #8fa398;
  --line: rgba(232, 240, 234, 0.12);
  --accent: #c8f542;
  --accent-ink: #0b1210;
  --warn: #ff7a45;
  --map-h: min(58vh, 640px);
  --radius: 14px;
  --font-display: "Syne", sans-serif;
  --font-body: "DM Sans", sans-serif;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(200, 245, 66, 0.12), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(255, 122, 69, 0.1), transparent 50%),
    linear-gradient(165deg, #0b1210 0%, #102018 45%, #0b1210 100%);
  color: var(--ink);
  font-family: var(--font-body);
  font-optical-sizing: auto;
}

body {
  min-height: 100dvh;
}

a {
  color: var(--accent);
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(11, 18, 16, 0.75);
}

.brand {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.35rem;
  letter-spacing: -0.03em;
  color: var(--ink);
  display: inline-flex;
  align-items: baseline;
  gap: 0.45rem;
}

.brand span {
  color: var(--accent);
}

.nav {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.nav button,
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  padding: 0.55rem 0.9rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
}

.nav button:hover,
.btn:hover {
  border-color: rgba(200, 245, 66, 0.45);
  background: rgba(200, 245, 66, 0.08);
}

.nav button.active {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  font-weight: 600;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  font-weight: 600;
}

.btn-ghost {
  background: transparent;
}

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

.page {
  flex: 1;
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 1.25rem;
}

.hero-live {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 1rem;
  animation: rise 0.55s ease both;
}

.hero-live h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  letter-spacing: -0.04em;
  line-height: 1.05;
}

.hero-live p {
  margin: 0;
  color: var(--muted);
  max-width: 38rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: end;
  margin: 1rem 0;
}

.field {
  display: grid;
  gap: 0.35rem;
  min-width: min(100%, 220px);
}

.field label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.field input,
.field select,
.field textarea {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
  outline: none;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: rgba(200, 245, 66, 0.55);
  box-shadow: 0 0 0 3px rgba(200, 245, 66, 0.12);
}

.live-shell {
  display: grid;
  grid-template-rows: var(--map-h) auto;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  overflow: hidden;
  background: var(--bg-elev);
  box-shadow: var(--shadow);
  animation: rise 0.7s ease 0.08s both;
}

#map {
  width: 100%;
  height: var(--map-h);
  background: #1a2420;
}

.athlete-rail {
  display: flex;
  gap: 0.65rem;
  overflow-x: auto;
  padding: 0.85rem;
  border-top: 1px solid var(--line);
  background: var(--bg-panel);
  scroll-snap-type: x mandatory;
}

.athlete-chip {
  flex: 0 0 auto;
  min-width: 168px;
  max-width: 280px;
  scroll-snap-align: start;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(11, 18, 16, 0.65);
  padding: 0.65rem;
  cursor: pointer;
  transition: border-color 0.2s ease, transform 0.2s ease, background 0.2s ease;
}

.athlete-chip:hover {
  transform: translateY(-2px);
  border-color: rgba(200, 245, 66, 0.35);
}

.athlete-chip.expanded {
  min-width: min(92vw, 320px);
  background: rgba(11, 18, 16, 0.9);
  border-color: color-mix(in srgb, var(--chip-color, var(--accent)) 55%, transparent);
}

.chip-head {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--chip-color, var(--accent));
  background: #24302b;
  flex: 0 0 auto;
}

.avatar.fallback {
  display: grid;
  place-items: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--ink);
}

.chip-name {
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.2;
}

.chip-meta {
  color: var(--muted);
  font-size: 0.78rem;
}

.chip-plus {
  margin-left: auto;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  font-size: 1.1rem;
  line-height: 1;
  color: var(--accent);
  transition: transform 0.25s ease, background 0.2s ease;
}

.athlete-chip.expanded .chip-plus {
  transform: rotate(45deg);
  background: rgba(200, 245, 66, 0.12);
}

.chip-body {
  display: none;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
  animation: fade 0.25s ease;
}

.athlete-chip.expanded .chip-body {
  display: grid;
  gap: 0.65rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.45rem;
}

.stat {
  background: rgba(232, 240, 234, 0.04);
  border-radius: 10px;
  padding: 0.5rem;
}

.stat b {
  display: block;
  font-family: var(--font-display);
  font-size: 0.95rem;
}

.stat span {
  font-size: 0.68rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.split-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.3rem;
  max-height: 160px;
  overflow: auto;
}

.split-list li {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.82rem;
  padding: 0.25rem 0;
  border-bottom: 1px dashed rgba(232, 240, 234, 0.08);
}

.empty {
  color: var(--muted);
  padding: 1.5rem;
  text-align: center;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(18, 26, 23, 0.72);
  padding: 1.1rem;
  margin-bottom: 1rem;
  animation: rise 0.5s ease both;
}

.panel h2 {
  margin: 0 0 0.85rem;
  font-family: var(--font-display);
  font-size: 1.25rem;
  letter-spacing: -0.03em;
}

.form-grid {
  display: grid;
  gap: 0.85rem;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.form-actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

.list {
  display: grid;
  gap: 0.55rem;
}

.list-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(11, 18, 16, 0.45);
}

.list-item .grow {
  flex: 1;
  min-width: 0;
}

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

.toast {
  position: fixed;
  bottom: 1.2rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--accent);
  color: var(--accent-ink);
  padding: 0.7rem 1rem;
  border-radius: 999px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 50;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.error {
  background: var(--warn);
  color: #1a0c06;
}

.marker-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 45%, transparent);
  background: var(--c);
}

.color-swatch {
  width: 100%;
  height: 42px;
  border: none;
  padding: 0;
  background: transparent;
}

.sim-hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 0.75rem;
}

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

@keyframes fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.leaflet-container {
  font: inherit;
  background: #1a2420;
}

@media (max-width: 720px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }
  .nav {
    justify-content: flex-start;
  }
  :root {
    --map-h: min(46vh, 420px);
  }
}
