:root {
  --paper: #f6f5f1;
  --ink: #1a1a1e;
  --ink-soft: #55555c;
  --rule: #d8d6cd;
  --sc: #c8402c;
  --ew: #5a8f29;
  --ow: #1f77a8;
  --visited: #b8860b;
  --danger: #b23a2e;
  --font-display: "Space Grotesk", sans-serif;
  --font-body: "Inter", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
}

body { min-height: 100vh; }

h1, h2 { font-family: var(--font-display); margin: 0; }

button { font-family: inherit; }

input {
  font-family: var(--font-body);
  font-size: 1rem;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- Auth ---------- */

.auth-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 20px 48px;
}

.auth-card { width: 100%; max-width: 400px; }

.wordmark {
  font-size: 2.1rem;
  line-height: 1.05;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.wordmark.small { font-size: 1.25rem; }

.auth-sub {
  margin: 14px 0 28px;
  color: var(--ink-soft);
  line-height: 1.5;
  font-size: 0.96rem;
}

.auth-tabs {
  display: flex;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 22px;
}

.auth-tab {
  flex: 1;
  padding: 10px 4px 12px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--ink-soft);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
}

.auth-tab.is-active {
  color: var(--ink);
  border-bottom-color: var(--ink);
}

.auth-form { display: flex; flex-direction: column; gap: 6px; }

.auth-form label {
  font-size: 0.82rem;
  color: var(--ink-soft);
  margin-top: 12px;
}

.auth-form input {
  padding: 11px 12px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}

.auth-form input:focus-visible,
button:focus-visible,
.station-row:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.field-hint {
  margin: 4px 0 0;
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.btn-primary {
  margin-top: 20px;
  padding: 13px;
  background: var(--ink);
  color: var(--paper);
  border: none;
  border-radius: 6px;
  font-size: 0.98rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary:active { opacity: 0.85; }

.btn-text {
  background: none;
  border: none;
  color: var(--ink-soft);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 6px 4px;
}

.btn-danger { color: var(--danger); }

.auth-error {
  margin-top: 18px;
  padding: 10px 12px;
  background: #fbeceb;
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: 6px;
  font-size: 0.88rem;
}

/* ---------- App shell ---------- */

.app-view { padding-bottom: 40px; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--paper);
  padding: 18px 20px 0;
  border-bottom: 1px solid var(--rule);
}

.app-header-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.signed-in-as {
  margin: 4px 0 16px;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.progress-block { margin-bottom: 14px; }

.progress-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 8px;
}

#progress-count {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 700;
}

.progress-label { color: var(--ink-soft); font-size: 0.88rem; }

.progress-track {
  height: 6px;
  background: var(--rule);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--visited);
  transition: width 0.4s ease;
}

.view-toggle { display: flex; gap: 4px; }

.view-tab {
  padding: 9px 4px 11px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--ink-soft);
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  margin-right: 18px;
}

.view-tab.is-active { color: var(--ink); border-bottom-color: var(--ink); }

/* ---------- Station list ---------- */

.station-list { list-style: none; margin: 0; padding: 0; }

.station-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 20px;
  border-bottom: 1px solid var(--rule);
  background: none;
  border-left: none;
  border-right: none;
  border-top: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
}

.station-row:disabled { cursor: default; }

.line-bars { display: flex; flex-direction: column; gap: 2px; flex: 0 0 4px; align-self: stretch; }
.line-bar { flex: 1; width: 4px; border-radius: 2px; min-height: 8px; }

.station-main { flex: 1; min-width: 0; }

