:root {
  --ink: #1d2b2a;
  --muted: #5d6b69;
  --paper: #f7f2ea;
  --card: rgba(253, 250, 245, 0.88);
  --line: rgba(29, 43, 42, 0.12);
  --accent: #f0532b;
  --accent-2: #ffae5c;
  --forest: #1f3a34;
  --slate: #21495c;
  --radius: 18px;
  --shadow: 0 10px 30px rgba(20, 30, 28, 0.18), 0 2px 6px rgba(20, 30, 28, 0.08);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.45 var(--sans); color: var(--ink); background: var(--paper); -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--slate); }

/* ------------------------------------------------------------------ public page */
body.public { overflow: hidden; }
#map {
  position: fixed; inset: 0;
  background: radial-gradient(ellipse at 50% 40%, #24364a 0%, #101a26 55%, #070b11 100%);
}

.card {
  background: var(--card);
  backdrop-filter: blur(14px) saturate(1.3);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.hero {
  position: fixed; z-index: 3; top: 18px; left: 18px; width: 360px;
  padding: 20px 22px 18px;
}
.eyebrow { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--accent); font-weight: 700; }
.hero h1 { font: 600 30px/1.1 var(--serif); margin: 6px 0 4px; color: var(--forest); letter-spacing: -0.01em; }
.hero .sub { margin: 0 0 16px; color: var(--muted); font-size: 14px; }

.progress .bar {
  position: relative; height: 10px; border-radius: 99px;
  background: repeating-linear-gradient(90deg, rgba(33,73,92,.16) 0 6px, rgba(33,73,92,.08) 6px 10px);
  overflow: visible;
}
.progress .bar > span {
  position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 99px;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  box-shadow: 0 0 12px rgba(240, 83, 43, 0.45);
  transition: width 1.4s cubic-bezier(.2,.8,.2,1);
}
.progress .bar > i {
  position: absolute; top: 50%; left: 0; width: 18px; height: 18px; margin: -9px 0 0 -9px;
  border-radius: 50%; background: #fff; border: 4px solid var(--accent);
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
  transition: left 1.4s cubic-bezier(.2,.8,.2,1);
}
.progress .ends { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 6px; letter-spacing: .02em; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0 10px; }
.stats div { background: rgba(255,255,255,.6); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; }
.stats b { display: block; font: 600 24px/1.1 var(--serif); color: var(--forest); font-variant-numeric: tabular-nums; }
.stats small { color: var(--muted); font-size: 11.5px; }

.now { margin: 10px 0 2px; font-size: 14.5px; }
.now b { color: var(--forest); }
.meta, .you { margin: 2px 0; color: var(--muted); font-size: 13px; }

