:root {
  --bg: #f7f6f3;
  --surface: #ffffff;
  --text: #1d2129;
  --muted: #5c6470;
  --border: #e0ddd6;
  --accent: #2f5fd0;
  --accent-dark: #2450b3;
  --danger: #b3261e;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
}

#login-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--bg);
  align-items: center;
  justify-content: center;
  padding: 20px;
}
#login-overlay:not([hidden]) { display: flex; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-weight: 700; font-size: 1.15rem; color: var(--text); text-decoration: none; }
.topbar nav { display: flex; gap: 1rem; align-items: center; }
.topbar nav a { color: var(--accent); text-decoration: none; }
.topbar nav a.btn-primary { color: #fff; }

main { max-width: 820px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }

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

.btn, .btn-primary {
  display: inline-block;
  padding: 0.45rem 0.9rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
  cursor: pointer;
  text-decoration: none;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-danger { color: var(--danger); border-color: var(--danger); }

.toolbar { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-bottom: 0.6rem; }
.toolbar input[type="search"] { flex: 1 1 220px; }
.toolbar-secondary { display: flex; gap: 0.6rem; margin-bottom: 1rem; }
.check { display: flex; align-items: center; gap: 0.35rem; color: var(--muted); }

input, select, textarea {
  font: inherit;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  max-width: 100%;
}

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

.source-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.6rem; }
.source-list li {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.8rem 1rem;
}
.source-list a.title { color: var(--text); font-weight: 600; text-decoration: none; font-size: 1.05rem; }
.source-list a.title:hover { color: var(--accent); }
.meta { color: var(--muted); font-size: 0.85rem; margin: 0.25rem 0 0; }
.badge {
  display: inline-block; font-size: 0.75rem; padding: 0.1rem 0.5rem;
  border-radius: 999px; border: 1px solid var(--border); color: var(--muted); margin-right: 0.3rem;
}
.badge.fav { color: #8a6d00; border-color: #d9b500; }
.tag-chip { display: inline-block; font-size: 0.78rem; background: #eef1f8; color: var(--accent-dark); border-radius: 999px; padding: 0.1rem 0.55rem; margin-right: 0.3rem; }

.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.loading { color: var(--muted); }
[role="alert"], [role="status"] { min-height: 1.2em; font-size: 0.9rem; }
[role="alert"] { color: var(--danger); }
#library-message, #notes-status { color: #1e7a34; }

.form { display: grid; gap: 0.6rem; max-width: 560px; margin-bottom: 2rem; }
.form .hint { color: var(--muted); font-weight: 400; font-size: 0.85rem; }
details { max-width: 560px; }
details summary { cursor: pointer; color: var(--accent); margin-bottom: 1rem; }

/* Lector */
.reader-header { border-bottom: 1px solid var(--border); padding-bottom: 1rem; margin-bottom: 1.5rem; }
.reader-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin: 0.75rem 0; }
.reader-tags { display: grid; gap: 0.3rem; max-width: 420px; }
.content { font-size: 1.06rem; }
.content img { max-width: 100%; height: auto; }
.content pre { overflow-x: auto; background: #f0efeb; padding: 0.75rem; border-radius: var(--radius); }
.content blockquote { border-left: 3px solid var(--border); margin-left: 0; padding-left: 1rem; color: var(--muted); }
.content a { color: var(--accent); }
.notes { margin-top: 2.5rem; border-top: 1px solid var(--border); padding-top: 1rem; }
.notes textarea { width: 100%; }
.notes button { margin-top: 0.5rem; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

@media (max-width: 480px) {
  main { padding: 1rem 0.9rem 4rem; }
  .toolbar { flex-direction: column; }
  .toolbar input[type="search"], .toolbar select { width: 100%; }
  .reader-actions .btn, .reader-actions select { width: 100%; text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

.title-row { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; }
.title-row a.title { flex: 1; }
.ext-link { padding: 0.15rem 0.55rem; font-size: 1rem; line-height: 1.4; }
