* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  color: #111;
  background: #fafafa;
}

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 24px 80px;
}

@media (max-width: 480px) {
  main {
    padding: 16px 12px 60px;
  }
  /* Slightly larger tap targets for small action buttons on mobile */
  .btn-clear, .clip-act {
    padding: 8px 12px;
  }
}

header {
  margin-bottom: 28px;
}

h1 {
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 8px;
}

h2 {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 12px;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

p { margin: 0; }

.status {
  font-size: 14px;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid transparent;
}
.status-loading { background: #f0f0f0; color: #555; border-color: #e0e0e0; }
.status-ok      { background: #ecfdf3; color: #0a6c3a; border-color: #c7eed5; }
.status-error   { background: #fef1f1; color: #9c1b1b; border-color: #f3c8c8; }

.card {
  background: #fff;
  border: 1px solid #e3e3e3;
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
}

label {
  display: block;
  margin-bottom: 16px;
}

.label-text {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: #444;
  margin-bottom: 6px;
}

textarea, input[type="text"], select, input[type="file"] {
  width: 100%;
  font-family: inherit;
  font-size: 16px; /* ≥16px prevents iOS auto-zoom on focus */
  padding: 8px 10px;
  border: 1px solid #d4d4d4;
  border-radius: 6px;
  background: #fff;
  color: #111;
}

textarea {
  resize: vertical;
  min-height: 88px;
  line-height: 1.5;
}

textarea:focus, select:focus, input:focus {
  outline: 2px solid #2563eb33;
  border-color: #2563eb;
}

.params {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.params label {
  margin-bottom: 0;
}

.audio-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 24px;
  font-size: 14px;
}

.audio-toggle input {
  width: auto;
  margin: 0;
}

button {
  width: 100%;
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  padding: 12px 16px;
  min-height: 44px; /* iOS/Android minimum tap target */
  border: none;
  border-radius: 6px;
  cursor: pointer;
  touch-action: manipulation; /* prevent 300ms tap delay on mobile */
}

button:disabled {
  cursor: not-allowed;
}

/* Dark primary style is scoped to the main Generate button only. Applying it to
   every <button> made sub-buttons (mode tabs, ratio picker) flip to black on
   hover, because `button:hover` outranks `.mode-tab:hover` on specificity. */
#generate-btn {
  background: #111;
  color: #fff;
}

#generate-btn:hover:not(:disabled) {
  background: #000;
}

#generate-btn:disabled {
  background: #999;
}

.task-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: #666;
  margin-bottom: 6px;
}

.muted {
  color: #777;
  font-size: 13px;
}

.status-slow {
  color: #8a5d00;
  font-size: 13px;
}

.status-warning {
  color: #9c1b1b;
  font-size: 13px;
  font-weight: 500;
}

#current-video video {
  width: 100%;
  margin-top: 12px;
  border-radius: 6px;
  background: #000;
}

.failure-detail {
  margin: 12px 0 0;
  padding: 12px 14px;
  background: #fef1f1;
  border: 1px solid #f3c8c8;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.55;
  color: #5a1010;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 320px;
  overflow-y: auto;
}

.actions {
  display: flex;
  gap: 12px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.actions a, .actions button {
  width: auto;
  padding: 6px 12px;
  font-size: 13px;
  background: #fff;
  border: 1px solid #d4d4d4;
  color: #333;
  border-radius: 6px;
  text-decoration: none;
  cursor: pointer;
}

.actions a:hover, .actions button:hover {
  background: #f3f3f3;
}

.recent-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.recent-header h2 {
  margin: 0;
}

/* ── Modal ──────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.modal-card {
  position: relative;
  background: #fff;
  border-radius: 10px;
  width: min(720px, calc(100vw - 16px));
  max-height: calc(100svh - 32px); /* svh = small viewport height, safe on mobile */
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  overflow: hidden;
}

@media (max-width: 480px) {
  .modal-card {
    width: 100vw;
    max-height: 100svh;
    border-radius: 16px 16px 0 0;
    align-self: flex-end; /* sheet slides up from bottom */
    margin: 0;
  }
  .modal {
    align-items: flex-end;
  }
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid #eee;
}

