/* ── Reset & Base ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --c-bg:        #0b0b0f;
  --c-surface:   #131318;
  --c-elevated:  #1a1a22;
  --c-hover:     #21212c;
  --c-border:    rgba(255,255,255,0.07);
  --c-border-hi: rgba(255,255,255,0.13);

  --c-text:   #e2e2ef;
  --c-text-2: #80809a;
  --c-text-3: #48485e;

  --c-accent:      #7c6af7;
  --c-accent-h:    #9078ff;
  --c-accent-glow: rgba(124,106,247,0.18);

  --c-hook:   #f59e0b;
  --c-film-1: #818cf8;
  --c-film-2: #a78bfa;
  --c-film-3: #c084fc;
  --c-meta:   #38bdf8;

  --c-success: #22c55e;
  --c-danger:  #ef4444;
  --c-warning: #f59e0b;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 20px;

  --header-h: 54px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
}

html { font-size: 14px; }
body {
  font-family: var(--font);
  background: var(--c-bg);
  color: var(--c-text);
  min-height: 100vh;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ──────────────────────────────────────────────────── */
.header {
  height: var(--header-h);
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { font-size: 22px; }
.brand-name { font-size: 18px; font-weight: 700; letter-spacing: -0.3px; }
.header-nav { display: flex; gap: 4px; }
.nav-btn {
  background: none; border: none; color: var(--c-text-2);
  padding: 6px 14px; border-radius: var(--r-md);
  font-size: 13px; font-weight: 500; cursor: pointer; transition: all .15s;
}
.nav-btn:hover { background: var(--c-hover); color: var(--c-text); }
.nav-btn.active { background: var(--c-accent-glow); color: var(--c-accent); }

/* ── Page layout ─────────────────────────────────────────────── */
.page {
  max-width: 980px;
  margin: 0 auto;
  padding: 0 24px 60px;
}

/* ── Search section ──────────────────────────────────────────── */
.search-wrap {
  padding: 52px 0 40px;
  display: flex;
  justify-content: center;
}
.search-wrap.compact {
  padding: 24px 0 28px;
}
.search-box {
  display: flex;
  gap: 10px;
  width: 100%;
  max-width: 640px;
}
.search-input {
  flex: 1;
  background: var(--c-surface);
  border: 1px solid var(--c-border-hi);
  border-radius: var(--r-lg);
  color: var(--c-text);
  font-family: var(--font);
  font-size: 15px;
  padding: 11px 16px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.search-input::placeholder { color: var(--c-text-3); }
.search-input:focus {
  border-color: var(--c-accent);
  box-shadow: 0 0 0 3px var(--c-accent-glow);
}

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; border-radius: var(--r-md); font-family: var(--font);
  font-size: 13px; font-weight: 500; padding: 8px 16px;
  cursor: pointer; transition: all .15s; white-space: nowrap;
}
.btn:disabled { opacity: .4; cursor: default; }
.btn-lg { padding: 11px 24px; font-size: 14.5px; border-radius: var(--r-lg); }
.w-full { width: 100%; }

.btn-primary { background: var(--c-accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--c-accent-h); }

.btn-accent {
  background: linear-gradient(135deg, #7c6af7, #a78bfa);
  color: #fff;
  box-shadow: 0 2px 12px rgba(124,106,247,0.3);
}
.btn-accent:hover:not(:disabled) {
  background: linear-gradient(135deg, #9078ff, #b99aff);
  box-shadow: 0 4px 18px rgba(124,106,247,0.4);
  transform: translateY(-1px);
}
.btn-success { background: #16a34a; color: #fff; }
.btn-success:hover:not(:disabled) { background: #15803d; }
.btn-ghost {
  background: var(--c-elevated); color: var(--c-text-2);
  border: 1px solid var(--c-border-hi);
}
.btn-ghost:hover:not(:disabled) { background: var(--c-hover); color: var(--c-text); }
.btn-danger { background: #dc2626; color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }

.icon-btn {
  background: none; border: none; color: var(--c-text-3);
  cursor: pointer; padding: 4px 8px; border-radius: var(--r-sm);
  font-size: 15px; transition: color .15s;
}
.icon-btn:hover { color: var(--c-text); }

.copy-btn {
  background: none;
  border: 1px solid var(--c-border-hi);
  color: var(--c-text-3);
  cursor: pointer;
  padding: 3px 10px;
  border-radius: var(--r-sm);
  font-size: 11.5px;
  font-family: var(--font);
  transition: all .15s;
}
.copy-btn:hover { color: var(--c-text); background: var(--c-hover); }
.copy-btn.copied { color: var(--c-success); border-color: var(--c-success); }

/* ── Movie grid ───────────────────────────────────────────────── */
.movie-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 18px;
}

.movie-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-xl);
  overflow: hidden;
  transition: border-color .2s, transform .2s;
  animation: fadeSlideIn .35s ease forwards;
  opacity: 0;
}
.movie-card:nth-child(1) { animation-delay: .05s; }
.movie-card:nth-child(2) { animation-delay: .12s; }
.movie-card:nth-child(3) { animation-delay: .19s; }
.movie-card:hover { border-color: var(--c-border-hi); transform: translateY(-3px); }

.movie-poster-wrap {
  position: relative;
  aspect-ratio: 2/3;
  background: var(--c-elevated);
  overflow: hidden;
}
.movie-poster {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  transition: transform .3s;
}
.movie-card:hover .movie-poster { transform: scale(1.04); }
.movie-poster-placeholder {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  font-size: 48px; opacity: .3;
}
.movie-index-badge {
  position: absolute;
  top: 10px; left: 10px;
  background: rgba(0,0,0,.7);
  backdrop-filter: blur(4px);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
}
.movie-replace-wrap {
  position: absolute;
  top: 10px; right: 10px;
}
.movie-replace-btn {
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255,255,255,.15);
  color: #fff;
  border-radius: 8px;
  cursor: pointer;
  padding: 5px 10px;
  font-size: 15px;
  line-height: 1;
  transition: all .15s;
}
.movie-replace-btn:hover { background: rgba(124,106,247,.7); border-color: var(--c-accent); }
.movie-replace-btn.loading { opacity: .5; cursor: default; }

.movie-card-body { padding: 14px 16px; }
.movie-title {
  font-size: 14.5px; font-weight: 700;
  color: var(--c-text);
  margin-bottom: 3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.movie-title-en {
  font-size: 12px; color: var(--c-text-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-bottom: 10px;
}
.movie-card-footer {
  display: flex; align-items: center; justify-content: space-between;
}
.movie-rating { font-size: 14px; font-weight: 700; color: var(--c-warning, #f59e0b); }
.movie-year { font-size: 12px; color: var(--c-text-3); margin-left: 6px; }
.kp-link {
  font-size: 12px; color: var(--c-accent);
  text-decoration: none;
  border: 1px solid rgba(124,106,247,.3);
  border-radius: var(--r-sm);
  padding: 3px 9px;
  transition: all .15s;
}
.kp-link:hover { background: var(--c-accent-glow); border-color: var(--c-accent); }

.movies-actions {
  display: flex; gap: 12px; justify-content: center;
  margin-bottom: 40px;
}

/* ── Script blocks ───────────────────────────────────────────── */
.script-blocks { display: flex; flex-direction: column; gap: 14px; }

.script-block {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-left: 3px solid transparent;
  border-radius: var(--r-lg);
  overflow: hidden;
  animation: fadeSlideIn .35s ease forwards;
  opacity: 0;
}
.script-block:nth-child(1) { animation-delay: .04s; }
.script-block:nth-child(2) { animation-delay: .09s; }
.script-block:nth-child(3) { animation-delay: .14s; }
.script-block:nth-child(4) { animation-delay: .19s; }
.script-block:nth-child(5) { animation-delay: .24s; }

.script-block--hook   { border-left-color: var(--c-hook); }
.script-block--film-1 { border-left-color: var(--c-film-1); }
.script-block--film-2 { border-left-color: var(--c-film-2); }
.script-block--film-3 { border-left-color: var(--c-film-3); }
.script-block--meta   { border-left-color: var(--c-meta); }

.block-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--c-border);
}
.block-head-left { display: flex; align-items: center; gap: 10px; }
.block-head-right { display: flex; align-items: center; gap: 8px; }
.block-timecode {
  font-family: var(--font-mono);
  font-size: 11px; font-weight: 500; color: var(--c-text-3);
  background: var(--c-elevated);
  padding: 2px 7px; border-radius: 4px;
}
.block-type { font-size: 13px; font-weight: 700; }

.block-body { padding: 16px; }

.hook-text {
  font-size: 22px; font-weight: 700;
  color: var(--c-hook); letter-spacing: -0.3px;
}

.narration-text {
  font-family: var(--font-mono);
  font-size: 13px; line-height: 1.7;
  background: var(--c-elevated);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: 14px 16px;
  color: #c8d0ff;
}
.word-count {
  font-size: 11px; font-family: var(--font); margin-top: 5px;
  padding: 2px 8px; border-radius: 4px; display: inline-block;
}
.wc-ok   { color: var(--c-success); background: rgba(34,197,94,0.10); }
.wc-low  { color: var(--c-warning); background: rgba(245,158,11,0.10); }
.wc-high { color: var(--c-danger);  background: rgba(239,68,68,0.10); }

/* YouTube metadata */
.meta-grid { display: flex; flex-direction: column; gap: 14px; }
.meta-field { display: flex; flex-direction: column; gap: 5px; }
.meta-label {
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .7px;
  color: var(--c-text-3);
  display: flex; align-items: center; gap: 8px;
}
.meta-title-val {
  font-family: var(--font-mono);
  font-size: 13px; background: var(--c-elevated);
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm); padding: 10px 12px; color: #c8e8ff;
}
.meta-desc-val {
  font-size: 13.5px; color: var(--c-text); line-height: 1.6;
}
.tags-row { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  font-size: 11px; background: var(--c-elevated);
  border: 1px solid var(--c-border-hi);
  border-radius: 20px; padding: 3px 10px; color: var(--c-text-2);
}

.script-footer {
  display: flex; align-items: center; gap: 12px;
  padding: 24px 0 8px;
}

/* ── Saved scripts ───────────────────────────────────────────── */
.page-header { margin: 36px 0 20px; }
.page-title { font-size: 20px; font-weight: 700; }
.scripts-list { display: flex; flex-direction: column; gap: 10px; }

.script-card {
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--r-lg); padding: 16px 20px;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  transition: border-color .15s;
  animation: fadeSlideIn .3s ease forwards; opacity: 0;
}
.script-card:hover { border-color: var(--c-border-hi); }
.script-card-body { flex: 1; min-width: 0; }
.script-card-title {
  font-size: 14px; font-weight: 600; margin-bottom: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.script-card-genre { font-size: 12px; color: var(--c-accent); margin-bottom: 4px; }
.script-card-date { font-size: 11px; color: var(--c-text-3); }
.script-card-actions { display: flex; gap: 8px; flex-shrink: 0; }
.empty-scripts { text-align: center; color: var(--c-text-3); padding: 60px 0; font-size: 15px; }

/* ── Modals ──────────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.75); backdrop-filter: blur(4px); }
.modal-dialog {
  position: relative; z-index: 1;
  background: var(--c-elevated); border: 1px solid var(--c-border-hi);
  border-radius: var(--r-xl); width: min(480px, 92vw); max-height: 82vh;
  overflow-y: auto; display: flex; flex-direction: column;
  box-shadow: 0 24px 64px rgba(0,0,0,.6); animation: modalIn .2s ease;
}
.modal-dialog--wide { width: min(900px, 96vw); }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--c-border);
}
.modal-title { font-size: 15px; font-weight: 600; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--c-border); }

.variant-list { padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.variant-item {
  background: var(--c-surface); border: 1px solid var(--c-border-hi);
  border-radius: var(--r-md); padding: 12px 14px;
  cursor: pointer; transition: all .15s; font-size: 13.5px; line-height: 1.55;
}
.variant-item:hover { border-color: var(--c-accent); background: var(--c-accent-glow); transform: translateX(3px); }
.variant-num { font-size: 11px; font-weight: 700; color: var(--c-accent); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .5px; }

.detail-body { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.detail-block { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--r-md); padding: 14px; }
.detail-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .8px; color: var(--c-text-3); margin-bottom: 6px; }
.detail-text { font-size: 13.5px; line-height: 1.6; }
.detail-meta-copy { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

/* Hook in saved modal */
.detail-hook-val { color: var(--c-hook); font-size: 18px; font-weight: 700; line-height: 1.3; margin-bottom: 10px; }

/* Film block in saved modal */
.detail-block--film { border-left-width: 3px !important; }
.detail-film-row { display: flex; gap: 14px; align-items: flex-start; }
.detail-poster {
  width: 110px; min-width: 110px; aspect-ratio: 2/3; object-fit: cover;
  border-radius: var(--r-sm); background: var(--c-elevated);
}
.detail-poster--empty {
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; background: var(--c-elevated); color: var(--c-text-3);
}
.detail-film-body { flex: 1; min-width: 0; }
.detail-film-header { display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.detail-film-link { font-weight: 700; font-size: 15px; text-decoration: none; }
.detail-film-link:hover { text-decoration: underline; }
.detail-film-rating { color: var(--c-warning); font-weight: 700; font-size: 13px; }
.detail-film-tc { color: var(--c-text-3); font-size: 11px; font-family: var(--font-mono); }
.detail-narration {
  font-family: var(--font-mono); font-size: 12.5px; line-height: 1.7;
  background: var(--c-elevated); border: 1px solid var(--c-border);
  border-radius: var(--r-sm); padding: 10px 12px; color: #c8d0ff; margin-bottom: 8px;
}

/* YouTube block in saved modal */
.detail-yt-title { font-size: 14px; font-weight: 700; color: var(--c-text); margin-bottom: 8px; }
.detail-yt-desc { font-size: 13px; color: var(--c-text-2); line-height: 1.6; margin-bottom: 10px; }

/* ── Loading ─────────────────────────────────────────────────── */
.loading-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(11,11,15,.88); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
}
.loading-overlay.hidden { display: none; }
.loading-inner { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--c-border-hi);
  border-top-color: var(--c-accent);
  border-radius: 50%; animation: spin .8s linear infinite;
}
.loading-text { font-size: 14px; color: var(--c-text-2); min-width: 220px; text-align: center; transition: opacity .3s; }

/* ── Toasts ──────────────────────────────────────────────────── */
.toasts { position: fixed; bottom: 24px; right: 24px; z-index: 300; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.toast {
  background: var(--c-elevated); border: 1px solid var(--c-border-hi);
  border-radius: var(--r-md); padding: 10px 16px; font-size: 13px;
  max-width: 340px; box-shadow: 0 8px 24px rgba(0,0,0,.5);
  animation: toastIn .25s ease; display: flex; align-items: flex-start; gap: 8px;
}
.toast--error   { border-left: 3px solid var(--c-danger); }
.toast--success { border-left: 3px solid var(--c-success); }
.toast--info    { border-left: 3px solid var(--c-accent); }
.toast-icon { font-size: 15px; flex-shrink: 0; margin-top: 1px; }
.toast-msg { line-height: 1.45; }
.toast.fadeout { animation: toastOut .25s ease forwards; }

/* ── Utils ───────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Animations ──────────────────────────────────────────────── */
@keyframes fadeSlideIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes modalIn { from { opacity: 0; transform: translateY(-16px) scale(.97); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toastOut { from { opacity: 1; transform: translateX(0); } to { opacity: 0; transform: translateX(20px); } }
