* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

select {
  text-align: center !important;
  text-align-last: center !important;
}

option {
  text-align: center !important;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 120vh;
  margin-bottom: 150px;
  padding: 20px;
}

.container {
  max-width: 1600px;
  margin: 0 auto;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: white;
  margin-bottom: 30px;
  padding: 20px 30px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 15px;
  position: relative;
}

header h1 {
  font-size: 2rem;
}

.header-buttons {
  display: flex;
  gap: 16px;
}

.icon-btn {
  background: white;
  color: #667eea;
  border: none;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.3s;
  min-width: 42px;
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover {
  background: #f0f0f0;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.15);
}

.download-btn {
  background: #28a745;
  color: white;
}

.save-btn {
  background: #ffc107;
  color: #333;
}

.settings-btn {
  background: #6c5ce7;
  color: white;
}

.print-btn {
  background: #6c757d;
  color: white;
}

.share-btn {
  background: #17a2b8;
  color: white;
}

.download-btn:hover {
  background: #218838;
}

.save-btn:hover {
  background: #e0a800;
}

.settings-btn:hover {
  background: #5447c7;
}

.print-btn:hover {
  background: #5a6268;
}

.share-btn:hover {
  background: #138496;
}

.chat-history {
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 10px;
  padding: 10px;
  background: #f8f9fa;
  border-radius: 8px;
  display: none;
}

.chat-history.active {
  display: block;
}

.chat-message {
  margin-bottom: 12px;
  padding: 8px 12px;
  border-radius: 8px;
  max-width: 85%;
}

.chat-message.user {
  background: #667eea;
  color: white;
  margin-left: auto;
  text-align: right;
}

.chat-message.ai {
  background: white;
  border: 1px solid #ddd;
  margin-right: auto;
}

.chat-message-label {
  font-size: 0.75rem;
  font-weight: 600;
  margin-bottom: 4px;
  opacity: 0.8;
}

.chat-input-group {
  position: relative;
}

.chat-btn {
  padding: 10px 16px;
  background: #17a2b8;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.3s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chat-btn:hover {
  background: #138496;
  transform: translateY(-1px);
}

.chat-btn.thinking {
  background: #667eea;
  cursor: wait;
}

.chat-btn-small {
  padding: 6px 10px;
  background: #17a2b8;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.3s;
}

.chat-btn-small:hover {
  background: #138496;
}

.clear-chat-btn,
.clear-chat-btn-small {
  padding: 6px 10px;
  background: #dc3545;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.3s;
}

.clear-chat-btn:hover,
.clear-chat-btn-small:hover {
  background: #c82333;
}

.dropdown-menu {
  position: absolute;
  top: 90px;
  right: 30px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.25);
  overflow: hidden;
  z-index: 1000;
  min-width: 220px;
}

.dropdown-menu button {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 18px 24px;
  border: none;
  background: white;
  color: #333;
  font-size: 1rem;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s;
  border-bottom: 1px solid #f0f0f0;
}

.dropdown-menu button:last-child {
  border-bottom: none;
}

.dropdown-menu button:hover {
  background: #f8f9ff;
  color: #667eea;
}

.dropdown-menu button i {
  font-size: 1.2rem;
  width: 24px;
}

.book-display {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 20px;
  padding: 40px;
}

.ref-info-banner {
  background: transparent;
  color: #2563eb;
  padding: 6px 16px;
  text-align: center;
  margin: 0 0 12px 0;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.ref-info-banner i {
  font-size: 0.85rem;
}

.page-nav {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 24px;
  margin-bottom: 30px;
}

.nav-btn {
  background: #667eea;
  color: white;
  border: none;
  padding: 14px 24px;
  border-radius: 10px;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.3s;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 50px;
}

.nav-btn:hover {
  background: #5568d3;
  transform: scale(1.05);
}

#pageCounter {
  font-weight: 600;
  font-size: 1.1rem;
  min-width: 180px;
  text-align: center;
}

.book-pages {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px;
  max-width: 1400px;
  margin: 0 auto;
}

.page {
  aspect-ratio: 3 / 4;
  background: white;
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  padding: 40px 30px;
  overflow: hidden;
}

.text-page {
  background: #ffffff;
  display: flex;
  flex-direction: column;
}

.text-page h2 {
  font-size: 1.6rem;
  text-align: center;
  margin-bottom: 30px;
  padding-bottom: 20px;
  border-bottom: 3px double #ddd;
  font-family: Georgia, serif;
  color: #2d3436;
  line-height: 1.4;
}

.language-section {
  margin-bottom: 25px;
}

.language-section h3 {
  font-size: 1.2rem;
  font-weight: bold;
  color: #6c5ce7;
  margin-bottom: 10px;
  font-family: Georgia, serif;
}

.language-section p {
  font-size: 1rem;
  line-height: 1.8;
  color: #2d3436;
  text-align: justify;
}

.image-page {
  display: flex;
  align-items: center;
  justify-content: center;
  background: white;
  padding: 20px;
  position: relative;
}

