:root {
  color-scheme: light;
  --bg: #fff1df;
  --bg-2: #ffd8b5;
  --surface: rgba(255, 247, 235, 0.9);
  --surface-solid: #fff8ed;
  --surface-raised: rgba(255, 252, 246, 0.97);
  --ink: #2c150b;
  --text: #442518;
  --muted: #8a6046;
  --line: rgba(108, 58, 28, 0.15);
  --line-strong: rgba(108, 58, 28, 0.26);
  --brand: #d85a28;
  --brand-strong: #a43d1c;
  --accent: #f2a33a;
  --accent-2: #a7372d;
  --success: #157347;
  --danger: #b42318;
  --warning: #966400;
  --shadow-lg: 0 18px 50px rgba(131, 61, 22, 0.2);
  --shadow-md: 0 10px 26px rgba(131, 61, 22, 0.14);
  --radius: 24px;
  --radius-sm: 18px;
  --radius-control: 999px;
  --focus: 0 0 0 3px rgba(216, 90, 40, 0.22);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #02050c;
  --bg-2: #071320;
  --surface: rgba(5, 11, 22, 0.92);
  --surface-solid: #050914;
  --surface-raised: rgba(8, 17, 31, 0.98);
  --ink: #ffffff;
  --text: #ffffff;
  --muted: #ffffff;
  --line: rgba(148, 180, 214, 0.2);
  --line-strong: rgba(168, 202, 237, 0.34);
  --brand: #58bfff;
  --brand-strong: #a8ddff;
  --accent: #7dd3fc;
  --accent-2: #6d8dff;
  --success: #67e8f9;
  --danger: #ff7a9e;
  --warning: #93c5fd;
  --shadow-lg: 0 18px 56px rgba(0, 0, 0, 0.42);
  --shadow-md: 0 12px 34px rgba(0, 0, 0, 0.32);
  --focus: 0 0 0 3px rgba(88, 191, 255, 0.28);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  min-width: 320px;
  color: var(--text);
  font-family:
    "Aptos",
    "Segoe UI Variable",
    "Segoe UI",
    "Microsoft YaHei",
    sans-serif;
  background:
    radial-gradient(circle at 18% -10%, rgba(255, 255, 255, 0.85), transparent 34%),
    radial-gradient(circle at 88% 12%, rgba(242, 163, 58, 0.22), transparent 32%),
    linear-gradient(rgba(164, 61, 28, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(216, 90, 40, 0.05) 1px, transparent 1px),
    linear-gradient(135deg, var(--bg) 0%, var(--bg-2) 100%);
  background-size: auto, auto, 44px 44px, 44px 44px, auto;
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

svg {
  display: block;
}

.app-shell {
  width: min(100vw, 1920px);
  height: 100vh;
  margin: 0 auto;
  padding: 14px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
}

.topbar {
  min-height: 64px;
  display: grid;
  grid-template-columns: minmax(260px, 420px) minmax(420px, 1fr);
  gap: 12px;
  align-items: stretch;
}

.brand-block,
.topbar-controls,
.panel,
.settings-panel,
.history-hover-detail,
.image-lightbox-panel {
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(18px);
}

.brand-block {
  border-radius: var(--radius);
  padding: 10px;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}

.brand-mark {
  width: 46px;
  height: 46px;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #fff4de, #ffb36b);
  box-shadow: 0 10px 24px rgba(164, 61, 28, 0.24);
  overflow: hidden;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  display: block;
}

.brand-copy {
  min-width: 0;
}

.brand-copy h1 {
  margin: 0;
  color: var(--ink);
  font-family: "Bahnschrift", "Segoe UI", sans-serif;
  font-size: 1.12rem;
  font-weight: 750;
  line-height: 1.15;
  letter-spacing: 0;
}

.model-name {
  margin-top: 4px;
  max-width: 100%;
  display: inline-flex;
  align-items: center;
  color: var(--brand);
  font-size: 0.78rem;
  font-weight: 760;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-controls {
  border-radius: var(--radius);
  padding: 10px;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.quick-model-switch {
  min-width: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.quick-model-switch > span,
label > span,
.eyebrow {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 780;
  text-transform: uppercase;
  letter-spacing: 0;
}

.quick-model-switch select {
  min-width: 0;
}

.header-actions,
.inline,
.inline-actions,
.image-lightbox-actions,
.setting-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.workbench {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(310px, 360px) minmax(420px, 1fr) minmax(310px, 420px);
  gap: 12px;
}

.panel {
  min-width: 0;
  min-height: 0;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.compose-panel {
  padding: 12px;
  gap: 10px;
  overflow-y: auto;
  scrollbar-gutter: stable;
}

.preview-panel {
  padding: 12px;
}

.gallery-panel {
  padding: 12px;
  gap: 8px;
}

.panel-head,
.settings-head,
.section-head,
.right-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.panel-head {
  flex: 0 0 auto;
}

.panel-head.compact {
  align-items: center;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--accent);
}

h2,
h3 {
  margin: 0;
  color: var(--ink);
  letter-spacing: 0;
}

h2 {
  font-size: 1rem;
  line-height: 1.2;
}

h3 {
  font-size: 0.86rem;
  line-height: 1.25;
}

.soft-stat,
.meta-text,
.section-head span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 680;
}

label {
  display: block;
}

label > span {
  display: block;
  margin-bottom: 6px;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-raised);
  color: var(--text);
  outline: none;
  transition:
    border-color 0.18s ease,
    box-shadow 0.18s ease,
    background-color 0.18s ease;
}

input,
select {
  height: 38px;
  padding: 0 11px;
}

select {
  appearance: none;
  padding-right: 34px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 17px) 16px,
    calc(100% - 11px) 16px;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  overflow: hidden;
  text-overflow: ellipsis;
}

textarea {
  min-height: 96px;
  padding: 11px;
  resize: vertical;
  line-height: 1.55;
}

input:hover,
select:hover,
textarea:hover {
  border-color: var(--line-strong);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: var(--focus);
}

.prompt-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.prompt-wrap {
  position: relative;
}

#promptInput {
  width: 100%;
  min-width: 0;
  min-height: 210px;
  max-height: 44vh;
  padding: 14px 46px 14px 14px;
  overflow: auto;
  resize: vertical;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  outline: none;
  font: inherit;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.5), transparent),
    var(--surface-raised);
  border-color: var(--line-strong);
  cursor: text;
  transition:
    border-color 0.18s ease,
    box-shadow 0.18s ease,
    background-color 0.18s ease;
}

