/* Font Declarations
---------------------------------------- */
@font-face {
  font-family: 'Komika';
  src: url('/fonts/KOMIKASL.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
}

/* Base Styles
---------------------------------------- */
body {
  font-family: 'Komika', sans-serif;
  margin: 0;
  padding: 0;
  background-color: #FFFFFF;
  background-image: url('data:image/svg+xml;utf8,%3Csvg%0A%20%20width%3D%2240%22%0A%20%20height%3D%22300%22%0A%20%20viewBox%3D%220%200%2040%20300%22%0A%20%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%0A%20%20%20%20%3Ccircle%20cx%3D%2210.00%22%20cy%3D%220.00%22%20r%3D%2210.00%22%20fill%3D%22%23E6F3FF%22%20opacity%3D%221%22%2F%3E%0A%20%20%20%20%3Ccircle%20cx%3D%2230.00%22%20cy%3D%2213.64%22%20r%3D%2210.00%22%20fill%3D%22%23E6F3FF%22%20opacity%3D%221%22%2F%3E%0A%20%20%20%20%3Ccircle%20cx%3D%2210.00%22%20cy%3D%2227.27%22%20r%3D%229.09%22%20fill%3D%22%23E6F3FF%22%20opacity%3D%220.9090909090909091%22%2F%3E%0A%20%20%20%20%3Ccircle%20cx%3D%2230.00%22%20cy%3D%2240.91%22%20r%3D%229.09%22%20fill%3D%22%23E6F3FF%22%20opacity%3D%220.9090909090909091%22%2F%3E%0A%20%20%20%20%3Ccircle%20cx%3D%2210.00%22%20cy%3D%2254.55%22%20r%3D%228.18%22%20fill%3D%22%23E6F3FF%22%20opacity%3D%220.8181818181818181%22%2F%3E%0A%20%20%20%20%3Ccircle%20cx%3D%2230.00%22%20cy%3D%2268.18%22%20r%3D%228.18%22%20fill%3D%22%23E6F3FF%22%20opacity%3D%220.8181818181818181%22%2F%3E%0A%20%20%20%20%3Ccircle%20cx%3D%2210.00%22%20cy%3D%2281.82%22%20r%3D%227.27%22%20fill%3D%22%23E6F3FF%22%20opacity%3D%220.7272727272727273%22%2F%3E%0A%20%20%20%20%3Ccircle%20cx%3D%2230.00%22%20cy%3D%2295.45%22%20r%3D%227.27%22%20fill%3D%22%23E6F3FF%22%20opacity%3D%220.7272727272727273%22%2F%3E%0A%20%20%20%20%3Ccircle%20cx%3D%2210.00%22%20cy%3D%22109.09%22%20r%3D%226.36%22%20fill%3D%22%23E6F3FF%22%20opacity%3D%220.6363636363636364%22%2F%3E%0A%20%20%20%20%3Ccircle%20cx%3D%2230.00%22%20cy%3D%22122.73%22%20r%3D%226.36%22%20fill%3D%22%23E6F3FF%22%20opacity%3D%220.6363636363636364%22%2F%3E%0A%20%20%20%20%3Ccircle%20cx%3D%2210.00%22%20cy%3D%22136.36%22%20r%3D%225.45%22%20fill%3D%22%23E6F3FF%22%20opacity%3D%220.5454545454545454%22%2F%3E%0A%20%20%20%20%3Ccircle%20cx%3D%2230.00%22%20cy%3D%22150.00%22%20r%3D%225.45%22%20fill%3D%22%23E6F3FF%22%20opacity%3D%220.5454545454545454%22%2F%3E%0A%20%20%20%20%3Ccircle%20cx%3D%2210.00%22%20cy%3D%22163.64%22%20r%3D%224.55%22%20fill%3D%22%23E6F3FF%22%20opacity%3D%220.4545454545454546%22%2F%3E%0A%20%20%20%20%3Ccircle%20cx%3D%2230.00%22%20cy%3D%22177.27%22%20r%3D%224.55%22%20fill%3D%22%23E6F3FF%22%20opacity%3D%220.4545454545454546%22%2F%3E%0A%20%20%20%20%3Ccircle%20cx%3D%2210.00%22%20cy%3D%22190.91%22%20r%3D%223.64%22%20fill%3D%22%23E6F3FF%22%20opacity%3D%220.36363636363636365%22%2F%3E%0A%20%20%20%20%3Ccircle%20cx%3D%2230.00%22%20cy%3D%22204.55%22%20r%3D%223.64%22%20fill%3D%22%23E6F3FF%22%20opacity%3D%220.36363636363636365%22%2F%3E%0A%20%20%20%20%3Ccircle%20cx%3D%2210.00%22%20cy%3D%22218.18%22%20r%3D%222.73%22%20fill%3D%22%23E6F3FF%22%20opacity%3D%220.2727272727272727%22%2F%3E%0A%20%20%20%20%3Ccircle%20cx%3D%2230.00%22%20cy%3D%22231.82%22%20r%3D%222.73%22%20fill%3D%22%23E6F3FF%22%20opacity%3D%220.2727272727272727%22%2F%3E%0A%20%20%20%20%3Ccircle%20cx%3D%2210.00%22%20cy%3D%22245.45%22%20r%3D%221.82%22%20fill%3D%22%23E6F3FF%22%20opacity%3D%220.18181818181818177%22%2F%3E%0A%20%20%20%20%3Ccircle%20cx%3D%2230.00%22%20cy%3D%22259.09%22%20r%3D%221.82%22%20fill%3D%22%23E6F3FF%22%20opacity%3D%220.18181818181818177%22%2F%3E%0A%20%20%20%20%3Ccircle%20cx%3D%2210.00%22%20cy%3D%22272.73%22%20r%3D%220.91%22%20fill%3D%22%23E6F3FF%22%20opacity%3D%220.09090909090909083%22%2F%3E%0A%20%20%20%20%3Ccircle%20cx%3D%2230.00%22%20cy%3D%22286.36%22%20r%3D%220.91%22%20fill%3D%22%23E6F3FF%22%20opacity%3D%220.09090909090909083%22%2F%3E%0A%3C%2Fsvg%3E');
  background-repeat: repeat-x;
}

h1, h2, h3, h4, h5, h6 {
  font-family: 'Bangers', cursive;
}

/* Title Styles
---------------------------------------- */
.page-title {
  font-family: 'Bangers', cursive;
  font-size: 2.5rem;
  line-height: 1.2;
  text-align: center;
}

.page-title span {
  display: block;
}

.title-gradient {
  background: linear-gradient(45deg, 
    #ff6b6b 0%,
    #4ecdc4 25%,
    #45b7d1 50%,
    #a06cd5 75%,
    #ff6b6b 100%
  );
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: gradient 8s linear infinite;
  background-size: 200% auto;
  font-weight: bold;
}

@keyframes gradient {
  0% { background-position: 0% center; }
  100% { background-position: 200% center; }
}

/* Form Elements
---------------------------------------- */
.story-controls {
  margin-top: 2rem;
}

.story-label {
  display: block;
  text-align: left;
  margin-bottom: 0.5rem;
  color: #6c757d;
  font-size: 0.9rem;
  font-family: 'Komika', sans-serif;
  opacity: 0.8;
  transition: opacity 0.3s ease;
}

.story-controls select:focus + .story-label {
  opacity: 1;
}

.story-controls .form-select-lg {
  margin-bottom: 1.5rem;
}

.inline-select {
  display: inline-block;
  width: auto;
  margin: 0 4px;
}

/* Layout Selection Styles
---------------------------------------- */
.layout-option {
  cursor: pointer;
  border: 2px solid transparent;
  border-radius: 8px;
  transition: all 0.2s ease;
  padding: 8px;
  background: white;
}

.layout-option:hover {
  border-color: #adb5bd;
  transform: translateY(-2px);
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.layout-option.selected {
  border-color: #0d6efd;
  background-color: #f8f9fa;
}

.layout-label {
  text-align: center;
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: #6c757d;
}

.layout-options .row {
  margin: 0 -8px;
  width: 100%;
}

.layout-option-wrapper {
  max-width: 180px;
  padding: 0 8px;
}

/* Comic Layout Styles
---------------------------------------- */
#scenes-content {
  padding: 20px;
  max-width: 1400px;
  margin: 0 auto;
}

/* Comic Display Grid */
#comicDisplay {
  display: flex; /* Allow pages to flow */
  flex-direction: column; /* Stack pages vertically */
  align-items: center; /* Center pages if they don't take full width */
  padding: 1rem; /* Reduced padding, page will have its own */
  margin-bottom: 2rem;
}

