@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,400;0,500;0,600;1,400&family=Inter:wght@300;400;500;600&display=swap');

/* ================================================================
   Grundlagen
   ================================================================ */
:root {
  --bg: #faf9f7;
  --surface: #ffffff;
  --text: #1c1b19;
  --muted: #8a857d;
  --line: #e7e3dc;
  --soft: #f1eee9;
  --danger: #b3261e;
  --ok: #2f6b3a;
  --radius: 12px;
  --shadow: 0 12px 40px rgba(28, 27, 25, .10);
  --serif: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --ease: cubic-bezier(.2, .7, .2, 1);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
img { display: block; max-width: 100%; }
button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; color: inherit; }
a { color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.icon { width: 18px; height: 18px; flex: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .7rem 1.25rem;
  border: 1px solid var(--text); border-radius: 999px;
  background: transparent;
  font-size: .82rem; font-weight: 500; letter-spacing: .04em;
  white-space: nowrap;
  transition: background .2s, color .2s, opacity .2s, border-color .2s;
}
.btn:hover { background: var(--text); color: var(--bg); }
.btn-primary { background: var(--text); color: var(--bg); }
.btn-primary:hover { opacity: .85; }
.btn-ghost { border-color: transparent; }
.btn-ghost:hover { background: var(--soft); color: var(--text); }
.btn-danger { border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { padding: .45rem .85rem; font-size: .78rem; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn:disabled:hover { background: transparent; color: inherit; }
.btn-primary:disabled:hover { background: var(--text); color: var(--bg); }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 42px; height: 42px; border-radius: 50%;
  border: none; background: transparent;
  transition: background .2s;
}
.icon-btn:hover { background: var(--soft); }

/* ---------- Formulare ---------- */
.field { display: grid; gap: .35rem; text-align: left; }
.field label { font-size: .75rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.input {
  width: 100%; padding: .8rem 1rem;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); outline: none;
  transition: border-color .2s;
}
.input:focus { border-color: var(--text); }

.brand { font-family: var(--serif); font-size: 2.3rem; font-weight: 500; letter-spacing: .01em; line-height: 1.1; }
.brand-sub { font-size: .7rem; letter-spacing: .32em; text-transform: uppercase; color: var(--muted); margin-top: .4rem; }

.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ================================================================
   Code-Eingabe
   ================================================================ */
.gate { min-height: 100svh; display: grid; place-items: center; padding: 24px; }
.gate-card { width: 100%; max-width: 420px; text-align: center; animation: fadeUp .8s var(--ease) both; }
.gate-divider { width: 40px; height: 1px; background: var(--line); margin: 2.2rem auto; }
.gate h1 { font-family: var(--serif); font-weight: 400; font-size: 1.6rem; margin: 0 0 .4rem; }
.gate p { margin: 0 0 1.6rem; color: var(--muted); font-size: .9rem; }
.gate form { display: grid; gap: .9rem; }
.code-input {
  text-align: center; font-size: 1.25rem; font-weight: 500;
  letter-spacing: .3em; text-transform: uppercase; padding: 1rem;
}
.code-input::placeholder { letter-spacing: .15em; font-weight: 400; color: #c4bfb6; text-transform: none; }
.form-error { color: var(--danger); font-size: .85rem; min-height: 1.3em; margin: 0; }
.shake { animation: shake .45s; }
@keyframes shake {
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}
@keyframes fadeUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

/* ================================================================
   Galerie – Titelbild
   ================================================================ */
.hero {
  position: relative; height: 82svh; min-height: 440px;
  overflow: hidden; background: var(--soft);
}
.hero img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  transform: scale(1.04); opacity: 0; transition: opacity 1.2s var(--ease), transform 2.5s var(--ease);
}
.hero img.loaded { opacity: 1; transform: scale(1); }
.hero::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(0,0,0,.05) 30%, rgba(0,0,0,.45));
}
.hero-text {
  position: absolute; inset: auto 0 0 0; z-index: 1;
  padding: 0 24px 9svh; text-align: center; color: #fff;
  animation: fadeUp 1s .2s var(--ease) both;
}
.hero-text h1 { font-family: var(--serif); font-weight: 400; font-size: clamp(2.4rem, 6vw, 4.6rem); line-height: 1.05; margin: 0; }
.hero-meta { margin-top: .9rem; font-size: .72rem; letter-spacing: .3em; text-transform: uppercase; opacity: .9; }
.hero-scroll {
  margin-top: 2rem; background: none; border: 1px solid rgba(255,255,255,.7); color: #fff;
}
.hero-scroll:hover { background: #fff; color: var(--text); }
.hero.no-image { height: 46svh; min-height: 320px; }
.hero.no-image::after { display: none; }
.hero.no-image .hero-text { color: var(--text); inset: 0; display: grid; place-content: center; padding-bottom: 0; }
.hero.no-image .hero-scroll { display: none; }

/* ---------- Leiste ---------- */
.bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 22px;
  background: rgba(250, 249, 247, .86);
  backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid transparent; transition: border-color .3s;
}
.bar.scrolled { border-bottom-color: var(--line); }
.bar-brand { font-family: var(--serif); font-size: 1.35rem; font-weight: 500; line-height: 1; }
.bar-brand small { display: block; font-family: var(--sans); font-size: .68rem; letter-spacing: .12em; color: var(--muted); margin-top: .25rem; font-weight: 400; }
.bar-actions { display: flex; align-items: center; gap: 6px; }

