/* ============ Theme tokens ============ */
/* Dark is the default (:root). Light overrides live in [data-theme="light"]. */
:root {
  --bg: #14130f;
  --surface: #1f1c17;
  --ink: #f1ede6;
  --muted: #9c9488;
  --faint: #6f685e;
  --line: #332f28;

  --amber: #f2a638;
  --amber-soft: #f6b24a;
  --amber-glow: rgba(242, 166, 56, 0.35);

  --echo: #34c3b4;                       /* echo ripples — cool teal ping */
  --echo-glow: rgba(52, 195, 180, 0.40);

  --glass: rgba(28, 25, 20, 0.80);       /* frosted pills */
  --field-bg: #26221c;
  --ghost-bg: #2c2820;
  --chip-bg: #24201a;
  --chip-active-bg: rgba(242, 166, 56, 0.16);
  --switch-off: #3a352d;
  --disabled-bg: #2c2820;
  --disabled-fg: #6f685e;
  --toast-bg: #f1ede6;
  --toast-fg: #1a1712;
  --marker-ring: #f4f1ea;
  --backdrop: rgba(0, 0, 0, 0.5);
  --attr-bg: rgba(20, 19, 15, 0.7);
  --on-accent: #fff;

  --shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  --shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.4);

  --radius: 20px;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

:root[data-theme="light"] {
  --bg: #faf9f7;
  --surface: #ffffff;
  --ink: #211d18;
  --muted: #8a8178;
  --faint: #b7afa4;
  --line: #ece8e2;

  --amber: #e8880c;
  --amber-soft: #f6b24a;
  --amber-glow: rgba(232, 136, 12, 0.28);

  --echo: #0f9b8e;
  --echo-glow: rgba(15, 155, 142, 0.30);

  --glass: rgba(255, 255, 255, 0.82);
  --field-bg: #fdfcfa;
  --ghost-bg: #f3efe9;
  --chip-bg: #fdfcfa;
  --chip-active-bg: #fff7ec;
  --switch-off: #e2dbd0;
  --disabled-bg: #e8ded2;
  --disabled-fg: #b3a795;
  --toast-bg: #211d18;
  --toast-fg: #ffffff;
  --marker-ring: #ffffff;
  --backdrop: rgba(30, 22, 10, 0.28);
  --attr-bg: rgba(255, 255, 255, 0.7);
  --on-accent: #fff;

  --shadow: 0 10px 40px rgba(40, 30, 15, 0.14);
  --shadow-soft: 0 4px 20px rgba(40, 30, 15, 0.10);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  overscroll-behavior: none;
}

/* ---- Map ---- */
#map {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: var(--bg);
}
.leaflet-container { font-family: var(--sans); background: var(--bg); }
.leaflet-control-attribution {
  background: var(--attr-bg) !important;
  color: var(--muted) !important;
  font-size: 10px;
  backdrop-filter: blur(4px);
}
.leaflet-control-attribution a { color: var(--muted) !important; }
.leaflet-control-zoom { display: none; }

