:root {
  --bg: #0d0d0d;
  --bg-elevated: #1a1a1a;
  --bg-card: #222;
  --bg-input: #1a1a1a;
  --text: #f0f0f0;
  --text-secondary: #999;
  --text-muted: #666;
  --accent: #7c5cfc;
  --accent-hover: #6a4de6;
  --accent-soft: rgba(124, 92, 252, 0.15);
  --success: #34d399;
  --danger: #ef4444;
  --warning: #fbbf24;
  --border: #333;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  overflow-x: hidden;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(13, 13, 13, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 6px;
}

.logo {
  font-size: 19px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  letter-spacing: -0.02em;
}

.logo-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  padding: 6px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  transition: background 0.2s;
}

.icon-btn:active {
  background: var(--bg-card);
}

/* Tab Bar */
.tab-bar {
  display: flex;
  padding: 0 16px;
  gap: 24px;
}

.tab {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  padding: 10px 0 14px;
  cursor: pointer;
  position: relative;
  transition: color 0.2s;
}

.tab.active {
  color: var(--text);
}

.tab.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 2px;
  background: var(--accent);
  border-radius: 1px;
}

/* Main Content */
.main-content {
  flex: 1;
  padding: 16px;
  padding-bottom: calc(40px + var(--safe-bottom));
  max-width: 520px;
  margin: 0 auto;
  width: 100%;
}

.tab-panel {
  display: none;
  animation: fadeIn 0.25s ease;
}

.tab-panel.active {
  display: block;
}

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

/* Generate Tab */
.gen-section {
  margin-bottom: 20px;
}

.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.hint {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 12px;
}

/* Prompt Input */
.prompt-wrap {
  position: relative;
}

.prompt-input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 14px;
  font-size: 15px;
  font-family: inherit;
  resize: vertical;
  min-height: 96px;
  transition: border-color 0.2s;
}

.prompt-input:focus {
  outline: none;
  border-color: var(--accent);
}

.prompt-input::placeholder {
  color: var(--text-muted);
}

.prompt-clear {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--bg-card);
  border: none;
  color: var(--text-secondary);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.prompt-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
}

.chip-btn {
  background: var(--accent-soft);
  border: 1px solid transparent;
  color: var(--accent);
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.chip-btn:active {
  transform: scale(0.95);
}

.char-count {
  font-size: 12px;
  color: var(--text-muted);
}

/* Mode Tabs */
.mode-tabs {
  display: flex;
  gap: 8px;
}

.mode-tab {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 10px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.mode-tab.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.mode-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 8px;
  line-height: 1.4;
}

/* Keyframe Upload */
.keyframe-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.keyframe-slot {
  min-height: 130px;
}

.keyframe-drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 18px 10px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.keyframe-drop-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.keyframe-drop-zone .drop-placeholder {
  color: var(--text-muted);
}

.keyframe-drop-zone .drop-placeholder svg {
  margin-bottom: 6px;
  opacity: 0.5;
}

.keyframe-drop-zone .drop-placeholder p {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.keyframe-drop-zone .drop-placeholder small {
  font-size: 11px;
  color: var(--text-muted);
  display: block;
  margin-top: 2px;
}

.keyframe-preview {
  position: relative;
  width: 100%;
  height: 130px;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
}

.keyframe-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.keyframe-preview .upload-status {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0,0,0,0.7);
  color: var(--warning);
  font-size: 11px;
  text-align: center;
  padding: 2px 0;
}

.keyframe-preview .upload-status.done {
  color: var(--success);
}

.keyframe-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(0,0,0,0.7);
  border: none;
  color: #fff;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

/* Image Upload */
.image-drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.image-drop-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.drop-placeholder {
  color: var(--text-muted);
}

.drop-placeholder svg {
  margin-bottom: 8px;
  opacity: 0.5;
}

.drop-placeholder p {
  font-size: 13px;
}

.image-preview-list {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.image-thumb {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  flex-shrink: 0;
}

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

.image-thumb .remove-btn {
  position: absolute;
  top: 2px;
  right: 2px;
  background: rgba(0,0,0,0.7);
  border: none;
  color: #fff;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}

.image-thumb .upload-status {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0,0,0,0.7);
  color: var(--warning);
  font-size: 10px;
  text-align: center;
  padding: 1px 0;
}

.image-thumb .upload-status.done {
  color: var(--success);
}

/* Parameters */
.param-grid {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.param-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.param-name {
  font-size: 14px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.param-control {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  justify-content: flex-end;
}

.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 120px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 6px rgba(124, 92, 252, 0.5);
}

.slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  border: none;
}

.param-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  min-width: 28px;
  text-align: right;
}

.select-control {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
}

.select-control:focus {
  outline: none;
  border-color: var(--accent);
}

/* Generate Button */
.btn-generate {
  width: 100%;
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 14px;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.2s, transform 0.1s;
  margin-bottom: 20px;
}

.btn-generate:active {
  transform: scale(0.98);
}

.btn-generate:disabled {
  background: var(--bg-card);
  color: var(--text-muted);
  cursor: not-allowed;
}

/* Active Tasks */
.active-tasks {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.task-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  animation: slideIn 0.3s ease;
}

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

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

.task-prompt {
  font-size: 13px;
  color: var(--text-secondary);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-right: 8px;
}

.task-status {
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  white-space: nowrap;
}

.task-status.queued {
  background: rgba(251, 191, 36, 0.15);
  color: var(--warning);
}

.task-status.processing {
  background: rgba(124, 92, 252, 0.15);
  color: var(--accent);
}

.task-status.completed {
  background: rgba(52, 211, 153, 0.15);
  color: var(--success);
}

.task-status.failed {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
}

.task-progress-bar {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.task-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.5s ease;
  width: 0%;
}

.task-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-muted);
}