.actions { display: flex; gap: 8px; margin-top: 14px; }
.actions button {
  flex: 1; border: 1px solid var(--line); background: rgba(255,255,255,.75); border-radius: 12px;
  padding: 9px 10px; font-weight: 600; font-size: 13.5px;
  transition: transform .15s, box-shadow .15s, background .15s;
}
.actions button:hover { transform: translateY(-1px); box-shadow: 0 4px 10px rgba(0,0,0,.08); }
.actions .primary { background: var(--forest); color: #fff; border-color: var(--forest); }

/* journal */
.journal {
  position: fixed; z-index: 3; top: 18px; right: 18px; bottom: 18px; width: 360px;
  display: flex; flex-direction: column; padding: 18px 0 0;
}
.journal h2 { font: 600 20px/1.2 var(--serif); margin: 0 20px 10px; color: var(--forest); }
.journal h2 small { font: 600 12px var(--sans); color: #fff; background: var(--accent); border-radius: 99px; padding: 2px 8px; vertical-align: 3px; margin-left: 4px; }
.journal h2 small:empty { display: none; }
.journal .handle { display: none; }
.entries { list-style: none; margin: 0; padding: 0 12px 12px; overflow-y: auto; flex: 1; overscroll-behavior: contain; }
.entries li {
  padding: 12px 10px; border-radius: 14px; cursor: pointer; border: 1px solid transparent;
  transition: background .15s, border-color .15s;
}
.entries li + li { border-top-color: var(--line); border-radius: 0; }
.entries li:hover, .entries li:focus-visible { background: rgba(255,255,255,.7); border-radius: 14px; outline: none; }
.entries li.active { background: #fff; border-color: rgba(240,83,43,.35); border-radius: 14px; }
.empty { margin: 0 20px 16px; color: var(--muted); }
.credits { font-size: 11.5px; color: var(--muted); padding: 10px 20px 14px; border-top: 1px solid var(--line); }

.update .when { font-size: 12px; color: var(--muted); font-weight: 600; letter-spacing: .01em; }
.update .when .ago { font-weight: 400; }
.update .where { font-size: 12.5px; color: var(--slate); margin-top: 2px; }
.update .where::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-right: 6px; vertical-align: 1px; }
.update .note { margin: 8px 0 0; white-space: pre-line; overflow-wrap: anywhere; }
.photos { display: grid; gap: 4px; margin-top: 10px; grid-template-columns: repeat(2, 1fr); border-radius: 12px; overflow: hidden; }
.photos.n1 { grid-template-columns: 1fr; }
.photos .ph { padding: 0; border: 0; background: #ddd; display: block; aspect-ratio: 4 / 3; overflow: hidden; }
.photos.n1 .ph { aspect-ratio: 3 / 2; }
.photos img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .4s; }
.photos .ph:hover img { transform: scale(1.04); }

/* layer switch */
.layers {
  position: fixed; z-index: 3; left: 50%; transform: translateX(-50%); bottom: 18px;
  display: flex; gap: 2px; padding: 4px; border-radius: 99px;
}
.layers button { border: 0; background: transparent; padding: 7px 14px; border-radius: 99px; font-size: 13px; font-weight: 600; color: var(--muted); }
.layers button.on { background: var(--forest); color: #fff; }
.layers #b-3d { margin-left: 4px; border-left: 1px solid var(--line); border-radius: 0 99px 99px 0; }
.layers #b-3d.on { border-radius: 99px; }

/* intro caption */
.intro {
  position: fixed; z-index: 4; left: 50%; top: 50%; transform: translate(-50%, -50%);
  pointer-events: none; text-align: center;
  font: italic 500 26px/1.3 var(--serif); color: #fff; text-shadow: 0 2px 18px rgba(0,0,0,.6);
  animation: introIn 1.2s ease-out both;
}
.intro.done { animation: introOut 1s ease-in forwards; }
@keyframes introIn { from { opacity: 0; transform: translate(-50%, -40%); } to { opacity: 1; transform: translate(-50%, -50%); } }
@keyframes introOut { to { opacity: 0; transform: translate(-50%, -60%); } }

/* map markers */
/* note: never set `position` on marker roots - MapLibre positions them absolutely */
.here { width: 22px; height: 22px; cursor: pointer; }
.here .dot { position: absolute; inset: 3px; border-radius: 50%; background: var(--accent); border: 3px solid #fff; box-shadow: 0 2px 8px rgba(0,0,0,.35); }
.here .pulse { position: absolute; inset: -14px; border-radius: 50%; background: rgba(240, 83, 43, .35); animation: pulse 2.2s ease-out infinite; }
.here .tag {
  position: absolute; left: 50%; bottom: 26px; transform: translateX(-50%); white-space: nowrap;
  background: var(--forest); color: #fff; font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 99px;
  box-shadow: 0 4px 12px rgba(0,0,0,.25);
}
.here .tag::after { content: ""; position: absolute; left: 50%; bottom: -4px; margin-left: -5px; border: 5px solid transparent; border-bottom: 0; border-top-color: var(--forest); }
@keyframes pulse { 0% { transform: scale(.35); opacity: 1; } 100% { transform: scale(1.4); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .here .pulse { animation: none; opacity: .4; } .intro { display: none; } }

.endpin {
  background: #fff; border-radius: 10px; padding: 4px 9px 5px; box-shadow: 0 3px 10px rgba(0,0,0,.2);
  font-size: 12px; line-height: 1.15; text-align: center; border-top: 3px solid var(--slate);
}
.endpin.finish { border-top-color: var(--accent); }
.endpin b { display: block; font-family: var(--serif); font-size: 14px; color: var(--forest); }
.endpin small { color: var(--muted); font-size: 10.5px; white-space: nowrap; }
.endpin::after { content: ""; position: absolute; left: 50%; bottom: -6px; margin-left: -6px; border: 6px solid transparent; border-bottom: 0; border-top-color: #fff; }

/* popups */
.maplibregl-popup-content { border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow); font: 14px/1.4 var(--sans); }
.update-popup .maplibregl-popup-content { padding: 12px 14px 14px; max-height: 60vh; overflow-y: auto; }
.update-popup .photos { margin-right: 0; }
.maplibregl-popup-close-button { font-size: 20px; width: 28px; height: 28px; border-radius: 0 14px 0 8px; }
.section-popup b { font-family: var(--serif); font-size: 15px; color: var(--forest); }
.maplibregl-ctrl-bottom-right { bottom: 8px; right: 390px; }
.maplibregl-ctrl-attrib { font-size: 11px; }

/* lightbox */
.lightbox { position: fixed; inset: 0; z-index: 10; background: rgba(8, 12, 14, .92); display: flex; align-items: center; justify-content: center; }
.lightbox[hidden] { display: none; }
.lightbox figure { margin: 0; max-width: 94vw; max-height: 90vh; display: flex; flex-direction: column; align-items: center; }
.lightbox img { max-width: 94vw; max-height: 84vh; object-fit: contain; border-radius: 6px; box-shadow: 0 10px 40px rgba(0,0,0,.5); }
.lightbox figcaption { color: #e7e2da; margin-top: 10px; font-size: 13px; }
.lightbox button { position: absolute; background: rgba(255,255,255,.12); color: #fff; border: 0; border-radius: 50%; width: 46px; height: 46px; font-size: 28px; line-height: 1; }
.lightbox button:hover { background: rgba(255,255,255,.25); }
.lb-close { top: 16px; right: 16px; }
.lb-prev { left: 16px; top: 50%; margin-top: -23px; }
.lb-next { right: 16px; top: 50%; margin-top: -23px; }

/* ------------------------------------------------------------------ mobile */
@media (max-width: 760px) {
  .hero { top: max(10px, env(safe-area-inset-top)); left: 10px; right: 10px; width: auto; padding: 14px 16px 12px; }
  .hero h1 { font-size: 22px; margin: 2px 0 8px; }
  .hero .sub, .hero .actions, .you, .hero .eyebrow { display: none; }
  .endpin { padding: 3px 7px 4px; }
  .endpin small { display: none; }
  .endpin b { font-size: 12.5px; }
  .stats { margin: 10px 0 4px; }
  .stats b { font-size: 19px; }
  .stats div { padding: 6px 8px; }
  .now { font-size: 13.5px; margin-top: 6px; }

  .journal {
    top: auto; left: 0; right: 0; bottom: 0; width: auto; height: 34vh; border-radius: 22px 22px 0 0;
    padding-top: 6px; transition: height .3s cubic-bezier(.2,.8,.2,1);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .journal.open { height: 82vh; }
  .journal .handle { display: block; border: 0; background: none; padding: 6px 0 10px; width: 100%; }
  .journal .handle span { display: block; margin: 0 auto; width: 44px; height: 5px; border-radius: 9px; background: rgba(29,43,42,.25); }
  .journal h2 { font-size: 17px; margin-bottom: 4px; }
  .layers { bottom: auto; top: auto; left: 10px; transform: none; bottom: calc(34vh + 10px); }
  .layers button { padding: 6px 10px; font-size: 12px; }
  .maplibregl-ctrl-bottom-right { right: 0; bottom: calc(34vh + 4px); }
  .maplibregl-ctrl-scale { display: none; }
  .intro { font-size: 19px; width: 90vw; }
}

/* ================================================================== posting page */
body.poster { background: var(--paper); }
.poster main { max-width: 560px; margin: 0 auto; padding: max(16px, env(safe-area-inset-top)) 14px 40px; }
.poster header h1 { font: 600 24px/1.15 var(--serif); color: var(--forest); margin: 4px 0 2px; }
.poster header p { margin: 0 0 14px; color: var(--muted); font-size: 14px; }
.poster .panel { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; box-shadow: 0 2px 10px rgba(0,0,0,.04); }
.poster label.lbl { display: block; font-weight: 700; font-size: 13px; letter-spacing: .02em; color: var(--forest); margin: 0 0 6px; }
#pmap { height: 260px; border-radius: 12px; overflow: hidden; background: #e8e2d6; }
.locbar { display: flex; gap: 8px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.locbar .status { flex: 1 1 100%; font-size: 13px; color: var(--muted); }
.locbar .status b { color: var(--ink); }
.btn { border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 11px 14px; font-weight: 700; font-size: 15px; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); width: 100%; padding: 15px; font-size: 17px; box-shadow: 0 6px 16px rgba(240,83,43,.35); }
.btn.primary:disabled { opacity: .55; box-shadow: none; }
.btn.small { padding: 7px 10px; font-size: 13px; }
.btn.danger { color: #b3261e; }
textarea, input[type=datetime-local] { width: 100%; font: 16px/1.4 var(--sans); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: #fffdf9; color: var(--ink); }
textarea { min-height: 110px; resize: vertical; }
.thumbs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 10px; }
.thumbs:empty { display: none; }
.thumbs div { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: #eee; }
.thumbs img { width: 100%; height: 100%; object-fit: cover; }
.thumbs button { position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; font-size: 15px; line-height: 1; padding: 0; }
.filebtn { display: inline-flex; align-items: center; gap: 8px; }
.filebtn input { display: none; }
.sendbar { padding: 2px 0 18px; }
details.when summary { cursor: pointer; list-style: none; margin: 0; }
details.when summary::-webkit-details-marker { display: none; }
details.when summary::after { content: " ›"; color: var(--muted); }
details.when[open] summary { margin-bottom: 8px; }
details.when #when-label { font-weight: 400; color: var(--muted); }
.uprog { height: 6px; border-radius: 9px; background: rgba(0,0,0,.08); overflow: hidden; margin-top: 8px; }
.uprog[hidden] { display: none; }
.uprog span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.msg { margin: 10px 0 0; padding: 10px 12px; border-radius: 12px; font-size: 14px; }
.msg[hidden] { display: none; }
.msg.ok { background: #e6f4ea; color: #1e5631; }
.msg.err { background: #fde8e6; color: #8c1d18; }
.msg.wait { background: #fff4e0; color: #7a4b00; }
.outbox { font-size: 13px; color: #7a4b00; }
.mine { list-style: none; padding: 0; margin: 0; }
.mine li { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--line); }
.mine li:first-child { border-top: 0; }
.mine li > div { flex: 1; min-width: 0; }
.mine .t { font-size: 12px; color: var(--muted); }
.mine .w { font-size: 12.5px; color: var(--slate); }
.mine .n { font-size: 14px; white-space: pre-line; overflow-wrap: anywhere; margin-top: 2px; }
.mine img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; }
.poster .stats { margin: 0; }
.poster .stats div { background: var(--paper); }
.hint { font-size: 12.5px; color: var(--muted); margin: 6px 0 0; }
