:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --panel: #fffdf8;
  --ink: #1e2430;
  --muted: #6d7280;
  --line: #ddd7ca;
  --accent: #e2503d;
  --accent-dark: #bb3b2f;
  --teal: #197b76;
  --shadow: 0 24px 70px rgba(39, 35, 28, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(25, 123, 118, 0.12), transparent 36%),
    linear-gradient(315deg, rgba(226, 80, 61, 0.14), transparent 42%),
    var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

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

.app-shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 36px 0;
}

.workspace {
  display: grid;
  gap: 18px;
  min-height: calc(100vh - 72px);
}

.panel {
  background: rgba(255, 253, 248, 0.92);
  border: 1px solid rgba(221, 215, 202, 0.95);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  align-items: start;
  padding: 24px;
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
  grid-column: 1 / -1;
  margin-bottom: 2px;
}

.mark {
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  border-radius: 8px;
  background:
    linear-gradient(135deg, var(--accent), #f4a261 52%, var(--teal)),
    #ddd;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.45);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.2;
}

h2 {
  font-size: 18px;
  line-height: 1.25;
}

.brand p,
.preview-top p {
  color: var(--muted);
  margin-top: 6px;
  line-height: 1.5;
}

.form {
  grid-column: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.status-toast {
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 0.875rem;
  background: var(--surface2, #f0f0ee);
  color: var(--muted);
  border: 1px solid var(--line);
  line-height: 1.5;
}

.status-toast.error {
  background: #fff2f2;
  color: #c0392b;
  border-color: #f5c6c6;
}

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

.field span {
  color: #3b414e;
  font-size: 14px;
  font-weight: 700;
}

.image-upload-area {
  position: relative;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
  transition: border-color 160ms ease;
}

.image-upload-area:hover {
  border-color: var(--accent, #6366f1);
}

.image-file-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
  border: none;
  z-index: 0;
}

.image-upload-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 24px 16px;
  pointer-events: none;
  color: #6b7280;
  font-size: 14px;
}

.image-upload-hint {
  font-size: 12px;
  color: #9ca3af;
}

.image-preview-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 12px;
  position: relative;
  z-index: 1;
}

.image-preview-item {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 6px;
  overflow: hidden;
  flex-shrink: 0;
}

.image-preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.image-preview-item.uploading img {
  opacity: 0.5;
}

.image-preview-status {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: #fff;
  background: rgba(0,0,0,0.4);
}

.image-preview-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0,0,0,0.55);
  color: #fff;
  border: none;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}

.image-upload-actions {
  padding: 0 12px 8px;
  display: flex;
  justify-content: flex-end;
  position: relative;
  z-index: 1;
}

.text-button {
  background: none;
  border: none;
  padding: 0;
  color: #ef4444;
  font-size: 12px;
  cursor: pointer;
  text-align: left;
}

.text-button:hover {
  text-decoration: underline;
}

.hidden {
  display: none !important;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: none;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease;
}

textarea {
  min-height: 112px;
  max-height: 190px;
  resize: vertical;
  padding: 14px;
  line-height: 1.55;
}

input,
select {
  height: 44px;
  padding: 0 12px;
}

textarea:focus,
input:focus,
select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 4px rgba(25, 123, 118, 0.14);
}

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

button,
.download {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-weight: 800;
  text-decoration: none;
  transition:
    background 160ms ease,
    transform 160ms ease,
    opacity 160ms ease;
}

button:hover,
.download:hover {
  background: var(--accent-dark);
}

button:active,
.download:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: wait;
  opacity: 0.62;
}

.ghost {
  background: #ece7dc;
  color: #2f3541;
}

.ghost:hover {
  background: #e0d8c8;
}

.text-button {
  min-height: auto;
  padding: 0;
  background: transparent;
  color: var(--teal);
  font-size: 13px;
}

.text-button:hover {
  background: transparent;
  color: #11645f;
}

