/* ============================================================================
   PapaTales - Full-Featured Picture Book Creator
   ============================================================================ */

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

:root {
  --primary: #667eea;
  --primary-dark: #5a67d8;
  --secondary: #764ba2;
  --accent: #f093fb;
  --success: #48bb78;
  --warning: #ed8936;
  --danger: #f56565;
  --dark: #2d3748;
  --gray: #718096;
  --light: #edf2f7;
  --white: #ffffff;
  --gradient: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.15);
  --radius: 12px;
  --radius-sm: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans TC', sans-serif;
  background: var(--light);
  min-height: 100vh;
  color: var(--dark);
}

.app-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ============================================================================
   Header
   ============================================================================ */

.app-header {
  background: var(--white);
  padding: 12px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.logo-icon {
  font-size: 28px;
}

.logo-text {
  font-size: 24px;
  font-weight: 700;
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.nav-links {
  display: flex;
  gap: 8px;
}

.nav-btn {
  padding: 8px 16px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--gray);
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
}

.nav-btn:hover {
  background: var(--light);
  color: var(--primary);
}

/* ============================================================================
   Screens
   ============================================================================ */

.screen {
  display: none;
  flex: 1;
  padding: 24px;
}

.screen.active {
  display: block;
}

/* Library screen needs full width for coverflow */
#screen-library {
  padding: 0;
  overflow: hidden;
}

/* Smooth fade on coverflow edges using CSS mask */
.swiper-coverflow-wrapper {
  position: relative;
  -webkit-mask-image: linear-gradient(to right, 
    transparent 0%, 
    black 8%, 
    black 92%, 
    transparent 100%);
  mask-image: linear-gradient(to right, 
    transparent 0%, 
    black 8%, 
    black 92%, 
    transparent 100%);
}

/* ============================================================================
   Home Screen
   ============================================================================ */

.hero {
  text-align: center;
  padding: 60px 20px 40px;
  background: var(--gradient);
  border-radius: var(--radius);
  color: var(--white);
  margin-bottom: 40px;
}

.hero h1 {
  font-size: 2.5rem;
  margin-bottom: 12px;
}

.hero .subtitle {
  font-size: 1.2rem;
  opacity: 0.9;
}

.create-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 24px;
  max-width: 800px;
  margin: 0 auto;
}

.option-card {
  background: var(--white);
  padding: 32px;
  border-radius: var(--radius);
  text-align: center;
  cursor: pointer;
  transition: all 0.3s;
  box-shadow: var(--shadow);
  border: 2px solid transparent;
}

.option-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--primary);
}

.option-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.option-card h3 {
  font-size: 1.5rem;
  margin-bottom: 8px;
  color: var(--dark);
}

.option-card p {
  color: var(--gray);
  margin-bottom: 12px;
}

.badge {
  display: inline-block;
  padding: 4px 12px;
  background: var(--light);
  border-radius: 20px;
  font-size: 12px;
  color: var(--primary);
}

/* ============================================================================
   Form Screen
   ============================================================================ */

.form-container {
  max-width: 600px;
  margin: 0 auto;
  background: var(--white);
  padding: 40px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.form-container h2 {
  text-align: center;
  margin-bottom: 32px;
  color: var(--dark);
}

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

.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--dark);
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid var(--light);
  border-radius: var(--radius-sm);
  font-size: 16px;
  transition: border-color 0.3s;
  font-family: inherit;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
}

.form-hint {
  font-size: 13px;
  color: var(--gray);
  margin-top: 6px;
}

.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 32px;
}

/* ============================================================================
   Buttons
   ============================================================================ */

.btn-primary {
  flex: 1;
  padding: 14px 24px;
  background: var(--gradient);
  color: var(--white);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4);
}

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

.btn-secondary {
  padding: 12px 20px;
  background: var(--light);
  color: var(--dark);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-secondary:hover {
  background: #e2e8f0;
}

.btn-danger {
  background: var(--danger);
  color: var(--white);
}

.btn-danger:hover {
  background: #e53e3e;
}

.btn-small {
  padding: 8px 12px;
  font-size: 13px;
}

.btn-icon {
  padding: 8px;
  background: transparent;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  color: var(--gray);
  transition: all 0.2s;
}

.btn-icon:hover {
  background: var(--light);
  color: var(--primary);
}

/* ============================================================================
   Loading Screen
   ============================================================================ */

.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  text-align: center;
}

.loading-animation {
  margin-bottom: 32px;
}

.book-animation {
  position: relative;
  width: 80px;
  height: 100px;
}

.book-animation .book-page {
  position: absolute;
  width: 100%;
  height: 100%;
  background: var(--white);
  border-radius: 4px 12px 12px 4px;
  box-shadow: var(--shadow);
  animation: flip 1.5s ease-in-out infinite;
}

.book-animation .book-page:nth-child(1) { animation-delay: 0s; }
.book-animation .book-page:nth-child(2) { animation-delay: 0.15s; }
.book-animation .book-page:nth-child(3) { animation-delay: 0.3s; }

@keyframes flip {
  0%, 100% { transform: rotateY(0deg); }
  50% { transform: rotateY(-30deg); }
}

.loading-container h2 {
  margin-bottom: 8px;
  color: var(--dark);
}

.loading-container p {
  color: var(--gray);
  margin-bottom: 24px;
}

.progress-bar {
  width: 300px;
  height: 8px;
  background: var(--light);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 16px;
}

.progress-fill {
  height: 100%;
  background: var(--gradient);
  border-radius: 4px;
  width: 0%;
  transition: width 0.5s ease;
}

.loading-status {
  font-size: 14px;
  color: var(--primary);
}

/* ============================================================================
   Editor Screen
   ============================================================================ */

#screen-editor {
  padding: 0;
}

.editor-container {
  display: flex;
  height: calc(100vh - 60px);
}

