:root {
  --obsidian: #08070A;
  --obsidian-2: #121016;
  --panel: #16141b;
  --panel-2: #1d1a23;
  --line: #2a2731;
  --line-soft: #221f29;
  --cream: #F4E9D7;
  --cream-dim: #cbc0aa;
  --muted: #8a8577;
  --gold: #F1B43E;
  --gold-bright: #f6c766;
  --gold-deep: #a87d24;
  --danger: #c96b4a;
  --shadow: 0 18px 50px rgba(0,0,0,0.55);
  --radius: 14px;
  --radius-sm: 9px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(1200px 700px at 50% -10%, #171009 0%, var(--obsidian) 55%);
  color: var(--cream);
  font-family: 'Inter', system-ui, sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
}
body { width: 100%; max-width: 100%; }
textarea, input, button { font-family: inherit; }

.haze { position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background: radial-gradient(700px 420px at 50% 8%, rgba(241,180,62,0.10), transparent 70%); }

/* ---------------------------------- topbar -------------------------------- */
.topbar {
  position: relative; z-index: 2;
  display: flex; justify-content: space-between; align-items: center;
  padding: 20px clamp(16px, 5vw, 56px);
  border-bottom: 1px solid var(--line-soft);
  gap: 16px; flex-wrap: wrap;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand-mark { font-family: 'Cormorant Garamond', serif; font-weight: 600; font-size: 26px; letter-spacing: 0.22em; color: var(--cream); }
.brand-sub { font-size: 12px; letter-spacing: 0.42em; color: var(--gold); font-weight: 600; }
.account {
  display: flex; gap: clamp(12px, 3vw, 22px);
  padding: 10px 16px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: rgba(20,18,25,0.6);
  flex-wrap: wrap;
}
.acct-row { display: flex; flex-direction: column; gap: 2px; min-width: 60px; }
.acct-label { font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.acct-val { font-size: 14px; font-weight: 600; color: var(--cream); }

/* ---------------------------------- steps --------------------------------- */
.steps {
  position: relative; z-index: 2;
  display: flex; align-items: center; justify-content: center;
  gap: 6px; padding: 18px 16px 2px;
}
.step { display: flex; align-items: center; gap: 8px; background: transparent; border: none; cursor: pointer; padding: 6px 10px; border-radius: 40px; }
.step:disabled { opacity: 0.4; cursor: not-allowed; }
.step-n {
  width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center; font-size: 12px; font-weight: 600;
  border: 1px solid var(--line); color: var(--muted); background: var(--panel-2);
}
.step-l { font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.step.active .step-n { border-color: var(--gold); color: var(--obsidian); background: var(--gold); }
.step.active .step-l { color: var(--cream); }
.step.done .step-n { border-color: var(--gold-deep); color: var(--gold-bright); }
.step-sep { width: clamp(18px, 6vw, 54px); height: 1px; background: var(--line); }

/* ----------------------------------- stage -------------------------------- */
.stage { position: relative; z-index: 1; max-width: 1080px; margin: 0 auto; padding: clamp(18px, 3vw, 36px) clamp(14px, 5vw, 40px) 80px; }
.panel {
  background: linear-gradient(180deg, var(--panel) 0%, var(--obsidian-2) 100%);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: clamp(20px, 3.4vw, 40px); margin-bottom: 24px;
}
.panel[hidden] { display: none; }
.panel-head { margin-bottom: 24px; }
.title { font-family: 'Cormorant Garamond', serif; font-weight: 600; font-style: italic; font-size: clamp(30px, 5vw, 46px); margin: 0 0 10px; color: var(--cream); }
.title-sm { font-family: 'Cormorant Garamond', serif; font-weight: 600; font-style: italic; font-size: clamp(24px, 3.6vw, 34px); margin: 0 0 8px; }
.lede { color: var(--cream-dim); font-size: 15px; line-height: 1.55; margin: 0; max-width: 64ch; }

/* ----------------------------------- tiers -------------------------------- */
.tiers { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.tier { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px 22px; display: flex; flex-direction: column; gap: 14px; transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s; cursor: pointer; min-width: 0; }
.tier:hover { transform: translateY(-3px); border-color: var(--gold-deep); }
.tier.selected { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold), 0 14px 40px rgba(241,180,62,0.14); }
.tier-name { font-family: 'Cormorant Garamond', serif; font-size: 24px; font-weight: 600; }
.tier-price { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.tier-price .amt { font-size: 30px; font-weight: 600; color: var(--gold-bright); }
.tier-price .per { font-size: 13px; color: var(--muted); }
.tier-box { font-size: 13px; color: var(--cream-dim); }
.tier-blurb { font-size: 13px; color: var(--cream-dim); line-height: 1.5; flex: 1; }
.tier-feat { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.tier-feat li { font-size: 13px; color: var(--cream-dim); padding-left: 16px; position: relative; }
.tier-feat li::before { content: ""; position: absolute; left: 0; top: 7px; width: 6px; height: 6px; border-radius: 50%; background: var(--gold); }
.tier-cta { margin-top: 6px; padding: 11px; border-radius: var(--radius-sm); border: 1px solid var(--gold-deep); background: transparent; color: var(--gold-bright); font-weight: 600; font-size: 14px; cursor: pointer; transition: background 0.18s, color 0.18s; }
.tier.selected .tier-cta, .tier-cta:hover { background: var(--gold); color: var(--obsidian); border-color: var(--gold); }

/* --------------------------- upgrade nudge (driver) ----------------------- */
.upgrade-nudge {
  margin-top: 22px; padding: 18px 20px;
  border: 1px solid var(--gold-deep); border-radius: var(--radius-sm);
  background: linear-gradient(180deg, rgba(241,180,62,0.07), rgba(241,180,62,0.02));
  display: flex; flex-direction: column; gap: 8px;
}
.nudge-head { font-size: 13px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--gold-bright); font-weight: 600; }
.nudge-body { font-size: 14px; line-height: 1.55; color: var(--cream-dim); }
.nudge-body strong { color: var(--cream); }
.nudge-actions { display: flex; gap: 10px; margin-top: 4px; flex-wrap: wrap; }

/* ---------------------------------- fields -------------------------------- */
.field { margin-bottom: 22px; }
.field-label { display: block; font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); margin-bottom: 10px; }
.subject, .ce-prompt {
  width: 100%; background: var(--obsidian-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); color: var(--cream); padding: 14px 16px;
  font-size: 15px; line-height: 1.5; resize: vertical; min-height: 58px;
}
.subject:focus, .ce-prompt:focus, .topup input:focus { outline: none; border-color: var(--gold-deep); }
.subject::placeholder { color: var(--muted); }
.field-hint { font-size: 11px; color: var(--muted); text-align: right; margin-top: 6px; }
.brief-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }

.chips { display: flex; flex-wrap: wrap; gap: 10px; }
.chip {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 10px 14px; cursor: pointer; text-align: left; color: var(--cream-dim);
  display: flex; flex-direction: column; gap: 3px; transition: border-color 0.16s, background 0.16s; min-width: 0;
}
.chip:hover { border-color: var(--gold-deep); }
.chip.active { border-color: var(--gold); background: rgba(241,180,62,0.08); }
.chip-l { font-size: 14px; font-weight: 600; color: var(--cream); }
.chip-b { font-size: 11px; color: var(--muted); line-height: 1.35; }
.chip-aspect { flex-direction: row; align-items: center; gap: 10px; }
.chip-aspect .chip-l { font-size: 13px; }
.ar-box { width: 26px; background: linear-gradient(135deg, var(--gold-deep), var(--gold)); border-radius: 3px; flex: 0 0 auto; }

/* -------------------------------- length ---------------------------------- */
.length-row { display: grid; grid-template-columns: 1.3fr 1fr; gap: 24px; align-items: center; }
.length-presets { display: flex; flex-wrap: wrap; gap: 10px; }
.preset { padding: 12px 18px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--panel-2); color: var(--cream-dim); font-weight: 600; font-size: 14px; cursor: pointer; transition: all 0.16s; }
.preset:hover { border-color: var(--gold-deep); color: var(--cream); }
.preset.active { background: var(--gold); color: var(--obsidian); border-color: var(--gold); }
.length-custom { display: flex; flex-direction: column; gap: 8px; }
.length-custom output { font-size: 26px; font-weight: 600; color: var(--gold-bright); font-family: 'Cormorant Garamond', serif; }

input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 4px; border-radius: 3px; background: var(--line); outline: none; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%; background: var(--gold-bright); cursor: pointer; border: 2px solid var(--obsidian); }
input[type="range"]::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: var(--gold-bright); cursor: pointer; border: 2px solid var(--obsidian); }