.image-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-page img {
  max-width: 100%;
  max-height: 100%;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.add-to-ref-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  background: #667eea;
  color: white;
  border: none;
  border-radius: 50%;
  width: 42px;
  height: 42px;
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  transition: all 0.3s;
  z-index: 10;
  display: none;
  align-items: center;
  justify-content: center;
}

.add-to-ref-btn:hover {
  background: #5447c7;
  transform: scale(1.1);
  box-shadow: 0 6px 16px rgba(0,0,0,0.3);
}

.add-to-ref-btn:active {
  transform: scale(0.95);
}

.add-to-ref-btn.added {
  background: #28a745;
}

.add-to-ref-btn.added i {
  content: '\f02e';
}

.add-to-ref-btn.added::after {
  content: '✓';
  position: absolute;
  font-size: 14px;
  font-weight: bold;
}

#imageLoading {
  text-align: center;
  color: #667eea;
}

#imageLoading p {
  margin: 10px 0;
}

.attempts {
  font-size: 0.9rem;
  color: #999;
}

.loader {
  width: 60px;
  height: 60px;
  border: 6px solid #f3f3f3;
  border-top: 6px solid #667eea;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 20px;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  overflow-y: auto;
}

.modal-content {
  background: white;
  margin: 5% auto;
  border-radius: 20px;
  width: 90%;
  max-width: 600px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 25px 30px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-radius: 20px 20px 0 0;
}

.modal-header h2 {
  font-size: 1.5rem;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.close {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  font-size: 2rem;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  line-height: 1;
  transition: all 0.3s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.close:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: rotate(90deg);
}

.modal-body {
  padding: 30px;
}

.form-group {
  margin-bottom: 24px;
}

.form-group label:not(.dropzone):not(.toggle-container):not(.toggle-label) {
  display: block;
  font-weight: 600;
  margin-bottom: 12px;
  font-size: 1rem;
  color: #333;
}

.toggle-container {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  user-select: none;
  padding: 16px 20px;
  background: linear-gradient(135deg, #f8f9ff 0%, #fff 100%);
  border-radius: 12px;
  border: 2px solid #e0e0e0;
  transition: all 0.3s;
}

.toggle-container:hover {
  border-color: #667eea;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.1);
}

.toggle-container input[type="checkbox"] {
  width: 50px;
  height: 28px;
  appearance: none;
  background: #ccc;
  border-radius: 28px;
  position: relative;
  cursor: pointer;
  transition: all 0.3s;
  min-height: auto;
  padding: 0;
}

.toggle-container input[type="checkbox"]:checked {
  background: #667eea;
}

.toggle-container input[type="checkbox"]::before {
  content: '';
  position: absolute;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: white;
  top: 3px;
  left: 3px;
  transition: all 0.3s;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.toggle-container input[type="checkbox"]:checked::before {
  left: 25px;
}

.toggle-label {
  font-weight: 600;
  font-size: 1rem;
  color: #333;
  display: flex;
  align-items: center;
  gap: 8px;
}

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px 20px;
  border: 3px dashed #667eea;
  border-radius: 12px;
  background: linear-gradient(135deg, #f8f9ff 0%, #fff 100%);
  cursor: pointer;
  transition: all 0.3s;
  text-align: center;
  min-height: 140px;
  margin-bottom: 16px;
}

.dropzone:hover {
  border-color: #5568d3;
  background: linear-gradient(135deg, #eef0ff 0%, #f8f9ff 100%);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.15);
}

.dropzone i {
  font-size: 3rem;
  color: #667eea;
}

.dropzone span {
  font-size: 1rem;
  color: #555;
  font-weight: 500;
}

input, textarea, select {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid #e0e0e0;
  border-radius: 10px;
  font-size: 1rem;
  font-family: inherit;
  transition: all 0.3s;
  min-height: 50px;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
}

textarea {
  resize: vertical;
  min-height: 80px;
}

.ref-thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  min-height: 70px;
  max-height: 200px;
  overflow-y: auto;
  background: #111;
  padding: 8px;
  border-radius: 8px;
  justify-content: center;
}

.ref-thumbs:empty::after {
  content: 'Hochgeladene Bilder erscheinen hier';
  color: #888;
  font-size: 0.85rem;
  align-self: center;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.ref-thumb {
  position: relative;
  display: inline-block;
  margin: 4px;
}

.ref-thumb img {
  height: 60px;
  width: auto;
  object-fit: contain;
  border: 2px solid #555;
  border-radius: 6px;
}

.remove-thumb {
  position: absolute;
  top: -8px;
  right: -8px;
  background: #ff4444;
  color: white;
  border: 2px solid white;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: all 0.2s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.remove-thumb:hover {
  background: #cc0000;
  transform: scale(1.15);
}

.optimize-btn {
  width: auto;
  padding: 12px 20px;
  background: linear-gradient(135deg, #ffd700 0%, #ffb300 100%);
  color: #333;
  border: none;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
  margin-top: 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  position: relative;
  overflow: hidden;
}

.optimize-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(255, 193, 7, 0.4);
  background: linear-gradient(135deg, #ffdf00 0%, #ffc107 100%);
}

.optimize-btn.thinking {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  cursor: wait;
  animation: aiThinking 1.5s ease-in-out infinite;
}

.optimize-btn.thinking::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
  animation: shimmer 1.5s infinite;
}

@keyframes aiThinking {
  0%, 100% {
    box-shadow: 0 0 10px rgba(102, 126, 234, 0.5);
  }
  50% {
    box-shadow: 0 0 25px rgba(102, 126, 234, 0.8), 0 0 50px rgba(102, 126, 234, 0.4);
  }
}

@keyframes shimmer {
  0% {
    left: -100%;
  }
  100% {
    left: 100%;
  }
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.02);
  }
}

.generate-btn {
  width: 100%;
  padding: 18px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.generate-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 25px rgba(102, 126, 234, 0.3);
}

.generate-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

@media (max-width: 768px) {
  .book-pages {
    grid-template-columns: 1fr;
  }
  .header-buttons {
    gap: 12px;
  }
  header h1 {
    font-size: 1.5rem;
  }
  header {
    padding: 16px 20px;
  }
  .icon-btn {
    min-width: 40px;
    min-height: 40px;
    padding: 8px 10px;
    font-size: 0.9rem;
  }
}

@media print {
  * {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  
  body {
    background: white;
    margin: 0;
    padding: 0;
  }
  
  header, .page-nav, .modal, #generateMenu {
    display: none !important;
  }
  
  .container {
    max-width: 100%;
    padding: 0;
    background: white;
  }
  
  .book-display {
    box-shadow: none;
    padding: 0;
    background: white;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
  }
  
  .book-pages {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    page-break-inside: avoid;
  }
  
  .page {
    border: 1px solid #ddd;
    border-radius: 0;
    box-shadow: none;
    aspect-ratio: 3/4;
    page-break-inside: avoid;
  }
  
  .text-page {
    background: #ffffff;
  }
  
  .image-page {
    background: white;
  }
  
  #imageLoading {
    display: none !important;
  }
  
  #coloringImage {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
  }
  
  .image-container {
    width: 100%;
    height: 100%;
    aspect-ratio: 3/4 !important;
  }
  
  .add-to-ref-btn, .ref-info-banner {
    display: none !important;
  }

  @page {
    size: A4 landscape;
    margin: 0.5cm;
  }
}

.confirm-btn {
  background: #28a745;
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1em;
  font-weight: 600;
  transition: all 0.3s;
  box-shadow: 0 2px 8px rgba(40, 167, 69, 0.3);
}

.confirm-btn:hover {
  background: #218838;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(40, 167, 69, 0.4);
}

.confirm-btn-small {
  background: #28a745;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9em;
  transition: all 0.3s;
}

.confirm-btn-small:hover {
  background: #218838;
}

.image-selector-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 180px));
  gap: 12px;
  margin-top: 12px;
  justify-content: center;
  max-width: 600px;
  margin-left: auto;
  margin-right: auto;
}

