:root {
  --bg0: #f3efe6;
  --bg1: #e7f0e4;
  --ink: #142018;
  --muted: #5c6b60;
  --line: rgba(20, 32, 24, 0.12);
  --turf: #1f6b3a;
  --turf-deep: #0f3d22;
  --gold: #c7922b;
  --sand: #d9c39a;
  --danger: #a33b2c;
  --panel: rgba(255, 252, 246, 0.86);
  --shadow: 0 18px 50px rgba(15, 40, 24, 0.12);
  --radius: 18px;
  --font-display: "Bebas Neue", sans-serif;
  --font-body: "Manrope", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, #dcefdc 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #f0e2c4 0%, transparent 50%),
    linear-gradient(160deg, var(--bg0), var(--bg1));
}

.hidden { display: none !important; }

.brand {
  font-family: var(--font-display);
  letter-spacing: 0.04em;
  font-size: 2.4rem;
  line-height: 1;
  color: var(--turf-deep);
  margin: 0;
}
.brand.mini { font-size: 1.6rem; }

.btn {
  border: 0;
  border-radius: 999px;
  padding: 0.85rem 1.35rem;
  font-weight: 700;
  font-family: var(--font-body);
  cursor: pointer;
  transition: transform .18s ease, box-shadow .18s ease, background .18s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn.primary {
  background: linear-gradient(135deg, var(--turf), var(--turf-deep));
  color: #f7fff8;
  box-shadow: 0 10px 24px rgba(20, 90, 45, 0.28);
}
.btn.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
}
.btn.xl { padding: 1rem 1.8rem; font-size: 1.05rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

/* Auth */
.auth-body { min-height: 100vh; }
.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.2fr 1fr;
}
.auth-hero {
  background:
    linear-gradient(120deg, rgba(15, 61, 34, 0.55), rgba(20, 32, 24, 0.25)),
    url("https://images.unsplash.com/photo-1551884831-bbf3cdc6469e?auto=format&fit=crop&w=1600&q=80") center/cover;
  animation: drift 18s ease-in-out infinite alternate;
}
@keyframes drift {
  from { background-position: 50% 40%; }
  to { background-position: 54% 48%; }
}
.auth-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(2rem, 5vw, 4.5rem);
  background: rgba(255, 252, 246, 0.78);
  backdrop-filter: blur(10px);
}
.auth-panel h1 {
  font-family: var(--font-display);
  font-size: clamp(2.6rem, 6vw, 4.4rem);
  margin: 0.4rem 0 0.6rem;
  letter-spacing: 0.02em;
}
.lead { color: var(--muted); max-width: 34ch; margin-bottom: 1.8rem; }
.auth-panel form { display: grid; gap: 1rem; max-width: 380px; }
label { display: grid; gap: 0.4rem; font-weight: 600; font-size: 0.92rem; }
input, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.85rem 1rem;
  font: inherit;
  background: #fffdf8;
}
input:focus { outline: 2px solid rgba(31, 107, 58, 0.35); }

/* App shell */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 1rem;
  justify-content: space-between;
  padding: 0.9rem 1.4rem;
  background: rgba(255, 252, 246, 0.9);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}
