:root {
  --bg: #0c0e14;
  --panel: #141824;
  --panel-2: #1b2132;
  --border: #262f45;
  --text: #eef2ff;
  --muted: #94a3b8;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --accent: #22d3ee;
  --speech: #38bdf8;
  --broll: #a855f7;
  --beat: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding-top: var(--safe-top);
}

/* Topbar */
.topbar {
  height: 54px;
  padding: 0 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.brand-logo {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: linear-gradient(135deg, #6366f1, #22d3ee);
  display: grid;
  place-items: center;
  font-weight: 800;
  color: #fff;
  font-size: 14px;
  flex-shrink: 0;
}

.brand h1 {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.15;
}

.brand-sub {
  font-size: 10px;
  color: var(--muted);
  display: block;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.aspect-toggle {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
}

.aspect-btn {
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

.aspect-btn.active {
  background: var(--panel-2);
  color: var(--text);
}

/* Buttons */
.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  touch-action: manipulation;
}

.btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:active:not(:disabled),
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-compact {
  padding: 7px 10px;
  font-size: 12px;
  border-radius: 8px;
}

.btn-sm {
  padding: 8px 10px;
  font-size: 12px;
  border-radius: 8px;
}

.btn-block {
  width: 100%;
}

/* ========== MOBILE-FIRST LAYOUT (Default <= 900px) ========== */
.workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.stage-area {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  background: var(--bg);
}

.preview-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 12px 6px;
  gap: 8px;
}

.canvas-frame {
  position: relative;
  background: #05060a;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.canvas-frame.ratio-9-16 {
  aspect-ratio: 9 / 16;
  height: min(30dvh, 250px);
}

.canvas-frame.ratio-16-9 {
  aspect-ratio: 16 / 9;
  width: min(100%, 400px);
  max-height: 28dvh;
}

#previewCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.preview-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(10, 12, 18, 0.72);
  padding: 12px;
  pointer-events: none;
}

.preview-overlay.hidden {
  display: none;
}

.overlay-msg {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  padding: 8px 14px;
  border-radius: 99px;
  background: rgba(20, 24, 36, 0.92);
  border: 1px solid var(--border);
}

/* Transport */
.transport-bar {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 10px;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: none;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font-size: 13px;
  flex-shrink: 0;
}

.icon-btn:disabled {
  opacity: 0.4;
}

.timecode {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: var(--text);
  white-space: nowrap;
}

#seekSlider {
  flex: 1;
  min-width: 60px;
  accent-color: var(--primary);
  height: 24px;
}

.status-pill {
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 99px;
  background: var(--panel-2);
  color: var(--accent);
  white-space: nowrap;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Timeline */
.timeline-panel {
  height: 92px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 6px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
}

.timeline-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
}

.timeline-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  min-width: 0;
}

