:root {
	--paper: #efe3c6;
	--paper-2: #e6d5ad;
	--paper-edge: #c9b27e;
	--ink: #2b1d12;
	--ink-soft: #5c4630;
	--red: #a3271b;
	--red-deep: #7c1c13;
	--gold: #b5862c;
	--safe-b: env(safe-area-inset-bottom, 0px);
	--safe-t: env(safe-area-inset-top, 0px);
	--fell: "IM Fell English", Georgia, serif;
	--fell-sc: "IM Fell English SC", Georgia, serif;
	--body: "Spectral", Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--ink); }
body { font-family: var(--body); color: var(--ink); -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- Carte façon parchemin ---------- */
#map { position: fixed; inset: 0; background: var(--paper); }
.leaflet-tile-pane { filter: sepia(.6) saturate(.75) hue-rotate(-8deg) contrast(.92) brightness(1.03); }
.leaflet-container { font-family: var(--body); }
.vignette {
	position: fixed; inset: 0; pointer-events: none; z-index: 400;
	background:
		radial-gradient(120% 90% at 50% 45%, transparent 55%, rgba(80, 50, 20, .35) 100%),
		url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .22 0 0 0 0 .1 0 0 0 .09 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
	mix-blend-mode: multiply;
}
.leaflet-control-attribution { background: rgba(239, 227, 198, .75) !important; font-size: 10px; color: var(--ink-soft); }
.leaflet-control-attribution a { color: var(--ink-soft); }
.leaflet-bottom { bottom: calc(var(--sheet-h, 240px) - 4px); transition: bottom .3s; }
.leaflet-control-zoom { display: none; }

/* ---------- En-tête ---------- */
.top {
	position: fixed; z-index: 500; top: calc(var(--safe-t) + 12px); left: 12px; right: 12px;
	display: flex; justify-content: space-between; align-items: flex-start; pointer-events: none;
}
.top > * { pointer-events: auto; }
.cartouche {
	background: var(--paper); border: 1.5px solid var(--ink); outline: 1px solid var(--ink); outline-offset: 3px;
	padding: 6px 16px 7px; display: flex; flex-direction: column; align-items: center;
	box-shadow: 0 6px 18px rgba(40, 20, 5, .25);
}
.cartouche-title { font-family: var(--fell-sc); font-size: 24px; line-height: 1; letter-spacing: .04em; }
.cartouche-sub { font-family: var(--fell); font-style: italic; font-size: 13px; color: var(--ink-soft); }
.seal-btn, .locate {
	width: 46px; height: 46px; border-radius: 50%; border: 1.5px solid var(--ink);
	background: var(--paper); display: grid; place-items: center; box-shadow: 0 4px 12px rgba(40, 20, 5, .25);
}
.seal-btn svg, .locate svg { width: 22px; height: 22px; }
.locate { position: fixed; z-index: 500; right: 12px; bottom: calc(var(--sheet-h, 240px) + 14px); transition: bottom .3s; }

/* ---------- Feuille du bas ---------- */
.sheet {
	position: fixed; z-index: 600; left: 0; right: 0; bottom: 0;
	padding: 20px 20px calc(var(--safe-b) + 18px);
	background:
		linear-gradient(180deg, rgba(255, 250, 235, .5), transparent 40%),
		var(--paper);
	border-top: 1.5px solid var(--ink);
	box-shadow: 0 -10px 30px rgba(30, 15, 5, .35);
	max-width: 560px; margin: 0 auto;
}
@media (min-width: 560px) { .sheet { border: 1.5px solid var(--ink); border-bottom: 0; border-radius: 6px 6px 0 0; } }
.sheet::before { /* liseré double façon cadre de carte */
	content: ""; position: absolute; inset: 6px 6px auto; height: 0; border-top: 1px solid var(--ink); opacity: .5;
}
.view { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.eyebrow { margin: 0; font-family: var(--fell); font-style: italic; font-size: 17px; color: var(--ink-soft); }
.hint { margin: 0; font-size: 14px; color: var(--ink-soft); max-width: 34ch; min-height: 1.3em; }
.fine { font-size: 12.5px; color: var(--ink-soft); line-height: 1.4; }

.goal { display: flex; align-items: center; gap: 18px; }
.goal-read { display: flex; flex-direction: column; align-items: center; min-width: 7ch; }
.goal-read output { font-family: var(--fell); font-size: 52px; line-height: 1; font-variant-numeric: lining-nums; }
.goal-unit { font-size: 14px; color: var(--ink-soft); }
.goal-unit b { color: var(--ink); font-weight: 600; }
.step-btn {
	width: 48px; height: 48px; border-radius: 50%; border: 1.5px solid var(--ink); background: transparent;
	font-size: 26px; line-height: 1; display: grid; place-items: center;
}
.step-btn:active { background: var(--paper-2); }

input[type=range] { width: 100%; max-width: 360px; accent-color: var(--red); }

.cta {
	width: 100%; max-width: 360px; min-height: 54px; border: 0; border-radius: 3px;
	background: var(--red); color: #fbf1dc; font-family: var(--fell-sc); font-size: 22px; letter-spacing: .03em;
	box-shadow: inset 0 0 0 1.5px var(--red-deep), inset 0 0 0 4px var(--red), inset 0 0 0 5px rgba(251, 241, 220, .45), 0 4px 0 var(--red-deep);
}
.cta:active { transform: translateY(2px); box-shadow: inset 0 0 0 1.5px var(--red-deep), inset 0 0 0 4px var(--red), inset 0 0 0 5px rgba(251, 241, 220, .45), 0 2px 0 var(--red-deep); }
.cta:disabled { opacity: .45; }
.ghost {
	min-height: 50px; padding: 0 18px; border: 1.5px solid var(--ink); border-radius: 3px; background: transparent;
	font-family: var(--fell-sc); font-size: 19px;
}
.ghost.small { min-height: 42px; font-size: 16px; }
.ghost:active { background: var(--paper-2); }
.row { display: flex; gap: 10px; width: 100%; max-width: 360px; }
.row > * { flex: 1; }
.link { border: 0; background: none; font-size: 14px; color: var(--ink-soft); text-decoration: underline; text-underline-offset: 3px; padding: 4px; }

.stats3 { display: grid; grid-template-columns: repeat(3, 1fr); width: 100%; max-width: 380px; }
.stats3 > div { display: flex; flex-direction: column; align-items: center; padding: 2px 4px; }
.stats3 > div + div { border-left: 1px solid rgba(43, 29, 18, .25); }
.stats3 b { font-family: var(--fell); font-weight: 400; font-size: 30px; line-height: 1.1; }
.stats3 span { font-size: 12.5px; color: var(--ink-soft); }
.stats3 i { font-style: normal; }

/* Chargement : une plume qui gratte */
.quill { width: 64px; height: 26px; position: relative; }
.quill::before {
	content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 2px;
	background: repeating-linear-gradient(90deg, var(--red) 0 8px, transparent 8px 13px);
	animation: ink 1.1s linear infinite;
}
.loading-title { margin: 0; font-family: var(--fell); font-style: italic; font-size: 20px; }
@keyframes ink { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }

/* Progression */
.progress { position: relative; width: 100%; max-width: 380px; height: 10px; border: 1.5px solid var(--ink); border-radius: 6px; background: var(--paper-2); }
.progress-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--red); border-radius: 4px; transition: width .6s; }
.progress-walker { position: absolute; top: 50%; left: 0; width: 14px; height: 14px; margin: -7px 0 0 -7px; border-radius: 50%; background: var(--paper); border: 2px solid var(--ink); transition: left .6s; }

