/* =========================================================
   ComicCreator Modern Dark Theme & Design Tokens
   ========================================================= */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&family=Space+Grotesk:wght@400;600;700&display=swap');

:root {
  --bg-main: #0a0c10;
  --bg-card: rgba(18, 22, 31, 0.85);
  --bg-card-hover: rgba(26, 32, 45, 0.9);
  --bg-input: #121620;
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-glow: rgba(99, 102, 241, 0.15);

  --accent-primary: #6366f1;
  --accent-primary-hover: #4f46e5;
  --accent-secondary: #ec4899;
  --accent-cyan: #06b6d4;
  --accent-emerald: #10b981;
  --accent-warning: #f59e0b;

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --font-main: 'Outfit', sans-serif;
  --font-heading: 'Space Grotesk', sans-serif;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;

  --shadow-main: 0 10px 30px -10px rgba(0, 0, 0, 0.6);
  --shadow-glow: 0 0 25px rgba(99, 102, 241, 0.3);
}

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

body {
  font-family: var(--font-main);
  background-color: var(--bg-main);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  background-image: 
    radial-gradient(circle at 15% 20%, rgba(99, 102, 241, 0.12) 0%, transparent 40%),
    radial-gradient(circle at 85% 80%, rgba(236, 72, 153, 0.1) 0%, transparent 40%);
  background-attachment: fixed;
}

/* App Container Layout */
#app {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 300px;
  background: rgba(12, 15, 23, 0.95);
  backdrop-filter: blur(16px);
  border-right: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
  z-index: 100;
}

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

.logo-brand {
  font-family: var(--font-heading);
  font-size: 1.35rem;
  font-weight: 700;
  background: linear-gradient(135deg, #a5b4fc, var(--accent-secondary));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-new-story {
  width: calc(100% - 2.5rem);
  margin: 1rem 1.25rem;
  padding: 0.75rem 1rem;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  border: none;
  border-radius: var(--radius-md);
  color: white;
  font-weight: 600;
  font-family: var(--font-main);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
  transition: all 0.2s ease;
}

.btn-new-story:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(236, 72, 153, 0.4);
}

.story-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 1rem;
}

.story-item {
  padding: 0.85rem 1rem;
  margin-bottom: 0.5rem;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.story-item:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--glass-border);
}

.story-item.active {
  background: rgba(99, 102, 241, 0.15);
  border-color: var(--accent-primary);
}

.story-item-title {
  font-weight: 500;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.story-item-del {
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.story-item:hover .story-item-del {
  opacity: 1;
}

.story-item-del:hover {
  color: #ef4444;
}

/* User Footer in Sidebar */
.user-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(0, 0, 0, 0.2);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-primary));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
}

/* Main Content Area */
.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: relative;
  overflow: hidden;
}

/* Header Navbar */
.navbar {
  height: 65px;
  border-bottom: 1px solid var(--glass-border);
  background: rgba(10, 12, 16, 0.8);
  backdrop-filter: blur(12px);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 10;
}

.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 1.5rem;
  cursor: pointer;
}

.system-status-pills {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  padding: 0.3rem 0.75rem;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--glass-border);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #64748b;
}

.status-dot.online {
  background: var(--accent-emerald);
  box-shadow: 0 0 8px var(--accent-emerald);
}

.status-dot.offline {
  background: #ef4444;
}

/* Story Feed / Chat Area */
.story-feed {
  flex: 1;
  overflow-y: auto;
  padding: 2rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
  scroll-behavior: smooth;
}

.empty-state {
  text-align: center;
  margin: auto;
  padding: 2rem;
  color: var(--text-secondary);
}

.empty-state h2 {
  font-family: var(--font-heading);
  font-size: 1.8rem;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

/* Scene Card */
.scene-card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-main);
  animation: fadeIn 0.4s ease-out forwards;
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
}

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

.scene-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--glass-border);
  padding-bottom: 0.75rem;
}

.scene-badge {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--accent-cyan);
  font-weight: 700;
}

.scene-user-prompt {
  font-style: italic;
  color: var(--accent-secondary);
  font-weight: 500;
  background: rgba(236, 72, 153, 0.08);
  padding: 0.5rem 1rem;
  border-left: 3px solid var(--accent-secondary);
  border-radius: 4px;
}

.scene-title {
  font-family: var(--font-heading);
  font-size: 1.35rem;
  color: var(--text-primary);
}