/* ================================================================
   Galerie – Raster (Blocksatz-Layout mit echten Seitenverhältnissen)
   ================================================================ */
.grid {
  display: flex; flex-wrap: wrap; gap: 6px;
  max-width: 1800px; margin: 0 auto; padding: 8px 22px 80px;
}
.grid::after { content: ''; flex-grow: 999999; }
.tile {
  --r: 1.5;
  position: relative; overflow: hidden;
  flex-grow: var(--r); width: calc(var(--r) * 270px);
  background: var(--soft); cursor: zoom-in;
  border: none; padding: 0; text-align: left;
}
.tile > i { display: block; padding-bottom: calc(100% / var(--r)); }
.tile img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  opacity: 0; transition: opacity .5s, transform .5s var(--ease);
}
.tile img.loaded { opacity: 1; }
.tile:hover img { transform: scale(1.025); }

.tile-dl {
  position: absolute; right: 10px; bottom: 10px;
  display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%;
  background: rgba(255,255,255,.92); color: var(--text); border: none;
  opacity: 0; transform: translateY(6px); transition: opacity .2s, transform .2s;
  box-shadow: 0 4px 14px rgba(0,0,0,.15);
}
.tile:hover .tile-dl, .tile-dl:focus-visible { opacity: 1; transform: none; }
@media (hover: none) { .tile-dl { display: none; } }

.tile-check {
  position: absolute; top: 10px; left: 10px;
  display: none; place-items: center; width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid #fff; background: rgba(0,0,0,.18); color: transparent;
  box-shadow: 0 2px 8px rgba(0,0,0,.2); transition: background .15s;
}
.selecting .tile { cursor: pointer; }
.selecting .tile-check { display: grid; }
.selecting .tile-dl { display: none; }
.tile.selected .tile-check { background: var(--text); color: #fff; }
.tile.selected img { transform: scale(.9); }
.tile.selected { background: #e2ddd5; }

.empty { text-align: center; padding: 80px 24px; color: var(--muted); }
.empty h2 { font-family: var(--serif); font-weight: 400; color: var(--text); font-size: 1.8rem; margin: 0 0 .5rem; }

.footer { text-align: center; padding: 40px 24px 60px; border-top: 1px solid var(--line); color: var(--muted); font-size: .8rem; }
.footer .brand { font-size: 1.5rem; color: var(--text); margin-bottom: .5rem; }
.footer a { text-decoration: none; border-bottom: 1px solid var(--line); margin: 0 .5rem; }
.footer a:hover { border-color: var(--text); color: var(--text); }

/* ---------- Auswahl-Leiste ---------- */
.selbar {
  position: fixed; left: 50%; bottom: 22px; z-index: 30;
  display: flex; align-items: center; gap: 6px;
  padding: 8px 8px 8px 20px; border-radius: 999px;
  background: var(--text); color: var(--bg); box-shadow: var(--shadow);
  transform: translate(-50%, 140%); transition: transform .35s var(--ease), visibility .35s;
  max-width: calc(100vw - 24px); visibility: hidden;
}
.selbar.open { transform: translate(-50%, 0); visibility: visible; }
.selbar-count { font-size: .85rem; margin-right: 8px; white-space: nowrap; }
.selbar .btn { border-color: transparent; color: var(--bg); }
.selbar .btn:hover { background: rgba(255,255,255,.12); }
.selbar .btn-primary { background: var(--bg); color: var(--text); }
.selbar .btn-primary:hover { opacity: .9; background: var(--bg); }
.selbar .btn:disabled:hover { background: transparent; }
.selbar .btn-primary:disabled:hover { background: var(--bg); }

/* ================================================================
   Lightbox
   ================================================================ */
.lightbox {
  position: fixed; inset: 0; z-index: 50;
  background: var(--bg);
  display: grid; grid-template-rows: auto 1fr auto;
  opacity: 0; pointer-events: none; transition: opacity .25s;
}
.lightbox.open { opacity: 1; pointer-events: auto; }
.lb-top, .lb-bottom { display: flex; align-items: center; justify-content: space-between; padding: 12px 18px; gap: 12px; }
.lb-bottom { justify-content: center; padding-bottom: max(18px, env(safe-area-inset-bottom)); }
.lb-counter { font-size: .8rem; letter-spacing: .12em; color: var(--muted); }
.lb-stage { position: relative; min-height: 0; overflow: hidden; touch-action: pan-y; }
/* Bild füllt die Bühne und wird per object-fit immer vollständig eingepasst */
.lb-stage img {
  position: absolute; top: 0; bottom: 0; left: 70px; right: 70px;
  width: calc(100% - 140px); height: 100%;
  object-fit: contain;
  transition: opacity .25s;
  -webkit-user-select: none; user-select: none;
}
.lb-stage img.fading { opacity: 0; }
.lb-nav {
  position: absolute; z-index: 2; top: 50%; transform: translateY(-50%);
  width: 52px; height: 52px; border-radius: 50%; border: none;
  background: transparent; display: grid; place-items: center;
}
.lb-nav:hover { background: var(--soft); }
.lb-prev { left: 10px; }
.lb-next { right: 10px; }
.lb-nav .icon { width: 26px; height: 26px; }
@media (max-width: 700px) {
  .lb-stage img { left: 0; right: 0; width: 100%; }
  .lb-nav { display: none; }
}

/* ---------- Fortschritt / Toast ---------- */
.toast {
  position: fixed; left: 50%; top: 18px; z-index: 60;
  min-width: 280px; max-width: calc(100vw - 24px);
  padding: 14px 18px; border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow); border: 1px solid var(--line);
  transform: translate(-50%, -160%); transition: transform .35s var(--ease), visibility .35s;
  font-size: .88rem; visibility: hidden;
}
.toast.open { transform: translate(-50%, 0); visibility: visible; }
.toast.error { border-color: var(--danger); color: var(--danger); }
.toast-row { display: flex; align-items: center; gap: 10px; }
.progress { height: 3px; background: var(--soft); border-radius: 3px; overflow: hidden; margin-top: 10px; }
.progress > div { height: 100%; width: 0; background: var(--text); transition: width .25s; }

@media (max-width: 700px) {
  .bar { padding: 10px 14px; }
  .bar-brand small { display: none; }
  .bar .btn-label { display: none; }
  .bar .btn { padding: .6rem .75rem; }
  .grid { gap: 3px; padding: 3px 3px 90px; }
  .tile { width: calc(var(--r) * 150px); }
  .selbar { padding-left: 16px; bottom: 14px; }
  .selbar .btn-label { display: none; }
}

/* ================================================================
   Admin
   ================================================================ */
.admin-wrap { max-width: 1100px; margin: 0 auto; padding: 32px 22px 80px; }
.admin-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 32px; flex-wrap: wrap; }
.admin-head h1 { font-family: var(--serif); font-weight: 400; font-size: 2.2rem; margin: 0; line-height: 1.1; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 24px; }
.card + .card { margin-top: 20px; }
.card h2 { font-family: var(--serif); font-weight: 500; font-size: 1.4rem; margin: 0 0 16px; }

