:root {
  --bg-dark: #050508;
  --bg-panel: rgba(18, 18, 24, 0.65);
  --border-light: rgba(255, 255, 255, 0.08);
  --border-glow: rgba(139, 92, 246, 0.3);
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  
  --primary: #8b5cf6;
  --primary-glow: #a855f7;
  --secondary: #3b82f6;
  --accent: #06b6d4;
  
  --danger: #ef4444;
  --success: #10b981;
  --warning: #f59e0b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-dark);
  color: var(--text-main);
  height: 100vh;
  overflow: hidden;
  position: relative;
}

/* Background Effects */
.bg-grid {
  position: absolute;
  inset: 0;
  z-index: -2;
  background-image: 
    linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
  background-size: 40px 40px;
  background-position: center center;
  mask-image: radial-gradient(ellipse 100% 100% at 50% 0%, black 30%, transparent 80%);
  -webkit-mask-image: radial-gradient(ellipse 100% 100% at 50% 0%, black 30%, transparent 80%);
}

.bg-glows {
  position: absolute;
  inset: 0;
  z-index: -1;
  background-image: 
    radial-gradient(circle at 15% 30%, rgba(139, 92, 246, 0.12), transparent 40%),
    radial-gradient(circle at 85% 70%, rgba(6, 182, 212, 0.08), transparent 40%);
  filter: blur(40px);
}

#app {
  height: 100vh;
  max-width: 1600px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 48px;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon-wrap {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.2), rgba(59, 130, 246, 0.2));
  border: 1px solid rgba(139, 92, 246, 0.4);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 15px rgba(139, 92, 246, 0.2);
}

.brand-logo {
  font-size: 20px;
}

.brand h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(to right, #fff, #cbd5e1);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand h1 span {
  font-weight: 400;
  color: var(--text-muted);
  -webkit-text-fill-color: var(--text-muted);
}

/* Layout */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 24px;
  min-height: 0; /* Important for scrolling */
}

.left-stack {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 24px;
  min-height: 0;
}

/* Panels */
.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: 20px;
  padding: 24px;
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  display: flex;
  flex-direction: column;
}

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

.panel-header h2,
.history-title-wrap h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
  letter-spacing: 0.02em;
}

.neon-dot {
  width: 8px;
  height: 8px;
  background-color: var(--success);
  border-radius: 50%;
  box-shadow: 0 0 10px var(--success);
}
.neon-dot.blue { background-color: var(--secondary); box-shadow: 0 0 10px var(--secondary); }
.neon-dot.purple { background-color: var(--primary); box-shadow: 0 0 10px var(--primary); }

/* Dropzone */
.dropzone {
  flex: 1;
  border: 1px dashed rgba(139, 92, 246, 0.3);
  background: rgba(139, 92, 246, 0.02);
  border-radius: 16px;
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  padding: 20px;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
  overflow: hidden;
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--primary-glow);
  background: rgba(139, 92, 246, 0.05);
  box-shadow: 0 0 30px rgba(139, 92, 246, 0.15) inset;
}

.dropzone-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  pointer-events: none;
}

.drop-icon-wrap {
  width: 56px;
  height: 56px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-light);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  margin-bottom: 8px;
}

.drop-svg {
  width: 24px;
  height: 24px;
}

.drop-title { margin: 0; font-size: 15px; font-weight: 500; }
.drop-desc { margin: 0; font-size: 13px; color: var(--text-muted); }

.preview-wrap {
  width: 100%;
  height: 100%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.media-preview {
  max-width: 100%;
  max-height: 240px;
  object-fit: contain;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}

.remove-btn {
  position: absolute;
  right: 8px;
  top: 8px;
  z-index: 10;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.remove-btn:hover {
  background: var(--danger);
  border-color: var(--danger);
  transform: scale(1.05);
}

/* Generate Button */
.generate-btn {
  margin-top: 20px;
  width: 100%;
  height: 52px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  position: relative;
  overflow: hidden;
  transition: all 0.3s ease;
  box-shadow: 0 4px 20px rgba(139, 92, 246, 0.3);
}

.generate-btn::before {
  content: '';
  position: absolute;
  top: 0; left: -100%;
  width: 100%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  transition: left 0.5s ease;
}

.generate-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(139, 92, 246, 0.5);
}

.generate-btn:hover:not(:disabled)::before {
  left: 100%;
}

.generate-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  filter: grayscale(0.5);
  box-shadow: none;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Output Code Block */
.output-panel {
  padding: 0;
  overflow: hidden;
}

.output-panel .panel-header {
  padding: 20px 24px 0;
  margin-bottom: 16px;
}

.code-block {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #0d1117;
  border-top: 1px solid var(--border-light);
  min-height: 0;
}

.code-header {
  height: 44px;
  background: rgba(22, 27, 34, 0.8);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  padding: 0 16px;
  justify-content: space-between;
}

.mac-dots {
  display: flex;
  gap: 8px;
}

.mac-dot { width: 12px; height: 12px; border-radius: 50%; }
.mac-dot.red { background: #ff5f56; }
.mac-dot.yellow { background: #ffbd2e; }
.mac-dot.green { background: #27c93f; }

.code-title {
  font-family: 'Fira Code', monospace;
  font-size: 13px;
  color: var(--text-muted);
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.copy-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-light);
  color: var(--text-muted);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
}

.copy-btn svg { width: 14px; height: 14px; }

.copy-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
}

.code-body {
  flex: 1;
  position: relative;
  min-height: 0;
}

#output-text {
  width: 100%;
  height: 100%;
  background: transparent;
  color: #a5d6ff;
  font-family: 'Fira Code', Consolas, monospace;
  font-size: 14px;
  line-height: 1.6;
  padding: 20px;
  border: none;
  resize: none;
}

#output-text:focus {
  outline: none;
}

