:root {
  --bg: #f7f4ee;
  --card: #fffdf9;
  --ink: #2b2a26;
  --muted: #7c766b;
  --line: #e6dfd3;
  --coral: #c96442;
  --coral-dark: #ad5234;
  --coral-soft: #f6e4dc;
  --yellow: #ffd640;
  --ok: #4f7a56;
  --shadow: 0 10px 30px rgba(60, 44, 30, .09), 0 2px 6px rgba(60, 44, 30, .05);
  --radius: 20px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

.hidden { display: none !important; }

html, body { margin: 0; min-height: 100%; }

body {
  background:
    radial-gradient(1200px 700px at 80% -10%, #fdf1e6 0%, transparent 60%),
    radial-gradient(900px 600px at -10% 30%, #f3eee4 0%, transparent 55%),
    var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 520px;
  margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top)) 20px calc(32px + env(safe-area-inset-bottom));
}

.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 28px; }
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 42px; height: 42px; border-radius: 14px;
  background: linear-gradient(160deg, #d97856, var(--coral) 55%, #b45134);
  color: #fff8ef; font-weight: 800; font-size: 17px;
  display: grid; place-items: center;
  box-shadow: 0 6px 14px rgba(201, 100, 66, .28);
  letter-spacing: -.4px;
}
.logo.big { width: 64px; height: 64px; border-radius: 20px; font-size: 25px; margin: 0 auto 14px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text strong { font-size: 17px; letter-spacing: -.2px; }
.brand-text span { font-size: 12px; color: var(--muted); letter-spacing: .12em; text-transform: uppercase; margin-top: 2px; }

.icon-btn {
  width: 44px; height: 44px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); display: grid; place-items: center;
  cursor: pointer; transition: .18s ease;
}
.icon-btn:hover { border-color: #d8cfc0; transform: translateY(-1px); }
.icon-btn.small { width: 36px; height: 36px; border-radius: 12px; }

.screen { display: none; animation: rise .32s ease both; }
.screen.active { display: block; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.hero h1 {
  font-size: clamp(34px, 9vw, 42px);
  line-height: 1.06;
  letter-spacing: -.035em;
  margin: 0 0 12px;
  font-weight: 750;
}
.hero h1 em {
  font-family: Georgia, "Times New Roman", serif;
  font-style: italic;
  font-weight: 500;
  color: var(--coral);
  letter-spacing: -.02em;
}
.hero p { margin: 0 0 22px; color: var(--muted); font-size: 15px; max-width: 34ch; }

.drop {
  display: block; background: var(--card); border: 1.5px dashed #d9d0c1;
  border-radius: var(--radius); padding: 26px 20px; text-align: center;
  cursor: pointer; transition: .2s ease; box-shadow: 0 1px 0 rgba(255,255,255,.8) inset;
}
.drop:hover, .drop.dragging { border-color: var(--coral); background: #fffaf5; }
.drop-empty { display: flex; flex-direction: column; align-items: center; gap: 6px; color: var(--muted); }
.drop-empty svg { color: var(--coral); margin-bottom: 4px; }
.drop-empty strong { color: var(--ink); font-size: 15px; }
.drop-empty span { font-size: 12.5px; }

.picked { display: flex; align-items: center; gap: 14px; text-align: left; }
.picked.hidden { display: none; }
.picked video {
  width: 62px; height: 92px; object-fit: cover; border-radius: 12px;
  background: #111; flex: none;
}
.picked-info { min-width: 0; display: flex; flex-direction: column; gap: 3px; flex: 1; }
.picked-info strong { font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picked-info span { font-size: 12.5px; color: var(--muted); }
.picked-multi { display: block; }
.clip-list { display: flex; flex-direction: column; gap: 8px; }
.clip-item {
  display: flex; align-items: center; gap: 10px; background: #fff;
  border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px;
}
.clip-num {
  width: 26px; height: 26px; border-radius: 8px; background: var(--coral);
  color: #fff; display: grid; place-items: center; font-size: 12px;
  font-weight: 700; flex: none;
}
.clip-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.clip-thumb { width: 42px; height: 42px; object-fit: cover; border-radius: 8px; flex: none; }
.chip-img { width: 34px; height: 34px; object-fit: cover; border-radius: 6px; }
.url-input {
  flex: 1; min-width: 0; padding: 9px 12px; font-size: 13.5px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff;
}
.url-input:focus { outline: 2px solid var(--coral); outline-offset: 1px; }
.clip-meta strong {
  font-size: 13.5px; font-weight: 600; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.clip-meta span { font-size: 11.5px; color: var(--muted); }
.clip-x {
  border: 0; background: transparent; color: #b3402f; font-size: 18px;
  line-height: 1; padding: 6px; cursor: pointer; flex: none;
}
.picked-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-top: 10px;
}
.mini {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 10px; padding: 8px 12px; font-size: 13px; cursor: pointer; flex: none;
}

.install-card {
  display: flex; align-items: center; gap: 12px; width: 100%;
  text-align: left; font: inherit; color: var(--ink); cursor: pointer;
  border: 1px solid #ecd9c9; background: linear-gradient(180deg, #fffaf4, #fff6ee);
  border-radius: 16px; padding: 11px 14px; margin: 0 0 18px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .85) inset;
}
.install-card:active { transform: scale(.99); }
.install-badge {
  width: 40px; height: 40px; border-radius: 13px; flex: none;
  background: linear-gradient(160deg, #d97856, var(--coral) 60%, #b45134);
  color: #fff8ef; display: grid; place-items: center;
  box-shadow: 0 5px 12px rgba(201, 100, 66, .24);
}
.install-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.install-text strong { font-size: 14.5px; }
.install-text small { font-size: 12px; color: var(--muted); }
.install-arrow { color: var(--muted); font-size: 20px; line-height: 1; flex: none; }
.install-steps { color: var(--ink); font-size: 14.5px; }
.install-steps ol { margin: 0; padding-left: 20px; }
.install-steps li { margin: 0 0 10px; }
.install-steps .hint { margin-top: 2px; }

.field { margin-top: 22px; }
.label-row { display: flex; align-items: baseline; justify-content: space-between; }
.label {
  display: block; font-size: 13px; font-weight: 650; letter-spacing: .01em;
  margin-bottom: 9px; color: #49453d;
}
.opt { font-weight: 400; color: var(--muted); font-size: 11.5px; margin-left: 8px; }
input[type="file"] { font-size: 12.5px; color: var(--muted); }
input[type="file"]::file-selector-button {
  margin-right: 10px; padding: 8px 12px; border-radius: 9px; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--ink); font: inherit;
}

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 999px; padding: 10px 14px; font-size: 13.5px; cursor: pointer;
  transition: .16s ease; display: flex; flex-direction: column; gap: 1px; align-items: flex-start;
}
.chip small { color: var(--muted); font-size: 11px; }
.chip.selected {
  background: var(--ink); color: #fdf9f2; border-color: var(--ink);
  box-shadow: 0 8px 18px rgba(43, 42, 38, .18);
}
.chip.selected small { color: rgba(253, 249, 242, .68); }

textarea, input, select {
  width: 100%; font: inherit; color: var(--ink);
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 13px 14px; outline: none; transition: .16s ease;
  -webkit-appearance: none; appearance: none;
}
textarea { resize: none; line-height: 1.4; }
textarea::placeholder, input::placeholder { color: #a9a296; }
input:focus, textarea:focus, select:focus { border-color: var(--coral); box-shadow: 0 0 0 3px rgba(201,100,66,.12); }
select { background-image: linear-gradient(45deg, transparent 50%, #8b8579 50%), linear-gradient(135deg, #8b8579 50%, transparent 50%); background-position: calc(100% - 19px) 21px, calc(100% - 14px) 21px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 40px; }

.primary {
  width: 100%; border: 0; border-radius: 15px; background: var(--coral);
  color: #fff; font-size: 16px; font-weight: 650; letter-spacing: -.01em;
  padding: 16px 18px; margin-top: 26px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  box-shadow: 0 10px 22px rgba(201, 100, 66, .28);
  transition: .18s ease; text-decoration: none;
}
.primary:hover { background: var(--coral-dark); transform: translateY(-1px); }
.primary:disabled { background: #e2d8ca; color: #a49b8d; box-shadow: none; cursor: not-allowed; transform: none; }
.primary[aria-busy="true"] { background: #b96a4d; }

.fine { color: var(--muted); font-size: 12px; text-align: center; margin: 14px 0 0; }
.error { color: #b3402f; font-size: 13px; text-align: center; min-height: 18px; }

/* job */
.job-head { text-align: center; padding: 22px 0 18px; }
.pulse {
  width: 14px; height: 14px; border-radius: 50%; background: var(--coral);
  margin: 0 auto 16px; box-shadow: 0 0 0 0 rgba(201,100,66,.5);
  animation: pulse 1.8s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(201,100,66,.45); }
  70% { box-shadow: 0 0 0 16px rgba(201,100,66,0); }
  100% { box-shadow: 0 0 0 0 rgba(201,100,66,0); }
}
.job-head h2 { margin: 0 0 6px; font-size: 24px; letter-spacing: -.03em; }
.job-head p { margin: 0; color: var(--muted); font-size: 14px; }
.bar { height: 8px; background: #e9e2d6; border-radius: 999px; overflow: hidden; margin: 8px 0 22px; }
#bar-fill { height: 100%; width: 0%; border-radius: 999px; background: linear-gradient(90deg, #d97856, var(--coral)); transition: width .5s ease; }

.stages { display: flex; flex-direction: column; gap: 2px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 10px 16px; }
.stage { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid #f0eade; font-size: 14px; color: var(--muted); }
.stage:last-child { border-bottom: 0; }
.stage .dot { width: 18px; height: 18px; border-radius: 50%; border: 1.6px solid #d5ccbd; margin-top: 1px; flex: none; display: grid; place-items: center; }
.stage.done { color: var(--ink); }
.stage.done .dot { border-color: var(--ok); background: var(--ok); }
.stage.done .dot::after { content: ""; width: 7px; height: 4px; border-left: 2px solid #fff; border-bottom: 2px solid #fff; transform: rotate(-45deg) translateY(-1px); }
.stage.active { color: var(--ink); font-weight: 600; }
.stage.active .dot { border-color: var(--coral); border-top-color: transparent; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* result */
.result-head { text-align: center; margin-bottom: 16px; }
.badge { display: inline-block; background: #e6efe4; color: var(--ok); font-size: 11.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; padding: 5px 10px; border-radius: 999px; }
.result-head h2 { margin: 10px 0 4px; font-size: 23px; letter-spacing: -.03em; }
.result-head p { margin: 0; color: var(--muted); font-size: 13px; }
.player { background: #14120f; border-radius: 18px; overflow: hidden; box-shadow: var(--shadow); }
.player video { display: block; width: 100%; max-height: 68vh; aspect-ratio: 9 / 16; object-fit: contain; background: #14120f; }
.actions { display: flex; gap: 10px; margin-top: 16px; }
.actions .primary { margin-top: 0; }
.ghost {
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 15px; padding: 15px 18px; font: inherit; font-weight: 600; font-size: 15px;
  cursor: pointer; flex: none; transition: .16s ease;
}
.ghost:hover { border-color: #d5ccbd; }
.link { display: block; margin: 18px auto 0; border: 0; background: none; color: var(--muted); font: inherit; font-size: 14px; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }

/* dialog */
dialog {
  border: 0; padding: 0; width: min(520px, calc(100vw - 24px));
  border-radius: 22px; background: var(--card); color: var(--ink);
  box-shadow: 0 30px 80px rgba(40, 30, 20, .28);
}
dialog::backdrop { background: rgba(35, 30, 24, .38); backdrop-filter: blur(3px); }
#settings-form { padding: 22px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.dialog-head h2 { margin: 0; font-size: 21px; letter-spacing: -.02em; }
#settings-form .label { margin-top: 16px; }
.api-fields.hidden { display: none; }
.api-fields input { margin-bottom: 2px; }
.hint { color: var(--muted); font-size: 12px; margin: 7px 0 0; line-height: 1.45; }
.hint code { background: #f0eade; padding: 1px 5px; border-radius: 5px; font-size: 11.5px; }
.dialog-actions { display: flex; gap: 10px; margin-top: 22px; }
.dialog-actions .ghost { flex: 1; }
.dialog-actions .primary { flex: 1.4; margin-top: 0; }
.note { text-align: center; font-size: 12.5px; color: var(--ok); min-height: 18px; margin: 10px 0 0; }

/* login */
.login { position: fixed; inset: 0; background: rgba(247, 244, 238, .96); backdrop-filter: blur(8px); display: grid; place-items: center; padding: 24px; z-index: 50; }
.login.hidden { display: none; }
.login-box { width: min(360px, 100%); text-align: center; }
.login-box h2 { margin: 0 0 6px; font-size: 24px; letter-spacing: -.03em; }
.login-box p { margin: 0 0 20px; color: var(--muted); font-size: 14px; }
#login-form input { text-align: center; font-size: 22px; letter-spacing: .35em; padding: 14px; }
#login-form .primary { margin-top: 14px; }

/* review */
.review-head { margin: 4px 0 18px; }
.review-head h2 { margin: 9px 0 5px; font-size: 26px; letter-spacing: -.03em; }
.review-head p { margin: 0; color: var(--muted); font-size: 13.5px; }

.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  padding: 16px; margin-bottom: 12px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.panel-head h3 { margin: 0; font-size: 15px; letter-spacing: -.01em; }
.panel > input, .panel > textarea { margin-bottom: 10px; }
.panel .label { margin-top: 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scroll-snap-type: x proximity; }
.scene {
  position: relative; flex: none; width: 92px; height: 132px; border-radius: 12px;
  border: 2px solid transparent; padding: 0; overflow: hidden; background: #14120f;
  cursor: pointer; scroll-snap-align: start;
}
.scene img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: .88; }
.scene span {
  position: absolute; top: 6px; left: 6px; min-width: 20px; height: 20px; border-radius: 7px;
  background: rgba(0, 0, 0, .6); color: #fff; font-size: 11px; font-weight: 700;
  display: grid; place-items: center; padding: 0 5px;
}
.scene em {
  position: absolute; bottom: 5px; left: 5px; right: 5px; font-style: normal;
  font-size: 10.5px; color: #fff; background: rgba(0, 0, 0, .5);
  border-radius: 6px; padding: 2px 5px; text-align: center;
}
.scene.selected { border-color: var(--coral); }
.scene.selected img { opacity: 1; }

.line-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.tab {
  width: 30px; height: 30px; border-radius: 9px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); font: inherit; font-size: 12.5px; cursor: pointer;
}
.tab.selected { background: var(--ink); color: #fdf9f2; border-color: var(--ink); }
.rounds { display: flex; gap: 6px; }

.rewrite { display: flex; gap: 8px; margin: 4px 0 12px; }
.rewrite input { flex: 1; padding: 10px 12px; font-size: 13px; }
.rewrite .mini { flex: none; }
.scene-meta { display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--muted); margin-bottom: 12px; }
.scene-meta span:first-child { min-width: 58px; color: var(--ink); font-weight: 600; }
.scene-meta input[type="range"] { flex: 1; }
.scene-meta span:last-child { min-width: 38px; text-align: right; }
.line-tools { display: flex; gap: 8px; flex-wrap: wrap; }
.line-tools .mini { flex: 1; }
.danger { color: #b3402f; border-color: #eccfc8; }
.ghost.wide { width: 100%; margin-top: 10px; }

.chips.compact { gap: 6px; }
.chips.compact .chip { padding: 8px 12px; font-size: 12.5px; flex-direction: row; }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch {
  width: 34px; height: 34px; border-radius: 50%; border: 3px solid #fff;
  box-shadow: 0 0 0 1px var(--line); cursor: pointer; padding: 0;
}
.swatch.selected { box-shadow: 0 0 0 2px var(--ink); }
.toggles { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 14px; }
.toggle { display: flex; align-items: flex-start; gap: 8px; font-size: 13.5px; }
.toggle input { width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--coral); }
.toggle small { color: var(--muted); font-size: 11.5px; display: block; }
.review-toggle { margin: 18px 0 0; color: var(--ink); }

.upload-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.file-btn { display: inline-flex; align-items: center; cursor: pointer; gap: 6px; }
.audio { width: 100%; margin: 10px 0 2px; height: 38px; }
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  padding: 0; border: 0; background: transparent; box-shadow: none;
  height: 24px; accent-color: var(--coral); cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px; border-radius: 99px; background: #e7dfd2;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 20px; height: 20px; margin-top: -7px; border-radius: 50%;
  background: var(--coral); border: 3px solid #fff;
  box-shadow: 0 2px 6px rgba(43, 42, 38, .22);
}
input[type="range"]::-moz-range-track { height: 6px; border-radius: 99px; background: #e7dfd2; }
input[type="range"]::-moz-range-thumb {
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--coral); border: 3px solid #fff;
}

@media (max-width: 380px) {
  .app { padding-left: 16px; padding-right: 16px; }
  .hero h1 { font-size: 32px; }
}