/* ---- Top bar ---- */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  pointer-events: none;
}
.brand {
  display: flex; align-items: center; gap: 8px;
  background: var(--glass);
  backdrop-filter: blur(10px);
  padding: 8px 14px;
  border-radius: 999px;
  box-shadow: var(--shadow-soft);
  pointer-events: auto;
}
.brand-name { font-weight: 650; letter-spacing: 0.2px; font-size: 16px; }
.brand-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 4px var(--amber-glow);
}
.status-pill {
  pointer-events: auto;
  border: none;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--muted);
  background: var(--glass);
  backdrop-filter: blur(10px);
  padding: 8px 12px;
  border-radius: 999px;
  box-shadow: var(--shadow-soft);
}
.status-pill.ok { color: var(--amber); }
.status-pill.err { color: #e0685c; }

/* ---- Hint banner ---- */
.hint {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 60px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 480;
  background: var(--glass);
  backdrop-filter: blur(10px);
  color: var(--ink);
  font-size: 13px;
  padding: 9px 16px;
  border-radius: 999px;
  box-shadow: var(--shadow-soft);
  white-space: nowrap;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.hint b { color: var(--amber); }

/* ---- Geolocation status / diagnostic banner ---- */
.geo-banner {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 60px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 490;
  width: min(92vw, 380px);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--glass);
  backdrop-filter: blur(10px);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.35;
  padding: 12px 14px;
  border-radius: 16px;
  box-shadow: var(--shadow-soft);
}
.geo-text { flex: 1; }
.geo-text b { color: var(--amber); font-weight: 650; }
.geo-retry {
  flex: none;
  border: none;
  cursor: pointer;
  background: var(--amber);
  color: var(--on-accent);
  font-family: var(--sans);
  font-weight: 600;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 999px;
}
.geo-retry:active { transform: scale(0.96); }
.geo-spinner {
  display: none;
  flex: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 2px solid var(--line);
  border-top-color: var(--amber);
  animation: spin 0.8s linear infinite;
}
.geo-banner.busy .geo-spinner { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Round + FAB buttons ---- */
.round-btn {
  position: fixed;
  z-index: 500;
  width: 46px; height: 46px;
  border-radius: 50%;
  border: none;
  background: var(--glass);
  color: var(--ink);
  box-shadow: var(--shadow-soft);
  display: grid; place-items: center;
  backdrop-filter: blur(10px);
  cursor: pointer;
}
.round-btn:active { transform: scale(0.94); }
.recenter { right: 16px; bottom: calc(env(safe-area-inset-bottom) + 96px); }

.fab {
  position: fixed;
  z-index: 500;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 22px);
  display: flex; align-items: center; gap: 8px;
  padding: 14px 22px 14px 18px;
  border: none;
  border-radius: 999px;
  background: var(--amber);
  color: var(--on-accent);
  font-family: var(--sans);
  font-size: 15px;
  font-weight: 600;
  box-shadow: 0 8px 28px var(--amber-glow), 0 2px 6px rgba(0,0,0,0.2);
  cursor: pointer;
}
.fab:active { transform: translateX(-50%) scale(0.96); }

/* ---- Settings button ---- */
.settings { left: 16px; bottom: calc(env(safe-area-inset-bottom) + 96px); }

/* ---- Settings sheet ---- */
.setting-row { padding: 16px 0; border-bottom: 1px solid var(--line); }
.setting-row:last-of-type { border-bottom: none; margin-bottom: 4px; }
.setting-row > label {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 14px; color: var(--ink); margin-bottom: 10px;
}
.setting-row input[type="range"] { width: 100%; accent-color: var(--amber); }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.setting-name { font-size: 15px; font-weight: 600; }
.setting-desc { font-size: 12.5px; color: var(--muted); margin-top: 3px; line-height: 1.4; }
.switch {
  width: 48px; height: 29px; flex: none;
  border: none; border-radius: 999px;
  background: var(--switch-off);
  position: relative; cursor: pointer; padding: 0;
  transition: background 0.2s ease;
}
.switch[aria-checked="true"] { background: var(--amber); }
.switch .knob {
  position: absolute; top: 3px; left: 3px;
  width: 23px; height: 23px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s ease;
}
.switch[aria-checked="true"] .knob { transform: translateX(19px); }

/* ---- Compose: location source chips ---- */
.loc-source { display: flex; gap: 8px; margin-top: 14px; }
.chip {
  flex: 1;
  border: 1.5px solid var(--line);
  background: var(--chip-bg);
  border-radius: 12px;
  padding: 11px;
  font-family: var(--sans);
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
}
.chip.active { border-color: var(--amber-soft); color: var(--ink); background: var(--chip-active-bg); font-weight: 600; }
.chip:active { transform: scale(0.98); }

/* ---- Pin placement pushpin ---- */
/* The element sits at the map centre; the pin's needle tip (bottom-centre of
   the SVG) lands there, so -100% on Y puts the tip on the exact point. */
.crosshair {
  position: fixed;
  left: 50%; top: 50%;
  z-index: 600;
  transform: translate(-50%, -100%);
  pointer-events: none;
  color: var(--amber);
  filter: drop-shadow(0 3px 3px rgba(0, 0, 0, 0.35));
}
/* A small dot on the "board" marking exactly where the needle bites. */
.crosshair::after {
  content: "";
  position: absolute;
  left: 50%; bottom: -2px;
  width: 7px; height: 7px; margin-left: -3.5px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.75);
}
.place-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 650;
  background: var(--surface);
  border-radius: 24px 24px 0 0;
  padding: 16px 22px calc(env(safe-area-inset-bottom) + 18px);
  box-shadow: var(--shadow);
  max-width: 560px;
  margin: 0 auto;
}
.place-hint { display: block; text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 12px; }
.place-actions { display: flex; gap: 10px; }