.image-selector-item {
  position: relative;
  aspect-ratio: 3/4;
  border: 3px solid transparent;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.3s;
  background: white;
}

.image-selector-item:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.image-selector-item.selected {
  border-color: #28a745;
  box-shadow: 0 0 0 2px #28a745;
}

.image-selector-item img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.image-selector-item .check-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: #28a745;
  color: white;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.image-selector-item.selected .check-badge {
  display: flex;
}

.image-selector-section {
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid #ddd;
}

.confirm-selection-btn {
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, #48bb78, #38a169);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 16px;
  transition: all 0.3s;
}

.confirm-selection-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(72, 187, 120, 0.4);
}

.image-selector-section:last-child {
  border-bottom: none;
}


.bottom-nav {
  position: fixed;
  bottom: 40px;
  left: 0;
  width: 100%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 10px;
  overflow-x: auto;
  white-space: nowrap;
  border-top: 1px solid rgba(186, 77, 245, 0.1);
  z-index: 999;
  color: #fff;
}

.bottom-nav::-webkit-scrollbar {
  height: 3px;
}

.bottom-nav::-webkit-scrollbar-thumb {
  background: #ba4df5;
  border-radius: 10px;
}

.bottom-nav-links {
  display: flex;
  gap: 15px;
  padding: 0;
  justify-content: flex-start;
  min-width: max-content;
}

.bottom-nav-link {
  color: #fff;
  text-decoration: none;
  padding: 8px 15px;
  border-radius: 6px;
  white-space: nowrap;
  transition: all 0.3s ease;
}

.bottom-nav-link:hover {
  background: rgba(186, 77, 245, 0.1);
  color: #560075;
  box-shadow: 0 4px 12px rgb(248, 247, 248, 0.7);
}

.bottom-nav-link.active {
  background: rgba(186, 77, 245, 0.15);
  color: #fff;
  box-shadow: 0 4px 12px rgb(249, 1, 249, 0.7);
}

footer {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  width: 100%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 5px 0;
  z-index: 1000;
}

footer p {
  font-size: 14px;
  color: white;
  margin: 5px 0;
}