.book-title {
  margin-bottom: 14px;
}

.page {
  background: var(--cream);
  border-radius: 5px 15px 15px 5px;
  min-height: 520px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 25px 25px;
  position: relative;
  box-shadow:
    inset 0 0 30px var(--shadow-soft),
    2px 0 5px rgba(0, 0, 0, 0.1);
  animation: pageFlip 0.5s ease-out;
}

.subtitle {
  text-align: center;
  color: var(--text-dark);
  opacity: 0.9;
  line-height: 1.6;
  max-width: 720px;
  margin: 0 auto 6px;
}

.library-filter {
  width: 100%;
  max-width: 400px;
  margin: 0 auto 12px;
  padding: 10px 16px;
  border: 2px solid var(--lavender);
  border-radius: 12px;
  font-size: 1rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s ease;
  box-sizing: border-box;
}
.library-filter:focus {
  border-color: var(--primary);
}
.library-filter::placeholder {
  color: #aaa;
}

.library-spinner {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 48px 0;
}
.library-spinner .spinner-ring {
  width: 40px;
  height: 40px;
  border: 4px solid var(--lavender);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: libSpin 0.8s linear infinite;
}
@keyframes libSpin {
  to {
    transform: rotate(360deg);
  }
}

.library-no-results {
  text-align: center;
  color: var(--text-dark);
  opacity: 0.6;
  padding: 32px 0;
  font-size: 1rem;
}

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 18px;
  width: 100%;
  margin-top: 6px;
}

.book-card {
  background: white;
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 10px 30px var(--shadow-soft);
  border: 3px solid var(--lavender);
  transition:
    transform 0.15s ease,
    border-color 0.15s ease;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 165px;
}
.book-card:hover {
  transform: translateY(-2px);
  border-color: var(--coral);
}
.book-card:active {
  transform: translateY(2px);
}
.book-card.trash-selected {
  border-color: #e74c3c;
  background: rgba(231, 76, 60, 0.1);
}
.book-card.trash-mode:hover {
  border-color: #c0392b;
}

.card-title {
  font-family: 'Baloo 2', cursive;
  font-size: 1.15rem;
  color: var(--coral);
  text-shadow: 2px 2px 0 var(--sunshine);
}

.card-meta {
  color: var(--text-dark);
  opacity: 0.85;
  line-height: 1.5;
  font-size: 0.95rem;
  word-break: break-word;
}

.badge {
  align-self: flex-start;
  background: linear-gradient(145deg, var(--mint), var(--sky-blue));
  border: 2px solid var(--lavender);
  padding: 4px 10px;
  border-radius: 999px;
  font-family: 'Baloo 2', cursive;
  font-size: 0.85rem;
  color: #2d5a27;
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: auto;
  flex-wrap: wrap;
}
.card-edit-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-family: 'Baloo 2', cursive;
  font-size: 0.85rem;
  color: var(--text-dark);
  background: var(--mint);
  border: 2px solid var(--lavender);
  border-radius: 999px;
  text-decoration: none;
  cursor: pointer;
  transition:
    transform 0.15s ease,
    border-color 0.15s ease;
}
.card-edit-btn:hover {
  border-color: var(--coral);
  transform: translateY(-1px);
}
.card-edit-btn svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

.plus-card {
  border-style: dashed;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
  font-family: 'Baloo 2', cursive;
  font-size: 1.25rem;
  color: var(--text-dark);
  background: linear-gradient(135deg, var(--mint), var(--sky-blue));
}
.plus-card .plus {
  font-size: 2.1rem;
  color: var(--coral);
  text-shadow: 2px 2px 0 var(--sunshine);
  line-height: 1;
}

.form {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 14px;
  border: 3px solid var(--lavender);
  font-family: 'Fredoka', sans-serif;
  font-size: 1rem;
  outline: none;
  box-shadow: 0 10px 30px var(--shadow-soft);
}
.input:focus {
  border-color: var(--coral);
}

