:root {
  --bg: #fafaf7;
  --surface: #ffffff;
  --text: #1d1d1b;
  --muted: #6b6b66;
  --border: #deded8;
  --accent: #1b5e9e;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --radius: 10px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615;
    --surface: #202020;
    --text: #ececE8;
    --muted: #9a9a94;
    --border: #36362f;
    --accent: #6fb0ef;
    --accent-text: #0d1b2a;
    --danger: #f2877f;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 1rem/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

#app {
  max-width: 40rem;
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
}

h1 { font-size: 1.5rem; margin: 0 0 1rem; }

.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 0.875rem; margin: 0; }
.error { color: var(--danger); margin: 0; }
.empty { color: var(--muted); padding: 2rem 0; text-align: center; }

form { display: flex; flex-direction: column; gap: 0.875rem; }

label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.9375rem; }

input, select {
  font: inherit;
  min-height: 2.75rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

input:focus-visible, select:focus-visible, button:focus-visible, summary:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button {
  font: inherit;
  min-height: 2.75rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

button:disabled { opacity: 0.6; cursor: progress; }

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.tabs button[aria-selected="true"] {
  border-color: var(--accent);
  box-shadow: inset 0 -3px 0 var(--accent);
  font-weight: 600;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin-bottom: 1rem;
}

.topbar h1 { margin: 0; }

.who { display: flex; align-items: center; gap: 0.5rem; margin-left: auto; min-width: 0; }

.success { color: var(--accent); margin: 0; }

.danger-btn { border-color: var(--danger); color: var(--danger); font-weight: 600; }

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

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.wide { width: 100%; margin-top: 0.75rem; }

/* Artikel hinzufügen */
.add-form { flex-direction: row; gap: 0.5rem; margin-bottom: 0.5rem; }
.add-form input { flex: 1; min-width: 0; }
#add-status, #add-error { margin: 0.25rem 0 0.5rem; }

/* Artikelliste */
.article-list { list-style: none; margin: 1rem 0 0; padding: 0; display: flex; flex-direction: column; gap: 0.75rem; }

.article {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.article-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  padding: 0.75rem 1rem;
  color: inherit;
  text-decoration: none;
  border-radius: var(--radius);
}

.article-main:hover .article-title { text-decoration: underline; }
.article-title { font-weight: 600; overflow-wrap: anywhere; }
.article-meta { color: var(--muted); font-size: 0.8125rem; }

.article-excerpt {
  color: var(--muted);
  font-size: 0.9375rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.icon-btn { border: 0; border-left: 1px solid var(--border); border-radius: 0 var(--radius) var(--radius) 0; background: transparent; color: var(--muted); font-size: 0.875rem; }
.icon-btn:hover { color: var(--danger); }

/* Lesemodus */
.reader-nav { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1rem; margin-bottom: 1rem; min-height: 2.75rem; }
.reader-nav a { display: inline-flex; align-items: center; min-height: 2.75rem; white-space: nowrap; }
#reader-title { overflow-wrap: anywhere; line-height: 1.25; }
#reader-meta { margin-top: -0.5rem; font-size: 0.875rem; }

.prose { font-size: 1.0625rem; line-height: 1.7; overflow-wrap: anywhere; }
.prose img { max-width: 100%; height: auto; border-radius: 6px; }
.prose figure { margin: 1rem 0; }
.prose figcaption { color: var(--muted); font-size: 0.875rem; }
.prose blockquote { margin: 1rem 0; padding: 0 0 0 1rem; border-left: 3px solid var(--border); color: var(--muted); }
.prose pre { overflow-x: auto; padding: 0.75rem; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; font-size: 0.875rem; }
.prose code { font-size: 0.9em; }
.prose table { display: block; overflow-x: auto; border-collapse: collapse; }
.prose th, .prose td { border: 1px solid var(--border); padding: 0.25rem 0.5rem; }

/* Suche, Filter, Schlagwörter */
.filter { flex-direction: row; gap: 0.5rem; margin-top: 1rem; }
.filter input { flex: 1; min-width: 0; }

.tag-bar { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.75rem; }
.tag-chip { min-height: 2.25rem; padding: 0.25rem 0.75rem; border-radius: 999px; font-size: 0.875rem; }
.tag-chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.tag-count { opacity: 0.7; margin-left: 0.25rem; }

.article-tags { color: var(--accent); font-size: 0.8125rem; overflow-wrap: anywhere; }
.article.is-read .article-title { font-weight: 400; color: var(--muted); }
.article-excerpt mark { background: color-mix(in srgb, var(--accent) 30%, transparent); color: inherit; border-radius: 2px; }

.article-actions { display: flex; flex-direction: column; border-left: 1px solid var(--border); }
.article-actions .icon-btn { flex: 1; border: 0; border-radius: 0; font-size: 0.8125rem; min-height: 2.25rem; }
.article-actions .icon-btn + .icon-btn { border-top: 1px solid var(--border); }
.article-actions .icon-btn:first-child { border-top-right-radius: var(--radius); }
.article-actions .icon-btn:last-child { border-bottom-right-radius: var(--radius); }
.article-actions .icon-btn.toggle:hover { color: var(--accent); }

.reader-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.5rem; }
.tags-form { margin: 0 0 1rem; align-items: flex-end; }
.tags-form label { flex: 1; min-width: 0; }

/* Benutzermenü */
.user-menu { position: relative; min-width: 0; }
.user-btn { display: flex; align-items: center; gap: 0.375rem; max-width: 14rem; }
.user-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu {
  position: absolute;
  right: 0;
  z-index: 10;
  min-width: 12rem;
  margin: 0.25rem 0 0;
  padding: 0.25rem;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgb(0 0 0 / 0.15);
}
.menu a {
  display: flex;
  align-items: center;
  min-height: 2.75rem;
  padding: 0.25rem 0.75rem;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
}
.menu a:hover { background: var(--bg); }
.menu .menu-danger { color: var(--danger); }

/* Eigene Seiten für Kontoaktionen */
.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; }
.button-link {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
}
#home-notice { margin: 0 0 0.75rem; }

/* Teilen aus anderen Apps */
.token-created {
  display: grid;
  gap: 0.5rem;
  margin: 1rem 0;
  padding: 1rem;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--surface);
}
.token-created p { margin: 0; }
.token-created input { width: 100%; font-family: ui-monospace, monospace; }
.token-list { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; gap: 0.5rem; }
.token-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.token-info { display: grid; gap: 0.125rem; min-width: 0; }
#view-share code { overflow-wrap: anywhere; }
#view-share details { margin: 0.5rem 0; }
#view-share summary { cursor: pointer; min-height: 2.75rem; display: flex; align-items: center; }