.comic-page {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, auto); /* Auto rows to fit content like tall panels */
  gap: 1rem; /* Gap between panels within a page */
  padding: 1rem; /* Padding inside each page */
  background: #f0f0f0; /* Light background for page */
  border: 1px solid #ddd;
  border-radius: 8px;
  margin-bottom: 1.5rem; /* Space between pages */
  width: 100%; /* Pages take full width of comicDisplay */
  max-width: 800px; /* Max width for a comfortable 2x2 view */
  box-sizing: border-box;
}

/* Panel Types */
.comic-panel {
  position: relative;
  width: 100%;
  background: #f8f9fa;
  border: 3px solid #000;
  border-radius: 8px;
  overflow: hidden;
  break-inside: avoid; /* May not be needed with new flex structure */
}

/* Square Panel (1x1) */
.comic-panel.square {
  aspect-ratio: 1/1;
  grid-column: span 1;
  grid-row: span 1;
}

/* Wide Panel (2x1) */
.comic-panel.wide {
  aspect-ratio: 2/1;
  grid-column: span 2;
  grid-row: span 1;
}

/* Tall Panel (1x2) */
.comic-panel.tall {
  aspect-ratio: 1/2;
  grid-column: span 1;
  grid-row: span 2;
}

/* Panel Content */
.comic-panel img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.caption {
  padding: 0.5rem;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  font-size: 0.9rem;
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  margin: 0;
  text-align: center;
}

