:root {
  color-scheme: light;
  --bg: #f4f5f1;
  --surface: #ffffff;
  --surface-muted: #f8f7f2;
  --text: #20231f;
  --muted: #686f64;
  --line: #d9ddd2;
  --accent: #1f7a5b;
  --accent-dark: #155f45;
  --danger: #b3261e;
  --ink-soft: #343a35;
  --shadow: 0 22px 60px rgba(32, 35, 31, 0.11);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  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 {
  cursor: pointer;
}

.shell {
  min-height: 100vh;
  padding: 24px;
}

.login-view {
  min-height: calc(100vh - 48px);
  display: grid;
  place-items: center;
}

.login-panel {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 26px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #20231f;
  color: #ffffff;
  font-weight: 800;
}

h1,
h2,
p {
  margin: 0;
}

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

h2 {
  font-size: 16px;
  line-height: 1.3;
}

.brand-row p,
.topbar p {
  color: var(--muted);
  margin-top: 4px;
}

label {
  display: grid;
  gap: 8px;
  color: var(--ink-soft);
  font-weight: 650;
}

label + label {
  margin-top: 16px;
}

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 16px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
}

.mode-tabs label {
  display: block;
  margin: 0;
}

.mode-tabs input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
}

.mode-tabs span {
  display: grid;
  min-height: 36px;
  place-items: center;
  border-radius: 6px;
  color: var(--muted);
  font-weight: 800;
}

.mode-tabs input:checked + span {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 8px rgba(32, 35, 31, 0.1);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

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

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

.reference-panel {
  margin-top: 16px;
}

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

.reference-slot {
  gap: 8px;
  min-width: 0;
  margin: 0;
}

.reference-slot input {
  min-height: auto;
  padding: 8px;
  font-size: 12px;
}

.image-preview {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 122, 91, 0.16);
}

.primary-button,
.secondary-button,
.ghost-button {
  min-height: 42px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 16px;
  font-weight: 750;
}

.primary-button {
  width: 100%;
  margin-top: 22px;
  background: var(--accent);
  color: #ffffff;
}

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

.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.68;
}

.secondary-button {
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
}

.secondary-button:hover,
.ghost-button:hover {
  border-color: #9fa79a;
}

.ghost-button {
  background: transparent;
  border-color: var(--line);
  color: var(--ink-soft);
}

.compact {
  min-height: 34px;
  padding: 0 12px;
}

.form-error {
  min-height: 22px;
  margin-top: 12px;
  color: var(--danger);
  font-size: 14px;
}

.app-view {
  max-width: 1360px;
  margin: 0 auto;
}

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

.workspace {
  display: grid;
  grid-template-columns: minmax(340px, 440px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.control-panel,
.result-panel,
.history-section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.settings-grid label {
  margin: 0;
}

.actions-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}

.actions-row .primary-button {
  margin-top: 20px;
}

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

.result-frame {
  position: relative;
  min-height: 500px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px dashed #c6ccbf;
  border-radius: 8px;
  background: var(--surface-muted);
}

.result-frame img {
  width: 100%;
  height: 100%;
  max-height: 76vh;
  object-fit: contain;
}

.empty-state,
.loading-state {
  color: var(--muted);
  font-weight: 700;
}

.loading-state {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 3px solid #cfd6ca;
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.link-button {
  display: inline-grid;
  place-items: center;
  min-width: 82px;
  text-decoration: none;
}

.revised-prompt {
  margin-top: 14px;
  padding: 12px;
  border-radius: 8px;
  background: #f2efe7;
  color: var(--ink-soft);
  line-height: 1.55;
}

.history-section {
  margin-top: 20px;
}

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

.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.history-item {
  display: block;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
  color: inherit;
  text-decoration: none;
}

.history-item img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
}

.history-item span {
  display: block;
  padding: 8px;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 900px) {
  .shell {
    padding: 16px;
  }

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

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

  .result-frame {
    min-height: 360px;
  }
}

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

  .settings-grid,
  .actions-row,
  .reference-grid {
    grid-template-columns: 1fr;
  }

  .actions-row .primary-button {
    margin-top: 10px;
  }

  textarea {
    min-height: 220px;
  }
}