/* Markierungen und Notizen im Lesemodus */
.reader-body { position: relative; }

mark.hl {
  --hl: #ffd93d;
  background: color-mix(in srgb, var(--hl) 50%, transparent);
  color: inherit;
  border-radius: 2px;
  cursor: pointer;
  padding: 0.05em 0;
}
mark.hl.has-note { box-shadow: 0 2px 0 var(--hl); }
mark.hl.hl-active { outline: 2px solid var(--accent); outline-offset: 1px; }
.hl-off mark.hl { background: none; box-shadow: none; cursor: auto; outline: none; }

.notes { margin-top: 1.5rem; display: flex; flex-direction: column; gap: 0.5rem; }
.note {
  --hl: #ffd93d;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  width: 100%;
  min-height: 0;
  padding: 0.5rem 0.75rem;
  text-align: left;
  font-size: 0.875rem;
  line-height: 1.4;
  border: 1px solid var(--border);
  border-left: 5px solid var(--hl);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-weight: 400;
}
.note-quote { color: var(--muted); font-style: italic; overflow-wrap: anywhere; }
.note-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.note-lost { color: var(--danger); font-size: 0.8125rem; }
.note-active { outline: 2px solid var(--accent); }

/* Breite Fenster: Notizen stehen im rechten Rand neben dem Text. */
.notes.notes-margin {
  position: absolute;
  top: 0;
  left: 100%;
  width: 14rem;
  margin: 0 0 0 1.25rem;
  display: block;
}
.notes.notes-margin .note { position: absolute; left: 0; }

.hl-panel {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  z-index: 20;
  width: min(100%, 40rem);
  max-height: 70vh;
  overflow-y: auto;
  padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom));
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: 0 -4px 16px rgb(0 0 0 / 0.15);
}
.hl-title { margin: 0; font-weight: 600; padding-right: 2.75rem; }
.hl-quote { margin: 0.25rem 0 0.5rem; color: var(--muted); font-style: italic; overflow-wrap: anywhere; }
.hl-close { position: absolute; top: 0.25rem; right: 0.25rem; min-width: 2.75rem; border: 0; background: transparent; color: var(--muted); }
.hl-colors { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-bottom: 0.75rem; }
.hl-swatch {
  --hl: #ffd93d;
  width: 2.75rem;
  min-height: 2.75rem;
  padding: 0;
  border-radius: 50%;
  background: var(--hl);
  border: 2px solid var(--border);
}
.hl-swatch[aria-pressed="true"] { border-color: var(--text); box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); }
.hl-swatch:disabled { opacity: 0.4; }
.hl-custom { display: inline-flex; flex-direction: row; align-items: center; gap: 0.375rem; font-size: 0.875rem; color: var(--muted); }
.hl-custom input { width: 2.75rem; height: 2.75rem; padding: 0; border: 1px solid var(--border); border-radius: 50%; background: transparent; }
.hl-panel textarea { width: 100%; font: inherit; padding: 0.5rem 0.75rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); color: var(--text); resize: vertical; }
.hl-buttons { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.5rem; }

/* Hinweis bei fehlender Verbindung, Kontoseite „Offline-Lesen“ */
.banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin: 0 0 1rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-left: 5px solid var(--accent);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 0.9375rem;
}
.banner button { min-height: 2.25rem; padding: 0.25rem 0.75rem; }
label.check { flex-direction: row; align-items: center; gap: 0.5rem; }
label.check input { min-height: 0; width: 1.25rem; height: 1.25rem; }
