/* ===================================================
   T-Toons Design System
   Korean Webtoon Design Platform
   =================================================== */

:root {
  --bg-primary: #0B0B0D;
  --bg-secondary: #111115;
  --bg-elevated: #1A1A22;
  --bg-sheet: #16161E;
  --text-primary: #F2F2F2;
  --text-secondary: #9A9A9A;
  --text-tertiary: #6B6B7B;
  --accent-purple: #8B5CF6;
  --accent-cyan: #06B6D4;
  --accent-blue: #2563EB;
  --border-subtle: rgba(139, 92, 246, 0.15);
  --border-glow: rgba(139, 92, 246, 0.3);
  --glass-bg: rgba(22, 22, 30, 0.92);
  --glass-border: rgba(255, 255, 255, 0.06);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body { overscroll-behavior: none; }

/* ===== Scrollbar Styles ===== */
::-webkit-scrollbar { width: 3px; height: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(139, 92, 246, 0.3); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(139, 92, 246, 0.5); }

/* ===== Gradient Utilities ===== */
.gradient-text {
  background: linear-gradient(135deg, var(--accent-purple), var(--accent-cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.gradient-btn {
  background: linear-gradient(135deg, #7C3AED, #4F46E5, #2563EB);
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}
.gradient-btn:hover { filter: brightness(1.1); transform: translateY(-1px); }
.gradient-btn:active { transform: translateY(0); filter: brightness(0.95); }
.gradient-btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent 40%, rgba(255,255,255,0.1));
}

.gradient-btn-alt {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.15), rgba(6, 182, 212, 0.15));
  border: 1px solid rgba(139, 92, 246, 0.25);
  transition: all 0.3s ease;
}
.gradient-btn-alt:hover { border-color: rgba(139, 92, 246, 0.5); background: linear-gradient(135deg, rgba(139, 92, 246, 0.25), rgba(6, 182, 212, 0.25)); }

/* ===== Glass Effect ===== */
.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
}

.glass-card {
  background: rgba(26, 26, 34, 0.6);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  transition: all 0.3s ease;
}
.glass-card:hover { border-color: var(--border-glow); box-shadow: 0 0 20px rgba(139, 92, 246, 0.1); }
.glass-card:active { transform: scale(0.98); }

/* ===== Screen Transitions ===== */
.screen { 
  position: absolute; inset: 0; 
  display: flex; flex-direction: column;
  opacity: 0; transform: translateX(20px);
  transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
  overflow: hidden;
}
.screen.active { opacity: 1; transform: translateX(0); pointer-events: all; }
.screen.exit-left { opacity: 0; transform: translateX(-20px); }

/* ===== Bottom Sheet ===== */
.bottom-sheet {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: var(--glass-bg);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-top: 1px solid var(--glass-border);
  border-radius: 24px 24px 0 0;
  padding: 12px 20px 32px;
  transform: translateY(100%);
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 50;
}
.bottom-sheet.open { transform: translateY(0); }
.bottom-sheet-handle {
  width: 36px; height: 4px; border-radius: 2px;
  background: rgba(255,255,255,0.2);
  margin: 0 auto 16px;
}

/* ===== Series Card ===== */
.series-card {
  cursor: pointer;
  transition: all 0.2s ease;
}
.series-card:active { transform: scale(0.95); }
.series-card-img {
  aspect-ratio: 1; border-radius: 14px; overflow: hidden;
  border: 1.5px solid var(--border-subtle);
  position: relative;
  background: var(--bg-elevated);
}
.series-card-img img { width: 100%; height: 100%; object-fit: cover; }
.series-card-img::after {
  content: ''; position: absolute; inset: 0;
  border-radius: 14px;
  box-shadow: inset 0 -30px 30px -15px rgba(0,0,0,0.5);
}

