:root {
  color-scheme: light;
  --bg: #f2f5f7;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --ink: #16202a;
  --muted: #627284;
  --line: #d8e0e8;
  --accent: #0f7b6c;
  --accent-strong: #095d52;
  --blue: #295b9a;
  --warn: #a95d18;
  --danger: #a1313d;
  --shadow: 0 16px 44px rgba(25, 36, 50, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

body.locked {
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

.app-shell {
  width: min(1220px, calc(100vw - 32px));
  min-height: calc(100vh - 32px);
  margin: 16px auto;
  display: grid;
  grid-template-columns: minmax(320px, 430px) minmax(0, 1fr);
  gap: 16px;
}

.creator-panel,
.results-panel {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.creator-panel {
  display: flex;
  flex-direction: column;
}

.topbar {
  min-height: 88px;
  padding: 20px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 25px;
  line-height: 1.18;
}

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

#modelLine {
  margin-top: 7px;
  color: var(--muted);
  font-size: 13px;
}

.badge {
  min-width: 96px;
  padding: 7px 10px;
  border: 1px solid rgba(15, 123, 108, 0.24);
  border-radius: 999px;
  color: var(--accent-strong);
  background: rgba(15, 123, 108, 0.09);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
  white-space: nowrap;
}

.badge-warn {
  color: var(--warn);
  border-color: rgba(169, 93, 24, 0.26);
  background: rgba(169, 93, 24, 0.1);
}

.controls {
  padding: 20px;
  display: grid;
  gap: 16px;
}

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

.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

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

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

textarea {
  min-height: 260px;
  resize: vertical;
  padding: 13px;
  line-height: 1.55;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(15, 123, 108, 0.16);
}

.control-grid {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 12px;
  align-items: end;
}

.quick-actions {
  display: grid;
  grid-template-columns: 1fr 104px;
  gap: 10px;
}

button,
.image-actions a {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #ffffff;
  font-weight: 850;
  text-decoration: none;
  cursor: pointer;
}

button:hover,
.image-actions a:hover {
  background: var(--accent-strong);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

button.secondary {
  background: #e5ebf1;
  color: var(--ink);
}

button.secondary:hover {
  background: #d9e1e9;
}

.results-panel {
  display: flex;
  flex-direction: column;
}

.result-head {
  min-height: 68px;
  padding: 18px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
}

#statusLine {
  color: var(--muted);
  font-size: 13px;
}

.gallery {
  flex: 1;
  min-height: 410px;
  padding: 20px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  align-content: start;
  gap: 16px;
  overflow: auto;
}

.image-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.image-card img {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  background: #101720;
}

.image-actions {
  min-height: 56px;
  padding: 9px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.image-actions span {
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-actions a {
  min-height: 34px;
  padding: 0 14px;
  font-size: 13px;
  background: var(--blue);
}

.image-actions a:hover {
  background: #1f477a;
}

.empty {
  align-self: center;
  justify-self: center;
  color: var(--muted);
}

.details {
  border-top: 1px solid var(--line);
  padding: 12px 20px 18px;
}

.details summary {
  color: var(--danger);
  cursor: pointer;
  font-weight: 850;
}

.details pre {
  max-height: 240px;
  overflow: auto;
  margin: 12px 0 0;
  padding: 12px;
  border-radius: 8px;
  background: #151d25;
  color: #f5f7fa;
  white-space: pre-wrap;
}

.auth-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  padding: 24px;
  display: grid;
  place-items: center;
  background: rgba(14, 24, 34, 0.58);
}

.auth-modal[hidden] {
  display: none;
}

.auth-box {
  width: min(420px, 100%);
  padding: 24px;
  display: grid;
  gap: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.22);
}

.auth-message {
  min-height: 20px;
  color: var(--muted);
  font-size: 13px;
}

.auth-message.is-error {
  color: var(--danger);
}

@media (max-width: 880px) {
  .app-shell {
    width: min(100vw - 20px, 680px);
    grid-template-columns: 1fr;
  }

  .gallery {
    min-height: 300px;
  }
}

@media (max-width: 520px) {
  .topbar,
  .result-head {
    align-items: stretch;
    flex-direction: column;
  }

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