.row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.nav-btn {
  background: linear-gradient(145deg, var(--coral), #ff5252);
  border: none;
  color: white;
  padding: 12px 22px;
  font-family: 'Baloo 2', cursive;
  font-size: 1rem;
  border-radius: 50px;
  cursor: pointer;
  box-shadow:
    0 6px 0 #c94444,
    0 10px 20px var(--shadow-soft);
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.nav-btn:hover {
  transform: translateY(-2px);
  box-shadow:
    0 8px 0 #c94444,
    0 15px 30px var(--shadow-soft);
}
.nav-btn:active {
  transform: translateY(4px);
  box-shadow:
    0 2px 0 #c94444,
    0 5px 10px var(--shadow-soft);
}

.nav-btn.secondary {
  background: white;
  color: var(--text-dark);
  border: 3px solid var(--lavender);
  box-shadow: 0 6px 18px var(--shadow-soft);
}
.nav-btn.secondary:hover {
  transform: translateY(-2px);
  border-color: var(--coral);
  box-shadow: 0 10px 26px var(--shadow-soft);
}
.nav-btn.secondary:active {
  transform: translateY(2px);
}

.hint {
  color: var(--text-dark);
  opacity: 0.85;
  line-height: 1.6;
  font-size: 0.95rem;
  text-align: center;
}
.hint code {
  background: var(--mint);
  padding: 2px 7px;
  border-radius: 6px;
  font-family: 'Courier New', monospace;
  font-size: 0.92em;
  color: #2d5a27;
}

.error {
  background: white;
  border-left: 6px solid var(--coral);
  padding: 12px 14px;
  border-radius: 14px;
  box-shadow: 0 10px 30px var(--shadow-soft);
  color: var(--text-dark);
  display: none;
}
.error.show {
  display: block;
}

@media (max-width: 768px) {
  .page {
    min-height: 460px;
    padding: 20px;
  }
}

.thumbnail-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 10px;
  width: 100%;
  max-width: 500px;
  margin: 20px auto;
  max-height: 240px;
  overflow-y: auto;
  padding: 10px;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 12px;
}
.thumbnail {
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  border: 3px solid var(--lavender);
  background: #f0f0f0;
  transition:
    transform 0.15s ease,
    border-color 0.15s ease;
  position: relative;
}
.thumbnail:hover {
  transform: scale(1.05);
  border-color: var(--coral);
}
.thumbnail img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.thumbnail.pending {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  color: #888;
}
.thumbnail.failed {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  color: #c0392b;
  border-color: #e74c3c;
  background: rgba(231, 76, 60, 0.1);
}
.thumbnail .page-num {
  position: absolute;
  bottom: 2px;
  right: 4px;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  font-size: 0.65rem;
  padding: 1px 4px;
  border-radius: 4px;
}

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.lightbox.show {
  display: flex;
}
.lightbox-content {
  display: flex;
  gap: 20px;
  max-width: 95%;
  max-height: 90%;
  align-items: stretch;
}
.lightbox-content img {
  max-width: 55%;
  max-height: 90vh;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}
.lightbox-panel {
  width: 380px;
  max-width: 40%;
  min-width: 280px;
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.15);
}
.lightbox-panel-section {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 14px;
}
.lightbox-panel-section h4 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgba(255, 255, 255, 0.6);
  margin-bottom: 8px;
}
.lightbox-panel-section .text-block {
  font-size: 0.9rem;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.95);
  white-space: pre-wrap;
  word-break: break-word;
}
.lightbox-panel-section textarea.prompt-edit {
  width: 100%;
  min-height: 120px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  color: rgba(255, 255, 255, 0.95);
  font-size: 0.85rem;
  line-height: 1.4;
  padding: 8px;
  resize: vertical;
  font-family: inherit;
}
.lightbox-panel-section textarea.prompt-edit:focus {
  outline: none;
  border-color: var(--coral);
}
.lightbox-actions {
  padding: 12px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  display: flex;
  gap: 8px;
}
.lightbox-btn {
  flex: 1;
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  font-family: 'Baloo 2', cursive;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.15s ease;
}
.lightbox-btn.primary {
  background: linear-gradient(145deg, var(--coral), #ff5252);
  color: white;
}
.lightbox-btn.primary:hover:not(:disabled) {
  transform: translateY(-1px);
}
.lightbox-btn.primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.lightbox-btn.secondary {
  background: rgba(255, 255, 255, 0.1);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.2);
}
.lightbox-btn.secondary:hover {
  background: rgba(255, 255, 255, 0.2);
}
.lightbox-btn.approve {
  background: linear-gradient(145deg, var(--forest), #4a9e4a);
  color: white;
}
.lightbox-btn.approve:hover:not(:disabled) {
  transform: translateY(-1px);
}
.lightbox-btn.reject {
  background: linear-gradient(145deg, #e74c3c, #c0392b);
  color: white;
}
.lightbox-btn.reject:hover:not(:disabled) {
  transform: translateY(-1px);
}
.lightbox-panel-section:first-child {
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}
.lightbox-comparison {
  display: flex;
  gap: 12px;
  flex-direction: column;
}
.lightbox-comparison-row {
  display: flex;
  gap: 12px;
  align-items: center;
}
.lightbox-comparison-img {
  flex: 1;
  position: relative;
}
.lightbox-comparison-img img {
  width: 100%;
  max-height: 40vh;
  object-fit: contain;
  border-radius: 8px;
  border: 2px solid rgba(255, 255, 255, 0.2);
}
.lightbox-comparison-img.selected img {
  border-color: var(--forest);
  box-shadow: 0 0 12px rgba(107, 203, 119, 0.5);
}
.lightbox-comparison-label {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}
.comparison-arrow {
  font-size: 1.5rem;
  color: rgba(255, 255, 255, 0.5);
}
.lightbox-close {
  position: absolute;
  top: 20px;
  right: 20px;
  background: white;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 1.5rem;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
.lightbox-placeholder {
  max-width: 55%;
  min-width: 300px;
  min-height: 300px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  border: 2px dashed rgba(255, 255, 255, 0.3);
  color: rgba(255, 255, 255, 0.8);
  text-align: center;
  padding: 40px;
}
.placeholder-icon {
  font-size: 4rem;
  margin-bottom: 16px;
  opacity: 0.6;
}
.placeholder-text {
  font-size: 1.2rem;
  font-weight: 500;
  margin-bottom: 8px;
}
.placeholder-hint {
  font-size: 0.9rem;
  opacity: 0.7;
}

.card-publish-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-family: 'Baloo 2', cursive;
  font-size: 0.85rem;
  color: white;
  background: linear-gradient(145deg, var(--forest), #4a9e4a);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition:
    transform 0.15s ease,
    opacity 0.15s ease;
}
.card-publish-btn:hover {
  transform: translateY(-1px);
}
.card-publish-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.card-publish-btn.unpublish {
  background: linear-gradient(145deg, #888, #666);
}

/* Series card: stacked visual */
.series-card {
  position: relative;
  z-index: 1;
}
.series-card::before,
.series-card::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 18px;
  background: white;
  border: 3px solid var(--lavender);
  z-index: -1;
}
.series-card::before {
  transform: rotate(2deg) translate(4px, 4px);
  opacity: 0.6;
}
.series-card::after {
  transform: rotate(-1deg) translate(-2px, 6px);
  opacity: 0.35;
}
.series-card .badge {
  background: linear-gradient(145deg, var(--soft-pink), var(--lavender));
}

/* Toggle: Standalone / Part of Series */
.toggle-pill {
  display: flex;
  background: #e0e0e0;
  border-radius: 999px;
  overflow: hidden;
  align-self: center;
}
.toggle-pill button {
  padding: 10px 20px;
  border: none;
  background: transparent;
  font-family: 'Baloo 2', cursive;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--text-dark);
}
.toggle-pill button.active {
  background: white;
  box-shadow: 0 2px 8px var(--shadow-soft);
  border-radius: 999px;
  color: var(--coral);
}

/* Series detail screen */
.chapter-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}
.chapter-item {
  display: flex;
  align-items: center;
  gap: 14px;
  background: white;
  border: 2px solid var(--lavender);
  border-radius: 14px;
  padding: 12px 16px;
  cursor: pointer;
  transition:
    transform 0.15s ease,
    border-color 0.15s ease;
}
.chapter-item:hover {
  transform: translateY(-1px);
  border-color: var(--coral);
}
.chapter-num {
  font-family: 'Baloo 2', cursive;
  font-size: 1.4rem;
  color: var(--coral);
  min-width: 36px;
  text-align: center;
}
.chapter-info {
  flex: 1;
  min-width: 0;
}
.chapter-title {
  font-family: 'Baloo 2', cursive;
  font-size: 1rem;
  color: var(--text-dark);
}
.chapter-status {
  font-size: 0.85rem;
  opacity: 0.7;
}

.chapter-item.editing {
  cursor: default;
}
.chapter-item.editing:hover {
  transform: none;
  border-color: var(--lavender);
}
.chapter-rename-input {
  font-family: 'Baloo 2', cursive;
  font-size: 1rem;
  color: var(--text-dark);
  border: 2px solid var(--lavender);
  border-radius: 8px;
  padding: 4px 8px;
  width: 100%;
  outline: none;
}
.chapter-rename-input:focus {
  border-color: var(--coral);
}
.chapter-delete-btn {
  background: none;
  border: 2px solid var(--lavender);
  border-radius: 8px;
  padding: 4px 8px;
  cursor: pointer;
  color: #e74c3c;
  font-size: 0.85rem;
  font-family: 'Baloo 2', cursive;
  transition: border-color 0.15s ease;
  white-space: nowrap;
}
.chapter-delete-btn:hover {
  border-color: #e74c3c;
}
.series-edit-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-family: 'Baloo 2', cursive;
  font-size: 0.85rem;
  color: var(--text-dark);
  background: var(--mint);
  border: 2px solid var(--lavender);
  border-radius: 999px;
  cursor: pointer;
  transition:
    transform 0.15s ease,
    border-color 0.15s ease;
}
.series-edit-btn:hover {
  border-color: var(--coral);
  transform: translateY(-1px);
}
.series-edit-btn svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}
.series-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}
.series-title-input {
  font-family: 'Baloo 2', cursive;
  font-size: 1.3rem;
  color: var(--coral);
  border: 2px solid var(--lavender);
  border-radius: 8px;
  padding: 4px 8px;
  outline: none;
  text-align: center;
  max-width: 300px;
}
.series-title-input:focus {
  border-color: var(--coral);
}