#promptInput:hover {
  border-color: var(--line-strong);
}

#promptInput:focus {
  border-color: var(--brand);
  box-shadow: var(--focus);
}

#promptInput:empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
  pointer-events: none;
}

.prompt-ref-chip {
  display: inline-flex;
  width: 44px;
  height: 44px;
  margin: 0 4px;
  overflow: hidden;
  vertical-align: middle;
  border: 1px solid rgba(216, 90, 40, 0.42);
  border-radius: var(--radius-sm);
  background: var(--surface-solid);
  box-shadow: 0 5px 14px rgba(57, 36, 24, 0.14);
  cursor: grab;
  user-select: none;
}

.prompt-ref-chip:active {
  cursor: grabbing;
}

.prompt-ref-chip.is-dragging {
  opacity: 0.48;
}

.prompt-ref-chip img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

.save-template-fab {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--surface-solid);
  color: var(--accent-2);
  display: grid;
  place-items: center;
  cursor: pointer;
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
  transition:
    opacity 0.18s ease,
    transform 0.18s ease,
    border-color 0.18s ease;
}

.save-template-fab svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.prompt-wrap:hover .save-template-fab,
.prompt-wrap:focus-within .save-template-fab {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.control-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 104px;
  gap: 8px;
}

.tool-section,
.ref-block {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.42);
  padding: 10px;
  display: grid;
  gap: 9px;
}

html[data-theme="dark"] .tool-section,
html[data-theme="dark"] .ref-block {
  background: rgba(255, 255, 255, 0.035);
}

.inline {
  width: 100%;
}

.inline select {
  flex: 1 1 auto;
}

.full-width {
  width: 100%;
  justify-content: center;
}

.icon-btn,
.ghost-btn,
.primary-btn,
.ref-mini-btn,
.timeline-icon-btn,
.tiny-btn {
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  cursor: pointer;
  color: var(--text);
  background: var(--surface-raised);
  font-weight: 750;
  letter-spacing: 0;
  transition:
    transform 0.16s ease,
    border-color 0.16s ease,
    background-color 0.16s ease,
    color 0.16s ease,
    box-shadow 0.16s ease;
}

.icon-btn,
.ghost-btn,
.primary-btn {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 12px;
  font-size: 0.84rem;
  white-space: nowrap;
}

.icon-btn svg,
.ghost-btn svg,
.primary-btn svg,
.timeline-icon-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
  flex: 0 0 auto;
}

.icon-btn:hover,
.ghost-btn:hover,
.timeline-icon-btn:hover,
.tiny-btn:hover,
.ref-mini-btn:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
  box-shadow: var(--shadow-md);
}

.icon-btn.active {
  color: var(--brand-strong);
  border-color: rgba(216, 90, 40, 0.4);
  background: rgba(255, 184, 107, 0.24);
}

.ghost-btn.danger,
.ref-mini-btn.danger {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 32%, transparent);
}

.primary-btn {
  color: #fff8e8;
  border-color: transparent;
  background: linear-gradient(135deg, var(--brand), var(--accent));
  box-shadow: 0 14px 28px rgba(216, 90, 40, 0.28);
}

.primary-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 18px 34px rgba(216, 90, 40, 0.34);
}

.primary-btn:disabled {
  opacity: 0.62;
  cursor: not-allowed;
}

.primary-btn.is-busy svg {
  animation: pulseTilt 0.9s ease-in-out infinite;
}

.icon-only {
  width: 34px;
  min-height: 34px;
  padding: 0;
}

.composer-footer {
  position: sticky;
  bottom: -12px;
  z-index: 5;
  margin: 2px -12px -12px;
  padding: 10px 12px 12px;
  background: linear-gradient(180deg, transparent, var(--surface) 28%);
}

#generateBtn {
  width: 100%;
  min-height: 44px;
  font-size: 0.94rem;
}

.keyword-dropdown {
  position: relative;
}

.dropdown-btn {
  width: 100%;
  justify-content: space-between;
  text-align: left;
}

.dropdown-btn::after {
  content: "";
  width: 7px;
  height: 7px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg) translateY(-2px);
  transition: transform 0.18s ease;
}

.dropdown-btn.open::after {
  transform: rotate(225deg) translateY(-2px);
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 30;
  max-height: min(380px, 58vh);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-solid);
  box-shadow: var(--shadow-lg);
}

.dropdown-menu.hidden {
  display: none;
}

.dropdown-content {
  padding: 10px;
}

.keyword-categories,
.keyword-groups {
  display: grid;
  gap: 10px;
}

.keyword-category {
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.keyword-category:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.category-title,
.group-title {
  color: var(--ink);
  font-weight: 780;
}

.category-title {
  margin-bottom: 8px;
  font-size: 0.8rem;
}

.group-title {
  margin: 2px 0 6px;
  color: var(--muted);
  font-size: 0.74rem;
}

.keyword-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.keyword-option {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.54);
  font-size: 0.76rem;
  font-weight: 680;
  cursor: pointer;
  transition:
    background-color 0.16s ease,
    border-color 0.16s ease,
    color 0.16s ease,
    transform 0.16s ease;
}

.keyword-option:hover,
.keyword-option.selected {
  transform: translateY(-1px);
  color: #fff8e8;
  border-color: transparent;
  background: var(--brand);
}

