:root {
  --bg: #0f172a;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #f97316;
  --accent-ink: #ffffff;
  --ok: #16a34a;
  --bad: #dc2626;
  --top-h: 52px;
  --tabs-h: 60px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans Hebrew", sans-serif;
  color: var(--ink);
  background: #f8fafc;
  overscroll-behavior: none;
}

button { font: inherit; cursor: pointer; }
input, textarea, select { font: inherit; }

#top {
  position: fixed; inset: 0 0 auto 0; z-index: 1000;
  height: calc(var(--top-h) + var(--safe-t)); padding: var(--safe-t) 12px 0;
  display: flex; align-items: center; gap: 10px;
  background: var(--bg); color: #fff;
}
.brand { font-weight: 800; letter-spacing: .3px; flex: 1; }
.brand span { font-weight: 400; opacity: .7; }
.score {
  border: 0; border-radius: 999px; padding: 4px 12px;
  background: var(--accent); color: var(--accent-ink); font-weight: 800;
}
.icon-btn { border: 0; background: transparent; color: inherit; font-size: 22px; padding: 4px 6px; }

main { position: fixed; inset: calc(var(--top-h) + var(--safe-t)) 0 calc(var(--tabs-h) + var(--safe-b)) 0; }
.view { position: absolute; inset: 0; overflow: auto; }
#view-map { overflow: hidden; }
#map { position: absolute; inset: 0; }

.chips {
  position: absolute; top: 8px; left: 8px; right: 8px; z-index: 500;
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 999px; padding: 6px 12px; box-shadow: 0 1px 3px rgba(0,0,0,.12);
}
.chip.on { background: var(--bg); color: #fff; border-color: var(--bg); }

.map-btn {
  position: absolute; right: 12px; bottom: 16px; z-index: 500;
  width: 44px; height: 44px; border-radius: 50%; border: 0;
  background: #fff; font-size: 22px; box-shadow: 0 2px 8px rgba(0,0,0,.25);
}

#fab {
  position: fixed; z-index: 1100; right: 16px; bottom: calc(var(--tabs-h) + var(--safe-b) + 70px);
  width: 62px; height: 62px; border-radius: 50%; border: 0;
  background: var(--accent); color: #fff; font-size: 34px; line-height: 1;
  box-shadow: 0 4px 14px rgba(249,115,22,.5);
}

#tabs {
  position: fixed; inset: auto 0 0 0; z-index: 1000;
  height: calc(var(--tabs-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: flex; background: #fff; border-top: 1px solid var(--line);
}
#tabs button {
  flex: 1; border: 0; background: transparent; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 12px;
}
#tabs button span { font-size: 20px; }
#tabs button.active { color: var(--ink); font-weight: 700; }

/* Marqueurs */
.pin { background: none; border: 0; }
.pin span {
  display: flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 50%; border: 2px solid #fff;
  font-size: 16px; box-shadow: 0 1px 4px rgba(0,0,0,.35);
}
.pin.todo span { opacity: .55; border-style: dashed; width: 24px; height: 24px; font-size: 13px; }
.pin.gone span { filter: grayscale(1); opacity: .4; }
.pin.draft span { outline: 3px solid var(--accent); }
.me-dot { width: 16px; height: 16px; border-radius: 50%; background: #2563eb; border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(37,99,235,.25); }

/* Bottom sheet */
#backdrop { position: fixed; inset: 0; z-index: 1200; background: rgba(15,23,42,.35); }
#sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1300;
  max-height: 88vh; overflow: auto; background: var(--panel);
  border-radius: 18px 18px 0 0; padding: 6px 16px calc(20px + var(--safe-b));
  box-shadow: 0 -6px 24px rgba(0,0,0,.2);
  animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: .5; } to { transform: none; opacity: 1; } }
.grab { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 10px; }

h2 { margin: 4px 0 6px; font-size: 20px; }
h3 { margin: 18px 0 8px; font-size: 15px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.sub { color: var(--muted); font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; }

.big-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 8px 0; }
.big {
  border: 1px solid var(--line); background: #fff; border-radius: 14px; padding: 16px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 6px; font-weight: 600;
}
.big b { font-size: 30px; }
.big small { font-weight: 400; color: var(--muted); font-size: 12px; text-align: center; }

.type-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.type-grid .chip { box-shadow: none; }

label.f { display: block; margin: 12px 0 4px; font-weight: 600; font-size: 13px; }
input[type=text], input[type=number], input[type=date], input[type=search], textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff;
}
textarea { min-height: 80px; resize: vertical; }

