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

:root {
  --bg: #0a0a0f;
  --surface: #14141f;
  --surface-2: #1c1c2e;
  --border: #2a2a40;
  --border-hover: #3a3a55;
  --text: #e8e8f0;
  --text-dim: #8888a0;
  --accent: #7c5cfc;
  --accent-light: #9d82ff;
  --accent-glow: rgba(124, 92, 252, 0.3);
  --green: #34d399;
  --red: #f87171;
  --radius: 12px;
  --radius-sm: 8px;
}

body {
  font-family: 'Space Grotesk', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

/* Animated background grid */
.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(124, 92, 252, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(124, 92, 252, 0.03) 1px, transparent 1px);
  background-size: 60px 60px;
  z-index: 0;
}

/* Floating glow orbs */
.glow {
  position: fixed;
  border-radius: 50%;
  filter: blur(120px);
  opacity: 0.4;
  pointer-events: none;
  z-index: 0;
}

.glow-1 {
  width: 500px;
  height: 500px;
  background: var(--accent);
  top: -200px;
  right: -100px;
  animation: float-1 12s ease-in-out infinite;
}

.glow-2 {
  width: 400px;
  height: 400px;
  background: #5c8cfc;
  bottom: -150px;
  left: -100px;
  animation: float-2 15s ease-in-out infinite;
}

@keyframes float-1 {
  0%, 100% { transform: translate(0, 0); }
  50% { transform: translate(-60px, 40px); }
}

@keyframes float-2 {
  0%, 100% { transform: translate(0, 0); }
  50% { transform: translate(40px, -50px); }
}

/* Main layout */
main {
  position: relative;
  z-index: 1;
  max-width: 720px;
  margin: 0 auto;
  padding: 60px 24px 80px;
}

/* Header */
header {
  text-align: center;
  margin-bottom: 48px;
}

.logo {
  font-size: 3rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 12px;
}

.logo-demo {
  color: var(--text);
}

.logo-giphy {
  background: linear-gradient(135deg, var(--accent), #5c8cfc);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.tagline {
  color: var(--text-dim);
  font-size: 1.1rem;
  font-weight: 400;
}

/* URL Input */
.input-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.url-input-wrapper {
  width: 100%;
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 6px 6px 16px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.url-input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.url-icon {
  color: var(--text-dim);
  flex-shrink: 0;
  display: flex;
}

#urlInput {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  padding: 12px;
}

#urlInput::placeholder {
  color: var(--text-dim);
}

.btn-generate {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 24px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  white-space: nowrap;
}

.btn-generate:hover {
  background: var(--accent-light);
}

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

.btn-generate:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-generate.loading .btn-text { display: none; }
.btn-generate.loading .btn-icon { display: none; }
.btn-generate.loading::after {
  content: '';
  width: 20px;
  height: 20px;
  border: 2.5px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* Toggle Options */
.toggle-options {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: color 0.2s;
}

.toggle-options:hover {
  color: var(--text);
}

.toggle-options .chevron {
  transition: transform 0.3s;
}

.toggle-options.open .chevron {
  transform: rotate(180deg);
}

/* Options Panel */
.options-panel {
  width: 100%;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s;
  opacity: 0;
}

.options-panel.open {
  max-height: 400px;
  opacity: 1;
}

.options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 4px;
}

.option-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-dim);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.option-group select {
  width: 100%;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  outline: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%238888a0' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

.option-group select:focus {
  border-color: var(--accent);
}

.option-group-wide {
  grid-column: 1 / -1;
}

.quality-buttons {
  display: flex;
  gap: 8px;
}

.quality-btn {
  flex: 1;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.quality-btn:hover {
  border-color: var(--border-hover);
}

.quality-btn.active {
  border-color: var(--accent);
  background: rgba(124, 92, 252, 0.1);
}

.quality-label {
  display: block;
  color: var(--text);
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 2px;
}

.quality-desc {
  display: block;
  color: var(--text-dim);
  font-size: 0.75rem;
}

/* Page Sequence */
.page-sequence {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 4px;
}

.sequence-header {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-bottom: 12px;
}

.sequence-hint {
  opacity: 0.6;
}

.sequence-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
}

.sequence-list:empty {
  margin-bottom: 0;
}

.sequence-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.85rem;
}

.sequence-item .seq-number {
  color: var(--accent);
  font-weight: 600;
  font-size: 0.75rem;
  min-width: 20px;
}

