:root {
  --bg1: #7c3aed;
  --bg2: #4f46e5;
  --bg3: #0ea5e9;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #7c3aed;
  --primary-dark: #6d28d9;
  --ok: #16a34a;
  --no: #dc2626;
  --radius: 18px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roblox, Roboto, sans-serif;
  color: var(--text);
  background: linear-gradient(160deg, var(--bg1), var(--bg2) 50%, var(--bg3));
  background-attachment: fixed;
}

.screen {
  display: none;
  max-width: 520px;
  margin: 0 auto;
  padding: 20px 16px calc(28px + env(safe-area-inset-bottom));
  min-height: 100dvh;
}

.screen.active { display: block; }

.home-head { text-align: center; color: #fff; padding: 18px 0 22px; }
.logo { font-size: 40px; font-weight: 800; letter-spacing: 1px; text-shadow: 0 3px 10px rgba(0,0,0,.25); }
.tagline { margin: 8px 0 0; font-size: 17px; opacity: .95; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px 18px;
  box-shadow: 0 12px 32px rgba(0,0,0,.22);
  margin-bottom: 16px;
}

.lbl {
  display: block;
  font-weight: 700;
  font-size: 17px;
  margin: 18px 0 8px;
}
.lbl:first-child { margin-top: 0; }

input[type="text"], input:not([type]) {
  width: 100%;
  font-size: 19px;
  padding: 14px;
  border: 2px solid #d1d5db;
  border-radius: 12px;
  background: #f9fafb;
}
input:focus { outline: 3px solid #c4b5fd; border-color: var(--primary); }

.cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.card-btn {
  border: 3px solid #e5e7eb;
  background: #f9fafb;
  border-radius: 14px;
  padding: 14px 6px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  font-size: 16px;
}
.card-btn .ic { font-size: 34px; line-height: 1; }
.card-btn .t { font-weight: 800; }
.card-btn small { color: var(--muted); font-size: 12px; }
.card-btn.selected {
  border-color: var(--primary);
  background: #f5f3ff;
  box-shadow: 0 0 0 3px #ddd6fe;
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 2px solid #e5e7eb;
  background: #f9fafb;
  border-radius: 999px;
  padding: 12px 18px;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
}
.chip.selected {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.hint { color: var(--muted); font-size: 14px; margin: 10px 0 0; }
.center { text-align: center; }
.muted { color: var(--muted); }

.sim-check {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 18px 0 6px;
  padding: 12px;
  background: #fef9c3;
  border: 2px dashed #eab308;
  border-radius: 12px;
  font-size: 15px;
  cursor: pointer;
}
.sim-check input { width: 22px; height: 22px; accent-color: #ca8a04; }

.btn {
  display: block;
  width: 100%;
  border: none;
  border-radius: 14px;
  padding: 14px;
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
  background: #e5e7eb;
  color: var(--text);
  margin-top: 12px;
}
.btn.primary { background: var(--primary); color: #fff; box-shadow: 0 6px 16px rgba(124,58,237,.4); }
.btn.primary:active { background: var(--primary-dark); }
.btn.danger { background: #fee2e2; color: #b91c1c; }
#btn-finish {
  position: sticky;
  bottom: calc(10px + env(safe-area-inset-bottom));
  box-shadow: 0 -2px 14px rgba(0,0,0,.18);
}
.btn.big { font-size: 20px; padding: 16px; }
.btn.back { width: auto; background: rgba(255,255,255,.9); margin: 0 0 10px; }
.btn.link { background: none; border: none; color: #6d28d9; text-decoration: underline; font-size: 14px; cursor: pointer; }

.error {
  background: #fee2e2;
  color: #b91c1c;
  border-radius: 10px;
  padding: 10px 12px;
  margin: 12px 0 0;
  font-weight: 600;
}
.ok {
  background: #dcfce7;
  color: #15803d;
  border-radius: 10px;
  padding: 10px 12px;
  margin: 12px 0 0;
  font-weight: 600;
}
.hidden { display: none !important; }

.topbar h2 { margin: 0 0 12px; font-size: 24px; color: #fff; text-shadow: 0 2px 6px rgba(0,0,0,.3); }

.routes-list { display: flex; flex-direction: column; gap: 10px; }
.route-item {
  text-align: left;
  background: var(--card);
  border: none;
  border-radius: 14px;
  padding: 14px;
  font-size: 17px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: 0 6px 18px rgba(0,0,0,.15);
}
.route-item:active { transform: scale(.98); }
.ri-name { font-weight: 800; font-size: 19px; }
.ri-info { color: var(--muted); font-size: 14px; }

#rd-map,
#sum-map {
  height: 260px;
  background: #f5f3ff;
  border-radius: 12px;
  margin: 10px 0;
  z-index: 0;
}

#rd-map:fullscreen {
  width: 100vw;
  height: 100vh;
  border-radius: 0;
  margin: 0;
}

.route-arrow {
  background: transparent;
  border: none;
}

.board { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.board-row {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  align-items: center;
  gap: 8px;
  background: #f9fafb;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 16px;
}
.board-row .medal { font-size: 24px; text-align: center; }
.board-row .who { font-weight: 700; }
.board-row .who small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }
.board-row .pts { font-weight: 800; font-size: 18px; color: var(--primary); }
.board-empty { color: var(--muted); font-size: 15px; }

.walk-top { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-bottom: 6px; }
.pill {
  background: rgba(255,255,255,.92);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 14px;
  font-weight: 700;
}

.distance-box {
  text-align: center;
  color: #fff;
  margin: 10px 0 4px;
  text-shadow: 0 3px 10px rgba(0,0,0,.25);
}
.distance-box span { font-size: 76px; font-weight: 900; font-variant-numeric: tabular-nums; }
.distance-box small { font-size: 24px; margin-left: 6px; font-weight: 700; }

.progress {
  height: 20px;
  background: rgba(255,255,255,.3);
  border-radius: 999px;
  overflow: hidden;
  margin: 10px 0;
}
#w-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #34d399, #a3e635);
  border-radius: 999px;
  transition: width .4s ease;
}

.walk-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 14px 0;
}
.ws {
  background: var(--card);
  border-radius: 14px;
  text-align: center;
  padding: 12px 6px;
  box-shadow: 0 6px 16px rgba(0,0,0,.15);
}
.ws span { font-size: 26px; font-weight: 900; display: block; font-variant-numeric: tabular-nums; }
.ws small { color: var(--muted); }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(17,24,39,.72);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  padding: 12px;
}
.modal-card {
  background: var(--card);
  width: 100%;
  max-width: 520px;
  border-radius: 24px 24px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  max-height: 94dvh;
  overflow-y: auto;
  animation: slideUp .25s ease;
}
@keyframes slideUp { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }

.q-badge {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
  border-radius: 999px;
  padding: 6px 16px;
  font-size: 15px;
}
.q-emoji {
  text-align: center;
  font-size: 92px;
  line-height: 1.15;
  margin: 12px 0 2px;
  background: radial-gradient(circle, #ede9fe 60%, transparent 70%);
  border-radius: 50%;
}
.q-cat {
  text-align: center;
  color: var(--primary);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 13px;
}
#q-text {
  text-align: center;
  font-size: 23px;
  margin: 10px 0 16px;
}
#q-options { display: flex; flex-direction: column; gap: 10px; }
.opt {
  border: 3px solid #e5e7eb;
  background: #f9fafb;
  border-radius: 14px;
  padding: 16px;
  font-size: 19px;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
}
.opt:active { transform: scale(.98); }
.opt.picked { border-color: var(--primary); }
.opt.right { border-color: var(--ok); background: #dcfce7; color: #14532d; }
.opt.show-right { border-color: var(--ok); background: #dcfce7; }
.opt.wrong { border-color: var(--no); background: #fee2e2; }

.feedback { border-radius: 12px; padding: 14px; font-size: 19px; font-weight: 800; text-align: center; margin-top: 14px; }
.feedback.ok { background: #dcfce7; color: #15803d; }
.feedback.no { background: #fee2e2; color: #b91c1c; }

.party { text-align: center; font-size: 44px; margin-top: 20px; animation: bounce 1.2s infinite; }
@keyframes bounce { 0%,100% { transform: translateY(0);} 50% { transform: translateY(-10px);} }

#sum-title { text-align: center; color: #fff; font-size: 32px; margin: 4px 0 12px; text-shadow: 0 2px 8px rgba(0,0,0,.3); }

.sum-points { text-align: center; color: var(--primary); margin: 6px 0 14px; }
.sum-points span { font-size: 64px; font-weight: 900; }
.sum-points small { font-size: 20px; font-weight: 700; margin-left: 6px; }

.sum-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; margin-bottom: 8px; }
.sum-grid div {
  background: #f5f3ff;
  border-radius: 12px;
  text-align: center;
  padding: 10px 4px;
}
.sum-grid span { font-size: 22px; font-weight: 800; display: block; }
.sum-grid small { color: var(--muted); }

.route-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  background: #f5f3ff;
  border: 2px solid var(--primary);
  color: var(--primary-dark);
  border-radius: 12px;
  padding: 10px 12px;
  font-weight: 700;
  margin-bottom: 14px;
  font-size: 15px;
}

.install-box { margin-top: 14px; }
.install-box .btn { margin-top: 0; }

.install-hint {
  margin-top: 12px;
  padding: 12px;
  background: #eff6ff;
  border: 2px dashed #3b82f6;
  border-radius: 12px;
  color: #1e40af;
  font-size: 14px;
  line-height: 1.5;
}

.pwa-status {
  margin-top: 14px;
  text-align: center;
  font-size: 12px;
}

.byline {
  margin-top: 18px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}
