/* ------------------------------------------------------------------
   Bücherregal – Gestaltung
   Die Farben stehen ganz oben. --accent ist die Akzentfarbe
   (Buttons, Lesebändchen) – dort kannst du z. B. ihre Lieblingsfarbe setzen.
------------------------------------------------------------------- */

@font-face {
  font-family: "Literata";
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
  src: url("/fonts/literata-latin-opsz-normal.woff2") format("woff2");
}

@font-face {
  font-family: "Literata";
  font-style: italic;
  font-weight: 200 900;
  font-display: swap;
  src: url("/fonts/literata-latin-opsz-italic.woff2") format("woff2");
}

:root {
  color-scheme: light dark;

  --paper: #FBFBFA;
  --surface: #FFFFFF;
  --field: #F0F1F2;
  --ink: #23272E;
  --ink-soft: #686E77;
  --rule: #DADDE1;
  --accent: #8C2F3E;
  --accent-ink: #FFFFFF;
  --shelf-shadow: rgba(35, 39, 46, 0.07);
  --cover-shadow: 0 1px 1px rgba(35, 39, 46, 0.12), 0 9px 14px -10px rgba(35, 39, 46, 0.6);
  --small-cover-shadow: 0 1px 2px rgba(35, 39, 46, 0.22);
  --button-shadow: 0 12px 24px -14px rgba(140, 47, 62, 0.85);
  --backdrop: rgba(23, 25, 29, 0.36);

  --serif: "Literata", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --pad: 22px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --kb: 0px; /* Höhe der Bildschirmtastatur, wird per JS gesetzt */
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #17191D;
    --surface: #1F2227;
    --field: #2A2E34;
    --ink: #ECEAE6;
    --ink-soft: #9BA1A9;
    --rule: #353A41;
    --accent: #D77A8A;
    --accent-ink: #1B1012;
    --shelf-shadow: rgba(0, 0, 0, 0.28);
    --cover-shadow: 0 1px 1px rgba(0, 0, 0, 0.4), 0 10px 16px -10px rgba(0, 0, 0, 0.95);
    --small-cover-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
    --button-shadow: 0 12px 24px -14px rgba(0, 0, 0, 0.9);
    --backdrop: rgba(0, 0, 0, 0.55);
  }
}

/* ---------- Grundlagen ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font: 400 17px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}

html.is-locked,
html.is-locked body {
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled {
  cursor: default;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}

svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Bausteine ---------- */

.ribbon {
  display: block;
  width: 16px;
  height: 56px;
  background: var(--accent);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 80%, 0 100%);
}

.field {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  border: 0;
  border-radius: 12px;
  background: var(--field);
  color: var(--ink);
  font: 400 17px/1.3 var(--sans);
  padding: 13px 14px;
}

.field::placeholder {
  color: var(--ink-soft);
  opacity: 1;
}

.field:focus-visible {
  outline-offset: 0;
  border-radius: 12px;
}

.field-label {
  display: block;
  margin-bottom: 8px;
  color: var(--ink-soft);
  font-size: 15px;
}

.form-error {
  min-height: 1.4em;
  margin: 10px 0 18px;
  color: var(--accent);
  font-size: 15px;
}

.button-primary,
.add-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  padding: 0 26px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 17px;
  font-weight: 600;
  transition: transform 0.12s ease, opacity 0.2s ease;
}

.button-primary:active,
.add-button:active {
  transform: scale(0.97);
}

.button-primary:disabled {
  opacity: 0.55;
  transform: none;
}

.text-button {
  padding: 10px 4px;
  color: var(--accent);
  font-size: 17px;
  font-weight: 500;
}

.button-remove {
  width: 100%;
  min-height: 50px;
  padding: 0 22px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  color: var(--accent);
  font-weight: 500;
  transition: background-color 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}

.button-remove.is-confirming {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

/* Zeile mit Plus, z. B. „Neues Regal“ oder „ohne Cover auswählen“ */
.add-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 16px 0;
  color: var(--accent);
  font-weight: 500;
  text-align: left;
}

.add-row svg {
  flex: none;
  width: 22px;
  height: 22px;
}

.add-row .icon-check,
.add-row[aria-pressed="true"] .icon-plus {
  display: none;
}

.add-row[aria-pressed="true"] .icon-check {
  display: block;
}

.add-row:disabled {
  color: var(--ink-soft);
}

/* ---------- Anmeldung ---------- */

.login-view {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(var(--safe-top) + 24px) var(--pad) calc(var(--safe-bottom) + 24px);
}