.editor-sidebar {
  width: 280px;
  background: var(--white);
  border-right: 1px solid var(--light);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--light);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sidebar-header h3 {
  font-size: 16px;
  color: var(--dark);
}

.sidebar-author {
  padding: 8px 16px;
  border-bottom: 1px solid var(--light);
  display: flex;
  align-items: center;
  gap: 8px;
}
.sidebar-author label {
  font-size: 13px;
  white-space: nowrap;
}
.sidebar-author input {
  flex: 1;
  border: 1px solid var(--light);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 13px;
  min-width: 0;
}

.sidebar-section {
  padding: 16px;
  border-bottom: 1px solid var(--light);
  flex-shrink: 0;
}

.sidebar-section h4 {
  font-size: 13px;
  color: var(--gray);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.page-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 200px;
  overflow-y: auto;
}

.page-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--light);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
  border: 2px solid transparent;
}

.page-item:hover {
  background: #e2e8f0;
}

.page-item.active {
  border-color: var(--primary);
  background: rgba(102, 126, 234, 0.1);
}

.page-item .page-thumb {
  width: 36px;
  height: 36px;
  background: var(--gray);
  border-radius: 4px;
  object-fit: cover;
}

.page-item .page-info {
  flex: 1;
  min-width: 0;
}

.page-item .page-num {
  font-weight: 600;
  font-size: 13px;
}

.page-item .page-preview-text {
  font-size: 11px;
  color: var(--gray);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.page-item .drag-handle {
  color: var(--gray);
  cursor: grab;
}

.btn-add-page {
  width: 100%;
  margin-top: 12px;
  justify-content: center;
  background: transparent;
  border: 2px dashed var(--gray);
  color: var(--gray);
}

.btn-add-page:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: rgba(102, 126, 234, 0.05);
}

.character-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.character-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: var(--light);
  border-radius: var(--radius-sm);
}

.character-avatar {
  width: 32px;
  height: 32px;
  background: var(--gradient);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--white);
  font-size: 14px;
}

.character-info {
  flex: 1;
  min-width: 0;
}

.character-name {
  font-weight: 600;
  font-size: 13px;
}

.character-desc {
  font-size: 11px;
  color: var(--gray);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-actions {
  padding: 16px;
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 1px solid var(--light);
}

.sidebar-actions .btn-secondary,
.sidebar-actions .btn-primary {
  width: 100%;
}

/* Editor Main */
.editor-main {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  background: var(--light);
}

.page-editor {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  max-width: 1200px;
  margin: 0 auto;
}

.page-preview {
  background: var(--white);
  padding: 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.page-image-container {
  width: 100%;
  aspect-ratio: 4/3;
  background: #f0f0f0;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  margin-bottom: 16px;
}

.page-image-container img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.placeholder-text {
  color: var(--gray);
  font-size: 14px;
}

.btn-gen-image {
  width: 100%;
  padding: 12px;
  background: var(--primary);
  color: var(--white);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s;
}

.btn-gen-image:hover {
  background: var(--primary-dark);
}

.btn-gen-image:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.page-content-editor {
  background: var(--white);
  padding: 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.page-editor-actions {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
}

/* Mini Preview in Editor */
.mini-preview {
  margin-top: 24px;
  padding: 16px;
  background: var(--light);
  border-radius: var(--radius);
}

.mini-preview h4 {
  font-size: 14px;
  color: var(--gray);
  margin-bottom: 12px;
  text-align: center;
}

.mini-preview-spread {
  display: flex;
  gap: 4px;
  justify-content: center;
  margin-bottom: 12px;
}

.mini-page {
  width: 120px;
  height: 90px;
  background: var(--white);
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.mini-page img {
  width: 100%;
  height: 60px;
  object-fit: cover;
}

.mini-page .mini-text {
  padding: 4px 6px;
  font-size: 8px;
  line-height: 1.3;
  color: var(--dark);
  overflow: hidden;
  flex: 1;
}

.mini-page .mini-placeholder {
  width: 100%;
  height: 60px;
  background: #f0f0f0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray);
  font-size: 20px;
}

.mini-preview-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.mini-preview-nav span {
  font-size: 12px;
  color: var(--gray);
}

/* ============================================================================
   Preview Screen (Dummy Book) - 3D Flip Animation
   ============================================================================ */

#screen-preview {
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  perspective: 2000px;
}

#screen-preview.active {
  display: flex !important;
}

.preview-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
}

.book-viewer {
  display: flex;
  align-items: center;
  gap: 40px;
}

.nav-arrow {
  width: 56px;
  height: 56px;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  color: var(--white);
  font-size: 22px;
  cursor: pointer;
  transition: all 0.3s;
}

.nav-arrow:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(1.1);
}

.nav-arrow:active {
  transform: scale(0.95);
}

.book-spread {
  display: flex;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.6s ease;
}

.book-spread.flip-left {
  animation: flipToLeft 0.6s ease;
}

.book-spread.flip-right {
  animation: flipToRight 0.6s ease;
}

@keyframes flipToLeft {
  0% { transform: rotateY(0deg); }
  50% { transform: rotateY(-15deg); }
  100% { transform: rotateY(0deg); }
}

@keyframes flipToRight {
  0% { transform: rotateY(0deg); }
  50% { transform: rotateY(15deg); }
  100% { transform: rotateY(0deg); }
}

.book-page-left,
.book-page-right {
  width: 420px;
  height: 320px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  box-shadow: 
    0 0 30px rgba(0, 0, 0, 0.3),
    inset 0 0 80px rgba(0, 0, 0, 0.05);
  position: relative;
}