/* ===== Mode Toggle ===== */
.mode-toggle {
  display: flex; gap: 4px; padding: 4px;
  background: var(--bg-secondary);
  border-radius: 12px;
  border: 1px solid var(--glass-border);
}
.mode-toggle-btn {
  flex: 1; padding: 10px 16px; border-radius: 10px;
  font-size: 14px; font-weight: 500;
  color: var(--text-tertiary);
  transition: all 0.3s ease;
  text-align: center; cursor: pointer;
}
.mode-toggle-btn.active {
  background: var(--bg-elevated);
  color: var(--text-primary);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

/* ===== Prompt Bar ===== */
.prompt-bar {
  display: flex; gap: 10px; align-items: center;
  padding: 10px 12px;
  background: var(--bg-secondary);
  border-radius: 14px;
  border: 1px solid var(--glass-border);
}
.prompt-bar input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text-primary); font-size: 14px;
  font-family: 'Inter', sans-serif;
}
.prompt-bar input::placeholder { color: var(--text-tertiary); }
.prompt-generate-btn {
  padding: 10px 20px; border-radius: 10px;
  background: linear-gradient(135deg, #6D28D9, #4F46E5);
  color: white; font-weight: 600; font-size: 14px;
  cursor: pointer; white-space: nowrap;
  transition: all 0.2s ease;
}
.prompt-generate-btn:hover { filter: brightness(1.15); }
.prompt-generate-btn:active { transform: scale(0.95); }

/* ===== Chip Tags ===== */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 20px;
  font-size: 12px; font-weight: 500;
  background: var(--bg-secondary);
  border: 1px solid var(--glass-border);
  color: var(--text-secondary);
  cursor: pointer; white-space: nowrap;
  transition: all 0.2s ease;
  user-select: none;
}
.chip:hover { border-color: var(--border-subtle); color: var(--text-primary); }
.chip.selected {
  background: rgba(139, 92, 246, 0.2);
  border-color: var(--accent-purple);
  color: var(--accent-purple);
  box-shadow: 0 0 12px rgba(139, 92, 246, 0.15);
}
.chip.character {
  background: rgba(6, 182, 212, 0.15);
  border-color: rgba(6, 182, 212, 0.3);
  color: var(--accent-cyan);
}

