/* StoryForge — mobile-first, professional dark studio. No frameworks. */

:root {
  --bg: #0e1014;
  --panel: #16181f;
  --panel-2: #1c1f28;
  --line: #262a35;
  --text: #eef0f4;
  --muted: #9aa1af;
  --accent: #6e7bff;
  --accent-press: #5a66e6;
  --good: #3ecf8e;
  --warn: #f4b942;
  --bad: #f4645f;
  --radius: 14px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
        Roboto, Inter, sans-serif;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, select { font: inherit; color: inherit; }
h1 { font-size: 22px; font-weight: 700; margin: 4px 4px 14px; letter-spacing: -0.01em; }
h1 span { color: var(--muted); font-size: 14px; font-weight: 500; }
[hidden] { display: none !important; }

/* ---------- wordmark / profile picker ---------- */
.wordmark { font-size: 30px; font-weight: 800; letter-spacing: -0.02em; }
.wordmark span { color: var(--accent); }
.wordmark.small { font-size: 17px; }
.screen { min-height: 100dvh; display: flex; align-items: center; justify-content: center; }
.picker-wrap { width: min(440px, 92vw); text-align: center; padding: 8vh 0; }
.picker-title { font-size: 19px; font-weight: 700; margin: 26px 0 20px; }
.tiles { display: flex; flex-wrap: wrap; gap: 18px; justify-content: center; }
.tile-p { background: none; border: 0; color: var(--text); width: 88px; }
.tile-p .avatar { width: 76px; height: 76px; border-radius: 22px; margin: 0 auto 8px;
  display: flex; align-items: center; justify-content: center; font-size: 30px;
  font-weight: 800; color: #fff; position: relative;
  border: 2px solid transparent; transition: border-color .15s, transform .1s; }
.tile-p:active .avatar { transform: scale(.95); }
.tile-p.sel .avatar { border-color: #fff; }
.tile-p .avatar .lock { position: absolute; right: -4px; bottom: -4px; width: 24px;
  height: 24px; border-radius: 8px; background: var(--panel-2); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center; }
.tile-p .avatar .lock svg { width: 12px; height: 12px; stroke: var(--muted); fill: none; }
.tile-p .pname { font-size: 13.5px; font-weight: 650; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; display: block; }
.tile-p.new .avatar { background: var(--panel-2); border: 1.5px dashed #3a4050;
  color: var(--muted); font-size: 34px; font-weight: 400; }
.pin-form { margin-top: 26px; }
.pin-form p { color: var(--muted); font-size: 14px; margin: 0 0 10px; }
.pin-row { display: flex; gap: 10px; justify-content: center; }
.pin-row input { width: min(220px, 55vw); padding: 12px 14px; border-radius: 10px;
  background: var(--panel-2); border: 1px solid var(--line); outline: none; text-align: center; }
.pin-row input:focus { border-color: var(--accent); }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--sat)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
main { padding: 16px 14px calc(96px + var(--sab)); max-width: 640px; margin: 0 auto; }
.view { animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

/* ---------- fields ---------- */
.field { display: block; margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted);
  margin-bottom: 7px; letter-spacing: .01em; }
.field > span b { color: var(--text); float: right; font-variant-numeric: tabular-nums; }
.field > span i, .switch-row i { color: var(--muted); font-style: normal; font-weight: 400; display: block; font-size: 12px; }
input[type="text"], input[type="url"], input[type="password"], select {
  width: 100%; padding: 12px 14px; border-radius: 10px;
  background: var(--panel-2); border: 1px solid var(--line); outline: none;
  transition: border-color .15s;
  appearance: none; -webkit-appearance: none;
}
input:focus, select:focus { border-color: var(--accent); }
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
  linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px; background-repeat: no-repeat; }

input[type="range"] { width: 100%; accent-color: var(--accent); height: 32px; }

.split { display: grid; grid-template-columns: 1fr 1.4fr; gap: 14px; }

.stepper { display: flex; align-items: center; gap: 4px; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 10px; padding: 4px; }
.stepper button { flex: 1; min-height: 38px; background: none; border: 0; border-radius: 8px;
  font-size: 20px; color: var(--text); }
.stepper button:active { background: var(--line); }
.stepper b { min-width: 28px; text-align: center; font-variant-numeric: tabular-nums; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-opt { padding: 9px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--muted); font-size: 14px; font-weight: 600; }
.chip-opt.on { background: color-mix(in srgb, var(--accent) 18%, var(--panel-2));
  border-color: var(--accent); color: var(--text); }