.scene-text {
  font-size: 1.05rem;
  color: #e2e8f0;
  line-height: 1.75;
  white-space: pre-wrap;
}

/* Generated Image Wrapper */
.scene-image-container {
  position: relative;
  width: 100%;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #000;
  border: 1px solid var(--glass-border);
  min-height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.scene-image {
  width: 100%;
  height: auto;
  max-height: 600px;
  object-fit: cover;
  display: block;
  cursor: pointer;
  transition: transform 0.3s ease;
}

.scene-image:hover {
  transform: scale(1.015);
}

/* Image Generation Progress Overlay */
.image-gen-overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  text-align: center;
  gap: 1rem;
  width: 100%;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(99, 102, 241, 0.2);
  border-top-color: var(--accent-cyan);
  border-radius: 50%;
  animation: spin 1s infinite linear;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.progress-bar-bg {
  width: 100%;
  max-width: 320px;
  height: 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-cyan), var(--accent-primary));
  transition: width 0.3s ease;
}

.prompt-inspector-btn {
  align-self: flex-start;
  font-size: 0.85rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--glass-border);
  color: var(--text-secondary);
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.2s ease;
}

.prompt-inspector-btn:hover {
  background: rgba(99, 102, 241, 0.2);
  color: var(--text-primary);
  border-color: var(--accent-primary);
}

.btn-delete-scene {
  background: transparent;
  border: none;
  color: #ef4444;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  opacity: 0.7;
}

.btn-delete-scene:hover {
  opacity: 1;
  background: rgba(239, 68, 68, 0.15);
}

/* Suggested Action Chips */
.suggested-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.action-chip {
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid rgba(99, 102, 241, 0.3);
  color: #a5b4fc;
  padding: 0.5rem 1rem;
  border-radius: 20px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.action-chip:hover {
  background: var(--accent-primary);
  color: white;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
  transform: translateY(-1px);
}

/* Bottom Input Controls Bar */
.input-bar {
  padding: 1.25rem 1.5rem;
  background: rgba(10, 12, 16, 0.9);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--glass-border);
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

.input-container {
  display: flex;
  gap: 0.75rem;
  position: relative;
}

.story-input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: 0.85rem 1.25rem;
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 1rem;
  outline: none;
  transition: all 0.2s ease;
}

.story-input:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25);
}

.btn-send {
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  border: none;
  border-radius: var(--radius-md);
  width: 50px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.2rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-send:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 15px rgba(236, 72, 153, 0.4);
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 540px;
  padding: 2rem;
  box-shadow: 0 20px 50px rgba(0,0,0,0.8);
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-title {
  font-family: var(--font-heading);
  font-size: 1.4rem;
  margin-bottom: 0.5rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-group label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.form-control {
  background: var(--bg-input);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 0.95rem;
}

textarea.form-control {
  min-height: 100px;
  resize: vertical;
}

.btn-group {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1rem;
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--glass-border);
  color: var(--text-primary);
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.btn-primary {
  background: var(--accent-primary);
  border: none;
  color: white;
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
}

/* Character Cards & Quick Chips */
.char-card-item {
  background: rgba(18, 22, 31, 0.9);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.char-card-info {
  flex: 1;
}

.char-card-name {
  font-family: var(--font-heading);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--accent-cyan);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.char-card-tags {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
  font-family: monospace;
  background: rgba(0,0,0,0.3);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
}

.char-chip {
  background: rgba(6, 182, 212, 0.15);
  border: 1px solid rgba(6, 182, 212, 0.4);
  color: var(--accent-cyan);
  padding: 0.4rem 0.85rem;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.char-chip:hover {
  background: var(--accent-cyan);
  color: #000;
  box-shadow: 0 4px 12px rgba(6, 182, 212, 0.4);
  transform: translateY(-1px);
}

/* Responsive Media Queries */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    height: 100vh;
    transform: translateX(-100%);
  }

  .sidebar.mobile-open {
    transform: translateX(0);
  }

  .mobile-menu-btn {
    display: block;
  }
}

/* =========================================================
   LM Studio Thinking Card / Hourglass Indicator
   ========================================================= */
.thinking-card {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.15), rgba(6, 182, 212, 0.1));
  border: 1px solid rgba(99, 102, 241, 0.35);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 8px 32px rgba(99, 102, 241, 0.2);
  display: flex;
  align-items: center;
  gap: 1.25rem;
  animation: fadeInThinking 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
  overflow: hidden;
}

