:root {
  --bg: #fbfbf9;
  --text: #20201e;
  --muted: #76746e;
  --line: #e8e7e2;
  --surface: #ffffff;
  --accent: #20201e;
  --maxw: 1000px;
  --header-h: 60px;
}
[data-theme="dark"] {
  --bg: #161614;
  --text: #e8e7e2;
  --muted: #9b9a93;
  --line: #2a2a27;
  --surface: #1d1d1b;
  --accent: #e8e7e2;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  font: 17px/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; height: auto; display: block; }
a { color: inherit; }

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; height: var(--header-h); padding: 0 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--line);
}
.site-brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); min-width: 0; }
.site-name { font-weight: 600; font-size: .98rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.site-tagline { color: var(--muted); font-weight: 400; }
.site-tools { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }

.search-form { display: flex; align-items: center; }
.search-form input {
  width: 0; padding: 0; border: 0; opacity: 0; pointer-events: none;
  background: var(--surface); color: var(--text); border-radius: 999px; font: inherit;
  transition: width .25s ease, opacity .2s ease, padding .25s ease;
}
.search-form.open input {
  width: min(48vw, 280px); opacity: 1; pointer-events: auto;
  padding: 8px 14px; border: 1px solid var(--line); margin-right: 4px;
}
.search-toggle, .theme-toggle {
  border: 0; background: none; color: var(--muted); cursor: pointer;
  padding: 8px; border-radius: 999px; display: grid; place-items: center;
}
.search-toggle:hover, .theme-toggle:hover { color: var(--text); background: var(--line); }

/* ---------- Main ---------- */
.site-main { max-width: var(--maxw); margin: 0 auto; padding: 40px 20px 64px; }
.search-summary { color: var(--muted); margin-bottom: 24px; font-size: .95rem; }
.empty { text-align: center; color: var(--muted); padding: 80px 0; }

/* ---------- Journal ---------- */
.journal { display: flex; flex-direction: column; gap: 72px; }
.card-post { }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; text-decoration: none; margin-bottom: 16px; }
.card-head h2 { font-size: 1.4rem; font-weight: 600; margin: 0; letter-spacing: -.01em; }
.card-head time { color: var(--muted); font-size: .85rem; white-space: nowrap; flex: 0 0 auto; }
.card-head:hover h2 { opacity: .7; }

.card-gallery { display: block; text-decoration: none; }
.card-main img { width: 100%; max-height: 82vh; object-fit: contain; border-radius: 6px; background: var(--line); }

/* Querformat: Thumbnails darunter, drei gleich breite Spalten */
.is-landscape .card-thumbs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 12px; }
.is-landscape .card-thumbs img { width: 100%; aspect-ratio: 3 / 2; object-fit: cover; border-radius: 5px; }

/* Hochformat MIT Thumbs: Bild links auf voller Containerhöhe, Thumbs rechts füllen den Rest.
   Höhe ist explizit aus der Spaltenbreite hergeleitet (3:2), damit innere 1fr-Zeilen
   verlässlich aufgeteilt werden können. */
.is-portrait.has-thumbs {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: 1fr;
  gap: 12px;
  height: min(80vh, calc(min(100vw - 40px, 960px) / 1.5));
  overflow: hidden;
}
.is-portrait.has-thumbs > * { min-height: 0; min-width: 0; height: 100%; }
.is-portrait.has-thumbs .card-main img {
  height: 100%; width: auto; max-width: 100%; object-fit: contain;
  border-radius: 6px;
}
.is-portrait.has-thumbs .card-thumbs {
  display: grid;
  grid-template-rows: repeat(var(--thumbs, 3), 1fr);
  gap: 12px;
}
.is-portrait.has-thumbs .card-thumbs > * { min-height: 0; }
.is-portrait.has-thumbs .card-thumbs img {
  width: 100%; height: 100%; object-fit: cover; border-radius: 5px;
}

/* Desktop-only: 1-Thumb-Fall bei Hochformat → zwei gleichgewichtige Zellen nebeneinander,
   beide Bilder im natürlichen Seitenverhältnis (kein Beschneiden). */
@media (min-width: 641px) {
  .is-portrait.has-thumbs.thumbs-1 {
    display: flex;
    align-items: stretch;
    gap: 12px;
  }
  .is-portrait.has-thumbs.thumbs-1 > * {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    height: auto;
  }
  .is-portrait.has-thumbs.thumbs-1 .card-thumbs {
    display: flex;             /* überschreibt das Grid aus der Standard-Regel */
    grid-template-rows: none;
  }
  .is-portrait.has-thumbs.thumbs-1 .card-main img,
  .is-portrait.has-thumbs.thumbs-1 .card-thumbs img {
    max-height: 100%;
    max-width: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 6px;
  }
}

/* Hochformat OHNE Thumbs: einzelnes Bild zentriert. */
.is-portrait.no-thumbs { display: flex; justify-content: center; }
.is-portrait.no-thumbs .card-main img {
  max-height: 78vh; width: auto; max-width: 100%; object-fit: contain;
}

/* ---------- Beitragsseite ---------- */
.post-header { margin-bottom: 18px; }
.post-header h1 { font-size: 2rem; font-weight: 600; margin: 0 0 6px; letter-spacing: -.015em; }
.post-header time { color: var(--muted); font-size: .9rem; }
.post-text { font-size: 1.08rem; margin: 0 0 18px; max-width: 70ch; }
.post-tags { display: flex; flex-wrap: wrap; gap: 10px; margin: 0 0 8px; }
.post-tags a { color: var(--muted); font-size: .85rem; text-decoration: none; }
.post-tags a:hover { color: var(--text); }

