:root {
  --parch: #f3e9d2;
  --parch-2: #eadcbc;
  --paper: #fbf6ea;
  --ink: #2a1f17;
  --ink-2: #5b4a3a;
  --muted: #8a7761;
  --line: rgba(74, 52, 30, .16);
  --wine: #7a2a24;
  --wine-2: #962f27;
  --gold: #c18f32;
  --olive: #5f6b36;
  --shadow: 0 10px 30px -12px rgba(52, 33, 15, .45);
  --radius: 18px;
  --serif: "Cormorant Garamond", "Iowan Old Style", Georgia, serif;
  --sans: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

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

.app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 760px;
  margin: 0 auto;
  background:
    radial-gradient(120% 60% at 50% 0%, rgba(255, 250, 235, .9), transparent 70%),
    var(--parch);
}

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 8px;
}
.brand { display: flex; align-items: center; gap: 9px; text-decoration: none; color: var(--ink); }
.brand__mark { width: 30px; height: 30px; border-radius: 9px; box-shadow: 0 2px 6px rgba(122, 42, 36, .35); }
.brand__name { font-family: var(--serif); font-weight: 700; font-size: 25px; letter-spacing: .2px; line-height: 1; }
.chip {
  font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  color: var(--wine); background: rgba(122, 42, 36, .09); border: 1px solid rgba(122, 42, 36, .18);
  padding: 4px 8px; border-radius: 999px; white-space: nowrap;
}
.chip.is-practice { color: var(--olive); background: rgba(95, 107, 54, .12); border-color: rgba(95, 107, 54, .25); }
.topbar__actions { margin-left: auto; display: flex; gap: 4px; }
.iconbtn {
  width: 38px; height: 38px; display: grid; place-items: center;
  border: 0; background: transparent; border-radius: 12px;
}
.iconbtn:hover, .iconbtn:focus-visible { background: rgba(74, 52, 30, .08); }
.iconbtn.is-active { background: rgba(95, 107, 54, .16); color: var(--olive); }
.iconbtn svg, .mapbtn svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- clue card ---------- */
.clue {
  margin: 2px 12px 10px;
  padding: 12px 16px 13px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  position: relative;
}
.clue::before { /* subtle double rule like an old page */
  content: ""; position: absolute; inset: 5px; border: 1px solid rgba(193, 143, 50, .22);
  border-radius: 14px; pointer-events: none;
}
.clue__meta {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
}
.dots { display: flex; gap: 5px; }
.dot {
  width: 22px; height: 7px; border-radius: 99px; background: rgba(74, 52, 30, .14);
  transition: background .3s, transform .3s;
}
.dot.is-current { background: var(--ink-2); }
.dot.s-a { background: #3f8f4e; } .dot.s-b { background: #7aa43c; } .dot.s-c { background: #d6a62a; }
.dot.s-d { background: #d9772b; } .dot.s-e { background: #b8432f; }
.clue__name {
  font-family: var(--serif); font-weight: 700; font-size: clamp(30px, 8.6vw, 40px);
  line-height: 1.05; margin: 6px 0 4px; letter-spacing: .2px;
}
.clue__sub { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink-2); }
.clue__ref { font-style: italic; font-family: var(--serif); font-size: 18px; font-weight: 600; }
.diff {
  font-size: 10.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  padding: 3px 7px; border-radius: 6px; background: rgba(74, 52, 30, .08); color: var(--ink-2);
}
.diff.d1 { background: rgba(63, 143, 78, .13); color: #2f6e3b; }
.diff.d2 { background: rgba(214, 166, 42, .17); color: #8a6512; }
.diff.d3 { background: rgba(184, 67, 47, .13); color: #9a3524; }

/* ---------- map ---------- */
.stage { position: relative; flex: 1; min-height: 180px; margin: 0 12px; }
#map {
  position: absolute; inset: 0;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .4), var(--shadow);
  background: #d9cba8;
  cursor: crosshair;
}
.leaflet-container { font-family: var(--sans); background: #d4c6a3; }
.leaflet-grab { cursor: crosshair; }
.leaflet-dragging .leaflet-grab { cursor: grabbing; }
.tiles-parchment { filter: sepia(.28) saturate(1.25) contrast(1.1) brightness(.97); }
.modal__card:focus { outline: none; }
.leaflet-control-attribution {
  font-size: 9.5px; background: rgba(251, 246, 234, .82) !important; color: var(--ink-2);
  border-top-left-radius: 8px; padding: 1px 6px !important;
}
.leaflet-control-attribution a { color: var(--wine); }
.leaflet-control-zoom { border: 1px solid var(--line) !important; border-radius: 12px !important; overflow: hidden; box-shadow: var(--shadow) !important; }
.leaflet-control-zoom a { background: var(--paper) !important; color: var(--ink) !important; width: 36px !important; height: 36px !important; line-height: 34px !important; }
@media (pointer: coarse) { .leaflet-control-zoom { display: none; } }

.maptools { position: absolute; top: 10px; left: 10px; z-index: 500; display: flex; gap: 6px; }
.mapbtn {
  height: 34px; min-width: 34px; padding: 0 10px; display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 11px; background: rgba(251, 246, 234, .92);
  font-size: 12.5px; font-weight: 600; color: var(--ink-2); box-shadow: 0 4px 14px -6px rgba(52, 33, 15, .5);
  backdrop-filter: blur(6px);
}
.mapbtn svg { width: 17px; height: 17px; }

/* markers */
.pin { width: 22px; height: 22px; border-radius: 50%; position: relative; }
.pin--guess { background: var(--ink); border: 3px solid #fff; box-shadow: 0 3px 10px rgba(0, 0, 0, .45); }
.pin--guess::after { content: ""; position: absolute; inset: 5px; border-radius: 50%; background: #fff; }
.pin--true { background: var(--gold); border: 3px solid #fff; box-shadow: 0 3px 10px rgba(0, 0, 0, .45); }
.pin--true::before {
  content: ""; position: absolute; inset: -9px; border-radius: 50%;
  border: 2px solid var(--gold); animation: pulse 1.8s ease-out infinite;
}
.pin--true::after { content: ""; position: absolute; inset: 5px; border-radius: 50%; background: var(--wine); }
.pin--small { transform: scale(.75); }
@keyframes pulse { from { transform: scale(.6); opacity: 1; } to { transform: scale(1.5); opacity: 0; } }
.leaflet-tooltip.place-tip {
  font-family: var(--serif); font-weight: 700; font-size: 16px; color: var(--ink);
  background: var(--paper); border: 1px solid rgba(193, 143, 50, .5); border-radius: 9px;
  padding: 2px 9px; box-shadow: 0 4px 14px -6px rgba(0, 0, 0, .5);
}
.leaflet-tooltip.place-tip.small { font-size: 13px; padding: 1px 7px; }

/* ---------- bottom sheet ---------- */
.sheet {
  margin: 10px 12px calc(12px + env(safe-area-inset-bottom));
  padding: 14px 16px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.sheet__aim, .sheet__done { display: flex; align-items: center; gap: 12px; }
.hint { margin: 0; flex: 1; font-size: 14.5px; color: var(--ink-2); line-height: 1.35; }
.btn {
  border: 0; border-radius: 14px; padding: 13px 20px; font-weight: 700; font-size: 16px;
  transition: transform .08s, background .2s, opacity .2s;
}
.btn:active { transform: scale(.97); }
.btn--primary { background: var(--wine); color: #fff8ec; box-shadow: 0 6px 16px -8px rgba(122, 42, 36, .9); }
.btn--primary:hover { background: var(--wine-2); }
.btn--primary:disabled { background: #c9b9a0; color: #f6efe1; box-shadow: none; cursor: not-allowed; }
.btn--ghost { background: transparent; border: 1.5px solid var(--line); color: var(--ink); }
.sheet__aim .btn, .sheet__done .btn { min-width: 128px; }

.result__top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.verdict { font-family: var(--serif); font-size: 25px; font-weight: 700; line-height: 1.1; }
.distance { font-size: 14px; color: var(--ink-2); margin-top: 3px; }
.points { font-family: var(--serif); font-weight: 700; font-size: 44px; line-height: .9; color: var(--wine); text-align: right; }
.points small { font-family: var(--sans); font-size: 12px; font-weight: 600; color: var(--muted); margin-left: 3px; }
.fact { margin: 10px 0 0; font-size: 14.5px; line-height: 1.45; color: var(--ink); }
.fact__ref { font-family: var(--serif); font-style: italic; font-size: 17px; color: var(--wine); }
.note {
  margin: 8px 0 0; font-size: 12.5px; line-height: 1.4; color: #7a5a1c;
  background: rgba(193, 143, 50, .12); border-radius: 9px; padding: 6px 9px;
}
.sheet__result .btn { width: 100%; margin-top: 12px; }

/* ---------- modals ---------- */
.modal {
  position: fixed; inset: 0; z-index: 2000; display: grid; place-items: end center;
  background: rgba(36, 24, 14, .45); backdrop-filter: blur(3px);
  animation: fade .2s ease;
}
@media (min-width: 600px) { .modal { place-items: center; } }
.modal__card {
  position: relative; width: min(520px, 100%); max-height: 92dvh; overflow: auto;
  background: var(--paper); border-radius: 24px 24px 0 0; padding: 22px 20px calc(22px + env(safe-area-inset-bottom));
  box-shadow: 0 -10px 40px -10px rgba(0, 0, 0, .4); animation: rise .25s ease;
}
@media (min-width: 600px) { .modal__card { border-radius: 24px; } }
.modal__close {
  position: absolute; top: 10px; right: 12px; width: 38px; height: 38px; border: 0; background: transparent;
  font-size: 28px; line-height: 1; color: var(--muted); border-radius: 12px;
}
.modal__title { font-family: var(--serif); font-size: 32px; margin: 0 0 10px; line-height: 1.05; }
.eyebrow { margin: 0 0 2px; font-size: 12px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.subhead { font-size: 12px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin: 18px 0 8px; }
.small { font-size: 13px; color: var(--ink-2); line-height: 1.5; }
.steps { padding-left: 20px; margin: 0; line-height: 1.5; font-size: 15px; }
.steps li { margin-bottom: 8px; }
.scoretable { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.scoretable td { padding: 6px 2px; border-bottom: 1px solid var(--line); }
.scoretable td:last-child { text-align: right; font-weight: 700; }
.modal__card > .btn[data-close] { width: 100%; margin-top: 10px; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(30px); opacity: .5; } }

.total { font-family: var(--serif); font-weight: 700; font-size: 64px; line-height: 1; color: var(--wine); }
.total small { font-size: 24px; color: var(--muted); margin-left: 6px; }
.total__line { margin: 4px 0 12px; color: var(--ink-2); font-size: 15px; }
.breakdown { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.breakdown li {
  display: grid; grid-template-columns: 26px 1fr auto; gap: 10px; align-items: center;
  padding: 9px 0; border-bottom: 1px solid var(--line);
}
.breakdown .em { font-size: 19px; }
.breakdown .nm { font-family: var(--serif); font-weight: 700; font-size: 19px; line-height: 1.1; }
.breakdown .mi { display: block; font-family: var(--sans); font-weight: 400; font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.breakdown .pt { font-weight: 700; font-size: 17px; }
.modal__actions { display: flex; gap: 10px; margin-top: 16px; }
.modal__actions .btn { flex: 1; }
.countdown { text-align: center; font-size: 13px; color: var(--muted); margin: 12px 0 0; }
.countdown strong { color: var(--ink); font-variant-numeric: tabular-nums; }

.statgrid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; text-align: center; }
.statgrid div { background: rgba(74, 52, 30, .05); border-radius: 12px; padding: 10px 2px; }
.statgrid b { display: block; font-family: var(--serif); font-size: 28px; line-height: 1; }
.statgrid span { font-size: 10.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.bars { display: grid; gap: 6px; }
.bar { display: grid; grid-template-columns: 62px 1fr; gap: 8px; align-items: center; font-size: 12.5px; color: var(--ink-2); }
.bar__fill {
  height: 22px; min-width: 26px; border-radius: 7px; background: rgba(122, 42, 36, .75); color: #fff8ec;
  font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: flex-end; padding: 0 7px;
}
.bar__fill.is-today { background: var(--gold); }

.toast {
  position: fixed; left: 50%; top: 18px; transform: translate(-50%, -30px); opacity: 0; z-index: 3000;
  background: var(--ink); color: #fff8ec; padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px;
  transition: .25s ease; pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 760px) {
  .clue, .sheet, .stage { margin-left: 16px; margin-right: 16px; }
}
@media (max-height: 640px) {
  .clue { padding: 8px 14px; }
  .clue__name { font-size: 28px; margin: 3px 0 2px; }
  .sheet { padding: 10px 14px; }
}