.book-page-left {
  background: linear-gradient(to right, #f8f5f0 0%, #fdfcfa 100%);
  border-radius: 4px 0 0 4px;
  transform-origin: right center;
}

.book-page-left::after {
  content: '';
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 30px;
  background: linear-gradient(to right, transparent, rgba(0,0,0,0.05));
}

.book-page-right {
  background: linear-gradient(to left, #f8f5f0 0%, #fdfcfa 100%);
  border-radius: 0 4px 4px 0;
  transform-origin: left center;
}

.book-page-right::after {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 30px;
  background: linear-gradient(to left, transparent, rgba(0,0,0,0.05));
}

.book-spine {
  width: 24px;
  background: linear-gradient(to right, 
    #d4c4a8 0%, 
    #e8dcc8 20%, 
    #f0e6d8 50%,
    #e8dcc8 80%,
    #d4c4a8 100%
  );
  box-shadow: 
    inset 2px 0 4px rgba(0,0,0,0.1),
    inset -2px 0 4px rgba(0,0,0,0.1);
  position: relative;
}

.book-spine::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 2px;
  height: 100%;
  background: rgba(0,0,0,0.1);
}

.book-page-left .page-image,
.book-page-right .page-image {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f0ebe3;
  border-radius: 8px;
  margin-bottom: 16px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.book-page-left .page-image img,
.book-page-right .page-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.book-page-left .page-text,
.book-page-right .page-text {
  font-size: 15px;
  line-height: 1.7;
  color: #3d3d3d;
  text-align: center;
  font-family: 'Georgia', 'Noto Serif TC', serif;
  min-height: 50px;
}

.book-page-left .page-number,
.book-page-right .page-number {
  text-align: center;
  font-size: 13px;
  color: #999;
  margin-top: 10px;
  font-style: italic;
}

.preview-controls {
  display: flex;
  align-items: center;
  gap: 32px;
}

#preview-page-info {
  color: rgba(255, 255, 255, 0.9);
  font-size: 15px;
  font-weight: 500;
}

/* Cover page special styling */
.book-page-left.cover-page,
.book-page-right.cover-page {
  background: var(--gradient);
  color: white;
}

.book-page-left.cover-page .page-text,
.book-page-right.cover-page .page-text {
  color: white;
  font-size: 24px;
  font-weight: bold;
}

/* ============================================================================
   Bookshelf - Swiper Cover Flow Style
   ============================================================================ */

.bookshelf-container {
  width: 100%;
  margin: 0 auto;
  padding: 40px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: calc(100vh - 80px);
  overflow: visible;
}

.bookshelf-container .library-grid {
  width: 100%;
  align-self: stretch;
}

.bookshelf-container h2 {
  text-align: center;
  margin-bottom: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

/* Swiper Coverflow Wrapper */
.swiper-coverflow-wrapper {
  width: 100%;
  max-width: 100%;
  margin-bottom: 32px;
  padding: 20px 40px;
  height: 720px;
  min-height: 300px;
}

.swiper-coverflow-wrapper .swiper {
  width: 100%;
  height: 100%;
  padding-bottom: 40px;
  overflow: visible !important;
}

/* Let shadows and 3D depth render outside bounds */
.swiper-coverflow-wrapper .swiper-wrapper {
  overflow: visible !important;
}

.swiper-coverflow-wrapper .swiper-slide {
  overflow: visible !important;
}

.swiper-coverflow-wrapper .swiper-slide {
  /* Square hardcover picture book - 640px on desktop */
  width: 640px;
  height: 640px !important;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* iPad (768px - 1024px) */
@media (max-width: 1024px) {
  .swiper-coverflow-wrapper {
    height: 520px;
    min-height: 260px;
  }
  .swiper-coverflow-wrapper .swiper-slide {
    width: 440px;
    height: 440px !important;
  }
}

/* Mobile (< 768px) */
@media (max-width: 768px) {
  .swiper-coverflow-wrapper {
    height: 380px;
    min-height: 220px;
  }
  .swiper-coverflow-wrapper .swiper-slide {
    width: 280px;
    height: 280px !important;
  }
}

/* Small mobile (< 400px) */
@media (max-width: 400px) {
  .swiper-coverflow-wrapper {
    height: 300px;
    min-height: 200px;
  }
  .swiper-coverflow-wrapper .swiper-slide {
    width: 220px;
    height: 220px !important;
  }
}

.swiper-coverflow-wrapper .swiper-slide .book-cover {
  width: 100%;
  height: 100%;
  /* Hardcover book shape */
  border-radius: 4px 8px 8px 4px;
  /* Hardcover book shadow */
  box-shadow: 
    0 10px 30px rgba(0, 0, 0, 0.35),
    0 4px 0 0 rgba(0, 0, 0, 0.15),
    0 0 0 1px rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  transition: box-shadow 0.3s, transform 0.3s;
}

/* Hardcover spine effect on the left edge */
.swiper-coverflow-wrapper .swiper-slide .book-cover::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 12px;
  height: 100%;
  background: linear-gradient(90deg, 
    rgba(0,0,0,0.25) 0%, 
    rgba(0,0,0,0.08) 40%, 
    rgba(255,255,255,0.1) 60%, 
    transparent 100%);
  z-index: 5;
  pointer-events: none;
}

/* Hardcover edge/thickness at bottom */
.swiper-coverflow-wrapper .swiper-slide .book-cover::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 2px;
  right: 2px;
  height: 4px;
  background: linear-gradient(180deg, rgba(0,0,0,0.2), rgba(0,0,0,0.05));
  border-radius: 0 0 6px 6px;
  z-index: -1;
}

.swiper-coverflow-wrapper .swiper-slide .book-cover .book-emoji {
  font-size: 64px;
}

.swiper-coverflow-wrapper .swiper-slide .book-title-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 14px 12px;
  background: linear-gradient(transparent, rgba(0,0,0,0.85));
  color: white;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.swiper-coverflow-wrapper .swiper-slide-active .book-cover {
  box-shadow: 
    0 25px 60px rgba(0, 0, 0, 0.4),
    0 5px 0 0 rgba(0, 0, 0, 0.15),
    0 0 0 3px var(--primary),
    0 0 30px rgba(102, 126, 234, 0.3);
  transform: translateY(-5px);
}

.swiper-coverflow-wrapper .swiper-pagination-bullet {
  background: var(--primary);
}

.swiper-coverflow-wrapper .swiper-pagination-bullet-active {
  background: var(--primary);
}

/* Book Info */
.book-info {
  text-align: center;
  margin-bottom: 32px;
  min-height: 80px;
}

.book-info h3 {
  font-size: 1.5rem;
  margin-bottom: 8px;
  color: var(--dark);
}

.book-info p {
  color: var(--gray);
  font-size: 14px;
  margin: 4px 0;
}

/* Book Action Buttons */
.book-info-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 20px;
  flex-wrap: wrap;
  position: relative;
  z-index: 10;
}

