:root {
  --bg: #14161c;
  --surface: #1d2029;
  --surface-2: #262a35;
  --border: #323746;
  --text: #e8e6e1;
  --muted: #9a9ca6;
  --accent: #f4b860;
  --accent-text: #1a1408;
  --danger: #e57373;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}

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

button { cursor: pointer; }

a { color: var(--accent); }

/* Kopfzeile */
.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.icon-btn {
  min-width: 44px;
  min-height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  font-size: 1.4rem;
}
.icon-btn:active { background: var(--surface-2); }

.menu {
  position: absolute;
  right: 12px;
  top: calc(56px + env(safe-area-inset-top));
  display: flex;
  flex-direction: column;
  min-width: 240px;
  padding: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.4);
}
.menu[hidden] { display: none; }
.menu button {
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: left;
}
.menu button:active { background: var(--border); }

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 16px;
}

.intro p {
  margin: 16px 0 8px;
  color: var(--muted);
  font-size: 0.95rem;
}

/* Kategorie-Filter */
.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 0;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chips:empty { display: none; }

.chip {
  flex: none;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.9rem;
}
.chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

/* Liste */
.list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.card {
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.card-head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.card-title {
  flex: 1;
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.card-edit {
  flex: none;
  min-width: 44px;
  min-height: 44px;
  margin: -10px -12px -10px 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 1.1rem;
}
.card-edit:active { background: var(--surface-2); }

.card-link {
  display: inline-block;
  max-width: 100%;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.9rem;
  text-decoration: none;
}

.card-note {
  margin: 6px 0 0;
  color: var(--text);
  opacity: 0.85;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.95rem;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.8rem;
}

.tag {
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--accent);
}

.empty {
  margin: 48px 0;
  color: var(--muted);
  text-align: center;
}

/* Schwebender Hinzufügen-Knopf */
.fab {
  position: fixed;
  right: 20px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  width: 60px;
  height: 60px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 1.8rem;
  line-height: 1;
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.45);
}
.fab:active { transform: scale(0.96); }

/* Editor */
dialog {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / 0.6); }

dialog form {
  display: grid;
  gap: 14px;
  padding: 20px;
}

dialog h2 {
  margin: 0;
  font-size: 1.15rem;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.85rem;
}

input, textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  font-size: 1rem;
}
textarea { resize: vertical; }
input:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: transparent;
}

.actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 4px;
}
.actions .spacer { flex: 1; }
.actions button {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
}
.actions .primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}
.actions .danger {
  border-color: transparent;
  background: transparent;
  color: var(--danger);
  padding: 0 8px;
}

/* Hinweis unten */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.9rem;
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.4);
}
.toast[hidden] { display: none; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
