:root {
  --bg: #f4f3f0; --paper: #fff; --ink: #1b1b1b; --muted: #8a8780; --line: #e3e1dc;
  --accent: #1b1b1b; --ai: #6d4aff; --danger: #d83a2e; --ok: #2e8b57;
  --vo: #e53935; --super: #1e88e5;
  --font: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Heiti TC", system-ui, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 var(--font); }
button, input, textarea, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 12px; } .tiny { font-size: 11px; }
.spacer { flex: 1; }
a { color: inherit; }

.btn { border: 1px solid var(--line); background: var(--paper); padding: 7px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #bbb; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { background: #333; }
.btn.primary:disabled { opacity: .4; cursor: default; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: rgba(0,0,0,.05); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.big { padding: 12px 26px; font-size: 16px; }
.btn.danger, .danger { color: var(--danger); }
.btn.ai, button.ai { color: var(--ai); }
.icon-btn { border: 0; background: none; cursor: pointer; padding: 0 4px; font-size: 16px; color: var(--muted); }

/* 登入 */
#view-login { min-height: 100vh; display: grid; place-items: center; }
.login-box { background: var(--paper); padding: 48px 56px; border-radius: 16px; text-align: center; max-width: 440px; box-shadow: 0 10px 40px rgba(0,0,0,.06); }
.login-box h1 { margin: 0 0 8px; font-weight: 600; }
.login-box h1 span, .brand span { font-weight: 300; color: var(--muted); }

/* topbar */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px; padding: 10px 20px; background: rgba(244,243,240,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.brand { font-size: 17px; font-weight: 600; }
.sync { font-size: 12px; color: var(--muted); }
.title-input { border: 1px solid transparent; background: transparent; font-size: 20px; padding: 2px 8px; border-radius: 6px; width: 260px; }
.title-input:hover, .title-input:focus { border-color: var(--line); background: var(--paper); outline: none; }
.dur-box { display: flex; align-items: center; gap: 4px; font-size: 18px; }
.dur-box input { width: 56px; font-size: 18px; border: 1px solid transparent; background: transparent; border-radius: 6px; padding: 2px 4px; text-align: right; }
.dur-box input:hover, .dur-box input:focus { border-color: var(--line); background: var(--paper); outline: none; }
.total { margin-left: 12px; font-size: 13px; padding: 3px 10px; border-radius: 20px; background: #eceae5; }
.total.ok { background: #e3f3e9; color: var(--ok); }
.total.over { background: #fde8e6; color: var(--danger); }
.total.under { background: #fff4dc; color: #a26b00; }

.dropdown { position: relative; }
.menu, .pop-menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--paper); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.12); padding: 6px; min-width: 230px; z-index: 50; }
.pop-menu { position: absolute; min-width: 180px; }
.menu button, .pop-menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 12px; border-radius: 6px; cursor: pointer; }
.menu button:hover, .pop-menu button:hover { background: #f1f0ec; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

/* 首頁 */
.home { max-width: 1100px; margin: 0 auto; padding: 24px 20px 80px; }
.home-head { display: flex; align-items: center; justify-content: space-between; }
.project-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; margin-top: 12px; }
.proj-card { display: flex; gap: 12px; align-items: center; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 10px; cursor: pointer; }
.proj-card:hover { border-color: #bbb; }
.proj-thumb { width: 110px; aspect-ratio: 16/9; background: #eee; border-radius: 6px; overflow: hidden; display: grid; place-items: center; flex: none; font-size: 26px; }
.proj-thumb img { width: 100%; height: 100%; object-fit: cover; }
.proj-info { flex: 1; min-width: 0; }
.proj-title { font-weight: 600; font-size: 15px; }
.proj-actions { display: flex; flex-direction: column; }
.empty { padding: 60px; text-align: center; color: var(--muted); grid-column: 1/-1; }

/* 編輯頁 */
.editor { padding: 20px; max-width: 1700px; margin: 0 auto; }
.shot-grid { display: grid; grid-template-columns: repeat(var(--cols, 4), minmax(0, 1fr)); gap: 22px 10px; background: var(--paper); padding: 22px 18px; border-radius: 6px; box-shadow: 0 2px 14px rgba(0,0,0,.05); }
@media (max-width: 1200px) { .shot-grid { grid-template-columns: repeat(min(var(--cols), 3), minmax(0, 1fr)); } }
@media (max-width: 800px) { .shot-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.grid-foot { display: flex; gap: 10px; justify-content: center; margin: 18px 0 60px; }

.card { position: relative; min-width: 0; border-radius: 4px; }
.card.dragging { opacity: .35; }
.card.drop-before::before, .card.drop-after::after { content: ''; position: absolute; top: 0; bottom: 0; width: 3px; background: var(--ai); border-radius: 2px; }
.card.drop-before::before { left: -7px; } .card.drop-after::after { right: -7px; }
.card-head { display: flex; align-items: center; gap: 4px; height: 26px; }
.drag { cursor: grab; color: #bbb; user-select: none; font-size: 13px; letter-spacing: -2px; padding-right: 2px; }
.drag:hover { color: var(--ink); }
.card .label { width: 64px; border: 1px solid transparent; background: transparent; font-size: 15px; padding: 0 3px; border-radius: 4px; }
.card .label::placeholder { color: var(--ink); }
.card .label:hover, .card .label:focus { border-color: var(--line); outline: none; }
.dur-wrap { font-size: 12px; color: #666; }
.card .dur { width: 42px; border: 1px solid transparent; background: transparent; text-align: right; font-size: 12px; color: #666; border-radius: 4px; -moz-appearance: textfield; }
.card .dur::-webkit-inner-spin-button { display: none; }
.card .dur:hover, .card .dur:focus { border-color: var(--line); outline: none; }

.frame-wrap { position: relative; }
.frame-wrap.file-over .frame { outline: 3px dashed var(--ai); }
.frame { position: relative; width: 100%; overflow: hidden; background: #ececec; user-select: none; }
.frame .base { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.frame .lb { position: absolute; left: 0; right: 0; background: #000; pointer-events: none; }
.frame .brand-logo { position: absolute; pointer-events: none; z-index: 5; }
.frame .ph { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 6px; align-items: center; justify-content: center; z-index: 2; }
.layer { position: absolute; z-index: 3; }
.layer img { width: 100%; height: 100%; display: block; pointer-events: none; }
.layer .ltext { width: 100%; height: 100%; font-weight: 600; line-height: 1.25; white-space: pre-wrap; word-break: break-word; text-shadow: 0 1px 3px rgba(0,0,0,.55); padding-top: .1em; overflow: visible; }
.frame.interactive .layer { cursor: move; }
.frame.interactive .layer:hover { outline: 1px dashed rgba(109,74,255,.8); }
.layer.selected { outline: 2px solid var(--ai) !important; }
.layer .handle { display: none; position: absolute; right: -6px; bottom: -6px; width: 12px; height: 12px; background: #fff; border: 2px solid var(--ai); border-radius: 3px; cursor: nwse-resize; }
.layer.selected .handle, .frame.interactive .layer:hover .handle { display: block; }
.frame-tools { position: absolute; right: 6px; bottom: 6px; display: flex; gap: 4px; opacity: 0; transition: opacity .15s; z-index: 8; }
.frame-wrap:hover .frame-tools { opacity: 1; }
.frame-tools button { border: 0; background: rgba(255,255,255,.92); border-radius: 6px; padding: 3px 8px; font-size: 12px; cursor: pointer; box-shadow: 0 1px 4px rgba(0,0,0,.2); }
.frame-tools button:hover { background: #fff; }

.card textarea, .card .speaker { width: 100%; border: 1px solid transparent; background: transparent; resize: none; padding: 1px 3px; border-radius: 4px; font-size: 13px; line-height: 1.5; overflow: hidden; display: block; }
.card textarea:hover, .card textarea:focus, .card .speaker:hover, .card .speaker:focus { border-color: var(--line); background: #fbfbfa; outline: none; }
.card .f-camera { margin-top: 4px; }
.card textarea::placeholder, .card .speaker::placeholder { color: #c9c6bf; }
.f-row { display: flex; align-items: flex-start; }
.f-row > span { line-height: 1.5; padding: 2px 0; font-size: 13px; flex: none; }
.f-row.vo, .f-row.vo textarea, .f-row.vo .speaker { color: var(--vo); }
.f-row.super, .f-row.super textarea { color: var(--super); }
.card .speaker { flex: none; padding-right: 0; }
.f-row textarea { flex: 1; }
.f-row .tag { padding-left: 3px; }

/* modal */
.modal-wrap { position: fixed; inset: 0; background: rgba(20,20,20,.38); display: grid; place-items: center; z-index: 100; padding: 20px; }
.modal { background: var(--paper); border-radius: 14px; width: min(560px, 100%); max-height: calc(100vh - 40px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { width: min(980px, 100%); }
.modal.m-editor { width: min(1180px, 100%); }
.modal.m-preview { width: min(1500px, 100%); }
.modal-head { display: flex; align-items: center; padding: 14px 18px 8px; }
.modal-head h3 { margin: 0; font-size: 16px; flex: 1; }
.x { border: 0; background: none; cursor: pointer; font-size: 15px; color: var(--muted); }
.modal-body { padding: 8px 18px 16px; overflow: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }

.form label:not(.check):not(.inline) { display: block; margin: 10px 0; font-size: 13px; color: #555; }
.form label:not(.check):not(.inline) > input, .form label > textarea, .form label > select, .form .asset-group > input { display: block; width: 100%; margin-top: 4px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); resize: vertical; }
.form .row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.form .row > label { flex: 1; }
.form h4 { margin: 22px 0 6px; font-size: 14px; border-top: 1px solid var(--line); padding-top: 16px; }
.form h4:first-child { margin-top: 4px; border-top: 0; padding-top: 0; }
.field { margin: 10px 0; }
.flabel { font-size: 13px; color: #555; margin-bottom: 6px; }
.check { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; font-size: 13px; }
.inline { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.inline input[type=color] { width: 34px; height: 26px; border: 1px solid var(--line); border-radius: 6px; padding: 1px; background: #fff; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 6px 14px; cursor: pointer; border-right: 1px solid var(--line); font-size: 13px; }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent); color: #fff; }

.style-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.style-opt { border: 2px solid var(--line); border-radius: 10px; padding: 0; background: #fff; overflow: hidden; cursor: pointer; display: flex; flex-direction: column; text-align: center; }
.style-picker.static .style-opt { cursor: default; }
.style-opt img { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; background: #eee; }
.style-opt span { padding: 6px; font-size: 13px; }
.style-opt.on { border-color: var(--ai); box-shadow: 0 0 0 2px rgba(109,74,255,.2); }

.asset-groups { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.asset-group { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.asset-group .row input { flex: 1; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; }
.asset-imgs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.ref-thumb { position: relative; width: 84px; height: 84px; border-radius: 8px; overflow: hidden; background: #eee; }
.ref-thumb.logo { width: 120px; height: 60px; background: repeating-conic-gradient(#ddd 0 25%, #fff 0 50%) 0 0/14px 14px; }
.ref-thumb img { width: 100%; height: 100%; object-fit: cover; }
.ref-thumb.logo img { object-fit: contain; }
.ref-thumb .x { position: absolute; top: 2px; right: 2px; background: rgba(0,0,0,.6); color: #fff; border-radius: 50%; width: 20px; height: 20px; font-size: 11px; line-height: 20px; padding: 0; }
.add-img { width: 84px; height: 84px; border: 1.5px dashed #ccc; border-radius: 8px; background: #fafafa; cursor: pointer; font-size: 12px; color: #777; }
.logo-field { display: flex; gap: 10px; align-items: center; }

/* 畫面編輯器 */
.ed-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.text-tools { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; }
.text-tools input[type=color] { width: 32px; height: 26px; border: 1px solid var(--line); border-radius: 6px; padding: 1px; }
.text-tools select { padding: 3px; border-radius: 6px; border: 1px solid var(--line); }
.stage { display: flex; justify-content: center; background: #f1f0ec; padding: 24px; border-radius: 10px; margin-bottom: 8px; }

/* AI 卡片 */
.ai-dialog { display: grid; grid-template-columns: 1.25fr 1fr; gap: 20px; }
@media (max-width: 800px) { .ai-dialog { grid-template-columns: 1fr; } }
.ai-left { min-width: 0; }
.ai-preview { width: 100%; max-height: 60vh; background: #f1f0ec; border-radius: 10px; display: grid; place-items: center; overflow: hidden; margin: 0 auto; }
.ai-preview img { width: 100%; height: 100%; object-fit: contain; }
.ai-strip { display: flex; gap: 6px; margin-top: 8px; overflow-x: auto; }
.ai-strip img { height: 54px; border-radius: 5px; cursor: pointer; border: 2px solid transparent; }
.ai-strip img.on { border-color: var(--ai); }
.ai-right label { margin: 6px 0 !important; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 20px; padding: 3px 11px; font-size: 12px; cursor: pointer; }
.chip.on { background: var(--ai); color: #fff; border-color: var(--ai); }
.chip-check { border: 1px solid var(--line); border-radius: 20px; padding: 3px 10px; font-size: 12px; }
.ref-box { display: flex; }
.spinner-box { display: flex; flex-direction: column; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.spinner { width: 34px; height: 34px; border: 3px solid #ddd; border-top-color: var(--ai); border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.page-preview { display: flex; flex-direction: column; gap: 16px; align-items: center; }
.page-canvas { width: 100%; height: auto; box-shadow: 0 2px 12px rgba(0,0,0,.15); }

.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: #222; color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 200; font-size: 13px; max-width: 80vw; }
.credit { text-align: center; font-size: 12px; color: var(--muted); padding: 10px 0 24px; }
.credit a { color: var(--muted); }

/* 匯入分鏡大圖 */
.sheet-list { display: flex; flex-direction: column; gap: 16px; }
.sheet-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.sheet-head input { width: 52px; padding: 3px 6px; border: 1px solid var(--line); border-radius: 6px; }
.sheet-stage { position: relative; display: inline-block; max-width: 100%; line-height: 0; background: #eee; }
.sheet-stage img { max-width: 100%; max-height: 64vh; display: block; }
.sheet-box { position: absolute; border: 2px solid var(--ai); background: rgba(109,74,255,.08); cursor: pointer; }
.sheet-box:hover { background: rgba(109,74,255,.2); }
.sheet-box span { position: absolute; left: 0; top: 0; background: var(--ai); color: #fff; font-size: 12px; line-height: 1; padding: 3px 5px; border-radius: 0 0 4px 0; }
.sheet-box.off { border-color: #999; border-style: dashed; background: rgba(255,255,255,.65); }
.sheet-box.off span { background: #999; }
.sheet-busy { position: absolute; inset: 0; display: flex; gap: 10px; align-items: center; justify-content: center; background: rgba(255,255,255,.7); line-height: 1.4; }
.sheet-drop { border: 2px dashed #ccc; border-radius: 12px; padding: 34px; text-align: center; color: #777; cursor: pointer; }
.sheet-drop.over, .sheet-drop:hover { border-color: var(--ai); color: var(--ai); }
.modal-foot .import-summary { flex: 1 1 auto; min-width: 0; }
.import-summary .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.import-summary .flabel { margin: 0; }
.modal-foot { align-items: center; flex-wrap: wrap; }

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

.ai-picker { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.ai-picker select { padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.warn { color: #a26b00; }

.dropdown.split { display: inline-flex; }
.dropdown.split #btn-export { border-radius: 8px 0 0 8px; }
.dropdown.split .caret { border-radius: 0 8px 8px 0; border-left: 1px solid #444; padding: 7px 10px; }

/* 素材列 */
.asset-bar { display: flex; gap: 10px; align-items: stretch; flex-wrap: wrap; margin-bottom: 14px; }
.asset-chip { display: flex; align-items: center; gap: 10px; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; cursor: pointer; min-height: 58px; }
.asset-chip:hover { border-color: var(--ai); }
.asset-title { font-size: 13px; font-weight: 600; white-space: nowrap; }
.asset-thumbs { display: flex; gap: 8px; align-items: center; }
.asset-person { display: flex; align-items: center; gap: 5px; }
.asset-person img, .asset-thumbs > img { width: 40px; height: 40px; object-fit: cover; border-radius: 8px; background: #eee; }
.asset-thumbs img.logo { width: auto; max-width: 70px; height: 32px; object-fit: contain; border-radius: 0; background: repeating-conic-gradient(#ddd 0 25%, #fff 0 50%) 0 0/10px 10px; }
.asset-thumbs em, .asset-person em { font-style: normal; font-size: 12px; color: #555; }
.asset-empty { font-size: 12px; color: var(--ai); border: 1px dashed var(--ai); border-radius: 8px; padding: 6px 10px; }
.asset-note { align-self: center; margin-left: auto; }
h4.flash { animation: flash 1.6s ease; }
@keyframes flash { 0%, 40% { background: #ece7ff; } 100% { background: transparent; } }

.proposal-ref { background: #f6f5f2; border-radius: 10px; padding: 10px 12px; margin: 6px 0 10px; }
.proposal-ref .flabel { margin-bottom: 4px; }
.proposal-text { font-size: 13px; color: #666; white-space: pre-wrap; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.ai-right .field > textarea { display: block; width: 100%; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; resize: vertical; }
