:root {
  --ink: #1c261f; --muted: #5a685e; --line: #d3dbd2; --bg: #f2f5ef; --surface: #ffffff; --soft: #e9eee6;
  --accent: #e2621b; --accent-ink: #b04609; --forest: #1f3b2a; --water: #3f76ae;
  --shadow: 0 6px 24px rgba(20, 30, 24, .22);
  --radius: 16px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
  --panel-w: 400px;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font-family: var(--font); color: var(--ink); background: var(--bg); overscroll-behavior: none; -webkit-tap-highlight-color: transparent; -webkit-font-smoothing: antialiased; }
button, input { font: inherit; }
a { color: var(--accent-ink); }
[hidden] { display: none !important; }

#map { position: fixed; inset: 0; }
.maplibregl-ctrl-top-right { top: calc(var(--sat) + 60px); }
.maplibregl-ctrl-group { box-shadow: var(--shadow) !important; border-radius: 12px !important; }
.maplibregl-ctrl-group button { width: 40px; height: 40px; }
.maplibregl-ctrl-attrib { font-size: 11px; }
.maplibregl-ctrl-bottom-left { bottom: var(--sab); }
.maplibregl-ctrl-bottom-right { bottom: var(--sab); }
.locate-btn svg { width: 22px; height: 22px; display: block; margin: auto; }
.locate-btn.active svg { color: var(--water); }
.locate-btn.denied svg { color: #b04; opacity: .6; }

/* Topp */
.topbar { position: fixed; top: calc(var(--sat) + 10px); left: 10px; right: 10px; display: flex; justify-content: space-between; align-items: center; gap: 8px; z-index: 20; pointer-events: none; }
.topbar > * { pointer-events: auto; }
.brand { display: inline-flex; align-items: center; gap: 8px; background: var(--forest); color: #fff; text-decoration: none; padding: 8px 14px 8px 10px; border-radius: 999px; font-weight: 700; font-size: 15px; letter-spacing: .01em; box-shadow: var(--shadow); }
.brand-mark { width: 16px; height: 22px; }
.topbar-actions { display: flex; gap: 6px; }
.tb-btn { background: var(--surface); color: var(--ink); border: 0; border-radius: 999px; padding: 9px 14px; font-weight: 600; font-size: 14px; box-shadow: var(--shadow); cursor: pointer; }
.tb-btn:focus-visible, .btn:focus-visible, .ctl:focus-visible { outline: 2px solid var(--water); outline-offset: 2px; }

/* Panel (mobil: ark nedifrån) */
.panel { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--surface); border-radius: 22px 22px 0 0; box-shadow: 0 -4px 30px rgba(0,0,0,.22); max-height: 88vh; transform: translateY(calc(100% - 140px - var(--sab))); transition: transform .28s cubic-bezier(.2,.8,.2,1); touch-action: none; }
.panel.expanded { transform: translateY(0); }
.panel.dragging { transition: none; }
.panel-handle { height: 22px; display: flex; align-items: center; justify-content: center; cursor: grab; }
.panel-handle span { width: 40px; height: 5px; border-radius: 3px; background: var(--line); }
.panel-close { position: absolute; top: 8px; right: 10px; width: 34px; height: 34px; border: 0; border-radius: 50%; background: var(--soft); color: var(--ink); font-size: 22px; line-height: 1; cursor: pointer; z-index: 2; }
.panel-scroll { overflow-y: auto; max-height: calc(88vh - 22px); padding: 0 16px calc(24px + var(--sab)); overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.panel.expanded .panel-scroll { touch-action: pan-y; }
.panel-head { display: flex; gap: 12px; align-items: center; min-height: 96px; padding-right: 36px; }
.p-cover { width: 84px; height: 84px; object-fit: cover; border-radius: 12px; flex: none; background: var(--soft); }
.p-cat { margin: 0 0 2px; font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--accent-ink); }
.p-title h1 { margin: 0; font-size: 22px; line-height: 1.15; letter-spacing: -.01em; }
.p-meta { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.p-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 12px; }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 999px; padding: 9px 16px; font-weight: 600; font-size: 14px; text-decoration: none; cursor: pointer; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.p-summary { font-size: 16px; line-height: 1.5; margin: 0 0 8px; }
.p-body { font-size: 15.5px; line-height: 1.55; }
.p-body p { margin: 0 0 10px; }
.p-body h1, .p-body h2, .p-body h3 { font-size: 17px; margin: 16px 0 6px; }
.p-body img { max-width: 100%; }
.p-gallery { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin: 14px 0; }
.p-gallery button { border: 0; padding: 0; background: var(--soft); aspect-ratio: 1; border-radius: 8px; overflow: hidden; cursor: pointer; }
.p-gallery img { width: 100%; height: 100%; object-fit: cover; display: block; }
.p-gallery .board { position: relative; }
.p-gallery .board::after { content: "tavla"; position: absolute; left: 6px; bottom: 6px; background: rgba(0,0,0,.6); color: #fff; font-size: 10px; padding: 2px 6px; border-radius: 999px; }
.p-section h2 { font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 16px 0 6px; }
.p-section ul { list-style: none; margin: 0; padding: 0; }
.p-section li { padding: 7px 0; border-top: 1px solid var(--line); font-size: 15px; display: flex; gap: 10px; align-items: baseline; }
.p-section li a { text-decoration: none; color: var(--ink); font-weight: 600; }
.p-section li small { color: var(--muted); }
.poi-dot { display: inline-flex; width: 22px; height: 22px; border-radius: 50%; background: var(--forest); color: #fff; font-size: 10px; font-weight: 700; align-items: center; justify-content: center; flex: none; align-self: center; }
.p-section li button.linklike { border: 0; background: none; padding: 0; color: var(--ink); font-weight: 600; cursor: pointer; text-align: left; }
.p-foot { color: var(--muted); font-size: 13px; margin-top: 18px; }

/* Lista */
.listpanel { position: fixed; top: calc(var(--sat) + 60px); left: 10px; right: 10px; z-index: 25; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); max-height: calc(100vh - var(--sat) - 90px); display: flex; flex-direction: column; }
.list-head { display: flex; gap: 8px; padding: 10px; }
.list-head input { flex: 1; border: 1px solid var(--line); border-radius: 999px; padding: 9px 14px; font-size: 16px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 0 10px 8px; scrollbar-width: none; }
.chips button { flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px; font-size: 13px; cursor: pointer; }
.chips button.on { background: var(--forest); color: #fff; border-color: var(--forest); }
.list-items { list-style: none; margin: 0; padding: 0 6px 8px; overflow-y: auto; }
.list-items li button { width: 100%; display: flex; gap: 12px; align-items: center; text-align: left; border: 0; background: none; padding: 8px; border-radius: 12px; cursor: pointer; }
.list-items li button:hover { background: var(--soft); }
.list-items img, .list-items .noimg { width: 56px; height: 56px; border-radius: 10px; object-fit: cover; background: var(--soft); flex: none; }
.list-items b { display: block; font-size: 15px; }
.list-items small { color: var(--muted); font-size: 13px; }
.list-empty { padding: 20px; color: var(--muted); text-align: center; }

/* Lager */
.layerpanel { position: fixed; top: calc(var(--sat) + 60px); right: 10px; z-index: 25; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; width: min(280px, calc(100vw - 20px)); }
.lp-title { margin: 8px 0 6px; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.lp-title:first-child { margin-top: 0; }
.lp-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 15px; cursor: pointer; }
.lp-row input[type=range] { margin-left: auto; width: 90px; }

/* Bildvisare */
.lightbox { position: fixed; inset: 0; z-index: 60; background: #000; color: #fff; display: flex; flex-direction: column; }
.lb-fig { flex: 1; margin: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 0; }
.lb-fig img { max-width: 100%; max-height: 100%; object-fit: contain; }
.lb-fig figcaption { padding: 8px 16px; font-size: 14px; color: #ddd; text-align: center; }
.lb-close { position: absolute; top: calc(var(--sat) + 10px); right: 10px; width: 40px; height: 40px; border: 0; border-radius: 50%; background: rgba(255,255,255,.15); color: #fff; font-size: 26px; cursor: pointer; z-index: 2; }
.lb-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 64px; border: 0; background: rgba(0,0,0,.25); color: #fff; font-size: 34px; cursor: pointer; }
.lb-prev { left: 0; border-radius: 0 12px 12px 0; }
.lb-next { right: 0; border-radius: 12px 0 0 12px; }
.lb-bar { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px calc(12px + var(--sab)); font-size: 13px; color: #bbb; }
.lb-bar .btn { background: rgba(255,255,255,.12); border-color: transparent; color: #fff; }

/* Markörer */
.photo-marker { width: 46px; height: 46px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 2px 8px rgba(0,0,0,.35); overflow: hidden; background: var(--soft); cursor: pointer; transition: transform .15s; }
.photo-marker img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-marker.board { border-color: var(--forest); }
.photo-marker.active { transform: scale(1.2); border-color: var(--accent); z-index: 5; }
.poi-marker { width: 26px; height: 26px; border-radius: 50%; background: #fff; border: 2px solid var(--forest); color: var(--forest); font-size: 11px; font-weight: 800; display: flex; align-items: center; justify-content: center; box-shadow: 0 1px 4px rgba(0,0,0,.3); cursor: pointer; }
.me-marker { width: 18px; height: 18px; border-radius: 50%; background: var(--water); border: 3px solid #fff; box-shadow: 0 0 0 4px rgba(63,118,174,.25), 0 1px 6px rgba(0,0,0,.4); position: relative; }
.me-marker::before { content: ""; position: absolute; inset: -14px; border-radius: 50%; background: rgba(63,118,174,.18); animation: pulse 2.4s ease-out infinite; }
@keyframes pulse { 0% { transform: scale(.5); opacity: .9; } 100% { transform: scale(1.4); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .me-marker::before { animation: none; } .panel { transition: none; } }

.toast { position: fixed; left: 50%; bottom: calc(24px + var(--sab)); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px; z-index: 70; box-shadow: var(--shadow); max-width: 90vw; }

/* Enkla sidor (404) */
body.plain { display: flex; align-items: center; justify-content: center; min-height: 100%; }
.plain-main { padding: 24px; max-width: 480px; }

/* Desktop / paddor på bredden */
@media (min-width: 900px) {
  .panel { top: 0; bottom: 0; left: 0; right: auto; width: var(--panel-w); border-radius: 0; max-height: none; transform: none; box-shadow: 4px 0 30px rgba(0,0,0,.18); }
  .panel-handle { display: none; }
  .panel-scroll { max-height: 100vh; padding-top: 74px; }
  .panel-head { align-items: flex-start; }
  .p-cover { width: 100%; height: 200px; border-radius: 12px; }
  .panel-head { flex-direction: column; }
  .p-title h1 { font-size: 26px; }
  .panel-close { top: 20px; right: 16px; }
  body.has-panel .topbar { left: calc(var(--panel-w) + 10px); }
  body.has-panel .listpanel { left: calc(var(--panel-w) + 10px); }
  .listpanel { width: 380px; right: auto; }
  .p-gallery { grid-template-columns: repeat(3, 1fr); }
}