.modal-header h2 {
  flex: 1;
  margin: 0;
  font-size: 14px;
  color: #333;
  text-transform: none;
  letter-spacing: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.modal-close {
  width: 44px;
  height: 44px;
  min-height: unset; /* override the global button min-height */
  padding: 0;
  background: transparent;
  border: none;
  color: #666;
  font-size: 22px;
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  background: #f3f3f3;
  color: #000;
}

.modal-body {
  padding: 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-section h3 {
  font-size: 11px;
  font-weight: 600;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 0 0 6px;
}

.modal-prompt {
  margin: 0;
  padding: 12px 14px;
  background: #fafafa;
  border: 1px solid #eee;
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.55;
  color: #222;
  white-space: pre-wrap;
  word-break: break-word;
}

.modal-prompt.is-empty {
  color: #999;
  font-style: italic;
}

.modal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px 14px;
  font-size: 12px;
}

.modal-grid-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.modal-grid-cell .grid-label {
  font-size: 10px;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.modal-grid-cell .grid-value {
  color: #111;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  word-break: break-all;
}

.modal-thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
}

.modal-thumb {
  position: relative;
  aspect-ratio: 1 / 1;
  background: #f0f0f0;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid #e0e0e0;
}

.modal-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.modal-thumb .thumb-label {
  position: absolute;
  top: 4px;
  left: 4px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 10px;
  padding: 2px 5px;
  border-radius: 3px;
  font-family: ui-monospace, monospace;
}

.modal-video video {
  width: 100%;
  border-radius: 6px;
  background: #000;
}

.modal-error {
  margin: 0;
  padding: 12px 14px;
  background: #fef1f1;
  border: 1px solid #f3c8c8;
  border-radius: 6px;
  font-family: ui-monospace, monospace;
  font-size: 12px;
  color: #5a1010;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 200px;
  overflow-y: auto;
}

.modal-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid #eee;
  margin-top: 4px;
}

.modal-footer button,
.modal-footer a {
  width: auto;
  background: #fff;
  border: 1px solid #d4d4d4;
  color: #333;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
}

.modal-footer button:hover,
.modal-footer a:hover {
  background: #f3f3f3;
}

.modal-footer .btn-danger {
  border-color: #f3c8c8;
  color: #9c1b1b;
}

.modal-footer .btn-danger:hover {
  background: #fef1f1;
}

/* ── Share (clip detail modal) ──────────────────────────── */

.share-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
  font-size: 13px;
  color: #222;
  cursor: pointer;
}

.share-toggle input[type="checkbox"] {
  width: auto;
  margin: 0;
  accent-color: #111;
}

.share-link-row {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.share-link-row .share-link-input {
  flex: 1;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  padding: 6px 8px;
  color: #333;
  background: #fafafa;
}

.share-note {
  font-size: 12px;
}

/* ── Duration slider ────────────────────────────────────── */
.duration-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.duration-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.duration-value-display {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  font-weight: 600;
  color: #111;
}

.duration-cell input[type="range"] {
  width: 100%;
  padding: 0;
  margin: 4px 0 2px;
  background: transparent;
  border: none;
  accent-color: #111;
}

.duration-cost {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
}

/* ── Ratio picker ───────────────────────────────────────── */
.ratio-picker {
  position: relative;
}

.ratio-picker-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 1px solid #d4d4d4;
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 14px;
  color: #111;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
}

.ratio-picker-trigger:hover {
  background: #fafafa;
}

.ratio-picker-trigger:focus {
  outline: 2px solid #2563eb33;
  border-color: #2563eb;
}

.ratio-picker-label {
  flex: 1;
}

.ratio-picker-chev {
  color: #888;
  font-size: 11px;
  transition: transform 0.15s ease;
}

.ratio-picker[data-open="true"] .ratio-picker-chev {
  transform: rotate(180deg);
}

