:root {
  --bg: #101310;
  --panel: #1a201b;
  --panel-2: #242d24;
  --line: #384338;
  --line-2: #465346;
  --text: #eff5ec;
  --muted: #a7b4a5;
  --accent: #bdf46d;
  --accent-2: #a9de62;
  --accent-soft: rgba(189, 244, 109, .14);
  --ok: #3ccf91;
  --warn: #f5b041;
  --err: #ff5c6c;
  --radius: 12px;
  --radius-sm: 8px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { height: 100%; scrollbar-gutter: stable; }
html, body { margin: 0; }
body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h2 { font-size: 16px; margin: 0; font-weight: 650; }
h3 { font-size: 15px; margin: 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.pad { padding: 16px; }
[hidden] { display: none !important; }

button, .filebtn, select, input, textarea { font: inherit; color: inherit; }
button, .filebtn {
  cursor: pointer;
  border: 1px solid var(--line-2);
  background: var(--panel-2);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  transition: background .15s, border-color .15s, opacity .15s;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  white-space: nowrap;
}
button:hover, .filebtn:hover { border-color: var(--muted); }
button:disabled { opacity: .45; cursor: not-allowed; }
.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: #182115;
  font-weight: 650;
}
.primary:hover { border-color: transparent; filter: brightness(1.08); }
.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.ghost:hover { color: var(--text); border-color: var(--line-2); }
.sm { padding: 5px 10px; font-size: 13px; }
.danger { color: var(--err); }

input[type=text], input[type=search], input[type=password], input[type=number], input[type=url], select, textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  outline: none;
}
textarea { resize: vertical; min-height: 60px; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; padding: 3px 9px; border-radius: 99px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted);
}

/* ---------- header ---------- */
.top {
  height: 56px; display: flex; align-items: center; gap: 18px;
  padding: 0 16px; border-bottom: 1px solid var(--line); background: var(--panel);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 15px; white-space: nowrap; }
.brand img { width: 26px; height: 26px; }
.brand b { color: var(--accent); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.top-right form { margin: 0; }
.tabs { display: flex; gap: 2px; }
.tabs button { background: transparent; border-color: transparent; color: var(--muted); }
.tabs button.on { color: var(--text); background: var(--panel-2); border-color: var(--line); }

.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 5px 12px; border-radius: 7px; }
.seg button.on { background: var(--panel-2); color: var(--text); box-shadow: 0 1px 0 var(--line-2) inset; }
.seg.sm button { padding: 3px 9px; font-size: 12.5px; }
.seg .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); display: inline-block; }
.seg .dot.ok { background: var(--ok); }

/* ---------- generate layout ---------- */
.gen {
  display: grid;
  grid-template-columns: 280px minmax(360px, 460px) 1fr;
  height: calc(100dvh - var(--header-height, 56px));
}
.models, .form-pane, .results { min-height: 0; overflow: auto; }
.models { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; }
.models-toggle { display: none; }
.models-body { display: flex; flex-direction: column; min-height: 0; flex: 1; padding: 12px; gap: 10px; }
.seg.scope { display: flex; }
.seg.scope button { flex: 1; }
.cats { display: flex; flex-wrap: wrap; gap: 5px; }
.cats button { padding: 3px 9px; font-size: 12px; border-radius: 99px; background: transparent; color: var(--muted); }
.cats button.on { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }
.model-list { overflow: auto; flex: 1; margin: 0 -6px; }
.model-item {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; align-items: center;
  width: 100%; text-align: left; border: 1px solid transparent; background: transparent;
  padding: 8px 10px; border-radius: var(--radius-sm); white-space: normal;
}
.model-item:hover { background: var(--panel-2); border-color: transparent; }
.model-item.on { background: var(--accent-soft); border-color: var(--accent); }
.model-item .mname { font-weight: 550; overflow-wrap: anywhere; }
.model-item .mid { grid-column: 1 / -1; font-size: 11.5px; color: var(--muted); overflow-wrap: anywhere; }
.model-item .mprice { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.star { border: 0; background: none; padding: 0 2px; color: var(--muted); font-size: 14px; }
.star.on { color: var(--warn); }
.list-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 10px 10px 4px; }

