:root {
  --bg: #121211; --bg2: #1b1b19; --bg3: #262624; --bg4: #32322f;
  --border: #2f2f2c; --text: #ededea; --text2: #bdbdb8; --text3: #8b8b86;
  --accent: #e9c65c; --accent-ink: #171509; --danger: #e0796f;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
  --app-h: 100vh;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", system-ui, sans-serif;
  overscroll-behavior: none; touch-action: manipulation; }
body { position: fixed; inset: 0; overflow: hidden; }
.app { height: var(--app-h); display: flex; flex-direction: column; overflow: hidden; }
button, input, textarea { font-family: inherit; }
/* 16px is the floor: any smaller and iOS zooms the page in when the field is focused. */
input, textarea { font-size: 16px; }
button { cursor: pointer; }
img { -webkit-user-drag: none; user-select: none; -webkit-user-select: none; }
[hidden] { display: none !important; }
.muted { color: var(--text3); }
.small { font-size: 12.5px; }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 12px 18px;
  border-radius: 12px; border: 1px solid var(--border); background: var(--bg3); color: var(--text); font-size: 15px; font-weight: 500; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 650; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.block { width: 100%; }
.icon-btn { width: 40px; height: 40px; border-radius: 999px; border: 0; background: transparent; color: var(--text); font-size: 22px; display: grid; place-items: center; padding: 0; }
.icon-btn:active { background: var(--bg3); }

/* ── Login ── */
.login { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 32px 24px calc(32px + var(--sab)); gap: 14px; max-width: 420px; width: 100%; margin: 0 auto; }
.login h1 { margin: 0 0 6px; font-size: 26px; font-weight: 700; letter-spacing: -.01em; }
.login h1 small { display: block; font-size: 13px; color: var(--text3); font-weight: 500; letter-spacing: .12em; text-transform: uppercase; margin-bottom: 8px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; color: var(--text3); }
.field input { padding: 13px 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--bg2); color: var(--text); outline: none; }
.field input:focus { border-color: var(--accent); }
.error { color: var(--danger); font-size: 13.5px; min-height: 1.2em; }