.thinking-card::before {
  content: '';
  position: absolute;
  top: 0; left: -100%;
  width: 100%; height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent-cyan), var(--accent-primary), transparent);
  animation: shimmerBorder 2s infinite linear;
}

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

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

.hourglass-icon {
  font-size: 2.4rem;
  display: inline-block;
  animation: flipHourglass 2.2s infinite ease-in-out;
  filter: drop-shadow(0 0 12px rgba(99, 102, 241, 0.7));
}

@keyframes flipHourglass {
  0% { transform: rotate(0deg) scale(1); }
  40% { transform: rotate(180deg) scale(1.15); }
  50% { transform: rotate(180deg) scale(1.15); }
  90% { transform: rotate(360deg) scale(1); }
  100% { transform: rotate(360deg) scale(1); }
}

.thinking-content {
  flex: 1;
}

.thinking-title {
  font-family: var(--font-heading);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent-cyan);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.thinking-user-prompt {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 0.3rem;
  font-style: italic;
}

.thinking-dots {
  display: inline-flex;
  align-items: center;
  margin-left: 4px;
}

.thinking-dots span {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--accent-cyan);
  margin-left: 3px;
  animation: bounceDot 1.4s infinite ease-in-out both;
}

.thinking-dots span:nth-child(1) { animation-delay: -0.32s; }
.thinking-dots span:nth-child(2) { animation-delay: -0.16s; }
.thinking-dots span:nth-child(3) { animation-delay: 0s; }

@keyframes bounceDot {
  0%, 80%, 100% { transform: scale(0); opacity: 0.4; }
  40% { transform: scale(1.2); opacity: 1; background-color: var(--accent-primary); }
}

/* =========================================================
   A4 Comic Book Viewer & PDF Print Engine
   ========================================================= */
.comic-modal-content {
  max-width: 900px !important;
  width: 95vw !important;
  height: 92vh !important;
  padding: 1.5rem !important;
  display: flex !important;
  flex-direction: column !important;
  gap: 1rem !important;
  background: #0f131d !important;
}

.comic-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--glass-border);
}

.comic-pages-viewport {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2.5rem;
  background: rgba(0, 0, 0, 0.4);
  border-radius: var(--radius-md);
}

/* A4 Page Container (Fixed 794px x 1123px = Exact A4 @ 96DPI) */
.a4-comic-page {
  width: 794px;
  height: 1123px;
  min-height: 1123px;
  max-height: 1123px;
  background: #ffffff;
  color: #0f172a;
  border-radius: 4px;
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.7);
  padding: 24px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  page-break-after: always;
  page-break-inside: avoid;
  box-sizing: border-box;
  overflow: hidden;
}

.a4-page-header {
  height: 34px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 3px solid #0f172a;
  padding-bottom: 4px;
  margin-bottom: 12px;
  box-sizing: border-box;
}

.a4-page-title {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #0f172a;
}

.a4-page-number {
  font-weight: 700;
  font-size: 0.85rem;
  color: #64748b;
}

/* Panel Grid Layouts */
.comic-grid {
  height: 1000px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 12px;
  box-sizing: border-box;
}

/* Grid Rows & Aspect Ratio Layout Rules */
.comic-panel-row {
  display: flex;
  gap: 12px;
  width: 100%;
}

/* 1. Single Full Panel */
.grid-1-panel .comic-panel {
  height: 100%;
  width: 100%;
}

/* 2. All-Portrait Pages (Tall Vertical Side-by-Side Columns - ZERO CROPPING!) */
.grid-portrait-cols-2 {
  display: flex;
  flex-direction: row;
  gap: 12px;
  height: 1000px;
  width: 100%;
}
.grid-portrait-cols-2 .comic-panel {
  height: 100%;
  width: calc(50% - 6px);
  flex: 1;
}

.grid-portrait-cols-3 {
  display: flex;
  flex-direction: row;
  gap: 12px;
  height: 1000px;
  width: 100%;
}
.grid-portrait-cols-3 .comic-panel {
  height: 100%;
  width: calc(33.33% - 8px);
  flex: 1;
}

/* 3. All-Landscape Pages (Stacked Wide Rows) */
.grid-landscape-rows-2 {
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 1000px;
  width: 100%;
}
.grid-landscape-rows-2 .comic-panel {
  height: calc(50% - 6px);
  width: 100%;
}

/* 4. Mixed Pages (Top Landscape + Bottom 2 Portraits) */
.grid-mixed-top-landscape {
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 1000px;
  width: 100%;
}

