/* Happy Path. Map-first layout inspired by Corner: full-screen map, a floating
   rounded panel (bottom sheet on phones), emoji pins and chips, soft shadows. */
:root {
  --bg: #fbf8f3; --panel: #ffffffee; --card: #ffffff; --fg: #1d1d1f; --muted: #7a7670; --line: #ece6dc;
  --chip: #f3eee6; --chip-on: #1d1d1f; --chip-on-fg: #ffffff; --accent: #1f9d5c; --accent-soft: #e3f4ea;
  --shadow: 0 8px 30px rgba(40, 30, 10, .14); --radius: 20px;
  --font: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161514; --panel: #1f1e1cee; --card: #262523; --fg: #f2efe9; --muted: #a39d94; --line: #34322e;
    --chip: #2e2c29; --chip-on: #f2efe9; --chip-on-fg: #161514; --accent: #4cc68a; --accent-soft: #1d3a2b;
    --shadow: 0 8px 30px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--fg);
  font: 15px/1.4 var(--font); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; }

#map { position: fixed; inset: 0; }

/* ---- Panel: floating on desktop, bottom sheet on phones ---- */
#panel {
  position: fixed; top: 16px; left: 16px; bottom: 16px; width: 392px; z-index: 2;
  overflow-y: auto; overscroll-behavior: contain; padding: 18px 16px 20px;
  background: var(--panel); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border-radius: 28px; box-shadow: var(--shadow);
}
#handle { display: none; }
.brand { display: flex; align-items: center; gap: 10px; margin: 0 4px 14px; }
.brand .logo { font-size: 26px; width: 44px; height: 44px; display: grid; place-items: center;
  background: var(--accent-soft); border-radius: 14px; }
.brand h1 { font-size: 20px; margin: 0; letter-spacing: -.01em; }
.brand p { margin: 0; color: var(--muted); font-size: 13px; }

section { margin: 16px 0 0; }
h2 { font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 4px 8px; letter-spacing: .01em; }
.hint { color: var(--muted); margin: 0 4px 8px; font-size: 13px; }
.hint a { color: var(--accent); }
.card { background: var(--card); border-radius: var(--radius); padding: 10px; box-shadow: 0 1px 0 var(--line), 0 2px 10px rgba(40, 30, 10, .05); }

/* ---- Search fields ---- */
.field { position: relative; display: flex; align-items: center; gap: 8px; padding: 2px 0; }
.field input { flex: 1; min-width: 0; font-size: 16px; padding: 9px 12px; border: 0; border-radius: 12px;
  background: var(--chip); color: var(--fg); }
.field input:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
.dot { flex: none; width: 26px; height: 26px; border-radius: 50%; color: #fff; font-weight: 700; font-size: 13px;
  display: grid; place-items: center; }
