/* Design tokens: quiet memorial, warm paper + evergreen. Display: Fraunces, body: Inter. */
:root {
  --ink: #1b2a22;
  --moss: #2f5d46;
  --moss-2: #3d7a5c;
  --moss-soft: #e3ede6;
  --paper: #f8f5ee;
  --paper-2: #efeadf;
  --line: #d8d1c2;
  --muted: #68756c;
  --gold: #b8862b;
  --gold-soft: #f4e9d2;
  --route: #d9480f;
  --you: #1f6fd0;
  --danger: #a33a2a;
  --shadow: 0 6px 24px rgba(27, 42, 34, .18);
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --sheet-peek: 136px;
  --sheet-half: 46dvh;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font-body); color: var(--ink); background: var(--paper-2);
  overflow: hidden; -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; }
button:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.search:focus-within { border-color: var(--gold); box-shadow: var(--shadow), 0 0 0 2px var(--gold-soft); }
input[type="search"]::-webkit-search-cancel-button, input[type="search"]::-webkit-search-decoration { -webkit-appearance: none; appearance: none; }

.app { position: fixed; inset: 0; }
#map { position: absolute; inset: 0; background: #cfd9d2; }
#map canvas { outline: none; }

/* ----- Top bar ----- */
.topbar {
  position: absolute; top: calc(10px + var(--safe-t)); left: 12px; right: 12px; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 8px; pointer-events: none;
}
.topbar .fab { pointer-events: auto; }
.brand {
  pointer-events: auto;
  display: inline-flex; align-items: baseline; gap: 8px;
  background: rgba(248, 245, 238, .92); backdrop-filter: blur(8px);
  border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px 6px 12px;
  box-shadow: var(--shadow);
}
.brand h1 { margin: 0; font-family: var(--font-display); font-weight: 600; font-size: 1.05rem; letter-spacing: .01em; }
.brand span { color: var(--muted); font-size: .72rem; }
/* Search: a round button that expands into a full-width field */
.search {
  pointer-events: auto; display: none; flex: 1; align-items: center; gap: 4px;
  background: var(--paper); border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 6px 4px 6px; box-shadow: var(--shadow);
}
.topbar.search-open .brand, .topbar.search-open #btnSearch { display: none; }
.topbar.search-open .search { display: flex; }
.search .back { border: 0; background: transparent; width: 38px; height: 38px; display: inline-grid; place-items: center; cursor: pointer; color: var(--moss); border-radius: 999px; }
.search .back svg { width: 22px; height: 22px; }
.search input {
  flex: 1; min-width: 0; border: 0; background: transparent; font: inherit; font-size: 16px;
  padding: 10px 0; color: var(--ink); outline: none;
}
.search input::placeholder { color: var(--muted); }
.search .clear { border: 0; background: var(--paper-2); border-radius: 999px; width: 34px; height: 34px; display: none; cursor: pointer; }
.search.has-text .clear { display: inline-grid; place-items: center; }

