:root {
  color-scheme: dark;
  --bg: #0c0e13;
  --panel: #151821;
  --panel-2: #1b1f2a;
  --line: #2a3040;
  --text: #eef1f8;
  --muted: #929bad;
  --accent: #8b7cff;
  --accent-2: #b3a9ff;
  --danger: #ff7185;
  --success: #68d5a7;
  --warning: #f3c969;
  --radius: 16px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at top left, #19162d 0, transparent 32rem), var(--bg); color: var(--text); }
button, input, textarea, select { font: inherit; }
button, .button { cursor: pointer; }
.hidden { display: none !important; }
.error-text { color: var(--danger); min-height: 1.4em; }
.hint, small, .panel p { color: var(--muted); }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(420px, 100%); padding: 34px; background: color-mix(in srgb, var(--panel) 92%, transparent); border: 1px solid var(--line); border-radius: 24px; box-shadow: 0 24px 80px #0008; backdrop-filter: blur(18px); }
.login-card h1 { margin: 14px 0 4px; }
.login-card p { color: var(--muted); }
.login-card label { display: grid; gap: 8px; margin: 24px 0 16px; }
.brand-mark { width: 56px; height: 56px; border-radius: 18px; display: grid; place-items: center; font-weight: 900; font-size: 28px; background: linear-gradient(145deg, var(--accent), #4d67ff); box-shadow: 0 10px 30px #6255ff55; }
.brand-mark.small { width: 38px; height: 38px; border-radius: 12px; font-size: 20px; }

input, textarea, select { width: 100%; color: var(--text); background: #0f1219; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; outline: none; }
textarea { resize: vertical; line-height: 1.55; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px #8b7cff22; }
button, .button { border: 1px solid transparent; border-radius: 10px; padding: 9px 13px; color: var(--text); background: var(--panel-2); text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
button:hover, .button:hover { filter: brightness(1.12); }
button:disabled { opacity: .45; cursor: not-allowed; }
.primary { background: linear-gradient(135deg, var(--accent), #6377ff); color: white; box-shadow: 0 8px 24px #5d55ff28; }
.ghost { background: #202532; border-color: #333a4d; }
.danger { color: #ff9aaa; }
.wide { width: 100%; }
.giant { min-height: 54px; font-weight: 800; font-size: 17px; }

.app-shell { min-height: 100vh; }
.topbar { height: 66px; padding: 0 max(16px, env(safe-area-inset-left)); display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); background: #0d1017e8; position: sticky; top: 0; z-index: 30; backdrop-filter: blur(18px); }
.brand-inline { display: flex; align-items: center; gap: 11px; }
.brand-inline div { display: grid; }
.brand-inline small { font-size: 11px; }
.top-actions { display: flex; gap: 8px; }
.tabs { position: sticky; top: 66px; z-index: 25; background: #0d1017e8; display: flex; justify-content: center; gap: 6px; padding: 8px; border-bottom: 1px solid var(--line); backdrop-filter: blur(18px); }
.tab { min-width: 96px; background: transparent; color: var(--muted); }
.tab.active { background: var(--panel-2); color: var(--text); }
.badge { padding: 1px 6px; border-radius: 999px; background: #353d52; font-size: 11px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; max-width: 1500px; margin: 0 auto; padding: 16px; }
.editor-column { display: grid; gap: 16px; min-width: 0; }
.settings-column { min-width: 0; }
.sticky-settings { position: sticky; top: 126px; }
.panel { background: color-mix(in srgb, var(--panel) 96%, transparent); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: 0 12px 36px #0003; }
.panel h2 { margin: 0; font-size: 18px; }
.panel p { margin: 4px 0 0; font-size: 13px; }
.panel-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.scheme-grid { display: grid; grid-template-columns: 1.2fr 1fr auto auto auto; gap: 8px; }
.file-button { position: relative; }
.inline-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.prompt-primary { border-color: #45406e; }
#promptPreview { min-height: 150px; resize: none; overflow-y: hidden; }
.prompt-mode-hint { margin: 9px 0 10px !important; padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px; background: #10141d; }
.prompt-mode-hint[data-mode="direct"] { color: var(--warning); border-color: #665726; }
.prompt-mode-hint[data-mode="cards"] { color: var(--success); border-color: #275c4b; }

.tag-groups { display: grid; gap: 9px; }
.tag-group { border: 1px solid #292f3e; border-radius: 13px; background: #11141c; overflow: visible; }
.tag-group-header { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid #292f3e; cursor: pointer; list-style: none; user-select: none; }
.tag-group-header::-webkit-details-marker { display: none; }
.tag-group-header::before { content: '›'; color: var(--muted); transform: rotate(0deg); transition: transform .16s ease; }
.tag-group[open] > .tag-group-header::before { transform: rotate(90deg); }
.tag-group:not([open]) > .tag-group-header { border-bottom: 0; }
.tag-group-header strong { font-size: 14px; margin-right: auto; }
.tag-group-body { position: relative; }
.tag-count { color: var(--muted); font-size: 12px; }
.tag-list { min-height: 48px; display: flex; align-items: center; flex-wrap: wrap; gap: 7px; padding: 10px; }
.tag-list.drag-over { background: #8b7cff16; outline: 1px dashed var(--accent); outline-offset: -4px; }
.tag-chip { display: inline-flex; align-items: center; gap: 5px; padding: 5px 7px 5px 9px; border: 1px solid #394158; background: #202635; border-radius: 999px; user-select: none; max-width: 100%; }
.tag-chip.disabled { opacity: .42; text-decoration: line-through; }
.tag-chip.dragging { opacity: .25; }
.tag-text { max-width: 330px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.tag-weight { color: var(--accent-2); font-size: 11px; min-width: 26px; text-align: center; }
.chip-btn { width: 22px; height: 22px; padding: 0; border-radius: 50%; background: #111520; border-color: #353d50; font-size: 12px; }
.tag-add { position: relative; display: flex; gap: 8px; padding: 0 10px 10px; }
.tag-add input { padding: 8px 10px; }
.suggestion-menu { position: absolute; z-index: 50; left: 10px; right: 52px; top: calc(100% - 8px); max-height: 240px; overflow: auto; background: #171b25; border: 1px solid #3a4256; border-radius: 10px; box-shadow: 0 14px 40px #0009; }
.suggestion-item { display: flex; justify-content: space-between; width: 100%; border: 0; border-radius: 0; background: transparent; padding: 9px 11px; text-align: left; }
.suggestion-item:hover, .suggestion-item.active { background: #2a3042; }
.suggestion-item small { font-variant-numeric: tabular-nums; }

.snippet-create { display: grid; grid-template-columns: 160px 1fr auto; gap: 8px; }
.snippet-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.snippet-card { display: flex; align-items: center; gap: 7px; padding: 7px 9px; border: 1px solid #353c50; border-radius: 10px; background: #202532; }
.snippet-card button { padding: 4px 7px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-grid label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.check-label { display: flex !important; align-items: center; gap: 8px; color: var(--text) !important; }
.check-label input { width: auto; accent-color: var(--accent); }
.advanced-box { border: 1px solid var(--line); border-radius: 10px; padding: 9px; }
.advanced-box summary { cursor: pointer; color: var(--muted); }
.generate-box { display: grid; gap: 9px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.quick-counts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.custom-generate { display: grid; grid-template-columns: 90px 1fr; gap: 8px; }

.standalone { max-width: 1200px; margin: 16px auto; }
.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
.metric { padding: 12px; background: #10141d; border: 1px solid var(--line); border-radius: 12px; }
.metric strong { display: block; font-size: 22px; }
.metric span { color: var(--muted); font-size: 12px; }
.queue-list { display: grid; gap: 8px; }
.queue-item { display: grid; grid-template-columns: 1fr auto; gap: 10px; padding: 11px; background: #11151e; border: 1px solid var(--line); border-radius: 12px; }
.queue-main { display: grid; gap: 5px; min-width: 0; }
.queue-line { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.status { font-size: 11px; padding: 3px 7px; border-radius: 999px; background: #30384a; }
.status.running { background: #6459d4; }
.status.completed { background: #1d7558; }
.status.failed { background: #8a3444; }
.status.pending { background: #665726; }
.status.cancelled { background: #4a4d55; }
.queue-error { color: #ff9aaa; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; }

.storage-meter { display: grid; gap: 6px; margin-bottom: 14px; }
.meter-track { width: 100%; height: 10px; overflow: hidden; appearance: none; border: 1px solid var(--line); border-radius: 999px; background: #0d1017; }
.meter-track::-webkit-progress-bar { background: #0d1017; }
.meter-track::-webkit-progress-value { background: linear-gradient(90deg, var(--success), var(--warning)); }
.meter-track::-moz-progress-bar { background: linear-gradient(90deg, var(--success), var(--warning)); }
.quick-latest { min-height: 110px; display: grid; place-items: center; overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: #0b0e14; color: var(--muted); cursor: pointer; }
.quick-latest img { display: block; width: 100%; max-height: 320px; object-fit: contain; }
.gallery-grid { columns: 5 210px; column-gap: 10px; }
.gallery-card { break-inside: avoid; margin: 0 0 10px; display: block; position: relative; border: 1px solid var(--line); background: #10131a; border-radius: 12px; overflow: hidden; cursor: pointer; }
.gallery-card img { display: block; width: 100%; height: auto; background: #0a0c10; }
.gallery-card footer { padding: 8px; display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; }
.favorite-mark { position: absolute; top: 8px; right: 8px; padding: 4px 7px; border-radius: 999px; background: #111b; color: #ffd86f; }
.empty-state:empty, .empty-state { color: var(--muted); text-align: center; padding: 28px; }
.empty-state:not(:empty):has(.gallery-card), .empty-state:not(:empty):has(.queue-item), .empty-state:not(:empty):has(.snippet-card) { text-align: initial; padding: 0; color: inherit; }

.image-dialog, .json-dialog { width: min(1120px, calc(100vw - 24px)); max-height: calc(100vh - 24px); padding: 0; border: 1px solid var(--line); border-radius: 18px; background: #11141c; color: var(--text); box-shadow: 0 30px 100px #000c; }
dialog::backdrop { background: #000a; backdrop-filter: blur(5px); }
.dialog-header { position: sticky; top: 0; z-index: 3; display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; background: #151923; border-bottom: 1px solid var(--line); }
.icon-button { width: 34px; height: 34px; padding: 0; font-size: 22px; }
.dialog-body { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(300px, .6fr); }
.dialog-image-wrap { display: grid; place-items: center; padding: 12px; min-height: 420px; background: #080a0e; }
.dialog-image-wrap img { max-width: 100%; max-height: calc(100vh - 100px); object-fit: contain; }
.dialog-info { padding: 16px; overflow: auto; max-height: calc(100vh - 70px); }
.meta-list { display: grid; gap: 10px; margin-bottom: 14px; }
.meta-row { display: grid; gap: 3px; }
.meta-row span { color: var(--muted); font-size: 11px; }
.meta-row code { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--text); background: #0b0e14; padding: 8px; border-radius: 8px; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.json-dialog pre { margin: 0; padding: 16px; overflow: auto; max-height: calc(100vh - 80px); white-space: pre-wrap; font-size: 12px; }
.toast-host { position: fixed; right: 14px; bottom: 14px; z-index: 100; display: grid; gap: 8px; width: min(360px, calc(100vw - 28px)); }
.toast { padding: 11px 13px; border: 1px solid var(--line); border-radius: 11px; background: #202635; box-shadow: 0 12px 35px #0008; }
.toast.error { border-color: #85394b; }
.toast.success { border-color: #27785c; }

body.compact .tabs, body.compact .editor-column > :not(.scheme-panel), body.compact .form-grid, body.compact .panel-title-row p { display: none; }
body.compact .workspace { grid-template-columns: minmax(0, 680px); justify-content: center; padding-top: 34px; }
body.compact .settings-column { grid-row: 2; }
body.compact .sticky-settings { position: static; }
body.compact .scheme-grid { grid-template-columns: 1fr; }
body.compact .scheme-grid > :not(#schemeSelect) { display: none; }
body.compact .generate-box { border-top: 0; margin-top: 0; padding-top: 0; }

@media (max-width: 960px) {
  .workspace { grid-template-columns: 1fr; }
  .sticky-settings { position: static; }
  .scheme-grid { grid-template-columns: 1fr 1fr; }
  .gallery-grid { columns: 3 180px; }
}
@media (max-width: 640px) {
  .topbar { height: auto; min-height: 62px; padding-block: 8px; }
  .top-actions { gap: 4px; }
  .top-actions button { font-size: 12px; padding: 7px 8px; }
  .tabs { top: 62px; }
  .tab { min-width: 78px; }
  .workspace { padding: 10px; gap: 10px; }
  .panel { padding: 13px; border-radius: 13px; }
  .scheme-grid, .snippet-create { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .gallery-grid { columns: 2 140px; column-gap: 8px; }
  .gallery-card { margin-bottom: 8px; }
  .dialog-body { grid-template-columns: 1fr; }
  .dialog-image-wrap { min-height: 300px; }
  .dialog-info { max-height: none; }
  .tag-text { max-width: 190px; }
  .tag-add input, #promptPreview, #negativePrompt { font-size: 16px; }
  .prompt-primary .panel-title-row { align-items: center; }
  .prompt-primary .inline-actions button { flex: 1 1 220px; }
}

/* v0.3 mobile-first bilingual Tag editor */
.tag-panel-heading { align-items: center; }
.compact-actions { justify-content: flex-end; }
.compact-actions button { padding: 7px 10px; }
.tag-display-options { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: -2px 0 12px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 11px; background: #10141d; }
.tag-display-options .hint { font-size: 12px; }
.prompt-import-actions button { min-height: 42px; }

.tag-list { min-height: 48px; display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); align-items: stretch; gap: 8px; padding: 10px; }
.tag-card { min-width: 0; display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; align-items: center; gap: 7px; min-height: 58px; padding: 7px; border: 1px solid #394158; border-radius: 12px; background: linear-gradient(145deg, #202635, #1b202d); user-select: none; touch-action: manipulation; }
.tag-card:hover { border-color: #4d5874; }
.tag-card.disabled { opacity: .48; }
.tag-card.disabled .tag-copy strong { text-decoration: line-through; }
.tag-card.dragging { opacity: .25; }
.tag-enable { width: 34px; height: 40px; padding: 0; border-radius: 10px; border-color: #46506a; background: #111722; color: var(--success); font-weight: 900; }
.tag-card.disabled .tag-enable { color: var(--muted); }
.tag-copy { min-width: 0; display: grid; gap: 3px; padding: 4px 2px; border: 0; border-radius: 8px; background: transparent; text-align: left; justify-items: start; }
.tag-copy strong { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); font-size: 13px; font-weight: 650; }
.tag-copy small { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--accent-2); font-size: 11px; }
.tag-copy small.missing { color: #6f788a; }
.tag-card.translations-hidden { min-height: 48px; }
.tag-card.translations-hidden .tag-copy small { display: none; }
.tag-controls { display: flex; align-items: center; gap: 4px; }
.tag-controls .chip-btn { flex: 0 0 auto; width: 30px; height: 34px; border-radius: 9px; font-size: 15px; }
.tag-controls .chip-btn.edit { font-size: 14px; color: var(--accent-2); }
.tag-controls .tag-weight { min-width: 38px; height: 34px; padding: 0 5px; border-radius: 9px; border-color: #3b455d; background: #111722; color: var(--accent-2); font-size: 11px; font-variant-numeric: tabular-nums; }
.drag-handle { display: inline-grid; place-items: center; width: 18px; height: 34px; color: #687188; cursor: grab; letter-spacing: -5px; overflow: hidden; }
.tag-add { align-items: stretch; padding: 0 10px 10px; }
.tag-add input { min-height: 44px; }
.tag-add-button { width: 48px; min-width: 48px; min-height: 44px; padding: 0; font-size: 22px; }
.suggestion-menu { right: 66px; top: calc(100% - 6px); max-height: min(44vh, 340px); overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.suggestion-item { min-height: 54px; align-items: center; gap: 10px; padding: 8px 11px; touch-action: manipulation; }
.suggestion-copy { min-width: 0; display: grid; gap: 3px; text-align: left; }
.suggestion-copy strong, .suggestion-copy small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggestion-copy strong { color: var(--text); font-size: 13px; }
.suggestion-copy small { color: var(--accent-2); font-size: 11px; }
.suggestion-count { flex: 0 0 auto; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.suggestion-loading, .suggestion-empty { padding: 13px; color: var(--muted); font-size: 12px; line-height: 1.5; }

.tag-editor-dialog { width: min(560px, calc(100vw - 20px)); max-height: calc(100dvh - 20px); padding: 0; border: 1px solid var(--line); border-radius: 18px; background: #11141c; color: var(--text); box-shadow: 0 30px 100px #000c; }
.tag-editor-dialog form { margin: 0; }
.tag-editor-body { display: grid; gap: 14px; padding: 16px; overflow: auto; max-height: calc(100dvh - 78px); }
.tag-editor-body label { display: grid; gap: 7px; color: var(--muted); font-size: 12px; }
.translation-edit-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.tag-editor-grid { display: grid; grid-template-columns: 1.5fr .7fr; gap: 10px; }
.tag-editor-order { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tag-editor-actions { justify-content: flex-end; padding-top: 4px; }
.tag-editor-actions #tagEditorDelete { margin-right: auto; }

@media (max-width: 720px) {
  .tag-panel-heading { align-items: flex-start; }
  .compact-actions { width: 100%; justify-content: stretch; }
  .compact-actions button { flex: 1 1 calc(50% - 6px); min-height: 40px; }
  .tag-display-options { align-items: flex-start; }
  .tag-list { grid-template-columns: 1fr; padding: 8px; gap: 7px; }
  .tag-card { grid-template-columns: 38px minmax(0, 1fr); min-height: 64px; padding: 7px 8px; }
  .tag-controls { grid-column: 1 / -1; justify-content: flex-end; padding-left: 44px; margin-top: -2px; }
  .tag-controls .chip-btn, .tag-controls .tag-weight { min-height: 38px; }
  .drag-handle { display: none; }
  .tag-copy strong { white-space: normal; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .tag-copy small { white-space: normal; overflow-wrap: anywhere; }
  .tag-card.translations-hidden { min-height: 48px; grid-template-columns: 38px minmax(0, 1fr) auto; }
  .tag-card.translations-hidden .tag-controls { grid-column: auto; padding-left: 0; margin-top: 0; }
  .tag-card.translations-hidden .tag-controls .edit, .tag-card.translations-hidden .drag-handle { display: none; }
  .tag-add { position: relative; padding: 0 8px 9px; }
  .suggestion-menu { left: 8px; right: 64px; max-height: min(38dvh, 300px); }
  .suggestion-item { min-height: 58px; }
  .translation-edit-row { grid-template-columns: 1fr; }
  .tag-editor-grid { grid-template-columns: 1fr 1fr; }
  .tag-editor-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .tag-editor-actions #tagEditorDelete { margin-right: 0; grid-column: 1 / -1; }
  .tag-editor-actions .primary { grid-column: 2; }
  .prompt-import-actions { display: grid; grid-template-columns: 1fr; }
  .prompt-import-actions button { width: 100%; }
}

@media (max-width: 420px) {
  .tag-card { grid-template-columns: 36px minmax(0, 1fr); }
  .tag-controls { padding-left: 42px; }
  .tag-controls .chip-btn { width: 36px; }
  .tag-controls .tag-weight { min-width: 42px; }
  .tag-editor-grid { grid-template-columns: 1fr; }
}

.character-list { display: grid; gap: 12px; }
.character-card { display: grid; gap: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: #131823; }
.character-card.disabled { opacity: .6; }
.character-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.character-card label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; }
.character-card input, .character-card textarea { width: 100%; }
.gallery-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.gallery-card.selected { outline: 2px solid var(--accent); outline-offset: 1px; }
.gallery-check { position: absolute; top: 8px; left: 8px; width: 30px; height: 30px; border-radius: 999px; border: 1px solid #506080; background: rgba(12,15,25,.8); color: var(--text); font-weight: 700; }
@media (max-width: 720px) {
  .character-head { align-items: flex-start; }
  .gallery-toolbar button { flex: 1 1 calc(50% - 6px); }
}

/* v0.5 character Tag editor */
.character-head > div:first-child { display: grid; gap: 3px; }
.character-head small { color: var(--muted); font-size: 11px; }
.character-tag-area { display: grid; gap: 8px; border-top: 1px solid var(--line); padding-top: 10px; }
.character-tag-title { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 12px; }
.character-tag-title span { min-width: 28px; padding: 2px 7px; border: 1px solid var(--line); border-radius: 999px; text-align: center; }
.character-tag-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 8px; min-height: 10px; }
.character-tag-add { padding: 0; grid-template-columns: minmax(0, 1fr) 48px auto; }
.whole-add-button { min-height: 44px; padding-inline: 12px; white-space: nowrap; }
.bundle-mark { display: inline-block; margin-left: 7px; padding: 1px 5px; border: 1px solid #58627a; border-radius: 999px; color: var(--muted); font-size: 9px; font-style: normal; font-weight: 500; vertical-align: middle; }
.tag-controls .danger { color: var(--danger); }
.character-tag-card .tag-copy strong { white-space: normal; overflow-wrap: anywhere; }
.character-tag-add .suggestion-menu { right: 118px; }

@media (max-width: 720px) {
  .character-tag-list { grid-template-columns: 1fr; }
  .character-tag-add { grid-template-columns: minmax(0, 1fr) 48px; }
  .character-tag-add .whole-add-button { grid-column: 1 / -1; width: 100%; }
  .character-tag-add .suggestion-menu { right: 64px; }
  .tag-add:not(.character-tag-add) { grid-template-columns: minmax(0, 1fr) 48px; }
  .tag-add:not(.character-tag-add) .whole-add-button { grid-column: 1 / -1; width: 100%; }
}
.character-tag-add { display: grid; }
@media (max-width: 720px) {
  .tag-add:not(.character-tag-add) { display: grid; }
}

/* v0.6 semantic search, collapsible panels and floating generation */
.collapsible-panel-body { display: grid; gap: 12px; }
.panel.collapsed > .collapsible-panel-body { display: none; }
.panel.collapsed > .panel-title-row { margin-bottom: 0; }
.panel-collapse-button { margin-left: auto; min-width: 58px; }
.panel-title-row > .panel-collapse-button:last-child { flex: 0 0 auto; }

.semantic-open-button { min-height: 44px; padding-inline: 12px; white-space: nowrap; color: var(--accent-2); }
.tag-add:not(.character-tag-add) { display: grid; grid-template-columns: minmax(0, 1fr) 48px auto auto; }
.character-tag-add { grid-template-columns: minmax(0, 1fr) 48px auto auto; }
.tag-add .suggestion-menu { right: 180px; }
.character-tag-add .suggestion-menu { right: 180px; }

.chip-btn.holding { background: var(--accent); color: white; transform: scale(.96); }
.tag-controls .danger { font-size: 17px; font-weight: 800; }

.semantic-dialog { width: min(820px, calc(100vw - 20px)); max-height: calc(100dvh - 20px); padding: 0; border: 1px solid var(--line); border-radius: 18px; background: #11141c; color: var(--text); box-shadow: 0 30px 100px #000d; }
.semantic-dialog .dialog-header > div { display: grid; gap: 3px; }
.semantic-dialog .dialog-header small { font-size: 11px; }
.semantic-body { display: grid; gap: 12px; padding: 14px; max-height: calc(100dvh - 78px); overflow: auto; overscroll-behavior: contain; }
.semantic-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.semantic-tab { background: #181d28; border-color: var(--line); color: var(--muted); }
.semantic-tab.active { background: #292e45; border-color: #56508c; color: var(--text); }
.semantic-pane { display: none; gap: 11px; }
.semantic-pane.active { display: grid; }
.semantic-pane label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; }
.semantic-options { display: grid; grid-template-columns: 1fr 1fr auto; gap: 9px; align-items: end; }
.semantic-nsfw { min-height: 42px; padding: 0 5px 7px; white-space: nowrap; }
.semantic-status { padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px; background: #0f131b; }
.semantic-results { display: grid; gap: 8px; min-height: 80px; }
.semantic-result-card { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 9px; align-items: stretch; padding: 8px; border: 1px solid #353d50; border-radius: 12px; background: #171c27; }
.semantic-result-card.already-added { opacity: .62; }
.semantic-result-main { min-width: 0; display: grid; gap: 3px; align-content: center; padding: 5px 7px; border: 0; background: transparent; text-align: left; color: var(--text); }
button.semantic-result-main { justify-content: stretch; }
.semantic-result-main strong { overflow-wrap: anywhere; font-size: 14px; }
.semantic-result-main span { color: var(--accent-2); font-size: 12px; }
.semantic-result-main small { color: var(--muted); font-size: 11px; }
.semantic-result-main em { color: #aab2c4; font-size: 11px; font-style: normal; line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.semantic-result-add { min-width: 76px; }
.semantic-credit { margin: 2px 0 0 !important; font-size: 11px !important; text-align: center; }
.semantic-credit a { color: var(--accent-2); }

.app-shell { padding-bottom: calc(82px + env(safe-area-inset-bottom)); }
.floating-generate-bar { position: fixed; z-index: 70; left: 50%; bottom: max(10px, env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(520px, calc(100vw - 20px)); display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; padding: 8px; border: 1px solid #484260; border-radius: 16px; background: #10141de8; box-shadow: 0 16px 48px #000b; backdrop-filter: blur(18px); }
.floating-generate-button { min-height: 50px; font-size: 16px; font-weight: 850; }
.floating-queue-button { min-width: 92px; }

@media (max-width: 720px) {
  .panel-title-row { flex-wrap: wrap; }
  .panel-collapse-button { margin-left: 0; }
  .tag-add:not(.character-tag-add), .character-tag-add { grid-template-columns: minmax(0, 1fr) 48px; }
  .tag-add .whole-add-button, .tag-add .semantic-open-button { width: 100%; }
  .tag-add .suggestion-menu, .character-tag-add .suggestion-menu { right: 64px; }
  .semantic-options { grid-template-columns: 1fr 1fr; }
  .semantic-nsfw { grid-column: 1 / -1; padding-bottom: 0; }
  .semantic-result-card { grid-template-columns: minmax(0, 1fr) 74px; }
  .semantic-result-add { min-width: 0; padding-inline: 8px; }
  .floating-generate-bar { bottom: max(6px, env(safe-area-inset-bottom)); width: calc(100vw - 12px); border-radius: 14px; }
}

@media (max-width: 430px) {
  .semantic-tabs { grid-template-columns: 1fr; }
  .semantic-options { grid-template-columns: 1fr; }
  .semantic-nsfw { grid-column: auto; }
  .floating-generate-bar { grid-template-columns: minmax(0, 1fr) 82px; }
}

/* v0.6.1: generation controls stay outside the collapsible parameter panel */
.generation-panel .generate-box {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

/* “整块 / 语义” share one balanced action row */
.tag-add:not(.character-tag-add),
.character-tag-add {
  grid-template-columns: minmax(0, 1fr) 48px minmax(168px, .52fr);
}
.tag-extra-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  min-width: 0;
}
.tag-add .tag-extra-actions > .whole-add-button,
.tag-add .tag-extra-actions > .semantic-open-button {
  grid-column: auto;
  width: 100%;
  min-width: 0;
}

@media (max-width: 720px) {
  .tag-add:not(.character-tag-add),
  .character-tag-add {
    grid-template-columns: minmax(0, 1fr) 48px;
  }
  .tag-extra-actions {
    grid-column: 1 / -1;
  }
  .tag-add .tag-extra-actions > .whole-add-button,
  .tag-add .tag-extra-actions > .semantic-open-button {
    grid-column: auto;
    width: 100%;
  }
}

/* v0.7 image inspector and frictionless gallery controls */
.gallery-delete-button,
.gallery-favorite-button,
.gallery-check {
  position: absolute;
  z-index: 4;
  top: 8px;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid #596277;
  border-radius: 999px;
  background: rgba(11, 14, 21, .82);
  box-shadow: 0 4px 16px #0008;
  backdrop-filter: blur(8px);
  font-size: 19px;
  line-height: 1;
}
.gallery-delete-button { left: 8px; color: #ff9bad; }
.gallery-favorite-button { right: 8px; color: #d2d6df; }
.gallery-favorite-button.active { color: #ffd86f; border-color: #8a763b; }
.gallery-check { left: 8px; color: var(--text); font-size: 16px; font-weight: 800; }
.gallery-grid.selection-mode .gallery-delete-button { display: none; }
.gallery-card.selected::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  border: 3px solid var(--accent);
  border-radius: 11px;
  box-shadow: inset 0 0 0 2px #0b0d14aa;
}
.gallery-card > button:active { transform: scale(.92); }
.gallery-toolbar { position: sticky; top: 112px; z-index: 9; padding: 8px; border: 1px solid var(--line); border-radius: 12px; background: #11151eea; backdrop-filter: blur(14px); }

.inspect-dialog {
  width: min(1060px, calc(100vw - 20px));
  max-height: calc(100dvh - 20px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #11141c;
  color: var(--text);
  box-shadow: 0 30px 100px #000d;
}
.inspect-dialog .dialog-header > div { display: grid; gap: 3px; }
.inspect-dialog .dialog-header small { color: var(--muted); font-size: 11px; }
.inspect-body { display: grid; grid-template-columns: minmax(260px, .8fr) minmax(320px, 1.2fr); max-height: calc(100dvh - 70px); }
.inspect-preview-wrap { min-height: 420px; display: grid; place-items: center; padding: 12px; background: #080a0e; }
.inspect-preview-wrap img { max-width: 100%; max-height: calc(100dvh - 100px); object-fit: contain; }
.inspect-info { min-width: 0; padding: 16px; overflow: auto; }
.inspect-raw-box { margin: 12px 0; border: 1px solid var(--line); border-radius: 11px; background: #0c0f16; }
.inspect-raw-box summary { padding: 10px 12px; cursor: pointer; color: var(--accent-2); }
.inspect-raw-box pre { max-height: 320px; margin: 0; padding: 12px; overflow: auto; border-top: 1px solid var(--line); white-space: pre-wrap; overflow-wrap: anywhere; font-size: 11px; }
.inspect-warnings { display: grid; gap: 6px; padding: 10px 12px; border: 1px solid #765b28; border-radius: 10px; background: #2d2415; color: #ffd990; }
.inspect-warnings p { margin: 0; font-size: 12px; }
.inspect-actions { justify-content: flex-end; }

@media (max-width: 720px) {
  .gallery-toolbar { top: 111px; }
  .gallery-delete-button,
  .gallery-favorite-button,
  .gallery-check { width: 38px; height: 38px; }
  .inspect-body { grid-template-columns: 1fr; overflow: auto; }
  .inspect-preview-wrap { min-height: 240px; max-height: 42dvh; }
  .inspect-preview-wrap img { max-height: 38dvh; }
  .inspect-info { overflow: visible; }
  .inspect-actions { display: grid; grid-template-columns: 1fr 1fr; }
}
.inspect-drop-overlay {
  position: fixed;
  z-index: 140;
  inset: 14px;
  display: grid;
  place-items: center;
  border: 3px dashed #8c83ff;
  border-radius: 22px;
  background: #0c0f17e8;
  color: #dedbff;
  font-size: clamp(18px, 4vw, 30px);
  font-weight: 800;
  text-align: center;
  pointer-events: none;
  backdrop-filter: blur(12px);
}

/* v0.7.1 large-image viewer */
.dialog-title-stack { display: grid; gap: 2px; }
.dialog-title-stack small { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.image-dialog { overflow: hidden; }
.image-dialog .dialog-body { max-height: calc(100dvh - 70px); }
.image-viewer-column {
  min-width: 0;
  min-height: 0;
  max-height: calc(100dvh - 70px);
  display: flex;
  flex-direction: column;
  background: #080a0e;
  border-right: 1px solid var(--line);
}
.dialog-image-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  flex: 1 1 auto;
  display: grid;
  place-items: center;
  overflow: hidden;
  touch-action: pan-y;
}
.dialog-image-stage .dialog-image-wrap {
  width: 100%;
  min-height: 0;
  height: 100%;
  padding: 12px 54px;
}
.dialog-image-stage .dialog-image-wrap img {
  max-height: calc(100dvh - 155px);
}
.dialog-nav {
  position: absolute;
  z-index: 5;
  top: 50%;
  width: 42px;
  height: 72px;
  display: grid;
  place-items: center;
  padding: 0;
  transform: translateY(-50%);
  border: 1px solid #616a7e;
  border-radius: 13px;
  background: rgba(11, 14, 21, .78);
  color: #f3f4f8;
  box-shadow: 0 8px 28px #0009;
  backdrop-filter: blur(10px);
  font-size: 35px;
  line-height: 1;
}
.dialog-nav:hover:not(:disabled) { background: rgba(35, 41, 57, .9); border-color: var(--accent); }
.dialog-nav:active:not(:disabled) { transform: translateY(-50%) scale(.94); }
.dialog-nav:disabled { opacity: .18; cursor: default; }
.dialog-nav-previous { left: 10px; }
.dialog-nav-next { right: 10px; }
.dialog-image-actions {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--line);
  background: #11151d;
}
.dialog-image-actions > * {
  min-width: 0;
  min-height: 43px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.dialog-favorite-button.active { color: #ffd86f; border-color: #8a763b; }
.dialog-secondary-actions { margin-top: 14px; }

@media (max-width: 720px) {
  .image-dialog { width: calc(100vw - 10px); max-height: calc(100dvh - 10px); border-radius: 14px; }
  .image-dialog .dialog-body { display: block; max-height: calc(100dvh - 62px); overflow-y: auto; overscroll-behavior: contain; }
  .image-viewer-column { max-height: none; border-right: 0; border-bottom: 1px solid var(--line); }
  .dialog-image-stage { min-height: 240px; max-height: calc(100dvh - 178px); }
  .dialog-image-stage .dialog-image-wrap { height: auto; min-height: 240px; padding: 8px 43px; }
  .dialog-image-stage .dialog-image-wrap img { max-height: calc(100dvh - 195px); }
  .dialog-nav { width: 36px; height: 62px; border-radius: 11px; font-size: 30px; }
  .dialog-nav-previous { left: 5px; }
  .dialog-nav-next { right: 5px; }
  .dialog-image-actions { position: sticky; top: 0; z-index: 6; padding: 8px; background: #11151df2; backdrop-filter: blur(12px); }
  .dialog-image-actions > * { min-height: 44px; padding-inline: 8px; }
  .image-dialog .dialog-info { padding: 13px; }
}

@media (max-width: 390px) {
  .dialog-image-actions { gap: 6px; }
  .dialog-image-actions > * { font-size: 12px; }
}
