:root {
  color-scheme: light;
  --cream: #f7f0e6;
  --paper: #fffaf2;
  --ink: #1d2520;
  --muted: #6f766f;
  --green: #173d34;
  --green-soft: #d8e3dc;
  --rose: #b86f6b;
  --gold: #b7945b;
  --line: #ded2c0;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 250, 242, 0.92), rgba(247, 240, 230, 0.96)),
    radial-gradient(circle at top left, rgba(184, 111, 107, 0.16), transparent 36%),
    var(--cream);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.viewer-open {
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

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

.workspace {
  display: grid;
  gap: 16px;
  width: min(1180px, 100%);
  margin: 0 auto;
}

.topbar {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 14px;
  padding: 16px 0 8px;
}

.topbar h1 {
  line-height: 0.94;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--rose);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 600;
}

h1 {
  font-size: clamp(2.1rem, 12vw, 4.4rem);
}

h2 {
  font-size: 1.45rem;
}

p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.auth-panel,
.status-header,
.results-header,
.form-row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 14px;
}

.auth-panel {
  border-color: rgba(23, 61, 52, 0.22);
  background: linear-gradient(135deg, var(--paper), #f3eadb);
}

.auth-panel.is-allowed {
  border-color: rgba(23, 61, 52, 0.42);
  background: linear-gradient(135deg, #f8f3e8, #d8e3dc);
}

.generation-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.upload-panel {
  display: grid;
  gap: 18px;
}

.upload-target {
  display: grid;
  place-items: center;
  min-height: 170px;
  border: 1px dashed var(--gold);
  border-radius: 8px;
  background: #fbf6ec;
  background-position: center;
  background-size: cover;
  color: var(--green);
  font-weight: 700;
  text-align: center;
  padding: 18px;
  transition: border-color 160ms ease, transform 160ms ease;
}

.upload-target:focus-within,
.upload-target:hover {
  border-color: var(--green);
  transform: translateY(-1px);
}

.upload-target input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

#portraitLabel {
  max-width: 100%;
  border-radius: 999px;
  background: rgba(255, 250, 242, 0.9);
  padding: 10px 14px;
  overflow-wrap: anywhere;
}

.consent-row {
  display: grid;
  grid-template-columns: 20px 1fr;
  gap: 10px;
  color: var(--muted);
  line-height: 1.45;
}

.form-row label {
  color: var(--muted);
  font-size: 0.92rem;
}

.demo-note {
  margin: -4px 0 0;
  border-left: 3px solid var(--gold);
  padding-left: 12px;
  color: var(--green);
  font-size: 0.94rem;
}

select {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  padding: 10px 12px;
  color: var(--ink);
}

.primary-button,
#requestAccessButton,
#downloadButton,
.icon-button,
.secondary-button {
  min-height: 44px;
  border-radius: 6px;
  padding: 0 16px;
  font-weight: 700;
}

.primary-button,
#downloadButton {
  background: var(--green);
  color: white;
}

.primary-button {
  box-shadow: 0 10px 24px rgba(23, 61, 52, 0.18);
}

#requestAccessButton,
.icon-button,
.secondary-button {
  background: var(--green-soft);
  color: var(--green);
}

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

.status-pill {
  width: fit-content;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green);
  padding: 6px 10px;
  font-size: 0.82rem;
  font-weight: 700;
}

.status-pill[data-status="ready"] {
  background: #dbe8d3;
}

.status-pill[data-status="failed"] {
  background: #efd7d5;
  color: #80362f;
}

.page-list {
  display: grid;
  gap: 10px;
  margin: 18px 0 0;
  padding: 0;
  list-style: none;
}

.page-list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  padding: 0 0 10px;
}

.page-list li.is-ready span:last-child {
  color: var(--green);
  font-weight: 700;
}

.page-list span:last-child {
  color: var(--muted);
}

.results-band {
  display: grid;
  gap: 16px;
  padding: 4px 0 30px;
}

.result-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.page-preview {
  display: flex;
  flex-direction: column;
  aspect-ratio: 4 / 5;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, var(--paper), #efe1cf);
  color: var(--green);
  text-align: center;
  overflow: hidden;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 0.95rem;
  min-width: 0;
}

.page-preview--empty {
  display: grid;
  place-items: center;
  padding: 12px;
}

.page-preview--ready img {
  display: block;
  width: 100%;
  min-height: 0;
  flex: 1;
  object-fit: cover;
}

.page-preview--ready {
  cursor: zoom-in;
}

.page-preview__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-top: 1px solid var(--line);
  background: var(--paper);
  padding: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.9rem;
  font-weight: 700;
}

.page-preview__actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.secondary-button {
  min-height: 34px;
  padding: 0 12px;
  font-size: 0.8rem;
}

.viewer[hidden] {
  display: none;
}

.viewer {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(13, 23, 18, 0.76);
  padding: 14px;
}

.viewer__surface {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  width: min(100%, 520px);
  max-height: calc(100vh - 28px);
  border: 1px solid rgba(255, 250, 242, 0.35);
  border-radius: 8px;
  background: var(--cream);
  padding: 10px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.32);
}

.viewer__bar {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 10px;
}

.viewer__bar h2,
.viewer__eyebrow {
  margin: 0;
}

.viewer__eyebrow {
  color: var(--rose);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.viewer__icon,
.viewer__download,
.viewer__nav {
  min-height: 44px;
  border-radius: 6px;
  font-weight: 800;
}

.viewer__icon,
.viewer__download {
  background: var(--green-soft);
  color: var(--green);
}

.viewer__icon {
  font-size: 1.25rem;
  line-height: 1;
}

.viewer__download {
  padding: 0 14px;
}

.viewer__stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
}

.viewer__stage img {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 132px);
  aspect-ratio: 4 / 5;
  object-fit: contain;
  border-radius: 8px;
  background: var(--paper);
}

.viewer__nav {
  position: absolute;
  top: 50%;
  width: 42px;
  translate: 0 -50%;
  background: rgba(255, 250, 242, 0.92);
  color: var(--green);
  font-size: 2.1rem;
  line-height: 1;
}

.viewer__nav--prev {
  left: 8px;
}

.viewer__nav--next {
  right: 8px;
}

@media (min-width: 520px) {
  .result-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 720px) {
  .app-shell {
    padding: 24px;
  }

  .workspace {
    gap: 20px;
  }

  .topbar {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 20px 0;
  }

  h1 {
    font-size: clamp(2.1rem, 6vw, 4.4rem);
  }

  .panel {
    padding: 20px;
  }

  .auth-panel,
  .status-header,
  .results-header,
  .form-row {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
  }

  select {
    width: auto;
    min-width: 180px;
  }
}

@media (max-width: 430px) {
  .page-preview__footer {
    align-items: stretch;
    flex-direction: column;
  }

  .page-preview__actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
}

@media (min-width: 860px) {
  .result-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (min-width: 920px) {
  .generation-grid {
    grid-template-columns: minmax(280px, 0.8fr) minmax(320px, 1.2fr);
    gap: 20px;
  }
}

@media (min-width: 1180px) {
  .result-grid {
    grid-template-columns: repeat(7, minmax(120px, 1fr));
  }
}
