:root {
  --bg: #f4f5f7;
  --ink: #1c1917;
  --muted: #57534e;
  --line: #e7e5e4;
  --card: #ffffff;
  --accent: #0f6b4c;
  --accent-ink: #ffffff;
  --accent-soft: #e8f5ef;
  --warm: #c2410c;
  --danger: #b42318;
  --shadow: 0 1px 2px rgba(28, 25, 23, 0.06);
  --nav: 64px;
  --safe-b: env(safe-area-inset-bottom);
  --safe-t: env(safe-area-inset-top);
  color-scheme: light;
  font-family: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", "Source Han Sans SC", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink);
}

html[data-theme="dark"] {
  --bg: #141414;
  --ink: #f5f5f4;
  --muted: #a8a29e;
  --line: #3f3f46;
  --card: #1c1c1c;
  --accent: #34d399;
  --accent-ink: #052e16;
  --accent-soft: #14352a;
  --warm: #fb923c;
  --danger: #fca5a5;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--ink); }
body { overflow-x: hidden; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.7rem; font-weight: 700; letter-spacing: -0.03em; line-height: 1.2; }
h2 { font-size: 1.05rem; font-weight: 700; line-height: 1.3; }
img { max-width: 100%; display: block; }

.layout { min-height: 100dvh; }
.sidebar { display: none; }
.main {
  width: min(1080px, 100%);
  margin: 0 auto;
  padding: calc(8px + var(--safe-t)) 16px calc(var(--nav) + var(--safe-b) + 24px);
}
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  position: sticky;
  top: 0;
  z-index: 8;
  padding: 8px 0 10px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; font-weight: 700; }