.ref-dropzone {
  position: relative;
  min-height: 146px;
  max-height: 310px;
  overflow: auto;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(216, 90, 40, 0.08), transparent 42%),
    var(--surface-raised);
  padding: 8px;
  transition:
    border-color 0.18s ease,
    background-color 0.18s ease,
    box-shadow 0.18s ease;
}

.ref-dropzone.is-dragging {
  border-color: var(--brand);
  box-shadow: inset 0 0 0 2px rgba(216, 90, 40, 0.14);
  background: rgba(255, 184, 107, 0.18);
}

.ref-placeholder {
  position: absolute;
  inset: 8px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 0.84rem;
  text-align: center;
  pointer-events: none;
}

.ref-dropzone.has-image .ref-placeholder {
  display: none;
}

.ref-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.ref-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px;
  background: var(--surface-solid);
  transition:
    opacity 0.16s ease,
    border-color 0.16s ease,
    box-shadow 0.16s ease,
    transform 0.16s ease;
}

.ref-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.ref-card.is-disabled {
  opacity: 0.54;
}

.ref-card.is-enabled {
  border-color: rgba(216, 90, 40, 0.36);
}

.ref-thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-sm);
  object-fit: cover;
  display: block;
  background: #e8e3d7;
}

.ref-card-name,
.ref-card-source {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ref-card-name {
  margin-top: 6px;
  color: var(--ink);
  font-size: 0.72rem;
  font-weight: 780;
}

.ref-card-source {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.66rem;
}

.ref-card-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  margin-top: 6px;
}

.ref-mini-btn {
  min-height: 28px;
  padding: 0 6px;
  font-size: 0.68rem;
}

.ref-mini-btn.active {
  color: var(--brand-strong);
  border-color: rgba(216, 90, 40, 0.38);
  background: rgba(255, 184, 107, 0.22);
}

.main-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  margin-top: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, rgba(23, 23, 23, 0.045) 1px, transparent 1px),
    linear-gradient(rgba(23, 23, 23, 0.045) 1px, transparent 1px),
    radial-gradient(circle at 50% 35%, rgba(255, 255, 255, 0.92), rgba(230, 226, 215, 0.54));
  background-size: 28px 28px, 28px 28px, auto;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.42);
}

.main-stage img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: none;
  cursor: zoom-in;
}

.main-stage.has-image img {
  display: block;
}

.main-stage-actions {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 5;
  display: none;
  align-items: center;
  gap: 7px;
  max-width: calc(100% - 24px);
  padding: 6px;
  border: 1px solid rgba(255, 255, 255, 0.66);
  border-radius: var(--radius-control);
  background: rgba(15, 23, 42, 0.58);
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.22);
  backdrop-filter: blur(14px);
}

.main-stage.has-image .main-stage-actions {
  display: flex;
}

.stage-action-btn {
  min-height: 30px;
  border: 1px solid rgba(255, 255, 255, 0.54);
  border-radius: var(--radius-control);
  padding: 0 10px;
  color: #ffffff;
  background: rgba(15, 23, 42, 0.72);
  font-size: 0.74rem;
  font-weight: 780;
  cursor: pointer;
  white-space: nowrap;
  transition:
    background-color 0.16s ease,
    border-color 0.16s ease,
    transform 0.16s ease;
}

.stage-action-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(255, 255, 255, 0.82);
  background: rgba(15, 23, 42, 0.9);
}

.stage-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  color: var(--muted);
  text-align: center;
  font-size: 0.92rem;
}

.main-stage.has-image .stage-empty {
  display: none;
}

.empty-mark {
  width: 54px;
  height: 54px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  color: var(--brand);
  background: var(--surface);
}

.empty-mark svg {
  width: 28px;
  height: 28px;
  fill: currentColor;
}

.stage-error {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  z-index: 4;
  display: none;
  border: 1px solid rgba(180, 35, 24, 0.34);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface-solid) 92%, var(--danger));
  color: var(--danger);
  box-shadow: var(--shadow-md);
  padding: 10px 12px;
  font-size: 0.82rem;
  font-weight: 740;
  line-height: 1.45;
}

.stage-error.active {
  display: block;
}

.stage-error.stage-unknown {
  color: var(--warning);
  border-color: color-mix(in srgb, var(--warning) 38%, transparent);
}

.main-stage:not(.has-image) .stage-error.active {
  top: 50%;
  bottom: auto;
  transform: translateY(-50%);
}

.stage-loading {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: none;
  place-items: center;
  align-content: center;
  gap: 12px;
  text-align: center;
  background:
    linear-gradient(110deg, rgba(255, 255, 255, 0.82), rgba(255, 184, 107, 0.22), rgba(255, 255, 255, 0.82));
  background-size: 220% 100%;
  animation: shimmer 1.7s linear infinite;
}

.stage-loading.active {
  display: grid;
}

.stage-loading p {
  margin: 0;
  color: var(--ink);
  font-weight: 780;
}

.loader-ring {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(216, 90, 40, 0.22);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
}

.timeline-tools {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.gallery-retention-note {
  margin: -2px 0 8px;
  border: 1px solid rgba(216, 90, 40, 0.18);
  border-radius: var(--radius-control);
  background: rgba(255, 248, 238, 0.72);
  color: var(--muted);
  padding: 7px 9px;
  font-size: 0.74rem;
  font-weight: 720;
  line-height: 1.35;
}

.timeline-tools .ghost-btn {
  min-width: 0;
  padding: 0 8px;
  font-size: 0.76rem;
}

.timeline-tools .ghost-btn.toggle-on {
  color: var(--brand-strong);
  border-color: rgba(216, 90, 40, 0.38);
  background: rgba(255, 184, 107, 0.24);
}

.board-switch {
  flex: 0 0 auto;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  padding: 3px 9px 3px 5px;
  color: var(--text);
  background: var(--surface-raised);
  font-size: 0.74rem;
  font-weight: 780;
  cursor: pointer;
  transition:
    background-color 0.16s ease,
    border-color 0.16s ease,
    color 0.16s ease,
    box-shadow 0.16s ease;
}

.board-switch:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-md);
}

