:root {
  color-scheme: light;
  --bg: #f5f3ee;
  --surface: #fffdfa;
  --surface-soft: #f9f4ee;
  --text: #171412;
  --muted: #746d66;
  --line: #e4dcd1;
  --accent: #2f6f5e;
  --accent-strong: #16483c;
  --accent-soft: #e7f2ec;
  --danger: #a13a2a;
  --shadow: 0 18px 42px rgba(45, 35, 25, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(140deg, rgba(47, 111, 94, 0.12), transparent 34%),
    linear-gradient(180deg, #fffdfa 0%, var(--bg) 48%, #efebe4 100%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(920px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 12px calc(24px + env(safe-area-inset-bottom));
}

.screen-view[hidden] {
  display: none;
}

.upload-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start;
  padding: 16px;
  border: 1px solid rgba(47, 111, 94, 0.18);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(47, 111, 94, 0.12), rgba(255, 255, 255, 0.2)),
    var(--surface);
  box-shadow: var(--shadow);
}

.section-kicker {
  display: block;
  margin-bottom: 8px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 720;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.upload-hero h1,
.topbar h2 {
  margin: 0;
  max-width: 680px;
  font-size: clamp(30px, 7vw, 44px);
  line-height: 0.96;
  letter-spacing: 0;
}

.upload-hero p,
.topbar p {
  max-width: 620px;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.45;
}

.ghost-button,
.restore-button,
.load-more-button,
.analyze-button,
.copy-button,
.secondary-button,
.danger-button,
.icon-button,
.generate-button,
.delete-button,
.tab {
  border-radius: 8px;
  cursor: pointer;
}

.ghost-button {
  height: 38px;
  border: 1px solid rgba(47, 111, 94, 0.22);
  padding: 0 13px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--accent-strong);
  white-space: nowrap;
}

.upload-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 12px;
  margin-top: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(45, 35, 25, 0.08);
}

.upload-drop {
  position: relative;
  display: grid;
  min-height: 330px;
  place-items: center;
  grid-row: span 3;
  overflow: hidden;
  border: 1px dashed #b9aa99;
  border-radius: 8px;
  padding: 18px;
  background: var(--surface-soft);
  text-align: center;
  cursor: pointer;
}

.upload-drop input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.upload-drop img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.upload-drop::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 48%, rgba(0, 0, 0, 0.48));
  opacity: 0;
}

.upload-drop.has-photo::after {
  opacity: 1;
}

.upload-icon,
.upload-drop strong,
.upload-drop small {
  position: relative;
  z-index: 1;
}

.upload-icon {
  display: grid;
  width: 52px;
  height: 52px;
  place-items: center;
  margin-bottom: 12px;
  border-radius: 50%;
  background: var(--text);
  color: #fff;
  font-size: 30px;
  line-height: 1;
}