.brand-lockup { display: flex; align-items: baseline; gap: 0.7rem; }
.brand-sub { color: var(--muted); font-size: 0.9rem; }
.steps { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.step {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  font-weight: 600;
  color: var(--muted);
}
.step.active {
  background: var(--turf);
  border-color: var(--turf);
  color: #fff;
  animation: pop .35s ease;
}
@keyframes pop {
  from { transform: scale(0.92); opacity: .5; }
  to { transform: scale(1); opacity: 1; }
}

.workspace {
  width: min(1180px, calc(100% - 2rem));
  margin: 1.4rem auto 3rem;
  display: grid;
  gap: 1.2rem;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.3rem 1.4rem 1.5rem;
  animation: rise .45s ease;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.panel-head h2 {
  font-family: var(--font-display);
  font-size: 2rem;
  margin: 0;
  letter-spacing: 0.03em;
}
.panel-head p { margin: 0.25rem 0 1rem; color: var(--muted); }
.row { display: flex; gap: 1rem; align-items: end; flex-wrap: wrap; }
.grow { flex: 1; min-width: 220px; }

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 0.85rem;
}
.tile {
  text-align: left;
  border: 1px solid var(--line);
  background: #fffef9;
  border-radius: 16px;
  padding: 1rem;
  cursor: pointer;
  transition: border-color .2s ease, transform .2s ease;
}
.tile:hover { border-color: var(--turf); transform: translateY(-2px); }
.tile strong { display: block; font-size: 1.05rem; }
.tile span { color: var(--muted); font-size: 0.86rem; }
.tile .tag {
  display: inline-block;
  margin-top: 0.55rem;
  background: rgba(31, 107, 58, 0.1);
  color: var(--turf-deep);
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  font-size: 0.75rem;
  font-weight: 700;
}

.race-list { display: grid; gap: 0.65rem; margin-bottom: 1rem; }
.race-item {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  gap: 0.8rem;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.85rem 1rem;
  background: #fffef9;
  cursor: pointer;
}
.race-item:hover { border-color: var(--gold); }
.race-no {
  font-family: var(--font-display);
  font-size: 1.8rem;
  color: var(--turf-deep);
}
.race-item small { color: var(--muted); }

.meta-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-bottom: 1rem;
}
.chip {
  background: rgba(199, 146, 43, 0.14);
  border: 1px solid rgba(199, 146, 43, 0.28);
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.table-wrap { overflow: auto; border-radius: 14px; border: 1px solid var(--line); }
.data-table { width: 100%; border-collapse: collapse; background: #fffef9; }
.data-table th, .data-table td {
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
  font-size: 0.9rem;
}
.data-table th { background: rgba(31, 107, 58, 0.08); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }
.data-table tr:hover td { background: rgba(231, 240, 228, 0.55); }

.chart-grid {
  margin-top: 1rem;
}
.chart-grid.twin {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
}
.chart-box {
  background: #fffef9;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.75rem 0.85rem 0.5rem;
  height: 260px;
  max-height: 260px;
  position: relative;
  overflow: hidden;
}
.chart-box.tall {
  height: 320px;
  max-height: 320px;
}
.chart-box canvas {
  width: 100% !important;
  height: 100% !important;
  max-width: 100%;
  display: block;
}

.actions { display: flex; justify-content: center; margin-top: 1.2rem; }

.rank-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0.8rem;
  margin-bottom: 1rem;
}
.rank-card {
  border-radius: 16px;
  border: 1px solid var(--line);
  background: linear-gradient(160deg, #fffef9, #f3f7ef);
  padding: 1rem;
  position: relative;
  overflow: hidden;
}
.rank-card.top {
  border-color: rgba(199, 146, 43, 0.55);
  box-shadow: 0 12px 30px rgba(199, 146, 43, 0.18);
}
.rank-card .place {
  font-family: var(--font-display);
  font-size: 2.2rem;
  color: var(--gold);
}
.rank-card h3 { margin: 0.1rem 0; font-size: 1.05rem; }
.rank-card .muted { color: var(--muted); font-size: 0.86rem; }
.score-line {
  margin-top: 0.7rem;
  height: 8px;
  border-radius: 999px;
  background: rgba(20, 32, 24, 0.08);
  overflow: hidden;
}
.score-line > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--turf), var(--gold));
  width: 0;
  animation: fillBar 1s ease forwards;
}
@keyframes fillBar { to { width: var(--w); } }

.insight-box {
  margin-top: 1rem;
  padding: 1rem 1.1rem;
  border-radius: 14px;
  background: rgba(31, 107, 58, 0.08);
  border: 1px solid rgba(31, 107, 58, 0.18);
}
.insight-box li { margin: 0.35rem 0; }
.check { display: flex; align-items: center; gap: .5rem; font-weight: 600; }
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: .75rem;
  margin-bottom: 1rem;
}
.stat {
  background: #fffef9;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: .85rem 1rem;
  display: grid;
  gap: .35rem;
}
.stat span { color: var(--muted); font-size: .8rem; }
.stat strong { font-size: 1.05rem; }
.disclaimer {
  margin-top: 1rem;
  color: var(--muted);
  font-size: .85rem;
  border-left: 3px solid var(--gold);
  padding-left: .75rem;
}
.code-box {
  background: #142018;
  color: #dcefdc;
  border-radius: 12px;
  padding: 1rem;
  overflow: auto;
  max-height: 420px;
  font-size: .8rem;
}
.empty { color: var(--muted); padding: 1rem 0; }
.top-actions { display: flex; gap: .4rem; flex-wrap: wrap; }

.progress-overlay {
  position: fixed;
  inset: 0;
  background: rgba(12, 24, 16, 0.45);
  display: grid;
  place-items: center;
  z-index: 50;
  backdrop-filter: blur(4px);
}
.progress-card {
  width: min(420px, calc(100% - 2rem));
  background: #fffdf8;
  border-radius: 18px;
  padding: 1.4rem 1.5rem;
  box-shadow: var(--shadow);
  text-align: center;
}
.bar {
  height: 12px;
  border-radius: 999px;
  background: rgba(20, 32, 24, 0.08);
  overflow: hidden;
  margin: 1rem 0 0.5rem;
}
#progressBar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--turf), var(--gold));
  transition: width .35s ease;
}

@media (max-width: 900px) {
  .auth-shell { grid-template-columns: 1fr; }
  .auth-hero { min-height: 28vh; }
  .chart-grid.twin { grid-template-columns: 1fr; }
  .chart-box, .chart-box.tall { height: 240px; max-height: 240px; }
  .topbar { flex-wrap: wrap; }
  .race-item { grid-template-columns: 48px 1fr; }
}