.switch-track {
  position: relative;
  width: 34px;
  height: 20px;
  border-radius: 999px;
  background: rgba(101, 68, 42, 0.22);
  box-shadow: inset 0 0 0 1px var(--line);
  transition: background-color 0.16s ease;
}

.switch-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 999px;
  background: #ffffff;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.24);
  transition: transform 0.16s ease;
}

.board-switch.toggle-on {
  color: var(--brand-strong);
  border-color: rgba(216, 90, 40, 0.38);
  background: rgba(255, 184, 107, 0.2);
}

.board-switch.toggle-on .switch-track {
  background: var(--brand);
}

.board-switch.toggle-on .switch-thumb {
  transform: translateX(14px);
}

.history-content {
  position: relative;
  min-height: 0;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
}

.history-list {
  min-height: 0;
  flex: 1 1 auto;
  overflow: auto;
  padding: 1px 3px 1px 1px;
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  grid-auto-rows: 4px;
  grid-auto-flow: dense;
  gap: 5px;
  align-content: start;
}

.history-list > .history-meta {
  grid-column: 1 / -1;
}

.history-item {
  position: relative;
  min-width: 0;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  cursor: pointer;
  transition:
    grid-column-end 0.26s cubic-bezier(0.16, 1, 0.3, 1),
    height 0.26s cubic-bezier(0.16, 1, 0.3, 1),
    filter 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  will-change: transform, height, filter;
}

.history-image-item {
  grid-column: span var(--gallery-span, 4);
}

.history-item.active {
  outline: 2px solid rgba(216, 90, 40, 0.54);
  outline-offset: -2px;
}

.history-image-item.is-expanded {
  z-index: 3;
  grid-column: span var(--gallery-expanded-span, 8);
  filter: saturate(1.05) contrast(1.02);
}

.history-list.has-expanded .history-image-item:not(.is-expanded) {
  grid-column: span var(--gallery-shrink-span, 3);
}

.history-list.has-expanded .history-task {
  opacity: 0.72;
}

.history-list.is-gallery-fixed .history-image-item,
.history-list.is-gallery-fixed .history-image-item.is-expanded,
.history-list.is-gallery-fixed.has-expanded .history-image-item:not(.is-expanded) {
  grid-column: span var(--gallery-span, 4);
}

.history-list.is-gallery-fixed {
  grid-auto-flow: dense;
}

.history-list.is-gallery-fixed .history-item {
  transition:
    filter 0.16s ease,
    outline-color 0.16s ease;
  will-change: auto;
}

.history-row {
  display: flex;
  align-items: stretch;
  overflow: hidden;
  border-radius: 0;
  width: 100%;
  height: 100%;
}

.history-thumb-wrap {
  position: relative;
  min-width: 0;
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  background: transparent;
}

.history-thumb {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  background: transparent;
  transition:
    filter 0.28s cubic-bezier(0.16, 1, 0.3, 1),
    transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

.reference-pill {
  position: absolute;
  left: 6px;
  top: 6px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: calc(100% - 12px);
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: var(--radius-control);
  background: rgba(216, 90, 40, 0.92);
  color: #fff8e8;
  box-shadow: 0 8px 18px rgba(80, 31, 12, 0.22);
  padding: 4px 7px;
  font-size: 0.64rem;
  font-weight: 820;
  line-height: 1;
  pointer-events: none;
}

.reference-pill svg {
  width: 13px;
  height: 13px;
  fill: currentColor;
  flex: 0 0 auto;
}

.history-reference-item {
  background: transparent;
}

.history-meta {
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.45;
}

.history-meta-compact {
  margin: 4px 0 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-model-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  z-index: 2;
  max-width: calc(100% - 12px);
  pointer-events: none;
}

.history-model-badge.compact .model-pill {
  padding: 3px 5px;
}

.history-model-badge.compact .model-pill-text {
  display: none;
}

.history-thumb.is-broken {
  color: transparent;
}

.history-thumb-wrap.image-unavailable::after {
  content: "图片链接已失效";
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  padding: 10px;
  border: 1px dashed rgba(180, 86, 61, 0.42);
  background: rgba(255, 248, 238, 0.9);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 720;
  text-align: center;
  line-height: 1.35;
  pointer-events: none;
}

.history-delete-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 4;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 999px;
  color: #ffffff;
  background: rgba(15, 23, 42, 0.72);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.22);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-2px) scale(0.92);
  transition:
    opacity 0.16s ease,
    transform 0.16s ease,
    background-color 0.16s ease,
    border-color 0.16s ease;
}

.history-delete-btn span {
  font-size: 1.18rem;
  font-weight: 860;
  line-height: 1;
  transform: translateY(-1px);
}

.history-image-item:hover .history-delete-btn,
.history-image-item:focus-within .history-delete-btn,
.history-delete-btn.confirm-delete {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.history-delete-btn:hover {
  border-color: rgba(255, 255, 255, 0.88);
  background: rgba(30, 41, 59, 0.92);
}

.history-delete-btn.confirm-delete {
  border-color: rgba(255, 255, 255, 0.86);
  background: rgba(180, 35, 24, 0.94);
  box-shadow: 0 10px 22px rgba(180, 35, 24, 0.3);
}

.model-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.86);
  color: var(--ink);
  padding: 3px 8px 3px 5px;
  font-size: 0.64rem;
  font-weight: 780;
  line-height: 1;
  white-space: nowrap;
  backdrop-filter: blur(10px);
}

.model-pill.gpt {
  color: #fff8e8;
  border-color: rgba(23, 23, 23, 0.55);
  background: rgba(23, 23, 23, 0.86);
}

.model-pill.banana {
  color: #4d3510;
  border-color: rgba(201, 111, 45, 0.42);
  background: rgba(255, 226, 164, 0.9);
}