.upload-drop strong {
  max-width: 100%;
  overflow: hidden;
  font-size: 20px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-drop small {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.upload-drop.has-photo strong,
.upload-drop.has-photo small {
  color: #fff;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.46);
}

.upload-drop.has-photo .upload-icon {
  display: none;
}

.analyze-button {
  height: 50px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 720;
}

.analyze-button:disabled {
  border-color: #d0c7bc;
  background: #ddd7cf;
  color: #8a8278;
  cursor: default;
}

.quality-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.quality-list span {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 10px;
  background: #fbf9f5;
  color: #4a4641;
  font-size: 12px;
  text-align: left;
}

.analysis-result {
  display: grid;
  grid-column: 1 / -1;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px;
  background: #fbf9f5;
}

.analysis-result[hidden] {
  display: none;
}

.analysis-result.accept {
  border-color: #a9d4bd;
  background: #effaf3;
}

.analysis-result.warn,
.analysis-result.pending {
  border-color: #e2c875;
  background: #fff8df;
}

.analysis-result.reject {
  border-color: #dda89c;
  background: #fff1ee;
}

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

.analysis-head strong {
  font-size: 17px;
}

.analysis-head span {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.analysis-result p,
.analysis-result small {
  margin: 0;
  color: #302d29;
  font-size: 14px;
  line-height: 1.45;
}

.analysis-result small {
  color: var(--muted);
}

.analysis-result ul {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.analysis-result li {
  border-radius: 999px;
  padding: 5px 8px;
  background: rgba(23, 20, 18, 0.08);
  color: #34302b;
  font-size: 12px;
}

.generation-status {
  margin: 0 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: #fbf9f5;
  color: #302d29;
  font-size: 14px;
  line-height: 1.4;
}

.generation-status[hidden] {
  display: none;
}

.generation-status.pending {
  border-color: #e2c875;
  background: #fff8df;
}

.generation-status.done {
  border-color: #a9d4bd;
  background: #effaf3;
}

.generation-status.error {
  border-color: #dda89c;
  background: #fff1ee;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 3;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  padding: 4px 0 14px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
}

.topbar-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
}

.search {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.search input {
  width: 100%;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}

.search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 111, 94, 0.13);
}

.restore-button {
  height: 44px;
  border: 1px solid rgba(47, 111, 94, 0.28);
  padding: 0 12px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  white-space: nowrap;
}

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

.card {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.card-main {
  display: grid;
  gap: 8px;
  min-width: 0;
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.thumb {
  width: 100%;
  aspect-ratio: 4 / 5;
  overflow: hidden;
  border-radius: 8px;
  background: #e9e1d7;
  box-shadow: 0 1px 0 rgba(23, 20, 18, 0.06);
}

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

.card-meta {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  min-height: 24px;
  font-size: 12px;
}

.card-meta strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-meta span {
  color: var(--muted);
  white-space: nowrap;
}

.card-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(70px, 0.72fr);
  gap: 6px;
}

.generate-button,
.delete-button {
  height: 32px;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 680;
}

.generate-button {
  border: 1px solid rgba(47, 111, 94, 0.28);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.delete-button {
  border: 1px solid #e0bbb1;
  background: #fff6f3;
  color: var(--danger);
}

.load-more-button {
  display: block;
  width: min(360px, 100%);
  height: 46px;
  margin: 18px auto 0;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 680;
}

.empty-state {
  grid-column: 1 / -1;
  margin: 40px 0;
  color: var(--muted);
  text-align: center;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  width: min(360px, calc(100vw - 28px));
  padding: 6px;
  border: 1px solid rgba(228, 220, 209, 0.86);
  border-radius: 8px;
  background: rgba(255, 253, 250, 0.9);
  box-shadow: 0 16px 38px rgba(45, 35, 25, 0.18);
  transform: translateX(-50%);
  backdrop-filter: blur(18px);
}

.nav-button {
  display: grid;
  grid-template-columns: auto auto;
  justify-content: center;
  align-items: center;
  gap: 6px;
  height: 42px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-weight: 680;
  cursor: pointer;
}

.nav-button.active {
  background: var(--text);
  color: #fff;
}

.prompt-dialog {
  width: min(980px, calc(100vw - 24px));
  max-height: min(760px, calc(100vh - 24px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.prompt-dialog::backdrop,
.delete-dialog::backdrop {
  background: rgba(10, 9, 8, 0.55);
}

.dialog-layout {
  display: grid;
  grid-template-columns: minmax(260px, 42%) 1fr;
  max-height: inherit;
}

.preview-pane {
  min-height: 420px;
  background: #e8e1d8;
}

.preview-pane img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

.prompt-pane {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  min-height: 420px;
  max-height: inherit;
  padding: 18px;
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.dialog-head h2 {
  margin: 0 0 4px;
  font-size: 19px;
}

.dialog-head a {
  color: var(--accent);
  font-size: 13px;
  text-decoration: none;
}

.icon-button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-size: 26px;
  line-height: 1;
}

.tabs {
  display: flex;
  gap: 6px;
  margin: 16px 0 10px;
}

.tab,
.copy-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}

.tab {
  height: 34px;
  padding: 0 12px;
}

.tab.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

pre {
  min-height: 0;
  margin: 0;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: #27231f;
  font: 14px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.copy-button {
  height: 42px;
  margin-top: 14px;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.delete-dialog {
  width: min(360px, calc(100vw - 24px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.model-dialog {
  width: min(520px, calc(100vw - 24px));
  max-height: min(720px, calc(100vh - 24px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.model-dialog::backdrop {
  background: rgba(10, 9, 8, 0.55);
}

.model-dialog form {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.model-dialog .dialog-head p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
}

.model-list {
  display: grid;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
}

.model-option {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  min-height: 46px;
  border: 1px solid rgba(47, 111, 94, 0.24);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  text-align: left;
  cursor: pointer;
}

.model-option strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.model-empty {
  margin: 0;
}

.model-upload {
  display: grid;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.model-upload label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.model-upload input[type="text"] {
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}

.file-row {
  min-height: 42px;
  border: 1px dashed #b9aa99;
  border-radius: 8px;
  padding: 11px 12px;
  background: var(--surface-soft);
  cursor: pointer;
}

.file-row input {
  display: none;
}

.delete-dialog form {
  padding: 18px;
}

.delete-dialog h2 {
  margin: 0;
  font-size: 19px;
}

.delete-dialog p {
  margin: 8px 0 18px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.delete-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.secondary-button,
.danger-button {
  height: 40px;
  font: inherit;
}

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

.danger-button {
  border: 1px solid var(--danger);
  background: var(--danger);
  color: #fff;
}

@media (max-width: 720px) {
  .app-shell {
    padding-inline: 12px;
  }

  .upload-hero {
    grid-template-columns: 1fr;
    padding: 14px;
  }

  .ghost-button {
    width: 100%;
  }

  .upload-drop {
    min-height: 220px;
  }

  .upload-card {
    grid-template-columns: 1fr;
  }

  .upload-drop {
    grid-row: auto;
  }

  .quality-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .quality-list span {
    min-height: 38px;
    padding: 9px 8px;
    text-align: center;
  }

  .topbar-actions {
    grid-template-columns: 1fr;
  }

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

  .dialog-layout {
    grid-template-columns: 1fr;
  }

  .preview-pane {
    min-height: 250px;
    max-height: 42vh;
  }

  .prompt-pane {
    min-height: 360px;
  }
}