/* Continuity panel */
.continuity-panel {
  width: 100%;
  background: white;
  border: 2px solid var(--lavender);
  border-radius: 14px;
  overflow: hidden;
  margin-top: 10px;
}
.continuity-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  cursor: pointer;
  background: linear-gradient(135deg, var(--mint), var(--sky-blue));
  font-family: 'Baloo 2', cursive;
  font-size: 1rem;
  color: var(--text-dark);
}
.continuity-body {
  padding: 16px;
  display: none;
}
.continuity-body.open {
  display: block;
}
.continuity-char {
  margin-bottom: 12px;
  padding: 10px;
  background: var(--cream);
  border-radius: 10px;
}
.continuity-char-name {
  font-family: 'Baloo 2', cursive;
  color: var(--coral);
  font-size: 0.95rem;
}
.continuity-char-detail {
  font-size: 0.85rem;
  color: var(--text-dark);
  line-height: 1.5;
}
.continuity-edit-area {
  width: 100%;
  min-height: 100px;
  border: 2px solid var(--lavender);
  border-radius: 10px;
  padding: 10px;
  font-family: 'Fredoka', sans-serif;
  font-size: 0.9rem;
  resize: vertical;
  margin-top: 8px;
}
.continuity-edit-area:focus {
  border-color: var(--coral);
  outline: none;
}

/* Inline add chapter form */
.inline-add {
  display: flex;
  gap: 10px;
  width: 100%;
  margin-top: 10px;
}
.inline-add .input {
  flex: 1;
}