.grid-mixed-top-landscape .comic-panel-row-top {
  height: calc(52% - 6px);
  width: 100%;
}

.grid-mixed-top-landscape .comic-panel-row-top .comic-panel {
  height: 100%;
  width: 100%;
}

.grid-mixed-top-landscape .comic-panel-row-bottom {
  height: calc(48% - 6px);
  width: 100%;
  display: flex;
  gap: 12px;
}

.grid-mixed-top-landscape .comic-panel-row-bottom .comic-panel {
  height: 100%;
  flex: 1;
}

/* 9-Grid Layout System (3x3 = 9 Equal Panels Side-by-Side & Stacked) */
.grid-9-panels {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 8px;
  height: 1000px;
  width: 100%;
}
.grid-9-panels .comic-panel {
  width: 100%;
  height: 100%;
}

/* 6-Grid Layout System (3 rows x 2 columns = 6 Equal Panels) */
.grid-6-panels {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 10px;
  height: 1000px;
  width: 100%;
}
.grid-6-panels .comic-panel {
  width: 100%;
  height: 100%;
}

/* 4-Grid Layout (2x2 Equal Panels) */
.grid-4-panels {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 12px;
  height: 1000px;
  width: 100%;
}
.grid-4-panels .comic-panel {
  width: 100%;
  height: 100%;
}

/* 3er Spalten / Vertical Columns (1x3 side-by-side) */
.grid-3-cols {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  height: 1000px;
  width: 100%;
}
.grid-3-cols .comic-panel {
  width: 100%;
  height: 100%;
}

/* 3er Reihen / Horizontal Rows (3x1 stacked) */
.grid-3-rows {
  display: grid;
  grid-template-rows: repeat(3, 1fr);
  gap: 12px;
  height: 1000px;
  width: 100%;
}
.grid-3-rows .comic-panel {
  width: 100%;
  height: 100%;
}

/* Page Layout Toolbar in A4 Comic Viewer */
.a4-page-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.a4-page-layout-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--glass-border);
  padding: 0.45rem 1rem;
  border-radius: var(--radius-md);
  width: 794px;
  box-sizing: border-box;
}

.a4-page-layout-toolbar label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--accent-cyan);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.a4-page-layout-toolbar select {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--glass-border);
  border-radius: 4px;
  padding: 0.3rem 0.6rem;
  font-size: 0.82rem;
  outline: none;
}

/* Quick Focal Position Controls Overlay on Panels */
.panel-crop-btn {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(15, 23, 42, 0.85);
  color: #67e8f9;
  border: 1.5px solid var(--accent-cyan);
  border-radius: 4px;
  font-size: 0.7rem;
  padding: 3px 7px;
  cursor: pointer;
  z-index: 15;
  opacity: 0.6;
  transition: opacity 0.2s ease;
}

.comic-panel:hover .panel-crop-btn {
  opacity: 1;
}

.panel-crop-menu {
  position: absolute;
  bottom: 34px;
  right: 8px;
  background: #0f172a;
  border: 1.5px solid var(--accent-cyan);
  border-radius: 6px;
  padding: 6px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  z-index: 25;
  box-shadow: 0 10px 30px rgba(0,0,0,0.9);
}

