:root {
  --bg: #f6f3ec;
  --surface: #ffffff;
  --surface-2: #efebe2;
  --text: #1d2430;
  --muted: #6b7280;
  --border: #ddd6c8;
  --primary: #1f3a5f;
  --primary-text: #ffffff;
  --accent: #e8772e;
  --danger: #b3261e;
  --radius: 12px;
  --shadow: 0 8px 30px rgba(20, 30, 50, .14);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161d;
    --surface: #1a2029;
    --surface-2: #232b36;
    --text: #e6e8ec;
    --muted: #98a2b3;
    --border: #2f3946;
    --primary: #6f9fd8;
    --primary-text: #0d1420;
    --accent: #f0904f;
    --danger: #ef6b62;
    --shadow: 0 8px 30px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text); font: 16px/1.5 var(--font);
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }

.app { display: flex; flex-direction: column; height: 100dvh; }

/* Kopfzeile */
.topbar {
  position: relative; display: flex; align-items: center; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; white-space: nowrap; }
.brand img { border-radius: 7px; }
.search { flex: 1; min-width: 0; }
.search input {
  width: 100%; padding: 8px 12px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface-2); outline: none;
}
.search input:focus { border-color: var(--primary); }

.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.icon { padding: 8px 12px; font-size: 18px; line-height: 1; }

.menu {
  position: absolute; right: 12px; top: calc(100% + 4px); z-index: 20; min-width: 270px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 6px; display: flex; flex-direction: column;
}
.menu button { text-align: left; padding: 10px 12px; border: 0; background: none; border-radius: 8px; cursor: pointer; }
.menu button:hover { background: var(--surface-2); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; width: 100%; }

.banner {
  padding: 10px 14px; background: color-mix(in srgb, var(--accent) 18%, var(--surface));
  border-bottom: 1px solid var(--border); display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
}

/* Layout */
.layout { flex: 1; display: flex; min-height: 0; }
.pane { min-height: 0; }
.list-pane { width: 360px; flex-shrink: 0; overflow-y: auto; border-right: 1px solid var(--border); }
.editor-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--surface); }
.placeholder { align-items: center; justify-content: center; }

.list-head { padding: 10px 14px 4px; display: flex; flex-direction: column; gap: 6px; }
.tagbar { display: flex; gap: 6px; flex-wrap: wrap; }
.tag {
  font-size: 12px; padding: 2px 9px; border-radius: 999px; background: var(--surface-2);
  border: 1px solid var(--border); cursor: pointer;
}
.tag.active { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }

