:root {
  --bg: #0f1115;
  --surface: #181b22;
  --surface-2: #20242d;
  --border: #2a2f3a;
  --text: #e8eaf0;
  --muted: #8b93a5;
  --accent: #3b82f6;
  --danger: #ef4444;
  --radius: 14px;
  --gap: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

button, input { font: inherit; color: inherit; }

/* ---------- Kopfzeile ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + var(--safe-top)) calc(16px + var(--safe-right)) 10px calc(16px + var(--safe-left));
  background: rgba(15, 17, 21, 0.85);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}
.title { margin: 0; font-size: 1.2rem; font-weight: 600; letter-spacing: .01em; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-right: -8px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color .15s, background .15s, transform .3s;
}
.icon-btn:hover, .icon-btn:focus-visible { color: var(--text); background: var(--surface-2); }
.icon-btn:active { transform: rotate(45deg); }

/* ---------- Raster ---------- */
.grid {
  display: grid;
  gap: var(--gap);
  padding: 8px calc(16px + var(--safe-right)) calc(24px + var(--safe-bottom)) calc(16px + var(--safe-left));
  /* grid-template-columns wird per JS gesetzt */
}

.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1 / 1;
  min-width: 0;
  overflow: hidden;
  container-type: inline-size;
  border-radius: 22%;
  background: var(--surface);
  color: #fff;
  text-decoration: none;
  box-shadow: 0 1px 2px rgba(0,0,0,.4), inset 0 0 0 1px rgba(255,255,255,.04);
  transition: transform .12s ease, filter .12s ease;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.tile:hover { filter: brightness(1.12); }
.tile:active { transform: scale(.95); }
.tile:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

.tile-icon {
  width: 62%;
  height: 62%;
  object-fit: contain;
  border-radius: 18%;
  pointer-events: none;
}
.tile.has-label .tile-icon { width: 54%; height: 54%; margin-top: -10%; }

.tile-letter {
  font-size: 48cqw;
  font-weight: 650;
  line-height: 1;
  text-shadow: 0 1px 2px rgba(0,0,0,.2);
  pointer-events: none;
}
.tile.has-label .tile-letter { font-size: 40cqw; margin-top: -10%; }

.tile-label {
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: 8%;
  font-size: max(10px, 10cqw);
  font-weight: 500;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: .92;
  pointer-events: none;
}
.tile.is-icon .tile-label { color: var(--text); }

@container (max-width: 72px) {
  .tile-label { display: none; }
  .tile.has-label .tile-icon { width: 62%; height: 62%; margin-top: 0; }
  .tile.has-label .tile-letter { font-size: 48cqw; margin-top: 0; }
}

.empty {
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 18vh 24px;
  color: var(--muted);
  text-align: center;
}

/* ---------- Einstellungen ---------- */
.settings {
  display: grid;
  gap: 16px;
  max-width: 760px;
  margin: 0 auto;
  padding: 8px calc(16px + var(--safe-right)) calc(32px + var(--safe-bottom)) calc(16px + var(--safe-left));
}

.card {
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.card h2 { margin: 0 0 14px; font-size: 1rem; font-weight: 600; }

.muted { color: var(--muted); font-size: .9rem; margin: 0 0 14px; }

.field { display: grid; gap: 6px; margin-bottom: 14px; min-width: 0; }
.field > span { font-size: .85rem; color: var(--muted); }
.field small { font-size: .8em; }

input[type="text"], input[type="number"] {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  font-size: 16px; /* verhindert Zoom auf iOS */
  outline: none;
}
input[type="text"]:focus, input[type="number"]:focus { border-color: var(--accent); }

input[type="color"] {
  width: 100%;
  height: 46px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  cursor: pointer;
}

.row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 12px; align-items: end; }
.row-3 { grid-template-columns: repeat(3, 1fr); align-items: start; }
@media (max-width: 560px) {
  .row-3 { grid-template-columns: 1fr; gap: 0; }
}

.preview-tile {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 22%;
  background: var(--surface-2);
  font-weight: 650;
  font-size: 22px;
  color: #fff;
  overflow: hidden;
}
.preview-tile img { width: 70%; height: 70%; object-fit: contain; border-radius: 18%; }

.check { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 14px; cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 1px 0 0; accent-color: var(--accent); flex: none; }

.actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.actions-left { justify-content: flex-start; }

.btn {
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  font-weight: 500;
  cursor: pointer;
  transition: filter .15s;
}
.btn:hover { filter: brightness(1.15); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Liste */
.item-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.item {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 8px;
  border-radius: 10px;
  background: var(--bg);
}
.item.editing { outline: 2px solid var(--accent); }
.item .preview-tile { width: 40px; height: 40px; font-size: 19px; }
.item-text { min-width: 0; }
.item-name, .item-url { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-name { font-weight: 500; }
.item-url { font-size: .8rem; color: var(--muted); }
.item-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 0 6px;
  border-radius: 6px;
  background: rgba(59,130,246,.18);
  color: #93c5fd;
  font-size: .7rem;
  font-weight: 600;
  vertical-align: 2px;
}
.item-actions { display: flex; gap: 2px; }
.mini-btn {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.mini-btn:hover { background: var(--surface-2); color: var(--text); }
.mini-btn.danger:hover { color: var(--danger); }
.mini-btn:disabled { opacity: .3; pointer-events: none; }
.mini-btn svg { width: 18px; height: 18px; }

@media (max-width: 420px) {
  .item { grid-template-columns: 40px 1fr; }
  .item-actions { grid-column: 1 / -1; justify-content: flex-end; }
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 50;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  font-size: .9rem;
}