.post-images { display: flex; flex-direction: column; gap: 28px; margin: 36px 0; }
.post-image { margin: 0; }
.post-image img { width: 100%; border-radius: 6px; cursor: zoom-in; background: var(--line); }
.post-image.is-portrait { display: flex; justify-content: center; }
.post-image.is-portrait img { width: auto; max-width: 100%; max-height: 88vh; }

/* Navigation vor/zurück */
.post-nav { display: flex; justify-content: space-between; gap: 16px; padding: 18px 0; border-top: 1px solid var(--line); }
.post-nav.top { border-top: 0; border-bottom: 1px solid var(--line); }
.post-nav a { text-decoration: none; max-width: 48%; display: flex; flex-direction: column; }
.post-nav small { color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; }
.post-nav span { font-weight: 500; }
.post-nav .nav-next { text-align: right; margin-left: auto; }
.post-nav a:hover span { opacity: .7; }
.nav-empty { flex: 1; }

/* ---------- Footer ---------- */
.site-footer { text-align: center; color: var(--muted); font-size: .85rem; padding: 40px 20px; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.site-footer a { color: var(--muted); text-decoration: none; }
.site-footer a:hover { color: var(--text); }

/* ---------- Rechtstexte (Impressum / Datenschutz) ---------- */
.legal { max-width: 70ch; margin: 0 auto; }
.legal h1 { font-size: 1.8rem; font-weight: 600; margin: 0 0 24px; letter-spacing: -.015em; }
.legal h2 { font-size: 1.1rem; font-weight: 600; margin: 32px 0 8px; }
.legal p, .legal ul { margin: 0 0 14px; }
.legal ul { padding-left: 1.2em; }
.legal li { margin-bottom: 4px; }
.legal a { color: var(--text); }
.legal .hint { color: var(--muted); font-size: .9em; }
.legal-date { color: var(--muted); font-size: .85rem; margin-top: 32px; }

/* ---------- Lightbox ---------- */
body.lb-open { overflow: hidden; }
.lightbox {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(12,12,11,.94);
  display: grid; place-items: center;
}
.lightbox[hidden] { display: none; }
.lb-stage { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; }
.lb-img {
  max-width: 96vw; max-height: 94vh; object-fit: contain;
  cursor: zoom-in; border-radius: 2px;
  transform-origin: center center; touch-action: none; user-select: none;
}
.lb-img.zoomed { cursor: grab; }
.lb-img.zoomed:active { cursor: grabbing; }
.lb-close, .lb-prev, .lb-next {
  position: absolute; z-index: 2; border: 0; cursor: pointer;
  background: rgba(0,0,0,.25); color: #fff; opacity: 0; transition: opacity .2s ease;
}
.lightbox:hover .lb-close, .lightbox:hover .lb-prev, .lightbox:hover .lb-next { opacity: .8; }
.lb-close:hover, .lb-prev:hover, .lb-next:hover { opacity: 1 !important; }
.lb-close { top: 16px; right: 18px; width: 44px; height: 44px; border-radius: 50%; font-size: 26px; line-height: 1; }
.lb-prev, .lb-next { top: 50%; transform: translateY(-50%); width: 56px; height: 84px; font-size: 38px; border-radius: 8px; }
.lb-prev { left: 14px; }
.lb-next { right: 14px; }
.lb-counter { position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%); color: #fff; opacity: .7; font-size: .85rem; z-index: 2; }

/* Touch-Geräte: Navigationsbuttons dauerhaft sichtbar */
@media (hover: none) {
  .lb-close, .lb-prev, .lb-next { opacity: .8; }
}

/* ---------- Mobil ---------- */
@media (max-width: 640px) {
  .site-tagline { display: none; }
  .site-main { padding: 28px 16px 48px; }
  .journal { gap: 56px; }
  .post-header h1 { font-size: 1.6rem; }

  /* Hochformat-Karten auf schmalen Bildschirmen stapeln (Bild oben, Thumbs als Reihe darunter,
     so viele Spalten wie es Thumbs gibt — also 1 oder 2). */
  .is-portrait.has-thumbs {
    grid-template-columns: 1fr; grid-template-rows: auto;
    height: auto; max-height: none;
  }
  .is-portrait.has-thumbs > * { height: auto; }
  .is-portrait.has-thumbs .card-main { display: flex; justify-content: center; }
  .is-portrait.has-thumbs .card-main img { height: auto; max-height: 70vh; }
  .is-portrait.has-thumbs .card-thumbs {
    grid-template-rows: auto;
    grid-template-columns: repeat(var(--thumbs, 2), 1fr);
  }
  .is-portrait.has-thumbs .card-thumbs img { aspect-ratio: 3 / 2; height: auto; }

  /* Mobiler Sonderfall: nur 1 Thumb → mittig im natürlichen Seitenverhältnis darstellen. */
  .is-portrait.has-thumbs.thumbs-1 .card-thumbs {
    display: flex;
    justify-content: center;
    grid-template-columns: none;
  }
  .is-portrait.has-thumbs.thumbs-1 .card-thumbs img {
    aspect-ratio: auto;
    max-height: 50vh;
    max-width: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
  }
}