.text-button:disabled {
  cursor: default;
  opacity: 0.45;
}

.button-icon {
  font-size: 18px;
  line-height: 1;
}

.credit-box {
  grid-column: 2;
  display: grid;
  gap: 12px;
  padding-left: 18px;
  border-left: 1px solid var(--line);
}

.credit-box p {
  color: var(--muted);
  margin-top: 6px;
  line-height: 1.45;
}

.account-notice {
  margin-top: 0 !important;
  padding: 10px 12px;
  border: 1px solid rgba(25, 123, 118, 0.28);
  border-radius: 8px;
  background: rgba(25, 123, 118, 0.1);
  color: #11645f !important;
  font-size: 14px;
  font-weight: 700;
}

.account-notice.error {
  border-color: rgba(187, 59, 47, 0.28);
  background: rgba(187, 59, 47, 0.1);
  color: var(--accent-dark) !important;
}

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

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

.login-form #loginCode {
  grid-column: 1;
}

.invite-form input,
.login-form input {
  min-width: 0;
}

.invite-guide {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.invite-guide img {
  width: 72px;
  height: 72px;
  border-radius: 6px;
  object-fit: cover;
}

.invite-guide p {
  margin-top: 0;
  font-size: 13px;
}

.history {
  grid-column: 2;
  min-width: 0;
  padding-left: 18px;
  border-left: 1px solid var(--line);
}

.history-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.history-list {
  display: grid;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
  padding-right: 2px;
}

.history-item {
  width: 100%;
  min-height: 64px;
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  gap: 10px;
  padding: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  text-align: left;
}

.history-item:hover {
  background: #f8f5ee;
}

.history-item img {
  width: 56px;
  height: 56px;
  border-radius: 6px;
  object-fit: cover;
  background: #ece7dc;
}

.history-text {
  min-width: 0;
  display: grid;
  align-content: center;
  gap: 4px;
}

.history-text strong,
.history-text span,
.history-empty {
  line-height: 1.35;
}

.history-text strong {
  overflow: hidden;
  color: var(--ink);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-text span,
.history-empty {
  color: var(--muted);
  font-size: 12px;
}

.history-empty {
  padding: 8px 0;
}

.preview {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  padding: 20px;
}

.preview-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.download {
  flex: 0 0 auto;
  background: var(--teal);
}

.download:hover {
  background: #11645f;
}

.image-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 160px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(45deg, rgba(30, 36, 48, 0.045) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(30, 36, 48, 0.045) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(30, 36, 48, 0.045) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(30, 36, 48, 0.045) 75%);
  background-position:
    0 0,
    0 10px,
    10px -10px,
    -10px 0;
  background-size: 20px 20px;
}

.image-stage.has-image {
  min-height: unset;
}

.image-stage.loading::after {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(255, 253, 248, 0.78);
  color: var(--teal);
  content: "生成中...";
  font-weight: 900;
}

.empty-state {
  display: grid;
  place-items: center;
  gap: 8px;
  color: var(--muted);
  text-align: center;
}

.empty-state span {
  color: var(--teal);
  font-size: 48px;
}

#resultImage {
  width: 100%;
  height: auto;
  max-height: calc(100vh - 190px);
  object-fit: contain;
  display: block;
}

.hidden {
  display: none !important;
}

@media (max-width: 860px) {
  .app-shell {
    width: min(100% - 24px, 620px);
    padding: 12px 0;
  }

  .workspace {
    min-height: auto;
  }

  .controls {
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 16px;
  }

  .form,
  .credit-box,
  .history {
    grid-column: auto;
  }

  .preview {
    padding: 16px;
  }

  .credit-box,
  .history {
    padding-left: 0;
    padding-top: 16px;
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .preview-top {
    align-items: stretch;
    flex-direction: column;
  }

  .download {
    width: 100%;
  }

  .image-stage {
    min-height: 300px;
  }

  #resultImage {
    max-height: 560px;
  }
}