/* ===== Toolbar ===== */
.side-toolbar {
  display: flex; flex-direction: column; gap: 2px;
  padding: 8px 4px;
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
}
.toolbar-btn {
  width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;
  border-radius: 10px; color: var(--text-secondary);
  cursor: pointer; transition: all 0.2s ease; font-size: 16px;
}
.toolbar-btn:hover { color: var(--text-primary); background: rgba(255,255,255,0.05); }
.toolbar-btn.active {
  background: linear-gradient(135deg, #7C3AED, #4F46E5);
  color: white;
  box-shadow: 0 0 16px rgba(139, 92, 246, 0.4);
}

/* ===== Panel Items ===== */
.panel-item {
  border-radius: 8px; overflow: hidden;
  border: 2px solid transparent;
  transition: all 0.2s ease;
  cursor: pointer; position: relative;
}
.panel-item:hover { border-color: var(--border-subtle); }
.panel-item.selected { border-color: var(--accent-purple); box-shadow: 0 0 16px rgba(139, 92, 246, 0.3); }
.panel-item img { width: 100%; display: block; }

/* ===== Speech Bubble ===== */
.speech-bubble {
  position: absolute; padding: 8px 14px;
  background: white; border-radius: 18px;
  color: #1a1a2e; font-size: 11px; font-weight: 500;
  line-height: 1.4; max-width: 140px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  pointer-events: none;
}
.speech-bubble::after {
  content: ''; position: absolute; bottom: -8px; left: 20px;
  width: 0; height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 10px solid white;
}
.speech-bubble.thought {
  border-radius: 50%; padding: 10px 16px;
}
.speech-bubble.thought::after {
  width: 8px; height: 8px; border-radius: 50%;
  background: white; border: none;
  bottom: -12px; left: 24px;
}
.speech-bubble.shout {
  background: #FFE135; color: #1a1a2e;
  font-weight: 700; font-size: 12px;
  border-radius: 4px;
  transform: rotate(-1deg);
}
.speech-bubble.shout::after { border-top-color: #FFE135; }

/* ===== Episode Thumbnail Strip ===== */
.episode-thumb {
  width: 56px; height: 72px; flex-shrink: 0;
  border-radius: 8px; overflow: hidden;
  border: 2px solid transparent;
  cursor: pointer; transition: all 0.2s ease;
  background: var(--bg-elevated);
}
.episode-thumb.active {
  border-color: var(--accent-purple);
  box-shadow: 0 0 12px rgba(139, 92, 246, 0.4);
}
.episode-thumb img { width: 100%; height: 100%; object-fit: cover; }

/* ===== Hamburger Menu ===== */
.menu-overlay {
  position: absolute; inset: 0; z-index: 60;
  background: rgba(0,0,0,0.6);
  opacity: 0; pointer-events: none;
  transition: opacity 0.3s ease;
}
.menu-overlay.open { opacity: 1; pointer-events: all; }
.menu-panel {
  position: absolute; top: 0; left: 0; bottom: 0;
  width: 280px; padding: 60px 24px 32px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--glass-border);
  transform: translateX(-100%);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}
.menu-overlay.open .menu-panel { transform: translateX(0); }
.menu-item {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px; border-radius: 12px;
  color: var(--text-secondary); font-size: 15px; font-weight: 500;
  cursor: pointer; transition: all 0.2s ease;
  margin-bottom: 4px;
}
.menu-item:hover, .menu-item.active {
  background: rgba(139, 92, 246, 0.1);
  color: var(--text-primary);
}
.menu-item i { width: 20px; text-align: center; font-size: 16px; }

/* ===== Input Fields ===== */
.input-field {
  width: 100%; padding: 14px 16px; border-radius: 12px;
  background: var(--bg-primary);
  border: 1px solid var(--glass-border);
  color: var(--text-primary); font-size: 15px;
  font-family: 'Inter', sans-serif;
  outline: none; transition: border-color 0.2s ease;
}
.input-field:focus { border-color: var(--accent-purple); }
.input-field::placeholder { color: var(--text-tertiary); }

/* ===== Modal ===== */
.modal-overlay {
  position: absolute; inset: 0; z-index: 70;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; opacity: 0; pointer-events: none;
  transition: opacity 0.3s ease;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal-content {
  width: 100%; max-width: 380px; padding: 28px;
  background: var(--bg-elevated);
  border-radius: 20px;
  border: 1px solid var(--glass-border);
  transform: scale(0.9) translateY(20px);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}
.modal-overlay.open .modal-content { transform: scale(1) translateY(0); }

/* ===== Toast Notifications ===== */
.toast {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%) translateY(-100px);
  padding: 12px 24px; border-radius: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary); font-size: 14px; font-weight: 500;
  z-index: 100; opacity: 0;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== Skeleton Loading ===== */
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
.skeleton {
  background: linear-gradient(90deg, var(--bg-elevated) 25%, rgba(139,92,246,0.08) 50%, var(--bg-elevated) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: 8px;
}

/* ===== Generate Animation ===== */
@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 15px rgba(139, 92, 246, 0.3); }
  50% { box-shadow: 0 0 30px rgba(139, 92, 246, 0.6); }
}
.generating { animation: pulse-glow 1.5s ease-in-out infinite; }

/* ===== Floating Action Button ===== */
.fab {
  width: 52px; height: 52px; border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #7C3AED, #4F46E5);
  color: white; font-size: 20px; cursor: pointer;
  box-shadow: 0 4px 20px rgba(139, 92, 246, 0.4);
  transition: all 0.2s ease;
}
.fab:hover { transform: scale(1.05); }
.fab:active { transform: scale(0.95); }

/* ===== Empty State ===== */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 48px 24px; text-align: center;
}
.empty-state-icon {
  width: 80px; height: 80px; border-radius: 24px;
  background: rgba(139, 92, 246, 0.1);
  display: flex; align-items: center; justify-content: center;
  font-size: 32px; color: var(--accent-purple);
}

/* ===== Page Header ===== */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px;
  position: relative; z-index: 10;
}
.header-btn {
  width: 40px; height: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--glass-border);
  color: var(--text-secondary); font-size: 16px;
  cursor: pointer; transition: all 0.2s ease;
}
.header-btn:hover { color: var(--text-primary); background: rgba(255,255,255,0.1); }