.timeline-meta {
  color: var(--muted);
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.timeline-legend {
  display: flex;
  gap: 8px;
  color: var(--muted);
  font-size: 10px;
  flex-shrink: 0;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
}
.dot-speech { background: var(--speech); }
.dot-broll { background: var(--broll); }
.dot-beat { background: var(--beat); }
.dot-sfx { background: #34d399; }

.timeline-canvas-wrap {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  touch-action: none;
}

#timelineCanvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: pointer;
}

/* Mobile Drawer Panes */
.panel {
  background: var(--panel);
  padding: 12px 14px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.mobile-pane {
  display: none;
  flex: 1;
  min-height: 0;
}

.mobile-pane.active {
  display: flex;
}

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

.panel-header h2 {
  font-size: 14px;
  font-weight: 700;
}

.badge {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 99px;
  background: var(--panel-2);
  color: var(--muted);
}

.badge-accent {
  color: var(--accent);
}

/* Dropzone */
.dropzone {
  border: 1.5px dashed var(--primary);
  border-radius: var(--radius);
  padding: 16px 12px;
  text-align: center;
  cursor: pointer;
  background: rgba(99, 102, 241, 0.08);
  transition: 0.15s;
}

.dropzone.dragover {
  background: rgba(99, 102, 241, 0.2);
}

.dropzone-sm {
  padding: 14px 12px;
}

.dropzone-icon {
  font-size: 24px;
  margin-bottom: 4px;
}

.dropzone-title {
  font-size: 13px;
  font-weight: 700;
}

.dropzone-hint {
  font-size: 11px;
  color: var(--muted);
  margin-top: 3px;
}

/* Clip List */
.clip-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.clip-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.clip-thumb {
  width: 60px;
  height: 40px;
  border-radius: 6px;
  object-fit: cover;
  background: #000;
  flex-shrink: 0;
}

.clip-info {
  flex: 1;
  min-width: 0;
}

.clip-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.clip-meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.clip-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.clip-action-btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}

.clip-action-btn.danger {
  color: #f87171;
}

.empty-hint {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  padding: 16px 8px;
}

/* Auto-BGM Banner & Style Cards */
.ai-bgm-banner {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.16), rgba(34, 211, 238, 0.1));
  border: 1px solid rgba(99, 102, 241, 0.45);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ai-bgm-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.ai-bgm-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
}

.ai-bgm-reason {
  font-size: 11px;
  color: #cbd5e1;
  line-height: 1.45;
}

.music-style-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.music-card {
  background: var(--panel-2);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 9px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
  transition: 0.15s;
  text-align: left;
}

.music-card.active {
  border-color: var(--accent);
  background: rgba(34, 211, 238, 0.12);
}

.music-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.music-card-name {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
}

.music-card-tag {
  font-size: 10px;
  color: var(--accent);
}

.music-card-meta {
  font-size: 10px;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.music-play-btn {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 10px;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
}

.music-play-btn.playing {
  background: var(--accent);
  color: #0b0e14;
  border-color: var(--accent);
}

/* Draft Auto-Save Bar & Draft Box Modal */
.draft-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(34, 211, 238, 0.08);
  border: 1px solid rgba(34, 211, 238, 0.25);
}

.draft-status {
  font-size: 11px;
  color: #bae6fd;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.draft-bar-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.btn-chip {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.btn-chip-danger {
  color: #fca5a5;
}

.modal-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.draft-save-row {
  display: flex;
  gap: 8px;
}

.draft-save-row input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
}

.draft-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 36dvh;
  overflow-y: auto;
}

.draft-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.draft-item-thumb {
  width: 52px;
  height: 38px;
  border-radius: 6px;
  object-fit: cover;
  background: #05060a;
  flex-shrink: 0;
}

.draft-item-info {
  flex: 1;
  min-width: 0;
}

.draft-item-name {
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.draft-item-meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.draft-item-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* Funny SFX Soundboard & Event List */
.badge-sfx {
  color: #34d399;
}

.sfx-pad-hint {
  font-size: 11px;
  color: var(--muted);
}

.sfx-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.sfx-pad {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  cursor: pointer;
  transition: 0.12s;
}

.sfx-pad:active {
  transform: scale(0.97);
  border-color: #34d399;
}

.sfx-pad-left {
  min-width: 0;
}

.sfx-pad-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
}

.sfx-pad-desc {
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sfx-add-btn {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 1px solid rgba(52, 211, 153, 0.45);
  background: rgba(52, 211, 153, 0.14);
  color: #34d399;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}

.sfx-event-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sfx-event-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 12px;
}

.sfx-event-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  cursor: pointer;
}

.sfx-event-time {
  font-family: ui-monospace, monospace;
  font-size: 11px;
  color: #34d399;
}

.sfx-event-label {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sfx-event-reason {
  font-size: 10px;
  color: var(--muted);
}

/* Auto Copywriting & Douyin Post Box */
.hook-edit-box {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 11px;
  color: var(--muted);
}

.hook-edit-box input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: #fde68a;
  font-weight: 700;
  padding: 8px 10px;
  font-size: 13px;
}

