:root {
  --bg: #0d1117;
  --bg-elev: #161b22;
  --bg-elev-2: #1f242d;
  --bg-elev-3: #2a313c;
  --fg: #e6edf3;
  --fg-dim: #8b949e;
  --fg-faint: #586069;
  --accent: #00a2e8;
  --accent-2: #00b8ff;
  --accent-fg: #ffffff;
  --green: #3fb950;
  --amber: #d29922;
  --red: #f85149;
  --border: #30363d;
}

body[data-theme="light"] {
  --bg: #ffffff;
  --bg-elev: #f6f8fa;
  --bg-elev-2: #ebeef2;
  --bg-elev-3: #d8dde3;
  --fg: #1f2328;
  --fg-dim: #59636e;
  --fg-faint: #8b949e;
  --border: #d0d7de;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
body { display: grid; grid-template-rows: auto 1fr; height: 100vh; }
.hidden { display: none !important; }
button { font-family: inherit; font-size: inherit; cursor: pointer; }
input, textarea, select {
  font-family: inherit; font-size: inherit;
  background: var(--bg-elev-2); color: var(--fg);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 8px 10px;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
.muted { color: var(--fg-dim); } .small { font-size: 12px; }

/* Topbar */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 8px 14px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--fg); font-weight: 700; font-size: 15px; }
.brand-mark { width: 28px; height: 28px; display: block; border-radius: 6px; }
.brand-stack { display: inline-flex; flex-direction: column; line-height: 1.05; }
.brand-studio {
  font-weight: 400; font-size: 9.5px; letter-spacing: 0.4px;
  color: var(--fg-faint); text-transform: uppercase; margin-top: 1px;
}
.doc-title { flex: 1; display: flex; align-items: center; gap: 10px; max-width: 480px; }
.doc-title input {
  flex: 1; background: transparent; border: 1px solid transparent;
  padding: 6px 10px; font-weight: 600;
}
.doc-title input:not(:disabled):hover { border-color: var(--border); }
.doc-title input:not(:disabled):focus { background: var(--bg-elev-2); border-color: var(--accent); }
.doc-status { font-size: 12px; color: var(--fg-dim); white-space: nowrap; }
.topbar-right { display: flex; gap: 8px; align-items: center; }

.btn {
  padding: 7px 14px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--bg-elev-2); color: var(--fg);
  font-weight: 500;
  transition: border-color 0.12s, background 0.12s;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.15); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.big { font-size: 15px; padding: 11px 16px; font-weight: 600; }