/* ----- Floating map buttons ----- */
.fabs {
  position: absolute; right: 12px; z-index: 20; display: flex; flex-direction: column; gap: 10px;
  bottom: calc(var(--sheet-peek) + 16px + var(--safe-b));
  transition: bottom .25s ease;
}
.fab {
  width: 48px; height: 48px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--paper); box-shadow: var(--shadow); cursor: pointer;
  display: grid; place-items: center; color: var(--moss); position: relative;
}
.fab svg { width: 24px; height: 24px; }
.fab.active { background: var(--moss); color: #fff; border-color: var(--moss); }
.fab.busy::after {
  content: ""; position: absolute; inset: -3px; border-radius: 16px;
  border: 2px solid var(--gold); border-top-color: transparent; animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.fab .north { transition: transform .15s linear; }

/* Keep the buttons above the sheet in every state */
.app:has(.sheet.half) .fabs { bottom: calc(var(--sheet-half) + 16px + var(--safe-b)); }
.app:has(.sheet.full) .fabs { display: none; }

/* ----- Bottom sheet ----- */
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 30;
  background: var(--paper); border-radius: 22px 22px 0 0; box-shadow: 0 -8px 30px rgba(27, 42, 34, .22);
  height: calc(var(--sheet-peek) + var(--safe-b)); transition: height .28s cubic-bezier(.2, .8, .2, 1);
  display: flex; flex-direction: column; padding-bottom: var(--safe-b);
}
.sheet.half { height: calc(var(--sheet-half) + var(--safe-b)); }
.sheet.full { height: calc(100dvh - 120px - var(--safe-t)); }
.sheet .handle { flex: none; height: 26px; display: grid; place-items: center; cursor: grab; touch-action: none; }
.sheet .handle::before { content: ""; width: 44px; height: 5px; border-radius: 3px; background: var(--line); }
.sheet .body { flex: 1; overflow: auto; padding: 0 16px 20px; -webkit-overflow-scrolling: touch; }
.sheet.peek .body { overflow: hidden; }

.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 2px 0 8px; }
.section-title h2 { font-family: var(--font-display); font-weight: 600; font-size: 1.1rem; margin: 0; }
.section-title small { color: var(--muted); font-size: .78rem; }

.list { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; list-style: none; }
.item {
  width: 100%; text-align: left; border: 1px solid transparent; border-radius: 12px; padding: 10px 12px;
  background: #fff; cursor: pointer; display: flex; align-items: center; gap: 12px;
}
.item:hover, .item:focus-visible { border-color: var(--line); background: var(--moss-soft); }
.item .dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--moss); box-shadow: 0 0 0 2px #fff, 0 0 0 3px var(--moss); }
.avatar { flex: none; width: 36px; height: 36px; border-radius: 50%; object-fit: cover; background: var(--paper-2); border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); }
.avatar.big { width: 56px; height: 56px; }
.item .name { font-weight: 600; font-size: .95rem; }
.item .meta { color: var(--muted); font-size: .78rem; margin-top: 2px; }
.item .dist { margin-left: auto; flex: none; color: var(--moss); font-weight: 600; font-size: .85rem; font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); padding: 12px 4px; }

/* Selected grave card */
.card-head { display: flex; align-items: flex-start; gap: 12px; }
.card-title { flex: 1; min-width: 0; }
.card .kicker { color: var(--gold); font-size: .72rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.card h2 { font-family: var(--font-display); font-weight: 600; font-size: 1.5rem; margin: 2px 0 6px; line-height: 1.15; }
.card .dates { color: var(--muted); font-size: .88rem; margin-bottom: 8px; }
.card .facts { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 10px; }
.chip { background: var(--paper-2); border-radius: 999px; padding: 4px 10px; font-size: .78rem; color: var(--ink); }
.chip b { color: var(--muted); font-weight: 500; }
.card p { margin: 0 0 12px; line-height: 1.45; font-size: .93rem; }
.card p.muted { color: var(--muted); }
.card figure.photo { margin: 16px 0 0; }
.card figure.photo img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 14px; background: var(--paper-2); }
.card figure.photo figcaption { color: var(--muted); font-size: .76rem; margin-top: 6px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 12px 16px;
  font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; min-height: 46px;
}
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: var(--moss); color: #fff; border-color: var(--moss); flex: 1; justify-content: center; }
.btn.primary:hover { background: var(--moss-2); }
.btn.danger { color: var(--danger); }
.btn.icon { padding: 12px; }