.note-list { list-style: none; margin: 0; padding: 4px 8px 24px; }
.note-item {
  display: flex; gap: 10px; padding: 10px; border-radius: 10px; cursor: pointer; align-items: flex-start;
}
.note-item:hover { background: var(--surface-2); }
.note-item.active { background: color-mix(in srgb, var(--primary) 14%, var(--surface)); }
.note-item .thumb { width: 72px; height: 44px; border-radius: 6px; object-fit: cover; flex-shrink: 0; background: var(--surface-2); }
.note-item .txt { min-width: 0; flex: 1; }
.note-item .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-item .s { color: var(--muted); font-size: 14px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.note-item .m { color: var(--muted); font-size: 12px; margin-top: 2px; }

.empty { padding: 32px 20px; text-align: center; color: var(--muted); }
.empty .big { font-size: 20px; color: var(--text); margin-bottom: 4px; }

/* Editor */
.editor-head { display: flex; gap: 8px; align-items: center; padding: 12px 16px 6px; }
.ed-title {
  flex: 1; min-width: 0; font-size: 22px; font-weight: 700; border: 0; background: none; outline: none; padding: 4px 0;
}
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; flex-shrink: 0; }
.seg-btn { border: 0; background: none; padding: 6px 12px; cursor: pointer; font-size: 14px; }
.seg-btn.active { background: var(--primary); color: var(--primary-text); }
.editor-meta { display: flex; gap: 10px; align-items: center; padding: 0 16px 8px; border-bottom: 1px solid var(--border); }
.editor-meta input { flex: 1; min-width: 0; border: 0; background: none; outline: none; color: var(--muted); font-size: 14px; }
.ed-body {
  flex: 1; width: 100%; border: 0; outline: none; resize: none; padding: 16px; background: none;
  font: 15px/1.6 var(--mono);
}
.preview { flex: 1; overflow-y: auto; padding: 16px 20px 40px; }
.editor-foot {
  display: flex; gap: 8px; align-items: center; padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Markdown-Darstellung */
.md { line-height: 1.65; overflow-wrap: anywhere; }
.md h1, .md h2, .md h3 { line-height: 1.25; margin: 1.2em 0 .5em; }
.md a { color: var(--primary); }
.md img { max-width: 100%; border-radius: 8px; }
.md code { font-family: var(--mono); background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: .92em; }
.md pre { background: var(--surface-2); padding: 12px; border-radius: 8px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md blockquote { margin: 0; padding: 2px 14px; border-left: 3px solid var(--accent); color: var(--muted); }
.md table { border-collapse: collapse; }
.md th, .md td { border: 1px solid var(--border); padding: 4px 8px; }
.md hr { border: 0; border-top: 1px solid var(--border); }
.md li input[type=checkbox] { margin-right: 6px; }

.yt {
  position: relative; display: block; width: 100%; max-width: 640px; aspect-ratio: 16 / 9;
  border-radius: 10px; overflow: hidden; background: #000; border: 0; padding: 0; cursor: pointer;
}
.yt img { width: 100%; height: 100%; object-fit: cover; border-radius: 0; display: block; }
.yt .play {
  position: absolute; inset: 0; margin: auto; width: 68px; height: 48px; border-radius: 12px;
  background: rgba(220, 0, 0, .9); color: #fff; font-size: 22px; display: flex; align-items: center; justify-content: center;
}
.yt iframe { width: 100%; height: 100%; border: 0; }

/* Clip-Formular und Dialog */
.sheet-wrap {
  position: fixed; inset: 0; z-index: 50; background: rgba(10, 14, 20, .45);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 560px; max-height: 92dvh; overflow-y: auto; background: var(--surface);
  border-radius: 18px 18px 0 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 12px; box-shadow: var(--shadow);
}
@media (min-width: 700px) {
  .sheet-wrap { align-items: center; }
  .sheet { border-radius: 18px; }
}
.sheet h2 { margin: 0; font-size: 20px; }
.sheet label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 600; }
.sheet input, .sheet textarea, .sheet select {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2);
  font-weight: 400; font-size: 16px; color: var(--text);
}
.sheet .row { display: flex; gap: 8px; align-items: center; }
.clip-preview:empty { display: none; }
.clip-preview { display: flex; gap: 12px; align-items: center; padding: 10px; background: var(--surface-2); border-radius: 10px; }
.clip-preview img { width: 120px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 6px; }
.clip-preview .badge { font-size: 12px; font-weight: 700; color: #fff; background: #d00; padding: 2px 8px; border-radius: 999px; }
#dialog-body h3 { margin: 0 0 8px; }
#dialog-body p, #dialog-body li { font-size: 15px; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; z-index: 60;
  box-shadow: var(--shadow); font-size: 14px; max-width: 90vw;
}

.only-sm { display: none; }

/* Smartphone: entweder Liste oder Editor */
@media (max-width: 799px) {
  .hide-sm { display: none; }
  .brand span { display: none; }
  .only-sm { display: inline-flex; }
  .list-pane { width: 100%; border-right: 0; }
  .placeholder { display: none !important; }
  .app.editing .list-pane { display: none; }
  .app:not(.editing) .editor-pane { display: none !important; }
  .ed-title { font-size: 19px; }
}