.login-form {
  display: flex;
  flex-direction: column;
  width: min(100%, 320px);
}

.login-title {
  margin: 28px 0 44px;
  font: 500 34px/1.1 var(--serif);
  letter-spacing: -0.015em;
}

.login-field {
  font-size: 22px;
  letter-spacing: 0.25em;
}

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

.picker-view {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 40px) var(--pad) calc(var(--safe-bottom) + 40px);
}

.picker-title {
  margin: 0 0 26px;
  font: 500 34px/1.12 var(--serif);
  letter-spacing: -0.015em;
}

.shelf-list {
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--rule);
}

.shelf-row {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--rule);
}

.shelf-open {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 18px;
  min-width: 0;
  padding: 18px 0;
  text-align: left;
  transition: opacity 0.15s ease;
}

.shelf-open:active {
  opacity: 0.6;
}

.shelf-row-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.shelf-row-name {
  overflow: hidden;
  font: 500 21px/1.25 var(--serif);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.shelf-row-count {
  color: var(--ink-soft);
  font-size: 15px;
}

.shelf-more {
  display: grid;
  flex: none;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-right: -10px;
  color: var(--ink-soft);
}

.shelf-more svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
  stroke: none;
}

/* Kleiner Bücherstapel als Vorschau */
.mini-stack {
  display: flex;
  flex: none;
  align-items: flex-end;
  width: 76px;
}

.mini-stack .cover {
  width: 36px;
  flex: none;
  box-shadow: var(--small-cover-shadow);
}

.mini-stack .cover + .cover {
  margin-left: -16px;
}

.mini-stack .cover:nth-child(1) { z-index: 3; }
.mini-stack .cover:nth-child(2) { z-index: 2; transform: translateY(-3px); }
.mini-stack .cover:nth-child(3) { z-index: 1; transform: translateY(-6px); }

.mini-empty {
  display: block;
  width: 36px;
  aspect-ratio: 2 / 3;
  border: 1.5px dashed var(--rule);
  border-radius: 2px 3px 3px 2px;
}

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

.shelf-view {
  max-width: 980px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 28px) var(--pad) calc(var(--safe-bottom) + 128px);
}

.shelf-header {
  margin-bottom: 34px;
}

.shelf-switch {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  max-width: 100%;
  margin: 0 0 4px -2px;
  padding: 6px 2px;
  color: var(--ink-soft);
  font-size: 16px;
  font-weight: 500;
}

.shelf-switch span {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.shelf-switch svg {
  flex: none;
  width: 18px;
  height: 18px;
  stroke-width: 2.4;
}

.count {
  margin: 0;
  font: 500 34px/1.12 var(--serif);
  letter-spacing: -0.015em;
  text-wrap: balance;
}

.empty-hint {
  max-width: 30ch;
  margin: 12px 0 0;
  color: var(--ink-soft);
}

.shelf {
  --gap-x: 16px;
  --gap-y: 40px;
  position: relative;
  z-index: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  column-gap: var(--gap-x);
  row-gap: var(--gap-y);
  margin: 0 -14px;
  padding: 0 14px 12px;
  list-style: none;
  overflow-x: clip;
}

/* Leeres Regal: ein einzelnes Brett */
.shelf:empty {
  height: 1px;
  padding: 0;
  margin: 8px 0 0;
  background: var(--rule);
}

.shelf-item {
  position: relative;
}

/* Das Regalbrett: läuft unter jeder Reihe über die volle Breite */
.shelf-item::after {
  content: "";
  position: absolute;
  left: -100vw;
  right: -100vw;
  bottom: -10px;
  height: 10px;
  background:
    linear-gradient(var(--rule), var(--rule)) top / 100% 1px no-repeat,
    linear-gradient(var(--shelf-shadow), transparent) 0 1px / 100% 9px no-repeat;
  pointer-events: none;
  z-index: -1;
}

.book {
  display: block;
  width: 100%;
}

.book:active .cover {
  transform: translateY(-4px);
}

.shelf-item.is-new .cover {
  animation: settle 0.55s var(--ease-out) both;
  animation-delay: var(--delay, 0s);
}

@keyframes settle {
  from {
    opacity: 0;
    transform: translateY(-18px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---------- Cover ---------- */

.cover {
  position: relative;
  display: block;
  aspect-ratio: 2 / 3;
  overflow: hidden;
  border-radius: 2px 3px 3px 2px;
  background: var(--field);
  box-shadow: var(--cover-shadow);
  transition: transform 0.18s var(--ease-out);
}

/* Leichter Buchrücken-Knick am linken Rand */
.cover::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg,
    rgba(0, 0, 0, 0.16) 0,
    rgba(255, 255, 255, 0.16) 2px,
    rgba(255, 255, 255, 0) 7px);
  pointer-events: none;
}

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

/* Cover ohne Bild: wie ein Leinen-Einband */
.cover-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  padding: 14% 11%;
  background: var(--cloth, #55606B);
  color: #F3F2EE;
}

.cover-placeholder-title {
  display: -webkit-box;
  overflow: hidden;
  font: 500 12.5px/1.25 var(--serif);
  overflow-wrap: break-word;
  -webkit-hyphens: auto;
  hyphens: auto;
  -webkit-line-clamp: 6;
  -webkit-box-orient: vertical;
}

/* In kleinen Covern ist für den Titel kein Platz */
.result .cover-placeholder-title,
.tray-item .cover-placeholder-title,
.mini-stack .cover-placeholder-title {
  display: none;
}

/* Button unten im Regal */
.add-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  padding: 28px var(--pad) calc(var(--safe-bottom) + 18px);
  background: linear-gradient(to top, var(--paper) 50%, rgba(251, 251, 250, 0));
  pointer-events: none;
}

@media (prefers-color-scheme: dark) {
  .add-bar {
    background: linear-gradient(to top, var(--paper) 50%, rgba(23, 25, 29, 0));
  }
}

.add-button {
  pointer-events: auto;
  box-shadow: var(--button-shadow);
}

.add-button svg {
  width: 20px;
  height: 20px;
  margin-left: -4px;
}

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

.search-sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  background: var(--surface);
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 0.2s ease, transform 0.28s var(--ease-out);
}

