:root {
  --bg: #fff7ef;
  --card: #ffffff;
  --ink: #3a2a1f;
  --muted: #8b7563;
  --line: #f0e0cf;
  --accent: #ff8a3d;
  --accent-ink: #ffffff;
  --danger: #d64545;
  --shadow: 0 6px 24px rgba(90, 50, 20, .14);
  --radius: 18px;
  --tabbar: 68px;
  font-family: "Nunito", ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1714;
    --card: #2a221d;
    --ink: #f6eadf;
    --muted: #b49d8a;
    --line: #3d322b;
    --shadow: 0 6px 24px rgba(0, 0, 0, .45);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
/* Seite selbst nicht zoombar (nur scrollen) – die Karte zoomt weiterhin über Leaflet */
html { touch-action: pan-x pan-y; }
body { overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }
button, input, select { font: inherit; color: inherit; }

/* Gesperrt */
.locked { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.locked-card { text-align: center; max-width: 360px; }
.locked-card img { border-radius: 24px; box-shadow: var(--shadow); }
.locked-card p { color: var(--muted); line-height: 1.5; }

/* Layout */
#app { height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--card); border-bottom: 1px solid var(--line); z-index: 5;
}
.brand { font-weight: 800; font-size: 1.15rem; }
.count { color: var(--muted); font-size: .9rem; font-weight: 700; }
main { flex: 1; position: relative; overflow: hidden; }
.view { position: absolute; inset: 0; display: none; overflow-y: auto; padding-bottom: calc(var(--tabbar) + 16px + env(safe-area-inset-bottom)); }
.view.active { display: block; }
#view-map { padding-bottom: 0; }
#map { position: absolute; inset: 0; bottom: calc(var(--tabbar) + env(safe-area-inset-bottom)); }

/* Tabbar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000;
  height: calc(var(--tabbar) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: grid; grid-template-columns: 1fr 1fr 1fr 1fr;
  background: var(--card); border-top: 1px solid var(--line);
}
.tabbar { grid-template-areas: "map fab album me"; }
.tab {
  background: none; border: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: .75rem; font-weight: 700; color: var(--muted); cursor: pointer;
}
.tab span { font-size: 1.35rem; filter: grayscale(1); opacity: .7; }
.tab.active { color: var(--accent); }
.tab.active span { filter: none; opacity: 1; }
.fab {
  justify-self: center; align-self: start; margin-top: -22px;
  width: 64px; height: 64px; border-radius: 50%; border: 4px solid var(--bg);
  background: var(--accent); color: var(--accent-ink); font-size: 2.2rem; line-height: 1; font-weight: 800;
  box-shadow: var(--shadow); cursor: pointer;
}
.fab:active { transform: scale(.94); }

/* Karten-Sticker */
.cat-marker { background: none; border: 0; }
.cat-marker .pin {
  width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  transition: transform .15s;
}
/* Leaflet setzt für Marker-Bilder width:auto und max-width:none – daher feste Größe mit höherer Spezifität */
.leaflet-container .leaflet-marker-pane .cat-marker img {
  width: 100%; height: 100%; object-fit: contain; object-position: center bottom;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,.25));
}
.cat-marker .pin:hover { transform: scale(1.12) rotate(-3deg); }
.cat-marker .label {
  position: absolute; bottom: -16px; left: 50%; transform: translateX(-50%); white-space: nowrap;
  background: var(--card); color: var(--ink); border-radius: 999px; padding: 1px 8px;
  font-size: 11px; font-weight: 800; box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
.cluster {
  background: var(--accent); color: #fff; border-radius: 50%; display: grid; place-items: center;
  font-weight: 800; border: 3px solid #fff; box-shadow: var(--shadow);
}
.map-filter { position: absolute; top: 12px; left: 12px; z-index: 800; background: var(--card); box-shadow: var(--shadow); }
.map-filter button { padding: 8px 14px; }

/* Album */
.album-head { display: flex; gap: 8px; padding: 14px 14px 4px; position: sticky; top: 0; background: var(--bg); z-index: 2; }
.album-head input { flex: 1; }
.album { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; padding: 12px 14px; }
.card {
  background: var(--card); border-radius: var(--radius); padding: 12px 10px 10px; text-align: center; cursor: pointer;
  box-shadow: 0 2px 10px rgba(90, 50, 20, .08); border: 1px solid var(--line);
}
.card:nth-child(odd) img { transform: rotate(-3deg); }
.card:nth-child(even) img { transform: rotate(2deg); }
.card img { width: 100%; aspect-ratio: 1; object-fit: contain; transition: transform .2s; }
.card:hover img { transform: rotate(0) scale(1.05); }
.card .n { font-weight: 800; margin-top: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .f { color: var(--muted); font-size: .78rem; }
.empty { text-align: center; color: var(--muted); padding: 40px 24px; line-height: 1.5; }

/* Panels / Formulare */
.panel { background: var(--card); margin: 14px; padding: 16px; border-radius: var(--radius); border: 1px solid var(--line); }
.panel h2 { margin: 0 0 12px; font-size: 1.15rem; }
.field { display: block; font-weight: 700; font-size: .9rem; margin: 12px 0; }
.field input { margin-top: 6px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
input, select {
  width: 100%; min-width: 0; padding: 11px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); font-size: 16px;
}
select { width: auto; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.hint { color: var(--muted); font-size: .85rem; font-weight: 500; line-height: 1.45; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; white-space: nowrap; text-decoration: none;
  padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg);
  font-weight: 700; cursor: pointer; margin-top: 6px;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.big { width: 100%; padding: 14px; font-size: 1.05rem; margin-top: 10px; }
.btn.ghost { background: none; }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn:disabled { opacity: .5; }
.link { background: none; border: 0; color: var(--accent); font-weight: 800; cursor: pointer; padding: 0; }

.friends { list-style: none; padding: 0; margin: 12px 0 0; }
.friends li { border-top: 1px solid var(--line); padding: 12px 0; }
.friends .top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.friends .who { font-weight: 800; }
.friends .sub { color: var(--muted); font-size: .8rem; }
.friends .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.friends .actions .btn { padding: 7px 10px; font-size: .85rem; }

/* Einladen & Sichtbarkeit */
.switch { position: relative; flex: none; width: 46px; height: 28px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; padding: 0; cursor: inherit; }
.switch i { position: absolute; inset: 0; border-radius: 999px; background: var(--line); transition: background .15s; pointer-events: none; }
.switch i::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: left .15s;
}
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { left: 21px; }
.switch input:disabled + i { opacity: .45; }
.switch input:focus-visible + i { outline: 2px solid var(--accent); outline-offset: 2px; }
.perm {
  display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 8px 0 4px;
  background: var(--bg); border-radius: 12px; padding: 8px 10px 8px 12px; font-weight: 700; font-size: .88rem;
}
.perm small { display: block; color: var(--muted); font-weight: 600; font-size: .76rem; }
.seg { display: grid; grid-template-columns: 1fr 1fr 1fr; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 3px; }
.seg button { background: none; border: 0; padding: 8px 4px; border-radius: 9px; font-weight: 800; font-size: .88rem; color: var(--muted); cursor: pointer; }
.seg button.active { background: var(--accent); color: var(--accent-ink); }
.seg.two { grid-template-columns: 1fr 1fr; }
.field .seg { margin-top: 6px; }
.people { list-style: none; padding: 0; margin: 10px 0 0; }
.people li { display: flex; justify-content: space-between; align-items: center; gap: 10px; border-top: 1px solid var(--line); padding: 9px 0; }
.people .who { font-weight: 800; }
.people .sub { color: var(--muted); font-size: .78rem; font-weight: 600; }
.badge {
  background: color-mix(in srgb, var(--accent) 22%, var(--card)); color: var(--accent); border-radius: 999px;
  padding: 1px 8px; font-size: .7rem; font-weight: 800; margin-left: 4px; vertical-align: 1px;
}
.check { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: .88rem; margin: 10px 0 2px; cursor: pointer; }
.check input { width: 20px; height: 20px; padding: 0; margin: 0; accent-color: var(--accent); }
.info {
  margin: 14px 14px 0; padding: 10px 12px; border-radius: 14px; font-size: .85rem; font-weight: 600; line-height: 1.4;
  background: color-mix(in srgb, var(--accent) 16%, var(--card)); border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--card));
}

