:root {
  --bg: #f6f2ec;
  --surface: #fffdf9;
  --surface-2: #efe8de;
  --text: #2b2420;
  --muted: #7a6e64;
  --line: #e2d8cb;
  --accent: #b5562b;
  --accent-text: #fff;
  --danger: #b3261e;
  --ok: #2e7d32;
  --tag: #ffd54f;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 2px 8px rgb(0 0 0 / .05);
  --nav-h: 62px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #181412;
    --surface: #221d1a;
    --surface-2: #2d2622;
    --text: #efe7de;
    --muted: #a39789;
    --line: #3a322c;
    --accent: #e07a46;
    --accent-text: #1a1310;
    --danger: #ff6b5e;
    --ok: #6fcf75;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}
body.center { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
a { color: var(--accent); }
h1 { font-size: 1.5rem; line-height: 1.25; margin: .2em 0 .4em; }
h2 { font-size: 1.1rem; margin: 1.2em 0 .5em; }
h3 { font-size: 1rem; margin: 1em 0 .4em; }
img { max-width: 100%; }

.wrap { max-width: 1100px; margin: 0 auto; padding: 12px 16px 32px; }
.wrap.wide { max-width: 1500px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.error { color: var(--danger); }
.ok { color: var(--ok); }
.row { display: flex; gap: 12px; align-items: center; }
.wrapgap { flex-wrap: wrap; gap: 8px; }
.grow { flex: 1; min-width: 0; }
.inline { display: inline; }
[hidden] { display: none !important; }

/* ---------- Navigation: unten auf dem Handy, oben am Desktop ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: block; padding: 10px 16px; font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; }
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: space-around;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); height: calc(var(--nav-h) + env(safe-area-inset-bottom));
}
.nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: .68rem; min-width: 0;
}
.nav a.on { color: var(--accent); }
.nav svg { flex: none; width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

@media (min-width: 900px) {
  body { padding-bottom: 0; }
  .topbar { display: flex; align-items: center; justify-content: space-between; padding: 0 12px; }
  .nav { position: static; height: auto; border: 0; padding: 0; gap: 4px; }
  .nav a { flex-direction: row; font-size: .95rem; padding: 14px 12px; gap: 6px; }
  .nav svg { width: 20px; height: 20px; }
}

.flash {
  max-width: 1100px; margin: 12px auto 0; padding: 10px 14px; border-radius: var(--radius);
  background: var(--surface-2); border-left: 4px solid var(--accent); width: calc(100% - 32px);
}

/* ---------- Bausteine ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 12px 0; box-shadow: var(--shadow); }
.card > h1:first-child, .card > h2:first-child { margin-top: 0; }
.card.narrow { width: 100%; max-width: 420px; }
.card.warn { border-color: var(--accent); }
.card.highlight { border: 2px solid var(--accent); }
.card.inactive { opacity: .6; }
.pagehead { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

label { display: block; margin: 0 0 12px; font-size: .92rem; }
label.check { display: flex; gap: 8px; align-items: center; }
input:not([type=checkbox]):not([type=file]), select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px;
  font: inherit; font-size: 16px; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
textarea { resize: vertical; }
input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 8px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; font-size: .95rem;
  text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.ghost { background: transparent; }
.btn.wide { width: 100%; }
.btn.small { min-height: 30px; padding: 2px 10px; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: default; }
button.x {
  border: 0; background: none; color: var(--muted); font-size: 1.1rem; line-height: 1;
  padding: 2px 4px; cursor: pointer;
}
button.x:hover { color: var(--danger); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0; margin: 0 0 8px; list-style: none; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--text); text-decoration: none; font-size: .9rem;
}
.chip a { color: inherit; text-decoration: none; }
.chip.hl { outline: 2px solid var(--tag); }

details > summary { cursor: pointer; color: var(--accent); margin: 6px 0; }
details > summary.btn { color: var(--text); list-style: none; }
details > summary.btn::-webkit-details-marker { display: none; }
.editbox[open] { padding-bottom: 6px; }
.editbox form { margin: 8px 0; }

.avatar { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; background: var(--surface-2); flex: none; }
.avatar.big { width: 72px; height: 72px; }
.avatar.initials { display: inline-grid; place-items: center; font-weight: 700; color: var(--muted); }

/* ---------- Galerie ---------- */
.searchbar { display: flex; gap: 8px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 4px; }
.searchbar input[type=search] { flex: 1; min-width: 180px; margin: 0; }
.filters { position: relative; }
.filters > summary { margin: 0; }
.filterbox {
  position: absolute; right: 0; top: 48px; z-index: 15; width: min(320px, calc(100vw - 32px));
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px;
  box-shadow: 0 8px 24px rgb(0 0 0 / .18);
}
.resultline { margin: 6px 0 8px; }
.headcard h1 { margin-top: 0; }
.crumbs { margin: 0; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); gap: 3px; }
@media (min-width: 700px) { .grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 6px; } }
.grid.small { grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); }
.tile { position: relative; display: block; aspect-ratio: 1; overflow: hidden; background: var(--surface-2); border-radius: 4px; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .2s; }
.tile:hover img { transform: scale(1.03); }
.badge {
  position: absolute; bottom: 4px; padding: 1px 6px; border-radius: 6px; font-size: .72rem;
  color: #fff; background: rgb(0 0 0 / .6);
}
.badge.video { left: 4px; }
.badge.com { right: 4px; }
.more { grid-column: 1 / -1; text-align: center; padding: 16px; }
.empty { text-align: center; padding: 32px 16px; }