.ratio-picker-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #d4d4d4;
  border-radius: 6px;
  padding: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  z-index: 10;
  display: flex;
  flex-direction: column;
}

.ratio-picker-menu button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  border: none;
  border-radius: 4px;
  padding: 6px 8px;
  font-size: 14px;
  color: #111;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
}

.ratio-picker-menu button:hover {
  background: #f3f3f3;
}

.ratio-picker-menu button[aria-selected="true"] {
  background: #eef5ff;
  color: #1e40af;
}

.ratio-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.ratio-icon::before {
  content: '';
  display: block;
  background: currentColor;
  border-radius: 2px;
  opacity: 0.85;
}

.ratio-icon[data-ratio="16:9"]::before  { width: 20px; height: 11px; }
.ratio-icon[data-ratio="9:16"]::before  { width: 11px; height: 20px; }
.ratio-icon[data-ratio="1:1"]::before   { width: 16px; height: 16px; }
.ratio-icon[data-ratio="4:3"]::before   { width: 18px; height: 14px; }
.ratio-icon[data-ratio="3:4"]::before   { width: 14px; height: 18px; }
.ratio-icon[data-ratio="21:9"]::before  { width: 22px; height: 9px; }
.ratio-icon-auto::before                {
  width: 14px; height: 14px;
  background: transparent;
  border: 1.5px dashed currentColor;
  opacity: 0.7;
  border-radius: 2px;
}

.image-info-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
}

.frame-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid #e0e0e0;
  background: #f0f0f0;
  flex-shrink: 0;
}

.frame-fields, .reference-fields {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.frame-fields > label, .reference-fields > label {
  margin-bottom: 0;
}

.last-frame-hint, .ref-hint {
  margin-top: 6px;
  font-size: 11px;
}

.ref-hint code {
  background: #f3f3f3;
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 11px;
}

input[type="file"]:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.prompt-wrap {
  position: relative;
}

.mention-popup {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 240px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #d4d4d4;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  z-index: 20;
  padding: 4px;
}

.mention-popup-header {
  padding: 6px 8px 4px;
  font-size: 11px;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.mention-empty {
  padding: 12px;
  font-size: 12px;
  color: #888;
  text-align: center;
}

.mention-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 8px;
  background: transparent;
  border: none;
  border-radius: 4px;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  color: #111;
}

.mention-item:hover,
.mention-item[aria-selected="true"] {
  background: #eef5ff;
}

.mention-item-tag {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: #1e40af;
  background: #eef5ff;
  padding: 2px 6px;
  border-radius: 3px;
  flex-shrink: 0;
}

.mention-item-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mention-item-meta {
  font-size: 11px;
  color: #888;
  flex-shrink: 0;
}

.image-mode-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
  padding: 3px;
  background: #f3f3f3;
  border-radius: 6px;
}

.mode-price-hint {
  font-size: 11px;
  margin-bottom: 12px;
  padding: 4px 2px;
}

.mode-tab {
  flex: 1;
  width: auto;
  background: transparent;
  border: none;
  color: #555;
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
}

.mode-tab:hover {
  background: rgba(255, 255, 255, 0.6);
  color: #111;
}

.mode-tab[aria-selected="true"] {
  background: #fff;
  color: #111;
  font-weight: 500;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.reference-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.reference-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  background: #fafafa;
  border: 1px solid #eee;
  border-radius: 4px;
  padding: 5px 8px;
}

.reference-list .ref-index {
  font-family: ui-monospace, monospace;
  font-size: 11px;
  color: #1e40af;
  background: #eef5ff;
  padding: 1px 5px;
  border-radius: 3px;
  flex-shrink: 0;
}

.reference-list .ref-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reference-list .ref-size {
  color: #888;
  font-family: ui-monospace, monospace;
  font-size: 11px;
  flex-shrink: 0;
}

.reference-list .ref-remove {
  width: auto;
  background: transparent;
  border: 1px solid #ddd;
  color: #888;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 11px;
  cursor: pointer;
  flex-shrink: 0;
}

