@import url('https://fonts.googleapis.com/css2?family=Prompt:wght@500;600;700&family=Sarabun:wght@400;500;600&display=swap');

:root {
  --bg: #0c0f14;
  --bg-elevated: #161b22;
  --bg-card: #1b212b;
  --line: #2a313d;
  --accent: #ff5a1f;
  --accent-soft: rgba(255, 90, 31, 0.15);
  --text: #eef1f5;
  --text-muted: #8b93a1;
  --green: #3ddc84;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Sarabun', sans-serif;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, .display {
  font-family: 'Prompt', sans-serif;
  margin: 0;
}

a { color: inherit; text-decoration: none; }

.app-shell {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg);
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  position: sticky;
  top: 0;
  z-index: 30;
  background: linear-gradient(to bottom, rgba(12,15,20,0.95), rgba(12,15,20,0.7));
  backdrop-filter: blur(6px);
}

.topbar .brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Prompt', sans-serif;
  font-weight: 600;
  font-size: 18px;
  letter-spacing: 0.2px;
}

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

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  cursor: pointer;
}
.icon-btn:active { background: rgba(255,255,255,0.12); }

/* ---------- Map ---------- */
#map {
  width: 100%;
  flex: 1;
  min-height: 300px;
  background: #101418;
}
.leaflet-container { background: #101418; font-family: 'Sarabun', sans-serif; }

.map-wrap {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.search-bar {
  position: absolute;
  top: 14px;
  left: 14px;
  right: 14px;
  z-index: 20;
  display: flex;
  gap: 8px;
}

.search-bar input {
  flex: 1;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(20,24,31,0.92);
  color: var(--text);
  font-size: 14px;
  font-family: 'Sarabun', sans-serif;
  backdrop-filter: blur(6px);
}
.search-bar input::placeholder { color: var(--text-muted); }

.search-results {
  position: absolute;
  top: 62px;
  left: 14px;
  right: 14px;
  z-index: 25;
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  max-height: 240px;
  overflow-y: auto;
  display: none;
}
.search-results.show { display: block; }
.search-results div {
  padding: 12px 14px;
  font-size: 13.5px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.search-results div:last-child { border-bottom: none; }
.search-results div:active { background: rgba(255,90,31,0.12); }

.locate-btn {
  position: absolute;
  bottom: 190px;
  right: 14px;
  z-index: 20;
}

.start-pin-label {
  position: absolute;
  bottom: 168px;
  left: 14px;
  right: 14px;
  z-index: 20;
  background: rgba(20,24,31,0.92);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-muted);
  backdrop-filter: blur(6px);
}
.start-pin-label b { color: var(--text); font-weight: 500; }

/* ---------- Bottom control panel ---------- */
.panel {
  background: var(--bg-elevated);
  border-top: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
  padding: 18px 18px 22px;
  z-index: 20;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 18px;
}
.stat-row .stat { text-align: center; flex: 1; }
.stat-row .stat .val {
  font-family: 'Prompt', sans-serif;
  font-size: 22px;
  font-weight: 600;
}
.stat-row .stat .lbl {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

.btn-primary {
  width: 100%;
  padding: 16px;
  border-radius: 50px;
  background: var(--accent);
  color: #fff;
  border: none;
  font-family: 'Prompt', sans-serif;
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
}
.btn-primary:active { filter: brightness(0.92); }
.btn-primary.stop { background: #e0384c; }

.btn-row { display: flex; gap: 10px; }
.btn-row .btn-primary { flex: 1; }
.btn-secondary {
  flex: 1;
  padding: 16px;
  border-radius: 50px;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
  font-family: 'Prompt', sans-serif;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
}

.gps-status {
  text-align: center;
  font-size: 12.5px;
  color: var(--green);
  margin-bottom: 12px;
}
.gps-status.bad { color: #e0384c; }

/* ---------- Bottom nav ---------- */
.bottom-nav {
  display: flex;
  border-top: 1px solid var(--line);
  background: var(--bg-elevated);
}
.bottom-nav a {
  flex: 1;
  text-align: center;
  padding: 12px 0 10px;
  font-size: 11.5px;
  color: var(--text-muted);
}
.bottom-nav a .nav-ic { font-size: 20px; display: block; margin-bottom: 2px; }
.bottom-nav a.active { color: var(--accent); }

/* ---------- History list ---------- */
.page-body { padding: 4px 16px 90px; flex: 1; }
.page-title { font-size: 22px; font-weight: 600; padding: 10px 2px 16px; }

.run-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  display: block;
}
.run-card .date { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.run-card .title { font-family: 'Prompt', sans-serif; font-size: 16px; font-weight: 600; margin-bottom: 12px; }
.run-card .metrics { display: flex; gap: 22px; }
.run-card .metrics .m .v { font-family: 'Prompt', sans-serif; font-size: 17px; font-weight: 600; }
.run-card .metrics .m .l { font-size: 11px; color: var(--text-muted); }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 60px 20px;
  font-size: 14px;
}
.empty-state .big { font-size: 40px; margin-bottom: 10px; }

/* ---------- Detail page ---------- */
.detail-map { width: 100%; height: 280px; }
.detail-stats {
  background: var(--bg-elevated);
  border-radius: 20px 20px 0 0;
  margin-top: -18px;
  position: relative;
  z-index: 5;
  padding: 22px 20px 30px;
}
.detail-stats .headline { text-align: center; margin-bottom: 22px; }
.detail-stats .headline .dist {
  font-family: 'Prompt', sans-serif;
  font-size: 40px;
  font-weight: 700;
  color: var(--accent);
}
.detail-stats .headline .lbl { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px 10px;
}
.detail-grid .cell { text-align: center; padding: 14px 6px; background: var(--bg-card); border-radius: 12px; border: 1px solid var(--line); }
.detail-grid .cell .v { font-family: 'Prompt', sans-serif; font-size: 19px; font-weight: 600; }
.detail-grid .cell .l { font-size: 11.5px; color: var(--text-muted); margin-top: 3px; }

.back-float {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 10;
}
.delete-float {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 10;
}

/* ---------- Auth pages ---------- */
.auth-wrap {
  max-width: 360px;
  margin: 0 auto;
  padding: 56px 24px 40px;
}
.auth-brand {
  font-family: 'Prompt', sans-serif;
  font-weight: 600;
  font-size: 18px;
  margin-bottom: 34px;
}
.auth-brand .dot { color: var(--accent); }
.auth-title { font-size: 24px; font-weight: 600; margin-bottom: 6px; }
.auth-sub { color: var(--text-muted); font-size: 13.5px; margin-bottom: 26px; }

.google-btn-wrap { display: flex; justify-content: center; margin-bottom: 20px; }

.auth-divider {
  display: flex;
  align-items: center;
  text-align: center;
  color: var(--text-muted);
  font-size: 12.5px;
  margin: 22px 0;
}
.auth-divider::before, .auth-divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid var(--line);
}
.auth-divider span { padding: 0 12px; }

.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form input {
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-card);
  color: var(--text);
  font-size: 14px;
  font-family: 'Sarabun', sans-serif;
}
.auth-form input::placeholder { color: var(--text-muted); }
.auth-form .btn-primary { margin-top: 6px; }

.auth-error {
  color: #ff6b6b;
  font-size: 13px;
  min-height: 16px;
}

.auth-switch {
  text-align: center;
  margin-top: 22px;
  font-size: 13.5px;
  color: var(--text-muted);
}
.auth-switch a { color: var(--accent); font-weight: 500; }

/* ---------- Topbar user chip ---------- */
.topbar .user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
}
.topbar .avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--line);
}
.topbar .avatar-initials {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Prompt', sans-serif;
  font-weight: 600;
  font-size: 13px;
}

