:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #0284c7;
  --accent-text: #ffffff;
  --danger: #dc2626;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0d10;
    --card: #171a1f;
    --text: #f3f4f6;
    --muted: #9ca3af;
    --line: #2a2f36;
    --accent: #38bdf8;
    --accent-text: #04121c;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }

main, .panel {
  min-height: 100%;
  padding: calc(env(safe-area-inset-top) + 8px) 16px calc(env(safe-area-inset-bottom) + 16px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
h1 { font-size: 28px; margin: 4px 0; }
.panel h1 { font-size: 18px; }
h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 8px 0 0; }

button {
  font: inherit;
  border: 0;
  border-radius: 12px;
  padding: 14px 16px;
  cursor: pointer;
}
button:disabled { opacity: .4; }
.primary { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.secondary { background: var(--card); color: var(--text); border: 1px solid var(--line); }
.link { background: none; color: var(--accent); padding: 8px 0; }
.icon { background: none; color: var(--text); font-size: 26px; padding: 4px 8px; }
.row { display: flex; gap: 10px; }
.row > button { flex: 1; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.card p { margin: 0 0 10px; }
.notice { background: #fef3c7; color: #78350f; border-radius: 12px; padding: 10px 12px; font-size: 14px; }
.target { margin: 0; color: var(--muted); font-size: 14px; word-break: break-word; }
.target strong { color: var(--text); font-weight: 600; }
.empty { color: var(--muted); text-align: center; margin: 40px 0; }

.pages {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px;
  flex: 1; align-content: start;
}
.pages li { position: relative; }
.pages img {
  width: 100%; aspect-ratio: 3 / 4; object-fit: contain; display: block;
  border-radius: 8px; border: 1px solid var(--line); background: #fff;
}
.pages .num {
  position: absolute; left: 6px; bottom: 6px; background: rgba(0,0,0,.6); color: #fff;
  font-size: 12px; border-radius: 6px; padding: 1px 6px;
}
.pages .del {
  position: absolute; right: -6px; top: -6px; width: 28px; height: 28px; padding: 0;
  border-radius: 50%; background: var(--danger); color: #fff; font-size: 16px; line-height: 28px;
}

.actions { display: flex; flex-direction: column; gap: 10px; position: sticky; bottom: 0; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.field input {
  font: inherit; font-size: 16px; color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px;
}

/* Vollbild-Ansichten */
.fullscreen { position: fixed; inset: 0; background: var(--bg); z-index: 10; overflow: auto; }
#view-crop { background: #000; display: flex; flex-direction: column; overflow: hidden; }
.crop-stage {
  flex: 1; position: relative; display: flex; align-items: center; justify-content: center;
  margin: calc(env(safe-area-inset-top) + 12px) 12px 8px; min-height: 0;
}
#crop-canvas { max-width: 100%; max-height: 100%; display: block; }
#crop-svg { position: absolute; touch-action: none; overflow: visible; }
#crop-svg polygon { fill: rgba(56,189,248,.18); stroke: #38bdf8; }
#crop-svg circle.h { fill: rgba(255,255,255,.9); stroke: #0284c7; }
.crop-bar {
  padding: 8px 16px calc(env(safe-area-inset-bottom) + 12px);
  display: flex; flex-direction: column; gap: 10px;
}
.crop-bar .secondary { background: #1f2329; color: #fff; border-color: #333; }
.seg { display: flex; background: #1f2329; border-radius: 12px; padding: 3px; }
.seg button { flex: 1; background: none; color: #ccc; padding: 9px 4px; border-radius: 9px; font-size: 14px; }
.seg button.on { background: #fff; color: #000; font-weight: 600; }

.crumbs { margin: 0; font-size: 14px; color: var(--muted); }
.crumbs a { color: var(--accent); text-decoration: none; }
.folders { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.folders li { border-top: 1px solid var(--line); }
.folders li:first-child { border-top: 0; }
.folders button { width: 100%; text-align: left; background: none; color: var(--text); border-radius: 0; padding: 14px; }
.folders .none { padding: 14px; color: var(--muted); }

.busy {
  position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.45);
  display: flex; flex-direction: column; align-items: center; justify-content: center; color: #fff;
}
.spinner { width: 40px; height: 40px; border: 4px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 20px); z-index: 40;
  background: #111827; color: #fff; border-radius: 12px; padding: 12px 14px; font-size: 14px; text-align: center;
}
.toast.err { background: var(--danger); }