.reference-list .ref-remove:hover {
  background: #fef1f1;
  color: #9c1b1b;
  border-color: #f3c8c8;
}

/* HTML `hidden` attribute must beat the display rules above */
[hidden] {
  display: none !important;
}

.btn-clear {
  width: auto;
  background: transparent;
  border: 1px solid #d4d4d4;
  color: #666;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
}

.btn-clear:hover:not(:disabled) {
  background: #fef1f1;
  border-color: #f3c8c8;
  color: #9c1b1b;
}

.error-banner {
  margin-top: 16px;
  border: 1px solid #f3c8c8;
  background: #fef1f1;
  border-radius: 6px;
  padding: 0;
  overflow: hidden;
}

.error-banner-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: #fde6e6;
  border-bottom: 1px solid #f3c8c8;
}

.error-banner-icon {
  color: #9c1b1b;
  font-weight: bold;
  font-size: 14px;
}

.error-banner-title {
  flex: 1;
  font-size: 13px;
  font-weight: 600;
  color: #9c1b1b;
}

.error-banner-close {
  width: auto;
  background: transparent;
  border: none;
  color: #9c1b1b;
  font-size: 18px;
  padding: 0 4px;
  cursor: pointer;
  line-height: 1;
}

.error-banner-close:hover {
  background: transparent;
  color: #000;
}

.error-banner-body {
  margin: 0;
  padding: 12px 14px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, sans-serif;
  font-size: 13px;
  line-height: 1.55;
  color: #5a1010;
  white-space: pre-wrap;
  word-break: break-word;
}

@media (max-width: 540px) {
  .params {
    grid-template-columns: 1fr;
  }
  .audio-toggle {
    padding-top: 0;
  }
}

/* ───── Asset Library ───── */
.btn-browse-assets {
  width: 100%;
  margin: 8px 0;
  background: #f3f0ff;
  border: 1px solid #d8cffb;
  color: #5b3fc4;
  font-size: 13px;
  padding: 9px 12px;
  border-radius: 6px;
  cursor: pointer;
}
.btn-browse-assets:hover {
  background: #ece6ff;
  border-color: #c3b4f7;
}

.reference-list .ref-thumb {
  width: 30px;
  height: 30px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid #e3ddf7;
  flex-shrink: 0;
}
.reference-list .ref-asset-tag {
  color: #5b3fc4;
  background: #f3f0ff;
  border: 1px solid #e3ddf7;
  border-radius: 3px;
  padding: 1px 5px;
}
.reference-list .ref-asset-id {
  font-family: ui-monospace, monospace;
  font-size: 11px;
  color: #666;
  background: #f4f4f6;
  border: 1px solid #e6e6ea;
  border-radius: 3px;
  padding: 1px 5px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  user-select: all;
  flex-shrink: 0;
}

.modal-card-wide {
  width: min(960px, calc(100vw - 32px));
}
.asset-modal-sub {
  font-family: inherit;
  font-size: 12px;
}

.asset-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  border-bottom: 1px solid #eee;
  background: #fbfbfd;
}
.asset-filters > input,
.asset-filters > select {
  font-size: 13px;
  padding: 6px 8px;
  border: 1px solid #d8d8d8;
  border-radius: 6px;
  background: #fff;
}
.asset-filters #asset-search {
  flex: 1;
  min-width: 200px;
}
#asset-count {
  margin-left: auto;
  font-size: 12px;
  white-space: nowrap;
}

/* Gender toggle (segmented click control) */
.gender-toggle {
  display: inline-flex;
  border: 1px solid #d8d8d8;
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
}
.gender-opt {
  font-size: 13px;
  padding: 6px 12px;
  border: none;
  border-left: 1px solid #d8d8d8;
  background: #fff;
  color: #444;
  cursor: pointer;
}
.gender-opt:first-child {
  border-left: none;
}
.gender-opt:hover {
  background: #f5f3ff;
}
.gender-opt.is-active {
  background: #5b3fc4;
  color: #fff;
}

