:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --line: #dbe2ed;
  --line-strong: #c8d3e3;
  --text: #101828;
  --muted: #667085;
  --muted-2: #8a95a8;
  --primary: #1469ff;
  --primary-dark: #0955df;
  --success: #13a36f;
  --danger: #d92d20;
  --shadow: 0 16px 42px rgba(15, 23, 42, .08);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 1180px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

img {
  display: block;
  max-width: 100%;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: 64px 1fr;
}

.topbar {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0;
}

.brand-mark {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--text);
  color: #fff;
  font-size: 17px;
}

.api-status,
.success-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-weight: 650;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  min-width: 0;
}

.user-chip {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px 0 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-soft);
  color: #344054;
  font-weight: 750;
}

.user-avatar {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #edf4ff;
  color: var(--primary);
  font-size: 13px;
  font-weight: 900;
}

.logout-button {
  min-height: 36px;
  padding: 0 12px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--success);
}

.workspace {
  display: grid;
  grid-template-columns: 374px minmax(520px, 1fr) 316px;
  gap: 18px;
  padding: 20px;
  min-height: 0;
}

.control-panel,
.result-panel,
.task-panel {
  min-width: 0;
}

.control-panel,
.task-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.mode-switch,
.panel-section,
.result-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 4px;
  gap: 4px;
}

.mode-button,
.option-button,
.primary-button,
.secondary-button,
.icon-button,
.chevron-button {
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
}

.mode-button {
  height: 42px;
  color: var(--muted);
  font-weight: 800;
  font-size: 18px;
}

.mode-button.is-active {
  border-color: var(--primary);
  color: var(--primary);
  background: #fff;
}

.panel-section {
  padding: 18px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.panel-section h2,
.section-heading h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
}

.section-heading span {
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
}

