:root {
  --bg: #f7f4ef;
  --panel: #fffaf4;
  --panel-strong: #ffffff;
  --ink: #22252a;
  --muted: #68707a;
  --line: #e5ded3;
  --accent: #c7354c;
  --accent-dark: #a42b3f;
  --sage: #6f866f;
  --blue: #405f7f;
  --shadow: 0 18px 48px rgba(53, 45, 35, 0.12);
  --danger: #a9232f;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: "SF Pro Text", "PingFang SC", "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background:
    linear-gradient(120deg, rgba(199, 53, 76, 0.08), transparent 38%),
    linear-gradient(220deg, rgba(64, 95, 127, 0.11), transparent 34%),
    var(--bg);
}

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

.hidden {
  display: none !important;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(16px, 4vw, 40px);
  background: rgba(247, 244, 239, 0.86);
  border-bottom: 1px solid rgba(229, 222, 211, 0.8);
  backdrop-filter: blur(18px);
}

.brand,
.account-actions {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.brand {
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  font-size: 13px;
  letter-spacing: 0;
}

.workspace {
  width: min(1220px, 100%);
  margin: 0 auto;
  padding: clamp(18px, 4vw, 42px);
  display: grid;
  grid-template-columns: minmax(320px, 460px) minmax(0, 1fr);
  gap: clamp(18px, 3vw, 32px);
  align-items: start;
}

.control-panel,
.result-panel,
.auth-card {
  border: 1px solid var(--line);
  background: rgba(255, 250, 244, 0.92);
  box-shadow: var(--shadow);
}

.control-panel {
  border-radius: 8px;
  padding: clamp(18px, 3vw, 28px);
}

.panel-head h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1.16;
  letter-spacing: 0;
}

.panel-head p,
.empty-result p,
.loading-result p {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.65;
}

.generator-form {
  margin-top: 24px;
  display: grid;
  gap: 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

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

.field span {
  color: #424850;
  font-size: 13px;
  font-weight: 650;
}

textarea,
select,
input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--ink);
  outline: none;
}

textarea {
  min-height: 150px;
  padding: 14px;
  resize: vertical;
  line-height: 1.55;
}

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

textarea:focus,
select:focus,
input:focus {
  border-color: rgba(199, 53, 76, 0.72);
  box-shadow: 0 0 0 3px rgba(199, 53, 76, 0.12);
}

.prompt-preview {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fcf7f0;
  overflow: hidden;
}

.preview-head {
  min-height: 42px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  color: var(--blue);
  font-size: 13px;
  font-weight: 700;
}

pre {
  max-height: 260px;
  margin: 0;
  padding: 14px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: #34383e;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
}

.primary-button,
.secondary-button,
.text-button {
  cursor: pointer;
  border: 0;
}

.primary-button {
  min-height: 50px;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  font-weight: 750;
}

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

.primary-button:disabled,
.secondary-button:disabled,
.text-button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: #fff;
  text-decoration: none;
  font-weight: 650;
}

.text-button {
  padding: 0;
  color: var(--accent);
  background: transparent;
  font-weight: 650;
}

.user-label {
  color: var(--muted);
  font-size: 13px;
}

.result-panel {
  min-height: calc(100vh - 132px);
  border-radius: 8px;
  padding: clamp(16px, 2.5vw, 24px);
  display: grid;
  place-items: center;
  background:
    linear-gradient(180deg, rgba(111, 134, 111, 0.1), transparent 44%),
    rgba(255, 255, 255, 0.72);
}

.empty-result,
.loading-result,
.image-result {
  width: 100%;
}

.empty-result,
.loading-result {
  max-width: 480px;
  text-align: center;
}

.portrait-placeholder,
.loading-frame {
  aspect-ratio: 4 / 5;
  width: min(360px, 100%);
  margin: 0 auto;
  border-radius: 8px;
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.15), transparent),
    linear-gradient(140deg, rgba(199, 53, 76, 0.15), rgba(111, 134, 111, 0.18), rgba(64, 95, 127, 0.18));
}

.loading-frame {
  position: relative;
  overflow: hidden;
}

.loading-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.65), transparent);
  animation: shimmer 1.4s infinite;
}

@keyframes shimmer {
  to {
    transform: translateX(100%);
  }
}

.image-result img {
  display: block;
  width: min(720px, 100%);
  max-height: calc(100vh - 220px);
  margin: 0 auto;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 18px 44px rgba(28, 26, 22, 0.2);
}

.result-actions {
  margin-top: 16px;
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.error-banner {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  width: min(680px, calc(100% - 32px));
  padding: 13px 16px;
  border-radius: 8px;
  color: var(--danger);
  background: #fff3f2;
  border: 1px solid #f2c7c4;
  box-shadow: var(--shadow);
}

.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(28, 29, 31, 0.34);
  backdrop-filter: blur(10px);
}

.auth-card {
  width: min(380px, 100%);
  border-radius: 8px;
  padding: 24px;
  display: grid;
  gap: 16px;
}

.auth-card h2 {
  margin: 0;
  font-size: 24px;
  letter-spacing: 0;
}

@media (max-width: 860px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .result-panel {
    min-height: 560px;
  }
}

@media (max-width: 560px) {
  .form-grid,
  .account-actions {
    grid-template-columns: 1fr;
    flex-wrap: wrap;
  }

  .panel-head h1 {
    font-size: 25px;
  }
}