.create-form { display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: 12px; align-items: end; }
@media (max-width: 800px) { .create-form { grid-template-columns: 1fr; } }
.code-field { display: flex; gap: 6px; }
.code-field .input { text-transform: uppercase; letter-spacing: .12em; font-weight: 500; }

.event-list { display: grid; gap: 10px; }
.event-row {
  display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center;
  padding: 16px 18px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg); transition: border-color .2s;
}
.event-row:hover { border-color: #cfc9bf; }
.event-row h3 { margin: 0; font-size: 1rem; font-weight: 500; }
.event-meta { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .8rem; color: var(--muted); margin-top: 4px; }
.pill { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: .8rem; background: var(--soft); padding: 2px 8px; border-radius: 6px; color: var(--text); letter-spacing: .06em; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 700px) { .event-row { grid-template-columns: 1fr; } .row-actions { justify-content: flex-start; } }

.dropzone {
  display: grid; place-items: center; gap: 8px; text-align: center;
  padding: 44px 20px; border: 1.5px dashed #cfc9bf; border-radius: 16px;
  background: var(--bg); cursor: pointer; transition: border-color .2s, background .2s;
}
.dropzone:hover, .dropzone.over { border-color: var(--text); background: var(--soft); }
.dropzone .icon { width: 32px; height: 32px; color: var(--muted); }
.dropzone strong { font-weight: 500; }

.upload-status { margin-top: 16px; }
.upload-summary { display: flex; justify-content: space-between; font-size: .85rem; margin-bottom: 6px; }
.upload-errors { margin: 10px 0 0; padding: 0; list-style: none; font-size: .8rem; color: var(--danger); }

.admin-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.admin-thumb { position: relative; aspect-ratio: 1; background: var(--soft); border-radius: 8px; overflow: hidden; }
.admin-thumb img { width: 100%; height: 100%; object-fit: cover; }
.admin-thumb button {
  position: absolute; top: 6px; right: 6px; width: 30px; height: 30px; border-radius: 50%;
  border: none; background: rgba(255,255,255,.92); color: var(--danger);
  display: grid; place-items: center; opacity: 0; transition: opacity .2s;
}
.admin-thumb:hover button { opacity: 1; }
@media (hover: none) { .admin-thumb button { opacity: 1; } }
.admin-thumb span {
  position: absolute; inset: auto 0 0 0; padding: 14px 6px 4px; font-size: .68rem; color: #fff;
  background: linear-gradient(transparent, rgba(0,0,0,.55));
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.back-link { display: inline-flex; align-items: center; gap: 6px; background: none; border: none; padding: 0; color: var(--muted); font-size: .85rem; margin-bottom: 10px; }
.back-link:hover { color: var(--text); }