/* Responsive Adjustments */
@media (max-width: 768px) {
  /* #comicDisplay specific grid changes removed */
  /* You might want to add rules for .comic-page here if needed, */
  /* e.g., making it stack panels in a single column: */
  /* .comic-page { grid-template-columns: 1fr; grid-template-rows: repeat(4, auto); } */
  
  .comic-panel.wide,
  .comic-panel.tall {
    grid-column: span 1;
    grid-row: span 1;
    aspect-ratio: 1/1; /* On small screens, make wide/tall panels behave like square */
  }
}

/* Comic Panel Styles
---------------------------------------- */
.comic-panel {
  position: relative;
  width: 100%;
  margin: 15px 0;
  background: #f8f9fa;
  border: 3px solid #000;
  border-radius: 4px;
  overflow: hidden; /* Ensure image stays within panel bounds */
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.1);
}

.comic-panel img {
  width: 100%;
  height: 100%;
  object-fit: cover; /* Fill the panel, zooming only when necessary */
}

.comic-panel:hover {
  transform: translateY(-2px);
  box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.15);
  transition: all 0.2s ease;
}

.comic-panel:not([class*="aspect-"]) {
  aspect-ratio: 1;
}

.panel-content {
  position: relative;
  width: 100%;
  height: 100%;
}

/* Base panel image container */
.panel-image-container {
  width: 100%;
  height: 0;
  position: relative;
  background-size: contain;  /* Changed from cover to contain */
  background-position: center;
  background-repeat: no-repeat;
  border-radius: 4px;
  overflow: hidden;
  background-color: #f8f9fa;  /* Add a background color to fill empty space */
}

/* Layout-specific styles - maintain your existing padding-top ratios */
.layout1 .comic-panel .panel-image-container {
  padding-top: 100% !important;
}

.layout2 .comic-panel:nth-child(3) .panel-image-container,
.layout3 .comic-panel:first-child .panel-image-container,
.layout4 .comic-panel .panel-image-container {
  padding-top: 50% !important;
}

.layout5 .comic-panel:last-child .panel-image-container,
.layout6 .comic-panel:first-child .panel-image-container,
.layout7 .comic-panel .panel-image-container {
  padding-top: 200% !important;
}

/* Caption Styles
---------------------------------------- */
.caption-wrapper {
  position: absolute;
  bottom: 1rem;
  left: 1rem;
  right: 1rem;
  z-index: 10;
  margin-top: 8px;
}

.caption-box {
  position: relative;
  display: inline-block;
  width: calc(100% - 2rem);
  font-size: 14px;
  line-height: 1.4;
  padding: 8px 12px;
  margin: 1rem;
  border: 2px solid #000;
  box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.2);
  font-family: "Komika", "bradley hand", "Verdana", sans-serif;
  background-color: rgba(255, 255, 255, 0.9);
  border-radius: 4px;
}

.caption-box.gradient-yellow {
  background: linear-gradient(to bottom, #fff5cc 0%, #fff 100%);
}

.caption-box.caption-location {
  font-style: italic;
}

.drop-cap {
  float: left;
  font-size: 3em;
  line-height: 0.8;
  padding-right: 0.3em;
  margin-top: 0.1em;
  font-weight: bold;
  color: #000;
}

/* PDF-specific drop cap adjustments */
.pdf-export .drop-cap {
  font-size: 2.5em;
  line-height: 1;
  margin-top: -0.1em;
  margin-right: 0em;
}

/* Image Container and Overlay
---------------------------------------- */
.image-container { /* This is a general .image-container style. */
  position: relative;
  width: 100%;
  overflow: hidden;
  /* ADDITIONS FOR ASPECT RATIO BY DEFAULT (SQUARE) */
  height: 0;
  padding-bottom: 100%; /* Default to 1:1 aspect ratio (square) */
  background-color: #e9ecef; /* Basic background for empty or loading state */
}

/* General aspect ratio modifiers for any image-container */
.image-container.wide {
    padding-bottom: 50%; /* For 2:1 aspect ratio */
}

.image-container.tall {
    padding-bottom: 200%; /* For 1:2 aspect ratio */
}

/* THE FOLLOWING CONFLICTING STYLES WILL BE COMMENTED OUT */
/*
.image-container.generating::after { 
  content: \'''Generating...\''';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: rgba(0, 0, 0, 0.7);
  color: white;
  font-size: 1.2rem;
  z-index: 2;
}
*/

.image-container .loading-spinner { /* Keep loading spinner, ensure z-index is high */
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 5; /* High z-index */
  display: none;
}

.image-container.generating .loading-spinner {
  display: block;
}

/* Canvas and Mood Overlay for Generating Effect - COMMENTED OUT as ui.js handles this */
/*
.pixel-canvas,
.mood-color-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none; 
  object-fit: cover; 
}

.pixel-canvas {
  z-index: 0; 
}

.mood-color-overlay {
  z-index: 1; 
  pointer-events: none; 
  position: relative; 
  overflow: hidden; 
}
*/
.pixel-canvas,
.mood-color-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none; /* Hidden by default */
  object-fit: cover; /* Ensure canvas and overlay match image sizing */
}

