:root {
  --fg: #1c1f26;
  --fg-soft: rgba(28, 31, 38, 0.62);
  --panel: rgba(255, 255, 255, 0.58);
  --panel-line: rgba(255, 255, 255, 0.7);
  --dlg: #fbfbfd;
  --field: rgba(0, 0, 0, 0.05);
  --line: rgba(0, 0, 0, 0.1);
  --accent: #2f6df6;
  --danger: #d23b3b;
  --shade: rgba(255, 255, 255, 0);
  --tile-bg: rgba(255, 255, 255, 0.85);
  --shadow: 0 6px 18px rgba(30, 40, 70, 0.14);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fg: #f1f3f7;
    --fg-soft: rgba(241, 243, 247, 0.66);
    --panel: rgba(24, 27, 34, 0.55);
    --panel-line: rgba(255, 255, 255, 0.12);
    --dlg: #1d2028;
    --field: rgba(255, 255, 255, 0.08);
    --line: rgba(255, 255, 255, 0.14);
    --accent: #6b9bff;
    --danger: #ff7a7a;
    --shade: rgba(8, 10, 16, 0.55);
    --tile-bg: rgba(40, 44, 54, 0.9);
    --shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color: var(--fg);
  background: #cfd8e6;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }

/* Hintergründe */
.wallpaper { position: fixed; inset: 0; z-index: -1; background: var(--bg); }
.wallpaper::after { content: ""; position: absolute; inset: 0; background: var(--shade); }
[data-bg="aurora"]   { --bg: linear-gradient(135deg, #ffd2ad 0%, #ffe8a3 30%, #bfe3d3 58%, #a6c6f0 100%); }
[data-bg="dusk"]     { --bg: linear-gradient(135deg, #f7c5da 0%, #cdb8f2 50%, #9db7f2 100%); }
[data-bg="meadow"]   { --bg: linear-gradient(135deg, #e6f1b3 0%, #b7e3c6 50%, #8dd1c9 100%); }
[data-bg="ocean"]    { --bg: linear-gradient(135deg, #d3ecf8 0%, #9ad0ee 50%, #6ba6e0 100%); }
[data-bg="sand"]     { --bg: linear-gradient(135deg, #f8ecd9 0%, #ecd9bd 50%, #dcc6a4 100%); }
[data-bg="graphite"] { --bg: linear-gradient(135deg, #dcdfe5 0%, #b9bfca 50%, #99a2b1 100%); }

.page {
  max-width: 920px;
  margin: 0 auto;
  padding: max(8vh, 56px) 20px 96px;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 28px;
  padding: 22px 22px 26px;
  -webkit-backdrop-filter: blur(28px) saturate(1.5);
  backdrop-filter: blur(28px) saturate(1.5);
  box-shadow: var(--shadow);
}
h1 {
  margin: 0 0 18px 6px;
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

/* Raster */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 22px 16px;
}
.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-width: 0;
  outline: none;
}
.card {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 24px;
  overflow: hidden;
  background: var(--tile-bg);
  box-shadow: var(--shadow);
  color: inherit;
  text-decoration: none;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
a.card:hover { transform: translateY(-2px) scale(1.02); }
.tile:focus-visible .card, a.card:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.thumb { position: relative; display: block; width: 100%; height: 100%; }
.thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top left; display: block; }
.ph {
  display: grid; place-items: center; width: 100%; height: 100%;
  font-size: 40px; font-weight: 600; color: #fff;
  background: linear-gradient(145deg, hsl(var(--h, 215) 55% 62%), hsl(calc(var(--h, 215) + 28) 55% 52%));
}
.spin::after {
  content: ""; position: absolute; right: 8px; bottom: 8px; width: 16px; height: 16px;
  border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.55); border-top-color: #fff;
  background: rgba(0, 0, 0, 0.25); animation: turn 0.9s linear infinite;
}
@keyframes turn { to { transform: rotate(360deg); } }
.name {
  max-width: 100%;
  font-size: 13px;
  line-height: 1.25;
  text-align: center;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Bearbeiten */
.edit .tile { cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; }
.edit .card { animation: wiggle 0.34s ease-in-out infinite alternate; pointer-events: none; }
.edit .tile:nth-child(2n) .card { animation-delay: -0.17s; }
@keyframes wiggle { from { transform: rotate(-0.8deg); } to { transform: rotate(0.8deg); } }
.del {
  position: absolute; top: -8px; left: -8px; z-index: 2;
  width: 28px; height: 28px; border-radius: 50%; border: 0; padding: 0;
  display: none; place-items: center;
  background: #e9ebef; color: #333; font-size: 18px; line-height: 1;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3); cursor: pointer;
}
.edit .del { display: grid; }
.tile.dragging { position: fixed; z-index: 50; margin: 0; pointer-events: none; cursor: grabbing; }
.tile.dragging .card { animation: none; transform: scale(1.08); box-shadow: 0 16px 36px rgba(0, 0, 0, 0.3); }
.placeholder { border-radius: 24px; border: 2px dashed var(--line); aspect-ratio: 1 / 1; margin-bottom: 26px; }
.add .card {
  display: grid; place-items: center; border: 2px dashed var(--line);
  background: transparent; box-shadow: none; font-size: 38px; color: var(--fg-soft); cursor: pointer;
  pointer-events: auto; animation: none;
}
.add { cursor: pointer; touch-action: auto; }
.empty { margin: 10px 6px 0; color: var(--fg-soft); }

/* Leiste und Knöpfe */
.bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  display: flex; gap: 8px; align-items: center; justify-content: flex-end;
  padding: max(10px, env(safe-area-inset-top)) 14px 10px;
}
.status { margin-right: auto; padding: 6px 12px; font-size: 13px; color: var(--fg-soft); border-radius: 999px; }
.pill {
  border: 1px solid var(--panel-line); background: var(--panel); color: var(--fg);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  border-radius: 999px; padding: 8px 15px; font: inherit; font-size: 14px; cursor: pointer;
}
.pill.strong { background: var(--accent); border-color: transparent; color: #fff; font-weight: 600; }
.fab {
  position: fixed; right: max(18px, env(safe-area-inset-right)); bottom: max(18px, env(safe-area-inset-bottom)); z-index: 10;
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--panel-line);
  background: var(--panel); color: var(--fg-soft); display: grid; place-items: center; cursor: pointer;
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  opacity: 0.55; transition: opacity 0.2s;
}
.fab:hover, .fab:focus-visible { opacity: 1; }
button:focus-visible, input:focus-visible, .filebtn:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Dialoge */
dialog {
  width: min(440px, calc(100vw - 32px)); border: 0; border-radius: 22px; padding: 22px;
  background: var(--dlg); color: var(--fg); box-shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
}
dialog::backdrop { background: rgba(10, 14, 24, 0.35); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
dialog h2 { margin: 0 0 6px; font-size: 18px; }
.hint { margin: 0 0 14px; color: var(--fg-soft); font-size: 14px; }
label { display: block; margin: 12px 0 0; font-size: 13px; color: var(--fg-soft); }
input[type="text"], input[type="password"] {
  display: block; width: 100%; margin-top: 6px; padding: 11px 13px; font: inherit; font-size: 16px;
  color: var(--fg); background: var(--field); border: 1px solid var(--line); border-radius: 12px;
}
.err { min-height: 1.3em; margin: 10px 0 0; color: var(--danger); font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; margin-top: 14px; }
.grow { flex: 1; }
.btn {
  display: inline-block; border: 1px solid var(--line); background: transparent; color: var(--fg);
  border-radius: 12px; padding: 9px 14px; font: inherit; font-size: 14px; cursor: pointer; text-align: center;
}
.filebtn { margin: 0; }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; font-weight: 600; }
.btn.danger { color: var(--danger); }
.extras { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.swatches { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 14px 0 4px; }
.sw {
  aspect-ratio: 16 / 10; border-radius: 14px; border: 3px solid transparent; cursor: pointer; padding: 0;
  background: var(--bg); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}
.sw[aria-pressed="true"] { border-color: var(--accent); }

@media (max-width: 520px) {
  .page { padding-top: 64px; }
  .panel { padding: 16px 14px 20px; border-radius: 24px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 18px 12px; }
  .ph { font-size: 32px; }
}
@media (prefers-reduced-motion: reduce) {
  .edit .card, .spin::after { animation: none; }
  a.card, .fab { transition: none; }
}