.switch-row { display: flex; align-items: center; justify-content: space-between;
  gap: 14px; padding: 10px 0; }
.switch-row span { font-size: 14.5px; font-weight: 600; }
.switch { appearance: none; -webkit-appearance: none; width: 50px; height: 30px; flex: none;
  border-radius: 999px; background: var(--line); position: relative; transition: background .18s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px;
  border-radius: 50%; background: #fff; transition: transform .18s; }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(20px); }

.adv summary { font-size: 14px; font-weight: 600; color: var(--muted); padding: 6px 0;
  cursor: pointer; list-style: none; }
.adv summary::before { content: "›"; display: inline-block; margin-right: 8px;
  transition: transform .15s; }
.adv[open] summary::before { transform: rotate(90deg); }
.adv[open] { padding-top: 4px; }

/* ---------- buttons ---------- */
.btn { border: 0; border-radius: 12px; padding: 13px 18px; font-weight: 700;
  background: var(--panel-2); color: var(--text); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:active { background: var(--accent-press); }
.btn.block { display: block; width: 100%; }
.btn.big { padding: 16px; font-size: 17px; }
.btn:disabled { opacity: .45; }
.linkish { background: none; border: 0; color: var(--accent); font-weight: 600; padding: 4px; }
.chip { border: 1px solid var(--line); background: var(--panel); color: var(--text);
  border-radius: 999px; padding: 6px 13px; font-size: 13.5px; font-weight: 650; }

.hint { font-size: 13px; color: var(--muted); text-align: center; margin: 12px 0 0; }
.hint.err { color: var(--bad); font-weight: 600; }
.empty { color: var(--muted); text-align: center; padding: 40px 20px; }

/* ---------- drop zone ---------- */
.drop { border: 1.5px dashed #343a48; border-radius: 12px; padding: 26px 16px;
  text-align: center; background: var(--panel-2); }
.drop.picked { border-style: solid; border-color: var(--good); }
.drop-idle strong, .drop-picked strong { display: block; margin-top: 8px; }
.drop .sub { color: var(--muted); font-size: 13px; }
.drop-picked { display: flex; align-items: center; justify-content: center; gap: 10px; }
.drop-picked strong { margin: 0; max-width: 60%; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; }
.drop-picked .ic { color: var(--good); }
.or { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 12px;
  margin: 14px 0; text-transform: uppercase; letter-spacing: .08em; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.ic { width: 22px; height: 22px; fill: none; stroke: currentColor; }
.ic.big { width: 34px; height: 34px; color: var(--accent); }

/* ---------- job cards ---------- */
.stack { display: flex; flex-direction: column; gap: 12px; }
.job { display: block; }
.job .row { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.job .title { font-weight: 700; font-size: 15.5px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; }
.job .who { color: var(--muted); font-size: 12.5px; }
.pill { font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; flex: none; }
.pill.queued { background: #2a2e3a; color: var(--muted); }
.pill.running { background: color-mix(in srgb, var(--accent) 22%, transparent); color: #aeb5ff; }
.pill.done { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); }
.pill.error { background: color-mix(in srgb, var(--bad) 18%, transparent); color: var(--bad); }
.bar { height: 6px; border-radius: 4px; background: var(--panel-2); margin: 12px 0 8px;
  overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 4px;
  transition: width .6s ease; }
.job .note { color: var(--muted); font-size: 13px; }
.job .actions { display: flex; gap: 10px; margin-top: 10px; }

/* ---------- gallery ---------- */
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, 1fr); } }
.tile { position: relative; border-radius: 12px; overflow: hidden; background: var(--panel);
  border: 1px solid var(--line); aspect-ratio: 9/13.5; text-align: left; padding: 0; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .tmeta { position: absolute; inset: auto 0 0 0; padding: 22px 10px 9px;
  background: linear-gradient(transparent, rgba(8,9,12,.88)); }
.tile .tmeta b { display: block; font-size: 13px; line-height: 1.25; max-height: 2.5em;
  overflow: hidden; }
.tile .tmeta span { font-size: 11.5px; color: #c6cad3; }
.tile .score { position: absolute; top: 8px; right: 8px; background: rgba(8,9,12,.75);
  border-radius: 8px; padding: 2px 8px; font-size: 12px; font-weight: 800; color: var(--good); }
.tile .noposter { display: flex; align-items: center; justify-content: center; height: 100%;
  color: var(--muted); }

/* ---------- tab bar ---------- */
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; justify-content: space-around;
  padding: 8px 10px calc(8px + var(--sab));
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line); }
.tab { position: relative; flex: 1; max-width: 130px; background: none; border: 0;
  color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 5px 0; font-size: 11.5px; font-weight: 650; border-radius: 10px; }
.tab.active { color: var(--accent); }
.tab i { position: absolute; top: 2px; right: 24%; min-width: 17px; height: 17px;
  border-radius: 999px; background: var(--accent); color: #fff; font-style: normal;
  font-size: 11px; font-weight: 800; display: flex; align-items: center;
  justify-content: center; padding: 0 4px; }

/* ---------- bottom sheet ---------- */
.sheet { position: fixed; inset: 0; z-index: 50; background: rgba(4,5,8,.6);
  display: flex; align-items: flex-end; justify-content: center;
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.sheet-card { width: min(640px, 100%); max-height: 92dvh; overflow-y: auto;
  background: var(--panel); border-radius: 18px 18px 0 0; border: 1px solid var(--line);
  border-bottom: 0; padding: 8px 16px calc(20px + var(--sab));
  animation: rise .22s ease; overscroll-behavior: contain; touch-action: pan-y; }
@keyframes rise { from { transform: translateY(40px); opacity: .6; } }
.sheet-grab { width: 42px; height: 5px; border-radius: 3px; background: var(--line);
  margin: 6px auto 12px; }
.sheet video { width: 100%; max-height: 58dvh; border-radius: 12px; background: #000; }
.sheet h2 { font-size: 17px; margin: 12px 2px 4px; }
.sheet .meta-row { color: var(--muted); font-size: 13px; margin: 0 2px 12px; }
.dl-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.dl-row .btn { flex: 1 1 30%; font-size: 13.5px; padding: 11px 8px; text-align: center;
  text-decoration: none; color: var(--text); }
.copyblock { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px; margin: 8px 0; }
.copyblock header { display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 6px; }
.copyblock header b { font-size: 13px; text-transform: capitalize; }
.copyblock p { margin: 0; font-size: 13.5px; white-space: pre-wrap; word-break: break-word;
  color: #cdd2dc; }
.seg { display: flex; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 3px; margin: 10px 0; }
.seg button { flex: 1; border: 0; background: none; color: var(--muted); padding: 8px;
  border-radius: 8px; font-weight: 650; font-size: 13.5px; }
.seg button.on { background: var(--accent); color: #fff; }

/* ---------- v2: entry / style cards / voice ---------- */
.entry .drop { margin-bottom: 10px; }
#url-row { display: flex; gap: 12px; align-items: center; }
#url-row input { margin-top: 2px; flex: 1; }
#paste-btn { font-size: 13.5px; white-space: nowrap; }

.style-cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.scard { text-align: left; background: var(--panel-2); border: 1.5px solid var(--line);
  border-radius: 12px; padding: 12px 12px 11px; color: var(--text); position: relative;
  transition: border-color .12s; }
.scard.on { border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, var(--panel-2)); }
.scard b { display: block; font-size: 14.5px; margin-bottom: 3px; }
.scard span { display: block; font-size: 12px; color: var(--muted); line-height: 1.35; }

.voice-row { display: flex; align-items: center; justify-content: space-between;
  padding: 13px 0 3px; }
.voice-row .vr-label { display: block; font-size: 13px; font-weight: 600;
  color: var(--muted); margin-bottom: 3px; }
.voice-row b { font-size: 15px; }
.voice-row i { color: var(--muted); font-style: normal; font-size: 13px; margin-left: 6px; }
.voice-list { margin-top: 10px; border-top: 1px solid var(--line); }
.vrow { display: flex; align-items: center; gap: 12px; padding: 11px 2px;
  border-bottom: 1px solid var(--line); }
.vrow:last-child { border-bottom: 0; }
.vrow .vplay { width: 40px; height: 40px; flex: none; border-radius: 50%;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  display: flex; align-items: center; justify-content: center; }
.vrow .vplay.playing { background: var(--accent); border-color: var(--accent); color: #fff; }
.vrow .vmeta { flex: 1; min-width: 0; }
.vrow .vmeta b { font-size: 14.5px; }
.vrow .vmeta small { display: block; color: var(--muted); font-size: 12.5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vrow .vpick { flex: none; }
.vrow.sel .vpick { color: var(--accent); font-weight: 800; }

.ref-file-row { margin-top: 8px; display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--muted); }
h1 { margin-top: 10px; }
