:root {
  color-scheme: light;
  --bg: #fbfcf8;
  --rail: #f2f7f4;
  --surface: #ffffff;
  --surface-soft: #f7faf7;
  --surface-glass: rgba(255, 255, 255, 0.94);
  --ink: #17211d;
  --muted: #6f7c75;
  --line: #e4ebe6;
  --line-strong: #c8ddd3;
  --accent: #11876f;
  --accent-soft: #e4f4ef;
  --accent-deep: #075f4d;
  --coral: #e15f4f;
  --blue: #3f79b8;
  --sidebar-bg: linear-gradient(180deg, #f7fbf8 0%, #f2f3ff 100%);
  --control-bg: #ffffff;
  --control-ink: #405149;
  --image-bg: #eef4f1;
  --caption-bg: rgba(10, 31, 25, 0.62);
  --caption-ink: #f7fffb;
  --skeleton-bg: linear-gradient(110deg, transparent 0%, rgba(255,255,255,0.54) 46%, transparent 60%),
    linear-gradient(135deg, #e5f0eb, #d9e5e6);
  --selected-bg: linear-gradient(180deg, rgba(228, 244, 239, 0.72), rgba(255, 255, 255, 0));
  --shadow: 0 18px 46px rgba(21, 51, 42, 0.11);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #080d0b;
  --rail: #0c1411;
  --surface: #111a16;
  --surface-soft: #17241f;
  --surface-glass: rgba(13, 22, 18, 0.9);
  --ink: #eef8f1;
  --muted: #9aada4;
  --line: rgba(178, 211, 196, 0.16);
  --line-strong: rgba(99, 219, 180, 0.34);
  --accent: #45d1a8;
  --accent-soft: rgba(69, 209, 168, 0.14);
  --accent-deep: #9df0d2;
  --coral: #ff866e;
  --blue: #79b8ff;
  --sidebar-bg: linear-gradient(180deg, #0e1713 0%, #0a1012 58%, #111018 100%);
  --control-bg: #101a16;
  --control-ink: #dbe9e2;
  --image-bg: #14211c;
  --caption-bg: rgba(4, 10, 8, 0.76);
  --caption-ink: #effaf5;
  --skeleton-bg: linear-gradient(110deg, transparent 0%, rgba(106, 242, 197, 0.12) 46%, transparent 60%),
    linear-gradient(135deg, #12201b, #182a25);
  --selected-bg: linear-gradient(180deg, rgba(69, 209, 168, 0.16), rgba(8, 13, 11, 0));
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.46);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Microsoft YaHei UI", "Noto Sans SC", "PingFang SC", sans-serif;
  background:
    linear-gradient(160deg, rgba(17, 135, 111, 0.08), transparent 34%),
    linear-gradient(20deg, rgba(225, 95, 79, 0.055), transparent 28%),
    var(--bg);
  transition: background 180ms ease, color 180ms ease;
}

:root[data-theme="dark"] body {
  background:
    radial-gradient(circle at 18% 10%, rgba(69, 209, 168, 0.16), transparent 28%),
    radial-gradient(circle at 78% 78%, rgba(121, 184, 255, 0.1), transparent 30%),
    linear-gradient(155deg, #07100d 0%, #0b1511 44%, #080d0c 100%);
}

button,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 104px minmax(0, 1fr);
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 4;
  width: 104px;
  padding: 18px 12px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--line);
}

.logo {
  display: grid;
  place-items: center;
  gap: 6px;
  color: var(--accent-deep);
  font-size: 12px;
  font-weight: 900;
}

.logo-mark {
  width: 42px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 2px solid #8fd4be;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 18px rgba(17, 135, 111, 0.16);
}

.nav-stack,
.nav-footer {
  display: grid;
  justify-items: center;
}

.nav-stack {
  align-content: start;
  gap: 18px;
  padding-top: 54px;
}

.nav-footer {
  gap: 14px;
}

.nav-item,
.icon-button {
  border: 0;
  background: transparent;
  color: var(--muted);
}

.nav-item {
  width: 62px;
  min-height: 58px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 800;
}

.nav-item span:first-child {
  width: 30px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--surface-soft);
  font-size: 16px;
}

.nav-item.active {
  color: var(--accent-deep);
  background: var(--surface);
  box-shadow: 0 14px 28px rgba(17, 135, 111, 0.12);
}

.nav-item.active span:first-child {
  color: #ffffff;
  background: linear-gradient(135deg, var(--accent), var(--blue));
}

.icon-button {
  min-width: 34px;
  min-height: 34px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 900;
}

.icon-button:hover,
.nav-item:hover {
  background: var(--surface-glass);
}

.main {
  grid-column: 2;
  min-height: 100vh;
  padding: 28px 40px 260px;
}

.topbar {
  max-width: 1530px;
  margin: 0 auto 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.topbar-actions {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.theme-toggle {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 13px 0 8px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--control-ink);
  background: var(--surface);
  font-weight: 900;
  box-shadow: 0 10px 24px rgba(21, 51, 42, 0.06);
}

.theme-toggle:hover {
  border-color: var(--line-strong);
  background: var(--surface-soft);
}

.theme-orb {
  width: 24px;
  aspect-ratio: 1;
  border-radius: 50%;
  display: inline-block;
  background:
    linear-gradient(135deg, #f7d46b 0%, #fff4bf 48%, #ffffff 49%, #d5ece4 100%);
  box-shadow: inset -5px -5px 8px rgba(8, 13, 11, 0.12), 0 0 0 4px rgba(17, 135, 111, 0.08);
}

:root[data-theme="dark"] .theme-orb {
  background:
    radial-gradient(circle at 64% 36%, #14211c 0 28%, transparent 30%),
    linear-gradient(135deg, #e8fff6 0%, #6be8bf 100%);
  box-shadow: 0 0 18px rgba(69, 209, 168, 0.34), 0 0 0 4px rgba(69, 209, 168, 0.1);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 900;
}

h1,
h2,
p,
figure {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.12;
  letter-spacing: 0;
  color: var(--ink);
}

.status-pill {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  background: var(--surface);
  font-size: 13px;
  font-weight: 800;
}

.status-dot {
  width: 8px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(17, 135, 111, 0.12);
}

.history-feed {
  max-width: 1530px;
  margin: 0 auto;
  display: grid;
  gap: 30px;
}

.local-notice {
  max-width: 1530px;
  min-height: 44px;
  margin: -8px auto 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  color: var(--control-ink);
  background: var(--surface-glass);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.55;
}

.history-task {
  padding: 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  transition: border-color 160ms ease, background 160ms ease;
}

.history-task.selected {
  border-color: var(--line-strong);
  background: var(--selected-bg);
}

.task-head {
  padding: 0 0 12px;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
}

.task-head h2 {
  margin-bottom: 10px;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag-row span {
  min-height: 32px;
  padding: 0 13px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  color: var(--control-ink);
  background: var(--surface-soft);
  font-size: 13px;
  font-weight: 800;
}

.reference-chip,
.reference-thumb {
  width: 50px;
  aspect-ratio: 1;
  border-radius: 8px;
  border: 1px solid var(--line);
  object-fit: cover;
}

.reference-chip-stack {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 80px;
}

.reference-chip-stack .reference-chip {
  margin-left: -12px;
  background: var(--surface);
  box-shadow: 0 8px 18px rgba(21, 51, 42, 0.12);
}

.reference-chip-stack span {
  min-width: 32px;
  min-height: 32px;
  margin-left: -8px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--accent-deep);
  background: var(--accent-soft);
  font-size: 12px;
  font-weight: 900;
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 2px;
  overflow: hidden;
  border-radius: 8px;
  background: transparent;
}

.image-grid.count-1 {
  grid-template-columns: minmax(240px, 360px);
}

.image-grid.count-2 {
  grid-template-columns: repeat(2, minmax(220px, 1fr));
}

.image-grid.count-3 {
  grid-template-columns: repeat(3, minmax(200px, 1fr));
}

.image-card {
  min-height: 230px;
  background: var(--image-bg);
  overflow: hidden;
  position: relative;
}

.image-card a,
.image-card img,
.image-skeleton,
.image-error {
  width: 100%;
  height: 100%;
  min-height: 230px;
  display: block;
}

.image-card img {
  object-fit: cover;
}

.image-card figcaption {
  position: absolute;
  inset: auto 10px 10px;
  max-width: calc(100% - 20px);
  padding: 7px 9px;
  border-radius: 8px;
  color: var(--caption-ink);
  background: var(--caption-bg);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-skeleton {
  display: grid;
  place-items: center;
  background: var(--skeleton-bg);
  background-size: 220% 100%, 100% 100%;
  animation: shimmer 1.1s linear infinite;
}

.image-skeleton span {
  width: 38px;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 4px solid rgba(17, 135, 111, 0.2);
  border-top-color: var(--accent);
  animation: spin 900ms linear infinite;
}

.image-error {
  display: grid;
  place-items: center;
  color: var(--coral);
  font-weight: 900;
}

.task-actions {
  padding-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.task-actions button,
.soft-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 13px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--control-ink);
  background: var(--control-bg);
  font-weight: 800;
}

.task-actions button:hover,
.soft-button:hover {
  border-color: var(--line-strong);
  background: var(--accent-soft);
}

.empty-state {
  max-width: 1530px;
  margin: 0 auto;
  min-height: 48vh;
  display: grid;
  place-items: center;
}

.empty-card {
  max-width: 430px;
  text-align: center;
  color: var(--muted);
}

.empty-icon {
  width: 72px;
  aspect-ratio: 1;
  margin: 0 auto 18px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: var(--accent-deep);
  background: var(--accent-soft);
  font-size: 30px;
}

.empty-card h2 {
  margin-bottom: 10px;
  color: var(--ink);
  font-size: 22px;
}

.empty-card p {
  line-height: 1.7;
}

.composer {
  position: fixed;
  z-index: 5;
  left: calc(104px + 50%);
  bottom: 20px;
  width: min(920px, calc(100vw - 150px));
  transform: translateX(-50%);
}

.mode-tabs {
  width: max-content;
  margin: 0 auto -1px;
  display: flex;
}

.mode-tab {
  min-height: 46px;
  min-width: 176px;
  border: 1px solid var(--line);
  border-bottom: 0;
  padding: 0 22px;
  border-radius: 8px 8px 0 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
  background: var(--surface-glass);
  font-weight: 900;
}

.mode-tab.active {
  color: var(--accent-deep);
  background: var(--surface);
}

.composer-card {
  min-height: 152px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  grid-template-columns: 94px minmax(0, 1fr) 86px;
  gap: 14px;
  align-items: stretch;
  background: var(--surface-glass);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.key-row {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.key-control {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px 0 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--control-ink);
  background: var(--control-bg);
  font-weight: 900;
}

.key-control span {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 13px;
}

.key-control input {
  min-width: 0;
  width: 100%;
  border: 0;
  outline: 0;
  color: var(--control-ink);
  background: transparent;
  font-weight: 800;
}

:root[data-theme="dark"] .composer-card,
:root[data-theme="dark"] .mode-tab.active,
:root[data-theme="dark"] .ratio-panel {
  box-shadow:
    0 24px 70px rgba(0, 0, 0, 0.58),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

:root[data-theme="dark"] .history-task.selected {
  box-shadow: inset 0 0 0 1px rgba(69, 209, 168, 0.1);
}

.upload-tile {
  min-height: 94px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: var(--surface-soft);
  overflow: hidden;
}

.upload-tile.is-emphasized {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.upload-tile input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.upload-tile span {
  font-size: 30px;
}

.prompt-zone {
  min-width: 0;
  display: grid;
  grid-template-rows: 1fr auto auto;
  gap: 10px;
}

textarea {
  width: 100%;
  min-height: 72px;
  border: 0;
  resize: none;
  outline: none;
  color: var(--ink);
  background: transparent;
  line-height: 1.55;
}

textarea::placeholder {
  color: #a6aea9;
}

.control-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

select {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--control-ink);
  background: var(--control-bg);
  font-weight: 800;
  outline: none;
}

.ratio-control {
  position: relative;
}

.ratio-button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--control-ink);
  background: var(--control-bg);
  font-weight: 900;
}

.ratio-icon,
.ratio-shape {
  display: inline-block;
  border: 2px solid currentColor;
  border-radius: 3px;
  color: var(--muted);
}

.ratio-icon {
  width: 17px;
  height: 17px;
}

.ratio-icon.auto,
.ratio-shape.auto {
  border-radius: 4px;
  position: relative;
}

.ratio-icon.auto::after,
.ratio-shape.auto::after {
  content: "";
  position: absolute;
  inset: 4px;
  border-top: 2px solid currentColor;
  border-right: 2px solid currentColor;
}

.ratio-panel {
  position: absolute;
  left: 0;
  bottom: calc(100% + 12px);
  z-index: 9;
  width: 520px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 22px 46px rgba(21, 51, 42, 0.16);
}

.ratio-panel p {
  margin-bottom: 12px;
  color: #79847f;
  font-size: 14px;
  font-weight: 900;
}

.ratio-options {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 8px;
}

.ratio-option {
  min-height: 62px;
  border: 1px solid transparent;
  border-radius: 8px;
  display: grid;
  place-items: center;
  gap: 6px;
  color: var(--control-ink);
  background: transparent;
  font-weight: 800;
}

.ratio-option:hover,
.ratio-option.selected {
  border-color: var(--line-strong);
  color: var(--accent-deep);
  background: var(--accent-soft);
}

.ratio-shape {
  width: 18px;
  height: 18px;
}

.ratio-shape.r-9-21,
.ratio-icon.r-9-21 {
  width: 10px;
  height: 24px;
}

.ratio-shape.r-9-16,
.ratio-icon.r-9-16 {
  width: 12px;
  height: 22px;
}

.ratio-shape.r-2-3,
.ratio-icon.r-2-3 {
  width: 14px;
  height: 21px;
}

.ratio-shape.r-3-4,
.ratio-icon.r-3-4 {
  width: 15px;
  height: 20px;
}

.ratio-shape.r-1-1,
.ratio-icon.r-1-1 {
  width: 18px;
  height: 18px;
}

.ratio-shape.r-4-3,
.ratio-icon.r-4-3 {
  width: 21px;
  height: 16px;
}

.ratio-shape.r-3-2,
.ratio-icon.r-3-2 {
  width: 22px;
  height: 15px;
}

.ratio-shape.r-16-9,
.ratio-icon.r-16-9 {
  width: 25px;
  height: 14px;
}

.ratio-shape.r-21-9,
.ratio-icon.r-21-9 {
  width: 28px;
  height: 12px;
}

.count-control {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 8px 0 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--control-ink);
  background: var(--control-bg);
  font-weight: 900;
}

.count-control span {
  color: var(--muted);
  font-size: 13px;
}

.count-control input {
  width: 58px;
  border: 0;
  outline: 0;
  color: var(--control-ink);
  background: transparent;
  font-weight: 900;
}

.reference-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  overflow-x: auto;
}

.reference-thumb {
  position: relative;
  flex: 0 0 auto;
  overflow: hidden;
}

.reference-thumb img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.reference-thumb button {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 50%;
  color: #ffffff;
  background: rgba(10, 31, 25, 0.68);
  font-size: 13px;
  line-height: 1;
}

.generate-button {
  align-self: end;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: #ffffff;
  background: linear-gradient(135deg, var(--accent), #1f7ca5);
  font-weight: 900;
  box-shadow: 0 14px 24px rgba(17, 135, 111, 0.22);
}

.toast {
  position: fixed;
  z-index: 8;
  right: 24px;
  bottom: 206px;
  max-width: 360px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--control-ink);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-weight: 800;
}

.hidden {
  display: none !important;
}

@keyframes shimmer {
  to {
    background-position: -120% 0, 0 0;
  }
}

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

@media (max-width: 980px) {
  .app {
    grid-template-columns: 74px minmax(0, 1fr);
  }

  .sidebar {
    width: 74px;
  }

  .logo span:last-child,
  .nav-item span:last-child {
    display: none;
  }

  .main {
    padding: 22px 18px 290px;
  }

  .composer {
    left: calc(74px + 50%);
    width: min(760px, calc(100vw - 96px));
  }

  .image-grid {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }
}

@media (max-width: 680px) {
  .app {
    display: block;
  }

  .sidebar {
    display: none;
  }

  .topbar {
    display: grid;
  }

  .main {
    padding: 18px 14px 330px;
  }

  .composer {
    left: 12px;
    right: 12px;
    width: auto;
    transform: none;
  }

  .composer-card {
    grid-template-columns: 72px minmax(0, 1fr);
  }

  .key-row {
    grid-template-columns: 1fr;
  }

  .ratio-panel {
    left: -86px;
    width: min(520px, calc(100vw - 24px));
  }

  .ratio-options {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .generate-button {
    grid-column: 1 / -1;
    width: 100%;
  }

  .mode-tab {
    min-width: 138px;
    padding: 0 14px;
  }

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