.form-pane { border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.form-pane, .models, .results { min-width: 0; }
.job-price { padding: 0 12px 10px; color: var(--muted); font-size: 12px; }
.compact-progress { padding: 0 12px 14px; display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.form-head { padding: 16px 18px 6px; }
.form-head .t { font-size: 17px; font-weight: 650; }
.form-head .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.form-head .desc { color: var(--muted); font-size: 12.5px; margin-top: 8px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.char-bar { padding: 8px 18px 0; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.char-pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 3px; border-radius: 99px; font-size: 12.5px; }
.char-pill img { width: 24px; height: 24px; border-radius: 50%; object-fit: cover; }

#genForm { padding: 8px 18px 18px; display: flex; flex-direction: column; gap: 14px; flex: 1; }
.field label.lbl { display: flex; justify-content: space-between; gap: 8px; font-weight: 550; font-size: 13px; margin-bottom: 6px; }
.field .req { color: var(--accent-2); margin-left: 2px; }
.field .hint { font-weight: 400; color: var(--muted); font-size: 12px; }
.field .help { color: var(--muted); font-size: 12px; margin-top: 5px; }
.group { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.group > summary { cursor: pointer; padding: 10px 14px; font-weight: 600; list-style: none; display: flex; justify-content: space-between; }
.group > summary::-webkit-details-marker { display: none; }
.group > summary::after { content: "▾"; color: var(--muted); transition: transform .15s; }
.group:not([open]) > summary::after { transform: rotate(-90deg); }
.group-body { padding: 4px 14px 14px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.group-body .field.wide { grid-column: 1 / -1; }
.fold-heading { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.fold-label { font-size: 13px; }
.fold-summary { font-size: 11px; color: var(--muted); font-weight: 400; white-space: normal; overflow-wrap: anywhere; }
.form-fold[open] .fold-summary { display: none; }
.form-fold>summary { align-items: center; gap: 12px; min-height: 48px; }
.char-bar.refs-folded { display: none; }

.pills { display: flex; flex-wrap: wrap; gap: 5px; }
.pills button { padding: 5px 10px; font-size: 12.5px; background: var(--bg); color: var(--muted); }
.pills button.on { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }

.slider { display: flex; align-items: center; gap: 10px; }
.slider input[type=range] { flex: 1; accent-color: var(--accent); }
.slider input[type=number] { width: 84px; }

.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { appearance: none; width: 38px; height: 22px; background: var(--line-2); border-radius: 99px; position: relative; margin: 0; cursor: pointer; transition: background .15s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; background: #fff; border-radius: 50%; transition: transform .15s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(16px); }

.seed { display: flex; gap: 6px; }
.seed input { flex: 1; }

/* media dropzone */
.drop {
  border: 1.5px dashed var(--line-2); border-radius: var(--radius); padding: 10px;
  background: var(--panel); transition: border-color .15s, background .15s;
}
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop .thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 10px; }
.drop .thumbs:empty { display: none; }
.drop .thumbs:not(:empty) + .drop-actions { margin-top: 10px; }
.thumb { position: relative; aspect-ratio: 1; border-radius: var(--radius-sm); overflow: hidden; background: var(--panel-2); border: 1px solid var(--line); }
.thumb img, .thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.video-thumb-wrap { position: relative; width: 100%; height: 100%; }
.video-thumb-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.video-badge { position: absolute; top: 4px; left: 4px; font-size: 9px; font-weight: 600; padding: 1px 5px; border-radius: 4px; background: rgba(0,0,0,.75); color: #fff; z-index: 1; }
.thumb .x { position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; padding: 0; border-radius: 50%; background: rgba(0,0,0,.65); border: 0; color: #fff; font-size: 12px; }
.thumb .badge { position: absolute; left: 4px; bottom: 4px; max-width: calc(100% - 8px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; padding: 1px 5px; border-radius: 4px; background: rgba(0,0,0,.65); color: #fff; }
.thumb .mv { position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; padding: 0; border-radius: 50%; background: rgba(0,0,0,.65); border: 0; color: #fff; font-size: 14px; line-height: 1; }
.drop .legend { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 8px; font-size: 12px; color: var(--muted); }
.drop .legend button { padding: 2px 8px; font-size: 12px; }
.char .refs { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.char .ref { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.char .ref input { padding: 4px 6px; font-size: 12px; }
.thumb.audio { display: grid; place-items: center; font-size: 22px; }
.thumb.loading::after { content: ""; position: absolute; inset: 0; background: rgba(0,0,0,.45) ; }
.drop-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.drop-actions .muted { font-size: 12px; margin-left: auto; }

.gen-bar {
  position: sticky; bottom: 0; display: flex; align-items: center; gap: 12px;
  padding: 12px 18px; border-top: 1px solid var(--line); background: var(--panel);
}
.gen-bar .count { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.gen-bar .count select { width: auto; padding: 6px 8px; }
.gen-bar .cost { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.gen-bar .primary { margin-left: auto; padding: 10px 26px; font-size: 15px; }
.form-error { margin: 0 18px 14px; padding: 10px 12px; border-radius: var(--radius-sm); background: rgba(255, 92, 108, .12); color: var(--err); font-size: 13px; }

/* results */
.results { padding: 16px 18px; }
.results-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.jobs { display: flex; flex-direction: column; gap: 14px; }
.job { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); overflow: hidden; }
.job-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; flex-wrap: wrap; }
.job-head .jm { font-weight: 600; }
.job-head .jt { color: var(--muted); font-size: 12px; margin-left: auto; font-variant-numeric: tabular-nums; }
.status { font-size: 11.5px; padding: 2px 8px; border-radius: 99px; display: inline-flex; align-items: center; gap: 5px; }
.status.running { background: var(--accent-soft); color: var(--accent); }
.status.completed { background: rgba(60, 207, 145, .13); color: var(--ok); }
.status.failed { background: rgba(255, 92, 108, .13); color: var(--err); }
.spin { width: 10px; height: 10px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.job-prompt { padding: 0 12px 10px; color: var(--muted); font-size: 12.5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.job-err { margin: 0 12px 10px; color: var(--err); font-size: 12.5px; overflow-wrap: anywhere; }
.outs { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; padding: 0 12px 12px; }
.gen .outs { grid-template-columns: minmax(0, 1fr); }
.gen .outs:has(>.out:nth-child(2)) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.out { position: relative; border-radius: var(--radius-sm); overflow: hidden; background: var(--panel-2); }
.out img, .out video { width: 100%; display: block; max-height: 520px; object-fit: contain; background: #000; cursor: zoom-in; }
.out .out-actions { position: absolute; right: 6px; top: 6px; display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.out:hover .out-actions, .out:focus-within .out-actions { opacity: 1; }
.out .out-actions a, .out .out-actions button { background: rgba(0,0,0,.7); border: 0; color: #fff; padding: 4px 8px; border-radius: 6px; font-size: 12px; text-decoration: none; }
.out pre { padding: 10px; margin: 0; white-space: pre-wrap; font-size: 12px; }
.placeholder { aspect-ratio: 9 / 16; max-height: 360px; display: grid; place-items: center; color: var(--muted); font-size: 12.5px; background: linear-gradient(110deg, var(--panel-2) 30%, var(--line) 50%, var(--panel-2) 70%); background-size: 200% 100%; animation: shimmer 1.6s linear infinite; border-radius: var(--radius-sm); }
@keyframes shimmer { to { background-position: -200% 0; } }
.job-foot { display: flex; gap: 4px; padding: 0 8px 8px; flex-wrap: wrap; }
.empty { text-align: center; color: var(--muted); padding: 60px 20px; border: 1px dashed var(--line-2); border-radius: var(--radius); }

/* library / settings */
.page { max-width: 1200px; margin: 0 auto; padding: 22px 16px 60px; display: flex; flex-direction: column; gap: 30px; }
.page.narrow { max-width: 620px; gap: 12px; }
.sec-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.sec-head h2 { margin-right: auto; }
.chars { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; margin-top: 10px; }
.char { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.char .row { display: flex; gap: 8px; align-items: center; }
.char .row input { font-weight: 600; }
.char .thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); gap: 6px; }
.asset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; margin-top: 10px; }
.asset-grid .thumb { cursor: pointer; }
.asset-grid .thumb.sel { outline: 2px solid var(--accent); outline-offset: 2px; }
.asset-grid .thumb .check { position: absolute; top: 5px; left: 5px; width: 20px; height: 20px; border-radius: 50%; background: var(--accent); color: #fff; display: none; place-items: center; font-size: 12px; }
.asset-grid .thumb.sel .check { display: grid; }
.dl-form { display: flex; gap: 10px; align-items: stretch; margin-top: 10px; }
.dl-form textarea { min-height: 46px; flex: 1; font-size: 13px; }
.dl-form .primary { padding: 10px 26px; font-size: 15px; }
.dl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; margin-top: 10px; }
.dl { display: flex; flex-direction: column; }
.dl video { width: 100%; aspect-ratio: 9 / 16; object-fit: contain; background: #000; display: block; }
.dl .placeholder { max-height: none; border-radius: 0; }
.dl .placeholder.stopped { animation: none; background: var(--panel-2); }
.dl-body { display: flex; flex-direction: column; flex: 1; }
.dl-title { padding: 0 12px; font-size: 12.5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.dl-meta { padding: 4px 12px 8px; font-size: 12px; font-variant-numeric: tabular-nums; }
.dl .job-err { margin-top: 4px; }
.dl .job-foot { margin-top: auto; padding: 4px 12px 12px; gap: 6px; }
a.btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line-2); border-radius: var(--radius-sm); padding: 5px 10px; font-size: 13px; color: var(--text); background: var(--panel-2); white-space: nowrap; }
a.btn.primary { color: #182115; border-color: transparent; background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
a.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
a.btn.ghost:hover { color: var(--text); border-color: var(--line-2); }
.keys { display: flex; flex-direction: column; gap: 16px; }
.key-card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.key-card .row { display: flex; gap: 8px; }
.key-card label.field { display: flex; flex-direction: column; }
.key-card .field .lbl { font-weight: 550; font-size: 13px; margin-bottom: 6px; }

/* modal, lightbox, toast */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; width: min(860px, 100%); max-height: 88vh; display: flex; flex-direction: column; }
.modal-head, .modal-foot { padding: 12px 16px; display: flex; align-items: center; gap: 8px; }
.modal-head { border-bottom: 1px solid var(--line); justify-content: space-between; }
.modal-foot { border-top: 1px solid var(--line); justify-content: flex-end; }
.modal-foot:empty { display: none; }
.modal-body { padding: 14px 16px; overflow: auto; }
.modal-body h4 { margin: 14px 0 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.modal-body h4:first-child { margin-top: 0; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 60; display: grid; place-items: center; padding: 20px; cursor: zoom-out; }
.lightbox img, .lightbox video { max-width: 100%; max-height: 100%; object-fit: contain; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--line-2); padding: 10px 16px; border-radius: 10px; z-index: 70; box-shadow: 0 8px 30px rgba(0,0,0,.35); max-width: calc(100% - 32px); }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .gen { grid-template-columns: 260px 1fr; grid-template-rows: auto; height: auto; }
  .results { grid-column: 1 / -1; border-top: 1px solid var(--line); }
  .top { height: auto; flex-wrap: wrap; padding: 10px 16px; gap: 8px 16px; }
  .top-right { order: 2; }
  .tabs { order: 3; flex-basis: 100%; }
  .models { max-height: calc(100dvh - var(--header-height, 56px)); position: sticky; top: var(--header-height, 56px); }
  .form-pane { border-right: 0; }
}
@media (max-width: 760px) {
  .top { padding: 10px 12px 0; gap: 8px; }
  .tabs { order: 4; width: 100%; gap: 0; padding: 0; }
  .tabs button { flex: 1; min-width: 0; min-height: 42px; padding: 10px 3px; font-size: 11px; border-radius: 7px 7px 0 0; }
  .tabs button.on { background: var(--accent-soft); color: var(--accent); border-color: transparent; box-shadow: inset 0 -2px var(--accent); }
  .gen { display: block; }
  .models { position: static; max-height: none; border-right: 0; border-bottom: 1px solid var(--line); }
  .models-toggle { display: flex; justify-content: space-between; width: 100%; border: 0; border-radius: 0; padding: 12px 16px; background: var(--panel); }
  .models:not(.open) .models-body { display: none; }
  .models.open .model-list { max-height: 55vh; }
  .models-body { padding: 0 16px 12px; }
  #genForm, .form-head, .char-bar { padding-left: 16px; padding-right: 16px; }
  .gen-bar { padding: 10px 16px; }
  .group-body { grid-template-columns: 1fr; }
  .results { padding: 16px; }
  .outs { grid-template-columns: repeat(2, 1fr); }
  .out .out-actions { opacity: 1; }
  .dl-form { flex-direction: column; }
  .dl-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
}

/* hidden photos */
.thumb .eye { position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; padding: 0; border-radius: 50%; background: rgba(0,0,0,.65); border: 0; font-size: 12px; opacity: 0; transition: opacity .15s; }
.thumb .use-ref { position: absolute; bottom: 3px; right: 3px; padding: 2px 6px; border-radius: 4px; background: rgba(0,0,0,.75); border: 1px solid rgba(255,255,255,.2); color: #fff; font-size: 10px; font-weight: 500; opacity: 0; transition: opacity .15s; z-index: 2; cursor: pointer; }
.thumb:hover .eye, .thumb:focus-within .eye, .thumb:hover .use-ref, .thumb:focus-within .use-ref { opacity: 1; }
.thumb.blur img, .thumb.blur video { filter: blur(14px) saturate(.6); transform: scale(1.08); }
.thumb.broken { border-color: var(--err, #e53e3e); opacity: 0.7; }
.thumb.broken::after { content: '⚠'; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-size: 18px; color: #e53e3e; }
@media (hover: none) { .thumb .eye, .thumb .use-ref { opacity: 1; } }

/* Saved results: video-first gallery and a dedicated media viewer. */
.gallery-page { max-width: 1500px; gap: 16px; }
.gallery-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.gallery-heading h1 { font-size: 26px; margin: 0; letter-spacing: -.6px; }
.gallery-heading p { margin: 5px 0 0; font-size: 13px; }
.storage-summary { display: flex; flex-direction: column; gap: 3px; font-size: 12px; }
.storage-summary>.muted { font-size: 10px; }
.gallery-delete { width: fit-content; min-height: 36px; margin-top: 5px; }
.delete-dialog { width: min(460px, calc(100% - 32px)); padding: 24px; background: var(--panel); border: 1px solid var(--line-2); border-radius: 14px; color: var(--text); }
.delete-dialog::backdrop { background: #000c; }
.delete-dialog p { font-size: 13px; line-height: 1.6; }
.delete-dialog>div { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.delete-dialog button { min-height: 44px; }
#deleteConfirm { background: #ff5c6c20; border-color: var(--err); }
.gallery-toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.gallery-toolbar input { flex: 1; min-width: 180px; }
.gallery-toolbar select { width: auto; }
.gallery-activity { border: 1px solid var(--line); border-radius: 10px; padding: 12px; color: var(--muted); font-size: 13px; }
.gallery-display { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.gallery-display>.muted { font-size: 12px; }
.gallery-display .seg button { min-width: 42px; min-height: 38px; font-size: 20px; line-height: 1; }
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 16px; align-items: start; }
.gallery-grid[data-layout="large"] { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
.gallery-card { min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.gallery-media { position: relative; aspect-ratio: 9 / 13; background: #070709; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.gallery-media video, .gallery-media img { width: 100%; height: 100%; object-fit: contain; display: block; }
.gallery-media video { max-height: 560px; }
.gallery-image { width: 100%; height: 100%; border: 0; padding: 0; border-radius: 0; background: transparent; }
.gallery-card-body { padding: 14px; }
.gallery-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.gallery-card-head b { overflow-wrap: anywhere; }
.gallery-date { display: block; font-size: 12px; margin-top: 5px; }
.gallery-price { display: block; margin-top: 4px; font-size: 10px; color: var(--muted); }
.group-variants { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); }
.group-variants input { width: 18px; height: 18px; accent-color: var(--accent); }
.variant-group { grid-column: 1 / -1; border: 1px solid var(--line); border-radius: 13px; padding: 12px; min-width: 0; }
.variant-heading { margin-bottom: 12px; font-size: 12px; font-weight: 600; color: var(--muted); }
.variant-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 16px; }
[data-layout="large"] .variant-grid { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
.cost-overview { border: 1px solid var(--line); border-radius: 10px; }
.cost-overview>summary { cursor: pointer; padding: 12px; font-size: 12px; }
.cost-overview-body { padding: 0 12px 12px; font-size: 12px; }
.cost-overview-body h3 { font-size: 12px; margin-top: 18px; }
.cost-overview-body p { font-size: 11px; line-height: 1.6; }
.cost-row { display: flex; flex-wrap: wrap; gap: 4px 12px; justify-content: space-between; border-bottom: 1px solid var(--line); padding: 8px 0; }
.cost-row>span:last-child { color: var(--muted); }
.cost-overview-body small { display: block; margin-top: 12px; }
.storage-open { align-self: flex-start; }
.storage-dialog { width: min(760px, calc(100% - 32px)); max-height: calc(100dvh - 32px); color: var(--text); background: var(--panel); border: 1px solid var(--line-2); border-radius: 14px; padding: 0; }
.storage-dialog::backdrop { background: #000d; }
#storageBody { padding: 18px; }
.storage-total { display: flex; flex-direction: column; gap: 4px; }
.storage-total>b { font-size: 32px; }
.storage-total>span { color: var(--muted); font-size: 12px; }
.storage-limit, .storage-cleanup p { font-size: 12px; line-height: 1.7; }
.storage-categories { margin: 12px 0 24px; }
.storage-categories>div { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.storage-cleanup { border: 1px solid var(--line); padding: 14px; border-radius: 10px; margin: 0 0 24px; }
.storage-cleanup>div { display: flex; gap: 7px; flex-wrap: wrap; }
.storage-cleanup button { min-height: 44px; font-size: 12px; }
.storage-files { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.storage-files button { display: flex; justify-content: space-between; gap: 10px; padding: 12px; text-align: left; min-height: 60px; }
.storage-files button>span:first-child { flex: 1; min-width: 0; white-space: normal; }
.storage-files small { display: block; font-size: 11px; color: var(--muted); margin-top: 4px; }
.storage-files button>b { font-size: 12px; }
@media (max-width:900px) {
  .gen { display: block; }
  .models { position: static; max-height: none; border-right: 0; border-bottom: 1px solid var(--line); }
  .models-toggle { display: flex; justify-content: space-between; width: 100%; border: 0; border-radius: 0; padding: 12px 16px; background: var(--panel); }
  .models:not(.open) .models-body { display: none; }
  .models.open .model-list { max-height: 50dvh; }
  .models-body { padding: 0 16px 12px; }
  .form-pane { overflow: visible; }
  .gen-bar { position: static; }
  #genForm textarea, #genForm select, #genForm input:not([type=range]):not([type=checkbox]) { font-size: 16px; }
}
@media (max-width:760px) {
  .variant-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  [data-layout="large"] .variant-grid { grid-template-columns: minmax(0, 1fr); }
  .variant-group { padding: 8px; }
  .variant-heading { line-height: 1.6; }
  .storage-dialog { width: 100%; max-width: 100%; height: 100dvh; max-height: 100dvh; border: 0; border-radius: 0; margin: 0; }
}
.gallery-prompt { color: var(--muted); font-size: 13px; margin: 12px 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.gallery-card-actions { display: flex; gap: 8px; }
.gallery-card-actions button, .gallery-card-actions a { flex: 1; min-height: 42px; }
.gallery-play { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; border-radius: 0; padding: 0; background: linear-gradient(0deg,rgba(0,0,0,.35),transparent 35%); }
.gallery-play span { display: grid; place-items: center; width: 44px; height: 44px; border: 1px solid #ffffff60; border-radius: 50%; background: #13191370; color: white; font-size: 15px; padding-left: 3px; backdrop-filter: blur(8px); box-shadow: 0 2px 18px #0003; }
.gallery-play:hover { background-color: #bdf46d14; }
.gallery-media:has(video[controls]) > .gallery-play { display: none; }
.gallery-duration { position: absolute; bottom: 9px; right: 9px; padding: 2px 6px; border-radius: 4px; background: #0009; color: #fff; font-size: 11px; font-variant-numeric: tabular-nums; pointer-events: none; }
[data-layout="grid"] .gallery-card-body { padding: 11px; }
[data-layout="grid"] .gallery-card-head b { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
[data-layout="grid"] .gallery-card-head .chip, [data-layout="grid"] .gallery-card-actions { display: none; }
[data-layout="grid"] .gallery-date { font-size: 11px; }
[data-layout="large"] .gallery-play, [data-layout="large"] .gallery-duration { display: none; }
.gallery-empty { grid-column: 1 / -1; }
.review-filters { display: flex; gap: 7px; flex-wrap: wrap; }
.review-filters button { min-height: 38px; font-size: 12px; padding: 6px 11px; border-radius: 99px; background: transparent; color: var(--muted); }
.review-filters button>span { font-size: 10px; border-radius: 99px; padding: 1px 5px; background: var(--panel-2); }
.review-filters button.on { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }
.review-badge { display: inline-flex; width: fit-content; align-items: center; max-width: 100%; border-radius: 5px; padding: 3px 7px; margin-bottom: 8px; font-size: 10px; color: var(--muted); background: var(--panel-2); }
.review-badge[data-review="ready"] { background: #3ccf911c; color: #3ccf91; }
.review-badge[data-review="polish"] { background: #f5b0411c; color: #f5b041; }
.review-badge[data-review="rejected"] { background: #ff5c6c1c; color: #ff7b87; }
.viewer-review { padding: 16px 18px; border-bottom: 1px solid var(--line); }
.review-title { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.review-title h3 { font-size: 13px; }
#reviewSaveState { font-size: 11px; color: var(--muted); }
.review-choices { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.review-choices button { min-height: 44px; padding: 10px; font-size: 12px; white-space: normal; }
.review-choices button>span { font-size: 17px; }
.review-choices button.on { border-color: var(--accent); background: var(--accent-soft); }
.review-choices button.on[data-review="ready"] { border-color: var(--ok); background: #3ccf911c; color: var(--ok); }
.review-choices button.on[data-review="polish"] { border-color: var(--warn); background: #f5b0411c; color: var(--warn); }
.review-choices button.on[data-review="rejected"] { border-color: var(--err); background: #ff5c6c1c; color: #ff7b87; }
#reviewNoteDetails { margin-top: 12px; }
#reviewNoteDetails summary { cursor: pointer; color: var(--muted); font-size: 12px; min-height: 36px; }
#reviewNoteDetails label { display: block; font-size: 12px; margin: 10px 0 6px; }
#reviewNoteDetails textarea { min-height: 70px; }
#reviewNoteDetails small { font-size: 11px; }
#galleryMore { align-self: center; min-height: 44px; }
.result-viewer { width: min(1050px, calc(100% - 32px)); max-height: calc(100dvh - 32px); padding: 0; border: 1px solid var(--line-2); border-radius: 16px; background: var(--panel); color: var(--text); overscroll-behavior: contain; }
.result-viewer::backdrop { background: rgba(0,0,0,.88); }
body:has(.result-viewer[open]) { overflow: hidden; }
.viewer-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.viewer-head h2 { overflow-wrap: anywhere; }
.viewer-head .muted { font-size: 12px; }
.viewer-head button { min-width: 44px; min-height: 44px; }
.viewer-stage { background: #000; height: 60dvh; min-height: 220px; display: flex; justify-content: center; align-items: center; }
.viewer-stage img, .viewer-stage video { display: block; max-height: 100%; max-width: 100%; object-fit: contain; }
.viewer-navigation { display: flex; justify-content: space-between; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.viewer-navigation button { min-height: 44px; }
.viewer-info { padding: 0 18px 18px; }
.viewer-filmstrip { display: flex; gap: 8px; padding: 12px 18px 0; }
.viewer-filmstrip button { flex: 1; min-width: 0; flex-direction: column; align-items: flex-start; gap: 3px; padding: 8px 10px; background: var(--bg); border-color: var(--line); }
.viewer-filmstrip button.on { border-color: var(--accent); background: var(--accent-soft); }
.filmstrip-number { font-size: 14px; font-variant-numeric: tabular-nums; color: var(--muted); }
.on>.filmstrip-number { color: var(--accent); }
.filmstrip-model { font-size: 10px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.viewer-info details { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 16px; }
.viewer-info summary { cursor: pointer; }
.viewer-info p, .viewer-info pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.viewer-info pre { font-size: 12px; }
.viewer-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.viewer-actions a, .viewer-actions button { min-height: 44px; }
@media (max-width:760px) {
  .gallery-page { padding: 20px 12px 40px; gap: 14px; }
  .gallery-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .gallery-grid[data-layout="large"] { grid-template-columns: minmax(0, 1fr); }
  .gallery-card { border-radius: 11px; }
  .gallery-media { aspect-ratio: 9 / 12; }
  [data-layout="large"] .gallery-media { aspect-ratio: 9 / 12; }
  .gallery-toolbar { gap: 10px; }
  .gallery-toolbar .seg { flex: 1; }
  .gallery-toolbar .seg button { flex: 1; min-height: 38px; }
  .gallery-toolbar select { max-width: 125px; min-height: 44px; font-size: 16px; }
  .gallery-toolbar input { flex-basis: 100%; order: 3; font-size: 16px; min-height: 44px; }
  .gallery-heading { align-items: flex-start; }
  .gallery-heading .chip { white-space: nowrap; margin-top: 4px; }
  .result-viewer { width: 100%; height: 100dvh; max-height: 100dvh; max-width: 100%; margin: 0; border: 0; border-radius: 0; }
  .viewer-stage { height: 44dvh; }
  .viewer-review { padding: 14px 16px; }
  .review-choices { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .review-choices button { justify-content: flex-start; }
  #reviewNote { font-size: 16px; }
  .viewer-head { padding: max(10px, env(safe-area-inset-top)) 16px 10px; }
  .viewer-navigation, .viewer-info { padding-left: 16px; padding-right: 16px; }
  .viewer-filmstrip { padding-left: 16px; padding-right: 16px; gap: 6px; }
  .viewer-filmstrip button { padding: 7px; }
  .viewer-info { padding-bottom: max(20px, env(safe-area-inset-bottom)); }
  .viewer-navigation button { flex: 1; }
  .results-head { flex-wrap: wrap; }
}

/* Quick decisions, publishing records, comparison and bulk selection. */
.gallery-display select { min-width: 0; width: auto; flex: 1; max-width: 220px; font-size: 12px; min-height: 42px; }
#gallerySelect { min-height: 42px; font-size: 12px; }
.gallery-select { position: absolute; top: 7px; left: 7px; width: 38px; height: 38px; z-index: 2; cursor: pointer; display: grid; place-items: center; }
.gallery-select input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.gallery-select>span { display: grid; place-items: center; width: 25px; height: 25px; border: 1px solid #fff9; border-radius: 50%; background: #10131066; color: transparent; pointer-events: none; }
.gallery-select input:checked+span { background: var(--accent); border-color: var(--accent); color: #182115; }
.gallery-select input:focus-visible+span { outline: 2px solid #fff; outline-offset: 3px; }
.gallery-card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.quick-review { display: flex; gap: 5px; margin: 11px 0 8px; }
.quick-review button { flex: 1; flex-direction: column; min-width: 0; min-height: 47px; padding: 5px 3px; gap: 1px; background: transparent; color: var(--muted); border-color: var(--line); }
.quick-review button>span { font-size: 18px; line-height: 1.2; }
.quick-review button small { font-size: 10px; }
.quick-review button.on[data-quick-review="ready"] { background: #3ccf911c; border-color: var(--ok); color: var(--ok); }
.quick-review button.on[data-quick-review="polish"] { background: #f5b0411c; border-color: var(--warn); color: var(--warn); }
.quick-review button.on[data-quick-review="rejected"] { background: #ff5c6c1c; border-color: var(--err); color: #ff7b87; }
.publication-badge { display: inline-flex; color: var(--accent); font-size: 10px; padding: 3px 0; }
.prompt-preview { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 8px; }
.gallery-prompt { font-size: 12px; margin: 0; -webkit-line-clamp: 3; overflow-wrap: anywhere; }
.prompt-preview.expanded .gallery-prompt { display: block; white-space: pre-wrap; }
.prompt-buttons { display: flex; justify-content: space-between; gap: 3px; margin-top: 4px; }
.prompt-buttons button { min-width: 0; padding: 4px 0; min-height: 34px; font-size: 10px; }
.viewer-prompt { padding: 10px 18px 14px; border-bottom: 1px solid var(--line); }
.viewer-prompt>div { display: flex; justify-content: space-between; align-items: center; font-size: 12px; }
.viewer-prompt p { font-size: 12px; line-height: 1.6; color: var(--muted); margin: 5px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 140px; overflow: auto; }
.bulk-bar { position: sticky; bottom: max(12px, env(safe-area-inset-bottom)); z-index: 25; background: var(--panel); border: 1px solid var(--accent); border-radius: 13px; padding: 13px; box-shadow: 0 5px 35px #0008; display: flex; flex-direction: column; gap: 10px; }
.bulk-heading { display: flex; align-items: center; gap: 7px; font-size: 12px; }
.bulk-heading b { margin-right: auto; }
.bulk-heading button { min-height: 38px; }
.bulk-update, .bulk-buttons { display: flex; gap: 8px; }
.bulk-update select { flex: 1; min-width: 0; min-height: 44px; }
.bulk-update button, .bulk-buttons button { min-height: 44px; }
.bulk-buttons button { flex: 1; }
.publication-card { margin: 15px 18px; border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.publication-toggle { display: flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; min-height: 36px; }
.publication-toggle input { width: 20px; height: 20px; accent-color: var(--accent); }
.publication-card p { font-size: 11px; margin: 4px 0 8px; }
.publication-card summary { cursor: pointer; font-size: 12px; color: var(--muted); padding: 6px 0; }
.publication-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }
.publication-fields label { font-size: 12px; min-width: 0; }
.publication-fields input { display: block; width: 100%; min-height: 44px; margin-top: 5px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); padding: 10px; font: inherit; }
.publication-footer { display: flex; align-items: center; gap: 10px; }
.publication-message { font-size: 11px; }
.compare-dialog { width: min(1060px, calc(100% - 32px)); max-width: 100%; max-height: calc(100dvh - 32px); padding: 0; border: 1px solid var(--line-2); border-radius: 16px; background: var(--panel); color: var(--text); }
.compare-dialog::backdrop { background: #000d; }
body:has(.compare-dialog[open]) { overflow: hidden; }
.compare-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 14px 16px 0; }
.compare-controls button { min-height: 44px; }
.compare-controls label { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); }
.compare-controls input { width: 18px; height: 18px; accent-color: var(--accent); }
.compare-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; padding: 16px; }
.compare-item { min-width: 0; }
.compare-label { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 12px; }
.compare-label b { color: var(--accent); background: var(--accent-soft); border-radius: 5px; padding: 3px 9px; }
.compare-label span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.compare-frame { background: #000; height: min(53dvh, 520px); border-radius: 10px; overflow: hidden; }
.compare-frame video { display: block; width: 100%; height: 100%; object-fit: contain; }
.compare-prompt { font-size: 12px; color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; max-height: 140px; overflow: auto; }
@media (max-width:760px) {
  .gallery-display select { max-width: 170px; font-size: 12px; }
  .gallery-display { gap: 7px; }
  .bulk-bar { padding: 10px; }
  .bulk-heading { flex-wrap: wrap; }
  .bulk-heading button { font-size: 11px; }
  .bulk-update select { font-size: 16px; }
  .bulk-update button, .bulk-buttons button { padding-left: 10px; padding-right: 10px; font-size: 12px; }
  .publication-fields { grid-template-columns: 1fr; }
  .publication-fields input { font-size: 16px; }
  .review-choices button { flex-direction: column; align-items: center; padding: 8px 3px; gap: 3px; font-size: 11px; }
  .compare-dialog { width: 100%; height: 100dvh; max-height: 100dvh; border: 0; border-radius: 0; margin: 0; }
  .compare-grid { padding: 12px; gap: 10px; }
  .compare-frame { height: 34dvh; }
  .compare-controls { padding: 12px 12px 0; }
  .compare-controls button { font-size: 12px; padding: 8px 10px; }
}
@media (max-width:560px) {
  .compare-grid { grid-template-columns: 1fr; }
  .compare-frame { height: 42dvh; }
}

/* Keep preview geometry stable before metadata and after releasing a decoder. */
.out video { aspect-ratio: 9 / 16; height: auto; }
.gallery-play span { backdrop-filter: none; }

.video-preview { cursor: pointer; }
.video-preview-frame { position: relative; }
.download-preview-status { position: absolute; inset: 12px 12px auto; padding: 8px 10px; border-radius: 8px; background: var(--panel); color: var(--text); text-align: center; }
.inline-play { position:absolute; left:50%; top:50%; transform:translate(-50%,-50%); padding:12px 18px; border:1px solid #ffffff70; border-radius:30px; background:#131913e6; color:white; }
.out:has(video:not(.video-preview)) > .inline-play { display:none; }
.save-dialog { width:min(440px,calc(100% - 28px)); border:1px solid var(--line-2); border-radius:16px; padding:22px; background:var(--panel); color:var(--text); }
.save-dialog::backdrop { background:#000b; }
.save-dialog button,.save-dialog .btn { width:100%; min-height:46px; margin-top:12px; }
.save-dialog p { line-height:1.6; overflow-wrap:anywhere; }
#accountBadge { max-width:150px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }

.upscale-dialog{width:min(520px,calc(100vw - 24px));max-height:85dvh;overflow:auto;border:1px solid var(--line);border-radius:18px;padding:0;background:var(--panel,#1a201b);color:inherit}.upscale-dialog::backdrop{background:#000b}.upscale-content{padding:22px}.upscale-content label{display:grid;gap:8px}.upscale-content select{width:100%;min-height:44px}.upscale-content p{line-height:1.5}.upscale-content .row{flex-wrap:wrap;gap:10px}.gallery-card-actions{flex-wrap:wrap}

.upscale-open{min-height:44px;margin:8px 0 4px}.gallery-card-body>.upscale-open{width:100%}

.gen-bar .cost{min-width:0;overflow-wrap:anywhere;line-height:1.5}@media(max-width:600px){.gen-bar{flex-wrap:wrap}.gen-bar .cost{order:3;flex-basis:100%}.upscale-content label+label{margin-top:12px}}

.video-trim-dialog{width:min(500px,calc(100vw - 24px));max-height:85dvh;overflow:auto;border:1px solid var(--line);border-radius:18px;padding:0;background:var(--panel);color:var(--text)}.video-trim-dialog::backdrop{background:#000b}.video-trim-content{padding:22px}.video-trim-content label{display:grid;gap:8px}.video-trim-content p{line-height:1.5;overflow-wrap:anywhere}.video-trim-content .row{flex-wrap:wrap;gap:8px}.video-trim-content button{min-height:44px}.thumb .video-trim-control{position:absolute;left:4px;bottom:25px;width:calc(100% - 8px);min-height:36px;padding:4px 2px;font-size:11px;background:rgba(0,0,0,.82);color:white;border-color:rgba(255,255,255,.3)}

/* Reference photos stay small; originals load only after a tap. */
.result-references{margin:12px 0}.result-references>b{display:block;font-size:11px;color:var(--muted);margin-bottom:7px;font-weight:500}.reference-thumbnails{display:flex;gap:7px;overflow-x:auto;padding:2px 0 5px;max-width:100%}.reference-thumb{position:relative;flex:0 0 56px;width:56px;height:64px;padding:0;border:1px solid var(--line);border-radius:8px;overflow:hidden;background:var(--panel);isolation:isolate}.reference-thumb img{display:block;width:100%;height:100%;object-fit:cover;position:relative;z-index:1}.reference-placeholder{position:absolute;inset:0;display:grid;place-content:center;font-size:10px;color:var(--muted)}.reference-number{position:absolute;bottom:2px;left:3px;z-index:2;min-width:16px;border-radius:4px;padding:1px 3px;background:#000b;color:white;font-size:10px}.reference-unavailable{opacity:.65}.reference-viewer{width:min(94vw,720px);max-height:92dvh;padding:14px;background:var(--panel);color:var(--text);border:1px solid var(--line);border-radius:14px}.reference-viewer::backdrop{background:#000b}.reference-viewer-head{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:12px}.reference-viewer-head h3{font-size:13px;margin:0;overflow-wrap:anywhere}.reference-viewer>img{display:block;max-width:100%;max-height:75dvh;object-fit:contain;margin:auto}.result-viewer>.result-references{margin:12px 16px}

/* Cloud Stack shares the desktop palette and moves navigation to the side on wide screens. */
.cloud-nav { display: contents; }
.cloud-nav-label, .cloud-location { display: none; }
#cloudMenu, .cloud-mobile-label { display: none; }
#cloudExtraNav { display: contents; }
.cloud-api-balance { margin-left: auto; white-space: nowrap; font-variant-numeric: tabular-nums; }
.cloud-api-balance b { color: var(--text); font-weight: 750; }
.top:has(.cloud-api-balance:not([hidden])) .top-right { margin-left: 0; }
.default-provider { margin-top: 18px; }
.default-provider select { max-width: 360px; min-height: 44px; }
.brand { font-weight: 650; }
.tabs svg {
  width: 17px;
  height: 17px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
@media (max-width: 760px) {
  .tabs svg { display: none; }
  .top .brand img { width: 24px; height: 24px; }
  .top .brand { font-size: 13px; }
  .top-right { gap: 4px; }
  #accountBadge { max-width: 85px; }
}
@media (min-width: 1000px) {
  :root { --cloud-sidebar: 206px; }
  body:has(.cloud-nav) { padding-left: var(--cloud-sidebar); }
  .cloud-nav {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--cloud-sidebar);
    display: flex;
    flex-direction: column;
    padding: 18px 14px;
    background: #101510;
    border-right: 1px solid var(--line);
    overflow: auto;
  }
  .cloud-nav .brand { padding: 0 8px 14px; border-bottom: 1px solid var(--line); }
  .cloud-nav .brand img { width: 34px; height: 34px; }
  .cloud-nav-label {
    display: block;
    color: var(--muted);
    padding: 0 10px;
    margin: 18px 0 8px;
    font-size: 10px;
    font-weight: 650;
    letter-spacing: .12em;
    text-transform: uppercase;
  }
  .cloud-nav .tabs { order: initial; flex-direction: column; flex-basis: auto; gap: 4px; }
  .cloud-nav .tabs button { justify-content: flex-start; padding: 9px 10px; }
  .cloud-nav .tabs button.on { background: var(--accent); border-color: transparent; color: #182115; font-weight: 650; }
  .top { flex-wrap: nowrap; height: 60px; padding: 0 22px; gap: 16px; }
  .cloud-location { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 12px; white-space: nowrap; }
  .cloud-location b { color: var(--text); font-weight: 600; }
  .top-right { order: initial; }
  .gen { grid-template-columns: minmax(220px, 260px) minmax(0, 1fr); height: auto; }
  .models { position: sticky; top: var(--header-height, 60px); max-height: calc(100dvh - var(--header-height, 60px)); }
  .results { grid-column: 1 / -1; border-top: 1px solid var(--line); }
}
@media (min-width: 1430px) {
  .gen {
    grid-template-columns: minmax(220px, 260px) minmax(330px, 450px) minmax(0, 1fr);
    height: calc(100dvh - var(--header-height, 60px));
  }
  .models { position: static; }
  .results { grid-column: auto; border-top: 0; border-left: 1px solid var(--line); }
}

.cloud-model-group { margin: 0 6px 4px; }
.cloud-model-choice { min-height: 36px; }
.cloud-model-choice.on { background: #253126; border-color: #40563a; }
.cloud-model-favorite {
  border-radius: 5px;
  padding: 2px 5px;
  color: var(--accent);
  background: var(--accent-soft);
  font-size: 9px;
}
.cloud-model-modes {
  display: grid;
  gap: 2px;
  margin: 4px 0 6px 10px;
  padding-left: 7px;
  border-left: 1px solid var(--line);
}
.cloud-model-mode {
  justify-content: space-between;
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  font-size: 12px;
  padding: 6px 8px;
  min-height: 31px;
}
.cloud-model-mode[aria-pressed="true"] { background: #273825; border-color: #40563a; color: var(--accent); }
.cloud-model-mode small { font-size: 10px; }

/* Cloud Tvorba: one composer, one result, history on demand. */
.cloud-workspace-heading.creation-heading,
#view-generate.creation-studio { width: min(100%, 1180px); margin-inline: auto; padding-inline: clamp(16px, 2.4vw, 32px); }
.cloud-workspace-heading.creation-heading { padding-block: 30px 21px; }
.creation-heading #cloud-workspace-title { margin: 0; font-size: clamp(32px, 4vw, 43px); font-weight: 800; letter-spacing: -.04em; }
#view-generate.creation-studio {
  grid-template-columns: minmax(0, 1.16fr) minmax(0, 1fr);
  align-items: start; gap: 20px; height: auto; min-height: 0; overflow: visible; border: 0;
}
.creation-studio :is(.form-pane, .results) { border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius); overflow: visible; }
.creation-studio .models { position: static; border: 0; border-bottom: 1px solid var(--line); max-height: none; overflow: visible; border-radius: var(--radius) var(--radius) 0 0; }
.creation-toolbar { display: flex; justify-content: space-between; gap: 12px; padding: 14px 17px; }
.creation-toolbar .scope { flex: none; }
.creation-toolbar .scope button { min-height: 44px; font-weight: 750; }
.creation-toolbar svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; stroke-linecap: round; }
.creation-toolbar .scope button.on { color: var(--text); }
.creation-toolbar .scope button.on svg { color: var(--accent); }
.creation-studio .models-toggle {
  display: flex; justify-content: space-between; gap: 10px; min-width: 0; width: auto; max-width: 58%;
  min-height: 44px; padding: 8px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); text-align: left;
}
.creation-studio .models-toggle:hover { background: var(--panel-2); }
#modelsToggleLabel { min-width: 0; white-space: normal; overflow-wrap: anywhere; }
.creation-studio .models-toggle[aria-expanded=true] .caret { rotate: 180deg; }
.creation-studio .models-body { padding: 0 17px 14px; }
.creation-studio .model-list { max-height: 38dvh; padding: 4px; }
.creation-studio :is(.cloud-model-choice, .cloud-model-mode) { min-height: 44px; }
.creation-studio .form-head { padding: 8px 0 0; }
.creation-studio #genForm { gap: 0; padding: 0; }
.creation-studio #genForm :is([data-field=prompt], [data-field=text]) { padding: 17px; }
.creation-studio #genForm :is([data-field=prompt], [data-field=text]) :is(textarea,input) { min-height: 44px; font-size: 16px; }
.creation-studio #genForm :is([data-field=prompt], [data-field=text]) textarea { height: 150px; min-height: 110px; max-height: 48dvh; line-height: 1.6; }
.creation-studio .creation-message { margin: 0; padding: 17px; }
.creation-studio #genForm .form-fold { border: 0; border-top: 1px solid var(--line); border-radius: 0; }
.creation-studio .form-fold > summary { justify-content: start; min-height: 51px; padding-inline: 17px; }
.creation-studio .form-fold > summary:hover { background: var(--panel-2); }
.creation-studio .form-fold > summary::after { margin-left: auto; }
.creation-studio .fold-label { font-size: 14px; }
.creation-ref-peek { display: flex; margin-left: auto; }
.creation-studio summary:has(.creation-ref-peek:not(:empty))::after { margin-left: 0; }
.creation-ref-peek img { width: 26px; height: 26px; border: 1px solid var(--line); border-radius: 5px; object-fit: cover; }
.creation-ref-peek img + img { margin-left: -4px; }
.creation-studio details[open] .creation-ref-peek { display: none; }
.creation-studio .char-bar { grid-column: 1 / -1; padding: 0; }
.creation-studio .char-pill { min-height: 44px; }
.creation-studio .form-fold .drop-actions button { min-height: 44px; }
.creation-studio .form-fold .group-body { padding-inline: 17px; }
.creation-settings {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 76px), 1fr)); gap: 10px;
  padding: 12px 17px 15px; border-top: 1px solid var(--line); align-items: start;
}
.creation-settings > * { min-width: 0; }
.creation-settings select { min-height: 44px; text-overflow: ellipsis; }
.creation-settings .count { display: block; }
.creation-settings .count span, .creation-settings .field .lbl { display: block; margin-bottom: 6px; font-size: 12px; color: var(--muted); font-weight: 650; }
.creation-settings .help { display: none; }
.creation-studio .gen-bar { position: static; flex-wrap: nowrap; justify-content: space-between; border-radius: 0 0 var(--radius) var(--radius); padding: 12px 17px; }
.creation-estimate { min-width: 0; display: grid; gap: 2px; }
.creation-estimate > span { color: var(--muted); font-size: 12px; }
.creation-studio .gen-bar .cost { color: var(--text); }
.creation-studio .gen-bar .primary { min-height: 46px; margin-left: 0; padding-inline: 13px; }
.creation-studio .form-error:not([hidden]) { margin: 12px 17px; }
.creation-studio .results { grid-column: auto; padding: 0; scroll-margin-top: calc(var(--header-height, 0px) + 10px); }
.creation-studio .results-head { margin: 0; padding: 8px 15px; }
.creation-studio .results-head button { min-height: 44px; }
.creation-preview .job { border: 0; border-radius: 0; display: flex; flex-direction: column; }
.creation-preview .outs { order: -1; border-block: 1px solid var(--line); background: #0b0c0e; padding: 10px; }
.creation-preview .out { background: #0b0c0e; }
.creation-preview .out img, .creation-preview .out video { background: transparent; height: clamp(220px, 44dvh, 420px); max-height: none; }
.creation-preview .out video { aspect-ratio: auto; cursor: pointer; }
.creation-preview .out .out-actions { opacity: 1; }
.creation-preview .out .out-actions :is(a,button) { min-height: 40px; display: inline-flex; align-items: center; }
.creation-preview .job-head { padding-top: 13px; }
.creation-preview .job-foot button { min-height: 40px; }
.creation-preview .creation-empty { min-height: 260px; border-block: 1px solid var(--line); background: #0b0c0e; margin: 0; padding: 20px; display: grid; place-items: center; text-align: center; }
.creation-history { border-top: 1px solid var(--line); padding-inline: 12px; }
.creation-history > summary { cursor: pointer; padding: 14px 4px; font-weight: 650; }
.creation-history[open] { padding-bottom: 12px; }
.creation-history .seg { display: inline-flex; margin-bottom: 10px; }
#editCreationPrompt { display: none; }
@media (max-width: 900px) and (min-width: 821px) {
  #view-generate.creation-studio { display: grid; }
}
@media (max-width: 820px) {
  .top:has(#cloudMenu) {
    display: grid; grid-template-columns: max-content minmax(0, 1fr) max-content 44px;
    grid-template-areas: 'brand context balance menu' 'tabs tabs tabs tabs'; min-height: 58px; padding: 6px 16px; gap: 5px 8px;
  }
  .top:has(#cloudMenu[aria-expanded=true]) { grid-template-areas: 'brand context balance menu' 'tabs tabs tabs tabs' 'account account account account'; }
  .top:has(#cloudMenu) .brand { grid-area: brand; gap: 8px; font-size: 15px; }
  .top:has(#cloudMenu) .brand b { color: var(--text); }
  .top:has(#cloudMenu) .cloud-nav-label {
    display: block; grid-area: context; margin: 0; padding-left: 8px; border-left: 1px solid var(--line);
    color: var(--muted); font-size: 11px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .top:has(#cloudMenu) .cloud-nav-label > span:first-child { display: none; }
  .cloud-mobile-label { display: inline; }
  #cloudMenu { display: inline-flex; grid-area: menu; width: 44px; height: 44px; padding: 0; background: var(--panel); border-color: var(--line); }
  #cloudMenu:hover, #cloudMenu[aria-expanded=true] { background: var(--panel-2); border-color: var(--line-2); }
  #cloudMenu svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }
  #cloudMenu[aria-expanded=false] .menu-close-icon, #cloudMenu[aria-expanded=true] .menu-open-icon { display: none; }
  .cloud-api-balance { grid-area: balance; padding: 4px 7px; gap: 5px; font-size: 11px; }
  .top:has(#cloudMenu[aria-expanded=false]) :is(#cloudExtraNav, #cloudAccount) { display: none; }
  .top:has(#cloudMenu) #tabs { grid-area: tabs; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; padding: 0; }
  .top:has(#cloudMenu) #tabs button { min-height: 44px; padding: 5px 2px; font-size: 12px; font-weight: 650; border-radius: var(--radius-sm); }
  .top:has(#cloudMenu) #tabs svg { display: block; width: 15px; height: 15px; }
  .top:has(#cloudMenu) #tabs button.on { background: var(--accent-soft); color: var(--accent); box-shadow: none; }
  .top:has(#cloudMenu) #cloudExtraNav { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; padding-top: 4px; border-top: 1px solid var(--line); }
  .top:has(#cloudMenu) #cloudAccount { grid-area: account; width: 100%; margin-left: 0; border-top: 1px solid var(--line); padding: 5px 0; justify-content: space-between; }
  .top:has(#cloudMenu) #accountBadge { display: block; max-width: min(65%, 240px); }
  #view-generate.creation-studio { display: grid; grid-template-columns: minmax(0, 1fr); padding-bottom: calc(90px + env(safe-area-inset-bottom)); }
  .cloud-workspace-heading.creation-heading { padding-block: 18px 14px; }
  .creation-toolbar { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; padding: 12px; }
  .creation-toolbar .scope { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .creation-studio .models-toggle { max-width: none; width: 100%; }
  .creation-studio #genForm :is([data-field=prompt], [data-field=text]) { padding: 12px; }
  .creation-studio #genForm :is([data-field=prompt], [data-field=text]) textarea { height: 134px; }
  .creation-studio .form-fold > summary, .creation-studio .form-fold .group-body, .creation-settings { padding-inline: 12px; }
  .creation-settings select { padding-inline: 6px; }
  .creation-studio .gen-bar {
    position: fixed; inset: auto 0 0; z-index: 22; border-radius: 0;
    padding: 8px 16px max(8px, env(safe-area-inset-bottom));
  }
  .creation-studio.creation-keyboard-open .gen-bar { position: static; }
  #editCreationPrompt { display: inline-flex; min-height: 44px; margin: 0 8px; }
  .creation-preview .out .out-actions { gap: 2px; }
}
@media (max-width: 370px) {
  .top:has(#balance:not([hidden])) .cloud-nav-label { display: none; }
}
