:root {
  --bg: #000;
  --surface: #111114;
  --surface-2: #1c1c21;
  --line: #2a2a31;
  --fg: #f4f4f6;
  --muted: #8e8e98;
  --accent: #8b7bff;
  --accent-2: #b4a9ff;
  --danger: #ff5a6e;
  --radius: 18px;
  --safe-t: env(safe-area-inset-top);
  --safe-b: env(safe-area-inset-bottom);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--fg); height: 100%; }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;               /* kein "Bild sichern" per Langdruck */
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- Sichtschutz ---------- */
#shield { position: fixed; inset: 0; background: #000; z-index: 1000; opacity: 0; pointer-events: none; }
#shield.on { opacity: 1; pointer-events: all; }

/* ---------- Screens ---------- */
.screen { min-height: 100dvh; padding: calc(var(--safe-t) + 12px) 16px calc(var(--safe-b) + 24px); }
.center { display: grid; place-items: center; }
.panel {
  width: min(380px, 100%); display: flex; flex-direction: column; gap: 12px; text-align: center;
  padding: 32px 24px 24px; border-radius: 28px;
  background: linear-gradient(180deg, #16161b, #0d0d10); border: 1px solid var(--line);
  box-shadow: 0 30px 80px -30px rgba(139, 123, 255, .25);
  animation: rise .5s cubic-bezier(.2, .8, .2, 1);
}
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(.98); } }
.emblem {
  width: 64px; height: 64px; margin: 0 auto 6px; border-radius: 20px; display: grid; place-items: center;
  background: radial-gradient(circle at 30% 20%, #a497ff, #5b4be0); color: #fff;
  box-shadow: 0 10px 30px -8px rgba(139, 123, 255, .7);
}
.emblem svg { width: 30px; height: 30px; }
h1 { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.sub { margin: 0 0 8px; color: var(--muted); font-size: 15px; }
.msg { margin: 0; min-height: 1.3em; font-size: 14px; color: var(--muted); }
.msg.bad { color: var(--danger); }
.row { display: flex; gap: 8px; }
.row .btn { flex: 1; }

.field {
  width: 100%; padding: 15px 16px; border-radius: 14px; font-size: 17px;
  border: 1px solid var(--line); background: #0a0a0d; color: var(--fg); outline: none;
  -webkit-user-select: text; user-select: text;
}
.field:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(139, 123, 255, .18); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  padding: 15px 18px; border: 0; border-radius: 14px; font: inherit; font-size: 17px; font-weight: 600;
  color: #fff; cursor: pointer; transition: transform .12s, opacity .2s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; }
.btn.primary { background: linear-gradient(180deg, #9a8cff, #6f5ef0); box-shadow: 0 8px 24px -10px rgba(139, 123, 255, .9); }
.btn.ghost { background: var(--surface-2); color: var(--fg); font-weight: 500; }

#dev { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; padding-top: 16px; border-top: 1px dashed var(--line); }
.tag { align-self: center; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: #ffcf5a; }

/* ---------- Galerie ---------- */
#gallery { padding: 0 0 calc(var(--safe-b) + 100px); }
.bar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center;
  padding: calc(var(--safe-t) + 10px) 16px 8px;
  background: rgba(0, 0, 0, .72); -webkit-backdrop-filter: saturate(160%) blur(20px); backdrop-filter: saturate(160%) blur(20px);
}
.bar h1 { flex: 1; font-size: 30px; }
.icon {
  width: 40px; height: 40px; border-radius: 50%; border: 0; display: grid; place-items: center;
  background: var(--surface-2); color: var(--fg); cursor: pointer;
}
.icon:active { transform: scale(.94); }
.icon.danger { color: var(--danger); }

.tabs {
  position: sticky; top: calc(var(--safe-t) + 58px); z-index: 4; display: flex; gap: 4px;
  margin: 0 16px 12px; padding: 4px; border-radius: 14px; background: var(--surface);
}
.tab {
  flex: 1; border: 0; padding: 9px 8px; border-radius: 10px; background: transparent; color: var(--muted);
  font: inherit; font-size: 15px; font-weight: 600; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background .2s, color .2s;
}
.tab .n { font-weight: 500; opacity: .7; margin-left: 4px; }
.tab[aria-selected="true"] { background: var(--surface-2); color: var(--fg); box-shadow: 0 1px 0 rgba(255,255,255,.05) inset; }

.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; padding: 0 2px; }
@media (min-width: 700px) { .grid { grid-template-columns: repeat(5, 1fr); padding: 0 16px; gap: 4px; } }
@media (min-width: 1100px) { .grid { grid-template-columns: repeat(7, 1fr); } }
.tile { position: relative; aspect-ratio: 1; overflow: hidden; background: var(--surface); cursor: pointer; }
@media (min-width: 700px) { .tile { border-radius: 8px; } }
.tile canvas { width: 100%; height: 100%; display: block; }
.tile.loading::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(110deg, transparent 30%, rgba(255,255,255,.06) 50%, transparent 70%);
  background-size: 200% 100%; animation: shimmer 1.2s infinite linear;
}
@keyframes shimmer { from { background-position: 150% 0; } to { background-position: -50% 0; } }
.tile:active canvas { opacity: .8; }

.empty { display: grid; place-items: center; gap: 8px; padding: 80px 24px; color: var(--muted); text-align: center; }
.empty svg { width: 48px; height: 48px; stroke-width: 1.3; }
.empty p { margin: 0; }

.fab {
  position: fixed; right: 20px; bottom: calc(var(--safe-b) + 22px); z-index: 6;
  width: 60px; height: 60px; border-radius: 50%; display: grid; place-items: center; cursor: pointer; color: #fff;
  background: linear-gradient(180deg, #9a8cff, #6f5ef0); box-shadow: 0 12px 30px -8px rgba(139, 123, 255, .9);
}
.fab svg { width: 28px; height: 28px; stroke-width: 2.2; }
.fab:active { transform: scale(.94); }

/* ---------- Vollbild ---------- */
#viewer { position: fixed; inset: 0; z-index: 50; background: #000; display: flex; flex-direction: column; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.vbar { position: absolute; left: 0; right: 0; z-index: 2; display: flex; align-items: center; gap: 12px; padding: 10px 16px; transition: opacity .2s; }
.vbar.top { top: 0; padding-top: calc(var(--safe-t) + 10px); background: linear-gradient(rgba(0,0,0,.6), transparent); }
.vbar.bottom { bottom: 0; justify-content: center; padding-bottom: calc(var(--safe-b) + 14px); background: linear-gradient(transparent, rgba(0,0,0,.6)); color: var(--muted); font-size: 13px; }
.vbar.top #v-count { flex: 1; text-align: center; font-size: 15px; font-weight: 600; }
.vbar .icon { background: rgba(40, 40, 48, .7); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); }
#viewer.chrome-off .vbar { opacity: 0; pointer-events: none; }
#v-stage { flex: 1; min-height: 0; display: grid; place-items: center; overflow: hidden; touch-action: none; }
#v-img { max-width: 100%; max-height: 100%; object-fit: contain; transition: transform .25s cubic-bezier(.2,.8,.2,1), opacity .25s; will-change: transform; }
#v-img.dragging { transition: none; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 96px); z-index: 60; transform: translate(-50%, 20px);
  padding: 10px 16px; border-radius: 999px; background: rgba(30, 30, 36, .92); color: var(--fg); font-size: 14px;
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); opacity: 0; pointer-events: none; transition: .25s;
  white-space: nowrap;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { color: var(--danger); }