.model-pill.banana2 {
  color: #5c1730;
  border-color: rgba(169, 61, 84, 0.34);
  background: rgba(255, 218, 225, 0.9);
}

.model-pill-icon {
  width: 15px;
  height: 15px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  font-size: 0.66rem;
  font-weight: 850;
  line-height: 1;
}

.model-pill-icon.gpt-mark svg {
  width: 100%;
  height: 100%;
  fill: currentColor;
}

.model-pill-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-task {
  grid-column: 1 / -1;
  padding: 10px;
}

.history-task-running {
  grid-column: span var(--gallery-span, 4);
  aspect-ratio: 1 / 1;
  padding: 0;
  cursor: default;
  border: 1px solid rgba(255, 193, 148, 0.64);
  background:
    radial-gradient(circle at 24% 20%, rgba(255, 248, 232, 0.72), transparent 28%),
    linear-gradient(135deg, #c94c27 0%, #f29b48 34%, #ffd48c 58%, #d85a28 100%);
  background-size: 180% 180%;
  box-shadow: inset 0 0 0 1px rgba(255, 248, 232, 0.28);
  isolation: isolate;
  animation: taskGradientFlow 4.8s cubic-bezier(0.65, 0, 0.35, 1) infinite;
}

.history-task-running::before,
.history-task-running::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.history-task-running::before {
  z-index: 0;
  background:
    radial-gradient(circle at 72% 24%, rgba(255, 255, 255, 0.5), transparent 24%),
    radial-gradient(circle at 30% 76%, rgba(122, 43, 22, 0.16), transparent 30%);
  mix-blend-mode: soft-light;
  animation: taskGlowDrift 5.6s cubic-bezier(0.45, 0, 0.25, 1) infinite;
}

.history-task-running::after {
  z-index: 1;
  background: linear-gradient(112deg, transparent 20%, rgba(255, 248, 232, 0.5) 46%, transparent 72%);
  transform: translateX(-135%);
  animation: taskLightSweep 2.7s cubic-bezier(0.32, 0, 0.18, 1) infinite;
}

.task-loading-tile {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.task-loading-text {
  color: #fff8e8;
  font-size: 0.88rem;
  font-weight: 860;
  line-height: 1;
  letter-spacing: 0;
  text-shadow: 0 2px 10px rgba(90, 28, 10, 0.32);
}

.history-task-failed {
  border-color: color-mix(in srgb, var(--danger) 34%, transparent);
  background: color-mix(in srgb, var(--surface-raised) 92%, var(--danger));
}

.history-task-unknown {
  border-color: color-mix(in srgb, var(--warning) 36%, transparent);
  background: color-mix(in srgb, var(--surface-raised) 92%, var(--warning));
}

.task-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.task-title {
  min-width: 0;
  flex: 1 1 auto;
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.task-status {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 3px 7px;
  font-size: 0.68rem;
  font-weight: 800;
}

.task-status.running {
  color: var(--brand-strong);
  background: rgba(255, 184, 107, 0.24);
}

.task-status.failed {
  color: var(--danger);
  background: rgba(180, 35, 24, 0.12);
}

.task-status.unknown {
  color: var(--warning);
  background: rgba(150, 100, 0, 0.13);
}

.task-copy-btn {
  margin-left: 0;
}

.task-prompt {
  margin-top: 7px;
  max-height: 62px;
  overflow: hidden;
  color: var(--text);
  font-size: 0.74rem;
  line-height: 1.45;
}

.task-progress {
  margin-top: 8px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}

.task-spinner {
  width: 13px;
  height: 13px;
  border: 2px solid rgba(216, 90, 40, 0.22);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

.timeline-icon-btn {
  width: 29px;
  height: 29px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.tiny-btn {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 9px;
  text-decoration: none;
  font-size: 0.74rem;
}

.history-hover-detail {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 80;
  width: min(300px, calc(100vw - 20px));
  max-height: min(390px, calc(100vh - 16px));
  border-radius: var(--radius);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
  opacity: 0;
  transform: translateX(-4px);
  pointer-events: none;
  transition:
    opacity 0.14s ease,
    transform 0.14s ease;
}

.history-hover-detail.active {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
}

.history-hover-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.history-hover-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.history-hover-time {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 760;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-hover-actions {
  display: inline-flex;
  gap: 5px;
  flex: 0 0 auto;
}

.history-hover-prompt {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.74rem;
  line-height: 1.55;
}

.history-detail-empty {
  margin: auto;
  color: var(--muted);
  text-align: center;
  font-size: 0.78rem;
  line-height: 1.5;
}

.status-toast-container {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 120;
  width: min(420px, calc(100vw - 28px));
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.status-toast {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-solid);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  padding: 10px 12px;
  font-size: 0.82rem;
  line-height: 1.45;
  opacity: 0;
  transform: translateY(-8px);
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
}

.status-toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.status-toast.leaving {
  opacity: 0;
  transform: translateY(-6px);
}

.status-toast.info {
  border-color: rgba(216, 90, 40, 0.3);
}

.status-toast.error {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 38%, transparent);
}

.settings-modal.hidden,
.image-lightbox.hidden {
  display: none;
}

.settings-modal,
.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 99;
}

.image-lightbox {
  z-index: 110;
}

.settings-backdrop,
.image-lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 18, 15, 0.58);
  backdrop-filter: blur(14px);
}

.settings-panel {
  position: absolute;
  top: 5vh;
  left: 50%;
  transform: translateX(-50%);
  width: min(960px, calc(100vw - 28px));
  max-height: 90vh;
  overflow: auto;
  border-radius: var(--radius);
  padding: 16px;
}

.setting-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.balance-strip {
  margin-top: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid rgba(216, 90, 40, 0.18);
  border-radius: var(--radius-control);
  background: rgba(255, 248, 238, 0.72);
  padding: 10px 12px;
}

.balance-label {
  display: block;
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 760;
}

#balanceValue {
  display: block;
  color: var(--ink);
  font-size: 1.3rem;
  line-height: 1.1;
  letter-spacing: 0;
}

.balance-side {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 720;
}

.balance-refresh-note {
  color: color-mix(in srgb, var(--muted) 84%, transparent);
  white-space: nowrap;
}

.balance-side .ghost-btn {
  min-width: 84px;
}

.setting-grid .full {
  grid-column: 1 / -1;
}

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

.setting-links {
  margin-top: 14px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.34);
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.5;
}