/* ---------- Detail ---------- */
.detail { display: grid; gap: 16px; }
@media (min-width: 1000px) {
  .detail { grid-template-columns: minmax(0, 1fr) 380px; align-items: start; }
  .stagecol { position: sticky; top: 64px; }
}
.stagecol { margin: 0 -16px; }
@media (min-width: 700px) { .stagecol { margin: 0; } }
.stage {
  position: relative; display: grid; place-items: center; background: #0d0b0a;
  touch-action: pan-y pinch-zoom; user-select: none; -webkit-user-select: none;
}
@media (min-width: 700px) { .stage { border-radius: var(--radius); overflow: hidden; } }
.stage img, .stage video { display: block; max-width: 100%; max-height: 78vh; margin: 0 auto; }
.stagenote { color: #ddd; padding: 8px 16px; text-align: center; }
.stage.tagging { cursor: crosshair; touch-action: none; }
.stage.tagging .tagbox { display: none; }
.stagenav { display: flex; justify-content: space-between; gap: 6px; padding: 8px 16px; }
@media (min-width: 700px) { .stagenav { padding: 8px 0; } }
.stagenav .btn { min-width: 48px; font-size: 1.1rem; }

.tagbox {
  position: absolute; border: 2px solid var(--tag); border-radius: 6px;
  box-shadow: 0 0 0 1px rgb(0 0 0 / .5); text-decoration: none;
  opacity: 0; transition: opacity .15s;
}
.tagbox span {
  position: absolute; left: 50%; top: 100%; transform: translate(-50%, 4px); white-space: nowrap;
  background: rgb(0 0 0 / .75); color: #fff; font-size: .78rem; padding: 1px 6px; border-radius: 6px;
}
.stage.showtags .tagbox, .tagbox.hl { opacity: 1; }
@media (hover: hover) { .stage:hover .tagbox { opacity: .85; } }
.drawbox { position: absolute; border: 2px dashed var(--tag); background: rgb(255 213 79 / .15); border-radius: 6px; pointer-events: none; }

.info h1 { margin-top: 0; }
.info section { border-top: 1px solid var(--line); margin-top: 12px; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); margin: 0 0 8px; }
.tagactions { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0; }
.tagform { background: var(--surface-2); border-radius: var(--radius); padding: 12px; margin: 8px 0; }
.comment { padding: 8px 0; border-bottom: 1px solid var(--line); }
.comment header { display: flex; gap: 8px; align-items: baseline; }
.comment header form { margin-left: auto; }
.comment p { margin: 4px 0 0; }
.commentform { margin-top: 10px; }
.commentform textarea { margin-bottom: 8px; }
.filebox { border-top: 1px solid var(--line); margin-top: 16px; padding-top: 4px; }
.filebox dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; font-size: .9rem; }
.filebox dt { color: var(--muted); }
.filebox dd { margin: 0; overflow-wrap: anywhere; }
.history { padding-left: 18px; font-size: .9rem; }
.history li { margin-bottom: 8px; overflow-wrap: anywhere; }

.checklist { max-height: 300px; overflow: auto; margin-bottom: 10px; }
.checklist .check { margin: 0; padding: 6px 0; }
.depth1 { padding-left: 20px !important; }
.depth2 { padding-left: 40px !important; }
.depth3 { padding-left: 60px !important; }
.depth4 { padding-left: 80px !important; }

/* ---------- Personen & Kategorien ---------- */
.quickfilter { max-width: 260px; }
.people { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; }
.people a { display: grid; grid-template-columns: 48px 1fr; grid-template-rows: auto auto; column-gap: 12px; align-items: center;
  padding: 8px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); color: var(--text); text-decoration: none; }
.people .avatar { grid-row: span 2; }
.pname { font-weight: 600; }
.cattree { list-style: none; padding: 0; }
.cattree li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.catrow { display: flex; gap: 8px; align-items: baseline; }
.catrow a { color: var(--text); text-decoration: none; }

/* ---------- Upload ---------- */
.dropzone {
  display: grid; place-items: center; text-align: center; min-height: 140px; padding: 16px; margin-bottom: 16px;
  border: 2px dashed var(--line); border-radius: var(--radius); cursor: pointer; background: var(--bg);
}
.dropzone.over { border-color: var(--accent); }
.dropzone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.uploads { list-style: none; padding: 0; }
.uploads li { display: grid; grid-template-columns: 56px 1fr; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.uploads .thumb { width: 56px; height: 56px; border-radius: 6px; object-fit: cover; background: var(--surface-2); }
.uploads .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9rem; }
.uploads progress { width: 100%; }

/* ---------- Admin ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; text-align: center; }
.stat b { display: block; font-size: 1.5rem; }
.stat span { color: var(--muted); font-size: .85rem; }
progress { width: 100%; height: 10px; accent-color: var(--accent); }
.plain { list-style: none; padding: 0; }
.plain li { padding: 6px 0; }
.userlist { list-style: none; padding: 0; }