.search-sheet.is-open {
  opacity: 1;
  transform: none;
}

.search-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px var(--pad);
  border-bottom: 1px solid var(--rule);
}

.search-field-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}

.search-icon {
  position: absolute;
  top: 50%;
  left: 12px;
  width: 20px;
  height: 20px;
  color: var(--ink-soft);
  stroke-width: 2;
  transform: translateY(-50%);
  pointer-events: none;
}

.search-field {
  padding-left: 40px;
}

.search-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 0 var(--pad) calc(var(--safe-bottom) + 28px);
}

.search-sheet.has-selection .search-body {
  padding-bottom: calc(var(--safe-bottom) + var(--kb) + 120px);
}

.search-status {
  margin: 16px 0 4px;
  color: var(--ink-soft);
  font-size: 15px;
}

.search-status:empty {
  display: none;
}

.results {
  margin: 0;
  padding: 0;
  list-style: none;
}

.result {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  padding: 12px 0;
  border-bottom: 1px solid var(--rule);
  text-align: left;
  transition: opacity 0.15s ease;
}

.result:active {
  opacity: 0.7;
}

.result:disabled,
.result:disabled:active {
  opacity: 0.5;
}

.result-cover {
  position: relative;
  flex: none;
  width: 44px;
}

.result-cover .cover {
  box-shadow: var(--small-cover-shadow);
}

/* Haken an ausgewählten Büchern */
.check {
  position: absolute;
  top: -8px;
  right: -9px;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 0 0 2px var(--surface);
  transform: scale(0);
  transition: transform 0.18s var(--ease-out);
}

.check svg {
  width: 14px;
  height: 14px;
  stroke-width: 3;
}

.result.is-selected .check {
  transform: scale(1);
}

.result-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.result-title {
  display: -webkit-box;
  overflow: hidden;
  font: 500 17px/1.3 var(--serif);
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.result-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.result-author {
  overflow: hidden;
  min-width: 0;
  color: var(--ink-soft);
  font-size: 15px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.result-lang {
  flex: none;
  padding: 2px 6px;
  border: 1px solid var(--rule);
  border-radius: 5px;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.3;
}

/* Leiste mit der Auswahl */
.selection-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: var(--kb);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px var(--pad) calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--rule);
  background: var(--surface);
}

.selection-tray {
  display: flex;
  flex: 1;
  gap: 8px;
  min-width: 0;
  margin: 0;
  padding: 4px 2px;
  overflow-x: auto;
  list-style: none;
  scrollbar-width: none;
}

.selection-tray::-webkit-scrollbar {
  display: none;
}

.tray-item {
  display: block;
  flex: none;
  width: 30px;
}

.tray-item .cover {
  box-shadow: var(--small-cover-shadow);
}

.tray-item.is-new .cover {
  animation: pop 0.25s var(--ease-out);
}