.setting-links p {
  margin: 0 0 6px;
}

.setting-links p:last-child {
  margin-bottom: 0;
}

.setting-status {
  margin-top: 14px;
}

.setting-status h3 {
  margin-bottom: 8px;
}

.status-box {
  width: 100%;
  min-height: 92px;
  max-height: 170px;
  overflow: auto;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #171717;
  color: #f9e7bd;
  padding: 10px;
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 0.76rem;
  line-height: 1.5;
}

.image-lightbox-panel {
  position: absolute;
  inset: 16px;
  min-width: 0;
  min-height: 0;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: rgba(24, 24, 22, 0.86);
}

.image-lightbox-toolbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
  color: #fff8e8;
}

.image-lightbox-info {
  min-width: 0;
  color: rgba(255, 248, 232, 0.82);
  font-size: 0.86rem;
  font-weight: 780;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-lightbox-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.image-lightbox-actions .ghost-btn {
  color: #fff8e8;
  border-color: rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.1);
}

.image-lightbox-canvas {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 12px;
  overflow: hidden;
}

.image-lightbox-canvas img {
  display: block;
  min-width: 0;
  min-height: 0;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: var(--radius);
  background: #171717;
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.44);
}

body.has-lightbox {
  overflow: hidden;
}

html[data-theme="dark"] body {
  background:
    radial-gradient(circle at 18% -10%, rgba(88, 191, 255, 0.18), transparent 34%),
    radial-gradient(circle at 88% 12%, rgba(109, 141, 255, 0.16), transparent 32%),
    linear-gradient(rgba(125, 211, 252, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(109, 141, 255, 0.05) 1px, transparent 1px),
    linear-gradient(135deg, var(--bg) 0%, var(--bg-2) 100%);
  background-size: auto, auto, 44px 44px, 44px 44px, auto;
}

html[data-theme="dark"] .brand-mark,
html[data-theme="dark"] .primary-btn {
  color: #02050c;
  background: linear-gradient(135deg, var(--brand), var(--accent-2));
}

html[data-theme="dark"] .brand-mark {
  box-shadow: 0 12px 28px rgba(88, 191, 255, 0.22);
}

html[data-theme="dark"] .primary-btn {
  box-shadow: 0 14px 30px rgba(88, 191, 255, 0.24);
}

html[data-theme="dark"] .primary-btn:hover:not(:disabled) {
  box-shadow: 0 18px 36px rgba(88, 191, 255, 0.32);
}

html[data-theme="dark"] .icon-btn.active,
html[data-theme="dark"] .ghost-btn.toggle-on,
html[data-theme="dark"] .ghost-btn:hover,
html[data-theme="dark"] .icon-btn:hover,
html[data-theme="dark"] .timeline-icon-btn:hover,
html[data-theme="dark"] .tiny-btn:hover,
html[data-theme="dark"] .ref-mini-btn:hover {
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.28);
}

html[data-theme="dark"] .icon-btn.active,
html[data-theme="dark"] .ghost-btn.toggle-on,
html[data-theme="dark"] .timeline-tools .ghost-btn.toggle-on {
  color: #ffffff;
  border-color: rgba(88, 191, 255, 0.5);
  background: rgba(20, 82, 130, 0.52);
}

html[data-theme="dark"] .board-switch {
  color: #ffffff;
  border-color: rgba(168, 202, 237, 0.34);
  background: rgba(8, 17, 31, 0.96);
}

html[data-theme="dark"] .board-switch.toggle-on {
  color: #ffffff;
  border-color: rgba(88, 191, 255, 0.5);
  background: rgba(20, 82, 130, 0.52);
}

html[data-theme="dark"] .switch-track {
  background: rgba(148, 180, 214, 0.18);
  box-shadow: inset 0 0 0 1px rgba(168, 202, 237, 0.26);
}

html[data-theme="dark"] .board-switch.toggle-on .switch-track {
  background: var(--brand);
}

html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea {
  background: #000000;
  color: #ffffff;
  border-color: rgba(168, 202, 237, 0.38);
}

html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder {
  color: rgba(255, 255, 255, 0.58);
}

html[data-theme="dark"] #promptInput {
  background: #000000;
  color: #ffffff;
  border-color: rgba(168, 202, 237, 0.46);
}

html[data-theme="dark"] #promptInput:empty::before {
  color: rgba(255, 255, 255, 0.58);
}

html[data-theme="dark"] input:focus,
html[data-theme="dark"] select:focus,
html[data-theme="dark"] textarea:focus,
html[data-theme="dark"] #promptInput:focus {
  border-color: var(--brand);
  box-shadow: var(--focus);
}

html[data-theme="dark"] .dropdown-menu,
html[data-theme="dark"] .ref-card,
html[data-theme="dark"] .model-pill {
  background-color: var(--surface-raised);
  color: #ffffff;
}

html[data-theme="dark"] .model-pill.gpt {
  background: rgba(15, 23, 42, 0.94);
  color: #ffffff;
  border-color: rgba(168, 202, 237, 0.34);
}

html[data-theme="dark"] .model-pill.banana {
  background: rgba(14, 116, 144, 0.28);
  color: #dff7ff;
  border-color: rgba(125, 211, 252, 0.34);
}

html[data-theme="dark"] .model-pill.banana2 {
  background: rgba(59, 130, 246, 0.24);
  color: #e7f0ff;
  border-color: rgba(147, 197, 253, 0.34);
}

