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

:root {
  --bg: #f2f2f2;
  --card: #ffffff;
  --border: #e0e0e0;
  --text: #111;
  --text-dim: #999;
  --primary: #111;
  --primary-hover: #333;
  --danger: #888;
  --pill-bg: #ebebeb;
  --shadow: 0 1px 8px rgba(0,0,0,0.05);
  --radius: 14px;
  --pill-radius: 999px;
}

body {
  font-family: 'Inter', -apple-system, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.app { max-width: 600px; margin: 0 auto; padding: 0 12px 80px; }
.page-title {
  font-size: 22px; font-weight: 700; letter-spacing: -0.3px;
  padding: 16px 0 8px;
}

/* Bottom Navigation Bar */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; justify-content: space-around;
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom, 0));
  z-index: 200;
}
.nav-item {
  display: flex; flex-direction: column; align-items: center;
  gap: 3px; padding: 8px 8px 4px; border: none; background: none;
  color: #999; font-size: 10px; font-weight: 500;
  cursor: pointer; transition: color 0.2s;
  font-family: inherit; -webkit-tap-highlight-color: transparent;
}
.nav-item svg { transition: color 0.2s; }
.nav-item.active { color: var(--text); }
.nav-item.active svg { stroke: var(--text); }

/* Header */
.header {
  position: sticky; top: 0; z-index: 100;
  padding: 16px 0 10px;
  background: rgba(242,242,242,0.85);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
}
.logo {
  font-size: 22px; font-weight: 700; letter-spacing: -0.3px;
  color: var(--text); margin-bottom: 10px;
}
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.tab {
  padding: 7px 16px; border: none; border-radius: var(--pill-radius);
  background: var(--pill-bg); color: var(--text-dim);
  font-size: 13px; font-weight: 500; cursor: pointer;
  transition: all 0.2s ease; white-space: nowrap;
  font-family: inherit;
}
.tab:hover { background: #ddd; }
.tab.active {
  background: var(--primary); color: white;
}

/* Cards */
.card {
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: var(--radius);
  padding: 18px; margin-top: 12px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255,255,255,0.5);
  animation: cardIn 0.3s ease;
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.card h2 { font-size: 17px; font-weight: 600; margin-bottom: 14px; }
.card h3 { font-size: 14px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.card h4 { font-size: 13px; font-weight: 500; color: var(--text-dim); margin: 10px 0 4px; }

/* Inputs */
.input-pill {
  width: 100%; padding: 11px 16px; border: 1px solid var(--border);
  border-radius: var(--pill-radius); font-size: 14px;
  outline: none; transition: border-color 0.2s;
  font-family: inherit; background: #fafafa;
}
.input-pill:focus { border-color: #999; }
.input-row { display: flex; gap: 8px; align-items: center; }

/* Buttons */
.btn-pill {
  padding: 9px 20px; border: none; border-radius: var(--pill-radius);
  font-size: 13px; font-weight: 600; cursor: pointer;
  transition: all 0.2s ease; display: inline-flex; align-items: center;
  text-decoration: none; font-family: inherit;
}
.btn-primary {
  background: var(--primary); color: white;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-secondary { background: var(--pill-bg); color: var(--text); }
.btn-secondary:hover { background: #ddd; }
.btn-danger { background: #ddd; color: #666; font-size: 12px; padding: 6px 12px; }
.btn-danger:hover { background: #ccc; }
.btn-row { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

/* Script/Caption */
.script-text, .caption-text {
  background: #f8f8f8; padding: 14px; border-radius: 10px;
  font-size: 13px; line-height: 1.65; white-space: pre-wrap;
  font-family: inherit; max-height: 260px; overflow-y: auto;
  border: 1px solid var(--border);
}

/* Log panel */
.log-panel {
  background: #1a1a1a; border-radius: 10px; padding: 14px;
  font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px;
  color: #8c8; min-height: 60px; max-height: 240px; overflow-y: auto;
}
.log-placeholder { color: #444; }
.log-line { padding: 1px 0; animation: logIn 0.2s ease; }
.log-line.error { color: #e66; }
.log-line.done { color: #6d6; }
@keyframes logIn { from { opacity: 0; } to { opacity: 1; } }

/* Video player */
.video-player { width: 100%; max-height: 400px; border-radius: 10px; background: #000; }

/* Upload */
.upload-area { margin-bottom: 12px; }
.file-input { display: none; }
.upload-btn { display: inline-block; cursor: pointer; }
.upload-progress {
  display: none; align-items: center; gap: 10px;
  margin-top: 8px; padding: 8px 12px;
  background: #f8f8f8; border-radius: 10px; border: 1px solid var(--border);
}
.upload-bar {
  flex: 1; height: 6px; background: var(--border);
  border-radius: 3px; overflow: hidden;
}
.upload-fill {
  height: 100%; background: var(--primary);
  border-radius: 3px; transition: width 0.2s ease;
}
.upload-label {
  font-size: 11px; color: var(--text-dim);
  white-space: nowrap; min-width: 120px;
}

/* Asset list */
.asset-list { display: flex; flex-direction: column; gap: 6px; }
.asset-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; background: #f8f8f8; border-radius: 10px;
  border: 1px solid var(--border);
}
.asset-name { flex: 1; font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.asset-meta { font-size: 11px; color: var(--text-dim); min-width: 30px; }
.asset-play {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--primary); border: none; cursor: pointer;
  color: white; font-size: 11px; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: background 0.2s;
}
.asset-play:hover { background: #333; }

/* Settings */
.setting-group { margin-bottom: 18px; }
.setting-group > label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.slider {
  width: 100%; height: 4px; border-radius: 2px;
  -webkit-appearance: none; background: var(--border);
  outline: none; margin-top: 4px;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 18px; height: 18px;
  border-radius: 50%; background: var(--primary); cursor: pointer;
}
.slider-sm { max-width: 160px; margin-left: 10px; }
.select-pill {
  padding: 9px 16px; border: 1px solid var(--border);
  border-radius: var(--pill-radius); font-size: 13px;
  background: white; outline: none; font-family: inherit;
}
.pill-toggle { display: flex; gap: 6px; flex-wrap: wrap; }
.pill-opt {
  padding: 7px 14px; border: 1px solid var(--border); border-radius: var(--pill-radius);
  background: white; font-size: 12px; cursor: pointer; transition: all 0.2s;
  font-family: inherit;
}
.pill-opt.active { background: var(--primary); color: white; border-color: var(--primary); }
.toggle-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* Toggle switch */
.toggle { position: relative; display: inline-block; width: 44px; height: 26px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; cursor: pointer; inset: 0;
  background: #ccc; border-radius: 26px; transition: 0.25s;
}
.toggle-slider::before {
  content: ''; position: absolute; height: 20px; width: 20px;
  left: 3px; bottom: 3px; background: white; border-radius: 50%; transition: 0.25s;
}
.toggle input:checked + .toggle-slider { background: var(--primary); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }

/* Preview images for settings */
.preview-row { display: flex; gap: 10px; margin-top: 6px; }
.preview-option {
  flex: 1; border: 2px solid var(--border); border-radius: 10px;
  overflow: hidden; cursor: pointer; transition: border-color 0.2s;
  text-align: center; background: #fafafa;
}
.preview-option.active { border-color: var(--text); }
.preview-option img {
  width: 100%; height: auto; display: block;
}
.preview-option span {
  display: block; padding: 6px; font-size: 11px; font-weight: 500;
}
.preview-compare { display: flex; gap: 8px; margin-top: 8px; }
.preview-compare div { flex: 1; text-align: center; }
.preview-compare img { width: 100%; border-radius: 6px; border: 1px solid var(--border); }
.preview-compare span { display: block; font-size: 10px; color: var(--text-dim); margin-top: 3px; }

/* Transition grid */
.transition-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 8px; margin-top: 6px;
}
.trans-card {
  border: 2px solid var(--border); border-radius: 10px;
  overflow: hidden; cursor: pointer; transition: border-color 0.2s;
  text-align: center; background: #fafafa;
}
.trans-card.active { border-color: var(--text); }
.trans-card img {
  width: 100%; height: auto; display: block;
  border-radius: 8px 8px 0 0;
}
.trans-card span {
  display: block; padding: 4px; font-size: 10px; font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.trans-custom-icon {
  display: flex; align-items: center; justify-content: center;
  height: 60px; background: #1a1a1a; color: #666; font-size: 24px;
}

/* Trim controls */
.trim-controls {
  margin-top: 10px; padding: 12px; background: #f8f8f8;
  border-radius: 10px; border: 1px solid var(--border);
  animation: cardIn 0.2s ease;
}
.trim-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px;
}
.trim-title { font-size: 13px; font-weight: 600; }
.trim-range { font-size: 11px; color: var(--text-dim); font-family: monospace; }
.trim-preview { margin-bottom: 8px; }
.trim-slider-row {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px;
}
.trim-slider-row .slider { flex: 1; }

/* Subtitle live preview */
.sub-live-preview {
  background: #1a1a1a; border-radius: 10px; padding: 20px;
  text-align: center; margin-top: 10px; min-height: 80px;
  display: flex; align-items: center; justify-content: center;
}
.sub-live-preview span {
  font-weight: 700; color: white;
  text-shadow: 2px 2px 0 #000, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000;
}

/* Color inputs */
.color-row { display: flex; gap: 16px; }
.color-group { flex: 1; }
.color-group label { display: block; font-size: 12px; margin-bottom: 4px; }
.color-input {
  width: 100%; height: 36px; border: 1px solid var(--border);
  border-radius: 8px; cursor: pointer; padding: 2px;
}

/* Temperature labels */
.temp-labels {
  display: flex; justify-content: space-between;
  font-size: 10px; color: var(--text-dim); margin-top: 2px;
}

/* Save status */
.save-status {
  text-align: center; font-size: 12px; color: var(--text-dim);
  padding: 8px; opacity: 0; transition: opacity 0.3s;
}
.save-status.visible { opacity: 1; }

/* History */
.history-list { display: flex; flex-direction: column; gap: 10px; }
.history-item {
  padding: 14px; background: #f8f8f8; border-radius: 10px;
  border: 1px solid var(--border);
}
.history-topic { font-weight: 600; font-size: 13px; margin-bottom: 3px; }
.history-date { font-size: 11px; color: var(--text-dim); }
.history-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }

/* Panels */
.panel { display: block; }
.panel.hidden { display: none; }

/* Editor */
.editor-preview {
  background: #000; border-radius: 14px; overflow: hidden;
  margin-bottom: 12px; position: relative;
}
.editor-video-player {
  width: 100%; max-height: 50vh; display: block;
  background: #111;
}
.editor-controls {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 14px;
  background: rgba(0,0,0,0.8);
}
.editor-btn {
  width: 36px; height: 36px; border-radius: 50%;
  border: none; background: white; color: #111;
  font-size: 14px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.editor-time { color: #aaa; font-size: 12px; font-family: monospace; }

.editor-sources {
  display: flex; gap: 8px; overflow-x: auto;
  padding: 4px 0; scroll-snap-type: x mandatory;
}
.editor-source-card {
  min-width: 100px; max-width: 100px; border-radius: 8px;
  overflow: hidden; border: 2px solid var(--border);
  cursor: pointer; scroll-snap-align: start;
  transition: border-color 0.2s; flex-shrink: 0;
}
.editor-source-card.active { border-color: var(--text); }
.editor-source-card video {
  width: 100%; height: 140px; object-fit: cover; display: block;
  pointer-events: none;
}
.editor-source-card span {
  display: block; padding: 4px; font-size: 10px;
  text-align: center; background: #f8f8f8;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Timeline */
.timeline-container {
  display: flex; flex-direction: column; gap: 4px;
}
.timeline-track {
  height: 40px; background: #1a1a1a; border-radius: 8px;
  position: relative; overflow: hidden;
  display: flex; align-items: center;
}
.timeline-track.timeline-broll { background: #1a2a1a; }
.timeline-track.timeline-audio { background: #1a1a2a; }
.timeline-label {
  position: absolute; left: 8px; font-size: 10px;
  color: #555; z-index: 1;
}
.timeline-empty {
  color: #444; font-size: 11px; padding: 0 12px;
}
.timeline-clip {
  height: 32px; border-radius: 4px; margin: 4px 2px;
  display: flex; align-items: center; padding: 0 6px;
  font-size: 10px; color: white; cursor: grab;
  min-width: 30px;
}
.timeline-clip.main { background: #555; }
.timeline-clip.broll { background: #3a6a3a; }
.timeline-clip.audio { background: #3a3a6a; }

/* B-roll grid */
.broll-controls { margin-bottom: 12px; }
.broll-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 8px; margin-top: 10px;
}
.broll-card {
  position: relative; border-radius: 8px; overflow: hidden;
  border: 1px solid var(--border); background: #000;
  aspect-ratio: 9/16; cursor: pointer;
}
.broll-card img { width: 100%; height: 100%; object-fit: cover; }
.broll-card video {
  width: 100%; height: 100%; object-fit: cover; display: none;
}
.broll-card:hover video { display: block; }
.broll-card:hover img { display: none; }
.broll-card .broll-del {
  position: absolute; top: 4px; right: 4px;
  width: 22px; height: 22px; border-radius: 50%;
  background: rgba(0,0,0,0.6); border: none;
  color: white; font-size: 12px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity 0.2s;
}
.broll-card:hover .broll-del { opacity: 1; }
.broll-card .broll-dur {
  position: absolute; bottom: 4px; right: 4px;
  background: rgba(0,0,0,0.6); color: white;
  font-size: 10px; padding: 2px 6px; border-radius: 4px;
}
.broll-count { font-size: 12px; color: var(--text-dim); margin-top: 8px; }

/* Transition video preview */
.transition-item { flex-wrap: wrap; }
.transition-video-preview {
  width: 100%; height: 120px; object-fit: cover;
  border-radius: 8px; margin-bottom: 8px;
  background: #111; cursor: pointer;
}

/* Mobile */
@media (max-width: 480px) {
  .input-row { flex-direction: column; }
  .pill-toggle { flex-direction: column; }
  .app { padding: 0 10px 60px; }
  .broll-grid { grid-template-columns: repeat(2, 1fr); }
}
