  :root {
    --bg: #f3f8ff;
    --surface: #ffffff;
    --ink: #2a3b4d;
    --muted: #6b7c8f;
    --blue: #4a8fdc;
    --blue-dark: #2f6fb8;
    --mint: #8fd5b5;
    --sun: #ffd569;
    --line: #dbe7f5;
    --danger: #d9534f;
    --radius: 16px;
  }
  * { box-sizing: border-box; }
  html { scroll-padding-top: 90px; }
  body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: "Trebuchet MS", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
    font-size: 1.05rem;
    line-height: 1.55;
  }
  h1, h2, h3 { line-height: 1.2; margin: 0 0 .6em; }
  h1 { font-size: 2rem; }
  h2 { font-size: 1.5rem; }

  /* Header */
  header {
    position: sticky; top: 0; z-index: 10;
    background: var(--surface);
    border-bottom: 4px solid var(--sun);
    display: flex; align-items: center; gap: 24px;
    padding: 10px 24px;
  }
  .logo {
    flex: none; display: block; line-height: 0; border-radius: 12px;
    text-decoration: none;
  }
  .logo img { height: 64px; width: auto; display: block; }
  nav { display: flex; gap: 8px; flex-wrap: wrap; }
  nav a {
    text-decoration: none; color: var(--ink); font-weight: bold;
    padding: 10px 20px; border-radius: 999px;
  }
  nav a:hover { background: #eaf3ff; }
  nav a.active { background: var(--blue); color: #fff; }
  nav a:focus-visible, .logo:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible {
    outline: 3px solid var(--sun); outline-offset: 2px;
  }

  main { max-width: 1100px; margin: 0 auto; padding: 32px 20px 60px; }

  /* Buttons & Forms */
  button, .btn {
    font: inherit; font-weight: bold; cursor: pointer;
    background: var(--blue); color: #fff; border: 0;
    padding: 10px 20px; border-radius: 999px;
  }
  button:hover { background: var(--blue-dark); }
  button.secondary { background: #e4eefb; color: var(--blue-dark); }
  button.secondary:hover { background: #d3e4f9; }
  button.danger { background: #fdeceb; color: var(--danger); }
  button.danger:hover { background: #fadad8; }
  button.small { padding: 6px 14px; font-size: .9rem; }

  label { display: block; font-weight: bold; margin-bottom: 4px; font-size: .95rem; }
  input[type=text], input[type=password], input[type=number], input[type=file], select {
    font: inherit; width: 100%; padding: 9px 12px;
    border: 2px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink);
  }
  input:focus, select:focus { border-color: var(--blue); }

  .panel {
    background: var(--surface); border: 2px solid var(--line);
    border-radius: var(--radius); padding: 20px; margin-bottom: 28px;
  }
  .form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; align-items: end; }
  .toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 18px; }
  .toolbar .spacer { flex: 1; }
  .muted { color: var(--muted); }
  .msg { padding: 10px 14px; border-radius: 12px; margin: 12px 0; background: #fff6dc; border: 2px solid var(--sun); }
  .msg.error { background: #fdeceb; border-color: #f0b3b1; }


  /* Bücher */
  .books { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 22px; list-style: none; padding: 0; margin: 0; }
  .book {
    background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius);
    overflow: hidden; display: flex; flex-direction: column;
  }
  .book .cover { aspect-ratio: 3 / 4; background: #eaf3ff; display: grid; place-items: center; }
  .book .cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
  .book .info { padding: 14px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
  .book h3 { font-size: 1.1rem; margin: 0; }
  .book .author { color: var(--muted); margin: 0; }
  .giver { margin-top: auto; padding-top: 8px; border-top: 2px dashed var(--line); }
  .giver .name { font-weight: bold; }
  .giver .name.free { color: var(--muted); font-weight: normal; font-style: italic; }
  .giver form { display: flex; gap: 6px; margin-top: 6px; }
  .giver input { padding: 6px 10px; }

  /* Geschenkdepot */
  table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius); overflow: hidden; }
  th, td { text-align: left; padding: 12px 16px; border-bottom: 2px solid var(--line); }
  th { background: #eaf3ff; }
  tr:last-child td { border-bottom: 0; }
  td.num, th.num { text-align: right; }
  .table-wrap { overflow-x: auto; }
  .tag { display: inline-block; background: #e3f6ec; color: #2d7a57; padding: 2px 12px; border-radius: 999px; font-weight: bold; font-size: .9rem; white-space: nowrap; }

  .user-list { list-style: none; padding: 0; margin: 12px 0 0; }
  .user-list li { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 2px solid var(--line); }
  .user-list li:last-child { border-bottom: 0; }

  .intro { max-width: 640px; color: var(--muted); margin: -.2em 0 1.6em; }
  .visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  table.booklist td { vertical-align: middle; }
  table.booklist th, table.booklist td { padding-left: 10px; padding-right: 10px; }
  table.booklist th.c-check, table.booklist td.c-check { width: 52px; font-size: .85rem; text-align: center; padding-left: 12px; padding-right: 4px; }
  table.booklist th.c-cover, table.booklist td.c-cover { width: 76px; padding-left: 8px; padding-right: 8px; }
  table.booklist input[type=checkbox] { width: 24px; height: 24px; accent-color: var(--blue); cursor: pointer; vertical-align: middle; }
  table.booklist input[type=checkbox]:disabled { cursor: not-allowed; }
  .thumb { width: 48px; height: 66px; object-fit: cover; display: block; border-radius: 6px; border: 2px solid var(--line); background: #eaf3ff; }
  .von { font-weight: bold; color: var(--blue-dark); white-space: nowrap; }
  .c-actions { text-align: right; }
  .c-actions button { margin: 3px 0 3px 6px; white-space: nowrap; }
  tr.edit-row td { background: #f7fbff; }
  .chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 20px; }
  .chip { background: #fff; color: var(--ink); border: 2px solid var(--line); padding: 8px 18px; }
  .chip:hover { background: #eaf3ff; }
  .chip.active, .chip.active:hover { background: var(--blue); border-color: var(--blue); color: #fff; }
  .thumb.sq { width: 56px; height: 56px; }
  tr.reserved td { background: #eef0f3; color: #8b97a5; }
  tr.reserved .thumb { filter: grayscale(1); opacity: .55; }
  tr.reserved .von { color: #7a8796; }
  /* Startseite */
  .welcome { position: relative; text-align: center; padding: 24px 0 8px; }
  .welcome .dot { position: absolute; border-radius: 50%; animation: drift var(--t, 9s) ease-in-out var(--dl, 0s) infinite alternate; }
  @keyframes drift {
    from { transform: translate(0, 0); opacity: .85; }
    to   { transform: translate(var(--dx, 8px), var(--dy, -12px)); opacity: 1; }
  }
  @media (prefers-reduced-motion: reduce) { .welcome .dot { animation: none; } }
  .welcome-logo { width: 150px; height: auto; position: relative; }
  .welcome h1 { font-size: clamp(2rem, 5.5vw, 2.9rem); margin: 18px 0 8px; position: relative; }
  .welcome-sub { color: var(--muted); font-size: 1.15rem; margin: 0 0 40px; position: relative; }
  .welcome-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 20px; max-width: 700px; margin: 0 auto; position: relative; }
  .wcard { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 28px 20px; border-radius: 24px; border: 3px solid transparent; text-decoration: none; color: var(--ink); }
  .wcard.books { background: #e2eefc; }
  .wcard.depot { background: #e3f6ec; }
  .wcard:hover, .wcard:focus-visible { border-color: var(--sun); }
  .wcard svg { width: 68px; height: 68px; margin-bottom: 4px; }
  .wcard strong { font-size: 1.3rem; }
  .wcard .t { color: var(--muted); }
  /* Seiten ohne Login */
  .lock-card { max-width: 520px; margin: 28px auto 0; text-align: center; background: var(--surface); border: 2px solid var(--line); border-radius: 24px; padding: 36px 28px; }
  .lock-icon { position: relative; width: 112px; height: 112px; margin: 0 auto 20px; border-radius: 50%; background: #eaf3ff; display: grid; place-items: center; }
  .lock-icon > svg { width: 62px; height: 62px; }
  .lock-badge { position: absolute; right: -2px; bottom: -2px; width: 42px; height: 42px; border-radius: 50%; background: var(--sun); border: 3px solid #fff; display: grid; place-items: center; }
  .lock-badge svg { width: 22px; height: 22px; }
  .lock-card p { margin: 0; font-size: 1.1rem; }
  .lock-card a { font-weight: bold; color: var(--blue-dark); }
  /* Bild einfügen */
  .lbl { display: block; font-weight: bold; margin-bottom: 4px; font-size: .95rem; }
  .pastebox { display: flex; align-items: center; gap: 12px; min-height: 72px; padding: 10px 14px; border: 2px dashed var(--mint); border-radius: 12px; background: #f6fcf9; cursor: pointer; font-size: .95rem; }
  .pastebox:focus { outline: 3px solid var(--sun); outline-offset: 2px; border-style: solid; }
  .pastebox [data-preview] { display: flex; align-items: center; gap: 10px; }
  .pastebox .ok { color: #2d7a57; font-weight: bold; }
  summary { cursor: pointer; }
  .hero { text-align: center; padding: 40px 0; }
  .hero .box { display: inline-block; border: 3px dashed var(--mint); border-radius: 24px; padding: 40px 60px; background: #fff; }

  @media (max-width: 600px) {
    .hero .box { padding: 28px 24px; }
  }

  /* ============ Handy & Tablet ============ */
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  button, a, input, select, summary { touch-action: manipulation; }
  .menu-btn { display: none; }
  .mobile-only { display: none; }

  /* Kopfzeile: Menü-Knopf statt mehrzeiliger Navigation */
  @media (max-width: 860px) {
    header {
      flex-wrap: wrap; gap: 8px 12px;
      padding: 8px max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
    }
    .logo img { height: 48px; }
    .menu-btn { display: inline-flex; align-items: center; gap: 8px; margin-left: auto; min-height: 44px; }
    nav { display: none; width: 100%; flex-direction: column; gap: 4px; padding: 4px 0 8px; }
    header.open nav { display: flex; }
    nav a { padding: 12px 16px; border-radius: 12px; }
    html { scroll-padding-top: 76px; }
  }

  /* Allgemeine Abstände auf kleinen Bildschirmen */
  @media (max-width: 1100px) {
    body { font-size: 1rem; }
    main { padding: 20px 16px 48px; }
    h1 { font-size: 1.6rem; }
    h2 { font-size: 1.3rem; }
    .panel { padding: 16px; margin-bottom: 20px; }
    .form-grid { grid-template-columns: 1fr; }
    .form-grid button[type=submit] { width: 100%; }
    .intro { margin-bottom: 1.2em; }
    .welcome { padding-top: 8px; }
    .welcome-logo { width: 110px; }
    .welcome-sub { margin-bottom: 28px; }
    .wcard { padding: 22px 16px; }
    .lock-card { padding: 28px 18px; margin-top: 16px; }
    .lock-icon { width: 92px; height: 92px; }
    .chips { flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px 16px; padding: 2px 16px 6px; scrollbar-width: none; }
    .chips::-webkit-scrollbar { display: none; }
    .chip { flex: none; }
    .toolbar { gap: 8px; }
    .toolbar .spacer { flex: 1 0 100%; height: 0; }
    .user-list li { flex-wrap: wrap; }

    /* Tabellen werden zu Karten */
    .table-wrap { overflow: visible; }
    table.cards, table.cards tbody { display: block; border: 0; border-radius: 0; background: none; overflow: visible; }
    table.cards thead { display: none; }
    table.cards tr {
      display: grid; grid-template-columns: auto auto minmax(0, 1fr); align-items: center;
      background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius);
      padding: 12px 14px; margin-bottom: 12px;
    }
    table.cards td { display: block; grid-column: 3; border: 0; padding: 1px 0; text-align: left; background: none; min-width: 0; overflow-wrap: anywhere; }
    table.cards td:empty { display: none; }
    table.cards td.c-check, table.cards td.c-cover {
      grid-row: 1 / span 8; align-self: start; width: auto; padding: 0 12px 0 0; text-align: left;
    }
    table.cards td.c-check { grid-column: 1; padding-top: 2px; }
    table.cards td.c-cover { grid-column: 2; }
    table.cards td.c-main { font-size: 1.05rem; }
    table.cards td.c-sub { font-size: .95rem; }
    table.cards td.c-actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; padding-top: 10px; white-space: normal; }
    table.cards td.c-actions button { margin: 0; }
    table.cards td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); font-weight: normal; }
    table.cards td .von, table.cards td.von { white-space: normal; }
    table.cards tr.reserved { background: #eef0f3; }
    table.cards tr.reserved td { background: none; }
    table.cards tr.edit-row { display: block; margin-top: -6px; background: #f7fbff; }
    table.cards tr.edit-row td { padding: 0; }
    table.cards .mobile-only { display: block; font-size: .75rem; color: var(--muted); margin-top: 2px; text-align: center; }
    .c-actions button { flex: 1 1 auto; }
  }

  /* Touch-Geräte: größere Tippflächen, kein Strg+V-Hinweis */
  @media (pointer: coarse) {
    button { min-height: 44px; }
    button.small { min-height: 40px; padding: 8px 16px; }
    table.booklist input[type=checkbox] { width: 30px; height: 30px; }
    .paste-hint { display: none; }
    .pastebox { min-height: 0; border: 0; padding: 0; background: none; }
    .pastebox:not(:has(img)) { display: none; }
    input[type=text], input[type=password], input[type=number], select { min-height: 44px; font-size: max(16px, 1em); }
  }

  /* Bildauswahl */
  .filepick { position: relative; display: flex; align-items: center; gap: 10px; min-height: 46px; min-width: 0; }
  .filepick input[type=file] {
    position: absolute; left: 0; top: 0; width: 1px; height: 1px; padding: 0; border: 0;
    opacity: 0; overflow: hidden; clip: rect(0 0 0 0);
  }
  .filepick label.filebtn {
    display: inline-flex; align-items: center; gap: 8px; flex: none; margin: 0;
    padding: 10px 18px; border-radius: 999px; cursor: pointer;
    background: #e4eefb; color: var(--blue-dark); font-weight: bold; font-size: 1rem; line-height: 1.2;
  }
  .filepick label.filebtn:hover { background: #d3e4f9; }
  .filepick input:focus-visible + label.filebtn { outline: 3px solid var(--sun); outline-offset: 2px; }
  .filebtn svg { width: 20px; height: 20px; flex: none; }
  .filepick .filename {
    flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    color: var(--muted); font-size: .95rem;
  }
  .filepick.has-file .filename { color: var(--ink); font-weight: bold; }
  .filepick .filethumb { width: 40px; height: 40px; flex: none; object-fit: cover; border-radius: 8px; border: 2px solid var(--line); background: #eaf3ff; }
  .filepick .fileclear {
    flex: none; width: 36px; height: 36px; min-height: 0; padding: 0; border-radius: 50%;
    background: #fdeceb; color: var(--danger); font-size: 1.3rem; line-height: 1;
  }
  .filepick .fileclear:hover { background: #fadad8; }
  .filepick [hidden] { display: none !important; }
  @media (pointer: coarse) {
    .filepick label.filebtn { min-height: 44px; }
    .filepick .fileclear { width: 44px; height: 44px; min-height: 44px; }
  }
  .form-grid > * { min-width: 0; }
  .form-grid > .wide { grid-column: span 2; }
  @media (max-width: 1100px) { .form-grid > .wide { grid-column: auto; } }
  .filepick .filename {
    white-space: normal; overflow-wrap: anywhere; line-height: 1.25;
    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2;
  }
  .form-grid button { white-space: nowrap; }

  /* Versteckt (nur Admin sieht das) */
  .tag.hidden-tag {
    display: inline-flex; align-items: center; gap: 4px; margin-left: 8px; vertical-align: middle;
    background: #ece8f6; color: #5b4b8a; font-size: .8rem; padding: 1px 10px 1px 8px;
  }
  .hidden-tag svg { width: 14px; height: 14px; }
  tr.is-hidden td { background: repeating-linear-gradient(135deg, #fbfaff 0 10px, #f3f0fa 10px 20px); }
  tr.is-hidden .thumb { opacity: .5; }
  tr.is-hidden td.c-main strong { color: var(--muted); }
  .chip.chip-hidden { border-style: dashed; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
  .chip.chip-hidden.active { color: #fff; border-style: solid; }
  .chip svg { width: 16px; height: 16px; }
  .user-list li.is-hidden strong { color: var(--muted); }
  .user-list li { flex-wrap: wrap; }
  .li-actions { display: inline-flex; gap: 6px; flex-wrap: wrap; }
  @media (max-width: 1100px) {
    table.cards tr.is-hidden { border-style: dashed; background: repeating-linear-gradient(135deg, #fbfaff 0 10px, #f3f0fa 10px 20px); }
    table.cards tr.is-hidden td { background: none; }
    table.cards .hidden-tag { margin: 4px 0 0; display: flex; width: fit-content; }
  }
  @media (min-width: 1101px) {
    td.c-actions { width: 1%; }
    td.c-actions:has(button + button + button) button { display: block; width: 100%; margin: 3px 0; }
  }
  td.c-main .hidden-tag { display: flex; width: fit-content; margin: 4px 0 0; }

  /* Kommentare */
  textarea {
    font: inherit; width: 100%; padding: 9px 12px; resize: vertical; min-height: 76px;
    border: 2px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink);
  }
  textarea:focus { border-color: var(--blue); }
  textarea:focus-visible { outline: 3px solid var(--sun); outline-offset: 2px; }
  .form-grid > .full { grid-column: 1 / -1; }
  .edit-sub { font-size: 1rem; margin: 18px 0 8px; padding-top: 14px; border-top: 2px dashed var(--line); }
  /* Kommentar: gelb-oranges Ausrufezeichen + Blase */
  td.c-note { width: 1%; padding-left: 4px; padding-right: 4px; text-align: center; }
  button.note-btn {
    display: inline-grid; place-items: center; width: 30px; height: 30px; min-height: 0; padding: 0;
    border-radius: 50%; background: none; color: #f5a000; cursor: help; vertical-align: middle;
  }
  button.note-btn:hover, button.note-btn[aria-expanded="true"] { background: #fff1cc; color: #e08a00; }
  button.note-btn svg { width: 24px; height: 24px; }
  .note-pop {
    position: fixed; z-index: 60; max-width: min(300px, calc(100vw - 16px)); width: max-content;
    padding: 10px 14px; border-radius: 12px; border: 2px solid #f5c04a; background: #fffbea; color: var(--ink);
    box-shadow: 0 6px 20px rgba(42, 59, 77, .18); font-size: .95rem; line-height: 1.45;
    white-space: pre-line; overflow-wrap: anywhere; pointer-events: auto;
  }
  .note-pop[hidden] { display: none; }
  @media (pointer: coarse) { button.note-btn { width: 44px; height: 44px; min-height: 44px; } button.note-btn svg { width: 28px; height: 28px; } }
  @media (max-width: 1100px) {
    table.cards tr { position: relative; }
    table.cards td.c-note { position: absolute; top: 6px; right: 6px; width: auto; padding: 0; grid-column: auto; }
    table.cards tr:has(td.c-note:not(:empty)) td.c-main { padding-right: 40px; }
  }
  @media (max-width: 1100px) and (pointer: coarse) { table.cards tr:has(td.c-note:not(:empty)) td.c-main { padding-right: 52px; } }

  /* Einleitungstexte bearbeiten (Admin) */
  .intro { white-space: pre-line; }
  button.edit-btn {
    display: inline-grid; place-items: center; width: 28px; height: 28px; min-height: 0; padding: 0;
    margin-left: 8px; vertical-align: middle; border-radius: 50%;
    background: #fff; color: var(--blue-dark); border: 2px solid var(--line);
  }
  button.edit-btn:hover { background: #eaf3ff; border-color: var(--blue); }
  button.edit-btn svg { width: 15px; height: 15px; }
  .intro-edit { max-width: 640px; margin: -.2em 0 1.6em; }
  .intro-edit-actions { display: flex; gap: 8px; margin-top: 8px; }
  @media (pointer: coarse) { button.edit-btn { width: 40px; height: 40px; min-height: 40px; } button.edit-btn svg { width: 18px; height: 18px; } }

  /* Reservierungen (Admin): Bild, Titel, bunter Name, Anmerkung und Geldbetrag */
  .giver { margin-top: 4px; font-size: .95rem; color: var(--muted); }
  .giver-name {
    display: inline-block; font-weight: bold; color: #fff; background: var(--gc, var(--blue));
    padding: 1px 10px; border-radius: 999px; margin-left: 2px;
  }
  tr.reserved .giver-name { opacity: .6; }
  .res-date { font-size: .85rem; margin-top: 2px; }
  table.reslist td.c-main { min-width: 160px; }
  table.reslist td.c-resinfo { width: 50%; min-width: 280px; }
  .res-form { display: grid; grid-template-columns: minmax(0, 1fr) 130px; gap: 6px 10px; align-items: end; }
  .res-form .res-note { grid-row: 1 / span 2; }
  .res-form textarea { min-height: 64px; resize: vertical; }
  .res-form .res-save button { width: 100%; }
  @media (max-width: 1100px) {
    table.reslist td.c-resinfo { width: auto; min-width: 0; grid-column: 1 / -1; padding-top: 10px; }
    table.reslist td.c-main { min-width: 0; }
  }
  @media (max-width: 600px) {
    .res-form { grid-template-columns: 1fr; }
    .res-form .res-note { grid-row: auto; }
  }