.book-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: 12px;
  border: none;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  /* Touch support for iPad/mobile */
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(0,0,0,0.1);
  -webkit-user-select: none;
  user-select: none;
}

.book-action-btn i {
  font-size: 16px;
}

.book-action-btn.btn-read {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.book-action-btn.btn-read:hover,
.book-action-btn.btn-read:active {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.5);
}

.book-action-btn.btn-edit {
  background: #f8f9fa;
  color: #495057;
  border: 1px solid #dee2e6;
}

.book-action-btn.btn-edit:hover {
  background: #e9ecef;
  transform: translateY(-2px);
}

.book-action-btn.btn-delete {
  background: #f8f9fa;
  color: #dc3545;
  border: 1px solid #dee2e6;
}

.book-action-btn.btn-delete:hover {
  background: #dc3545;
  color: white;
  transform: translateY(-2px);
}

/* View Toggle */
.view-toggle {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 24px;
}

.view-toggle button.active {
  background: var(--primary);
  color: var(--white);
}

/* Grid View */
.library-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 24px;
  margin: 0 auto;
  padding: 0 24px;
}

@media (max-width: 1024px) {
  .library-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 768px) {
  .library-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    padding: 0 16px;
  }
}

@media (max-width: 480px) {
  .library-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    padding: 0 12px;
  }
}

.grid-item {
  background: var(--white);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: all 0.3s;
  position: relative;
}

.grid-item:hover {
  transform: translateY(-8px);
  box-shadow: var(--shadow-lg);
}

.grid-item-cover {
  width: 100%;
  height: 360px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
  color: var(--white);
  background-position: center;
}

.grid-item-info {
  padding: 16px;
}

.grid-item-title {
  font-weight: 600;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.grid-item-author {
  font-size: 13px;
  color: var(--primary);
  margin-bottom: 4px;
}

.grid-item-meta {
  font-size: 12px;
  color: var(--gray);
}

.grid-item-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.2s;
}

.grid-item:hover .grid-item-actions {
  opacity: 1;
}

.grid-item-actions button {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.9);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
}

.grid-item-actions button:hover {
  background: var(--primary);
  color: var(--white);
}

.grid-item-actions button.btn-danger:hover {
  background: var(--danger);
}

/* Library Empty */
.library-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 80px 20px;
  background: var(--white);
  border-radius: var(--radius);
  max-width: 500px;
  margin: 40px auto;
}

.library-empty i {
  font-size: 64px;
  color: var(--gray);
  margin-bottom: 24px;
  display: block;
}

.library-empty p {
  color: var(--gray);
  margin-bottom: 24px;
  font-size: 18px;
}

/* ============================================================================
   Fullscreen Reader
   ============================================================================ */

.fullscreen-reader {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #fff;
  z-index: 1000;
  /* iOS Safari safe areas */
  padding-top: env(safe-area-inset-top);
}

.reader-close {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.08);
  border: none;
  color: #333;
  font-size: 20px;
  cursor: pointer;
  transition: all 0.2s;
  z-index: 10;
}

.reader-close:hover {
  background: rgba(0, 0, 0, 0.15);
  transform: scale(1.1);
}

.reader-content {
  width: 100vw;
  height: 100vh;
  height: 100dvh;        /* iOS Safari: exclude toolbar */
  position: relative;
  display: flex;
  flex-direction: column;
}

.reader-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.06);
  border: none;
  color: #555;
  font-size: 20px;
  cursor: pointer;
  transition: all 0.3s;
  z-index: 10;
  opacity: 0.7;
}

.reader-nav:hover {
  background: rgba(0, 0, 0, 0.12);
  opacity: 1;
}

.reader-nav.reader-prev { left: 20px; }
.reader-nav.reader-next { right: 20px; }

/* ── Letterbox layout: image on top, text in white bar below ── */
.reader-page {
  width: 100vw;
  height: 100vh;
  height: 100dvh;        /* iOS Safari: exclude toolbar */
  display: flex;
  flex-direction: column;
  background: #fff;
  position: relative;
}

.reader-image {
  flex: 1 1 auto;
  min-height: 0;        /* allow shrink */
  position: relative;
  overflow: hidden;
}

.reader-image img {
  width: 100%;
  height: 100%;
  object-fit: contain;   /* show full image, no crop */
  object-position: center;
}

.reader-placeholder {
  font-size: 80px;
  opacity: 0.3;
}

.reader-cover-placeholder {
  width: 100%;
  height: 100%;
  background: var(--gradient);
  display: flex;
  align-items: center;
  justify-content: center;
}

.reader-cover-placeholder span {
  font-size: 100px;
}

