:root {
  color-scheme: light;
  --bg: #f7f4ef;
  --ink: #1e2320;
  --muted: #687069;
  --line: #d9d2c6;
  --panel: #fffdf9;
  --accent: #13795b;
  --accent-ink: #ffffff;
  --warn: #b54708;
  --danger: #b42318;
  --shadow: 0 18px 50px rgba(34, 31, 25, 0.12);
}

* {
  box-sizing: border-box;
}

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

button,
textarea,
input {
  font: inherit;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 22px;
}

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

.login-box h1 {
  margin-bottom: 8px;
}

.login-box input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 0 12px;
  color: var(--ink);
}

.login-box button[type="submit"] {
  min-height: 50px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.login-error {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
  font-size: 14px;
}

.app {
  width: min(100%, 720px);
  margin: 0 auto;
  padding: 18px 14px 104px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 8px 2px 18px;
}

.userbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1.1;
  letter-spacing: 0;
}

label {
  display: block;
  font-size: 15px;
  font-weight: 700;
}

.status-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--warn);
  box-shadow: 0 0 0 5px rgba(181, 71, 8, 0.12);
  flex: 0 0 auto;
}

.status-dot.ready {
  background: var(--accent);
  box-shadow: 0 0 0 5px rgba(19, 121, 91, 0.12);
}

.composer,
.controls,
.result,
.history {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.composer {
  padding: 14px;
}

textarea {
  width: 100%;
  min-height: 168px;
  margin-top: 10px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px;
  background: #fff;
  color: var(--ink);
  line-height: 1.55;
  outline: none;
}

textarea:focus,
button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(19, 121, 91, 0.25);
  outline-offset: 2px;
}

.prompt-meta,
.field-head,
.result-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.result-head {
  align-items: flex-start;
}

.result-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
}

.prompt-meta {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.ghost {
  border: 0;
  background: transparent;
  color: var(--accent);
  padding: 8px 0;
  font-weight: 700;
  text-decoration: none;
}

.ghost.small {
  padding: 4px 0;
  font-size: 13px;
}

.link-button[aria-disabled="true"],
.download-button[aria-disabled="true"] {
  pointer-events: none;
  opacity: 0.45;
}

.download-button {
  display: inline-grid;
  place-items: center;
  min-height: 38px;
  padding: 0 12px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.controls,
.result,
.history {
  margin-top: 14px;
  padding: 14px;
}

.field + .field {
  margin-top: 18px;
}

.field-head span,
.result-head p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.field-note {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.segmented.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.segmented button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 700;
}

.segmented button.active {
  border-color: var(--accent);
  background: #e7f3ee;
  color: #07513c;
}

input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.upload {
  display: grid;
  gap: 4px;
  place-items: center;
  min-height: 92px;
  margin-top: 10px;
  border: 1px dashed #b9b0a3;
  border-radius: 8px;
  background: #fbfaf7;
  color: var(--muted);
  text-align: center;
  padding: 16px;
}

.upload strong {
  color: var(--ink);
}

.thumbs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #eee;
}

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

.progress {
  height: 8px;
  margin: 12px 0;
  background: #ece6dc;
  border-radius: 999px;
  overflow: hidden;
}

.progress div {
  width: 0%;
  height: 100%;
  background: var(--accent);
  transition: width 0.25s ease;
}

.imageStage {
  display: grid;
  place-items: center;
  min-height: 280px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf7;
  color: var(--muted);
  overflow: hidden;
}

.imageStage img {
  width: 100%;
  height: auto;
  display: block;
}

.imageStage .fallback {
  display: grid;
  gap: 10px;
  place-items: center;
  padding: 24px;
  text-align: center;
}

.history-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

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

.history-thumb {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 8px;
  overflow: hidden;
  background: #f0ece5;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.history-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.history-main {
  min-width: 0;
  display: grid;
  gap: 5px;
}

.history-main strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

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

.empty {
  padding: 16px 0 2px;
}

.bottomBar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  background: rgba(247, 244, 239, 0.88);
  border-top: 1px solid rgba(217, 210, 198, 0.9);
  backdrop-filter: blur(14px);
}

#generateButton {
  display: block;
  width: min(100%, 720px);
  min-height: 54px;
  margin: 0 auto;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 17px;
  font-weight: 800;
}

#generateButton[disabled] {
  opacity: 0.65;
}

.error {
  color: var(--danger) !important;
}

@media (min-width: 760px) {
  .app {
    padding-top: 34px;
  }

  h1 {
    font-size: 36px;
  }
}