.estimate { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin: 24px 0; }
.est-cell { background: var(--obsidian-2); border: 1px solid var(--line-soft); border-radius: var(--radius-sm); padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.est-k { font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.est-v { font-size: 18px; font-weight: 600; color: var(--cream); }

/* ---------------------------------- actions ------------------------------- */
.actions { display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap; }
.actions-end { justify-content: flex-end; margin-top: 22px; }
.export-group { display: flex; gap: 12px; }
.btn-gold, .btn-gold-sm { background: linear-gradient(180deg, var(--gold-bright), var(--gold)); color: var(--obsidian); border: none; border-radius: var(--radius-sm); font-weight: 600; cursor: pointer; transition: filter 0.16s, transform 0.12s; }
.btn-gold { padding: 13px 30px; font-size: 15px; }
.btn-gold-sm { padding: 10px 18px; font-size: 13px; }
.btn-gold:hover, .btn-gold-sm:hover { filter: brightness(1.06); }
.btn-gold:active { transform: translateY(1px); }
.btn-gold:disabled { filter: grayscale(0.6) brightness(0.7); cursor: not-allowed; }
.btn-gold.loading { position: relative; color: transparent; }
.btn-gold.loading::after, .btn-ghost-sm.loading::after { content: ""; position: absolute; inset: 0; margin: auto; width: 15px; height: 15px; border: 2px solid rgba(8,7,10,0.3); border-top-color: var(--obsidian); border-radius: 50%; animation: spin 0.7s linear infinite; }
.btn-ghost-sm.loading::after { border-color: rgba(241,180,62,0.3); border-top-color: var(--gold-bright); }
@keyframes spin { to { transform: rotate(360deg); } }
.btn-ghost { background: transparent; border: 1px solid var(--line); color: var(--cream-dim); padding: 13px 26px; border-radius: var(--radius-sm); font-weight: 600; font-size: 15px; cursor: pointer; transition: border-color 0.16s, color 0.16s; }
.btn-ghost:hover { border-color: var(--gold-deep); color: var(--cream); }
.btn-ghost-sm { position: relative; background: transparent; border: 1px solid var(--line); color: var(--cream-dim); padding: 8px 14px; border-radius: var(--radius-sm); font-weight: 600; font-size: 13px; cursor: pointer; transition: border-color 0.16s, color 0.16s; }
.btn-ghost-sm:hover { border-color: var(--gold-deep); color: var(--cream); }
.btn-ghost-sm.danger:hover { border-color: var(--danger); color: var(--danger); }

/* --------------------------------- gate banner ---------------------------- */
.gate-banner { margin-top: 22px; border: 1px solid var(--gold-deep); background: rgba(241,180,62,0.07); border-radius: var(--radius-sm); padding: 18px 20px; display: flex; justify-content: space-between; align-items: center; gap: 18px; flex-wrap: wrap; }
.gate-text { color: var(--cream); font-size: 14px; font-weight: 500; max-width: 52ch; }
.topup { display: flex; gap: 10px; align-items: center; }
.topup input { width: 90px; padding: 10px 12px; background: var(--obsidian-2); border: 1px solid var(--line); border-radius: var(--radius-sm); color: var(--cream); font-size: 14px; }

/* ---------------------------------- editor -------------------------------- */
.editor-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.editor-total { text-align: right; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 16px; background: var(--obsidian-2); }
.et-k { display: block; font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.et-v { font-size: 20px; font-weight: 600; color: var(--gold-bright); font-family: 'Cormorant Garamond', serif; }

.preview { margin-bottom: 22px; display: flex; justify-content: center; }
.preview-frame {
  position: relative; width: 100%; max-width: 720px; aspect-ratio: 16 / 9;
  border-radius: var(--radius); border: 1px solid var(--line);
  background: radial-gradient(400px 220px at 50% 40%, rgba(241,180,62,0.12), transparent 70%), linear-gradient(135deg, #0d0b10 0%, #1b140b 100%);
  display: flex; align-items: center; justify-content: center; overflow: hidden; transition: aspect-ratio 0.25s;
}
.preview-frame[data-aspect="9:16"] { aspect-ratio: 9 / 16; max-width: 360px; }
.preview-frame[data-aspect="1:1"] { aspect-ratio: 1 / 1; max-width: 460px; }
.preview-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; display: none; }
.preview-frame.has-video .preview-video { display: block; }
.preview-frame.has-video .preview-play { position: absolute; z-index: 2; }
.preview-play { width: 0; height: 0; border: none; background: transparent; border-left: 30px solid var(--gold-bright); border-top: 18px solid transparent; border-bottom: 18px solid transparent; opacity: 0.9; cursor: pointer; transition: opacity 0.15s, transform 0.15s; }
.preview-play:hover { opacity: 1; transform: scale(1.05); }
.preview-play.playing { border-left: none; width: 22px; height: 30px; border-radius: 3px; background: linear-gradient(90deg, var(--gold-bright) 0 8px, transparent 8px 14px, var(--gold-bright) 14px 22px); }
.preview-caption { position: absolute; top: 16px; left: 18px; right: 18px; font-size: 12px; color: var(--cream-dim); line-height: 1.4; text-align: center; opacity: 0.85; }
.preview-meta { position: absolute; bottom: 18px; left: 16px; right: 16px; display: flex; justify-content: space-between; font-size: 12px; color: var(--cream-dim); }
.preview-progress { position: absolute; bottom: 0; left: 0; right: 0; height: 3px; background: rgba(0,0,0,0.4); }
.preview-progress-fill { height: 100%; width: 0; background: var(--gold); transition: width 0.05s linear; }

.timeline-wrap { display: flex; align-items: stretch; gap: 12px; margin-bottom: 18px; }
.timeline { display: flex; gap: 10px; overflow-x: auto; padding: 8px 2px 12px; min-height: 96px; flex: 1; }
.tl-clip { flex: 0 0 auto; width: 124px; height: 78px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: linear-gradient(135deg, #14121a, #201a10); cursor: grab; position: relative; padding: 8px 10px; display: flex; flex-direction: column; justify-content: space-between; transition: border-color 0.16s; }
.tl-clip:hover { border-color: var(--gold-deep); }
.tl-clip.selected { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }
.tl-clip.dragging { opacity: 0.4; }
.tl-clip.drop-target { border-color: var(--gold-bright); border-style: dashed; }
.tl-idx { font-size: 11px; color: var(--muted); letter-spacing: 0.1em; }
.tl-name { font-size: 13px; font-weight: 600; color: var(--cream); }
.tl-len { font-size: 12px; color: var(--gold-bright); }
.tl-bar { position: absolute; bottom: 0; left: 0; right: 0; height: 3px; background: var(--gold); border-radius: 0 0 var(--radius-sm) var(--radius-sm); opacity: 0.5; }
.tl-add { flex: 0 0 auto; align-self: center; background: transparent; border: 1px dashed var(--line); color: var(--cream-dim); border-radius: var(--radius-sm); padding: 0 16px; height: 78px; font-weight: 600; font-size: 13px; cursor: pointer; transition: border-color 0.16s, color 0.16s; }
.tl-add:hover { border-color: var(--gold-deep); color: var(--gold-bright); }

.clip-edit { background: var(--obsidian-2); border: 1px solid var(--line-soft); border-radius: var(--radius-sm); padding: 18px; margin-bottom: 22px; }
.ce-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 12px; flex-wrap: wrap; }
.ce-head > span { font-weight: 600; color: var(--cream); }
.ce-actions { display: flex; gap: 8px; }
.ce-prompt { margin-bottom: 14px; }
.trim { border-top: 1px solid var(--line-soft); padding-top: 14px; }
.trim-head { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 12px; }
.trim-head span:first-child { font-weight: 600; color: var(--cream); }
.trim-head span:last-child { color: var(--gold-bright); }
.trim-track { display: grid; gap: 10px; }

.export-note { margin-top: 18px; padding: 16px 18px; border: 1px solid var(--gold-deep); background: rgba(241,180,62,0.06); border-radius: var(--radius-sm); font-size: 13px; color: var(--cream-dim); line-height: 1.55; }
.export-note strong { color: var(--gold-bright); }

/* ---------------------------------- footer -------------------------------- */
.foot { position: relative; z-index: 1; text-align: center; padding: 24px; font-size: 12px; color: var(--muted); letter-spacing: 0.08em; }
.foot-dot { margin: 0 10px; color: var(--line); }

/* ---------------------------- script (Script Lab) ------------------------- */
.select { width: 100%; background: var(--panel-2); color: var(--cream); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 11px 12px; font-size: 14px; font-family: inherit; }
.select:focus { outline: none; border-color: var(--gold-deep); }
.opt { color: var(--muted); text-transform: none; letter-spacing: 0; font-weight: 400; }
.script-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 26px; }
.script-col { display: flex; flex-direction: column; gap: 16px; }
.upload-box { border-top: 1px solid var(--line-soft); padding-top: 16px; margin-top: 4px; }
.script-preview { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.sp-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.sp-head #sp-title { font-family: 'Cormorant Garamond', serif; font-size: 22px; color: var(--cream); font-weight: 600; }
.sp-meta { font-size: 11px; color: var(--muted); letter-spacing: 0.06em; }
.sp-scenes { display: flex; flex-direction: column; gap: 10px; max-height: 360px; overflow-y: auto; padding-right: 6px; }
.sp-scene { border-left: 2px solid var(--gold-deep); padding: 4px 0 4px 12px; }
.sp-role { font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--gold); margin-bottom: 3px; }
.sp-text { font-size: 13px; color: var(--cream-dim); line-height: 1.4; }
.sp-visual { font-size: 11px; color: var(--muted); margin-top: 3px; font-style: italic; }
.save-row { display: flex; gap: 8px; margin-top: 14px; }
.save-row .subject { flex: 1; }
.saved-scripts { margin-top: 4px; }
.saved-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.saved-empty { font-size: 13px; color: var(--muted); padding: 8px 0; }
.saved-row { display: flex; align-items: stretch; gap: 6px; }
.saved-open { flex: 1; display: flex; flex-direction: column; gap: 2px; text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; cursor: pointer; transition: border-color 0.15s; }
.saved-open:hover { border-color: var(--gold-deep); }
.saved-title { font-size: 14px; color: var(--cream); font-weight: 500; }
.saved-sub { font-size: 11px; color: var(--muted); }
.saved-del { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-sm); color: var(--muted); width: 38px; font-size: 18px; cursor: pointer; }
.saved-del:hover { border-color: var(--danger); color: var(--danger); }
.script-msg { margin-top: 14px; padding: 10px 14px; border-radius: var(--radius-sm); background: rgba(241,180,62,0.06); border: 1px solid var(--line); font-size: 13px; color: var(--cream-dim); }
.script-msg.warn { background: rgba(201,107,74,0.08); border-color: var(--danger); color: var(--cream); }
.script-banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: rgba(241,180,62,0.07); border: 1px solid var(--gold-deep); border-radius: var(--radius-sm); padding: 12px 16px; margin-bottom: 18px; }
.sb-text { font-size: 13px; color: var(--cream); }

/* -------------------------------- responsive ------------------------------ */
@media (max-width: 820px) {
  .script-grid { grid-template-columns: 1fr; }
  .tiers { grid-template-columns: 1fr; }
  .brief-grid { grid-template-columns: 1fr; }
  .length-row { grid-template-columns: 1fr; gap: 16px; }
  .estimate { grid-template-columns: repeat(2, 1fr); }
  .topbar { padding-left: 16px; padding-right: 16px; }
  .account { width: 100%; justify-content: space-between; }
  .actions { flex-direction: column; align-items: stretch; }
  .export-group { flex-direction: column; }
  .actions .btn-gold, .actions .btn-ghost { width: 100%; }
  .stage { padding-left: 14px; padding-right: 14px; }
  .panel { padding: 20px 16px; }
  .lede { max-width: 100%; }
  .editor-head { flex-direction: column; }
  .editor-total { align-self: flex-start; }
  .chip { flex: 1 1 auto; }
}
@media (max-width: 460px) {
  .estimate { grid-template-columns: 1fr 1fr; }
  .steps { gap: 2px; }
  .step { padding: 6px 6px; }
  .step-sep { width: 16px; }
}