/* ---------- Public/private toggle ---------- */
.visibility-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 16px;
  font-size: 13.5px;
}
.switch {
  position: relative;
  width: 42px;
  height: 24px;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0;
  background: var(--line);
  border-radius: 30px;
  transition: 0.2s;
  cursor: pointer;
}
.switch .track::before {
  content: '';
  position: absolute;
  width: 18px; height: 18px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.2s;
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::before { transform: translateX(18px); }

.owner-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.owner-chip .avatar, .owner-chip .avatar-initials {
  width: 26px; height: 26px; font-size: 11px;
}

/* ---------- Explore page ---------- */
.explore-map { width: 100%; height: 42vh; min-height: 260px; }
.explore-list { padding: 4px 16px 90px; }
.explore-radius-row {
  display: flex;
  gap: 8px;
  padding: 14px 16px 6px;
  overflow-x: auto;
}
.chip {
  padding: 8px 16px;
  border-radius: 30px;
  border: 1px solid var(--line);
  background: var(--bg-card);
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  cursor: pointer;
}
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.public-run-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  display: block;
}
.public-run-card .top-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.public-run-card .owner-name { font-size: 13.5px; font-weight: 500; }
.public-run-card .meta { font-size: 11.5px; color: var(--text-muted); }
.public-run-card .metrics { display: flex; gap: 20px; }
.public-run-card .metrics .m .v { font-family: 'Prompt', sans-serif; font-size: 15px; font-weight: 600; }
.public-run-card .metrics .m .l { font-size: 10.5px; color: var(--text-muted); }
.public-run-card .distance-badge {
  margin-left: auto;
  font-size: 11px;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 4px 10px;
  border-radius: 20px;
}

.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  padding: 10px 18px;
  border-radius: 30px;
  font-size: 13px;
  z-index: 100;
  display: none;
}
.toast.show { display: block; }