/* ── Top bar ── */
.topbar { display: flex; align-items: center; gap: 6px; padding: calc(var(--sat) + 8px) 10px 8px; border-bottom: 1px solid var(--border); background: var(--bg); flex: 0 0 auto; }
.topbar .title { flex: 1; min-width: 0; font-weight: 650; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .title small { display: block; font-size: 12px; color: var(--text3); font-weight: 500; }

/* ── Dashboard ── */
.dash { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 14px 14px calc(24px + var(--sab)); }
.dash .new { margin-bottom: 16px; padding: 15px; font-size: 16px; }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 640px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 960px) { .grid { grid-template-columns: repeat(4, 1fr); } .dash { max-width: 1100px; margin: 0 auto; width: 100%; } }
.card { background: var(--bg2); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; }
.card:active { transform: scale(.985); }
.card .pic { aspect-ratio: 4 / 3; background: #000; display: block; width: 100%; object-fit: cover; }
.card .meta { padding: 9px 11px 11px; }
.card .name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .sub { font-size: 12px; color: var(--text3); margin-top: 2px; display: flex; justify-content: space-between; gap: 6px; }
.empty { text-align: center; color: var(--text3); padding: 40px 20px; line-height: 1.6; }

/* ── Studio ── */
.studio { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.stage { flex: 0 0 48%; position: relative; background: #000; display: flex; align-items: center; justify-content: center; overflow: hidden; }
@media (min-width: 900px) and (orientation: landscape) {
  .studio { flex-direction: row; }
  .stage { flex: 1 1 60%; height: auto; }
  .panel { flex: 0 0 400px; border-left: 1px solid var(--border); }
}
.stage img { max-width: 100%; max-height: 100%; width: auto; height: auto; display: block; }
.stage .tag { position: absolute; left: 10px; bottom: 10px; font-size: 11.5px; padding: 4px 8px; border-radius: 999px; background: rgba(0,0,0,.6); color: #fff; pointer-events: none; }
.stage .tag.dim { color: var(--text2); }
.panel { flex: 1; display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.chat { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 12px 6px; display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: 86%; padding: 9px 12px; border-radius: 16px; font-size: 14.5px; line-height: 1.4; white-space: pre-wrap; word-break: break-word; }
.bubble.me { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 5px; }
.bubble.sys { align-self: flex-start; background: var(--bg3); color: var(--text2); border-bottom-left-radius: 5px; }
.reply { align-self: flex-start; display: flex; align-items: center; gap: 10px; background: var(--bg2); border: 1px solid var(--border); border-radius: 14px; padding: 7px 10px 7px 7px; max-width: 86%; }
.reply img { width: 54px; height: 54px; object-fit: cover; border-radius: 9px; background: #000; }
.reply .t { font-size: 13px; }
.reply .t b { display: block; font-weight: 600; }
.reply.on { border-color: var(--accent); }
.strip { flex: 0 0 auto; display: flex; gap: 8px; padding: 8px 12px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; border-top: 1px solid var(--border); }
.strip::-webkit-scrollbar { display: none; }
.thumb { flex: 0 0 auto; width: 66px; height: 66px; border-radius: 10px; overflow: hidden; position: relative; border: 2px solid transparent; background: #000;
  -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; touch-action: pan-x; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.thumb.cur { border-color: var(--accent); }
.thumb.shown::after { content: ""; position: absolute; inset: 0; border: 2px solid #fff; border-radius: 8px; pointer-events: none; }
.thumb .n { position: absolute; left: 4px; bottom: 3px; font-size: 10px; padding: 1px 5px; border-radius: 999px; background: rgba(0,0,0,.7); color: #fff; }
.thumb.pending { display: grid; place-items: center; color: var(--text3); font-size: 18px; }
.attach-row { display: flex; gap: 8px; padding: 6px 12px 0; overflow-x: auto; }
.attach-row .a { position: relative; flex: 0 0 auto; width: 48px; height: 48px; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }
.attach-row .a img { width: 100%; height: 100%; object-fit: cover; }
.attach-row .a button { position: absolute; top: 1px; right: 1px; width: 18px; height: 18px; border-radius: 999px; border: 0; background: rgba(0,0,0,.75); color: #fff; font-size: 12px; line-height: 1; padding: 0; }
.composer { flex: 0 0 auto; display: flex; align-items: flex-end; gap: 8px; padding: 8px 10px calc(8px + var(--sab)); border-top: 1px solid var(--border); background: var(--bg); }
.composer textarea { flex: 1; resize: none; min-height: 42px; max-height: 120px; padding: 10px 13px; border-radius: 21px; border: 1px solid var(--border); background: var(--bg2); color: var(--text); outline: none; line-height: 1.35; }
.composer textarea:focus { border-color: var(--bg4); }
.composer .round { width: 42px; height: 42px; border-radius: 999px; border: 1px solid var(--border); background: var(--bg3); color: var(--text); font-size: 22px; display: grid; place-items: center; padding: 0; flex: 0 0 auto; }
.composer .round.send { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 700; }
.composer .round:disabled { opacity: .4; }

/* ── Sheets & modals ── */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade .18s ease; }
.backdrop.center { align-items: center; padding: 24px; }
.sheet { width: 100%; max-width: 560px; background: var(--bg2); border: 1px solid var(--border); border-radius: 20px 20px 0 0; padding: 12px 16px calc(18px + var(--sab)); max-height: 92%; overflow-y: auto; animation: rise .22s ease; }
.backdrop.center .sheet { border-radius: 18px; padding-bottom: 18px; max-width: 440px; }
.sheet h2 { margin: 6px 0 12px; font-size: 18px; }
.sheet .grab { width: 38px; height: 4px; border-radius: 4px; background: var(--bg4); margin: 0 auto 10px; }
.opt { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; padding: 14px; border-radius: 14px; border: 1px solid var(--border); background: var(--bg3); color: var(--text); margin-bottom: 10px; }
.opt .ic { font-size: 24px; width: 34px; text-align: center; }
.opt b { display: block; font-size: 15px; }
.opt span { font-size: 12.5px; color: var(--text3); }
.opt:active { background: var(--bg4); }
.opt.danger { color: var(--danger); }
.sheet textarea { width: 100%; min-height: 96px; padding: 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--bg3); color: var(--text); outline: none; resize: none; }
.chips { display: flex; gap: 8px; margin: 10px 0 4px; }
.chip { padding: 8px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--bg3); color: var(--text2); font-size: 13.5px; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.preview { width: 100%; max-height: 38vh; object-fit: contain; border-radius: 12px; background: #000; display: block; margin-bottom: 10px; }
.pick { display: grid; place-items: center; gap: 6px; padding: 26px 12px; border: 1.5px dashed var(--bg4); border-radius: 14px; color: var(--text3); background: var(--bg3); margin-bottom: 10px; }
.row { display: flex; gap: 10px; margin-top: 10px; }
.row .btn { flex: 1; }

/* ── Progress ── */
.progress h3 { margin: 0 0 4px; font-size: 16px; display: flex; gap: 8px; align-items: center; }
.progress h3 .spark { color: var(--accent); animation: spin 2.4s linear infinite; display: inline-block; }
.progress p { margin: 0 0 14px; font-size: 12.5px; color: var(--text3); }
.bar { height: 6px; border-radius: 999px; background: var(--bg3); overflow: hidden; position: relative; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width .12s linear; }
.bar::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, transparent 0, rgba(255,255,255,.28) 50%, transparent 100%); background-size: 200% 100%; animation: shimmer 1.6s linear infinite; mix-blend-mode: screen; }
.steps { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.steps li { display: flex; align-items: center; gap: 10px; font-size: 13.5px; color: var(--text3); }
.steps li .dot { width: 17px; height: 17px; border-radius: 999px; border: 1px solid var(--border); display: grid; place-items: center; font-size: 10px; flex: 0 0 auto; }
.steps li.now { color: var(--text); } .steps li.now .dot { border-color: var(--accent); }
.steps li.now .dot::before { content: ""; width: 7px; height: 7px; border-radius: 999px; background: var(--accent); animation: pulse 1s ease-in-out infinite; }
.steps li.done { color: var(--text2); } .steps li.done .dot { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.steps li.done .dot::before { content: "✓"; }
.progress .ghost { margin-top: 14px; width: 100%; aspect-ratio: 3 / 2; border-radius: 12px; background: linear-gradient(110deg, var(--bg3) 30%, var(--bg4) 50%, var(--bg3) 70%); background-size: 200% 100%; animation: shimmer 1.8s linear infinite; }
.progress .ghost.has { background: #000; overflow: hidden; position: relative; aspect-ratio: auto; }
.progress .ghost.has img { width: 100%; max-height: 34vh; object-fit: contain; display: block; filter: saturate(.6) brightness(.7); }
.progress .ghost.has::after { content: ""; position: absolute; inset: 0; background: linear-gradient(110deg, transparent 30%, rgba(233,198,92,.22) 50%, transparent 70%); background-size: 200% 100%; animation: shimmer 1.8s linear infinite; }
.progress .foot { margin-top: 14px; font-size: 12px; color: var(--text3); display: flex; justify-content: space-between; align-items: center; gap: 10px; }

/* ── Fullscreen ── */
.full { position: fixed; inset: 0; background: #000; z-index: 80; display: flex; align-items: center; justify-content: center; animation: fade .15s ease; }
.full img { max-width: 100%; max-height: 100%; object-fit: contain; -webkit-touch-callout: none; }
.full .x { position: absolute; top: calc(var(--sat) + 10px); right: 12px; width: 42px; height: 42px; border-radius: 999px; border: 0; background: rgba(255,255,255,.14); color: #fff; font-size: 24px; display: grid; place-items: center; padding: 0; backdrop-filter: blur(6px); }
.full .cap { position: absolute; left: 14px; bottom: calc(var(--sab) + 14px); right: 70px; color: #fff; font-size: 12.5px; opacity: .85; text-shadow: 0 1px 2px #000; }

.toast { position: fixed; left: 50%; bottom: calc(var(--sab) + 84px); transform: translateX(-50%); background: var(--bg4); color: var(--text); padding: 9px 14px; border-radius: 999px; font-size: 13.5px; z-index: 90; box-shadow: 0 6px 20px rgba(0,0,0,.4); animation: fade .2s ease; max-width: 90%; text-align: center; }
.toast.err { color: var(--danger); }

@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
@keyframes rise { from { transform: translateY(24px); opacity: 0 } to { transform: none; opacity: 1 } }
@keyframes shimmer { from { background-position: 200% 0 } to { background-position: -200% 0 } }
@keyframes pulse { 0%, 100% { transform: scale(.7); opacity: .6 } 50% { transform: scale(1.1); opacity: 1 } }
@keyframes spin { to { transform: rotate(360deg) } }