.panel-crop-menu button {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  color: #fff;
  font-size: 0.7rem;
  padding: 4px 6px;
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.panel-crop-menu button:hover {
  background: var(--accent-cyan);
  color: #000;
}


/* Comic Panel Styling */
.comic-panel {
  border: 3.5px solid #0f172a;
  border-radius: 6px;
  background: #0f172a;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 3px 3px 0px #0f172a;
  box-sizing: border-box;
}

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

/* Narrator Caption Box (Yellow/Amber box in top left of panel) */
.narrator-box {
  position: absolute;
  top: 10px;
  left: 10px;
  max-width: 82%;
  background: #fef08a; /* Classic comic narration yellow */
  color: #0f172a;
  border: 2.5px solid #0f172a;
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.3;
  box-shadow: 3px 3px 0px #0f172a;
  z-index: 5;
}

.narrator-box-label {
  font-family: var(--font-heading);
  font-size: 0.68rem;
  font-weight: 800;
  color: #b45309;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
  text-transform: uppercase;
}

/* Speech Bubbles Overlay */
.speech-bubble-container {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 6;
}

.speech-bubble {
  position: absolute;
  color: #0f172a;
  box-shadow: 3px 3px 0px #0f172a;
  z-index: 10;
  box-sizing: border-box;
  user-select: none;
  min-width: 110px;
  max-width: 240px;
}

/* Bubble Scaling Sizes */
.bubble-size-small {
  font-size: 0.72rem !important;
  min-width: 90px !important;
  max-width: 170px !important;
  padding: 0.35rem 0.65rem !important;
}
.bubble-size-small .speech-bubble-char { font-size: 0.62rem !important; }
.bubble-size-small .speech-bubble-text { font-size: 0.72rem !important; }

.bubble-size-medium {
  font-size: 0.82rem !important;
  min-width: 110px !important;
  max-width: 240px !important;
  padding: 0.5rem 0.85rem !important;
}

.bubble-size-large {
  font-size: 0.98rem !important;
  min-width: 140px !important;
  max-width: 300px !important;
  padding: 0.65rem 1.05rem !important;
}
.bubble-size-large .speech-bubble-char { font-size: 0.82rem !important; }
.bubble-size-large .speech-bubble-text { font-size: 0.95rem !important; }

.bubble-size-xlarge {
  font-size: 1.15rem !important;
  min-width: 170px !important;
  max-width: 360px !important;
  padding: 0.85rem 1.25rem !important;
}
.bubble-size-xlarge .speech-bubble-char { font-size: 0.95rem !important; }
.bubble-size-xlarge .speech-bubble-text { font-size: 1.12rem !important; }

/* 1. Speech (Standard Oval) */
.bubble-type-speech {
  background: #ffffff;
  border: 2.5px solid #0f172a;
  border-radius: 18px;
  padding: 0.5rem 0.85rem;
}

/* 2. Shout / Action (Starburst Jagged Border) */
.bubble-type-shout {
  background: #fff7ed;
  border: 3px solid #9a3412;
  border-radius: 6px;
  padding: 0.6rem 0.95rem;
  box-shadow: 4px 4px 0px #9a3412;
}
.bubble-type-shout .speech-bubble-char {
  color: #c2410c !important;
  font-weight: 900;
}
.bubble-type-shout .speech-bubble-text {
  font-weight: 800;
  text-transform: uppercase;
}

/* 3. Thought (Cloud Shape) */
.bubble-type-thought {
  background: #ffffff;
  border: 2.5px solid #0f172a;
  border-radius: 24px;
  padding: 0.6rem 0.9rem;
}

/* 4. Whisper (Dashed Border) */
.bubble-type-whisper {
  background: rgba(255, 255, 255, 0.92);
  border: 2.5px dashed #475569;
  border-radius: 14px;
  padding: 0.45rem 0.8rem;
  box-shadow: 2px 2px 0px rgba(0,0,0,0.2);
}
.bubble-type-whisper .speech-bubble-text {
  font-style: italic;
  color: #334155;
}

/* 5. Narrator Box */
.bubble-type-narrator {
  background: #fef08a;
  border: 2.5px solid #0f172a;
  border-radius: 2px;
  padding: 0.45rem 0.8rem;
  box-shadow: 3px 3px 0px #0f172a;
}
.bubble-type-narrator .speech-bubble-char {
  color: #b45309 !important;
  font-size: 0.65rem;
}

/* Tail Pointers (4 Directions) */
.tail-bottom-left::after {
  content: '';
  position: absolute;
  bottom: -9px;
  left: 18px;
  width: 0;
  height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 9px solid #0f172a;
}

.tail-bottom-right::after {
  content: '';
  position: absolute;
  bottom: -9px;
  right: 18px;
  width: 0;
  height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 9px solid #0f172a;
}

.tail-top-left::after {
  content: '';
  position: absolute;
  top: -9px;
  left: 18px;
  width: 0;
  height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-bottom: 9px solid #0f172a;
}

.tail-top-right::after {
  content: '';
  position: absolute;
  top: -9px;
  right: 18px;
  width: 0;
  height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-bottom: 9px solid #0f172a;
}

.speech-bubble-char {
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 0.72rem;
  text-transform: uppercase;
  color: #4f46e5;
  margin-bottom: 2px;
}

.speech-bubble-text {
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.35;
}

/* Editor Modal Layout */
.bubble-editor-content {
  max-width: 1100px !important;
  width: 95vw !important;
  height: 90vh !important;
  display: flex !important;
  flex-direction: column !important;
  padding: 1.25rem !important;
}

.bubble-editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--glass-border);
}

