/* ============================================================
   Trail MVP - mobile-first, dark, outdoor-readable
   ============================================================ */

:root {
  --bg:        #0a1620;
  --bg-2:      #0d1f2d;
  --bg-3:      #142b3d;
  --line:      #1f3a52;
  --fg:        #e8eef4;
  --fg-dim:    #8aa1b3;
  --accent:    #5ec264;       /* trail green */
  --accent-2:  #2a8f3d;
  --gps:       #5bb1ff;
  --warn:      #ffb74d;
  --bad:       #ff6b6b;
  --shadow:    0 6px 24px rgba(0,0,0,0.4);

  --safe-top:    env(safe-area-inset-top, 0);
  --safe-bot:    env(safe-area-inset-bottom, 0);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

button { font-family: inherit; }

.hidden { display: none !important; }

/* ============================================================
   LANDING
   ============================================================ */
.landing {
  position: fixed; inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-top) + 24px) 20px calc(var(--safe-bot) + 24px);
  background:
    radial-gradient(at 20% 0%,  rgba(94,194,100,0.15), transparent 50%),
    radial-gradient(at 80% 100%, rgba(91,177,255,0.12), transparent 50%),
    var(--bg);
  z-index: 100;
  overflow-y: auto;
}

.landing-card {
  width: 100%;
  max-width: 380px;
  background: linear-gradient(180deg, var(--bg-2), var(--bg-3));
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px 22px 22px;
  box-shadow: var(--shadow);
  text-align: center;
}

.logo {
  display: inline-flex;
  margin-bottom: 12px;
  filter: drop-shadow(0 4px 12px rgba(94,194,100,0.35));
}

.landing-card h1 {
  margin: 0 0 4px;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.trail-name {
  margin: 0 0 14px;
  color: var(--fg-dim);
  font-size: 14px;
  line-height: 1.35;
}

.trail-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 0 0 22px;
  padding: 12px 8px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.trail-stats .ts-cell {
  text-align: center;
}
.trail-stats .ts-val  { font-size: 17px; font-weight: 600; color: var(--fg); }
.trail-stats .ts-lbl  { font-size: 11px; color: var(--fg-dim); margin-top: 2px;
                         text-transform: uppercase; letter-spacing: 0.06em; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 52px;
  border-radius: 12px;
  border: none;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.05s, filter 0.15s;
}
.btn:active { transform: scale(0.98); filter: brightness(0.92); }

.btn-primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  color: #08130b;
  box-shadow: 0 4px 14px rgba(94,194,100,0.35);
}

.btn-ghost {
  background: transparent;
  color: var(--fg-dim);
  margin-top: 10px;
  border: 1px solid var(--line);
}

.btn-icon {
  font-size: 18px;
  line-height: 1;
}

.hint {
  margin: 16px 4px 0;
  color: var(--fg-dim);
  font-size: 12px;
  line-height: 1.45;
}

/* ============================================================
   APP shell
   ============================================================ */
.app {
  position: fixed; inset: 0;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  background: var(--bg);
}

/* topbar */
.topbar {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: calc(var(--safe-top) + 10px) 12px 10px;
  background: linear-gradient(180deg, rgba(13,31,45,0.95), rgba(13,31,45,0.7));
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  z-index: 5;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: var(--fg-dim);
  background: rgba(255,255,255,0.02);
}
.pill .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--fg-dim);
}
.pill[data-state="on"]   .dot { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.pill[data-state="warn"] .dot { background: var(--warn); }
.pill[data-state="bad"]  .dot { background: var(--bad); }
.pill[data-state="on"]    { color: var(--fg); border-color: rgba(94,194,100,0.4); }
.pill[data-state="warn"]  { color: var(--warn); border-color: rgba(255,183,77,0.4); }
.pill[data-state="bad"]   { color: var(--bad);  border-color: rgba(255,107,107,0.4); }

.pill-flex { flex: 1; justify-content: flex-end; }
#status-text { font-weight: 500; color: var(--fg-dim); }

/* map */
.map {
  width: 100%;
  background: #001120;
}
.leaflet-container {
  background: #061726;
  font-family: inherit;
}

/* user dot pulse */
.user-dot {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--gps);
  border: 3px solid #fff;
  box-shadow: 0 0 0 0 rgba(91,177,255,0.7);
  animation: pulse 2s infinite;
}
.user-dot.off { background: var(--bad); }
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(91,177,255,0.55); }
  70%  { box-shadow: 0 0 0 14px rgba(91,177,255,0); }
  100% { box-shadow: 0 0 0 0 rgba(91,177,255,0); }
}

.start-dot, .end-dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.6);
}
.start-dot { background: var(--accent); }
.end-dot   { background: var(--bad); }

/* metrics */
.metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--line);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.metric {
  background: var(--bg-2);
  padding: 8px 6px 7px;
  text-align: center;
  min-width: 0;
}
.metric-label {
  font-size: 10px;
  color: var(--fg-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 2px;
}
.metric-value {
  font-size: 16px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.metric-value.warn { color: var(--warn); }
.metric-value.bad  { color: var(--bad); }

/* actions */
.actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--line);
  padding-bottom: var(--safe-bot);
  background-color: var(--bg-2);
}
.action {
  appearance: none;
  border: none;
  background: var(--bg-2);
  color: var(--fg);
  padding: 12px 4px 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: background 0.15s;
  min-height: 64px;
}
.action:active { background: var(--bg-3); }
.action.is-active { background: var(--bg-3); color: var(--accent); }
.action-icon {
  font-size: 22px;
  line-height: 1;
}
.action-label {
  font-size: 11px;
  color: var(--fg-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.action.is-active .action-label { color: var(--accent); }

/* off-trail banner */
.off-banner {
  position: fixed;
  top: calc(var(--safe-top) + 56px);
  left: 12px; right: 12px;
  padding: 10px 14px;
  background: linear-gradient(180deg, #c83a3a, #a02828);
  color: #fff;
  border-radius: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 14px;
  box-shadow: 0 6px 20px rgba(255,107,107,0.4);
  animation: slidedown 0.25s ease-out;
  z-index: 50;
}
.off-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: rgba(255,255,255,0.25);
  font-weight: 700;
}
@keyframes slidedown {
  from { transform: translateY(-12px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

/* toast */
.toast {
  position: fixed;
  bottom: calc(var(--safe-bot) + 90px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(13,31,45,0.95);
  border: 1px solid var(--line);
  color: var(--fg);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  box-shadow: var(--shadow);
  z-index: 60;
  animation: fadein 0.2s;
}
@keyframes fadein {
  from { opacity: 0; transform: translate(-50%, 6px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}
