:root {
  --bg: #f6efe3;
  --bg-2: #efe5d4;
  --card: #fffaf2;
  --ink: #2b2620;
  --ink-2: #6b6155;
  --line: #e2d6c2;
  --accent: #c2581f;
  --accent-ink: #fff;
  --accent-soft: #f6dcc8;
  --chip: #ebe0ce;
  --chip-on: #2b2620;
  --chip-on-ink: #fff8ee;
  --danger: #b3261e;
  --shadow: 0 1px 2px rgba(60, 40, 20, .08), 0 6px 18px rgba(60, 40, 20, .08);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --r: 14px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #141a2e;
  --bg-2: #1b2340;
  --card: #1f2847;
  --ink: #f1e9da;
  --ink-2: #a9b0c8;
  --line: #2e3a62;
  --accent: #f0a646;
  --accent-ink: #1a1408;
  --accent-soft: #3b3524;
  --chip: #263055;
  --chip-on: #f0a646;
  --chip-on-ink: #1a1408;
  --danger: #ff8a80;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 var(--sans);
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}
:root[data-theme="dark"] body {
  background:
    radial-gradient(1px 1px at 12% 8%, #fff8 50%, transparent 51%),
    radial-gradient(1px 1px at 78% 4%, #fff6 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 52% 14%, #fff5 50%, transparent 51%),
    radial-gradient(1px 1px at 90% 22%, #fff4 50%, transparent 51%),
    var(--bg);
  background-repeat: no-repeat;
}
button, input, textarea, select { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--ink-2); font-weight: 400; }
[hidden] { display: none !important; }

/* ---------- header */
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top)) 16px 6px;
  max-width: 1100px; margin: 0 auto;
}
.brand { display: flex; gap: 10px; align-items: center; }
.moon { width: 30px; height: 30px; fill: var(--accent); stroke: none; }
h1 { font: 600 1.55rem/1.1 var(--serif); margin: 0; letter-spacing: -.01em; }
.sub { margin: 2px 0 0; font-size: .85rem; color: var(--ink-2); }
.top-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--card); display: grid; place-items: center; cursor: pointer;
}
.icon-btn.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

main { max-width: 1100px; margin: 0 auto; padding: 0 16px; }

/* ---------- tonight */
.tonight {
  background: var(--card); border: 1px solid var(--line); border-radius: 20px;
  padding: 16px; margin: 10px 0 14px; box-shadow: var(--shadow);
}
.tonight-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.tonight h2 { font: 600 1.25rem var(--serif); margin: 0; }
.season-now { font-size: .85rem; color: var(--ink-2); white-space: nowrap; }
.label { margin: 12px 0 6px; font-size: .8rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-2); }
.row2 { display: grid; grid-template-columns: 1fr; gap: 0 16px; }
@media (min-width: 560px) { .row2 { grid-template-columns: 1fr 1fr; } }
.suggest {
  margin-top: 16px; width: 100%; min-height: 52px; border: 0; border-radius: 14px;
  background: var(--accent); color: var(--accent-ink); font-weight: 650; font-size: 1.05rem;
  display: flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer;
}
.suggest svg { fill: currentColor; stroke: none; }
.suggest:active { transform: scale(.99); }

/* ---------- chips */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding: 2px 16px; margin: 0 -16px; scroll-padding: 16px; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip, .chips button {
  flex: none; min-height: 36px; padding: 6px 13px; border-radius: 999px; border: 1px solid transparent;
  background: var(--chip); cursor: pointer; font-size: .92rem; display: inline-flex; align-items: center; gap: 5px;
  user-select: none;
}
.chips button[aria-pressed="true"], .chip:has(input:checked) { background: var(--chip-on); color: var(--chip-on-ink); }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.ages button { min-width: 44px; justify-content: center; font-variant-numeric: tabular-nums; font-weight: 600; }
.chips .count { opacity: .6; font-size: .8em; }
.chips .now-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.chips button[aria-pressed="true"] .now-dot { background: currentColor; }

/* ---------- sticky search */
.sticky {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  padding: 10px 16px 8px; margin: 0 -16px; display: grid; gap: 8px;
  border-bottom: 1px solid transparent; transition: border-color .2s;
}
.sticky.stuck { border-bottom-color: var(--line); }
.search {
  display: flex; align-items: center; gap: 8px; background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 0 12px; min-height: 48px;
}
.search svg { color: var(--ink-2); flex: none; }
.search input { border: 0; outline: 0; background: transparent; flex: 1; min-width: 0; height: 46px; font-size: 1rem; }
.search:focus-within { border-color: var(--accent); }