.brand strong { font-size: 15px; white-space: nowrap; }
.brand-logo { height: 44px; width: auto; max-width: 210px; display: block; object-fit: contain; }
.login-logo { width: min(210px, 70vw); height: auto; display: block; }
.lp-root { min-height: 100dvh; display: flex; background: #07111c; }
.lp-left { display: none; position: relative; overflow: hidden; flex: 1; }
.lp-bg-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: 62% center; }
.lp-overlay { position: absolute; inset: 0; background: linear-gradient(160deg, rgba(5,15,40,.28), rgba(0,30,20,.12) 55%, rgba(0,0,0,.18)); }
.lp-left-accent { position: absolute; top: 0; right: 0; width: 3px; height: 100%; background: linear-gradient(180deg, transparent, #8fd14f 40%, #d6ff4a 70%, transparent); }
.lp-right { width: 100%; min-height: 100dvh; background: #fff; display: flex; align-items: center; justify-content: center; padding: calc(64px + var(--safe-t)) 24px 32px; position: relative; }
.lp-right-bar { position: absolute; top: 0; left: 0; right: 0; height: 4px; background: linear-gradient(90deg, #3d8c12, #8fd14f, #d6ff4a); }
.lp-lang { position: absolute; top: calc(14px + var(--safe-t)); right: 16px; }
.lp-form-wrap { width: min(360px, 100%); display: flex; flex-direction: column; gap: 16px; flex-shrink: 0; }
.lp-form-wrap form { display: flex; flex-direction: column; gap: 18px; margin: 0; }
.lp-logo-wrap { display: flex; justify-content: center; margin: 0 0 12px; }
.lp-field { display: flex; flex-direction: column; gap: 8px; margin: 0; }
.lp-label { display: block; font-size: 12px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: #374151; line-height: 1.35; }
.lp-input { display: block; width: 100%; height: 48px; box-sizing: border-box; border: 1.5px solid #e2e8f0; border-radius: 10px; background: #f8fafc; padding: 0 14px; color: #0f172a; line-height: 46px; margin: 0; }
.lp-input:focus { outline: none; border-color: #65a30d; background: #fff; box-shadow: 0 0 0 3px rgba(101,163,13,.15); }
.lp-btn { width: 100%; height: 48px; margin: 0; border: 0; border-radius: 10px; background: linear-gradient(135deg, #3d8c12, #84cc16); color: #fff; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase; cursor: pointer; }
.lp-alt { display: flex; align-items: center; justify-content: center; min-height: 46px; margin: 0; border-radius: 10px; border: 1.5px solid #d9e7c8; color: #3f6212; font-weight: 700; background: #f7fee7; }
.lp-alt.quiet { background: transparent; color: #57534e; border-color: #e7e5e4; }
@media (min-width: 900px) {
  .lp-left { display: block; }
  .lp-right { width: min(480px, 42vw); flex: none; }
}
@media (max-width: 899px) {
  .lp-root { flex-direction: column; }
  .lp-left { display: block; height: 34vh; min-height: 180px; flex: none; }
  .lp-right { min-height: 0; flex: 1; }
}
.sidebar .brand-logo { height: 56px; max-width: 200px; }
.search { flex: 1; min-width: 0; }
.search input, .field input, .field select, .field textarea {
  width: 100%;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  padding: 10px 12px;
}
.field textarea { min-height: 96px; resize: vertical; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea { font-weight: 450; color: var(--ink); }
.icon-btn {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--card);
  border: 1px solid var(--line);
  flex: 0 0 auto;
}
.badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 99px;
  background: var(--warm);
  color: white;
  font-size: 10px;
  line-height: 16px;
  text-align: center;
}
.view, .stack { display: grid; gap: 12px; align-content: start; }
.split { display: grid; gap: 12px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 14px;
  min-width: 0;
}
.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.who > div { min-width: 0; }
.meta, .muted, time { color: var(--muted); font-size: 13px; font-weight: 450; }
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  background: var(--c, var(--accent));
  color: white;
  flex: 0 0 auto;
  overflow: hidden;
}
.avatar.lg { width: 72px; height: 72px; font-size: 28px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.sport-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 26px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  flex: 0 0 auto;
}
.activity-link { display: grid; gap: 10px; margin-top: 12px; min-width: 0; }
.activity-link h2 { font-size: 1.25rem; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.stats div, .stat {
  background: var(--bg);
  border-radius: 10px;
  padding: 10px;
  min-width: 0;
}
.stats b, .stat b { display: block; font-size: 1.02rem; font-variant-numeric: tabular-nums; font-weight: 700; }
.stats span, .stat span { color: var(--muted); font-size: 12px; }
.route-svg, .elev-svg {
  width: 100%;
  height: 168px;
  min-height: 168px;
  display: block;
  border-radius: 12px;
  background: #e7eef2;
  border: 1px solid var(--line);
}
.elev-svg { height: 110px; min-height: 110px; background: var(--bg); }
.map-frame {
  height: 320px;
  min-height: 320px;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #dbe4ea;
  position: relative;
  z-index: 0;
}
.map-frame.tall, .map-frame.explore { height: min(68dvh, 560px); }
.map-frame.record { height: min(52dvh, 460px); }
.map-thumb { height: 190px; min-height: 190px; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); background: #d5dee6; }
.map-thumb, .map-thumb .leaflet-container, .map-thumb .leaflet-pane { pointer-events: none; }
.segment-card { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "copy time"; gap: 8px 16px; align-items: center; }
.segment-card .map-thumb { grid-area: map; height: 150px; min-height: 150px; }
.segment-card:has(.map-thumb) { grid-template-areas: "map map" "copy time"; }
.segment-copy { grid-area: copy; min-width: 0; }
.segment-copy p { margin: 4px 0 0; overflow-wrap: anywhere; }
.segment-time { grid-area: time; font-size: 1.2rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
@media (max-width: 640px) {
  .segment-card, .segment-card:has(.map-thumb) { grid-template-areas: "map map" "copy copy" "time time"; grid-template-columns: 1fr; }
  .segment-card:not(:has(.map-thumb)) { grid-template-areas: "copy" "time"; }
}
.leaflet-container { height: 100%; width: 100%; background: #dbe4ea; font: inherit; }
.map-layers {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px;
  box-shadow: var(--shadow);
}
.map-layers button {
  border: 0;
  background: transparent;
  border-radius: 8px;
  min-height: 32px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 650;
  color: var(--ink);
}
.map-layers button.on { background: var(--accent); color: var(--accent-ink); }
.row-actions, .btn-row, .chips, .lang { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.chip, .btn, .lang button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  padding: 6px 12px;
  font-size: 14px;
  font-weight: 650;
  line-height: 1.1;
  white-space: nowrap;
}
.chip.active, .lang button.on, .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.warm { background: var(--warm); color: white; border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.danger { background: transparent; color: var(--danger); border-color: transparent; }
.btn.full { width: 100%; }
.kudo.on { background: #fff1ec; color: var(--warm); border-color: #ffd7cc; }
html[data-theme="dark"] .kudo.on { background: #3b241c; }
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 2px;
  padding: 6px 6px calc(6px + var(--safe-b));
  background: var(--card);
  border-top: 1px solid var(--line);
}
.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  min-height: 48px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  line-height: 1.1;
  padding: 4px 2px;
  text-align: center;
}
.tab.active { color: var(--accent); }
.tab-rec { color: var(--warm); }
.rail { display: grid; gap: 12px; align-content: start; }
.bar { height: 8px; border-radius: 99px; background: var(--bg); overflow: hidden; border: 1px solid var(--line); }
.bar span { display: block; height: 100%; background: var(--accent); }
.person, .note, .conv, .leader {
  display: flex;
  gap: 10px;
  align-items: center;
  min-width: 0;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.person:last-child, .note:last-child, .leader:last-child, .conv:last-child { border-bottom: 0; }
.person > div, .leader > div, .note > div { min-width: 0; }
.empty, .loading { padding: 28px 8px; text-align: center; color: var(--muted); }
.banner {
  display: block;
  padding: 12px 14px;
  border-radius: 12px;
  background: #fff7ed;
  color: #9a3412;
  border: 1px solid #fed7aa;
}
html[data-theme="dark"] .banner { background: #3b2412; color: #fdba74; border-color: #7c2d12; }
.sport-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.sport-tile {
  min-height: 64px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  font-weight: 650;
  padding: 8px;
}
.sport-tile.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.timer { font-variant-numeric: tabular-nums; font-size: clamp(44px, 12vw, 72px); letter-spacing: -0.04em; line-height: 1; font-weight: 700; }
.sheet { display: grid; gap: 12px; }
.calendar { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.calendar b, .day { text-align: center; font-size: 12px; }
.day { min-height: 36px; border-radius: 8px; display: grid; place-items: center; }
.day.has { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.weeks { display: flex; align-items: end; gap: 6px; height: 120px; }
.weeks i { flex: 1; display: block; border-radius: 6px 6px 2px 2px; background: var(--accent); min-height: 4px; }
.auth {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(72px + var(--safe-t)) 16px calc(28px + var(--safe-b));
  background: #07111c url("/login-hero.jpg") center/cover no-repeat;
  position: relative;
}
.auth::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(5, 10, 20, 0.28), rgba(5, 10, 20, 0.55));
}
.lang-corner { position: absolute; top: calc(14px + var(--safe-t)); right: 14px; z-index: 2; }
.auth .lang button { background: rgba(255, 255, 255, 0.92); }
.auth-panel, .register-page .auth-card {
  position: relative;
  z-index: 1;
  width: min(400px, 100%);
  display: grid;
  gap: 12px;
}
.auth-about { background: rgba(255, 255, 255, 0.92); }
.register-page {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(72px + var(--safe-t)) 16px calc(28px + var(--safe-b));
  background: var(--bg);
}
.simple { width: min(860px, calc(100% - 32px)); margin: 24px auto 48px; display: grid; gap: 14px; }
.livebar {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(var(--nav) + var(--safe-b) + 8px);
  z-index: 10;
  background: var(--ink);
  color: var(--bg);
  border-radius: 999px;
  padding: 12px 16px;
  text-align: center;
}
body.is-recording .bottom-nav { display: none; }
body.is-recording .main { padding-bottom: calc(16px + var(--safe-b)); }
body.is-recording .livebar { display: none; }
#toasts { position: fixed; left: 12px; right: 12px; top: calc(12px + var(--safe-t)); z-index: 40; display: grid; gap: 8px; pointer-events: none; }
.toast { justify-self: center; background: var(--ink); color: var(--bg); border-radius: 999px; padding: 10px 14px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
.check { display: flex; gap: 8px; align-items: center; min-height: 44px; font-weight: 600; }
.grid-2 { display: grid; gap: 10px; }
.menu-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.menu-grid a {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 72px;
  padding: 12px;
  font-weight: 700;
}
.challenge { display: grid; gap: 8px; }
.challenge .bar { margin-top: 4px; }
.compare { display: grid; gap: 8px; }
.compare-row { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center; }
.compare-row b { font-variant-numeric: tabular-nums; }
.compare-row span { text-align: center; color: var(--muted); font-size: 12px; }
.photo-row { display: flex; align-items: center; gap: 12px; }
.admin-list { display: grid; gap: 12px; }
.admin-user { display: grid; gap: 12px; }
.admin-user form { display: grid; gap: 8px; }
@media (min-width: 860px) {
  .admin-user { grid-template-columns: minmax(0, 1.2fr) 150px minmax(200px, 1fr) auto; align-items: end; }
}

@media (min-width: 720px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .menu-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .sport-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .auth { place-items: center; }
}

@media (min-width: 980px) {
  .layout { display: grid; grid-template-columns: 232px minmax(0, 1fr); }
  .sidebar {
    display: flex;
    flex-direction: column;
    gap: 18px;
    position: sticky;
    top: 0;
    height: 100dvh;
    padding: 20px 14px;
    border-right: 1px solid var(--line);
    background: var(--card);
  }
  .side-nav { display: grid; gap: 2px; }
  .side-nav a, .side-foot button {
    display: flex;
    align-items: center;
    min-height: 40px;
    border-radius: 10px;
    padding: 8px 10px;
    background: transparent;
    border: 0;
    text-align: left;
    font-weight: 650;
    color: var(--ink);
  }
  .side-nav a.active { background: var(--accent-soft); color: var(--accent); }
  .side-foot { margin-top: auto; display: grid; gap: 8px; }
  .mobile-brand, .bottom-nav, .topbar .lang { display: none; }
  .main { padding: 18px 28px 48px; }
  .split { grid-template-columns: minmax(0, 1fr) 300px; align-items: start; }
  .rail { position: sticky; top: 18px; }
  .livebar { left: 252px; right: auto; bottom: 16px; }
}

@media (max-width: 979px) {
  .desktop-only { display: none; }
}