/* Navigation strip inside the card */
.nav {
  display: flex; align-items: center; gap: 14px; background: var(--gold-soft); border: 1px solid #e8d7ad;
  border-radius: 14px; padding: 10px 14px; margin: 0 0 12px;
}
.nav .arrow { flex: none; width: 44px; height: 44px; border-radius: 50%; background: var(--route); color: #fff; display: grid; place-items: center; transition: transform .2s ease; }
.nav .arrow svg { width: 24px; height: 24px; }
.nav .big { font-family: var(--font-display); font-size: 1.6rem; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; }
.nav .small { color: var(--muted); font-size: .78rem; margin-top: 2px; }
.nav.arrived { background: var(--moss-soft); border-color: #bfd5c7; }
.nav.arrived .arrow { background: var(--moss); }

/* User marker */
.you { width: 22px; height: 22px; position: relative; }
.you .cone {
  position: absolute; left: 50%; bottom: 50%; width: 0; height: 0; transform: translateX(-50%);
  border-left: 18px solid transparent; border-right: 18px solid transparent; border-bottom: 46px solid rgba(31, 111, 208, .28);
  display: none;
}
.you.heading .cone { display: block; }
.you .dot {
  position: absolute; inset: 0; border-radius: 50%; background: var(--you);
  border: 3px solid #fff; box-shadow: 0 0 0 2px rgba(31, 111, 208, .35), 0 2px 8px rgba(0, 0, 0, .35);
}

/* Toast */
.toast {
  position: absolute; left: 50%; transform: translateX(-50%); top: calc(72px + var(--safe-t)); z-index: 50;
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: .88rem;
  max-width: calc(100% - 32px); box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity .2s;
}
.toast.show { opacity: 1; }

/* Fatal error panel */
.fatal { position: absolute; inset: 0; z-index: 100; display: none; place-items: center; background: var(--paper-2); padding: 24px; text-align: center; }
.fatal.show { display: grid; }
.fatal div { max-width: 420px; }
.fatal h2 { font-family: var(--font-display); }

.maplibregl-ctrl-attrib { font-size: 10px; }
.maplibregl-ctrl-bottom-right { bottom: calc(var(--sheet-peek) + var(--safe-b)); transition: bottom .25s; }
.sheet.half ~ .maplibregl-ctrl-bottom-right { display: none; }

/* ----- Desktop: side panel layout ----- */
@media (min-width: 900px) {
  :root { --sheet-peek: 0px; }
  .app { display: grid; grid-template-columns: 380px 1fr; }
  #map { position: relative; grid-column: 2; }
  .topbar { left: 392px; right: 12px; justify-content: flex-end; }
  .brand, #btnSearch, .search .back { display: none !important; }
  .search { display: flex; flex: 0 1 360px; padding-left: 12px; }
  .search::before { content: ""; width: 18px; height: 18px; flex: none; margin-right: 6px; background: currentColor; color: var(--muted);
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='11' cy='11' r='7' fill='none' stroke='black' stroke-width='2'/%3E%3Cpath d='M16.5 16.5 21 21' stroke='black' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E") center / contain no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='11' cy='11' r='7' fill='none' stroke='black' stroke-width='2'/%3E%3Cpath d='M16.5 16.5 21 21' stroke='black' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E") center / contain no-repeat; }
  .sheet {
    position: relative; grid-column: 1; grid-row: 1; height: auto !important; border-radius: 0;
    box-shadow: none; border-right: 1px solid var(--line); transition: none;
  }
  .sheet .handle { display: none; }
  .sheet .body { padding: 20px 20px 24px; overflow: auto !important; }
  .desk-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
  .desk-brand .mark { width: 40px; height: auto; border-radius: 8px; border: 1px solid var(--line); }
  .desk-brand h1 { font-family: var(--font-display); font-weight: 600; font-size: 1.7rem; margin: 0; }
  .desk-brand p { margin: 2px 0 0; color: var(--muted); font-size: .85rem; }
  .fabs { bottom: 24px !important; display: flex !important; }
  .maplibregl-ctrl-bottom-right { bottom: 0; }
  .toast { left: calc(380px + (100% - 380px) / 2); }
}
@media (max-width: 899px) { .desk-brand { display: none; } }