.reader-cover-placeholder.back {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

/* ── Text bar: fixed at bottom, white background, never overlaps image ── */
.reader-text {
  flex: 0 0 auto;
  width: 100%;
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));  /* respect iOS safe area */
  background: #ffffff;
  text-align: center;
  z-index: 5;
  /* subtle top shadow so it "sits" on the image */
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.08);
  max-height: 35%;       /* prevent text from taking too much space */
  overflow-y: auto;      /* scroll if text is very long */
  -webkit-overflow-scrolling: touch;
}

/* iPad+ */
@media (min-width: 768px) {
  .reader-text {
    padding: 16px 24px;
  }
}

/* Desktop */
@media (min-width: 1024px) {
  .reader-text {
    padding: 20px 40px;
  }
}

.reader-text p {
  font-size: 16px;
  line-height: 1.7;
  color: #2d3748;
  font-family: 'Noto Sans TC', sans-serif;
  margin: 0;
  max-width: 900px;
  margin-left: auto;
  margin-right: auto;
}

/* iPad */
@media (min-width: 768px) {
  .reader-text p {
    font-size: 20px;
  }
}

/* Desktop */
@media (min-width: 1024px) {
  .reader-text p {
    font-size: 28px;
    line-height: 1.8;
  }
}

.reader-title {
  font-size: 2rem;
  color: #2d3748;
  margin-bottom: 8px;
}

.reader-author {
  font-size: 1.2rem;
  color: #718096;
}

.reader-end-text {
  font-style: italic;
  color: #4a5568;
  margin-bottom: 12px;
}

.reader-credits {
  font-size: 0.9rem !important;
  color: #718096 !important;
}

.reader-progress {
  position: absolute;
  top: 16px;
  right: 80px;
  color: #888;
  background: rgba(0, 0, 0, 0.05);
  padding: 4px 12px;
  border-radius: 16px;
  font-size: 13px;
  z-index: 100;
}

/* ============================================================================
   Mobile/Desktop Visibility
   ============================================================================ */

/* Mobile/Desktop visibility */
.mobile-only { display: block; }
.desktop-only { display: none; }

/* Mobile reader: horizontal flex so nav arrows sit on sides */
.reader-content.mobile-only {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  width: 100vw;
  height: 100vh;
}

/* Nav arrows become narrow columns; reader-page fills center */
.reader-content.mobile-only .reader-nav {
  flex: 0 0 auto;
  align-self: center;
}

.reader-content.mobile-only .reader-page {
  flex: 1 1 auto;
}

@media (min-width: 768px) {
  .mobile-only { display: none !important; }
  .desktop-only { display: block !important; }
}

/* ============================================================================
   Flipbook (Desktop/iPad)
   ============================================================================ */

.flipbook-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

#flipbook {
  width: 100%;
  height: 100%;
}

.flipbook-page {
  background: #fff;
}

/* Title page */
.page-title-page {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1a1a2e 0%, #0f0f1a 100%);
  color: #fff;
  text-align: center;
  padding: 40px;
}

.page-title-page h1 {
  font-size: 2.5rem;
  margin-bottom: 20px;
}

.page-title-page .title-divider {
  width: 80px;
  height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
  margin: 0 auto 20px;
}

.page-title-page p {
  font-size: 1.2rem;
  opacity: 0.8;
}

/* Cover page */
.page-cover {
  width: 100%;
  height: 100%;
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  background-color: #fff;
}

/* Content spread pages */
.page-spread {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
  background-color: #fff;
}

/* Blurred background fill — fills any letterbox gaps */
.page-spread .blur-bg {
  position: absolute;
  top: -5%;
  left: -5%;
  width: 110%;
  height: 110%;
  background-size: cover;
  background-position: center;
  filter: blur(40px) brightness(0.35);
  z-index: 1;
}

/* Main image — one image spans two pages (a "spread").
   Use a real <img> with object-fit so the browser always keeps the correct
   aspect ratio, regardless of how StPageFlip sizes the container. */
.page-spread .main-img {
  position: absolute;
  top: 0;
  left: 0;
  width: 200%;            /* span two pages */
  height: 100%;
  z-index: 2;
  overflow: hidden;
}

.page-spread .main-img img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  display: block;
}

.page-spread.left .main-img {
  left: 0;                /* image starts here; right half overflows */
}

.page-spread.right .main-img {
  left: -100%;            /* shift left so right half is visible */
}

/* ── Page-flip library overrides — ZERO gap between pages ── */
.stf__parent,
.stf__wrapper,
.stf__block {
  margin: 0 !important;
  padding: 0 !important;
  gap: 0 !important;
  column-gap: 0 !important;
  position: relative !important;
}

.stf__parent {
  overflow: hidden !important;
}

.stf__wrapper {
  width: 100% !important;
  height: 100% !important;
}

.stf__block {
  width: 100% !important;
  height: 100% !important;
  position: relative !important;
}

/* Pages: no border/shadow/margin */
.stf__item {
  margin: 0 !important;
  border: none !important;
  box-shadow: none !important;
}

/* Container background = white so no dark seam shows */
#flipbook {
  background: #fff !important;
}

/* Kill ALL library-rendered shadows (soft + hard + canvas) */
.stf__outerShadow,
.stf__innerShadow,
.stf__hardShadow,
.stf__hardInnerShadow {
  display: none !important;
}
.stf__parent canvas {
  opacity: 0 !important;
  pointer-events: none !important;
}
.stf__parent .stf__wrapper::after,
.stf__parent .stf__wrapper::before {
  display: none !important;
}

/* Back cover */
.page-back-cover {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  color: #fff;
  text-align: center;
}

.page-back-cover p:first-child {
  font-size: 1.5rem;
  font-style: italic;
  margin-bottom: 20px;
}

/* ── Flipbook text: white bar at bottom of viewport ── */
.flipbook-text {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 16px 40px;
  background: #ffffff;
  text-align: center;
  z-index: 100;
  display: none;
  box-shadow: 0 -2px 16px rgba(0, 0, 0, 0.1);
}