.btn.small { font-size: 12px; padding: 5px 10px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn.gated { position: relative; }
.btn.gated::after {
  content: ""; position: absolute; top: 5px; right: 5px;
  width: 5px; height: 5px; border-radius: 50%; background: var(--amber);
}
.btn.gated.unlocked::after { display: none; }

.user-menu { position: relative; }
.popover {
  position: absolute; top: calc(100% + 4px); right: 0;
  background: var(--bg-elev-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 4px; min-width: 160px;
  display: flex; flex-direction: column; z-index: 1000;
}
.popover a { padding: 8px 12px; color: var(--fg); text-decoration: none; border-radius: 4px; }
.popover a:hover { background: var(--bg-elev-3); }

/* Main + dropzone */
#main { position: relative; min-height: 0; overflow: hidden; }
.dropzone {
  height: 100%; display: flex; align-items: center; justify-content: center;
  padding: 32px;
}
.dropzone-inner {
  max-width: 520px; width: 100%; text-align: center;
  padding: 48px 32px;
  border: 2px dashed var(--border);
  border-radius: 16px;
  background: var(--bg-elev);
  transition: border-color 0.15s, background 0.15s;
}
.dropzone-inner.drag-active { border-color: var(--accent); background: var(--bg-elev-2); }
.dropzone-icon { font-size: 56px; margin-bottom: 16px; }
.dropzone h1 { margin: 0 0 8px; font-size: 22px; }
.dropzone p { margin: 0 0 16px; color: var(--fg-dim); }
.dropzone-meta { font-size: 12px; color: var(--fg-faint); margin-top: 18px !important; }

/* Workspace: video left, timeline bottom, AI right */
.workspace {
  display: grid;
  grid-template-columns: 1fr 320px;
  grid-template-rows: 1fr auto;
  grid-template-areas:
    "player right"
    "timeline right";
  height: 100%;
  gap: 0;
  min-height: 0;
}
.player-pane {
  grid-area: player;
  background: #000;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  overflow: hidden;
}
.player-pane video { max-width: 100%; max-height: 100%; }
.player-overlay {
  position: absolute; inset: 0;
  pointer-events: none;
}

.timeline-pane {
  grid-area: timeline;
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  padding: 10px 14px;
  display: flex; flex-direction: column; gap: 6px;
  min-height: 180px;
  max-height: 32vh;
  overflow: auto;
}
.timeline-header {
  display: flex; justify-content: space-between; align-items: center;
}
.timeline-actions { display: flex; gap: 6px; }
.timeline {
  position: relative;
  height: 56px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  cursor: crosshair;
}
.timeline-track {
  position: absolute; inset: 8px 8px 8px 8px;
  display: flex;
  background: linear-gradient(90deg, rgba(0, 162, 232, 0.35), rgba(0, 162, 232, 0.18));
  border-radius: 4px;
}
.timeline-cursor {
  position: absolute; top: 0; bottom: 0;
  width: 2px;
  background: var(--accent-2);
  pointer-events: none;
}
.timeline-beats {
  position: absolute; left: 8px; right: 8px; bottom: 2px; height: 6px;
  pointer-events: none;
}
.timeline-beat {
  position: absolute; top: 0; bottom: 0; width: 2px;
  background: var(--amber);
  opacity: 0.7;
}

.cuts-list, .texts-list {
  display: flex; flex-direction: column; gap: 4px; font-size: 12px;
}
.cuts-list .item, .texts-list .item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.cuts-list .item button.del, .texts-list .item button.del {
  margin-left: auto;
  background: transparent; border: none; color: var(--fg-dim);
  padding: 2px 6px; border-radius: 4px;
}
.cuts-list .item button.del:hover, .texts-list .item button.del:hover { color: var(--red); }

/* Right pane: AI cards + export */
.right-pane {
  grid-area: right;
  background: var(--bg-elev);
  border-left: 1px solid var(--border);
  padding: 14px;
  display: flex; flex-direction: column; gap: 14px;
  overflow: auto;
}
.ai-card, .export-card {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}
.ai-card h3 { margin: 0 0 8px; font-size: 13px; font-weight: 700; letter-spacing: 0.02em; }
.ai-card textarea, .ai-card input { width: 100%; resize: vertical; }
.ai-card .muted { font-size: 11.5px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; font-size: 12px; color: var(--fg-dim); }
.hook-results { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.hook-row {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  cursor: pointer;
}
.hook-row:hover { border-color: var(--accent); }

.export-card { margin-top: auto; }

/* Modal */
.modal {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 5000;
}
.modal-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: 100%; max-width: 460px;
  position: relative;
}
.modal-card h2 { margin: 0 0 8px; font-size: 18px; }
.modal-card p { margin: 0 0 12px; color: var(--fg-dim); }
.modal-card input { width: 100%; margin-bottom: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.modal-actions { display: flex; gap: 8px; margin-top: 14px; }
.modal-actions .btn { flex: 1; }
.modal-close {
  position: absolute; top: 8px; right: 8px;
  background: transparent; border: none;
  color: var(--fg-dim); font-size: 22px;
  width: 32px; height: 32px; border-radius: 6px;
}
.modal-close:hover { background: var(--bg-elev-2); color: var(--fg); }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--bg-elev-3); color: var(--fg);
  padding: 10px 16px; border-radius: 8px;
  border: 1px solid var(--border);
  z-index: 6000; font-size: 13px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

@media (max-width: 900px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: 35vh auto auto;
    grid-template-areas:
      "player"
      "timeline"
      "right";
  }
  .right-pane {
    border-left: none;
    border-top: 1px solid var(--border);
    max-height: none;
  }
  .timeline-pane { max-height: 28vh; }
}