.bubble-editor-body {
  flex: 1;
  display: flex;
  gap: 1.25rem;
  margin-top: 1rem;
  overflow: hidden;
}

.bubble-editor-canvas-container {
  flex: 1;
  background: #090d16;
  border-radius: var(--radius-md);
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--glass-border);
}

#editor-canvas-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
  user-select: none;
}

#editor-canvas-bubbles {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
}

#editor-canvas-bubbles .speech-bubble {
  pointer-events: auto;
  cursor: grab;
}

#editor-canvas-bubbles .speech-bubble.active-dragging {
  cursor: grabbing;
  outline: 2px dashed var(--accent-cyan);
  outline-offset: 3px;
}

.bubble-editor-pane {
  width: 340px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: 1rem;
  display: flex;
  flex-direction: column;
}

.editor-bubble-item {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.editor-bubble-item.selected {
  border-color: var(--accent-cyan);
  background: rgba(6, 182, 212, 0.1);
}

.a4-page-footer {
  border-top: 2px solid #e2e8f0;
  padding-top: 0.5rem;
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: #94a3b8;
  font-weight: 600;
}

/* Print Rules for PDF Export via Browser Print Dialog */
@media print {
  body * {
    visibility: hidden;
  }
  
  #comic-modal, #comic-pages-viewport, .a4-comic-page, .a4-comic-page * {
    visibility: visible;
  }

  #comic-modal {
    position: absolute;
    left: 0;
    top: 0;
    width: 100% !important;
    height: auto !important;
    background: white !important;
    padding: 0 !important;
  }

  .comic-modal-content {
    max-width: 100% !important;
    width: 100% !important;
    height: auto !important;
    box-shadow: none !important;
    padding: 0 !important;
    background: white !important;
  }

  .comic-modal-header {
    display: none !important;
  }

  .comic-pages-viewport {
    background: white !important;
    padding: 0 !important;
    gap: 0 !important;
  }

  .a4-comic-page {
    box-shadow: none !important;
    border-radius: 0 !important;
    width: 210mm !important;
    height: 297mm !important;
    min-height: 297mm !important;
    padding: 15mm !important;
    margin: 0 !important;
    page-break-after: always !important;
    page-break-inside: avoid !important;
  }

  @page {
    size: A4 portrait;
    margin: 0;
  }
}

/* LM Studio Streaming Thinking Card Styles */
.thinking-card {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  background: rgba(30, 41, 59, 0.85);
  border: 1px solid rgba(99, 102, 241, 0.4);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin: 1rem 0;
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 20px rgba(99, 102, 241, 0.15);
  animation: pulseGlow 2.5s infinite ease-in-out;
}

@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 4px 20px rgba(99, 102, 241, 0.15); }
  50% { box-shadow: 0 4px 25px rgba(99, 102, 241, 0.35); }
}

.hourglass-icon {
  font-size: 1.8rem;
  animation: spinSlow 3s infinite linear;
}

@keyframes spinSlow {
  0% { transform: rotate(0deg); }
  50% { transform: rotate(180deg); }
  100% { transform: rotate(360deg); }
}

.thinking-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  width: 100%;
}

.thinking-title {
  font-family: var(--font-heading);
  font-size: 1.05rem;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.thinking-dots {
  display: inline-flex;
  gap: 4px;
}

.thinking-dots span {
  width: 6px;
  height: 6px;
  background: var(--accent-primary);
  border-radius: 50%;
  animation: bounceDot 1.4s infinite ease-in-out both;
}

.thinking-dots span:nth-child(1) { animation-delay: -0.32s; }
.thinking-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounceDot {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1.0); }
}

.thinking-user-prompt {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-style: italic;
}

.thinking-stats-container {
  margin-top: 0.4rem;
  display: flex;
  gap: 0.6rem;
  align-items: center;
  flex-wrap: wrap;
}

.thinking-stat-badge {
  font-size: 0.78rem;
  padding: 0.2rem 0.6rem;
  border-radius: 12px;
  font-weight: 500;
  transition: all 0.2s ease;
}

.thinking-stat-badge.reasoning {
  background: rgba(99, 102, 241, 0.2);
  color: #a5b4fc;
  border: 1px solid rgba(99, 102, 241, 0.35);
}

.thinking-stat-badge.content {
  background: rgba(16, 185, 129, 0.2);
  color: #6ee7b7;
  border: 1px solid rgba(16, 185, 129, 0.35);
}