.flipbook-text p {
  font-size: 28px;
  line-height: 1.8;
  color: #2d3748;
  font-family: 'Noto Sans TC', sans-serif;
  margin: 0;
  max-width: 900px;
  margin-left: auto;
  margin-right: auto;
}

/* Navigation buttons */
.flipbook-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.06);
  border: none;
  color: #555;
  font-size: 18px;
  cursor: pointer;
  z-index: 100;
  opacity: 0.7;
  transition: all 0.2s;
}

.flipbook-nav:hover {
  background: rgba(0, 0, 0, 0.12);
  opacity: 1;
}

.flipbook-prev { left: 20px; }
.flipbook-next { right: 20px; }

/* ============================================================================
   Flipbook — Individual Page Layout (image top + text bottom)
   ============================================================================ */

.page-single {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #fff;
  overflow: hidden;
}

.page-single-image {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.page-single-image img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;  /* default — overridden by --left/--right below */
  display: block;
}

/* Push left-page image toward the spine (right edge) */
.stf__item.--left .page-single-image img {
  object-position: right center;
}

/* Push right-page image toward the spine (left edge) */
.stf__item.--right .page-single-image img {
  object-position: left center;
}

.page-single-placeholder {
  font-size: 64px;
  opacity: 0.3;
}

.page-single-text {
  flex: 0 0 120px !important;  /* Fixed height so all pages align */
  height: 120px !important;
  min-height: 120px !important;
  max-height: 120px !important;
  background: #fdfcfa !important;
  padding: 12px 24px !important;
  text-align: center !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  overflow: hidden !important;
  border-top: 2px solid rgba(0,0,0,0.08) !important;
  box-sizing: border-box !important;
}

.page-single-text p {
  font-size: 16px !important;
  line-height: 1.7 !important;
  color: #2d3748 !important;
  font-family: 'Noto Sans TC', sans-serif !important;
  margin: 0 !important;
  display: -webkit-box !important;
  -webkit-line-clamp: 3 !important;
  -webkit-box-orient: vertical !important;
  overflow: hidden !important;
}

.page-single-text .page-book-num {
  display: none !important; /* hide if present */
}

/* Larger text & taller area on bigger screens */
@media (min-width: 1024px) {
  .page-single-text {
    flex: 0 0 140px !important;
    height: 140px !important;
    min-height: 140px !important;
    max-height: 140px !important;
    padding: 16px 32px !important;
  }
  .page-single-text p {
    font-size: 20px !important;
    line-height: 1.8 !important;
  }
}

/* iPad */
@media (min-width: 768px) and (max-width: 1023px) {
  .page-single-text {
    flex: 0 0 110px !important;
    height: 110px !important;
    min-height: 110px !important;
    max-height: 110px !important;
    padding: 12px 20px !important;
  }
  .page-single-text p {
    font-size: 17px !important;
  }
}

/* ============================================================================
   Auth Screens
   ============================================================================ */

.auth-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: calc(100vh - 120px);
}

.auth-card {
  background: var(--white);
  padding: 40px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 400px;
}

.auth-card h2 {
  text-align: center;
  margin-bottom: 32px;
  color: var(--dark);
}

.auth-divider {
  display: flex;
  align-items: center;
  margin: 24px 0;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--light);
}

.auth-divider span {
  padding: 0 16px;
  color: var(--gray);
  font-size: 14px;
}

.btn-google {
  width: 100%;
  padding: 12px 20px;
  background: var(--white);
  border: 2px solid var(--light);
  border-radius: var(--radius-sm);
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  transition: all 0.2s;
}

.btn-google:hover {
  background: var(--light);
  border-color: #ddd;
}

.auth-footer {
  text-align: center;
  margin-top: 24px;
  font-size: 14px;
  color: var(--gray);
}

.auth-footer a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
}

.auth-footer a:hover {
  text-decoration: underline;
}

/* User Menu */
.user-menu {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-menu span {
  font-weight: 500;
  color: var(--dark);
}

#auth-nav {
  display: flex;
  align-items: center;
}

/* ============================================================================
   Utilities
   ============================================================================ */

.hidden {
  display: none !important;
}

/* ============================================================================
   Wizard Progress
   ============================================================================ */

.wizard-container {
  max-width: 700px;
}

.wizard-progress {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-bottom: 32px;
  padding: 0 10px;
}

.wizard-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex: 1;
  position: relative;
}

.wizard-step::after {
  content: '';
  position: absolute;
  top: 16px;
  left: calc(50% + 20px);
  width: calc(100% - 40px);
  height: 2px;
  background: var(--light);
  z-index: 0;
}

.wizard-step:last-child::after {
  display: none;
}

.wizard-step.active::after,
.wizard-step.done::after {
  background: var(--primary);
}

.wizard-step span {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--light);
  color: var(--gray);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  z-index: 1;
  transition: all 0.3s;
}

.wizard-step.active span {
  background: var(--gradient);
  color: var(--white);
  box-shadow: 0 2px 10px rgba(102, 126, 234, 0.4);
}

.wizard-step.done span {
  background: var(--success);
  color: var(--white);
}

.wizard-step label {
  font-size: 11px;
  color: var(--gray);
  white-space: nowrap;
}

.wizard-step.active label {
  color: var(--primary);
  font-weight: 600;
}

.wizard-panel {
  display: none;
}

.wizard-panel.active {
  display: block;
}

/* ============================================================================
   Q&A Chat Interface
   ============================================================================ */

.qa-chat {
  max-height: 400px;
  overflow-y: auto;
  margin-bottom: 16px;
  padding: 16px;
  background: var(--light);
  border-radius: var(--radius);
}

.qa-loading {
  text-align: center;
  padding: 24px;
  color: var(--primary);
  font-size: 15px;
}

