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

:root {
  --bg: #0a0b10;
  --surface: #12131a;
  --surface2: #1a1b24;
  --border: #2a2b36;
  --text: #e4e4ef;
  --text2: #8888a0;
  --accent: #6c5ce7;
  --accent2: #a29bfe;
  --danger: #ff4757;
  --success: #2ed573;
  --radius: 10px;
}

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

/* HEADER */
header {
  padding: 1.2rem 2rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.header-content h1 {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.subtitle {
  color: var(--text2);
  font-size: 0.85rem;
  margin-top: 0.2rem;
}

/* MAIN LAYOUT */
main {
  display: flex;
  flex: 1;
  gap: 0;
  overflow: hidden;
}
.panel {
  padding: 1.5rem;
  overflow-y: auto;
}
.panel-left {
  width: 420px;
  min-width: 420px;
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.panel-right {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* SECTIONS */
.section h2 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 0.7rem;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* TEXTAREA */
textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0.8rem;
  font-size: 0.92rem;
  font-family: inherit;
  resize: vertical;
  line-height: 1.5;
  transition: border-color 0.2s;
}
textarea:focus {
  outline: none;
  border-color: var(--accent);
}
textarea::placeholder {
  color: var(--text2);
  opacity: 0.7;
}

/* PARAMS */
.params-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.7rem;
}
.param label {
  display: block;
  font-size: 0.8rem;
  color: var(--text2);
  margin-bottom: 0.3rem;
}
.param input, .param select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 0.5rem 0.6rem;
  font-size: 0.88rem;
  font-family: inherit;
}
.param input:focus, .param select:focus {
  outline: none;
  border-color: var(--accent);
}
.param select { cursor: pointer; }
.param input[type="color"] {
  height: 38px;
  padding: 2px 4px;
  cursor: pointer;
}
.custom-res-inputs {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.custom-res-inputs span {
  color: var(--text2);
}
.custom-res-inputs input {
  flex: 1;
}
.custom-res {
  grid-column: 1 / -1;
}

/* BUTTONS */
.btn-primary {
  width: 100%;
  padding: 0.85rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: background 0.2s, transform 0.1s;
}
.btn-primary:hover { background: #5b4bd5; }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled {
  background: var(--border);
  cursor: not-allowed;
  color: var(--text2);
}
.btn-primary.loading .btn-text::after {
  content: '';
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid #fff4;
  border-top-color: #fff;
  border-radius: 50%;
  margin-left: 8px;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
}

.btn-secondary {
  padding: 0.45rem 0.8rem;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.82rem;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  transition: background 0.2s;
}
.btn-secondary:hover { background: var(--border); }
.btn-secondary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-accent {
  padding: 0.55rem 1rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.88rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  transition: background 0.2s;
  white-space: nowrap;
}
.btn-accent:hover { background: #5b4bd5; }
.btn-accent:disabled {
  background: var(--border);
  cursor: not-allowed;
  color: var(--text2);
}

.btn-icon-only {
  width: 34px;
  height: 34px;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
.btn-icon-only:hover { background: var(--border); }
.btn-icon-only:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-small {
  padding: 0.2rem 0.6rem;
  background: transparent;
  color: var(--text2);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.72rem;
  font-family: inherit;
  cursor: pointer;
}
.btn-small:hover { color: var(--danger); border-color: var(--danger); }

.btn-remove {
  color: var(--danger) !important;
  border-color: var(--danger) !important;
  font-size: 0.9rem;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: rgba(255, 71, 87, 0.1);
}
.btn-remove:hover {
  background: rgba(255, 71, 87, 0.25) !important;
}

.btn-danger {
  padding: 0.6rem 1.2rem;
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.btn-danger:hover { background: #e8414f; }

/* TEMPLATES */
.templates {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.template-btn {
  padding: 0.4rem 0.7rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.template-btn:hover {
  border-color: var(--accent);
  background: var(--surface2);
}

/* UPLOAD AREA */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  overflow: hidden;
}
.upload-area:hover, .upload-area.drag-over {
  border-color: var(--accent);
  background: rgba(108, 92, 231, 0.05);
}
.upload-placeholder {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.8rem;
  color: var(--text2);
  font-size: 0.82rem;
}
.upload-icon {
  font-size: 1.2rem;
}
.upload-preview {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  background: var(--bg);
}
.upload-preview img,
.upload-preview video {
  max-width: 100%;
  max-height: 120px;
  border-radius: 6px;
  object-fit: contain;
}
.upload-preview .btn-remove {
  position: absolute;
  top: 6px;
  right: 6px;
}

/* HISTORY */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 200px;
  overflow-y: auto;
}
.history-item {
  padding: 0.5rem 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: border-color 0.2s;
}
.history-item:hover {
  border-color: var(--accent);
}

/* PREVIEW */
.preview-section {
  flex: 1;
  display: flex;
  flex-direction: column;
}
.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.7rem;
}
.preview-header h2 { margin-bottom: 0; }
.preview-controls {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.preview-wrapper {
  flex: 1;
  position: relative;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 300px;
  background-image:
    linear-gradient(45deg, #1a1b24 25%, transparent 25%),
    linear-gradient(-45deg, #1a1b24 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1a1b24 75%),
    linear-gradient(-45deg, transparent 75%, #1a1b24 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

#previewFrame {
  width: 100%;
  height: 100%;
  border: none;
  position: absolute;
  top: 0;
  left: 0;
}

.preview-placeholder, .preview-loading {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  z-index: 2;
}
.placeholder-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}
.preview-placeholder p, .preview-loading p {
  color: var(--text2);
  font-size: 0.9rem;
}
.loading-hint {
  font-size: 0.78rem !important;
  margin-top: 0.3rem;
  opacity: 0.6;
}

.preview-info {
  display: flex;
  gap: 1rem;
  padding: 0.5rem 0;
  font-size: 0.78rem;
  color: var(--text2);
}
.preview-info span::before {
  content: '•';
  margin-right: 0.3rem;
  opacity: 0.5;
}
.preview-info span:first-child::before { display: none; }

/* EDIT SECTION */
.edit-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}
.edit-row {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
}
.edit-row textarea {
  flex: 1;
  min-height: 40px;
  padding: 0.55rem 0.7rem;
  font-size: 0.88rem;
}

/* EXPORT SECTION */
.export-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

/* STYLE LOCK */
.style-lock-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.btn-style-lock, .btn-style-unlock {
  font-size: 0.84rem;
}
.btn-style-unlock {
  color: var(--danger);
  border-color: var(--danger);
}
.btn-style-unlock:hover {
  background: rgba(255, 71, 87, 0.1);
}
.style-lock-hint {
  margin-top: 0.4rem;
  font-size: 0.75rem;
  color: var(--text2);
  opacity: 0.7;
}
.style-lock-active {
  margin-top: 0.5rem;
}
.style-lock-badge {
  display: inline-block;
  padding: 0.25rem 0.6rem;
  background: rgba(108, 92, 231, 0.15);
  border: 1px solid var(--accent);
  border-radius: 4px;
  font-size: 0.8rem;
  color: var(--accent2);
  font-weight: 600;
}
.style-lock-active details {
  margin-top: 0.4rem;
}
.style-lock-active details summary {
  font-size: 0.78rem;
  color: var(--text2);
  cursor: pointer;
  padding: 0.3rem 0;
}
.style-description {
  font-size: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem;
  max-height: 150px;
  overflow-y: auto;
  white-space: pre-wrap;
  color: var(--text2);
}
.export-row {
  display: flex;
  gap: 0.6rem;
  align-items: center;
}
.export-row select {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 0.5rem 0.6rem;
  font-size: 0.88rem;
  font-family: inherit;
  cursor: pointer;
}
.export-row select:focus {
  outline: none;
  border-color: var(--accent);
}
.btn-export {
  white-space: nowrap;
}
.export-hint {
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: var(--text2);
  opacity: 0.7;
}
.export-progress {
  margin-top: 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.export-progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
  color: var(--accent2);
}
.export-eta {
  font-size: 0.75rem;
  color: var(--text2);
}
.progress-bar-track {
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 3px;
  transition: width 0.4s ease;
}
.progress-text {
  font-size: 0.72rem;
  color: var(--text2);
  text-align: right;
}
.spinner-sm {
  width: 18px;
  height: 18px;
  border-width: 2px;
  margin-bottom: 0;
}

/* RECORDING */
.recording-overlay {
  position: absolute;
  top: 0; left: 0; right: 0;
  padding: 0.7rem 1rem;
  background: rgba(255, 71, 87, 0.15);
  border-bottom: 1px solid var(--danger);
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 10;
}
.recording-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  font-weight: 600;
}

.rec-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  background: var(--danger);
  border-radius: 50%;
}
.rec-dot-active {
  animation: pulse-rec 1s ease infinite;
}

/* CODE */
details summary {
  cursor: pointer;
  color: var(--text2);
  font-size: 0.85rem;
  padding: 0.5rem 0;
}
details summary:hover { color: var(--accent2); }
pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  overflow-x: auto;
  max-height: 300px;
}
code {
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 0.78rem;
  color: var(--text);
  white-space: pre;
}

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

/* FOOTER */
footer {
  padding: 0.8rem 2rem;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 0.78rem;
  color: var(--text2);
  background: var(--surface);
}

/* ANIMATIONS */
@keyframes spin {
  to { transform: rotate(360deg); }
}
@keyframes pulse-rec {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* SCROLLBAR */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text2); }

/* RESPONSIVE */
@media (max-width: 900px) {
  main {
    flex-direction: column;
  }
  .panel-left {
    width: 100%;
    min-width: 0;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 50vh;
  }
  .panel-right {
    min-height: 400px;
  }
}