.sequence-item .seq-url {
  flex: 1;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sequence-item .seq-remove {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 2px;
  display: flex;
  border-radius: 4px;
  transition: color 0.2s;
}

.sequence-item .seq-remove:hover {
  color: var(--red);
}

.sequence-add-row {
  display: flex;
  gap: 8px;
}

.sequence-input {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  outline: none;
}

.sequence-input:focus {
  border-color: var(--accent);
}

.sequence-input::placeholder {
  color: var(--text-dim);
}

.btn-add-sequence {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.2s;
  white-space: nowrap;
}

.btn-add-sequence:hover {
  border-color: var(--accent);
}

/* Trim Section */
.trim-section {
  margin-bottom: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.trim-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
}

.trim-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Video timeline */
.trim-timeline {
  position: relative;
  width: 100%;
  height: 56px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-2);
}

.timeline-filmstrip {
  display: flex;
  width: 100%;
  height: 100%;
  gap: 0;
}

.timeline-filmstrip img {
  flex: 1;
  min-width: 0;
  height: 100%;
  object-fit: cover;
}

.timeline-filmstrip.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 0.75rem;
}

.timeline-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  pointer-events: none;
}

.timeline-dim {
  background: rgba(0, 0, 0, 0.6);
  transition: width 0.05s;
}

.timeline-selected {
  flex-shrink: 0;
  border-top: 2px solid var(--accent);
  border-bottom: 2px solid var(--accent);
  transition: width 0.05s;
}

.timeline-handle {
  position: absolute;
  top: 0;
  width: 8px;
  height: 100%;
  background: var(--accent);
  pointer-events: none;
  z-index: 2;
}

.timeline-handle::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 20px;
  background: white;
  border-radius: 1px;
}

.timeline-handle-left {
  border-radius: 4px 0 0 4px;
}

.timeline-handle-right {
  border-radius: 0 4px 4px 0;
}

.trim-slider {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  -webkit-appearance: none;
  appearance: none;
  background: none;
  pointer-events: none;
  outline: none;
  z-index: 3;
}

.trim-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 56px;
  background: transparent;
  cursor: ew-resize;
  pointer-events: all;
}

.trim-slider::-webkit-slider-runnable-track {
  height: 56px;
  background: transparent;
}

/* Time row below timeline */
.trim-time-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.trim-time {
  font-size: 0.8rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  min-width: 36px;
}

.trim-time:first-child {
  text-align: left;
}

.trim-time:last-child {
  text-align: right;
}

.trim-duration {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.trim-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.btn-trim {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  color: var(--accent-light);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-trim:hover:not(:disabled) {
  background: rgba(124, 92, 252, 0.15);
}

.btn-trim:disabled {
  opacity: 0.4;
  cursor: default;
}

/* Progress */
.progress-section {
  margin-top: 40px;
  text-align: center;
}

.progress-bar-track {
  width: 100%;
  height: 4px;
  background: var(--surface-2);
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  width: 15%;
  background: linear-gradient(90deg, var(--accent), #5c8cfc);
  border-radius: 4px;
  transition: width 0.3s;
  animation: pulse-bar 2s ease-in-out infinite;
}

@keyframes pulse-bar {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.progress-text {
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-top: 12px;
}

/* Result */
.result-section {
  margin-top: 40px;
}

.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.result-preview {
  background: var(--surface-2);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  min-height: 200px;
}

.result-preview img {
  max-width: 100%;
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.result-info {
  padding: 20px;
}

.result-meta {
  display: flex;
  gap: 24px;
  margin-bottom: 20px;
}

.meta-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.meta-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.meta-value {
  font-size: 1rem;
  font-weight: 600;
}

.result-actions {
  display: flex;
  gap: 12px;
}

.btn-download {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 24px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s;
}

.btn-download:hover {
  background: var(--accent-light);
}

.btn-new {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 24px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.2s;
}

.btn-new:hover {
  border-color: var(--border-hover);
}

/* Error */
.error-section {
  margin-top: 40px;
}

.error-card {
  background: var(--surface);
  border: 1px solid rgba(248, 113, 113, 0.3);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--red);
}

.error-card p {
  color: var(--text-dim);
  font-size: 0.95rem;
}

/* Footer */
.site-footer {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 24px 16px 32px;
  color: var(--text-dim);
  font-size: 0.85rem;
}

.site-footer a {
  color: var(--accent-light);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s;
}

.site-footer a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.site-footer .copyright {
  margin-top: 6px;
  font-size: 0.75rem;
  opacity: 0.6;
}

/* Utilities */
.hidden {
  display: none !important;
}

/* Responsive */
@media (max-width: 600px) {
  main {
    padding: 40px 16px 60px;
  }

  .logo {
    font-size: 2.2rem;
  }

  .tagline {
    font-size: 0.95rem;
  }

  .options-grid {
    grid-template-columns: 1fr;
  }

  .quality-buttons {
    flex-direction: column;
  }

  .result-meta {
    flex-wrap: wrap;
    gap: 12px;
  }

  .result-actions {
    flex-direction: column;
  }

  .btn-generate {
    padding: 12px 16px;
  }
}