.reference-drop {
  display: grid;
  grid-template-columns: 1fr 32px;
  align-items: center;
  gap: 14px;
  min-height: 76px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.reference-drop.is-dragging {
  border-color: var(--primary);
  background: #eef5ff;
}

.reference-tile img,
.reference-preview-card img,
.history-item img,
.history-thumb {
  border-radius: 7px;
  background: linear-gradient(135deg, #dbeafe, #dff5ea);
  object-fit: cover;
}

.reference-drop strong {
  display: block;
  font-size: 16px;
  margin-bottom: 6px;
}

.reference-drop p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.reference-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.reference-tile {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.reference-tile img {
  width: 100%;
  aspect-ratio: 1 / 1;
}

.reference-badge {
  position: absolute;
  left: 6px;
  top: 6px;
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: rgba(16, 24, 40, .82);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
}

.remove-reference {
  position: absolute;
  right: 6px;
  top: 6px;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, .9);
  color: #344054;
  font-weight: 900;
}

.reference-empty {
  grid-column: 1 / -1;
  margin: 0;
  padding: 12px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  color: var(--muted);
  background: #fbfdff;
  line-height: 1.5;
}

.chevron-button {
  width: 32px;
  height: 32px;
  color: var(--muted);
  font-size: 30px;
  line-height: 1;
}

.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.secondary-button {
  min-height: 38px;
  padding: 0 14px;
  border-color: var(--line);
  background: #fff;
  color: #344054;
  font-weight: 700;
}

.secondary-button:hover,
.icon-button:hover,
.option-button:hover {
  border-color: var(--line-strong);
  background: #f8fafc;
}

.prompt-input {
  width: 100%;
  min-height: 130px;
  resize: vertical;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
  color: var(--text);
  line-height: 1.65;
  outline: none;
}

.prompt-input:focus {
  border-color: var(--primary);
  background: #fff;
}

.parameter-section {
  display: grid;
  gap: 14px;
}

.field-group {
  display: grid;
  gap: 8px;
}

.field-label {
  color: #344054;
  font-weight: 750;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.option-button {
  min-height: 40px;
  border-color: var(--line);
  background: #fff;
  font-weight: 750;
  color: #344054;
}

.option-button.is-active {
  border-color: var(--primary);
  color: var(--primary);
  background: #f7fbff;
}

.primary-button {
  min-height: 52px;
  width: 100%;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
  font-size: 20px;
  font-weight: 850;
  box-shadow: 0 14px 26px rgba(20, 105, 255, .24);
}

.primary-button:hover {
  background: var(--primary-dark);
}

.primary-button:disabled {
  cursor: wait;
  opacity: .72;
}

.task-strip {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px 22px;
  color: var(--muted);
  font-weight: 700;
}

.result-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px;
  min-height: calc(100vh - 104px);
}

.result-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.result-header p {
  margin: 0 0 6px;
  color: var(--muted);
  font-weight: 700;
}

.result-header h1 {
  margin: 0;
  font-size: 24px;
}

.result-actions {
  display: flex;
  gap: 10px;
}

.compare-layout {
  display: grid;
  grid-template-columns: minmax(112px, 180px) minmax(320px, 1fr);
  gap: 18px;
  align-items: start;
}

.reference-preview-card {
  display: grid;
  gap: 10px;
  color: var(--muted);
  font-weight: 750;
}

.reference-strip {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.reference-strip .reference-tile img {
  aspect-ratio: 1 / 1;
}

.generated-card {
  min-width: 0;
}

.generated-image-wrap {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background:
    radial-gradient(circle at 72% 18%, rgba(255, 255, 255, .98), transparent 22%),
    linear-gradient(135deg, #eef5ff, #eef8f2);
}

.generated-image-wrap img {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  gap: 12px;
  align-content: center;
  background: rgba(255, 255, 255, .74);
  color: var(--primary);
  font-weight: 850;
}

.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid rgba(20, 105, 255, .18);
  border-top-color: var(--primary);
  animation: spin 900ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(1turn);
  }
}

.generated-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 14px;
  color: #50607a;
  font-size: 18px;
  font-weight: 750;
}

.icon-actions {
  display: flex;
  gap: 10px;
}

.icon-button {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-color: var(--line);
  background: #fff;
  color: #344054;
  font-size: 22px;
}

.menu-button {
  justify-self: start;
  border-color: transparent;
  font-size: 24px;
}

.hint-note {
  margin: 0;
  padding: 14px 16px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  color: var(--muted);
  line-height: 1.5;
  background: #fbfdff;
}

.task-panel .panel-section {
  background: var(--panel);
}

.success-pill {
  padding: 5px 10px;
  border-radius: 999px;
  color: #057a55;
  background: #e9fbf3;
}

.task-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.task-grid div {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
}

.task-grid div:nth-child(odd) {
  border-right: 1px solid var(--line);
}

.task-grid div:nth-last-child(-n + 2) {
  border-bottom: 0;
}

.task-grid dt {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.task-grid dd {
  margin: 5px 0 0;
  font-weight: 750;
}

.history-section {
  display: grid;
  gap: 14px;
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-item {
  display: grid;
  grid-template-columns: 54px 1fr;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  text-align: left;
}

.history-item img,
.history-thumb {
  width: 54px;
  height: 54px;
}

.history-item strong,
.history-item small {
  display: block;
}

.history-item strong {
  margin-bottom: 4px;
}

.history-item small {
  color: var(--muted);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 16px;
  border-radius: var(--radius);
  background: #101828;
  color: #fff;
  box-shadow: var(--shadow);
  font-weight: 700;
  z-index: 30;
}

[hidden] {
  display: none !important;
}

.login-page {
  min-width: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 50% 0, rgba(20, 105, 255, .10), transparent 34%),
    var(--bg);
}

.login-shell {
  width: min(420px, 100%);
}

.login-card {
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-brand {
  justify-content: flex-start;
  margin-bottom: 24px;
  font-size: 20px;
}

.login-brand .brand-mark {
  display: grid;
}

.login-card h1 {
  margin: 0 0 10px;
  font-size: 28px;
  line-height: 1.2;
}

.login-copy,
.login-note,
.login-alert {
  line-height: 1.65;
}

.login-copy {
  margin: 0 0 22px;
  color: var(--muted);
}

.login-alert {
  margin: 0 0 16px;
  padding: 11px 12px;
  border: 1px solid #fed7d2;
  border-radius: var(--radius);
  background: #fff5f3;
  color: var(--danger);
  font-weight: 700;
}

.login-button {
  min-height: 48px;
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--primary);
  border-radius: 7px;
  background: var(--primary);
  color: #fff;
  text-decoration: none;
  font-weight: 850;
}

.login-button.is-disabled {
  border-color: var(--line-strong);
  background: #eef2f7;
  color: var(--muted);
  cursor: not-allowed;
}

.login-note {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 14px;
}

@media (max-width: 900px) {
  body {
    min-width: 0;
    background: #fff;
  }

  .app-shell {
    display: block;
    background:
      radial-gradient(circle at 50% 0, rgba(20, 105, 255, .08), transparent 38%),
      var(--bg);
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    grid-template-columns: 44px 1fr auto;
    height: 76px;
    padding: 0 18px;
    border-bottom: 1px solid rgba(219, 226, 237, .75);
    background: rgba(255, 255, 255, .92);
    backdrop-filter: blur(16px);
  }

  .brand {
    font-size: 22px;
  }

  .brand-mark {
    display: none;
  }

  .api-status {
    font-size: 15px;
  }

  .topbar-actions {
    gap: 8px;
  }

  .user-chip {
    max-width: 126px;
  }

  .user-chip span:last-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .workspace {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 14px;
  }

  .control-panel {
    display: contents;
  }

  .mode-switch {
    order: 1;
    padding: 4px;
  }

  .mode-button {
    height: 48px;
    font-size: 18px;
  }

  .reference-section {
    order: 2;
  }

  .prompt-section {
    order: 3;
  }

  .reference-drop {
    grid-template-columns: 1fr 26px;
    min-height: 78px;
  }

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

  .panel-section {
    padding: 16px;
  }

  .prompt-input {
    min-height: 112px;
  }

  .parameter-section {
    order: 4;
  }

  .segmented-control {
    gap: 8px;
  }

  .option-button {
    min-height: 44px;
  }

  .primary-button {
    position: static;
    width: 100%;
  }

  .task-strip {
    justify-content: center;
  }

  .result-panel {
    order: 5;
    min-height: auto;
    padding: 16px;
    box-shadow: none;
  }

  .result-header {
    display: none;
  }

  .compare-layout {
    grid-template-columns: 1fr;
  }

  .reference-preview-card {
    display: none;
  }

  .generated-image-wrap img {
    aspect-ratio: 16 / 10;
  }

  .generated-meta {
    font-size: 17px;
  }

  .hint-note {
    display: none;
  }

  .task-panel {
    order: 6;
    display: block;
  }

  .task-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .task-grid div,
  .task-grid div:nth-child(odd) {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .task-grid div:nth-child(3n + 1),
  .task-grid div:nth-child(3n + 2) {
    border-right: 1px solid var(--line);
  }

  .task-grid div:nth-last-child(-n + 3) {
    border-bottom: 0;
  }

  .history-section {
    display: none;
  }
}

@media (max-width: 560px) {
  .topbar {
    grid-template-columns: 36px 1fr auto;
    gap: 8px;
    padding: 0 12px;
  }

  .brand {
    font-size: 20px;
  }

  .api-status span:last-child,
  .user-chip span:last-child {
    display: none;
  }

  .user-chip {
    width: 36px;
    padding: 0;
    justify-content: center;
  }

  .logout-button {
    min-width: 0;
    padding: 0 10px;
  }

  .workspace {
    padding: 12px;
  }

  .panel-section h2,
  .section-heading h2 {
    font-size: 17px;
  }

  .section-heading {
    margin-bottom: 12px;
  }

  .reference-drop {
    grid-template-columns: 1fr 24px;
    gap: 12px;
    padding: 12px;
  }

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

  .reference-drop strong {
    font-size: 15px;
  }

  .reference-drop p,
  .task-strip,
  .section-heading span {
    font-size: 13px;
  }

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

  .prompt-input {
    min-height: 126px;
  }

  .generated-meta {
    align-items: flex-start;
  }

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

  .task-grid div:nth-child(3n + 1),
  .task-grid div:nth-child(3n + 2) {
    border-right: 0;
  }

  .task-grid div:nth-child(odd) {
    border-right: 1px solid var(--line);
  }

  .task-grid div:nth-last-child(-n + 3) {
    border-bottom: 1px solid var(--line);
  }

  .task-grid div:nth-last-child(-n + 2) {
    border-bottom: 0;
  }
}