.qa-bubble {
  margin-bottom: 16px;
  animation: fadeInUp 0.3s ease;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.qa-bubble.ai {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.qa-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.qa-message {
  background: var(--white);
  padding: 14px 18px;
  border-radius: 4px 16px 16px 16px;
  font-size: 15px;
  line-height: 1.6;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  max-width: 85%;
}

.qa-step-label {
  font-size: 11px;
  color: var(--gray);
  margin-bottom: 4px;
}

.qa-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.qa-chip {
  padding: 8px 16px;
  background: rgba(102, 126, 234, 0.1);
  color: var(--primary-dark);
  border: 1px solid rgba(102, 126, 234, 0.3);
  border-radius: 20px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  line-height: 1.4;
}

.qa-chip:hover {
  background: var(--primary);
  color: var(--white);
  border-color: var(--primary);
}

.qa-bubble.user {
  display: flex;
  justify-content: flex-end;
}

.qa-bubble.user .qa-message {
  background: var(--primary);
  color: var(--white);
  border-radius: 16px 4px 16px 16px;
}

.qa-input-area {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.qa-input-area input {
  flex: 1;
  padding: 12px 16px;
  border: 2px solid var(--light);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: inherit;
  transition: border-color 0.3s;
}

.qa-input-area input:focus {
  outline: none;
  border-color: var(--primary);
}

.qa-input-area .btn-primary {
  flex: none;
  padding: 12px 16px;
}

/* ============================================================================
   Create Mode Choice
   ============================================================================ */

.create-mode-hint {
  text-align: center;
  color: var(--gray);
  font-size: 16px;
  margin-bottom: 24px;
}

.create-mode-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

@media (max-width: 600px) {
  .create-mode-cards {
    grid-template-columns: 1fr;
  }
}

.create-mode-card {
  background: white;
  border: 2px solid var(--light);
  border-radius: var(--radius);
  padding: 32px 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s;
}

.create-mode-card:hover {
  border-color: var(--primary);
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

.create-mode-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.create-mode-card h3 {
  font-size: 1.2rem;
  margin-bottom: 8px;
  color: var(--dark);
}

.create-mode-card p {
  font-size: 14px;
  color: var(--gray);
}

.create-mode-panel {
  animation: fadeInUp 0.3s ease;
}

/* ============================================================================
   AI Full Chat Interface
   ============================================================================ */

.ai-fullchat {
  border: 1px solid rgba(102, 126, 234, 0.15);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fafbfe;
}

.ai-fullchat-messages {
  height: 420px;
  overflow-y: auto;
  padding: 20px;
}

@media (min-height: 900px) {
  .ai-fullchat-messages {
    height: 500px;
  }
}

.ai-chat-bubble {
  margin-bottom: 16px;
  animation: fadeInUp 0.3s ease;
}

.ai-chat-bubble.ai {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.ai-chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.ai-chat-bubble .ai-chat-text {
  background: white;
  padding: 14px 18px;
  border-radius: 4px 16px 16px 16px;
  font-size: 15px;
  line-height: 1.7;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  max-width: 80%;
}

.ai-chat-bubble.user {
  display: flex;
  justify-content: flex-end;
}

.ai-chat-bubble.user .ai-chat-text {
  background: var(--primary);
  color: white;
  border-radius: 16px 4px 16px 16px;
}

.ai-chat-bubble.typing-indicator .ai-chat-text {
  color: var(--gray);
  padding: 14px 24px;
}

.ai-chat-action {
  margin: 16px 0;
}

.ai-story-ready {
  background: linear-gradient(135deg, rgba(72, 187, 120, 0.1), rgba(102, 126, 234, 0.1));
  border: 1px solid rgba(72, 187, 120, 0.3);
  border-radius: var(--radius);
  padding: 16px 20px;
  text-align: center;
}

.ai-story-ready p {
  font-weight: 600;
  color: var(--success);
  margin-bottom: 12px;
  font-size: 15px;
}

.ai-story-ready .btn-primary {
  margin-right: 8px;
}

.ai-fullchat-input {
  display: flex;
  gap: 10px;
  padding: 14px 16px;
  background: white;
  border-top: 1px solid rgba(0,0,0,0.06);
}

.ai-fullchat-input input {
  flex: 1;
  padding: 12px 16px;
  border: 2px solid var(--light);
  border-radius: 24px;
  font-size: 15px;
  font-family: inherit;
  transition: border-color 0.3s;
}

.ai-fullchat-input input:focus {
  outline: none;
  border-color: var(--primary);
}

.ai-fullchat-input .btn-primary {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Story concept textarea */
#story-concept {
  min-height: 180px;
  font-size: 15px;
  line-height: 1.7;
  resize: vertical;
}

/* ============================================================================
   Art Style Picker
   ============================================================================ */

.style-picker-title {
  text-align: center;
  margin-bottom: 24px;
  font-size: 1.3rem;
}

.style-categories {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.style-category h4 {
  font-size: 14px;
  color: var(--gray);
  margin-bottom: 10px;
  padding-left: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.style-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.style-card {
  background: var(--white);
  border: 2px solid var(--light);
  border-radius: var(--radius);
  padding: 16px 12px;
  text-align: center;
  cursor: pointer;
  transition: all 0.25s ease;
  position: relative;
}

.style-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
}

.style-card.selected {
  border-color: var(--primary);
  background: rgba(102, 126, 234, 0.08);
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2), 0 4px 12px rgba(102, 126, 234, 0.15);
}

.style-card.selected::after {
  content: '✓';
  position: absolute;
  top: 6px;
  right: 8px;
  width: 20px;
  height: 20px;
  background: var(--primary);
  color: white;
  border-radius: 50%;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.style-icon {
  font-size: 32px;
  margin-bottom: 8px;
}

.style-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--dark);
  margin-bottom: 4px;
}

.style-desc {
  font-size: 11px;
  color: var(--gray);
  line-height: 1.3;
}

/* ============================================================================
   Confirm Summary
   ============================================================================ */

.confirm-summary {
  padding: 24px;
  background: var(--light);
  border-radius: var(--radius);
  margin-bottom: 24px;
}

.confirm-section {
  margin-bottom: 20px;
}

.confirm-section:last-child {
  margin-bottom: 0;
}

.confirm-section h4 {
  font-size: 13px;
  color: var(--gray);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.confirm-section p {
  font-size: 15px;
  line-height: 1.6;
  color: var(--dark);
}

.confirm-section .confirm-style-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--white);
  border-radius: 20px;
  font-size: 14px;
  border: 1px solid var(--light);
}

.confirm-qa-list {
  list-style: none;
  padding: 0;
}

.confirm-qa-list li {
  padding: 8px 0;
  border-bottom: 1px solid rgba(0,0,0,0.05);
  font-size: 14px;
  line-height: 1.5;
}

.confirm-qa-list li:last-child {
  border-bottom: none;
}

.confirm-qa-list li strong {
  color: var(--primary);
}

/* Responsive */
@media (max-width: 768px) {
  .hero h1 {
    font-size: 1.8rem;
  }
  
  .editor-container {
    flex-direction: column;
  }
  
  .editor-sidebar {
    width: 100%;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--light);
  }
  
  .page-editor {
    grid-template-columns: 1fr;
  }
  
  .book-spread {
    flex-direction: column;
  }
  
  .book-page-left,
  .book-page-right {
    width: 320px;
  }
  
  .book-spine {
    width: 100%;
    height: 10px;
  }
  
  /* Style picker responsive */
  .style-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .style-card {
    padding: 12px 8px;
  }
  
  .style-icon {
    font-size: 26px;
  }
  
  .style-name {
    font-size: 13px;
  }
  
  /* Wizard responsive */
  .wizard-container {
    padding: 20px;
  }
  
  .wizard-progress {
    gap: 4px;
  }
  
  .wizard-step label {
    font-size: 10px;
  }
  
  .qa-chat {
    max-height: 300px;
  }
}

/* ============================================================================
   Spread Image Mode - one image spanning both pages
   ============================================================================ */

.spread-image-mode {
  position: relative;
}

.spread-image-mode .book-page-left,
.spread-image-mode .book-page-right {
  overflow: hidden;
}

/* Left page: show left half of the spread image */
.spread-image-mode .book-page-left .spread-left {
  position: absolute;
  top: 0;
  left: 0;
  width: 200%; /* Double width so image spans both pages */
  height: 100%;
  margin: 0;
  border-radius: 0;
  z-index: 0;
}

.spread-image-mode .book-page-left .spread-left img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Right page: show right half of the spread image */
.spread-image-mode .book-page-right .spread-right {
  position: absolute;
  top: 0;
  left: -100%; /* Shift left to show right half */
  width: 200%;
  height: 100%;
  margin: 0;
  border-radius: 0;
  z-index: 0;
}

.spread-image-mode .book-page-right .spread-right img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Text overlay on right page for spread mode */
.spread-image-mode .book-page-right .spread-text {
  position: relative;
  z-index: 1;
  background: rgba(255, 255, 255, 0.85);
  padding: 12px 16px;
  border-radius: 8px;
  margin-top: auto;
  margin-bottom: 24px;
  font-size: 15px;
  line-height: 1.7;
  color: #3d3d3d;
  text-align: center;
  font-family: 'Georgia', 'Noto Serif TC', serif;
  backdrop-filter: blur(4px);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

/* Page numbers in spread mode */
.spread-image-mode .book-page-left .page-number,
.spread-image-mode .book-page-right .page-number {
  position: relative;
  z-index: 1;
  color: rgba(255, 255, 255, 0.8);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

/* ============================================================================
   Pending Approval Screen
   ============================================================================ */

.pending-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 60px);
  padding: 20px;
}

.pending-content {
  text-align: center;
  max-width: 400px;
}

.pending-icon {
  font-size: 64px;
  margin-bottom: 16px;
}

.pending-content h2 {
  font-size: 1.5rem;
  color: #2d3748;
  margin-bottom: 12px;
}

.pending-content p {
  color: #718096;
  line-height: 1.6;
  margin-bottom: 24px;
}

.pending-login-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;
  background: #4285f4;
  color: white;
  border-radius: 8px;
  text-decoration: none;
  font-size: 16px;
  transition: background 0.2s;
}

.pending-login-btn:hover {
  background: #3367d6;
}

.pending-waiting {
  display: none;
  margin-top: 20px;
  padding: 16px;
  background: #fef3cd;
  border-radius: 8px;
  color: #856404;
}

/* ============================================================================
   Admin Panel
   ============================================================================ */

.admin-panel {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.admin-panel.hidden {
  display: none;
}

.admin-panel-inner {
  background: white;
  border-radius: 12px;
  width: 100%;
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
  padding: 24px;
}

.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.admin-header h2 {
  margin: 0;
  font-size: 1.3rem;
}

.btn-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: #718096;
  padding: 4px 8px;
}

.admin-user-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  margin-bottom: 8px;
}

.admin-user-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.admin-user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

.admin-user-name {
  font-weight: 600;
  color: #2d3748;
}

.admin-user-email {
  font-size: 13px;
  color: #718096;
}

.admin-user-date {
  font-size: 12px;
  color: #a0aec0;
}

.admin-user-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.admin-badge {
  font-size: 13px;
  padding: 2px 8px;
  border-radius: 4px;
}

.admin-badge.approved {
  background: #c6f6d5;
  color: #276749;
}

.admin-badge.pending {
  background: #fef3cd;
  color: #856404;
}

.btn-primary {
  background: #4f46e5;
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
}

.btn-danger {
  background: #e53e3e;
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
}