#output-text::placeholder {
  color: rgba(165, 214, 255, 0.3);
}

/* Skeleton Loading */
.output-skeleton {
  position: absolute;
  inset: 0;
  background: #0d1117;
  padding: 20px;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sk-line {
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(90deg, #161b22 25%, #21262d 50%, #161b22 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite linear;
}

.sk-w-100 { width: 100%; }
.sk-w-90 { width: 90%; }
.sk-w-80 { width: 80%; }
.sk-w-60 { width: 60%; }
.sk-w-40 { width: 40%; }

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

/* History Panel */
.history-panel {
  display: flex;
  flex-direction: column;
  padding: 24px;
}

.history-title-wrap {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.ghost-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-light);
  color: var(--text-muted);
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.ghost-btn:hover {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.3);
}

.ghost-btn svg { width: 16px; height: 16px; }

.search-box {
  position: relative;
  margin-bottom: 12px;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-muted);
}

#history-search-input {
  width: 100%;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  padding: 10px 10px 10px 36px;
  color: var(--text-main);
  font-size: 13px;
  transition: all 0.3s ease;
}

#history-search-input:focus {
  outline: none;
  border-color: var(--primary);
  background: rgba(139, 92, 246, 0.05);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.1);
}

.history-status {
  margin: 0 0 12px;
  color: var(--text-muted);
  font-size: 12px;
  text-align: right;
}

.history-scroll-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Custom Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: rgba(0, 0, 0, 0.1); border-radius: 4px; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.2); }

.history-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.history-card {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  padding: 12px;
  display: grid;
  grid-template-columns: 60px 1fr auto;
  gap: 12px;
  align-items: center;
  transition: all 0.2s ease;
}

.history-card:hover {
  background: rgba(139, 92, 246, 0.05);
  border-color: rgba(139, 92, 246, 0.3);
  transform: translateX(-2px);
}

.history-thumb {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: 8px;
  background: #000;
  border: 1px solid var(--border-light);
}

.history-info {
  min-width: 0;
}

.history-meta {
  margin: 0 0 4px;
  color: var(--text-muted);
  font-size: 11px;
  font-family: 'Fira Code', monospace;
}

.history-text {
  margin: 0;
  font-size: 13px;
  color: var(--text-main);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.4;
}

.history-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.small-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-light);
  color: var(--text-main);
  border-radius: 6px;
  padding: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.small-btn svg { width: 14px; height: 14px; }

.small-btn:hover { background: rgba(255, 255, 255, 0.1); }
.small-btn.danger { color: var(--danger); border-color: rgba(239, 68, 68, 0.3); }
.small-btn.danger:hover { background: rgba(239, 68, 68, 0.1); color: var(--danger); border-color: rgba(239, 68, 68, 0.5); }

.history-load-more {
  width: 100%;
  margin-top: auto;
  padding: 12px;
  border-radius: 12px;
  color: var(--primary);
  border: 1px dashed rgba(139, 92, 246, 0.3);
  background: rgba(139, 92, 246, 0.02);
}

.history-load-more:hover {
  background: rgba(139, 92, 246, 0.08);
  border-color: var(--primary);
  color: #fff;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.modal-content {
  position: relative;
  z-index: 1;
  width: min(400px, 90vw);
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: 24px;
  padding: 32px;
  box-shadow: 0 24px 50px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  animation: modalIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.modal-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
  text-align: center;
}

.icon-pulse {
  width: 48px;
  height: 48px;
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(239, 68, 68, 0.3);
  box-shadow: 0 0 20px rgba(239, 68, 68, 0.2);
}

.icon-pulse svg { width: 24px; height: 24px; }

#access-title { margin: 0; font-size: 20px; font-weight: 600; }

.access-hint { margin: 0 0 24px; color: var(--text-muted); font-size: 14px; text-align: center; line-height: 1.5; }

.field { display: flex; flex-direction: column; gap: 8px; }
.field-label { font-size: 13px; font-weight: 500; color: var(--text-muted); }

.input-glow-wrap { position: relative; }

#access-password-input {
  width: 100%;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  padding: 12px 16px;
  color: #fff;
  font-family: inherit;
  transition: all 0.3s ease;
}

#access-password-input:focus {
  outline: none;
  border-color: var(--danger);
  background: rgba(239, 68, 68, 0.05);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.modal-actions { margin-top: 24px; }

.modal-btn {
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
}
.modal-btn:hover:not(:disabled) {
  box-shadow: 0 8px 25px rgba(239, 68, 68, 0.5);
}

/* Toast */
#toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  z-index: 200;
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
  background: rgba(18, 18, 24, 0.9);
  border: 1px solid var(--border-light);
  border-radius: 100px;
  padding: 12px 24px;
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  backdrop-filter: blur(10px);
}
#toast:not(.hidden) {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Responsive */
@media (max-width: 1024px) {
  .layout { grid-template-columns: minmax(0, 1fr) 300px; }
}

@media (max-width: 768px) {
  #app { height: auto; min-height: 100vh; overflow: visible; padding: 16px; }
  body { overflow: auto; }
  .layout { grid-template-columns: 1fr; }
  .left-stack { gap: 16px; }
  .history-panel { min-height: 500px; }
}
