:root {
  --bg: #f6f2ea;
  --surface: #fffdf8;
  --surface-2: #efe8db;
  --text: #2a2420;
  --muted: #7a6f64;
  --border: #e2d8c8;
  --accent: #9c4a1f;
  --accent-2: #c56a35;
  --accent-text: #fff;
  --ok: #3f7d4e;
  --danger: #b03a2e;
  --star: #e0a526;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 4px 16px rgba(60, 40, 20, .06);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17140f; --surface: #211d17; --surface-2: #2b261f; --text: #ece4d8; --muted: #a39887;
    --border: #3a3329; --accent: #e08a52; --accent-2: #f0a26f; --accent-text: #1a120c; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #17140f; --surface: #211d17; --surface-2: #2b261f; --text: #ece4d8; --muted: #a39887;
  --border: #3a3329; --accent: #e08a52; --accent-2: #f0a26f; --accent-text: #1a120c; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-family: Georgia, "Times New Roman", serif; font-weight: 700; line-height: 1.2; margin: 0 0 .6em; }
h1 { font-size: 1.8rem; } h2 { font-size: 1.35rem; } h3 { font-size: 1.1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }

/* Layout */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner { max-width: 1400px; margin: 0 auto; display: flex; align-items: center; gap: 16px; padding: 10px 20px; }
.brand { font-family: Georgia, serif; font-size: 1.35rem; font-weight: 700; color: var(--text); display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand .logo { width: 30px; height: 30px; border-radius: 7px; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; font-size: 17px; }
.nav { display: flex; gap: 2px; flex-wrap: wrap; flex: 1; }
.nav a { color: var(--muted); padding: 6px 11px; border-radius: 7px; font-weight: 500; position: relative; white-space: nowrap; }
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--surface-2); color: var(--text); }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; line-height: 18px; text-align: center; margin-left: 4px; }
.user-menu { display: flex; align-items: center; gap: 8px; }
.menu-toggle { display: none; }
main { max-width: 1400px; margin: 0 auto; padding: 24px 20px 60px; }

