:root {
  --bg: #edf2f7;
  --surface: #ffffff;
  --surface-soft: #f7f9fc;
  --line: #d8e0ea;
  --line-strong: #b9c7d8;
  --text: #152033;
  --muted: #627188;
  --primary: #1f5fbf;
  --primary-dark: #174b98;
  --accent: #007a78;
  --danger: #b42318;
  --shadow: 0 18px 42px rgba(21, 32, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  border: 0;
}

.app {
  width: min(1500px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 18px 0 28px;
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand img {
  width: 64px;
  height: 64px;
  border-radius: 8px;
  object-fit: cover;
  background: #0d1722;
  box-shadow: var(--shadow);
}

.brand p,
.panel-head p {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(30px, 4vw, 44px);
  line-height: 1.05;
}

h2 {
  font-size: 20px;
  line-height: 1.18;
}

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

.api-monitor {
  width: min(430px, 36vw);
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
}

.api-monitor span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.api-monitor strong {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.health-pill {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 850;
}

.health-pill i {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: currentColor;
}

.health-pill.is-checking {
  color: #5f6f86;
  background: #edf2f7;
}

.health-pill.is-ok {
  color: #057a55;
  background: #dff6eb;
}

.health-pill.is-bad {
  color: #b42318;
  background: #fff0ef;
}

.notice {
  margin-bottom: 12px;
  padding: 12px 14px;
  border: 1px solid #bdd7c8;
  border-radius: 8px;
  color: #064e3b;
  background: #e7f6ed;
}

.notice.is-error {
  border-color: #f2b8b5;
  color: #7a271a;
  background: #fff0ef;
}

.workspace {
  display: grid;
  grid-template-columns: 330px minmax(360px, 0.76fr) minmax(440px, 1.24fr);
  gap: 14px;
  align-items: stretch;
}

.panel {
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.settings,
.prompt-panel,
.result-panel {
  min-height: 680px;
  padding: 18px;
}

.settings {
  display: grid;
  align-content: start;
  gap: 15px;
}

.prompt-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 14px;
}

.result-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
}

.panel-head {
  display: grid;
  gap: 0;
}

.inline-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  padding: 10px 12px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

textarea {
  height: 100%;
  min-height: 480px;
  resize: none;
  line-height: 1.6;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31, 95, 191, 0.12);
}

input:disabled {
  color: var(--muted);
  background: #edf2f7;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.preset-block {
  display: grid;
  gap: 10px;
}

.subhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

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

.preset {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface-soft);
  cursor: pointer;
  font-weight: 750;
}

.preset.is-active,
.preset:hover {
  border-color: rgba(31, 95, 191, 0.5);
  color: var(--primary-dark);
  background: #edf5ff;
}

.prompt-field {
  min-height: 0;
}

.prompt-footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}

.primary,
.ghost,
.text-button {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 850;
}

.primary {
  color: #ffffff;
  background: var(--primary);
}

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

.ghost {
  color: var(--text);
  background: #edf2f7;
  border: 1px solid var(--line);
}

.ghost:hover {
  background: #e2e8f0;
}

.text-button {
  min-height: auto;
  padding: 0;
  color: var(--primary);
  background: transparent;
}

.small {
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
}

.wide {
  width: 100%;
}

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

.progress-wrap {
  display: grid;
  gap: 8px;
}

.progress-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.progress-meta strong {
  color: var(--text);
}

.progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #dbe5f0;
}

.progress-bar {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #0b7a78, #1f5fbf, #48b9d8);
  transition: width 0.35s ease;
}

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

.preview {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  overflow: hidden;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background:
    linear-gradient(45deg, #f4f7fb 25%, transparent 25%),
    linear-gradient(-45deg, #f4f7fb 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f4f7fb 75%),
    linear-gradient(-45deg, transparent 75%, #f4f7fb 75%);
  background-color: #ffffff;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-size: 20px 20px;
  color: var(--muted);
}

.preview img {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.preview-empty {
  display: grid;
  place-items: center;
  gap: 6px;
  text-align: center;
}

.preview-empty strong {
  color: var(--text);
}

.preview.is-generating {
  border-style: solid;
  background:
    radial-gradient(circle at 50% 42%, rgba(72, 185, 216, 0.18), transparent 34%),
    linear-gradient(45deg, #eef6fb 25%, transparent 25%),
    linear-gradient(-45deg, #eef6fb 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eef6fb 75%),
    linear-gradient(-45deg, transparent 75%, #eef6fb 75%);
  background-color: #ffffff;
  background-position: center, 0 0, 0 10px, 10px -10px, -10px 0;
  background-size: auto, 20px 20px, 20px 20px, 20px 20px, 20px 20px;
}

.render-stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  display: grid;
  place-items: center;
}

.scan-plane {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(31, 95, 191, 0.08), transparent 18%, transparent 82%, rgba(11, 122, 120, 0.08)),
    repeating-linear-gradient(0deg, rgba(31, 95, 191, 0.08) 0 1px, transparent 1px 22px),
    repeating-linear-gradient(90deg, rgba(11, 122, 120, 0.06) 0 1px, transparent 1px 22px);
  animation: planePulse 2.2s ease-in-out infinite;
}

.scan-line {
  position: absolute;
  left: 0;
  right: 0;
  top: -18%;
  height: 22%;
  background: linear-gradient(180deg, transparent, rgba(31, 95, 191, 0.18), rgba(72, 185, 216, 0.35), transparent);
  filter: blur(1px);
  animation: scanDown 2.4s ease-in-out infinite;
}

.scan-glow {
  position: absolute;
  width: 34%;
  aspect-ratio: 1;
  border-radius: 999px;
  background: rgba(72, 185, 216, 0.18);
  filter: blur(28px);
  animation: glowMove 3.4s ease-in-out infinite;
}

.render-status {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 6px;
  min-width: 240px;
  padding: 14px 16px;
  border: 1px solid rgba(189, 201, 215, 0.8);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow);
  text-align: center;
}

.render-status strong {
  color: var(--text);
}

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

.history-panel {
  margin-top: 14px;
  padding: 18px;
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  margin-top: 14px;
}

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

.image-card:hover {
  border-color: rgba(31, 95, 191, 0.42);
}

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

.image-card div {
  display: grid;
  gap: 5px;
  padding: 10px;
}

.image-card p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.empty {
  color: var(--muted);
}

@keyframes scanDown {
  0% {
    transform: translateY(0);
    opacity: 0;
  }
  12% {
    opacity: 1;
  }
  78% {
    opacity: 1;
  }
  100% {
    transform: translateY(560%);
    opacity: 0;
  }
}

@keyframes glowMove {
  0%, 100% {
    transform: translate(-70%, -40%);
  }
  50% {
    transform: translate(70%, 40%);
  }
}

@keyframes planePulse {
  0%, 100% {
    opacity: 0.75;
  }
  50% {
    opacity: 1;
  }
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 340px minmax(0, 1fr);
  }

  .result-panel {
    grid-column: 1 / -1;
    min-height: 560px;
  }
}

@media (max-width: 760px) {
  .app {
    width: min(100% - 24px, 1500px);
    padding-top: 12px;
  }

  .topbar,
  .top-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .brand img {
    width: 52px;
    height: 52px;
  }

  .api-monitor {
    width: 100%;
  }

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

  .settings,
  .prompt-panel,
  .result-panel {
    min-height: auto;
  }

  textarea {
    min-height: 300px;
  }

  .preview {
    min-height: 340px;
  }
}
