:root {
  --bg:       #0d0d12;
  --surface:  #16161f;
  --surface2: #1e1e2e;
  --border:   #2a2a3e;
  --primary:  #6c63ff;
  --accent:   #4a9eff;
  --success:  #4caf74;
  --warning:  #f0a030;
  --error:    #e05555;
  --text:     #dde1f0;
  --muted:    #6b7090;
  --radius:   8px;
  --shadow:   0 2px 12px rgba(0,0,0,.4);
}

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

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

/* ── HEADER ─────────────────────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}
.header-brand { font-size: 16px; font-weight: 700; letter-spacing: -.3px; }
.header-actions { display: flex; gap: 8px; }

/* ── LAYOUT ─────────────────────────────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: 260px 1fr 320px;
  flex: 1;
  overflow: hidden;
}

/* ── SIDEBAR ────────────────────────────────────────────────────────────── */
.sidebar {
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--surface);
}

/* ── PREVIEW ────────────────────────────────────────────────────────────── */
.preview-panel {
  border-left: 1px solid var(--border);
  padding: 16px 12px;
  overflow-y: auto;
  background: var(--surface);
}
.preview-placeholder {
  margin-top: 40px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

/* ── MAIN / SECTIONS ────────────────────────────────────────────────────── */
.main {
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.sections-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* ── PANEL ──────────────────────────────────────────────────────────────── */
.panel { display: flex; flex-direction: column; gap: 8px; }
.panel-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--muted);
  margin-bottom: 2px;
}

/* ── SECTION CARD ───────────────────────────────────────────────────────── */
.section-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color .2s;
}
.section-card:has(.section-body:focus-within) {
  border-color: var(--primary);
}

.section-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}
.section-head:hover { background: var(--border); }

.section-title-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  outline: none;
  cursor: text;
}
.section-status {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 500;
}
.status-pending   { background: #2a2a2a; color: var(--muted); }
.status-generating{ background: #1e2a40; color: var(--accent); }
.status-done      { background: #1a2e1a; color: var(--success); }
.status-error     { background: #2e1a1a; color: var(--error); }

.section-body { padding: 12px; display: flex; flex-direction: column; gap: 10px; }

.section-textarea {
  width: 100%;
  min-height: 90px;
  resize: vertical;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
  line-height: 1.5;
  outline: none;
  font-family: inherit;
  transition: border-color .2s;
}
.section-textarea:focus { border-color: var(--primary); }

/* bottom toolbar of section */
.section-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.section-toolbar .voice-pick {
  flex: 1;
  min-width: 140px;
}

/* voice settings inline */
.voice-settings {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  background: var(--bg);
  border-radius: 6px;
  border: 1px solid var(--border);
}
.voice-settings label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}
.voice-settings label span { min-width: 40px; text-align: right; color: var(--text); }
.voice-settings input[type=range] { flex: 1; accent-color: var(--primary); cursor: pointer; }

/* section sub-panels */
.sub-panel {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sub-panel-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .6px;
}

/* image thumbnail */
.image-thumb {
  width: 100%;
  aspect-ratio: 3/4;
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface2);
  border: 1px dashed var(--border);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 12px;
  transition: border-color .2s;
}
.image-thumb:hover { border-color: var(--accent); }
.image-thumb img { width: 100%; height: 100%; object-fit: cover; }
.image-thumb.small { aspect-ratio: 1; width: 64px; flex-shrink: 0; }

/* progress bar */
.progress-bar {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--primary);
  transition: width .3s;
  animation: pulse 1.5s infinite;
}
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.5} }

/* ── OVERLAY MODAL ──────────────────────────────────────────────────────── */
#overlay-canvas-wrap {
  position: relative;
  display: inline-block;
  max-width: 100%;
  border-radius: 6px;
  overflow: hidden;
  background: #111;
}
#ov-main {
  display: block;
  max-width: 520px;
  width: 100%;
  height: auto;
  user-select: none;
  -webkit-user-drag: none;
}
#ov-elem {
  position: absolute;
  cursor: move;
  border: 2px dashed rgba(100,160,255,.8);
  border-radius: 3px;
  display: none;
}
#ov-elem:hover { border-color: var(--accent); }
#ov-img {
  width: 100%; height: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
  user-select: none;
}
.ov-handle {
  position: absolute; width: 14px; height: 14px;
  background: white; border: 2px solid var(--accent);
  border-radius: 50%; z-index: 10;
  box-shadow: 0 1px 4px rgba(0,0,0,.4);
}
.ov-handle.tl { top:-7px; left:-7px; cursor:nw-resize; }
.ov-handle.tr { top:-7px; right:-7px; cursor:ne-resize; }
.ov-handle.bl { bottom:-7px; left:-7px; cursor:sw-resize; }
.ov-handle.br { bottom:-7px; right:-7px; cursor:se-resize; }

/* ── LIBRARY MODAL ──────────────────────────────────────────────────────── */
.library-upload {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  max-height: 55vh;
  overflow-y: auto;
}
.lib-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: border-color .15s, transform .15s;
}
.lib-card:hover { border-color: var(--accent); transform: scale(1.02); }
.lib-card img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.lib-card-info { padding: 6px 8px; }
.lib-card-name { font-size: 11px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-card-date { font-size: 10px; color: var(--muted); margin-top: 1px; }
.lib-card-del {
  width: 100%; padding: 4px;
  background: transparent;
  border: none; border-top: 1px solid var(--border);
  color: var(--error); cursor: pointer; font-size: 11px;
}
.lib-card-del:hover { background: var(--error); color: white; }

/* ── MODALS ─────────────────────────────────────────────────────────────── */
.modal {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.7);
  z-index: 100;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}
.modal.open { display: flex; }
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  width: 600px;
  max-width: 95vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
.modal-wide { width: 800px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 14px;
}
.modal-close {
  background: none; border: none;
  color: var(--muted); cursor: pointer; font-size: 16px; line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
}

/* ── BUTTONS ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 6px 14px;
  border-radius: 6px;
  border: none;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity .15s, background .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary  { background: var(--primary); color: white; }
.btn-success  { background: var(--success); color: white; }
.btn-secondary{ background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost    { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-danger   { background: transparent; color: var(--error); border: 1px solid var(--error); }
.btn-icon     { padding: 5px 8px; }
.btn:not(:disabled):hover { opacity: .85; }
.btn-play { background: var(--accent); color: white; }

/* ── FORMS ──────────────────────────────────────────────────────────────── */
.select, .input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 6px 10px;
  font-size: 12px;
  outline: none;
  width: 100%;
  transition: border-color .2s;
}
.select:focus, .input:focus { border-color: var(--primary); }
.select option { background: var(--bg); }

/* ── MISC ───────────────────────────────────────────────────────────────── */
.muted  { color: var(--muted); font-size: 11px; }
.hint   { text-align: center; font-size: 11px; color: var(--muted); margin-top: 8px; }
.toggle { accent-color: var(--primary); width: 15px; height: 15px; cursor: pointer; }
.audio-player { width: 100%; border-radius: 6px; margin-top: 4px; }

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