/* ===== Responsive Width Constraint ===== */
@media (min-width: 431px) {
  #app { box-shadow: 0 0 60px rgba(0,0,0,0.5), 0 0 1px rgba(139,92,246,0.2); border-radius: 0; }
  body { background: #050507; }
}

/* ===== Remix Slider ===== */
.remix-slider {
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--bg-elevated), var(--accent-purple));
  outline: none;
}
.remix-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: linear-gradient(135deg, #7C3AED, #4F46E5);
  cursor: pointer;
  box-shadow: 0 0 12px rgba(139, 92, 246, 0.5);
  border: 2px solid var(--bg-primary);
  transition: box-shadow 0.2s ease;
}
.remix-slider::-webkit-slider-thumb:hover {
  box-shadow: 0 0 20px rgba(139, 92, 246, 0.7);
}
.remix-slider::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: linear-gradient(135deg, #7C3AED, #4F46E5);
  cursor: pointer;
  box-shadow: 0 0 12px rgba(139, 92, 246, 0.5);
  border: 2px solid var(--bg-primary);
}

/* ===== Line Clamp ===== */
.line-clamp-1 {
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
}

/* ===== Ring Utilities (for Remix selection) ===== */
.ring-2 { box-shadow: 0 0 0 2px var(--accent-purple); }
.ring-accent-purple { --tw-ring-color: var(--accent-purple); }

/* ===== Story Mode Analysis Animation ===== */
@keyframes fadeInLeft {
  from { opacity: 0; transform: translateX(-10px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ===== Quick Share Platform Glow ===== */
.platform-selected {
  box-shadow: 0 0 16px rgba(139, 92, 246, 0.3);
}

/* ===== Prevent text selection on UI elements ===== */
button, .chip, .toolbar-btn, .mode-toggle-btn, .menu-item, .series-card, .episode-thumb {
  user-select: none; -webkit-user-select: none;
}

/* ===== Sketch Canvas ===== */
#sketchCanvas { touch-action: none; }

/* ===== Inpaint Canvas overlay ===== */
#inpaintCanvas {
  mix-blend-mode: multiply;
  cursor: crosshair;
}

/* ===== Adjust preview smooth transition ===== */
#adjustPreviewImg { transition: filter 0.15s ease, transform 0.15s ease; }

/* ===== Grid View panel hover ===== */
.group:hover .group-hover\:opacity-100 { opacity: 1; }

/* ===== Quick share improvements ===== */
.share-platform-btn {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 12px 10px; border-radius: 16px;
  border: 1.5px solid var(--glass-border);
  transition: all 0.25s ease; cursor: pointer;
  background: var(--bg-primary);
}
.share-platform-btn.selected {
  border-color: var(--accent-purple);
  background: rgba(139,92,246,0.1);
  box-shadow: 0 0 16px rgba(139,92,246,0.25);
}
.share-platform-btn i { font-size: 22px; }

/* ===== More Options Sheet ===== */
#editorMoreSheet { box-shadow: 0 -12px 40px rgba(0,0,0,0.5); }

/* ===== Model Badge Pulse ===== */
@keyframes model-badge-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* ===== Export preview thumbnail ===== */
.export-thumb { transition: border-color 0.2s ease; }

/* ===== Outpaint direction button ===== */
.outpaint-dir { transition: all 0.2s ease; }
.outpaint-dir:active { transform: scale(0.9); }

/* ===== Import drop zone active ===== */
#importDropZone:active, #i2iDropZone:active { border-color: var(--accent-cyan) !important; }

/* ===== Upscale level selector ===== */
.upscale-option { transition: all 0.2s ease; }
.upscale-option:active { transform: scale(0.98); }

/* ===== Story template card ===== */
.story-template-card {
  transition: all 0.2s ease;
  cursor: pointer;
}
.story-template-card:active { transform: scale(0.96); }

/* ===== PWA Install Banner ===== */
#pwaBanner { box-shadow: 0 8px 32px rgba(0,0,0,0.5); }

/* ===== Chip flex justify ===== */
.chip.justify-center { justify-content: center; }

/* ===== Fullscreen overlay for quick sketch ===== */
#sketchOverlay { align-items: flex-start; padding: 0; }

/* ===== Adjustment slider track fill ===== */
.remix-slider {
  background: linear-gradient(90deg, var(--accent-purple) 0%, var(--accent-purple) var(--val, 50%), var(--bg-elevated) var(--val, 50%));
}