html[data-theme="dark"] .main-stage {
  background:
    linear-gradient(90deg, rgba(125, 211, 252, 0.055) 1px, transparent 1px),
    linear-gradient(rgba(125, 211, 252, 0.055) 1px, transparent 1px),
    #000000;
  background-size: 28px 28px, 28px 28px, auto;
  box-shadow: inset 0 0 0 1px rgba(88, 191, 255, 0.08);
}

html[data-theme="dark"] .main-stage-actions {
  border-color: rgba(168, 202, 237, 0.38);
  background: rgba(0, 0, 0, 0.68);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.42);
}

html[data-theme="dark"] .stage-action-btn {
  color: #ffffff;
  border-color: rgba(168, 202, 237, 0.34);
  background: rgba(8, 17, 31, 0.86);
}

html[data-theme="dark"] .stage-action-btn:hover {
  border-color: rgba(125, 211, 252, 0.72);
  background: rgba(14, 116, 144, 0.42);
}

html[data-theme="dark"] .stage-loading {
  background: linear-gradient(110deg, rgba(0, 0, 0, 0.9), rgba(88, 191, 255, 0.14), rgba(0, 0, 0, 0.9));
}

html[data-theme="dark"] .image-lightbox-panel {
  background: rgba(3, 7, 18, 0.9);
}

html[data-theme="dark"] .image-lightbox-toolbar {
  color: #ffffff;
  border-color: rgba(168, 202, 237, 0.22);
}

html[data-theme="dark"] .image-lightbox-info {
  color: rgba(255, 255, 255, 0.88);
}

html[data-theme="dark"] .image-lightbox-actions .ghost-btn {
  color: #ffffff;
  border-color: rgba(168, 202, 237, 0.28);
  background: rgba(8, 17, 31, 0.72);
}

html[data-theme="dark"] .setting-links,
html[data-theme="dark"] .keyword-option {
  background: rgba(125, 211, 252, 0.05);
}

html[data-theme="dark"] .balance-strip {
  border-color: rgba(125, 211, 252, 0.2);
  background: #000000;
}

html[data-theme="dark"] #balanceValue {
  color: #ffffff;
}

html[data-theme="dark"] .status-box {
  background: #000000;
  color: #ffffff;
  border-color: rgba(168, 202, 237, 0.3);
}

html[data-theme="dark"] .gallery-retention-note {
  border-color: rgba(125, 211, 252, 0.2);
  background: #000000;
  color: #dbeafe;
}

html[data-theme="dark"] .settings-backdrop,
html[data-theme="dark"] .image-lightbox-backdrop {
  background: rgba(0, 0, 0, 0.82);
}

html[data-theme="dark"] .history-item.active {
  outline-color: rgba(88, 191, 255, 0.72);
}

html[data-theme="dark"] .ref-mini-btn.active {
  color: #ffffff;
  border-color: rgba(88, 191, 255, 0.48);
  background: rgba(20, 82, 130, 0.42);
}

html[data-theme="dark"] .reference-pill {
  color: #ffffff;
  border-color: rgba(190, 230, 255, 0.68);
  background: rgba(14, 116, 144, 0.92);
  box-shadow: 0 8px 18px rgba(8, 47, 73, 0.32);
}

html[data-theme="dark"] .prompt-ref-chip {
  background: #0c1420;
  border-color: rgba(88, 191, 255, 0.42);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.36);
}

html[data-theme="dark"] .history-delete-btn {
  color: #ffffff;
  border-color: rgba(190, 230, 255, 0.56);
  background: rgba(8, 17, 31, 0.78);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.34);
}

html[data-theme="dark"] .history-thumb-wrap.image-unavailable::after {
  border-color: rgba(148, 163, 184, 0.34);
  background: rgba(2, 6, 23, 0.9);
  color: #cbd5e1;
}

html[data-theme="dark"] .history-delete-btn:hover {
  border-color: rgba(125, 211, 252, 0.78);
  background: rgba(14, 116, 144, 0.72);
}

html[data-theme="dark"] .history-delete-btn.confirm-delete {
  border-color: rgba(255, 255, 255, 0.86);
  background: rgba(244, 63, 94, 0.92);
  box-shadow: 0 10px 22px rgba(244, 63, 94, 0.32);
}