.btn {
  border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 700;
  background: var(--bg); color: #fff;
}
.btn.accent { background: var(--accent); }
.btn.ghost { background: #f1f5f9; color: var(--ink); }
.btn.ok { background: var(--ok); }
.btn.bad { background: var(--bad); }
.btn.small { padding: 8px 12px; font-size: 13px; border-radius: 10px; }
.btn.full { width: 100%; margin-top: 14px; }

.stars { display: flex; gap: 4px; font-size: 28px; }
.stars button { border: 0; background: none; padding: 0; color: #cbd5e1; }
.stars button.on { color: #f59e0b; }
.stars-ro { color: #f59e0b; letter-spacing: 1px; }

.minimap { height: 170px; border-radius: 12px; margin-top: 6px; border: 1px solid var(--line); }

.media-strip { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0; }
.media-strip > * { flex: none; }
.thumb { width: 92px; height: 92px; border-radius: 10px; object-fit: cover; background: #e2e8f0; position: relative; }
.media-strip video { width: 220px; max-height: 160px; border-radius: 10px; background: #000; }
.media-strip audio { width: 260px; }
.media-tile { position: relative; }
.media-tile .x {
  position: absolute; top: -6px; right: -6px; width: 24px; height: 24px; border-radius: 50%;
  border: 0; background: var(--bad); color: #fff; font-size: 13px; line-height: 1;
}
.audio-tile { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--muted); }

.tags { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; }
.tags dt { color: var(--muted); }
.tags dd { margin: 0; word-break: break-word; }

.review { border-top: 1px solid var(--line); padding: 10px 0; }
.review .who { font-weight: 700; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: #f1f5f9; color: var(--muted); }
.badge.ok { background: #dcfce7; color: #166534; }
.badge.bad { background: #fee2e2; color: #991b1b; }
.badge.todo { background: #ffedd5; color: #9a3412; }

.nearby button { width: 100%; text-align: left; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 8px 10px; margin-bottom: 6px; }

/* Liste */
.list-head { position: sticky; top: 0; background: #f8fafc; padding: 10px 12px; z-index: 2; }
.item-row {
  display: flex; gap: 12px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line);
  background: #fff; width: 100%; border-left: 0; border-right: 0; border-top: 0; text-align: left;
}
.item-row .ic { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 18px; flex: none; }
.item-row .t { font-weight: 600; }
.group-title { padding: 14px 14px 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); font-weight: 700; }

/* Ma rue */
#rue { padding: 16px; max-width: 640px; margin: 0 auto; }
.score-big { text-align: center; padding: 18px; border-radius: 18px; background: var(--bg); color: #fff; }
.score-big b { font-size: 56px; display: block; line-height: 1; }
.check { margin: 10px 0; }
.check .bar { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; margin-top: 4px; }
.check .bar i { display: block; height: 100%; background: var(--accent); }
.board li { margin: 4px 0; }

/* Overlay plein écran (enregistreur, pente) */
#overlay {
  position: fixed; inset: 0; z-index: 2000; background: #000; color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  padding: calc(20px + var(--safe-t)) 20px calc(20px + var(--safe-b));
  text-align: center;
}
#overlay video { width: 100%; max-height: 60vh; object-fit: cover; border-radius: 12px; background: #111; }
.rec-time { font-size: 28px; font-variant-numeric: tabular-nums; font-weight: 700; }
.rec-dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; background: var(--bad); margin-right: 8px; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.meter { width: 80%; height: 14px; border-radius: 7px; background: #333; overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #22c55e, #f59e0b, #ef4444); transition: width .1s; }
.slope-val { font-size: 72px; font-weight: 800; line-height: 1; }
.level { width: 220px; height: 220px; border-radius: 50%; border: 3px solid #475569; position: relative; }
.level::after { content: ""; position: absolute; left: 50%; top: 50%; width: 2px; height: 100%; background: #475569; transform: translate(-50%, -50%); }
.level .bubble { position: absolute; width: 36px; height: 36px; margin: -18px 0 0 -18px; border-radius: 50%; background: var(--accent); left: 50%; top: 50%; }
#overlay .row { justify-content: center; }
#overlay .hint { color: #cbd5e1; max-width: 420px; }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 2100;
  bottom: calc(var(--tabs-h) + var(--safe-b) + 20px);
  background: var(--bg); color: #fff; padding: 10px 16px; border-radius: 12px; max-width: 90vw;
  box-shadow: 0 4px 14px rgba(0,0,0,.3);
}

.leaflet-popup-content { margin: 8px 12px; }

/* ---------- Fil du quartier ---------- */
#feed { max-width: 640px; margin: 0 auto; padding: 10px 10px 90px; }
.post {
  display: block; width: 100%; text-align: left; background: #fff; border: 1px solid var(--line);
  border-radius: 16px; padding: 12px; margin-bottom: 10px; color: var(--ink);
}
.avatar {
  width: 36px; height: 36px; border-radius: 50%; flex: none; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #f97316, #db2777); color: #fff; font-weight: 800;
}
.ptype { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 13px; color: var(--ink); margin-top: 2px; }
.ptext { margin: 8px 0 4px; white-space: pre-wrap; }
.empty { text-align: center; padding: 50px 20px; }

/* ---------- Quêtes, bataille, badges ---------- */
.quest {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; margin-bottom: 8px; color: var(--ink);
}
.quest .qi { font-size: 26px; }
.quest .qp { background: #ffedd5; color: #9a3412; font-weight: 800; border-radius: 999px; padding: 4px 10px; font-size: 13px; }
.battle { background: #fff; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.rival { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.rival:last-child { border-bottom: 0; }
.rival.me { background: #fff7ed; font-weight: 700; }
.rival .rk { width: 24px; height: 24px; border-radius: 50%; background: var(--bg); color: #fff; font-size: 12px; display: flex; align-items: center; justify-content: center; }
.badges { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.badge-card {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 2px;
  background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 8px 4px; opacity: .45; filter: grayscale(1);
}
.badge-card.got { opacity: 1; filter: none; border-color: #fdba74; background: #fff7ed; }
.badge-card span { font-size: 24px; }
.badge-card b { font-size: 11px; }
.badge-card small { font-size: 10px; color: var(--muted); }

/* ---------- Médias datés ---------- */
.mdate { position: absolute; left: 4px; bottom: 4px; background: rgba(15,23,42,.75); color: #fff; font-size: 10px; padding: 1px 5px; border-radius: 6px; }
.audio-tile .mdate { position: static; align-self: flex-start; }

/* ---------- Accueil ---------- */
.welcome { text-align: center; }
.wlogo { font-size: 54px; margin-top: 6px; }
.steps { text-align: left; padding-left: 20px; }
.steps li { margin: 8px 0; }

/* ---------- Finitions ---------- */
#top { background: linear-gradient(90deg, #0f172a, #1e293b); }
.brand { font-size: 17px; }
.score { box-shadow: 0 0 0 3px rgba(249,115,22,.25); }
.score-big { background: radial-gradient(circle at 30% 20%, #f97316, #9a3412 60%, #0f172a); }
.chip { font-size: 14px; }
#tabs button span { transition: transform .15s; }
#tabs button.active span { transform: translateY(-2px) scale(1.1); }

/* ---------- Pente & relief ---------- */
.slope-legend {
  display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: 11px; color: var(--ink);
  background: rgba(255,255,255,.94); border: 1px solid var(--line); border-radius: 10px; padding: 5px 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,.15); margin-bottom: 18px !important;
}
.slope-legend span { display: inline-flex; align-items: center; gap: 3px; }
.slope-legend i { display: inline-block; width: 14px; height: 6px; border-radius: 3px; }
.slope-here {
  display: block; width: 100%; text-align: left; margin: 8px 0; padding: 10px 12px; border-radius: 12px;
  border: 1px solid #fed7aa; background: #fff7ed; color: var(--ink); font-size: 14px;
}
.hero-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0 6px; }
.hero { background: #f8fafc; border: 1px solid var(--line); border-radius: 12px; padding: 10px 6px; text-align: center; }
.hero b { display: block; font-size: 22px; line-height: 1.1; }
.hero span { font-size: 11px; color: var(--muted); }
.chart-wrap { position: relative; margin-top: 8px; }
.chart-wrap svg { width: 100%; height: auto; display: block; touch-action: none; }
.chart-wrap .grid { stroke: #e2e8f0; stroke-width: 1; }
.chart-wrap .tick { font-size: 10px; fill: #64748b; }
.chart-wrap .cross { stroke: #0f172a; stroke-width: 1; stroke-dasharray: 3 3; }
.chart-tip {
  position: absolute; top: 4px; width: 150px; pointer-events: none;
  background: var(--bg); color: #fff; font-size: 12px; line-height: 1.35; padding: 6px 8px; border-radius: 8px;
}
.chart-ends { font-size: 12px; color: var(--muted); padding: 0 10px 0 34px; }
.sec-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.sec-table th { text-align: left; color: var(--muted); font-weight: 600; padding: 4px 6px; border-bottom: 1px solid var(--line); }
.sec-table td { padding: 6px; border-bottom: 1px solid var(--line); }
.sec-table tr.on td { background: #fff7ed; font-weight: 700; }
.sec-table .sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