.post-copy-card {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.14), rgba(168, 85, 247, 0.1));
  border: 1px solid rgba(168, 85, 247, 0.35);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.post-copy-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
}

.post-copy-card textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: #e2e8f0;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.5;
  resize: vertical;
  font-family: inherit;
}

.hook-edit-box input.en-input,
.sub-item input.sub-en-input {
  color: #bae6fd;
  font-weight: 500;
  font-size: 12px;
}

.gemini-box {
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.1), rgba(99, 102, 241, 0.14));
  border: 1px solid rgba(34, 211, 238, 0.35);
  border-radius: 12px;
  padding: 10px 12px;
}

.gemini-box summary {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  cursor: pointer;
  list-style: none;
}

.gemini-body {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.gemini-status {
  font-size: 11px;
  color: #a5f3fc;
  line-height: 1.4;
}

/* Settings */
.setting-group {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
}

.switch-row input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: var(--primary);
  flex-shrink: 0;
}

.setting-name {
  font-size: 13px;
  font-weight: 600;
}

.setting-desc {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.slider-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.slider-row input {
  width: 100%;
  accent-color: var(--primary);
  height: 24px;
}

.select-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
}

.select-row select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
}

/* Subtitles */
.sub-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.sub-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sub-item {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sub-item-head {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--accent);
  font-family: ui-monospace, monospace;
}

.sub-item input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 9px 10px;
  font-size: 14px;
}

/* Mobile Bottom Tab Bar */
.mobile-tabbar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  flex-shrink: 0;
}

.m-tab {
  height: 54px;
  background: transparent;
  border: none;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.m-tab-icon {
  font-size: 18px;
  line-height: 1;
}

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

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 100;
}

.modal.hidden,
.hidden {
  display: none !important;
}

.modal-card {
  width: min(100%, 400px);
  max-height: 90dvh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-desc {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
  margin-top: 6px;
}

.progress-bar {
  height: 10px;
  background: var(--bg);
  border-radius: 99px;
  overflow: hidden;
  margin: 14px 0;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #6366f1, #22d3ee);
  transition: width 0.2s;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
}

.exported-video {
  width: 100%;
  max-height: 45dvh;
  border-radius: 10px;
  background: #000;
  margin: 10px 0;
}

.export-done-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ========== DESKTOP / TABLET LAYOUT (> 900px) ========== */
@media (min-width: 901px) {
  .topbar {
    height: 60px;
    padding: 0 20px;
  }

  .brand-sub {
    font-size: 11px;
  }

  .mobile-tabbar,
  .mobile-only-cta {
    display: none !important;
  }

  .workspace {
    display: grid;
    grid-template-columns: 300px 1fr 320px;
    grid-template-rows: 1fr 1fr;
    grid-template-areas:
      "media stage settings"
      "bgm   stage subtitles";
  }

  .stage-area {
    grid-area: stage;
    min-height: 0;
  }

  .preview-wrapper {
    flex: 1;
    justify-content: center;
    padding: 16px 20px 10px;
    min-height: 0;
  }

  .canvas-frame.ratio-16-9 {
    width: min(100%, 740px);
    max-height: calc(100% - 54px);
  }

  .canvas-frame.ratio-9-16 {
    height: min(100%, 480px);
  }

  .transport-bar {
    max-width: 740px;
  }

  .timeline-panel {
    height: 160px;
    padding: 10px 16px;
  }

  .mobile-pane {
    display: flex !important;
    border-right: 1px solid var(--border);
  }

  .panel-media {
    grid-area: media;
    border-bottom: 1px solid var(--border);
  }

  .panel-bgm {
    grid-area: bgm;
  }

  .panel-settings {
    grid-area: settings;
    border-right: none;
    border-left: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
  }

  .panel-subtitles {
    grid-area: subtitles;
    border-right: none;
    border-left: 1px solid var(--border);
  }
}