.pixel-canvas {
  z-index: 2; /* Above base image, below mood overlay */
}

.mood-color-overlay {
  z-index: 3; /* Above pixel canvas, below generating text */
  pointer-events: none; /* Allow clicks to pass through if needed */
  position: relative; /* For scanline pseudo-element if used from CSS */
  overflow: hidden; /* Keep scanline within bounds if used from CSS */
}

/* Scanline animation for mood overlay during blur phase - this is a different effect from opacity scan, can be kept if still used elsewhere or desired */
.mood-color-overlay.scanning::after { /* This refers to a scanLINE, ui.js uses opacity scan */
  content: \'''\''';
  position: absolute;
  top: -100%; 
  left: 0;
  width: 100%;
  height: 50px; 
  background: linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0.1) 45%,
    rgba(255, 255, 255, 0.15) 50%,
    rgba(255, 255, 255, 0.1) 55%,
    rgba(255, 255, 255, 0) 100%
  );
  animation: scanline-anim 2s linear infinite;
  opacity: 0.7;
}

@keyframes scanline-anim {
  0% {
    top: -100%;
  }
  100% {
    top: 100%; 
  }
}

/* COMMENTED OUT as ui.js handles this with !important */
/*
.image-container.generating .pixel-canvas,
.image-container.generating .mood-color-overlay {
  display: block; 
}

.image-container.generating .scene-image {
  display: none; 
}
*/
.image-container.generating .pixel-canvas,
.image-container.generating .mood-color-overlay {
  display: block; /* Show pixelation and mood overlay */
}

.image-container.generating .scene-image {
  display: none; /* Hide original image */
}

/* Ensure the dark button overlay is also hidden during generation */
.image-container.generating .image-overlay {
  opacity: 0 !important; /* Override hover effect */
  pointer-events: none; /* Prevent any interaction */
}

.image-container .image-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.image-container:hover .image-overlay {
  opacity: 1;
}

/* Hide generate button while generating */
.image-container.generating .image-overlay .generate-button,
.image-container.generating .image-overlay .history-button {
  display: none;
}

/* History specific styles
---------------------------------------- */
.history-button {
  position: relative;
  z-index: 2;
}

/* Hide history button by default and show on hover */
.history-button {
  opacity: 0.9;
}

/* History modal items */
.history-item {
  position: relative;
  cursor: pointer;
  border: 3px solid transparent;
  border-radius: 8px;
  overflow: hidden;
  transition: all 0.2s ease;
  background-color: #f8f9fa;
}

.history-item:hover {
  transform: translateY(-3px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  border-color: var(--bs-primary);
  z-index: 1;
}

.history-item img {
  width: 100%;
  height: auto;
  max-height: 360px;
  object-fit: contain;
  background-color: #f0f0f0;
}

.history-item .timestamp {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: rgba(0, 0, 0, 0.7);
  color: white;
  font-size: 0.85rem; /* Increase font size for better readability */
  padding: 0.4rem;
  text-align: center;
}

.history-item .current-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  background-color: var(--bs-primary);
  color: white;
  padding: 0.2rem 0.5rem;
  border-radius: 10px;
  font-size: 0.7rem;
}

/* Card Flip Styles
---------------------------------------- */
.card-flip-container {
  perspective: 1000px;
  width: 100%;
  flex-grow: 1;
  min-height: 300px; /* Minimum height to ensure space for content */
  display: flex;
  flex-direction: column;
}

.card-flip {
  position: relative;
  width: 100%;
  flex-grow: 1;
  transition: transform 0.5s;
  transform-style: preserve-3d;
  display: flex;
  flex-direction: column;
  min-height: 300px; /* Ensure minimum height */
}

.card-flip.flipped {
  transform: rotateY(180deg);
}

.card-front, .card-back {
  width: 100%;
  height: auto; /* Allow height to be determined by content */
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 0;
  background-color: #fff;
  display: flex;
  flex-direction: column;
}

.card-front {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

.card-back {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  transform: rotateY(180deg);
  background-color: #f8f9fa;
}

/* Ensure card-body within front/back can expand naturally */
.card-front > .card-body,
.card-back > .card-body {
  flex-grow: 1;
  height: auto;
  min-height: 0;
  padding-bottom: 1rem;
}

.scene-setting-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.scene-setting-textarea {
  flex: 1;
  min-height: 180px;
  resize: vertical;
  margin-bottom: 1rem;
  padding: 0.5rem;
  border: 1px solid #ced4da;
  border-radius: 0.25rem;
}

.flip-button {
  margin-top: auto;
  width: 100%;
}

/* Fix caption spacing */
.caption-container {
  margin-bottom: 0;
}

/* Fix card padding */
.card-body.pt-0 {
  padding-top: 0 !important;
}

/* Modal Styles
---------------------------------------- */
.modal-close {
  position: absolute;
  top: 5px;
  right: 5px;
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: #666;
  padding: 5px 10px;
  border-radius: 50%;
  transition: background-color 0.3s;
  z-index: 2;
}

.modal-panel {
  position: relative;
  width: 100%;
  margin: 0 auto;
}

.modal-panel-image {
  width: 100%;
  height: auto;
  border-radius: 4px;
  display: block;
}

.modal-navigation {
  display: flex;
  gap: 1rem;
  margin-top: 0.75rem;
  width: 100%;
  justify-content: center;
}

.modal-nav-prev,
.modal-nav-next {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 1.5rem;
  padding: 0.5rem 1.5rem;
  line-height: 1;
}

.modal-nav-prev:disabled,
.modal-nav-next:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* PDF Export Styles
---------------------------------------- */
/* 
.pdf-export .panel-image-container {
  padding-top: 100%;
}
*/

.pdf-export .caption-box {
  font-size: 10px;
  line-height: 1.2;
  padding: 6px 8px;
  max-width: 90%;
  margin: 8px auto;
  opacity: 0.9;
}

/* Utility Classes
---------------------------------------- */
.position-fixed {
  z-index: 9999;
}

.tab-pane {
  height: auto;
  max-height: none;
  overflow: visible;
}

#novel-content {
  position: relative;
  overflow: visible;
}

/* Responsive Styles
---------------------------------------- */
@media (max-width: 991.98px) {
  .layout-page {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
  }
  
  .comic-panel {
    width: 100%;
    margin-bottom: 1.5rem;
  }
}

@media (max-width: 768px) {
  .comic-page {
    padding: 1rem;
    gap: 1rem;
  }
  
  .caption-box {
    font-size: 0.8rem;
    padding: 0.75rem;
    margin: 0.5rem;
  }
  
  .modal-content {
    padding: 1rem;
  }
  
  .modal-nav-prev,
  .modal-nav-next {
    padding: 0.25rem 1rem;
    font-size: 1.25rem;
  }
}

@media print {
  .comic-panel {
    page-break-inside: avoid;
  }

  .comic-panel img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
  
  .caption-box {
    font-size: 8pt;
    line-height: 1.2;
    padding: 4pt 6pt;
  }
}

.caption-editor {
  min-height: 60px;
  padding: 0.5rem;
  border: 1px solid #ced4da;
  border-radius: 0.25rem;
  background: #fff;
  margin-bottom: 0.5rem;
}

.caption-editor:focus {
  outline: none;
  border-color: #86b7fe;
  box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

.save-caption-btn {
  display: none;
}

.caption-editor.edited + .save-caption-btn {
  display: inline-block;
}

.caption-edit-input {
    width: 100%;
    min-height: 60px;
    padding: 0.5rem;
    border: 2px solid #000;
    border-radius: 4px;
    font-family: 'Comic Sans MS', cursive, sans-serif;
    background: #fff;
    resize: vertical;
}

.caption-edit-input:focus {
    outline: none;
    border-color: #0d6efd;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

/* Style for edited form elements */
.description-textarea.edited,
.scene-setting-textarea.edited {
    border-color: #0d6efd;
}

/* Comic Style Grid */
.comic-style-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr); /* 5 equal columns */
    gap: 0.5rem; /* Optional gap between buttons */
    width: 100%;
}


.comic-style-grid .comic-style-label {
    display: flex; /* Use flexbox for content alignment within the label */
    flex-direction: column; /* Stack image and text vertically */
    justify-content: center; /* Center content vertically */
    align-items: center; /* Center content horizontally */
    text-align: center;
    padding: 0.5rem; /* Adjust padding as needed */
    height: 100%; /* Make label fill the grid item height */
    border-radius: var(--bs-btn-border-radius); /* Ensure consistent border-radius */
    white-space: normal; /* Allow text wrapping if needed */
}

.comic-style-grid .comic-style-thumb {
    max-width: 100px; /* Ensure thumbnail doesn't exceed width */
    height: auto; /* Maintain aspect ratio */
    margin-bottom: 0.25rem; /* Space below thumbnail */
    border: none; /* Remove default thumbnail border */
    /* Remove d-block, mx-auto, mb-1 if using flexbox alignment */
    /* d-block mx-auto mb-1 */ 
}

/* Ensure checked state is visually clear */
.comic-style-grid .btn-check:checked + .comic-style-label {
    background-color: var(--bs-primary); /* Or your desired active background */
    color: white; /* Or your desired active text color */
}

/* Mood specific styles - ensure radio buttons are hidden */
.mood-radio {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    pointer-events: none; /* Prevent the radio from capturing clicks */
}

/* Style for the mood chooser grid and labels */
.mood-chooser-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(70px, 1fr)); /* Adjust minmax as needed */
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.mood-item {
    /* Styles for the grid item container if needed */
    position: relative; /* Ensure positioning context for absolute positioned radio */
}

.mood-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    text-align: center;
    font-size: 0.8rem;
    height: 70px; /* Fixed height for consistency */
    border: 1px solid #dee2e6; /* Default border */
    border-radius: 0.375rem; /* Bootstrap default */
    position: relative; /* Needed for potential future overlays */
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out, background-color 0.15s ease-in-out, color 0.15s ease-in-out;
}
.mood-label:hover {
    background-color: #f8f9fa; /* Subtle hover */
}

.mood-gradient {
    width: 30px;
    height: 30px;
    border-radius: 50%; /* Make it circular */
    margin-bottom: 0.3rem;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

/* Define gradients for each mood */
.mood-none {
    background: radial-gradient(circle, whitesmoke, lightgray);
}

.mood-happy {
    background: radial-gradient(circle, gold, sandybrown);
}

.mood-sad {
    background: radial-gradient(circle, lightsteelblue, slategray);
}

.mood-tense {
    background: radial-gradient(circle, firebrick, dimgray);
}

.mood-mysterious {
    background: radial-gradient(circle, mediumpurple, darkslateblue);
}

.mood-joyful {
    background: radial-gradient(circle, yellow, orange);
}

.mood-serene {
    background: radial-gradient(circle, lightcyan, powderblue);
}

.mood-dreamy {
    background: radial-gradient(circle, lightblue, plum);
}

/* Style for checked state */
.mood-radio:checked + .mood-label {
    border-color: var(--bs-primary); /* Use Bootstrap primary color for border */
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.25); /* Subtle glow */
    background-color: rgba(13, 110, 253, 0.1); /* Light background tint */
    color: var(--bs-primary); /* Change text color */
}
.mood-radio:focus-visible + .mood-label {
     /* Add focus style for accessibility */
     outline: 2px solid var(--bs-primary);
     outline-offset: 2px;
}

/* Camera angle preview on hover - ensure it's visible and properly styled */
.camera-angle-preview-wrapper {
    position: fixed;
    z-index: 1080; /* Higher than most elements */
    background-color: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 10px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    display: none; /* Initially hidden */
    flex-direction: column; /* Stack image and caption */
    align-items: center;
    text-align: center;
    pointer-events: none; /* Allow clicks to pass through */
    width: 320px; /* Match image width in JS */
    transition: opacity 0.1s ease-out;
}
.camera-angle-preview-wrapper.visible {
    display: flex; /* Use flex when visible */
    opacity: 1;
}
.camera-angle-preview-image {
    max-width: 100%; /* Image takes full width of wrapper */
    height: auto;
    border-radius: 4px;
    margin-bottom: 8px;
}
.camera-angle-preview-caption {
    font-size: 0.9rem;
    line-height: 1.4;
}
.camera-angle-preview-caption strong {
    display: block;
    font-size: 1rem;
    margin-bottom: 4px;
}

/* Make the grid show fewer columns for larger thumbnails */
#historyItemsContainer {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 15px;
}

/* Add extra styling for the Clear All Data button */
#clearAllData {
    margin-right: auto; /* Push the button to the left side */
}

/* Ensure .card itself is a flex column to manage its direct children's heights */
.card {
    display: flex;
    flex-direction: column;
    height: auto !important; /* Ensure card takes its natural height */
    min-height: 700px; /* Ensure minimum height for all cards */
}

/* Ensure fixed-size elements within .card do not shrink */
.card > .image-container,
.card > .card-title,
.card > .caption-container {
    flex-shrink: 0;
}

/* Ensure card-body within front/back can scroll and takes available space */
.card-front > .card-body,
.card-back > .card-body {
    flex-grow: 1; /* Take available vertical space */
    /* overflow-y: auto; */ /* REMOVED to allow content to expand parent height */
    min-height: 0; /* Necessary for flex children to shrink properly if needed */
    padding-bottom: 1rem; /* Add some padding at the bottom of the content body */
}

.card-back {
    transform: rotateY(180deg);
    background-color: #f8f9fa;
}

/* Scene Cards Container */
.scenes-container {
    position: relative;
    width: 100%;
    margin-bottom: 2rem;
    padding: 0;
}

.scenes-scroll-container {
    position: relative;
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
    /* Add padding to create visual space for the first card */
    padding: 1rem 20px; /* 1rem top/bottom, 20px left/right */
}

.scenes-row {
    display: flex;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 1rem;
    /* Remove margin and specific padding, rely on container padding and gap */
    margin-left: 0;
    padding: 0;
    min-height: 600px;
}

.scene-card {
    flex: 0 0 auto;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    /* Remove margins, rely on parent gap */
    margin: 0;
    width: 500px;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    transition: transform 0.2s, box-shadow 0.2s;
}

.scenes-row.single-card {
    justify-content: center;
    /* margin-left is already 0 by default for .scenes-row */
    /* padding: 1rem; /* This padding is for content within the row, which is fine */
    /* If cards have their own padding, this might not be needed or could be set to 0 */
}

/* Scene Card */
.scene-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.scene-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid #eee;
}

.scene-number {
    font-weight: bold;
    font-size: 1.1rem;
}

.scene-actions {
    display: flex;
    gap: 0.5rem;
}

.scene-card-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 1rem;
}

/* Image Container within Scene Cards - THIS IS THE PRIMARY TARGET FOR ASPECT RATIO */
.scene-card-body .image-container {
    margin-bottom: 1rem; /* Retain specific margin for scene cards */
    border-radius: 4px; /* Retain specific border-radius */
    background-color: #f0f0f0; /* Specific background for scene cards, overrides general if needed */
}

/* General styles for children of ANY .image-container that uses this effect system */
.image-container .scene-image,
.image-container .pixel-canvas,
.image-container .mood-color-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%; /* Fill the parent .image-container */
    object-fit: cover;
}

.image-container .scene-image {
    display: block; /* Visible by default */
    z-index: 1;
}

/* Styles for pixelation/mood overlay (previously around line 370 & my last edit) */
.image-container .pixel-canvas {
    display: none; /* Hidden by default */
    z-index: 2; /* Above base image, below mood overlay */
    /* image-smoothing will be handled by JS */
}

.image-container .mood-color-overlay {
    display: none; /* Hidden by default */
    z-index: 3; /* Above pixel canvas, below generating text */
    pointer-events: none;
    position: relative; /* For scanline pseudo-element if used from CSS */
    overflow: hidden; /* Keep scanline within bounds if used from CSS */
}

/* Generating State Styles */
.image-container.generating .scene-image {
    display: none !important; /* Hide original image forcefully */
    visibility: hidden !important; /* Ensure it's completely gone */
    opacity: 0 !important;
}

.image-container.generating .pixel-canvas,
.image-container.generating .mood-color-overlay {
    display: block !important; /* Show pixelation and mood overlay */
    visibility: visible !important;
    opacity: 1 !important;
}

/* "Generating..." text overlay */
.image-container.generating::after {
    content: "Generating...";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: rgba(0, 0, 0, 0.65); /* Slightly darker for better text contrast */
    color: white;
    font-size: 1.2rem;
    font-weight: bold;
    z-index: 4; /* Above mood overlay, below main loading spinner if any */
    text-align: center;
    padding: 10px;
    box-sizing: border-box;
    border-radius: inherit; /* Inherit border-radius from .image-container */
}

/* Ensure the original .image-container (around line 345) doesn't conflict.
   The one in .scene-card-body is more specific.
   If other .image-containers need this, they'll need the height:0/padding-bottom too.
*/

/* Existing .image-container .loading-spinner (around line 360) */
.image-container .loading-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 5; /* Highest, above the "Generating..." text */
  display: none;
}

/* Scanline animation for mood overlay (previously around line 381) */
/* This specific scanline effect might be different from the opacity based one.
   Keeping it in case it's used, ui.js might manage a different .scanning class for opacity.
*/
.mood-color-overlay.scanning::after {
  content: '';
  position: absolute;
  top: -100%;
  left: 0;
  width: 100%;
  height: 50px;
  background: linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0.1) 45%,
    rgba(255, 255, 255, 0.15) 50%,
    rgba(255, 255, 255, 0.1) 55%,
    rgba(255, 255, 255, 0) 100%
  );
  animation: scanline-anim 2s linear infinite;
  opacity: 0.7;
}

@keyframes scanline-anim {
  0% {
    top: -100%;
  }
  100% {
    top: 100%;
  }
}

/* Ensure the dark button overlay is also hidden during generation (around line 414) */
.image-container.generating .image-overlay {
  opacity: 0 !important; /* Override hover effect */
  pointer-events: none; /* Prevent any interaction */
}

/* Drag-and-Drop Thumbnail Styles */
.thumbnail-item.dragging-thumb {
    opacity: 0.6;
    border: 2px dashed #007bff; /* Bootstrap primary blue */
    transform: scale(0.95);
    background-color: #e9ecef; /* Light grey background when dragging */
}

/* Style for the item being hovered over as a potential drop target */
/* This is less critical if using a placeholder, but can be a fallback */
.thumbnail-item.drag-over-thumb {
    outline: 2px solid #0d6efd; 
    background-color: #ddeeff; /* Light blueish background */
}

/* Placeholder style for indicating drop location */
.drop-placeholder-thumb {
    box-sizing: border-box; /* Ensure padding and border are included in width/height */
    width: 68px;  /* Match .thumbnail-item width */
    height: 68px; /* Match .thumbnail-item height */
    background-color: rgba(13, 110, 253, 0.1); /* Light primary blue, semi-transparent */
    border: 2px dashed #0d6efd; /* Dashed primary blue border */
    border-radius: 0.375rem; /* Match .thumbnail-item border-radius */
    margin: 0 0.375rem; /* Approximate gap, adjust if needed to match .thumbnail-nav-scroll gap / 2 */
    flex-shrink: 0; /* Prevent shrinking in flex container */
}

/* Visual indicator for keyboard-focused options in popovers */
.camera-angle-example.keyboard-active,
.aspect-ratio-option.keyboard-active {
    outline: 2px solid #007bff; /* Or your preferred focus color */
    outline-offset: 2px;
    background-color: rgba(0, 123, 255, 0.1); /* Slight background change */
}

/* Thumbnail Navigation Styles */
.thumbnail-nav-container {
    width: 100%;
    overflow: hidden;
    position: relative;
    padding: 0.5rem 0;
    background-color: #f8f9fa; /* Light background for the nav area */
    border-bottom: 1px solid #dee2e6;
}

.thumbnail-nav-scroll {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 0.25rem 0.5rem; /* Padding inside the scroll area */
    gap: 0.75rem; /* Space between thumbnails */
    align-items: center; /* Vertically align items */
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
}

.thumbnail-nav-scroll::-webkit-scrollbar {
    height: 6px;
}

.thumbnail-nav-scroll::-webkit-scrollbar-track {
    background: transparent;
}

.thumbnail-nav-scroll::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.3);
    border-radius: 3px;
}

.thumbnail-item {
    flex: 0 0 auto; /* Prevent shrinking, allow natural width */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 68px; /* Increased width to accommodate border/padding and text */
    height: 68px; /* Increased height */
    border: 2px solid transparent;
    border-radius: 0.375rem; /* Bootstrap default */
    background-color: #fff;
    cursor: pointer;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
    text-align: center;
    overflow: hidden;
    padding: 2px; /* Small padding around image */
}

.thumbnail-item:hover {
    border-color: #adb5bd;
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.25); 
}

.thumbnail-item img {
    width: 48px; /* Maintain image size */
    height: 48px; /* Maintain image size */
    object-fit: cover;
    border-radius: 0.25rem; /* Slightly rounded corners for the image */
}

.thumbnail-item.active-thumbnail {
    border-color: var(--bs-primary);
    box-shadow: 0 0 0 0.2rem rgba(var(--bs-primary-rgb), 0.25);
}

.add-new-scene-thumb {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 68px;
    height: 68px;
    border: 2px dashed #adb5bd;
    border-radius: 0.375rem;
    background-color: #f8f9fa;
    cursor: pointer;
    transition: border-color 0.15s ease-in-out, background-color 0.15s ease-in-out;
}

.add-new-scene-thumb:hover {
    border-color: #007bff;
    background-color: #e9ecef;
}

.add-new-scene-thumb-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #495057;
    font-size: 0.75rem; /* Smaller text */
}

.add-new-scene-thumb-content i {
    font-size: 1.5rem; /* Adjust icon size */
    margin-bottom: 0.25rem;
}

/* Camera Angle Popover */
.camera-angle-popover {
    padding: 1rem;
    min-width: 250px;
    font-family: 'Komika', sans-serif;
}

.camera-angle-examples {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 0.75rem;
}

.camera-angle-example {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
    transition: background-color 0.2s;
    text-align: center;
}

.camera-angle-example:hover {
    background-color: #f8f9fa;
}

.camera-angle-example.active {
    background-color: var(--bs-primary-bg-subtle);
    color: var(--bs-primary);
    font-weight: bold;
    border-color: var(--bs-primary);
}

.camera-angle-example img {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid #ddd;
}

/* Scene Controls */
.scene-controls {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.camera-angle-container,
.mood-container,
.description-container,
.caption-container {
    width: 100%;
}

/* Aspect Ratio Popover */
.aspect-ratio-popover {
    padding: 1rem;
    min-width: 200px;
    font-family: 'Komika', sans-serif;
}

.aspect-ratio-options {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.aspect-ratio-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
    cursor: pointer;
    transition: all 0.2s ease;
}

.aspect-ratio-option:hover {
    background-color: #f8f9fa;
    border-color: #0d6efd;
}

.aspect-ratio-option.active {
    background-color: rgba(13, 110, 253, 0.1);
    border-color: #0d6efd;
    color: #0d6efd;
    font-weight: bold;
}

.ratio-preview {
    width: 40px;
    height: 40px;
    border: 1px solid #ddd;
    border-radius: 2px;
    background-color: #e9ecef;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ratio-preview.square {
    /* Ensure fixed size for square - aspect-ratio handled by parent if needed or direct w/h */
    width: 40px;
    height: 40px;
    /* aspect-ratio: 1/1; */ /* Redundant due to fixed w/h */
}

.ratio-preview.wide {
    /* Make it wider while maintaining similar visual weight or fixed height */
    width: 60px; /* Wider */
    height: 30px; /* Adjust height to maintain a 2:1 visual for the preview box itself */
    /* aspect-ratio: 2/1; */ /* Redundant */
}

.ratio-preview.tall {
    /* Make it taller while maintaining similar visual weight or fixed width */
    width: 30px; /* Narrower */
    height: 60px; /* Adjust height to maintain a 1:2 visual for the preview box itself */
    /* aspect-ratio: 1/2; */ /* Redundant */
}