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

body {
  font-family: "Poppins", sans-serif;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  min-height: 100vh;
  color: #e0e0e0;
  padding: 20px;
  transition: background 0.4s ease, color 0.4s ease;
}

body.theme-matrix {
  background: radial-gradient(circle, #001100 0%, #000000 100%);
  color: #00ff00;
}

body.theme-matrix .container,
body.theme-matrix .dashboard-container {
  border-color: #00ff00;
  box-shadow: 0 0 20px rgba(0, 255, 0, 0.2);
}

body.theme-matrix h1,
body.theme-matrix h2,
body.theme-matrix h3,
body.theme-matrix h4 {
  color: #00ff00;
  text-shadow: 0 0 10px rgba(0, 255, 0, 0.5);
}

body.theme-cyberpunk {
  background: linear-gradient(135deg, #0f0f0f 0%, #330066 50%, #1a0033 100%);
  color: #ff00ff;
}

body.theme-cyberpunk .container,
body.theme-cyberpunk .dashboard-container {
  border-color: #ff00ff;
  box-shadow: 0 0 20px rgba(255, 0, 255, 0.2);
}

body.theme-cyberpunk h1,
body.theme-cyberpunk h2,
body.theme-cyberpunk h3,
body.theme-cyberpunk h4 {
  color: #ff00ff;
  text-shadow: 0 0 10px rgba(255, 0, 255, 0.5);
}

body.theme-neonblue {
  background: radial-gradient(circle, #00111a 0%, #000000 100%);
  color: #00ffff;
}

body.theme-neonblue .container,
body.theme-neonblue .dashboard-container {
  border-color: #00ffff;
  box-shadow: 0 0 20px rgba(0, 255, 255, 0.2);
}

body.theme-neonblue h1,
body.theme-neonblue h2,
body.theme-neonblue h3,
body.theme-neonblue h4 {
  color: #00ffff;
  text-shadow: 0 0 10px rgba(0, 255, 255, 0.5);
}

.theme-selector {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1001;
}

.theme-selector select {
  padding: 8px 15px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  border: 1px solid #667eea;
  cursor: pointer;
  font-family: 'Poppins', sans-serif;
  font-size: 12px;
}

.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 30px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 20px;
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.auth-section {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

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

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #38ef7d;
}

.auth-btn {
  padding: 8px 16px;
  border-radius: 20px;
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
  transition: all 0.3s ease;
}

.login-btn {
  background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
  color: #fff;
}

.logout-btn {
  background: rgba(255, 107, 107, 0.2);
  color: #ff6b6b;
  border: 1px solid #ff6b6b;
}

.auth-btn:hover {
  transform: translateY(-2px);
}

.saved-stories-section {
  margin-top: 30px;
  padding: 20px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 15px;
  border: 1px solid #3a3a5c;
}

.saved-stories-section h3 {
  text-align: center;
  margin-bottom: 15px;
  color: #38ef7d;
}

.saved-stories-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 15px;
}

.saved-story-card {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid #3a3a5c;
}

.saved-story-img {
  width: 100%;
  height: 120px;
  object-fit: cover;
}

.saved-story-content {
  padding: 10px;
}

.saved-story-text {
  font-size: 0.8rem;
  color: #c0c0c0;
  line-height: 1.4;
  margin-bottom: 8px;
}

.saved-story-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: #808080;
  margin-bottom: 8px;
}

.saved-story-model {
  background: rgba(56, 239, 125, 0.2);
  color: #38ef7d;
  padding: 2px 6px;
  border-radius: 4px;
}

.delete-saved-btn {
  width: 100%;
  padding: 6px;
  background: rgba(255, 107, 107, 0.2);
  color: #ff6b6b;
  border: 1px solid #ff6b6b;
  border-radius: 5px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.3s ease;
}

.delete-saved-btn:hover {
  background: rgba(255, 107, 107, 0.4);
}

h1 {
  text-align: center;
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 10px;
  background: linear-gradient(90deg, #ff6b6b, #feca57, #48dbfb);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  text-align: center;
  color: #a0a0a0;
  margin-bottom: 30px;
  font-size: 0.95rem;
}

.model-selector {
  text-align: center;
  margin-bottom: 25px;
}

.model-selector label {
  display: block;
  margin-bottom: 12px;
  font-weight: 500;
  color: #c0c0c0;
}

.model-options {
  display: flex;
  justify-content: center;
  gap: 15px;
  flex-wrap: wrap;
}

.model-btn {
  padding: 12px 24px;
  border: 2px solid #3a3a5c;
  background: transparent;
  color: #a0a0a0;
  border-radius: 30px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  transition: all 0.3s ease;
}

.model-btn:hover {
  border-color: #5a5a8c;
  color: #ffffff;
}

.model-btn.active {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-color: transparent;
  color: #ffffff;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.upload-section {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 15px;
  margin-bottom: 25px;
  flex-wrap: wrap;
}

.file-label {
  display: inline-block;
  padding: 12px 28px;
  background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
  color: #ffffff;
  border-radius: 30px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(56, 239, 125, 0.3);
}

.file-label:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(56, 239, 125, 0.4);
}

.file-label input {
  display: none;
}

.file-name {
  color: #808080;
  font-size: 0.9rem;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.uploaded-images-section {
  margin-bottom: 20px;
  padding: 15px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 12px;
  border: 1px solid #3a3a5c;
}

.uploaded-images-section h4 {
  text-align: center;
  margin-bottom: 12px;
  color: #a0a0a0;
  font-size: 0.9rem;
}

.uploaded-images-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

.uploaded-image-item {
  position: relative;
  width: 80px;
  height: 80px;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid #3a3a5c;
  cursor: pointer;
  transition: all 0.3s ease;
}

.uploaded-image-item:hover {
  border-color: #667eea;
  transform: scale(1.05);
}

.uploaded-image-item.active {
  border-color: #38ef7d;
  box-shadow: 0 0 15px rgba(56, 239, 125, 0.4);
}

.uploaded-image-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.uploaded-image-name {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  font-size: 0.6rem;
  padding: 2px 4px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.remove-uploaded-btn {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  background: rgba(255, 107, 107, 0.9);
  color: #fff;
  border: none;
  border-radius: 50%;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.uploaded-image-item:hover .remove-uploaded-btn {
  opacity: 1;
}

.url-section {
  text-align: center;
  margin-bottom: 20px;
}

.or-divider {
  color: #606080;
  font-size: 0.9rem;
  margin-bottom: 12px;
}

.url-input-wrapper {
  display: flex;
  justify-content: center;
  gap: 10px;
  max-width: 500px;
  margin: 0 auto;
}

.url-input {
  flex: 1;
  padding: 12px 16px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid #3a3a5c;
  border-radius: 10px;
  color: #e0e0e0;
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.3s ease;
}

.url-input::placeholder {
  color: #606080;
}

.url-input:focus {
  border-color: #667eea;
}

.load-url-btn {
  padding: 12px 24px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #ffffff;
  border: none;
  border-radius: 10px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

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

.url-status {
  margin-top: 10px;
  font-size: 0.85rem;
}

.url-status.loading {
  color: #feca57;
}

.url-status.success {
  color: #38ef7d;
}

.url-status.error {
  color: #ff6b6b;
}

#cropContainer {
  position: relative;
  margin: 20px auto;
  max-width: 100%;
  min-height: 300px;
  border: 2px dashed #3a3a5c;
  border-radius: 15px;
  background: rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#image {
  display: none;
  max-width: 100%;
}

.placeholder-text {
  color: #606080;
  font-size: 1.1rem;
  text-align: center;
}

.output-section {
  margin-top: 30px;
}

.output-section h3 {
  text-align: center;
  font-size: 1.3rem;
  margin-bottom: 15px;
  color: #d0d0d0;
}

.story-box {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid #3a3a5c;
  border-radius: 15px;
  padding: 25px;
  min-height: 120px;
  line-height: 1.7;
}

.story-box p {
  white-space: pre-wrap;
  word-wrap: break-word;
}

.story-box .empty-state {
  color: #606080;
  text-align: center;
  font-style: italic;
}

.story-box .loading {
  color: #feca57;
  text-align: center;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.story-box .error {
  color: #ff6b6b;
  text-align: center;
}

.links-section {
  margin-top: 40px;
  text-align: center;
}

.links-section h3 {
  font-size: 1.3rem;
  margin-bottom: 20px;
  color: #d0d0d0;
}

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

.link-card {
  display: block;
  padding: 15px 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid #3a3a5c;
  border-radius: 12px;
  color: #a0a0a0;
  text-decoration: none;
  font-weight: 500;
  transition: all 0.3s ease;
}

.link-card:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: #667eea;
  color: #ffffff;
  transform: translateY(-2px);
}

.action-buttons {
  display: flex;
  justify-content: center;
  gap: 15px;
  margin: 25px 0;
  flex-wrap: wrap;
}

.crop-btn {
  padding: 15px 30px;
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  color: #ffffff;
  border: none;
  border-radius: 30px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(245, 87, 108, 0.4);
}

.history-btn {
  padding: 15px 30px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #ffffff;
  border: none;
  border-radius: 30px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.history-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 25px rgba(102, 126, 234, 0.5);
}

.gallery-section {
  margin: 30px 0;
}

.gallery-section h3 {
  text-align: center;
  font-size: 1.3rem;
  margin-bottom: 20px;
  color: #d0d0d0;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 15px;
}

.gallery-item {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid #3a3a5c;
  aspect-ratio: 1;
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.gallery-item-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.9));
  padding: 40px 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.narrated-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: #38ef7d;
  color: #000;
  font-size: 0.7rem;
  padding: 3px 8px;
  border-radius: 10px;
  font-weight: 600;
}

.narrate-btn {
  padding: 8px 12px;
  background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

.narrate-btn:hover:not(:disabled) {
  transform: scale(1.05);
}

.narrate-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.delete-btn {
  padding: 6px 10px;
  background: rgba(255, 107, 107, 0.2);
  color: #ff6b6b;
  border: 1px solid #ff6b6b;
  border-radius: 8px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.3s ease;
}

.delete-btn:hover {
  background: rgba(255, 107, 107, 0.4);
}

.video-btn {
  padding: 8px 12px;
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

.video-btn:hover:not(:disabled) {
  transform: scale(1.05);
}

.video-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.download-video-btn {
  display: inline-block;
  margin-top: 15px;
  padding: 12px 25px;
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  color: #fff;
  text-decoration: none;
  border-radius: 25px;
  font-weight: 600;
  transition: all 0.3s ease;
}

.download-video-btn:hover {
  transform: translateY(-2px);
}

.video-btn-large {
  padding: 15px 30px;
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
  display: block;
}

.video-btn-large:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(240, 147, 251, 0.4);
}

.video-btn-large:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.gallery-actions {
  text-align: center;
  margin-top: 20px;
}

.download-link {
  display: inline-block;
  margin-top: 15px;
  padding: 12px 25px;
  background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
  color: #fff;
  text-decoration: none;
  border-radius: 25px;
  font-weight: 600;
  transition: all 0.3s ease;
  box-shadow: 0 5px 20px rgba(240, 147, 251, 0.4);
}

.gallery-empty {
  text-align: center;
  color: #606080;
  font-style: italic;
  padding: 30px;
}

.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: #1a1a2e;
  border-radius: 20px;
  max-width: 800px;
  width: 100%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  border: 1px solid #3a3a5c;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 25px;
  border-bottom: 1px solid #3a3a5c;
}

.modal-header h2 {
  margin: 0;
  color: #e0e0e0;
  font-size: 1.4rem;
}

.modal-close {
  background: none;
  border: none;
  color: #a0a0a0;
  font-size: 2rem;
  cursor: pointer;
  line-height: 1;
  padding: 0;
}

.modal-close:hover {
  color: #ffffff;
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 25px;
}

.modal-footer {
  padding: 15px 25px;
  border-top: 1px solid #3a3a5c;
  text-align: center;
}

.clear-history-btn {
  padding: 10px 20px;
  background: rgba(255, 107, 107, 0.2);
  color: #ff6b6b;
  border: 1px solid #ff6b6b;
  border-radius: 10px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
}

.clear-history-btn:hover {
  background: rgba(255, 107, 107, 0.4);
}

.history-item {
  display: flex;
  gap: 15px;
  padding: 15px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 12px;
  margin-bottom: 15px;
  border: 1px solid #3a3a5c;
}

.history-image {
  width: 100px;
  height: 100px;
  flex-shrink: 0;
  border-radius: 8px;
  overflow: hidden;
}

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

.history-content {
  flex: 1;
  min-width: 0;
}

.history-meta {
  display: flex;
  gap: 10px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.history-date {
  font-size: 0.8rem;
  color: #808080;
}

.history-model {
  font-size: 0.75rem;
  padding: 2px 8px;
  background: rgba(102, 126, 234, 0.3);
  color: #667eea;
  border-radius: 10px;
}

.history-story {
  font-size: 0.9rem;
  color: #c0c0c0;
  line-height: 1.5;
  max-height: 100px;
  overflow-y: auto;
}

.history-empty {
  text-align: center;
  color: #606080;
  font-style: italic;
  padding: 40px 20px;
}

@media (max-width: 600px) {
  .container {
    padding: 20px 15px;
  }
  
  h1 {
    font-size: 1.5rem;
  }
  
  .model-options {
    flex-direction: column;
    align-items: center;
  }
  
  .model-btn {
    width: 100%;
    max-width: 250px;
  }
  
  .links-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .action-buttons {
    flex-direction: column;
    align-items: center;
  }
  
  .gallery-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .history-item {
    flex-direction: column;
  }
  
  .history-image {
    width: 100%;
    height: 150px;
  }
}

footer a:hover {
  opacity: 0.8;
  transform: scale(1.02);
  transition: 0.2s;
}

/* Loading pulse animation */
.loading-pulse {
  display: inline-block;
  animation: pulse 1s infinite;
}

.hidden {
  display: none !important;
}

#loading {
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0% { opacity: 0.4; }
  50% { opacity: 1; }
  100% { opacity: 0.4; }
}

/* Script action buttons */
.script-actions {
  display: flex;
  gap: 10px;
  margin-top: 15px;
  flex-wrap: wrap;
}

.script-btn {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-family: 'Share Tech Mono', monospace;
  font-size: 14px;
  transition: all 0.3s ease;
}

.script-btn-copy {
  background: linear-gradient(135deg, #00ffcc 0%, #00cc99 100%);
  color: #000;
}

.script-btn-download {
  background: linear-gradient(135deg, #ff0066 0%, #cc0055 100%);
  color: #fff;
}

.script-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(0, 255, 204, 0.3);
}