/* Dialoge */
dialog.sheet {
  width: min(520px, 100%); max-height: 92dvh; margin: auto auto 0; padding: 0; border: 0;
  border-radius: 24px 24px 0 0; background: var(--card); color: var(--ink); box-shadow: var(--shadow);
}
@media (min-width: 600px) { dialog.sheet { margin: auto; border-radius: 24px; } }
dialog::backdrop { background: rgba(30, 15, 5, .45); }
dialog form, .detail { padding: 0 18px 18px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px 6px; position: sticky; top: 0; background: var(--card); z-index: 2; }
.sheet-head h2 { margin: 0; font-size: 1.25rem; }
.x { background: var(--bg); border: 0; width: 34px; height: 34px; border-radius: 50%; cursor: pointer; font-size: 1rem; }
.photo-pick {
  display: grid; place-items: center; min-height: 160px; border-radius: var(--radius); margin-top: 6px;
  border: 2px dashed var(--line); background: var(--bg); cursor: pointer; overflow: hidden; position: relative;
  font-weight: 800; color: var(--muted);
}
.photo-pick input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.photo-pick img { width: 100%; max-height: 240px; object-fit: cover; }
.photo-pick img:not(.hidden) + span { display: none; }
.loc-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
#pick-map { height: 200px; border-radius: 14px; border: 1px solid var(--line); }
.working { position: absolute; inset: 0; background: color-mix(in srgb, var(--card) 92%, transparent); display: grid; place-content: center; text-align: center; gap: 12px; font-weight: 800; z-index: 3; }
.loader { display: block; width: 210px; max-width: 70vw; height: auto; margin: auto; border-radius: var(--radius); }
.detail { text-align: center; }
.detail-sticker { max-width: 100%; max-height: 320px; margin: 8px auto; display: block; animation: pop .35s cubic-bezier(.2,1.6,.4,1); }
@keyframes pop { from { transform: scale(.6) rotate(-8deg); opacity: 0; } }
.meta { color: var(--muted); margin: 4px 0 8px; }
.detail .row { justify-content: center; }
.owner { text-align: left; border-top: 1px solid var(--line); margin-top: 14px; padding-top: 4px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar) + 24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-weight: 700;
  opacity: 0; pointer-events: none; transition: .25s; z-index: 2000; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.move-banner {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 900;
  background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 999px; font-weight: 800;
  display: flex; gap: 10px; align-items: center; box-shadow: var(--shadow);
}
.move-banner button { background: var(--bg); color: var(--ink); border: 0; border-radius: 999px; padding: 4px 10px; font-weight: 800; cursor: pointer; }
.leaflet-container { font: inherit; background: var(--bg); }