/* ---------- results */
.group-h { font: 600 1.05rem var(--serif); margin: 18px 0 10px; display: flex; align-items: baseline; gap: 8px; }
.group-h small { font: .85rem var(--sans); color: var(--ink-2); }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 12px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 820px) { .grid { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.card { background: none; border: 0; padding: 0; text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 7px; }
.card .cv { position: relative; }
.card h3 { font: 600 .98rem/1.25 var(--serif); margin: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .by { font-size: .8rem; color: var(--ink-2); margin: -3px 0 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge {
  position: absolute; left: 6px; bottom: 6px; background: rgba(20, 16, 10, .78); color: #fff;
  font-size: .75rem; font-weight: 650; padding: 2px 8px; border-radius: 999px; backdrop-filter: blur(4px);
}
.heart { position: absolute; right: 6px; top: 6px; width: 26px; height: 26px; border-radius: 50%; background: rgba(255,255,255,.9); display: grid; place-items: center; }
.heart svg { width: 15px; height: 15px; fill: #d0453b; stroke: #d0453b; }
.read-tag { position: absolute; right: 6px; bottom: 6px; background: var(--accent); color: var(--accent-ink); font-size: .7rem; font-weight: 650; padding: 2px 7px; border-radius: 999px; }
.verify-dot { position: absolute; left: 6px; top: 6px; background: #e8b300; color: #241a00; font-size: .7rem; font-weight: 700; padding: 1px 7px; border-radius: 999px; }

/* covers */
.cover {
  aspect-ratio: 2 / 3; width: 100%; border-radius: 4px 10px 10px 4px; overflow: hidden;
  box-shadow: var(--shadow), inset 3px 0 0 rgba(0, 0, 0, .12); background: var(--bg-2); position: relative;
}
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover.gen { display: flex; flex-direction: column; justify-content: space-between; padding: 12% 10% 10% 14%; color: #fff8ee; }
.cover.gen::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 7%; background: rgba(0, 0, 0, .18); }
.cover.gen::after { content: ""; position: absolute; inset: 0; background: radial-gradient(circle at 80% 15%, rgba(255,255,255,.18), transparent 50%); }
.cover.gen .gt { font: 600 clamp(.85rem, 4.2vw, 1.15rem)/1.15 var(--serif); position: relative; z-index: 1; overflow-wrap: anywhere; }
.cover.gen .ga { font-size: clamp(.65rem, 2.8vw, .8rem); opacity: .85; position: relative; z-index: 1; }
@media (min-width: 820px) { .cover.gen .gt { font-size: 1rem; } }

.empty { text-align: center; color: var(--ink-2); padding: 40px 10px; }
.empty button { margin-top: 10px; }

/* ---------- sheets */
dialog.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 640px; max-height: 92dvh;
  border-radius: 22px 22px 0 0; background: var(--card); color: var(--ink); overflow: auto;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, .25); overscroll-behavior: contain;
}
dialog.sheet.small { max-width: 420px; }
@media (min-width: 700px) { dialog.sheet { margin: auto; border-radius: 22px; } }
dialog::backdrop { background: rgba(10, 12, 24, .55); backdrop-filter: blur(2px); }
dialog[open] { animation: up .22s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.sheet-grip { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 10px auto 4px; }
.sheet form, .detail-inner { padding: 4px 18px calc(22px + env(safe-area-inset-bottom)); }
.sheet h2 { font: 600 1.35rem/1.2 var(--serif); margin: 8px 0 14px; }

.detail-top { display: grid; grid-template-columns: 120px 1fr; gap: 16px; align-items: start; margin-top: 8px; }
.detail-top h2 { margin: 0 0 4px; }
.detail-top .by { color: var(--ink-2); margin: 0; font-size: .92rem; }
.facts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.fact { background: var(--bg-2); border-radius: 8px; padding: 3px 9px; font-size: .82rem; }
.fact.age { background: var(--accent); color: var(--accent-ink); font-weight: 650; }
.desc { margin: 16px 0 0; font-size: 1rem; }
.tip { margin: 12px 0 0; padding: 10px 12px; border-radius: 12px; background: var(--accent-soft); font-size: .93rem; }
.tip b { font-weight: 650; }
.meta { margin: 14px 0 0; font-size: .8rem; color: var(--ink-2); }
.detail-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.detail-tags button { border: 1px solid var(--line); background: none; border-radius: 999px; padding: 4px 11px; font-size: .85rem; cursor: pointer; }
.detail-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 18px; }
.detail-actions .wide { grid-column: 1 / -1; }

/* ---------- buttons & forms */
.btn {
  min-height: 44px; padding: 8px 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg-2); cursor: pointer; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: none; }
.btn.small { min-height: 36px; padding: 5px 12px; font-size: .88rem; }
.btn.danger { color: var(--danger); background: none; border-color: currentColor; }
.btn:disabled { opacity: .5; }
.field { display: grid; gap: 4px; margin: 0 0 12px; border: 0; padding: 0; min-width: 0; }
.field > span, .field > legend { font-size: .8rem; font-weight: 600; color: var(--ink-2); padding: 0; margin-bottom: 4px; }
.field input, .field textarea, .tag-add input, .age-range input {
  width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 10px 12px; font-size: 16px;
}
.field input:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.age-range { display: flex; gap: 12px; }
.age-range label { display: flex; align-items: center; gap: 6px; }
.age-range input { width: 80px; }
.isbn-row { display: flex; gap: 8px; align-items: end; margin-bottom: 4px; }
.isbn-row .field { margin: 0; }
.grow { flex: 1; }
.hint { font-size: .82rem; color: var(--ink-2); margin: 6px 0 12px; min-height: 1em; }
.hint.ok { color: #2f7d32; }
:root[data-theme="dark"] .hint.ok { color: #8fd694; }
.err { color: var(--danger); min-height: 1em; margin: 6px 0; font-size: .9rem; }
.cover-edit { display: grid; grid-template-columns: 96px 1fr; gap: 14px; margin: 6px 0 16px; align-items: start; }
.cover-actions { display: grid; gap: 6px; justify-items: start; }
.cover-actions .hint { margin: 0; }
.tag-add { display: flex; gap: 6px; margin-top: 8px; }
.check { display: flex; align-items: center; gap: 8px; margin: 4px 0 8px; font-size: .95rem; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.form-actions { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
#scanWrap { position: relative; margin: 8px 0; border-radius: 12px; overflow: hidden; background: #000; }
#scanWrap video { width: 100%; max-height: 260px; object-fit: cover; display: block; }
#scanWrap button { position: absolute; right: 8px; bottom: 8px; background: rgba(0,0,0,.6); color: #fff; border-color: #fff6; }

/* ---------- fab, toast */
.fab {
  position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom)); width: 60px; height: 60px; border-radius: 50%;
  border: 0; background: var(--accent); color: var(--accent-ink); box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
  display: grid; place-items: center; cursor: pointer; z-index: 10;
}
.fab svg { width: 28px; height: 28px; stroke-width: 2.4; }
#toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: .92rem;
  opacity: 0; pointer-events: none; transition: .25s; z-index: 50; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

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

.active-f { margin: 14px 0 -6px; font-size: .85rem; color: var(--ink-2); display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; }
.active-f button { border: 0; background: none; color: var(--accent); font-weight: 600; padding: 4px 0; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }

/* Hinweis für Eltern */
.note-dot {
  position: absolute; left: 6px; top: 6px; width: 22px; height: 22px; border-radius: 50%;
  background: #2d5f8b; color: #fff; font: 700 .8rem/22px Georgia, serif; text-align: center; font-style: italic;
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.note-dot + .verify-dot { top: 32px; }
.parent-note {
  margin: 12px 0 0; padding: 10px 12px; border-radius: 12px; font-size: .93rem;
  background: #e3edf6; color: #1d3a55; border: 1px solid #c7d9ea;
}
:root[data-theme="dark"] .parent-note { background: #1c3047; color: #d6e6f5; border-color: #2f4d6e; }
.parent-note summary { cursor: pointer; font-weight: 650; display: flex; align-items: center; gap: 6px; list-style: none; }
.parent-note summary::-webkit-details-marker { display: none; }
.parent-note summary::after { content: "›"; margin-left: auto; transition: transform .2s; font-size: 1.2em; }
.parent-note[open] summary::after { transform: rotate(90deg); }
.parent-note svg { width: 18px; height: 18px; }
.parent-note p { margin: 8px 0 0; }
.parent-note .muted { color: inherit; opacity: .75; font-size: .88rem; }
.form-actions { flex-wrap: nowrap; }
.form-actions .btn { padding-left: 13px; padding-right: 13px; }