.station-name {
  font-size: 1rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.badge {
  font-size: 0.66rem;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 999px;
  color: #fff;
  line-height: 1.5;
}

.badge-outline {
  font-size: 0.66rem;
  font-weight: 500;
  padding: 1px 6px;
  border-radius: 999px;
  color: var(--ink-soft);
  border: 1px solid var(--rule);
  line-height: 1.5;
}

.station-status {
  margin-top: 2px;
  font-size: 0.82rem;
  color: var(--ink-soft);
}

.station-status.is-visited { color: var(--visited); font-weight: 500; }

.station-action {
  flex: 0 0 auto;
  font-family: var(--font-display);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
}

.station-action.is-visited {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

.station-row.is-upcoming { opacity: 0.5; }

.station-row.is-upcoming .station-action { display: none; }

/* ---------- Map ---------- */

.map-view { padding: 8px 0 20px; }

.map-scroll {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y pinch-zoom;
  padding: 12px 20px 4px;
}

#network-svg {
  width: 100%;
  min-width: 640px;
  height: auto;
  display: block;
}

.map-legend {
  display: flex;
  gap: 18px;
  list-style: none;
  margin: 4px 20px 0;
  padding: 10px 0 0;
  border-top: 1px solid var(--rule);
  font-size: 0.78rem;
  color: var(--ink-soft);
  flex-wrap: wrap;
}

.map-legend li { display: flex; align-items: center; gap: 6px; }

.legend-swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

/* ---------- Leaderboard ---------- */

.leaderboard-view { padding: 4px 0 24px; }

.leaderboard-intro {
  margin: 14px 20px 10px;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.leaderboard-list { list-style: none; margin: 0; padding: 0; }

.leaderboard-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 20px;
  border-bottom: 1px solid var(--rule);
}

.leaderboard-row.is-you { background: #efe9d8; }

.leaderboard-rank {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.1rem;
  width: 1.6em;
  flex: 0 0 auto;
  color: var(--ink-soft);
}

.leaderboard-row:first-child .leaderboard-rank { color: var(--visited); }

.leaderboard-main { flex: 1; min-width: 0; }

.leaderboard-name { font-weight: 500; }

.leaderboard-meta { font-size: 0.8rem; color: var(--ink-soft); margin-top: 2px; }

.leaderboard-duration {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.95rem;
  flex: 0 0 auto;
}

.empty-note { margin: 20px; color: var(--ink-soft); font-size: 0.9rem; }

/* ---------- Admin ---------- */

.admin-row { display: flex; align-items: center; gap: 12px; }

.admin-main { flex: 1; min-width: 0; }

.admin-name { font-weight: 500; display: flex; align-items: center; gap: 6px; }

.admin-meta { font-size: 0.82rem; color: var(--ink-soft); margin-top: 2px; }

.admin-detail-heading { padding: 18px 20px 0; font-size: 1.15rem; }

#admin-back { margin: 14px 20px 0; }

.admin-visit-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--rule);
}

.admin-visit-station { font-weight: 500; }

.admin-visit-time { font-size: 0.82rem; color: var(--ink-soft); margin-top: 2px; }

.admin-visit-remove {
  flex: 0 0 auto;
  background: none;
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 6px 12px;
  cursor: pointer;
}

.admin-section-heading {
  font-family: var(--font-display);
  font-size: 0.82rem;
  color: var(--ink-soft);
  font-weight: 600;
  margin: 20px 20px 4px;
}

.admin-attempt-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--rule);
}

.admin-attempt-duration { font-weight: 500; }

.admin-attempt-meta { font-size: 0.8rem; color: var(--ink-soft); margin-top: 2px; }

.admin-attempt-toggle {
  flex: 0 0 auto;
  background: none;
  border: 1px solid var(--ink);
  color: var(--ink);
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
}

.admin-attempt-toggle.is-on {
  background: var(--visited);
  border-color: var(--visited);
  color: #fff;
}

.admin-future-form {
  display: flex;
  gap: 8px;
  padding: 4px 20px 18px;
  flex-wrap: wrap;
}

.admin-future-form select,
.admin-future-form input {
  padding: 9px 10px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: #fff;
  font-size: 0.9rem;
  color: var(--ink);
}

.admin-future-form select { flex: 1 1 160px; }
.admin-future-form input { flex: 0 1 150px; }
.admin-future-form .btn-primary { margin-top: 0; flex: 0 0 auto; }

.admin-future-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--rule);
}

.admin-future-name { font-weight: 500; }

.admin-future-date { font-size: 0.82rem; color: var(--ink-soft); margin-top: 2px; }



/* ---------- Edit sheet ---------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(26, 26, 30, 0.4);
  display: flex;
  align-items: flex-end;
  z-index: 20;
}

.sheet {
  background: var(--paper);
  width: 100%;
  padding: 22px 20px calc(24px + env(safe-area-inset-bottom));
  border-radius: 16px 16px 0 0;
}

.sheet h2 { font-size: 1.1rem; margin-bottom: 4px; }

.sheet-station { color: var(--ink-soft); font-size: 0.88rem; margin: 0 0 18px; }

.sheet label { font-size: 0.82rem; color: var(--ink-soft); }

.sheet input {
  width: 100%;
  margin-top: 6px;
  padding: 11px 12px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: #fff;
}

.sheet-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 22px;
}

.sheet-actions-right { display: flex; align-items: center; gap: 6px; }
.sheet-actions-right .btn-primary { margin-top: 0; padding: 10px 18px; }

.congrats-note { margin: 0 0 18px; font-size: 0.82rem; color: var(--ink-soft); line-height: 1.4; }

/* ---------- Small screens polish ---------- */

@media (min-width: 560px) {
  .app-header, .list-view, .map-legend { padding-left: 32px; padding-right: 32px; }
  .station-row { padding-left: 32px; padding-right: 32px; }
  .sheet { max-width: 420px; margin: 0 auto; border-radius: 16px; }
  .sheet-backdrop { align-items: center; justify-content: center; }
}