/* Controls */
button, .btn { font: inherit; cursor: pointer; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 7px 14px; border-radius: 8px; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; transition: background .15s, border-color .15s; white-space: nowrap; }
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }
button:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-sm { padding: 4px 10px; font-size: .85rem; }
.btn-ghost { border-color: transparent; background: transparent; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input[type="checkbox"] { width: auto; }
textarea { min-height: 90px; resize: vertical; }
label { display: block; font-weight: 600; font-size: .85rem; margin-bottom: 4px; color: var(--muted); }
.field { margin-bottom: 14px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0 16px; }
.grid-form .full { grid-column: 1 / -1; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.section { margin-bottom: 32px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.section-head h2 { margin: 0; }

/* Filter bar */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; align-items: center; }
.toolbar .search { flex: 1 1 280px; position: relative; }
.toolbar .search input { padding-left: 34px; }
.toolbar .search::before { content: "⌕"; position: absolute; left: 11px; top: 50%; transform: translateY(-52%); color: var(--muted); font-size: 18px; }
.toolbar select { width: auto; min-width: 140px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 3px 10px; border-radius: 99px; background: var(--surface-2); color: var(--text); font-size: .82rem; border: 1px solid var(--border); cursor: pointer; }
.chip.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
a.chip:hover { text-decoration: none; border-color: var(--accent); }

/* Book grid */
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 22px 18px; }
.book-card { display: flex; flex-direction: column; gap: 6px; color: var(--text); position: relative; }
.book-card:hover { text-decoration: none; }
.book-card .cover { aspect-ratio: 2 / 3; width: 100%; border-radius: 6px; overflow: hidden; background: var(--surface-2); box-shadow: 0 2px 6px rgba(0,0,0,.15), 0 8px 20px rgba(0,0,0,.08); transition: transform .15s; position: relative; }
.book-card:hover .cover { transform: translateY(-3px); }
.book-card .cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.book-card .title { font-weight: 600; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book-card .author { color: var(--muted); font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fmt { position: absolute; top: 6px; right: 6px; background: rgba(0,0,0,.65); color: #fff; font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 4px; letter-spacing: .04em; }
.shelf-tag { position: absolute; top: 6px; left: 6px; background: var(--ok); color: #fff; font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 4px; }
.progress { height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); }
.cover .progress { position: absolute; left: 0; right: 0; bottom: 0; border-radius: 0; background: rgba(0,0,0,.35); height: 5px; }
.scroller { display: grid; grid-auto-flow: column; grid-auto-columns: 130px; gap: 16px; overflow-x: auto; padding-bottom: 8px; }

/* Stars */
.stars { display: inline-flex; gap: 1px; color: var(--star); font-size: 1rem; line-height: 1; vertical-align: middle; }
.stars .off { color: var(--border); }
.stars.input span { cursor: pointer; font-size: 1.7rem; padding: 0 1px; transition: transform .1s; }
.stars.input span:hover { transform: scale(1.15); }
.rating-line { display: flex; align-items: center; gap: 6px; font-size: .85rem; color: var(--muted); }

/* Book detail */
.detail { display: grid; grid-template-columns: 260px 1fr; gap: 32px; align-items: start; }
.detail .cover-big { width: 100%; aspect-ratio: 2/3; object-fit: cover; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,.2), 0 16px 40px rgba(0,0,0,.12); background: var(--surface-2); }
.detail .actions { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.detail .actions .btn, .detail .actions button { justify-content: center; }
.meta-table { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 16px 0; font-size: .92rem; }
.meta-table dt { color: var(--muted); }
.meta-table dd { margin: 0; }
.description { white-space: pre-line; line-height: 1.65; max-width: 75ch; }
.dist { display: grid; grid-template-columns: auto 1fr auto; gap: 4px 8px; align-items: center; font-size: .8rem; max-width: 280px; }
.dist .bar { height: 7px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.dist .bar div { height: 100%; background: var(--star); }

/* Comments */
.comment { padding: 14px 0; border-top: 1px solid var(--border); }
.comment-head { display: flex; gap: 10px; align-items: center; margin-bottom: 4px; flex-wrap: wrap; }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; flex: none; font-size: .9rem; }
.comment-text { white-space: pre-wrap; margin-left: 42px; }

/* Lists / tables */
.list-item { display: flex; gap: 14px; padding: 12px; align-items: center; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; }
.list-item img.thumb { width: 52px; height: 78px; object-fit: cover; border-radius: 4px; flex: none; background: var(--surface-2); }
.list-item .grow { flex: 1; min-width: 0; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
tr:hover td { background: var(--surface-2); }
.status { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: .78rem; font-weight: 600; }
.status.published { background: rgba(63,125,78,.15); color: var(--ok); }
.status.draft { background: rgba(224,165,38,.18); color: #a3740c; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 500; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat .v { font-size: 1.7rem; font-weight: 700; font-family: Georgia, serif; }
.stat .l { color: var(--muted); font-size: .82rem; }
.spark { display: flex; align-items: flex-end; gap: 3px; height: 80px; }
.spark div { flex: 1; background: var(--accent); border-radius: 2px 2px 0 0; min-height: 2px; opacity: .8; }

/* Upload */
.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 40px 20px; text-align: center; background: var(--surface); cursor: pointer; transition: border-color .15s, background .15s; }
.dropzone.over { border-color: var(--accent); background: var(--surface-2); }
.dropzone .big { font-size: 42px; }

/* Auth */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card .brand { justify-content: center; font-size: 1.8rem; margin-bottom: 18px; }

/* Modal / Toast */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 100; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--surface); border-radius: 12px; padding: 22px; width: 100%; max-width: 480px; max-height: 90vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.user-pick { max-height: 240px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
.user-pick label { display: flex; gap: 10px; align-items: center; padding: 8px 12px; margin: 0; color: var(--text); font-weight: 400; font-size: .95rem; cursor: pointer; border-bottom: 1px solid var(--border); }
.user-pick label:last-child { border-bottom: 0; }
#toasts { position: fixed; bottom: 18px; right: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); max-width: 360px; animation: slidein .2s; }
.toast.error { background: var(--danger); color: #fff; }
@keyframes slidein { from { transform: translateY(10px); opacity: 0; } }
.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty .big { font-size: 44px; margin-bottom: 8px; }
mark { background: rgba(224,165,38,.35); color: inherit; padding: 0 1px; border-radius: 2px; }
.snippet { font-family: Georgia, serif; color: var(--text); font-size: .95rem; }
.pager { display: flex; gap: 8px; justify-content: center; margin-top: 24px; align-items: center; }

.bottom-nav { display: none; }

/* ---------- Smartphone / Tablet ---------- */
@media (max-width: 860px) {
  body { -webkit-tap-highlight-color: transparent; }
  .topbar-inner { flex-wrap: wrap; padding: 8px 16px; padding-top: max(8px, env(safe-area-inset-top)); gap: 8px; }
  .brand { font-size: 1.15rem; }
  .menu-toggle { display: none; }
  .nav { display: none; order: 3; flex-basis: 100%; flex-direction: column; padding-bottom: 6px; }
  .nav.open { display: flex; }
  .nav a { padding: 11px 12px; font-size: 1rem; }
  .user-menu { margin-left: auto; }
  #me-link span:not(.avatar) { display: none; }
  main { padding: 16px 16px calc(84px + env(safe-area-inset-bottom)); }
  h1 { font-size: 1.45rem; }
  .bottom-nav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--surface); border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -2px 12px rgba(0,0,0,.06); }
  .bottom-nav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 7px 2px 6px; font-size: 11px; color: var(--muted); min-height: 54px; justify-content: center; }
  .bottom-nav a:hover { text-decoration: none; }
  .bottom-nav a.active { color: var(--accent); font-weight: 600; }
  .bottom-nav .i { font-size: 20px; line-height: 1.1; position: relative; }
  .bottom-nav .badge { position: absolute; top: -4px; right: -14px; }
  /* grössere Tippflächen, kein iOS-Zoom beim Fokussieren */
  input, select, textarea { font-size: 16px; padding: 10px 12px; }
  button, .btn { padding: 9px 14px; min-height: 40px; }
  .btn-sm { min-height: 34px; }
  .toolbar { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .toolbar .search { grid-column: 1 / -1; }
  .toolbar select { min-width: 0; width: 100%; }
  .detail { grid-template-columns: 1fr; gap: 20px; }
  .detail > div:first-child { width: 100%; display: grid; grid-template-columns: 120px 1fr; gap: 14px; align-items: start; }
  .detail .actions { margin-top: 0; }
  .detail .actions .btn, .detail .actions button, .detail .actions select { font-size: .9rem; }
  .meta-table { grid-template-columns: max-content 1fr; font-size: .88rem; }
  .meta-table dd { word-break: break-word; }
  .book-grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 16px 12px; }
  .book-card .title { font-size: .9rem; }
  .scroller { grid-auto-columns: 104px; margin: 0 -16px; padding: 0 16px 8px; scroll-snap-type: x mandatory; }
  .scroller > * { scroll-snap-align: start; }
  .list-item { flex-wrap: wrap; gap: 10px; }
  .list-item .grow { flex-basis: calc(100% - 80px); }
  .list-item > .row:last-child { width: 100%; justify-content: flex-end; }
  .card { padding: 14px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat .v { font-size: 1.35rem; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .tabs a { white-space: nowrap; }
  .grid-form { grid-template-columns: 1fr !important; }
  .dropzone { padding: 28px 14px; }
  .comment-text { margin-left: 0; }
  /* Dialoge als Bottom-Sheet */
  .modal-bg { place-items: end center; padding: 0; }
  .modal { max-width: none; border-radius: 16px 16px 0 0; max-height: 88vh; padding-bottom: calc(22px + env(safe-area-inset-bottom)); animation: sheet .2s ease-out; }
  @keyframes sheet { from { transform: translateY(40px); opacity: 0; } }
  #toasts { left: 16px; right: 16px; bottom: calc(70px + env(safe-area-inset-bottom)); }
  .toast { max-width: none; }
  table { font-size: .82rem; }
  th, td { padding: 7px 8px; }
}
@media (max-width: 380px) {
  .detail > div:first-child { grid-template-columns: 96px 1fr; }
  .book-grid { grid-template-columns: repeat(3, 1fr); }
}