/* Multi-select dropdown (nationality) */
.ms {
  position: relative;
}
.ms-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  padding: 6px 10px;
  border: 1px solid #d8d8d8;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  min-width: 150px;
}
.ms-trigger .ms-chev {
  margin-left: auto;
  color: #888;
}
.ms-menu {
  position: absolute;
  z-index: 30;
  top: calc(100% + 4px);
  left: 0;
  width: 240px;
  background: #fff;
  border: 1px solid #d8d8d8;
  border-radius: 8px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ms-search {
  font-size: 13px;
  padding: 6px 8px;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
}
.ms-clear {
  align-self: flex-start;
  background: transparent;
  border: none;
  color: #5b3fc4;
  font-size: 12px;
  padding: 0 2px;
  cursor: pointer;
}
.ms-options {
  max-height: 240px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.ms-opt {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  padding: 5px 4px;
  border-radius: 4px;
  cursor: pointer;
}
.ms-opt:hover {
  background: #f5f3ff;
}
.ms-opt input {
  accent-color: #5b3fc4;
}

/* Dual-thumb age range slider */
.age-range {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 280px;
  flex: 1 1 280px;
}
.age-range-label {
  font-size: 11px;
  color: #666;
}
.age-range-track {
  position: relative;
  height: 26px;
}
.age-range-base,
.age-range-fill {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  height: 4px;
  border-radius: 2px;
}
.age-range-base {
  left: 0;
  right: 0;
  background: #e2e2e8;
}
.age-range-fill {
  background: #5b3fc4;
}
.age-range-track input[type="range"] {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 26px;
  margin: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  pointer-events: none;
}
.age-range-track #asset-age-min {
  z-index: 4;
}
.age-range-track #asset-age-max {
  z-index: 3;
}
.age-range-track input[type="range"]::-webkit-slider-runnable-track {
  background: transparent;
  border: none;
  height: 26px;
}
.age-range-track input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  pointer-events: auto;
  height: 16px;
  width: 16px;
  margin-top: 5px;
  border-radius: 50%;
  background: #5b3fc4;
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  cursor: pointer;
}
.age-range-track input[type="range"]::-moz-range-track {
  background: transparent;
  border: none;
  height: 26px;
}
.age-range-track input[type="range"]::-moz-range-thumb {
  pointer-events: auto;
  height: 16px;
  width: 16px;
  border-radius: 50%;
  background: #5b3fc4;
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  cursor: pointer;
}

.asset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 12px;
}
.asset-loading {
  grid-column: 1 / -1;
  padding: 28px 8px;
  text-align: center;
  font-size: 13px;
}

.asset-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  text-align: left;
  padding: 0;
  background: #fff;
  border: 1px solid #e6e6e6;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.asset-card:hover {
  border-color: #c3b4f7;
  box-shadow: 0 4px 14px rgba(91, 63, 196, 0.15);
}
.asset-card-selected {
  border-color: #5b3fc4;
  box-shadow: 0 0 0 2px rgba(91, 63, 196, 0.25);
}
.asset-card-img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  background: #f0f0f3;
  display: block;
}
.asset-card-label {
  padding: 6px 8px 0;
  font-size: 11px;
  line-height: 1.3;
  color: #222;
}
.asset-card-check {
  padding: 4px 8px 8px;
  font-size: 11px;
  color: #5b3fc4;
  font-weight: 600;
}
.asset-card-selected .asset-card-check {
  color: #2d7d3a;
}

/* ───── V1/V2 UI switch link ───── */
.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.ui-switch {
  text-decoration: none;
  font-size: 13px;
  white-space: nowrap;
}
.ui-switch:hover { text-decoration: underline; }

/* ---------- makereel: wallet + x402 quote ---------- */

.tagline { font-size: 14px; margin-top: 2px; }

.wallet-wrap {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
}