/* History */
.history-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.section-title {
  font-size: 18px;
  font-weight: 700;
}

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

.history-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.2s;
}

.history-card:active {
  border-color: var(--accent);
}

.history-thumb {
  width: 100%;
  aspect-ratio: 16/9;
  background: #000;
  position: relative;
  overflow: hidden;
}

.history-thumb video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.history-thumb .play-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 44px;
  height: 44px;
  background: rgba(0,0,0,0.6);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.history-info {
  padding: 10px 12px;
}

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

.history-meta {
  display: flex;
  gap: 10px;
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-muted);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state svg {
  opacity: 0.3;
  margin-bottom: 12px;
}

.empty-state p {
  font-size: 14px;
}

/* Settings */
.settings-group {
  margin-bottom: 24px;
}

.settings-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.settings-tip {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 10px;
  line-height: 1.5;
}

.text-input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
}

.text-input:focus {
  outline: none;
  border-color: var(--accent);
}

.api-key-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}

.api-key-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
}

.api-key-text {
  font-size: 13px;
  color: var(--text-secondary);
  font-family: monospace;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.api-key-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.api-key-status {
  font-size: 11px;
  color: var(--success);
}

.api-key-del {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 18px;
  padding: 0 4px;
}

.api-key-add {
  display: flex;
  gap: 8px;
}

.api-key-add .text-input {
  flex: 1;
}

.btn-secondary {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-secondary:active {
  transform: scale(0.97);
}

.btn-secondary.full-width {
  width: 100%;
  margin-top: 8px;
}

.text-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 13px;
  cursor: pointer;
  padding: 4px;
}

.text-btn-danger {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 13px;
  cursor: pointer;
  padding: 4px;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.85);
}

.modal-content {
  position: relative;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin: 20px;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: var(--bg-card);
  border: none;
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 22px;
  cursor: pointer;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-player {
  width: 100%;
  border-radius: var(--radius);
  background: #000;
  max-height: 60vh;
}

.player-info {
  margin-top: 14px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.player-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(80px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 14px;
  z-index: 300;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  animation: toastIn 0.3s ease;
  max-width: 90%;
  text-align: center;
}

.toast.error {
  border-color: var(--danger);
  color: var(--danger);
}

.toast.success {
  border-color: var(--success);
  color: var(--success);
}

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 20px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* Loading Overlay */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 250;
  background: rgba(0,0,0,0.8);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-overlay p {
  font-size: 14px;
  color: var(--text-secondary);
}

/* Responsive */
@media (max-width: 380px) {
  .param-item {
    flex-direction: column;
    align-items: stretch;
  }
  .param-control {
    justify-content: flex-start;
  }
}