/* ---- Markers (Leaflet divIcons) ---- */
/* Your location: amber dot with an amber pulse. */
.me-marker {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--amber);
  border: 3px solid var(--marker-ring);
  box-shadow: 0 0 0 2px var(--amber-glow), 0 1px 5px rgba(0, 0, 0, 0.35);
}
.me-marker::after {
  content: "";
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  background: var(--amber);
  opacity: 0.35;
  animation: pulse 2.4s ease-out infinite;
}
/* Echoes: teal dot with the same pulse, in a different colour. */
.echo-marker {
  position: relative;
  width: 30px; height: 30px;
  display: grid; place-items: center;
}
.echo-marker::after {
  content: "";
  position: absolute;
  left: 50%; top: 50%;
  width: 18px; height: 18px; margin: -9px 0 0 -9px;
  border-radius: 50%;
  background: var(--echo);
  opacity: 0.4;
  animation: pulse 2.4s ease-out infinite;
  animation-delay: var(--d, 0s);
}
.echo-marker .dot {
  position: relative;
  z-index: 2;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--echo);
  border: 2.5px solid var(--marker-ring);
  box-shadow: 0 0 0 2px var(--echo-glow), 0 1px 4px rgba(0, 0, 0, 0.35);
  transition: transform 0.15s ease;
}
.echo-marker:active .dot { transform: scale(0.85); }
@keyframes pulse {
  0% { transform: scale(0.5); opacity: 0.45; }
  100% { transform: scale(2.4); opacity: 0; }
}

/* ---- Sheets ---- */
.backdrop {
  position: fixed; inset: 0; z-index: 700;
  background: var(--backdrop);
  backdrop-filter: blur(2px);
  transition: opacity 0.25s ease;
}
.sheet {
  position: fixed;
  z-index: 800;
  left: 0; right: 0; bottom: 0;
  background: var(--surface);
  border-radius: 24px 24px 0 0;
  padding: 10px 22px calc(env(safe-area-inset-bottom) + 24px);
  box-shadow: var(--shadow);
  transform: translateY(0);
  transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
  max-width: 560px;
  margin: 0 auto;
}
.sheet.hidden { transform: translateY(110%); }
.backdrop.hidden { opacity: 0; pointer-events: none; }
.sheet-handle {
  width: 40px; height: 4px; border-radius: 2px;
  background: var(--line);
  margin: 6px auto 16px;
}
.reveal-text {
  font-size: 21px;
  line-height: 1.5;
  font-weight: 450;
  margin: 4px 0 18px;
  white-space: pre-wrap;
  word-break: break-word;
}
.reveal-meta {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.reveal-author { font-weight: 600; font-size: 15px; }
.reveal-meta .mono { color: var(--muted); font-size: 12px; }
.sheet-close { width: 100%; margin-top: 20px; }

.sheet-title { font-size: 20px; font-weight: 650; margin: 0 0 4px; }
.sheet-sub { color: var(--muted); font-size: 13.5px; margin: 0 0 16px; }
.field {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  padding: 13px 14px;
  font-family: var(--sans);
  font-size: 16px;
  color: var(--ink);
  background: var(--field-bg);
  outline: none;
  transition: border-color 0.15s ease;
}
.field::placeholder { color: var(--faint); }
.field:focus { border-color: var(--amber-soft); }
.textarea { resize: none; line-height: 1.45; }
.row-between {
  display: flex; align-items: center; gap: 12px;
  margin-top: 12px;
}
.nick { flex: 1; }
.char-count { color: var(--muted); font-size: 12px; flex: none; }
.compose-loc {
  color: var(--muted);
  font-size: 12px;
  margin: 14px 2px 0;
  display: flex; align-items: center; gap: 6px;
}
.compose-loc.ready { color: var(--amber); }
.sheet-actions {
  display: flex; gap: 10px; margin-top: 20px;
}
.btn {
  flex: 1;
  border: none;
  border-radius: 14px;
  padding: 15px;
  font-family: var(--sans);
  font-size: 15.5px;
  font-weight: 600;
  cursor: pointer;
}
.btn.primary { background: var(--amber); color: var(--on-accent); }
.btn.primary:disabled { background: var(--disabled-bg); color: var(--disabled-fg); cursor: not-allowed; }
.btn.ghost { background: var(--ghost-bg); color: var(--ink); }
.btn.danger { background: #b64545; color: #fff; }
.btn.danger:disabled { background: var(--disabled-bg); color: var(--disabled-fg); cursor: not-allowed; }
.btn:active:not(:disabled) { transform: scale(0.98); }

/* ---- Toast ---- */
.toast {
  position: fixed;
  z-index: 900;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 100px);
  transform: translateX(-50%) translateY(10px);
  background: var(--toast-bg);
  color: var(--toast-fg);
  font-size: 14px;
  padding: 12px 20px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.hidden { display: none; }