.dot.a { background: #1f9d5c; } .dot.b { background: #e5484d; }
.dot.stop { background: var(--chip); color: var(--muted); font-weight: 600; }
.icon { flex: none; width: 38px; height: 38px; border: 0; border-radius: 12px; background: var(--chip); }
.field.add input { background: transparent; }
.field.add input:focus { background: var(--chip); }
.suggest { position: absolute; top: 100%; left: 34px; right: 0; z-index: 10; list-style: none; margin: 4px 0 0; padding: 6px;
  background: var(--card); border-radius: 16px; box-shadow: var(--shadow); }
.suggest li { padding: 8px 10px; border-radius: 10px; cursor: pointer; display: flex; flex-direction: column; }
.suggest li:hover { background: var(--chip); }
.suggest li.none { color: var(--muted); cursor: default; }
.suggest small { color: var(--muted); }

.stop-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.stop-row .dot { background: var(--accent-soft); font-size: 14px; }
.stop-row span.name { flex: 1; min-width: 0; padding: 0 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stop-row button { border: 0; background: none; color: var(--muted); font-size: 15px; padding: 4px 8px; }

/* ---- Chips ---- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px 2px; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 0; border-radius: 999px; padding: 7px 13px; background: var(--chip); font-size: 14px; white-space: nowrap; }
.chip.on { background: var(--chip-on); color: var(--chip-on-fg); }

/* ---- Places along the way ---- */
#categoryResults:not(:empty) { margin-top: 8px; }
.place { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 14px; }
.place:hover { background: var(--chip); }
.place .em { font-size: 20px; }
.place div { flex: 1; min-width: 0; }
.place b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.place small { color: var(--muted); }
.place button { border: 0; border-radius: 999px; padding: 6px 12px; background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* ---- Status + route cards ---- */
#status { color: var(--muted); min-height: 1.4em; margin: 14px 4px 6px; font-size: 14px; }
.route { display: flex; gap: 12px; align-items: center; padding: 12px; margin-bottom: 8px; border-radius: 18px;
  background: var(--card); border: 2px solid transparent; cursor: pointer; box-shadow: 0 1px 0 var(--line); }
.route.on { border-color: var(--c); }
.route .em { font-size: 22px; width: 40px; height: 40px; border-radius: 14px; display: grid; place-items: center; background: var(--chip); }
.route .body { flex: 1; min-width: 0; }
.route .title { display: flex; justify-content: space-between; font-weight: 600; }
.route .title small { color: var(--muted); font-weight: 500; }
.route .meta { color: var(--muted); font-size: 13px; }
.bar { height: 5px; background: var(--chip); border-radius: 3px; margin-top: 6px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--c, var(--accent)); border-radius: 3px; }
.note { color: var(--muted); font-size: 13px; margin: 0 4px 8px; }

/* ---- Actions, rating ---- */
.rating { display: flex; gap: 6px; margin-bottom: 10px; }
.rating button { flex: 1; border: 0; border-radius: 14px; padding: 8px 4px; background: var(--chip); display: flex;
  flex-direction: column; align-items: center; font-size: 20px; line-height: 1.1; }
.rating button small { font-size: 11px; color: var(--muted); margin-top: 2px; }
.rating button.on { background: var(--chip-on); color: var(--chip-on-fg); }
.rating button.on small { color: inherit; opacity: .8; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }
.actions button, .row button { border: 0; border-radius: 999px; padding: 8px 14px; background: var(--chip); }
button.primary { background: var(--accent); color: #fff; font-weight: 600; }
#routePhotos:not(:empty) { margin-top: 10px; }
.thumbs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.thumbs img { flex: none; width: 64px; height: 64px; object-fit: cover; border-radius: 12px; cursor: pointer; }

/* ---- Saved walks ---- */
#savedFilter:not(:empty) { margin-bottom: 6px; }
.saved { display: flex; align-items: center; gap: 10px; padding: 9px 8px; border-radius: 14px; cursor: pointer; }
.saved:hover { background: var(--chip); }
.saved .em { font-size: 20px; width: 34px; text-align: center; }
.saved div { flex: 1; min-width: 0; }
.saved b { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.saved small { color: var(--muted); }
.saved button { border: 0; background: none; color: var(--muted); padding: 4px 8px; }
.empty { color: var(--muted); margin: 4px; font-size: 14px; }

/* ---- Map pins ---- */
.pin { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 14px;
  color: #fff; border: 3px solid #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, .3); }
.pin.a { background: #1f9d5c; } .pin.b { background: #e5484d; }
.pin.stop { background: #fff; font-size: 17px; }
.pin.place { width: 30px; height: 30px; background: #fff; font-size: 16px; border-width: 2px; opacity: .92; cursor: pointer; }
.pin.place:hover { transform: scale(1.15); opacity: 1; }
.photo-pin { width: 40px; height: 40px; border-radius: 12px; border: 3px solid #fff; padding: 0; background: #ddd center / cover;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .35); transform: rotate(-4deg); }
.photo-pin:hover { transform: rotate(0) scale(1.15); }
.photo-hover .maplibregl-popup-content { border-radius: 16px; padding: 8px; box-shadow: var(--shadow); background: var(--card); color: var(--fg); }
.photo-hover .maplibregl-popup-tip { display: none; }
.hover-strip { display: flex; gap: 4px; }
.hover-strip img { width: 84px; height: 84px; object-fit: cover; border-radius: 10px; }
.photo-hover small { display: block; margin-top: 4px; color: var(--muted); }

/* ---- Modals ---- */
.modal { position: fixed; inset: 0; z-index: 10; background: rgba(20, 15, 5, .45); display: grid; place-items: center; padding: 16px; }
.modal .sheet { width: min(420px, 100%); background: var(--card); border-radius: 24px; padding: 16px; box-shadow: var(--shadow); }
.modal .sheet img { width: 100%; max-height: 40vh; object-fit: cover; border-radius: 16px; }
.modal .where { color: var(--muted); margin: 10px 2px; }
.modal .row { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.modal .row.end { justify-content: flex-end; }
#photoCaption { width: 100%; font-size: 16px; padding: 10px 12px; border: 0; border-radius: 12px; background: var(--chip); color: var(--fg); }
.viewer-box { position: relative; max-width: min(900px, 100%); max-height: 100%; display: flex; flex-direction: column;
  background: #000; border-radius: 20px; overflow: hidden; }
.viewer-box img { max-width: 100%; max-height: calc(100vh - 140px); object-fit: contain; }
.viewer-box .prev, .viewer-box .next { position: absolute; top: 40%; border: 0; width: 44px; height: 44px; border-radius: 50%;
  background: rgba(255, 255, 255, .85); color: #000; font-size: 26px; line-height: 1; }
.viewer-box .prev { left: 10px; } .viewer-box .next { right: 10px; }
.viewer-bar { display: flex; align-items: center; gap: 8px; padding: 10px 14px; background: var(--card); }
.viewer-bar div { flex: 1; }
.viewer-bar p { margin: 0; }
.viewer-meta { color: var(--muted); font-size: 13px; }
.viewer-bar button { border: 0; background: var(--chip); border-radius: 999px; width: 38px; height: 38px; }
#placing { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 5; background: var(--chip-on); color: var(--chip-on-fg);
  padding: 10px 16px; border-radius: 999px; box-shadow: var(--shadow); white-space: nowrap; }
#placing button { border: 0; background: none; text-decoration: underline; color: inherit; }

.nomap { position: fixed; top: 20%; left: 440px; right: 24px; max-width: 460px; }
.nomap h2 { font-size: 18px; color: var(--fg); }

/* ---- Phones: the panel becomes a bottom sheet ---- */
@media (max-width: 720px) {
  #panel { top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 82vh; border-radius: 26px 26px 0 0;
    padding: 6px 14px calc(18px + env(safe-area-inset-bottom)); transition: max-height .25s ease; }
  #panel.collapsed { max-height: 44vh; }
  #handle { display: block; width: 100%; border: 0; background: none; padding: 6px 0 10px; }
  #handle span { display: block; margin: 0 auto; width: 40px; height: 5px; border-radius: 3px; background: var(--line); }
  .brand { margin-bottom: 10px; }
  .brand .logo { width: 36px; height: 36px; font-size: 21px; border-radius: 12px; }
  .chips.scroll { margin: 0 -14px; padding: 0 14px 2px; }
  .nomap { top: 10%; left: 24px; }
  .maplibregl-ctrl-top-right { top: env(safe-area-inset-top); }
}
