/* styles.css — mobil-first, große Touch-Ziele. */

:root {
  --accent: #6a5ae0;
  --accent-2: #8a7bff;
  --danger: #e0483b;
  --bg: #f4f2fb;
  --card: #ffffff;
  --ink: #2b2740;
  --muted: #8b86a3;
  --line: #e7e3f5;
  --topbar-h: 56px;
  --shadow: 0 6px 18px rgba(60, 40, 120, 0.12);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink); background: var(--bg);
  overscroll-behavior: none;
}
body { touch-action: manipulation; }
button { font-family: inherit; cursor: pointer; }

/* ---------- Screens ---------- */
.screen { display: none; min-height: 100%; flex-direction: column; }
.screen.is-active { display: flex; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 6px;
  height: calc(var(--topbar-h) + var(--safe-top));
  padding: var(--safe-top) 8px 0;
  background: var(--accent);
  color: #fff; box-shadow: var(--shadow);
}
.topbar__title {
  flex: 1; font-size: 19px; font-weight: 700;
  text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar__title--tap { text-decoration: underline dotted rgba(255,255,255,.5); }
.iconbtn {
  min-width: 44px; height: 44px; border: 0; background: transparent;
  color: #fff; font-size: 24px; border-radius: 12px;
}
.iconbtn:active { background: rgba(255,255,255,.18); }
.topbar--editor .topbar__title { font-size: 15px; }

/* ---------- Regal ---------- */
.shelf {
  flex: 1; display: grid; grid-template-columns: repeat(2, 1fr);
  gap: 16px; padding: 16px; padding-bottom: 120px;
}
.booktile { display: flex; flex-direction: column; }
.booktile__cover {
  position: relative; aspect-ratio: 3 / 4; border-radius: 14px;
  box-shadow: var(--shadow); overflow: hidden; background: #ddd;
}
.booktile__menu {
  position: absolute; top: 6px; right: 6px; width: 34px; height: 34px;
  border: 0; border-radius: 50%; background: rgba(0,0,0,.35); color: #fff;
  font-size: 20px; line-height: 1; padding: 0;
}
.booktile__name {
  margin-top: 8px; font-weight: 600; font-size: 14px; text-align: center;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.empty {
  grid-column: 1 / -1; text-align: center; color: var(--muted);
  margin-top: 60px; line-height: 1.6;
}
.empty__emoji { font-size: 54px; }
.empty--small { margin: 20px 0; }

/* ---------- FAB ---------- */
.fab {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(20px + var(--safe-bottom));
  display: inline-flex; align-items: center; gap: 8px;
  border: 0; border-radius: 30px; padding: 14px 22px;
  background: var(--accent); color: #fff; font-size: 16px; font-weight: 700;
  box-shadow: var(--shadow); z-index: 30;
}
.fab:active { background: var(--accent-2); }
.fab__plus { font-size: 22px; line-height: 1; }

/* ---------- Buch-Ansicht ---------- */
.book-scroll { flex: 1; overflow-y: auto; padding: 16px; padding-bottom: 120px; }
.cover {
  position: relative; width: 62%; max-width: 260px; margin: 4px auto 8px;
  aspect-ratio: 3 / 4; border-radius: 16px; box-shadow: var(--shadow);
  overflow: hidden; display: flex; align-items: flex-end; justify-content: center;
}
.cover__hint {
  position: absolute; top: 8px; left: 0; right: 0; text-align: center;
  font-size: 12px; color: rgba(0,0,0,.45);
}
.cover__title {
  position: relative; z-index: 2; width: 100%; padding: 12px 10px;
  text-align: center; font-weight: 800; font-size: 20px; color: #fff;
  text-shadow: 0 1px 4px rgba(0,0,0,.55); word-break: break-word;
}
.pages-head { margin: 18px 4px 8px; }
.pages-head h2 { margin: 0; font-size: 16px; color: var(--muted); }
.page-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.pagethumb { position: relative; }
.pagethumb__preview {
  position: relative; aspect-ratio: 3 / 4; border-radius: 10px;
  box-shadow: var(--shadow); overflow: hidden; background: #fff;
  container-type: inline-size;
}
.pagethumb__preview .prev-text { font-weight: 600; line-height: 1.1; }
.pagethumb__del {
  position: absolute; top: 4px; right: 4px; width: 26px; height: 26px;
  border: 0; border-radius: 50%; background: rgba(0,0,0,.4); color: #fff;
  font-size: 18px; line-height: 1; padding: 0; z-index: 3;
}
.pagethumb__num { text-align: center; font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ---------- Editor ---------- */
#screen-editor.is-active { display: flex; }
.stage {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 10px; overflow: hidden; background: #efeaf9;
}
.page {
  position: relative; width: min(100%, calc((100vh - var(--topbar-h) - 190px) * 0.75));
  max-height: 100%; aspect-ratio: 3 / 4;
  border-radius: 10px; box-shadow: var(--shadow); overflow: hidden;
  background: #fff; container-type: inline-size; touch-action: none;
}
.page__canvas { position: absolute; inset: 0; width: 100%; height: 100%; }

/* Elemente (Bild/Text) */
.el { position: absolute; z-index: 2; touch-action: none; }
.el--image { }
.el__content { display: block; }
.el--image .el__content { width: 100%; height: auto; pointer-events: none; }
.el--text { max-width: 90%; }
.el__text {
  min-width: 24px; padding: 2px 4px; outline: none; line-height: 1.15;
  white-space: pre-wrap; word-break: break-word; font-weight: 600;
}
.el__text:empty:before { content: attr(data-ph); color: rgba(0,0,0,.35); }
.el.selected { outline: 2px dashed var(--accent); outline-offset: 2px; }

/* Griffe */
.handle { display: none; position: absolute; z-index: 5; }
.el.selected .handle { display: flex; align-items: center; justify-content: center; }
.handle--del {
  top: -14px; right: -14px; width: 28px; height: 28px; border: 0;
  border-radius: 50%; background: var(--danger); color: #fff; font-size: 18px; padding: 0;
}
.handle--size {
  bottom: -14px; right: -14px; width: 28px; height: 28px;
  border-radius: 50%; background: var(--accent); color: #fff; font-size: 15px;
  cursor: nwse-resize;
}

/* Werkzeug-Leiste */
.tool-panel {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  min-height: 56px; overflow-x: auto; background: #fff; border-top: 1px solid var(--line);
}
.tp-row { display: flex; gap: 8px; }
.tp-scroll { overflow-x: auto; }
.tp-hint { color: var(--muted); font-size: 14px; padding: 0 4px; white-space: nowrap; }
.tp-btn {
  border: 1px solid var(--line); background: #f7f5ff; color: var(--ink);
  border-radius: 12px; padding: 10px 12px; font-size: 15px; font-weight: 600;
  white-space: nowrap;
}
.tp-btn:active { background: #ece7ff; }
.tp-btn--wide { flex: 1; }
.tp-btn--danger { background: #ffecea; color: var(--danger); border-color: #ffd3ce; }
.tp-btn--on { background: var(--accent); color: #fff; }
.tp-colors { display: flex; gap: 6px; }
.colordot {
  width: 30px; height: 30px; border-radius: 50%; border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--line); padding: 0;
}
.colordot.is-sel { box-shadow: 0 0 0 3px var(--accent); }
.sizedot {
  width: 40px; height: 40px; border: 1px solid var(--line); background: #f7f5ff;
  border-radius: 12px; display: flex; align-items: center; justify-content: center; padding: 0;
}
.sizedot span { display: block; background: var(--ink); border-radius: 50%; }
.sizedot.is-sel { border-color: var(--accent); background: #ece7ff; }

/* Modus-Leiste */
.modebar {
  display: flex; background: #fff; border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
}
.modebtn {
  flex: 1; border: 0; background: transparent; color: var(--muted);
  padding: 8px 2px 10px; font-size: 11px; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.modebtn__ico { font-size: 22px; }
.modebtn.is-active { color: var(--accent); }
.modebtn.is-active .modebtn__ico { transform: translateY(-1px); }

/* ---------- Overlay / Dialoge ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 100; background: rgba(30,20,60,.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.overlay[hidden] { display: none; }
.overlay__card {
  width: 100%; max-width: 480px; background: #fff;
  border-radius: 20px 20px 0 0; padding: 18px 18px calc(18px + var(--safe-bottom));
  box-shadow: 0 -8px 30px rgba(30,20,60,.25);
  animation: slideup .18s ease;
}
@keyframes slideup { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.dlg__title { margin: 4px 0 14px; font-size: 18px; }
.dlg__msg { margin: 0 0 14px; color: var(--muted); }
.dlg__label { margin: 6px 0; font-size: 14px; color: var(--muted); }
.dlg__input {
  width: 100%; padding: 14px; font-size: 16px; border: 1px solid var(--line);
  border-radius: 12px; margin-bottom: 14px; background: #faf9ff;
}
.dlg__row { display: flex; gap: 10px; justify-content: flex-end; }
.dlg__row--wrap { flex-wrap: wrap; justify-content: flex-start; margin-bottom: 10px; }
.dlg__check { display: flex; align-items: center; gap: 8px; margin: 6px 0 14px; font-size: 15px; }
.btn { border: 0; border-radius: 12px; padding: 13px 18px; font-size: 15px; font-weight: 700; }
.btn--primary { background: var(--accent); color: #fff; }
.btn--ghost { background: #f0edfb; color: var(--ink); }
.btn--danger { background: var(--danger); color: #fff; }

/* Swatches (Cover + Hintergrund) */
.swatches { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
.swatch { aspect-ratio: 1; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); border-radius: 12px; padding: 0; }
.swatch--sm { width: 42px; height: 42px; aspect-ratio: 1; flex: 0 0 auto; border-radius: 10px; }
.swatch.is-sel { box-shadow: 0 0 0 3px var(--accent); }

/* Bottom-Sheet */
.sheet { display: flex; flex-direction: column; gap: 8px; }
.sheet__btn {
  border: 0; background: #f4f2fb; border-radius: 12px; padding: 15px;
  font-size: 16px; font-weight: 600; text-align: left; color: var(--ink);
}
.sheet__btn--danger { color: var(--danger); }
.sheet__btn--cancel { text-align: center; color: var(--muted); margin-top: 4px; }
