/* Leselog – Design-Töne:
   Papier   #F3F3EE   (kühles Papiergrau)
   Tinte    #262F3A   (Blauschwarz, Text)
   Leinen   #2A5C48   (Buchleinen-Grün, Aktionen + "Lese ich")
   Ocker    #A3781F   ("Merkliste")
   Schiefer #47618D   ("Gelesen")
   Oxblut   #8A3434   (Entfernen)
*/

:root {
  --paper: #F3F3EE;
  --card: #FCFCFa;
  --field-bg: #FFFFFF;
  --ink: #262F3A;
  --muted: #6E7269;
  --line: #DDDCD2;
  --green: #2A5C48;
  --green-strong: #234C3C;
  --ochre: #A3781F;
  --slate: #47618D;
  --slate-soft: #E2E7F0;
  --oxblood: #8A3434;
  --star: #A3781F;
  --radius: 6px;
  --serif: Charter, "Bitstream Charter", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

/* Dunkles Design: gleiche Rollen, nächtliche Werte */
html[data-theme="dark"] {
  --paper: #1B1E23;
  --card: #24282F;
  --field-bg: #1B1E23;
  --ink: #E4E2D8;
  --muted: #9A9E96;
  --line: #383D46;
  --green: #4E8F72;
  --green-strong: #3E7A60;
  --ochre: #C89A3F;
  --slate: #7E97C4;
  --slate-soft: #2E3542;
  --oxblood: #C97070;
  --star: #C89A3F;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
}

h1, h2, h3 { font-family: var(--serif); font-weight: 600; }

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

/* ---------- Kopf ---------- */

.topbar {
  display: flex;
  align-items: baseline;
  gap: 2rem;
  flex-wrap: wrap;
  padding: 1.1rem 1.5rem 0;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}

.wordmark {
  margin: 0 0 0.8rem;
  font-size: 1.7rem;
  letter-spacing: -0.01em;
}

.tabs { display: flex; gap: 0.25rem; }

.tab {
  border: 0;
  background: none;
  font: inherit;
  color: var(--muted);
  padding: 0.5rem 0.9rem 0.85rem;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
}

.tab:hover { color: var(--ink); }

.tab.is-active {
  color: var(--ink);
  border-bottom-color: var(--green);
}

main { max-width: 1080px; margin: 0 auto; padding: 1.5rem; }

/* ---------- Filter ---------- */

.filterbar { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1.3rem; }

.chip {
  font: inherit;
  font-size: 0.9rem;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: 999px;
  padding: 0.3rem 0.9rem;
  cursor: pointer;
}

.chip.is-active { border-color: var(--ink); background: var(--ink); color: var(--paper); }

/* Status-Punkt vor den Filter-Namen = Legende für die Cover-Kanten */
.chip--want::before, .chip--reading::before, .chip--read::before {
  content: "";
  display: inline-block;
  width: 0.6em; height: 0.6em;
  border-radius: 2px;
  margin-right: 0.45em;
}
.chip--want::before    { background: var(--ochre); }
.chip--reading::before { background: var(--green); }
.chip--read::before    { background: var(--slate); }

/* ---------- Regal ---------- */

.shelf {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 1.3rem 1rem;
}

.book {
  border: 0;
  padding: 0;
  background: none;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.cover {
  position: relative;
  aspect-ratio: 2 / 3;
  border-radius: 3px;
  overflow: hidden;
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: 0 1px 2px rgba(38, 47, 58, 0.12);
}

.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Die Status-Kante: wie ein farbiges Lesezeichen am Buchrücken */
.cover::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  z-index: 1;
}
.book[data-status="want"]    .cover::before { background: var(--ochre); }
.book[data-status="reading"] .cover::before { background: var(--green); }
.book[data-status="read"]    .cover::before { background: var(--slate); }

/* Platzhalter, wenn kein Cover existiert */
.cover--none {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.7rem;
}
.cover--none span {
  font-family: var(--serif);
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
  overflow-wrap: anywhere;
}

.book-title {
  margin: 0.5rem 0 0;
  font-size: 0.88rem;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.book-author { margin: 0.1rem 0 0; font-size: 0.8rem; color: var(--muted); }

.empty { color: var(--muted); max-width: 46ch; }

/* ---------- Suche ---------- */

.searchbar { display: flex; gap: 0.6rem; margin-bottom: 0.4rem; }

.searchbar input {
  flex: 1;
  font: inherit;
  padding: 0.55rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
}
.searchbar input:focus-visible { outline: 2px solid var(--green); outline-offset: 1px; }

.results { display: grid; gap: 0.8rem; margin-top: 1.2rem; }

.result {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  gap: 0.9rem;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.7rem 0.9rem;
}

.result-cover {
  width: 56px; height: 84px;
  object-fit: cover;
  border-radius: 2px;
  background: var(--paper);
  border: 1px solid var(--line);
}

.result h3 { margin: 0; font-size: 1rem; }
.result p { margin: 0.15rem 0 0; font-size: 0.85rem; color: var(--muted); }

.result-actions { display: flex; flex-direction: column; gap: 0.4rem; }

.in-library { font-size: 0.85rem; color: var(--green); }

/* ---------- Buttons ---------- */

.btn {
  font: inherit;
  font-size: 0.9rem;
  padding: 0.45rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
}
.btn:hover { border-color: var(--ink); }

.btn--primary { background: var(--green); border-color: var(--green); color: #FFFFFF; }
.btn--primary:hover { background: var(--green-strong); border-color: var(--green-strong); }

.btn--danger { background: none; border-color: var(--line); color: var(--oxblood); }
.btn--danger:hover { border-color: var(--oxblood); }

.btn--small { padding: 0.3rem 0.7rem; font-size: 0.82rem; }

:is(.btn, .chip, .tab, .book):focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

/* ---------- Statistik ---------- */

.stat-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-box {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
}

.stat-box strong { display: block; font-family: var(--serif); font-size: 1.7rem; }
.stat-box span { font-size: 0.85rem; color: var(--muted); }

.stats-section { margin-bottom: 2rem; }
.stats-section h2 { font-size: 1.15rem; margin: 0 0 0.8rem; }

.yearbar { display: grid; grid-template-columns: 3.2em 1fr; gap: 0.7rem; align-items: center; margin-bottom: 0.45rem; }
.yearbar .bar {
  height: 1.5rem;
  background: var(--slate-soft);
  border-radius: 3px;
  position: relative;
  overflow: hidden;
}
.yearbar .bar i {
  position: absolute; inset: 0 auto 0 0;
  background: var(--slate);
  border-radius: 3px;
}
.yearbar .bar b {
  position: relative;
  z-index: 1;
  font-weight: 600;
  font-size: 0.82rem;
  padding-left: 0.5rem;
  line-height: 1.5rem;
  color: var(--ink);
}
.yearbar .bar b.on-bar { color: #FFFFFF; }

.author-row {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding: 0.4rem 0;
  font-size: 0.95rem;
}
.author-row span:last-child { color: var(--muted); }

/* ---------- Dialoge ---------- */

dialog {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  padding: 0;
  width: min(560px, calc(100vw - 2rem));
}
dialog::backdrop { background: rgba(38, 47, 58, 0.45); }

.dialog-head { display: flex; justify-content: flex-end; margin: 0; padding: 0.4rem 0.4rem 0; }
.dialog-close {
  border: 0; background: none; font-size: 1.5rem; line-height: 1;
  color: var(--muted); cursor: pointer; padding: 0.3rem 0.6rem;
}
.dialog-close:hover { color: var(--ink); }

.dialog-body {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 1.3rem;
  padding: 0 1.4rem 1.4rem;
}
.dialog-body--login { display: block; padding: 1.4rem; }

.dialog-cover img, .dialog-cover .cover--none {
  width: 150px;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 3px;
  border: 1px solid var(--line);
}

.dialog-info h2 { margin: 0; font-size: 1.35rem; line-height: 1.25; }
.muted { color: var(--muted); font-size: 0.9rem; margin: 0.25rem 0 1rem; }

.field { display: block; margin-bottom: 0.9rem; }
.field span { display: block; font-size: 0.83rem; color: var(--muted); margin-bottom: 0.25rem; }
.field :is(input, select, textarea) {
  width: 100%;
  font: inherit;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--field-bg);
  color: var(--ink);
}
.field textarea { resize: vertical; }
.field :is(input, select, textarea):focus-visible { outline: 2px solid var(--green); outline-offset: 1px; }

.dialog-actions { display: flex; gap: 0.6rem; margin-top: 0.4rem; }

.error { color: var(--oxblood); font-size: 0.9rem; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  padding: 0.55rem 1.1rem;
  border-radius: 999px;
  font-size: 0.9rem;
  box-shadow: 0 2px 10px rgba(38, 47, 58, 0.3);
}

/* ---------- Mobil ---------- */

@media (max-width: 560px) {
  .topbar { gap: 0.5rem 1.5rem; padding-inline: 1rem; }
  main { padding: 1rem; }
  .shelf { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 1rem 0.8rem; }
  .dialog-body { grid-template-columns: 1fr; }
  .dialog-cover { display: flex; justify-content: center; }
  .result { grid-template-columns: 44px 1fr; }
  .result-cover { width: 44px; height: 66px; }
  .result-actions { grid-column: 1 / -1; flex-direction: row; }
}

@media (prefers-reduced-motion: no-preference) {
  .toast { animation: toast-in 0.2s ease-out; }
  @keyframes toast-in {
    from { opacity: 0; transform: translate(-50%, 0.5rem); }
    to   { opacity: 1; transform: translate(-50%, 0); }
  }
}

/* ---------- Theme-Umschalter ---------- */

.theme-toggle {
  margin-left: auto;
  align-self: center;
  margin-bottom: 0.6rem;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font-size: 1rem;
  cursor: pointer;
}
.theme-toggle:hover { border-color: var(--ink); }
.theme-toggle:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

/* ---------- Zähler in den Filterchips ---------- */

.chip b {
  font-weight: 400;
  opacity: 0.65;
  margin-left: 0.15em;
}

/* ---------- Bewertungssterne ---------- */

.book-rating {
  margin: 0.15rem 0 0;
  font-size: 0.78rem;
  color: var(--star);
  letter-spacing: 0.1em;
}

.stars { display: flex; gap: 0.15rem; }

.star {
  border: 0;
  background: none;
  font-size: 1.6rem;
  line-height: 1;
  padding: 0.1rem;
  cursor: pointer;
  color: var(--line);
}
.star.is-on { color: var(--star); }
.star:hover { transform: scale(1.1); }
.star:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; border-radius: 4px; }

/* ---------- Datumsfelder nebeneinander ---------- */

.field-row { display: flex; gap: 0.8rem; }
.field-row .field { flex: 1; }

/* ---------- Statistik-Fußnote ---------- */

.stat-note {
  color: var(--muted);
  font-size: 0.85rem;
  margin: -1rem 0 2rem;
}