/* Arrivée */
.seal {
	width: 74px; height: 74px; border-radius: 50%; display: grid; place-items: center;
	background: radial-gradient(circle at 35% 30%, #c4372a, var(--red-deep));
	box-shadow: 0 0 0 4px rgba(163, 39, 27, .25), inset 0 -3px 6px rgba(0, 0, 0, .3);
	color: #fbe9c9; font-size: 34px; animation: stamp .5s cubic-bezier(.3, 1.6, .5, 1) both;
}
.done-title { margin: 0; font-family: var(--fell); font-size: 30px; }
@keyframes stamp { from { transform: scale(2.2) rotate(-20deg); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Carnet & listes ---------- */
.drawer { position: fixed; inset: 0; z-index: 800; background: rgba(30, 18, 8, .55); display: flex; align-items: flex-end; justify-content: center; }
.drawer-paper {
	position: relative; width: 100%; max-width: 560px; max-height: 86vh; overflow: auto;
	background: var(--paper); border: 1.5px solid var(--ink); border-bottom: 0; border-radius: 6px 6px 0 0;
	padding: 22px 22px calc(var(--safe-b) + 24px);
}
.drawer h2 { margin: 0 0 14px; font-family: var(--fell-sc); font-weight: 400; font-size: 28px; text-align: center; }
.drawer h3 { margin: 22px 0 8px; font-family: var(--fell); font-style: italic; font-weight: 400; font-size: 19px; border-bottom: 1px solid rgba(43, 29, 18, .3); padding-bottom: 4px; }
.close { position: absolute; top: 8px; right: 10px; width: 40px; height: 40px; border: 0; background: none; font-size: 30px; line-height: 1; }
.stats3.big { margin: 0 auto; }
.log { list-style: none; margin: 0; padding: 0; }
.log li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px dashed rgba(43, 29, 18, .25); font-size: 15px; }
.log li span:last-child { color: var(--ink-soft); white-space: nowrap; }
.log li.got { text-decoration: line-through; text-decoration-color: var(--red); color: var(--ink-soft); }
.log .empty { justify-content: center; color: var(--ink-soft); font-style: italic; }
.setting { display: flex; justify-content: space-between; align-items: center; font-size: 15px; }
.setting input { width: 5em; font: inherit; padding: 6px 8px; border: 1.5px solid var(--ink); border-radius: 3px; background: #f7eed8; text-align: right; }

.toast {
	position: fixed; z-index: 900; left: 50%; top: calc(var(--safe-t) + 80px); transform: translate(-50%, -20px);
	background: var(--ink); color: var(--paper); padding: 10px 18px; border-radius: 3px; font-family: var(--fell); font-size: 17px;
	opacity: 0; transition: opacity .25s, transform .25s; pointer-events: none; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Marqueurs ---------- */
.me-dot { width: 18px; height: 18px; border-radius: 50%; background: #2f5d8a; border: 3px solid #fbf1dc; box-shadow: 0 0 0 6px rgba(47, 93, 138, .22); }
.start-mark { width: 34px; height: 34px; display: grid; place-items: center; }
.start-mark svg { width: 34px; height: 34px; filter: drop-shadow(0 2px 2px rgba(0,0,0,.3)); }
.borne {
	width: 26px; height: 26px; border-radius: 50%; background: var(--paper); border: 1.5px solid var(--ink);
	display: grid; place-items: center; font-family: var(--fell); font-size: 14px; color: var(--ink); box-shadow: 0 2px 4px rgba(0,0,0,.25);
}
.borne.got { background: var(--red); color: #fbf1dc; border-color: var(--red-deep); }
.poi {
	width: 24px; height: 24px; transform: rotate(45deg); background: var(--gold); border: 1.5px solid var(--ink);
	box-shadow: 0 2px 4px rgba(0,0,0,.3); display: grid; place-items: center;
}
.poi::after { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--ink); }
.poi.got { background: var(--red); }
.arrow { width: 16px; height: 16px; color: var(--red-deep); }
.arrow svg { width: 16px; height: 16px; display: block; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--paper); color: var(--ink); border: 1px solid var(--ink); box-shadow: 0 4px 12px rgba(0,0,0,.3); }
.leaflet-popup-content { font-family: var(--body); font-size: 14px; margin: 10px 14px; }
.leaflet-popup-content b { font-family: var(--fell); font-size: 17px; font-weight: 400; }