@keyframes pop {
  from {
    transform: scale(0.6);
    opacity: 0;
  }
}

.selection-submit {
  flex: none;
  min-height: 48px;
  padding: 0 20px;
}

/* ---------- Fenster von unten ---------- */

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: var(--backdrop);
  opacity: 0;
  transition: opacity 0.22s ease;
}

.backdrop.is-open {
  opacity: 1;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: var(--kb);
  z-index: 31;
  max-width: 520px;
  max-height: 92dvh;
  margin: 0 auto;
  padding: 30px var(--pad) calc(var(--safe-bottom) + 16px);
  overflow-y: auto;
  border-radius: 18px 18px 0 0;
  background: var(--surface);
  transform: translateY(100%);
  transition: transform 0.32s var(--ease-out);
}

.sheet.is-open {
  transform: none;
}

.sheet-title {
  margin: 0 0 22px;
  font: 500 24px/1.22 var(--serif);
  letter-spacing: -0.01em;
}

/* Buchdetails */
.detail-sheet {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 34px;
  text-align: center;
}

.detail-cover {
  width: 136px;
  margin-bottom: 24px;
}

.detail-cover .cover {
  box-shadow: 0 2px 3px rgba(35, 39, 46, 0.14), 0 18px 28px -16px rgba(35, 39, 46, 0.65);
}

.detail-cover .cover-placeholder-title {
  font-size: 18px;
}

.detail-title {
  margin: 0;
  font: 500 24px/1.22 var(--serif);
  letter-spacing: -0.01em;
  text-wrap: balance;
}

.detail-author {
  margin: 6px 0 0;
  color: var(--ink-soft);
}

.detail-date {
  margin: 14px 0 0;
  color: var(--ink-soft);
  font-size: 15px;
}

.detail-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
  margin-top: 30px;
}

.detail-actions .button-remove {
  max-width: 320px;
}

/* Regal anlegen oder bearbeiten */
.shelf-form {
  display: flex;
  flex-direction: column;
}

.shelf-form .form-error {
  margin-bottom: 14px;
}

.shelf-form .button-remove {
  margin-top: 10px;
}

.shelf-form .text-button {
  align-self: center;
  margin-top: 6px;
}

/* ---------- Hinweis unten ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 96px);
  z-index: 50;
  width: max-content;
  max-width: calc(100% - 2 * var(--pad));
  padding: 11px 16px;
  border-radius: 12px;
  background: var(--ink);
  color: var(--paper);
  font-size: 15px;
  line-height: 1.35;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 8px);
  transition: opacity 0.2s ease, transform 0.25s var(--ease-out);
  pointer-events: none;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- Geburtstagsbotschaft ---------- */

.greeting {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  overflow-y: auto;
  padding: calc(var(--safe-top) + 40px) var(--pad) calc(var(--safe-bottom) + 32px);
  background: var(--paper);
  transition: opacity 0.4s ease;
}

.greeting.is-leaving {
  opacity: 0;
}

.greeting-inner {
  width: 100%;
  max-width: 34rem;
  margin: auto;
}

.greeting-name {
  margin: 30px 0 26px;
  font: 500 36px/1.1 var(--serif);
  letter-spacing: -0.015em;
  text-wrap: balance;
}

.greeting-message p {
  margin: 0 0 1em;
  font: 400 19px/1.65 var(--serif);
  white-space: pre-line;
}

.greeting-signature {
  margin: 28px 0 44px;
  font: italic 400 19px/1.5 var(--serif);
}

/* Der eine große Moment: Lesebändchen fällt, Zeilen erscheinen nacheinander */
.greeting .ribbon {
  transform: scaleY(0);
  transform-origin: top;
  transition: transform 0.9s var(--ease-out);
}

.greeting .reveal {
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.8s ease, transform 0.8s var(--ease-out);
  transition-delay: calc(0.5s + var(--i, 0) * 0.16s);
}

.greeting.is-visible .ribbon {
  transform: none;
}

.greeting.is-visible .reveal {
  opacity: 1;
  transform: none;
}

/* ---------- Größere Bildschirme ---------- */

@media (min-width: 700px) {
  :root {
    --pad: 40px;
  }

  .shelf {
    --gap-x: 22px;
    --gap-y: 46px;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  }

  .count,
  .picker-title {
    font-size: 42px;
  }

  .sheet {
    bottom: calc(24px + var(--kb));
    border-radius: 18px;
  }
}

/* ---------- Weniger Bewegung, wenn im System eingestellt ---------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0s !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0s !important;
  }
}
