:root {
  --cream: #f8f2e6;
  --cream-2: #efe4d1;
  --wall-1: #f4ead9;
  --wall-2: #e8dcc7;
  --ink: #3a332b;
  --muted: #7b6d5b;
  --line: #dfd2bb;
  --sage: #7c8a68;
  --sage-dark: #5f6d4e;
  --dusty: #6e7e96;
  --terracotta: #b26747;
  --wood-light: #bb8a5c;
  --wood-mid: #94633c;
  --wood-dark: #6a4427;
  --card: #fffaf0;
  --radius: 14px;
  --cover-h: 192px;
  --cap-h: 70px;
  --board-h: 16px;
  --gap: 20px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

a { color: var(--sage-dark); }

h1, h2, h3 { font-family: Georgia, "Iowan Old Style", "Times New Roman", serif; font-weight: 600; line-height: 1.2; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.skip {
  position: absolute; left: -999px; top: 0; background: var(--card);
  padding: 10px 14px; z-index: 50; border-radius: 0 0 8px 0;
}
.skip:focus { left: 0; }

/* ---------- Kopfbereich ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(248, 242, 230, .96);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 2px 10px rgba(90, 65, 35, .06);
}

.topbar-inner {
  max-width: 1180px; margin: 0 auto; padding: 12px 18px 6px;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}

.brand {
  font-family: Georgia, serif; font-size: 1.3rem; font-weight: 700;
  color: var(--ink); text-decoration: none; letter-spacing: .2px;
  margin-right: auto;
}

.search { display: flex; gap: 8px; flex: 1 1 260px; max-width: 420px; }
.search input {
  flex: 1; min-height: 44px; padding: 10px 14px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--card); color: var(--ink); font-size: 1rem;
}
.search input:focus { outline: 3px solid rgba(124, 138, 104, .35); border-color: var(--sage); }
.search button {
  min-height: 44px; padding: 0 18px; border-radius: 999px; border: 0;
  background: var(--sage); color: #fffdf7; font-size: 1rem; cursor: pointer;
}
.search button:hover { background: var(--sage-dark); }

.logout button.ghost {
  min-height: 44px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line); background: transparent; color: var(--muted);
  font-size: .95rem; cursor: pointer;
}
.logout button.ghost:hover { color: var(--ink); border-color: var(--wood-light); }

.shelves {
  max-width: 1180px; margin: 0 auto; padding: 0 18px;
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
}
.shelves::-webkit-scrollbar { display: none; }

.tab {
  flex: 0 0 auto; padding: 10px 16px 12px; text-decoration: none;
  color: var(--muted); border-bottom: 3px solid transparent;
  font-weight: 600; font-size: .98rem;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); border-bottom-color: var(--terracotta); }

/* ---------- Grundraster ---------- */
.wrap { max-width: 1180px; margin: 0 auto; padding: 22px 18px 60px; }

.shelf-head {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between;
  gap: 14px; margin-bottom: 8px;
}
.shelf-title h1 { margin: 0 0 2px; font-size: 1.7rem; }
.hint { color: var(--muted); margin: 0; }
.hint.small, .small { font-size: .86rem; }

.controls { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.sortgroup { display: flex; gap: 6px; align-items: center; }

.chip {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 16px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card);
  color: var(--muted); text-decoration: none; font-size: .95rem; font-weight: 600;
}
.chip:hover { border-color: var(--wood-light); color: var(--ink); }
.chip.active { background: var(--sage); border-color: var(--sage); color: #fffdf7; }
.chip.dir { width: 44px; padding: 0; font-size: 1.1rem; }

.statusgroup { display: flex; gap: 8px; }
.status {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 48px; padding: 0 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card);
  color: var(--muted); text-decoration: none; font-weight: 600;
}
.status b {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 26px; height: 26px; padding: 0 7px; border-radius: 999px;
  background: var(--cream-2); color: var(--ink); font-size: .85rem;
}
.status:hover { border-color: var(--wood-light); }
.status.active { background: var(--dusty); border-color: var(--dusty); color: #fffdf7; }
.status.active b { background: rgba(255, 255, 255, .22); color: #fffdf7; }

/* ---------- Regal ---------- */
.shelf {
  --row-h: calc(var(--cover-h) + var(--board-h));
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  grid-auto-rows: var(--row-h);
  column-gap: var(--gap);
  row-gap: calc(var(--cap-h) + 16px);
  margin-top: 10px;
  padding: 16px 18px calc(22px + var(--cap-h));
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .35), rgba(120, 90, 55, .05)),
    linear-gradient(180deg, var(--wall-1), var(--wall-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: inset 0 2px 30px rgba(110, 80, 45, .10), 0 10px 30px rgba(90, 65, 35, .08);
  overflow: hidden;
}

.book {
  position: relative;
  display: flex; flex-direction: column; justify-content: flex-end; align-items: center;
  padding: 0 3px var(--board-h);
  text-decoration: none; color: inherit;
  border-radius: 6px 6px 0 0;
  outline-offset: 2px;
}

.book::after {
  content: "";
  position: absolute; left: calc(var(--gap) / -2); right: calc(var(--gap) / -2);
  bottom: 0; height: var(--board-h);
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, .07) 0 2px, rgba(0, 0, 0, .05) 2px 5px, transparent 5px 11px),
    linear-gradient(180deg, var(--wood-light), var(--wood-mid) 55%, var(--wood-dark));
  border-top: 1px solid rgba(255, 245, 230, .34);
  box-shadow: 0 4px 6px rgba(55, 33, 14, .30), inset 0 -3px 4px rgba(60, 35, 15, .35);
}

.book-cover {
  position: relative;
  height: var(--cover-h);
  display: flex; align-items: flex-end; justify-content: center;
  filter: drop-shadow(0 6px 7px rgba(60, 40, 18, .32));
  transition: transform .18s ease;
}
.book:hover .book-cover { transform: translateY(-4px); }
.book img {
  display: block; height: var(--cover-h); width: auto; max-width: 100%;
  object-fit: contain; border-radius: 2px; background: #fff;
}

.cover-fallback {
  height: var(--cover-h); aspect-ratio: 2 / 3; max-width: 100%;
  display: flex; align-items: center; justify-content: center;
  padding: 12px; border-radius: 3px; text-align: center;
  color: #fffdf7; font-family: Georgia, serif; font-size: .95rem;
  line-height: 1.25; overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12), inset 8px 0 12px rgba(0, 0, 0, .16);
}
.spine-0 { background: linear-gradient(160deg, #8b9a74, #6d7c58); }
.spine-1 { background: linear-gradient(160deg, #8593a8, #64748c); }
.spine-2 { background: linear-gradient(160deg, #c18366, #a2624a); }
.spine-3 { background: linear-gradient(160deg, #b9a06a, #97804c); }
.spine-4 { background: linear-gradient(160deg, #9a8a9e, #7a6a80); }

.caption {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  padding: 0 2px; text-align: center;
  display: flex; flex-direction: column; gap: 1px;
}
.cap-title {
  font-size: 1rem; font-weight: 700; line-height: 1.22;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.cap-author {
  font-size: .82rem; color: var(--muted); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}

.read-badge {
  position: absolute; right: -6px; top: -6px;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--sage); color: #fffdf7; font-size: .8rem;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--wall-1);
}

/* ---------- Leerzustand ---------- */
.empty {
  margin: 40px auto; max-width: 560px; padding: 32px 24px;
  background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius);
  text-align: center; color: var(--muted);
}
.empty p { margin: 6px 0; }

/* ---------- Login ---------- */
.login-card {
  max-width: 440px; margin: 8vh auto 0; padding: 32px 28px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: 0 16px 40px rgba(90, 65, 35, .12);
}
.login-card h1 { margin: 0 0 4px; font-size: 1.6rem; }
.login-form { display: flex; flex-direction: column; gap: 6px; margin-top: 22px; }
.login-form label { font-weight: 600; font-size: .92rem; margin-top: 8px; }
.login-form input {
  min-height: 48px; padding: 10px 14px; font-size: 1rem;
  border: 1px solid var(--line); border-radius: 10px; background: #fffdf7; color: var(--ink);
}
.login-form input:focus { outline: 3px solid rgba(124, 138, 104, .35); border-color: var(--sage); }
.primary {
  margin-top: 18px; min-height: 52px; border: 0; border-radius: 12px;
  background: var(--terracotta); color: #fffdf7; font-size: 1.05rem; font-weight: 700;
  cursor: pointer;
}
.primary:hover { background: #9c5537; }
.error {
  margin-top: 16px; padding: 12px 14px; border-radius: 10px;
  background: #f7e2d9; color: #8a3a20; font-weight: 600;
}

/* ---------- Details ---------- */
.backlink { margin: 0 0 14px; }
.backlink a { color: var(--muted); text-decoration: none; }
.backlink a:hover { color: var(--ink); }

.detail {
  display: grid; grid-template-columns: minmax(200px, 300px) 1fr;
  gap: 34px; align-items: start;
}
.detail-cover img {
  width: 100%; height: auto; border-radius: 6px;
  box-shadow: 0 14px 30px rgba(70, 45, 20, .28);
}
.detail-cover .cover-fallback { width: 100%; height: auto; aspect-ratio: 2 / 3; font-size: 1.2rem; }
.detail-info h2 { margin: 0 0 4px; font-size: 1.9rem; }
.detail-info .author { font-size: 1.15rem; color: var(--muted); margin: 0 0 16px; }

.meta { display: flex; flex-wrap: wrap; gap: 8px 24px; margin: 0 0 22px; }
.meta div { margin: 0; }
.meta dt { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.meta dd { margin: 2px 0 0; font-weight: 600; }

.detail-info h3 { font-size: 1.1rem; margin: 8px 0 10px; }

.readers { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.reader-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px;
  padding: 12px 14px; background: var(--card);
  border: 1px solid var(--line); border-radius: 12px;
}
.rname { font-weight: 700; min-width: 92px; }
.toggles { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: .95rem; }
.switch input {
  appearance: none; width: 48px; height: 28px; border-radius: 999px;
  background: #ddd0ba; position: relative; cursor: pointer; margin: 0;
  transition: background .18s ease; flex: 0 0 auto;
}
.switch input::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px;
  border-radius: 50%; background: #fffdf7; transition: transform .18s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
}
.switch input:checked { background: var(--sage); }
.switch input:checked::after { transform: translateX(20px); }
.switch input:disabled { opacity: .45; cursor: not-allowed; }
.switch.is-disabled { opacity: .5; }
.switch input:checked + span { color: var(--sage-dark); font-weight: 700; }
.detail-info > .hint.small { margin-top: 14px; }
.switch input:focus-visible { outline: 3px solid rgba(111, 127, 150, .45); outline-offset: 2px; }
.fin-date { font-size: .88rem; color: var(--sage-dark); font-weight: 600; }

/* ---------- Dialog ---------- */
.book-dialog {
  position: relative;
  width: min(880px, calc(100vw - 24px));
  max-height: calc(100vh - 40px);
  padding: 0; border: 1px solid var(--line); border-radius: 18px;
  background: var(--cream); color: var(--ink);
  box-shadow: 0 30px 70px rgba(50, 32, 14, .4);
  overflow: auto;
}
.book-dialog::backdrop { background: rgba(46, 34, 22, .55); backdrop-filter: blur(3px); }
.dialog-body { padding: 28px; }
.detail-info { padding-right: 44px; }
.dialog-close {
  position: absolute; top: 12px; right: 12px; z-index: 2;
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font-size: 1.4rem; line-height: 1;
  cursor: pointer; box-shadow: 0 2px 6px rgba(60, 40, 18, .15);
}
.dialog-close:hover { background: var(--cream-2); }

@media (max-width: 900px) {
  :root { --cover-h: 158px; --cap-h: 58px; --gap: 14px; }
  .shelf { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); padding: 12px 12px 22px; }
  .topbar-inner { padding: 10px 14px 4px; }
  .shelves { padding: 0 14px; }
  .wrap { padding: 18px 14px 48px; }
}

@media (max-width: 640px) {
  :root { --cover-h: 138px; --cap-h: 46px; --gap: 8px; --board-h: 10px; }
  .shelf { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); padding: 10px 10px 18px; }
  .cap-title { font-size: .76rem; }
  .cap-author { font-size: .66rem; }
  .brand { font-size: 1.1rem; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  .shelf-title h1 { font-size: 1.4rem; }
  .status { flex: 1 1 0; justify-content: center; padding: 0 10px; font-size: .95rem; }
  .statusgroup { width: 100%; }
  .detail { grid-template-columns: 1fr; gap: 20px; }
  .detail-cover { max-width: 240px; }
  .dialog-body { padding: 18px 16px; }
  .rname { min-width: 0; flex-basis: 100%; }
}

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