html[data-theme="dark"] .history-task-running {
  border-color: rgba(88, 191, 255, 0.56);
  background:
    radial-gradient(circle at 24% 20%, rgba(125, 211, 252, 0.38), transparent 28%),
    linear-gradient(135deg, #020617 0%, #075985 34%, #38bdf8 62%, #1d4ed8 100%);
  box-shadow: inset 0 0 0 1px rgba(226, 242, 255, 0.16);
}

html[data-theme="dark"] .history-task-running::before {
  background:
    radial-gradient(circle at 72% 24%, rgba(255, 255, 255, 0.28), transparent 24%),
    radial-gradient(circle at 30% 76%, rgba(29, 78, 216, 0.22), transparent 30%);
}

html[data-theme="dark"] .history-task-running::after {
  background: linear-gradient(112deg, transparent 20%, rgba(226, 242, 255, 0.42) 46%, transparent 72%);
}

html[data-theme="dark"] .task-loading-text {
  color: #ffffff;
  text-shadow: 0 2px 12px rgba(15, 23, 42, 0.48);
}

*::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

*::-webkit-scrollbar-thumb {
  min-height: 44px;
  border: 3px solid transparent;
  border-radius: 999px;
  background:
    linear-gradient(180deg, rgba(255, 237, 210, 0.92), rgba(242, 163, 58, 0.84) 42%, rgba(216, 90, 40, 0.88))
    padding-box;
  background-clip: padding-box;
  box-shadow: inset 0 0 0 1px rgba(118, 55, 24, 0.14);
  transition:
    background-color 0.18s cubic-bezier(0.16, 1, 0.3, 1),
    box-shadow 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

*::-webkit-scrollbar-thumb:hover {
  background:
    linear-gradient(180deg, #fff1d9, #f4b356 42%, #cc4f24)
    padding-box;
  box-shadow: inset 0 0 0 1px rgba(118, 55, 24, 0.22), 0 0 0 1px rgba(216, 90, 40, 0.12);
}

*::-webkit-scrollbar-thumb:active {
  background:
    linear-gradient(180deg, #ffe0b8, #e98f32 44%, #a83d1c)
    padding-box;
  box-shadow: inset 0 0 0 1px rgba(76, 31, 12, 0.28);
}

*::-webkit-scrollbar-track {
  border-radius: 999px;
  background: rgba(255, 224, 190, 0.28);
}

*::-webkit-scrollbar-corner {
  background: transparent;
}

* {
  scrollbar-color: rgba(216, 90, 40, 0.72) rgba(255, 224, 190, 0.3);
  scrollbar-width: thin;
}

html[data-theme="dark"] *::-webkit-scrollbar-thumb {
  background:
    linear-gradient(180deg, rgba(168, 202, 237, 0.9), rgba(88, 191, 255, 0.82) 46%, rgba(29, 78, 216, 0.88))
    padding-box;
  box-shadow: inset 0 0 0 1px rgba(226, 242, 255, 0.12);
}

html[data-theme="dark"] *::-webkit-scrollbar-thumb:hover {
  background:
    linear-gradient(180deg, #dbeafe, #7dd3fc 46%, #2563eb)
    padding-box;
}

html[data-theme="dark"] *::-webkit-scrollbar-track {
  background: rgba(88, 191, 255, 0.1);
}

html[data-theme="dark"] * {
  scrollbar-color: rgba(88, 191, 255, 0.72) rgba(88, 191, 255, 0.1);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes shimmer {
  0% {
    background-position: 180% 0;
  }

  100% {
    background-position: -20% 0;
  }
}

@keyframes taskGradientFlow {
  0%,
  100% {
    background-position: 0% 50%;
    filter: saturate(1) brightness(1);
  }

  45% {
    background-position: 100% 50%;
    filter: saturate(1.12) brightness(1.04);
  }

  72% {
    background-position: 58% 100%;
    filter: saturate(1.06) brightness(0.98);
  }
}

@keyframes taskGlowDrift {
  0%,
  100% {
    opacity: 0.58;
    transform: translate3d(-4%, -3%, 0) scale(1);
  }

  50% {
    opacity: 0.95;
    transform: translate3d(5%, 4%, 0) scale(1.06);
  }
}

@keyframes taskLightSweep {
  0% {
    transform: translateX(-135%);
    opacity: 0;
  }

  26%,
  62% {
    opacity: 0.75;
  }

  100% {
    transform: translateX(135%);
    opacity: 0;
  }
}

@keyframes pulseTilt {
  0%,
  100% {
    transform: translateY(0) rotate(0deg);
  }

  50% {
    transform: translateY(-1px) rotate(8deg);
  }
}

@media (max-width: 1280px) {
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100vh;
  }

  .workbench {
    grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
    grid-template-areas:
      "compose preview"
      "gallery gallery";
  }

  .compose-panel {
    grid-area: compose;
    max-height: calc(100vh - 104px);
  }

  .preview-panel {
    grid-area: preview;
    min-height: 620px;
  }

  .gallery-panel {
    grid-area: gallery;
    min-height: 420px;
  }

  .history-list {
    grid-template-columns: repeat(12, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .app-shell {
    padding: 10px;
  }

  .topbar {
    grid-template-columns: 1fr;
  }

  .topbar-controls {
    grid-template-columns: 1fr;
  }

  .header-actions {
    width: 100%;
  }

  .header-actions .icon-btn {
    flex: 1 1 0;
  }

  .workbench {
    grid-template-columns: 1fr;
    grid-template-areas:
      "compose"
      "preview"
      "gallery";
  }

  .compose-panel {
    max-height: none;
  }

  .preview-panel {
    min-height: 520px;
  }

  .main-stage-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
    left: 12px;
  }

  .stage-action-btn {
    min-height: 28px;
    padding: 0 8px;
    font-size: 0.7rem;
  }

  .setting-grid,
  .control-grid {
    grid-template-columns: 1fr;
  }

  .balance-strip {
    align-items: stretch;
    flex-direction: column;
  }

  .balance-side {
    justify-content: space-between;
    flex-wrap: wrap;
  }

  .image-lightbox-panel {
    inset: 8px;
  }

  .image-lightbox-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .image-lightbox-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .brand-block {
    grid-template-columns: 36px minmax(0, 1fr);
  }

  .brand-mark {
    width: 36px;
    height: 36px;
  }

  .brand-copy h1 {
    font-size: 1rem;
  }

  .quick-model-switch {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .quick-model-switch > span {
    display: none;
  }

  .ref-list,
  .timeline-tools,
  .history-list {
    grid-template-columns: 1fr;
  }

  .history-list {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .history-image-item {
    grid-column: span var(--gallery-mobile-span, 3);
  }

  .history-task-running {
    grid-column: span var(--gallery-mobile-span, 3);
  }

  .history-image-item.is-expanded {
    grid-column: span 6;
  }

  .history-list.has-expanded .history-image-item:not(.is-expanded) {
    grid-column: span 3;
  }

  .history-list.is-gallery-fixed .history-image-item,
  .history-list.is-gallery-fixed .history-image-item.is-expanded,
  .history-list.is-gallery-fixed.has-expanded .history-image-item:not(.is-expanded) {
    grid-column: span var(--gallery-mobile-span, 3);
  }

  .preview-panel {
    min-height: 440px;
  }

  .setting-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .image-lightbox-actions {
    grid-template-columns: 1fr;
  }
}

@media (hover: none) {
  .history-delete-btn {
    opacity: 0.78;
    pointer-events: auto;
    transform: translateY(0) scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