.wallet-balance {
  font-size: 12px;
  font-weight: 600;
  font-family: ui-monospace, Menlo, monospace;
  color: #2d6a31;
  background: #eef9ef;
  border: 1px solid #c8e6cb;
  padding: 7px 12px;
  border-radius: 999px;
  white-space: nowrap;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wallet-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 200px;
  background: #fff;
  border: 1px solid #e3e3e3;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
  padding: 6px;
  z-index: 50;
}
.wallet-menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  background: none;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}
.wallet-menu-item:hover { background: #f5f5f5; }
.wallet-menu-item.is-active { background: #ecfdf3; }
.wallet-menu-item img { width: 20px; height: 20px; border-radius: 4px; }
.wallet-menu-disconnect { color: #9c1b1b; }

.wallet-btn {
  width: auto;
  padding: 8px 16px;
  min-height: 44px; /* iOS/Android minimum tap target */
  border: 1px solid #d8d8d8;
  border-radius: 999px;
  background: #fff;
  font-size: 13px;
  font-weight: 600;
  font-family: ui-monospace, Menlo, monospace;
  cursor: pointer;
}
.wallet-btn:hover { background: #f5f5f5; }
.wallet-btn.is-connected {
  background: #ecfdf3;
  border-color: #c7eed5;
  color: #0a6c3a;
}

.quote-panel {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid #bcd2fb;
  background: #f4f8ff;
  border-radius: 8px;
}
.quote-amount {
  font-size: 26px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.quote-unit { font-size: 14px; font-weight: 500; color: #555; }
.quote-detail { margin: 4px 0 12px; font-size: 13px; }
.quote-actions { display: flex; gap: 10px; align-items: center; }
.pay-btn {
  width: auto;
  padding: 10px 22px;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.pay-btn:hover { background: #1d4ed8; }
.pay-btn:disabled { background: #93b4f5; cursor: default; }
.quote-note { margin-top: 10px; font-size: 12px; }

/* recent: clip card grid */
.recent-count { font-size: 12px; text-transform: none; letter-spacing: 0; }

#recent-card .recent-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
}
#recent-card .recent-list li {
  border: 1px solid #e3e3e3;
  border-radius: 10px;
  padding: 0;
  margin: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: #fff;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
#recent-card .recent-list li:hover {
  border-color: #c6c6cc;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  background: #fff;
}
#recent-card .recent-list li.recent-empty {
  border: 1px dashed #d8d8dc;
  padding: 28px 16px;
  text-align: center;
  grid-column: 1 / -1;
}
#recent-card .recent-list li.is-pending,
#recent-card .recent-list li.has-details { cursor: pointer; }

.recent-thumb {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  background: #0d0d0f;
}
.recent-thumb-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 16 / 9;
  font-size: 13px;
  padding: 0 14px;
  text-align: center;
}
.recent-thumb-empty.is-busy { background: #f0f5ff; color: #2563eb; }
.recent-thumb-empty.is-dead { background: #fef1f1; color: #9c1b1b; }
.recent-thumb-empty.is-expired { background: #f5f5f5; color: #777; }

.btn-signin {
  width: auto;
  margin-top: 12px;
  padding: 8px 18px;
  border: 1px solid #d8d8d8;
  border-radius: 999px;
  background: #fff;
  font-size: 13px;
  font-weight: 600;
  font-family: ui-monospace, Menlo, monospace;
  cursor: pointer;
}
.btn-signin:hover { background: #f5f5f5; }

.recent-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px 12px;
  flex: 1;
}
.recent-prompt {
  font-size: 13px;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.recent-meta { font-size: 12px; }
.recent-err {
  font-size: 12px;
  color: #9c1b1b;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.clip-actions {
  display: flex;
  gap: 6px;
  margin-top: auto;
  padding-top: 6px;
}
.clip-act {
  width: auto;
  padding: 4px 10px;
  border: 1px solid #e0e0e4;
  border-radius: 6px;
  background: #fff;
  color: #3f3f46;
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  line-height: 1.4;
}
.clip-act:hover { background: #f4f5f6; border-color: #c9c9cf; }

.ref-thumbs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.page-footer { font-size: 12px; margin-top: 8px; }
.page-footer a { color: inherit; }

.tx-link {
  color: #2563eb;
  text-decoration: none;
  font-size: 12px;
  font-family: ui-monospace, Menlo, monospace;
}
.tx-link:hover { text-decoration: underline; }

/* ---------- prompt template (structured editor) ---------- */

/* Vertical tab rail in the left gutter — the card content moves up.
   Falls back to a horizontal row inside the card when there's no gutter. */
#form-card {
  position: relative;
}

.prompt-tabs {
  position: absolute;
  top: 20px;
  right: calc(100% + 14px);
  flex-direction: column;
  width: 104px;
}

.prompt-tabs .mode-tab {
  text-align: left;
  flex: none;
}

@media (max-width: 1219px) {
  .prompt-tabs {
    position: static;
    flex-direction: row;
    width: auto;
    max-width: 280px;
    margin-bottom: 12px;
  }
  .prompt-tabs .mode-tab {
    flex: 1;
    text-align: center;
  }
}

.tpl-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 14px;
}

.tpl-toolbar select {
  width: auto;
  font-size: 13px;
  padding: 6px 8px;
}

.tpl-top {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 14px;
}

.tpl-top label { margin-bottom: 0; }

.tpl-segment {
  border: 1px solid #e7e7ec;
  background: #fbfbfd;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
}

.tpl-segment-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
}

.tpl-segment-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.tpl-segment-grid label { margin-bottom: 0; }

.tpl-segment-grid textarea {
  min-height: 0;
  font-size: 13px;
  line-height: 1.45;
}

.tpl-add {
  margin-bottom: 16px;
  padding: 5px 10px;
}

.tpl-add:hover:not(:disabled) {
  background: #eef5ff;
  border-color: #bcd2fb;
  color: #1e40af;
}

.tpl-preview {
  margin-bottom: 16px;
  border: 1px solid #eee;
  border-radius: 6px;
  background: #fafafa;
}

.tpl-preview summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  color: #555;
  padding: 8px 12px;
}

.tpl-preview pre {
  margin: 0;
  padding: 0 12px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.5;
  color: #333;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 280px;
  overflow-y: auto;
}

#tpl-count.is-over,
#json-count.is-over {
  color: #9c1b1b;
  font-weight: 600;
}

/* JSON tab: paste left, parsed fields right */
.json-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 8px;
}

.json-input-col,
.json-fields-col label { margin-bottom: 0; }

#json-input {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.5;
  min-height: 320px;
  overflow-y: hidden; /* height auto-grows to fit content (see autosizeJsonInput) */
  resize: none;
}

.json-fields {
  border: 1px solid #e7e7ec;
  background: #fbfbfd;
  border-radius: 6px;
  padding: 10px 12px;
  min-height: 320px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.json-field-row {
  display: flex;
  flex-direction: column;
  gap: 1px;
  border-bottom: 1px solid #efeff3;
  padding-bottom: 7px;
}

.json-field-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.json-field-key {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  color: #1e40af;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.json-field-value {
  font-size: 12.5px;
  line-height: 1.45;
  color: #222;
  word-break: break-word;
}

.json-note { font-size: 12px; }

.json-error {
  font-size: 12px;
  color: #9c1b1b;
  background: #fef1f1;
  border: 1px solid #f3c8c8;
  border-radius: 4px;
  padding: 8px 10px;
}

.json-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 16px;
}

@media (max-width: 700px) {
  .json-split { grid-template-columns: 1fr; }
  #json-input, .json-fields { min-height: 200px; }
}

.recent-diff {
  font-size: 11px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: #1e40af;
  background: #eef5ff;
  border-radius: 4px;
  padding: 3px 6px;
  align-self: flex-start;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

@media (max-width: 540px) {
  .tpl-top,
  .tpl-segment-grid {
    grid-template-columns: 1fr;
  }
}

/* ── Ratio picker (custom dropdown with aspect-shape icons) ── */

.ratio-picker {
  position: relative;
}

.ratio-picker-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 1px solid #d4d4d4;
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 14px;
  color: #111;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
}

.ratio-picker-trigger:hover {
  background: #fafafa;
}

.ratio-picker-trigger:focus {
  outline: 2px solid #2563eb33;
  border-color: #2563eb;
}

.ratio-picker-label {
  flex: 1;
}

.ratio-picker-chev {
  color: #888;
  font-size: 11px;
  transition: transform 0.15s ease;
}

.ratio-picker[data-open="true"] .ratio-picker-chev {
  transform: rotate(180deg);
}

.ratio-picker-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #d4d4d4;
  border-radius: 6px;
  padding: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  z-index: 10;
  display: flex;
  flex-direction: column;
}

.ratio-picker-menu button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  border: none;
  border-radius: 4px;
  padding: 6px 8px;
  font-size: 14px;
  color: #111;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
}

.ratio-picker-menu button:hover {
  background: #f3f3f3;
}

.ratio-picker-menu button[aria-selected="true"] {
  background: #eef5ff;
  color: #1e40af;
}

.ratio-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.ratio-icon::before {
  content: '';
  display: block;
  background: currentColor;
  border-radius: 2px;
  opacity: 0.85;
}

.ratio-icon[data-ratio="16:9"]::before  { width: 20px; height: 11px; }
.ratio-icon[data-ratio="9:16"]::before  { width: 11px; height: 20px; }
.ratio-icon[data-ratio="1:1"]::before   { width: 16px; height: 16px; }
.ratio-icon[data-ratio="4:3"]::before   { width: 18px; height: 14px; }
.ratio-icon[data-ratio="3:4"]::before   { width: 14px; height: 18px; }
.ratio-icon[data-ratio="21:9"]::before  { width: 22px; height: 9px; }
.ratio-icon-auto::before                {
  width: 14px; height: 14px;
  background: transparent;
  border: 1.5px dashed currentColor;
  opacity: 0.7;
  border-radius: 2px;
}

/* ── Image inputs (de-emphasized optional chips) ────────── */

.image-inputs {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.image-chip {
  display: inline-flex;
  align-items: center;
  margin: 0;
  padding: 10px 14px; /* larger touch target on mobile */
  min-height: 44px;
  border: 1px dashed #c9c9cf;
  border-radius: 999px;
  background: transparent;
  color: #666;
  font-size: 12.5px;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}

.image-chip:hover {
  border-color: #999;
  color: #333;
  background: #f7f7f8;
}

.image-inputs-hint {
  font-size: 11.5px;
  color: #999;
}

.image-info-row {
  margin-bottom: 16px;
}

/* ── Prompt buy card (/?buy=<token>) ──────────────────────── */
.buy-card {
  background: #fff;
  border: 1px solid #e3e3e3;
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.buy-card-poster {
  width: 88px;
  height: 88px;
  object-fit: cover;
  border-radius: 6px;
  background: #f0f0f0;
  flex-shrink: 0;
  border: 1px solid #e3e3e3;
}

.buy-card-body {
  flex: 1;
  min-width: 0;
}

.buy-card-title {
  font-size: 14px;
  font-weight: 600;
  color: #111;
  margin: 0 0 6px;
}

.buy-card-sub {
  font-size: 13px;
  color: #555;
  margin: 0 0 12px;
}

.buy-card-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.buy-card-btn {
  width: auto;
  padding: 10px 20px;
  min-height: 44px;
  background: #111;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

.buy-card-btn:hover:not(:disabled) { background: #000; }
.buy-card-btn:disabled { background: #999; cursor: default; }

.buy-card-dismiss {
  width: auto;
  background: transparent;
  border: none;
  color: #888;
  font-size: 13px;
  padding: 4px 8px;
  cursor: pointer;
}

.buy-card-dismiss:hover { color: #333; }

.buy-success-note {
  font-size: 13px;
  color: #0a6c3a;
  background: #ecfdf3;
  border: 1px solid #c7eed5;
  border-radius: 6px;
  padding: 8px 12px;
  margin-top: 10px;
  display: inline-block;
}

@media (max-width: 480px) {
  .buy-card {
    flex-direction: column;
  }
  .buy-card-poster {
    width: 100%;
    height: 160px;
  }
}
