:root {
  color-scheme: dark;
  --bg: #09090b;
  --surface: #18181b;
  --surface-soft: #111113;
  --border: #27272a;
  --ink: #fafafa;
  --muted: #71717a;
  --muted-strong: #a1a1aa;
  --accent: #f59e0b;
  --accent-hover: #d97706;
  --danger: #f87171;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

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

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

.bg-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(ellipse at 25% 15%, rgba(245, 158, 11, 0.055) 0%, transparent 55%),
    radial-gradient(ellipse at 75% 85%, rgba(245, 158, 11, 0.03) 0%, transparent 50%);
}

.top-nav,
.app-shell,
.status {
  position: relative;
  z-index: 1;
}

.top-nav {
  width: min(768px, 100%);
  margin: 0 auto;
  padding: 22px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.top-nav.wide,
.history-shell {
  width: min(1024px, 100%);
}

.brand {
  color: var(--ink);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0;
}

.brand-link {
  text-decoration: none;
  transition: color 180ms ease;
}

.brand-link:hover {
  color: var(--accent);
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.history-link {
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  transition: color 180ms ease;
}

.history-link:hover {
  color: var(--accent);
}

.history-link-icon {
  width: 13px;
  height: 13px;
  border: 1.8px solid currentColor;
  border-radius: 50%;
  position: relative;
}

.history-link-icon::before,
.history-link-icon::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 2px;
  width: 1.8px;
  background: currentColor;
  transform-origin: bottom center;
}

.history-link-icon::before {
  height: 4px;
}

.history-link-icon::after {
  height: 5px;
  transform: rotate(125deg);
}

.back-icon {
  width: 12px;
  height: 12px;
  border-left: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
}

.trash-icon {
  width: 13px;
  height: 14px;
  border: 1.8px solid currentColor;
  border-top: 0;
  border-radius: 0 0 3px 3px;
  position: relative;
}

.trash-icon::before {
  content: "";
  position: absolute;
  left: -2px;
  top: -4px;
  width: 15px;
  height: 2px;
  background: currentColor;
}

.trash-icon::after {
  content: "";
  position: absolute;
  left: 4px;
  top: -7px;
  width: 5px;
  height: 2px;
  background: currentColor;
}

.app-shell {
  width: min(768px, 100%);
  margin: 0 auto;
  padding: 18px 24px 96px;
}

.hero {
  margin: 22px 0 38px;
}

.hero h1 {
  max-width: 680px;
  margin: 0;
  color: var(--ink);
  font-size: clamp(38px, 7vw, 56px);
  line-height: 1.12;
  font-weight: 800;
  letter-spacing: 0;
}

.hero h1 span {
  color: var(--accent);
}

.hero p {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.7;
}

.generator-form {
  display: grid;
  gap: 16px;
}

.field {
  display: grid;
  gap: 9px;
}

.field > span,
.segmented legend {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  outline: none;
  transition: border-color 260ms ease, box-shadow 260ms ease, background 260ms ease;
}

textarea {
  min-height: 152px;
  padding: 18px 20px;
  resize: vertical;
  line-height: 1.65;
}

input,
select {
  height: 46px;
  padding: 0 13px;
}

select {
  color: var(--ink);
}

textarea::placeholder,
input::placeholder {
  color: #52525b;
}

textarea:focus,
input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.1);
}

.prompt-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.prompt-count {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.primary-button,
.ghost-button {
  min-height: 44px;
  border-radius: 12px;
  border: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.primary-button {
  min-width: 126px;
  padding: 0 24px;
  background: var(--accent);
  color: var(--bg);
  position: relative;
  overflow: hidden;
  transition: background 220ms ease, opacity 220ms ease, transform 220ms ease;
}

.primary-button:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.primary-button:active:not(:disabled) {
  transform: translateY(0);
}

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

.primary-button.is-loading {
  cursor: wait;
  opacity: 0.78;
}

.primary-button.is-loading::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.25), transparent);
  transform: translateX(-100%);
  animation: button-sweep 1.25s ease-in-out infinite;
}

.button-icon {
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-radius: 4px;
  transform: rotate(45deg);
  flex: 0 0 auto;
}

.button-label,
.button-icon {
  position: relative;
  z-index: 1;
}

.primary-button.is-loading .button-icon {
  border-radius: 50%;
  border-color: rgba(9, 9, 11, 0.25);
  border-top-color: var(--bg);
  transform: none;
  animation: button-spin 720ms linear infinite;
}

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

.upload-field {
  grid-column: 1 / -1;
}

.upload-control {
  display: grid;
  gap: 10px;
}

.upload-dropzone {
  min-height: 78px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: rgba(24, 24, 27, 0.78);
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 14px;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 220ms ease, background 220ms ease, color 220ms ease;
}

.upload-dropzone:hover,
.upload-dropzone:focus-within {
  border-color: var(--accent);
  background: rgba(245, 158, 11, 0.055);
  color: var(--muted-strong);
}

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

.upload-icon {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background:
    linear-gradient(135deg, rgba(250, 250, 250, 0.08) 0 52%, rgba(245, 158, 11, 0.24) 52%),
    var(--surface-soft);
  position: relative;
}

.upload-icon::before {
  content: "";
  position: absolute;
  left: 10px;
  top: 10px;
  width: 13px;
  height: 13px;
  border-left: 2px solid var(--accent);
  border-top: 2px solid var(--accent);
  transform: rotate(45deg);
}

.upload-text {
  color: currentColor;
  font-size: 13px;
  font-weight: 700;
}

.source-preview {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) 36px;
  gap: 11px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

.source-preview.is-placeholder {
  border-style: dashed;
  background: rgba(24, 24, 27, 0.48);
}

.source-preview img {
  width: 58px;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 10px;
  background: var(--surface-soft);
}

.source-preview.is-placeholder img {
  opacity: 0.86;
}

.source-preview p {
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#source-preview-name {
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

#source-preview-size {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.clear-button {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  position: relative;
  transition: background 180ms ease;
}

.clear-button:hover {
  background: var(--surface-soft);
}

.clear-button::before,
.clear-button::after {
  content: "";
  position: absolute;
  left: 10px;
  top: 17px;
  width: 15px;
  height: 2px;
  background: var(--danger);
}

.clear-button::before {
  transform: rotate(45deg);
}

.clear-button::after {
  transform: rotate(-45deg);
}

.segmented {
  margin: 0;
  padding: 0;
  border: 0;
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(4, 1fr);
}

.segmented legend {
  grid-column: 1 / -1;
}

.segmented label {
  position: relative;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: grid;
  height: 46px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 180ms ease, color 180ms ease, background 180ms ease;
}

.segmented input:checked + span {
  border-color: rgba(245, 158, 11, 0.7);
  background: rgba(245, 158, 11, 0.11);
  color: var(--accent);
}

.preview-panel {
  margin-top: 58px;
}

.loader {
  margin: 0 0 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}

.loader[hidden] {
  display: none;
}

.empty-state[hidden],
#result-image[hidden],
.ghost-button[hidden],
.history-empty[hidden] {
  display: none;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spinner 700ms linear infinite;
}

.preview-stage {
  opacity: 0;
  transform: scale(0.96) translateY(12px);
  transition: opacity 700ms cubic-bezier(0.16, 1, 0.3, 1), transform 700ms cubic-bezier(0.16, 1, 0.3, 1);
}

.preview-stage.show,
.preview-stage.is-empty {
  opacity: 1;
  transform: scale(1) translateY(0);
}

.empty-state {
  min-height: 320px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  display: grid;
  place-items: center;
  gap: 14px;
  color: var(--muted);
  text-align: center;
}

.empty-state p {
  margin: 0;
  font-size: 13px;
}

.empty-mark {
  width: 76px;
  height: 76px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background:
    radial-gradient(circle at 35% 32%, rgba(245, 158, 11, 0.42), transparent 24%),
    linear-gradient(135deg, rgba(250, 250, 250, 0.08), rgba(245, 158, 11, 0.08)),
    var(--surface-soft);
}

#result-image {
  width: 100%;
  height: auto;
  max-height: 72vh;
  object-fit: contain;
  display: block;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.img-blur {
  filter: blur(12px);
  transition: filter 1000ms ease-out;
}

.img-blur.clear {
  filter: blur(0);
}

.result-actions {
  min-height: 44px;
  margin-top: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.result-actions p {
  margin: 0;
  max-width: 58%;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ghost-button,
.icon-button {
  color: var(--muted);
  background: transparent;
  transition: color 180ms ease, background 180ms ease, border-color 180ms ease;
}

.ghost-button {
  min-width: 82px;
  padding: 0 13px;
}

.ghost-button:hover,
.icon-button:hover {
  color: var(--ink);
  background: var(--surface);
}

.download-icon {
  width: 13px;
  height: 14px;
  border-bottom: 2px solid currentColor;
  position: relative;
}

.download-icon::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 0;
  width: 2px;
  height: 10px;
  background: currentColor;
}

.download-icon::after {
  content: "";
  position: absolute;
  left: 2px;
  top: 5px;
  width: 7px;
  height: 7px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
}

.history-section {
  margin-top: 52px;
  padding-top: 22px;
  border-top: 1px solid var(--border);
}

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

.history-header p {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

.history-header h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.icon-button {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  position: relative;
}

.icon-button::before {
  content: "";
  position: absolute;
  inset: 10px;
  border: 2px solid currentColor;
  border-left-color: transparent;
  border-radius: 50%;
}

.icon-button::after {
  content: "";
  position: absolute;
  right: 9px;
  top: 9px;
  width: 7px;
  height: 7px;
  border-top: 2px solid currentColor;
  border-right: 2px solid currentColor;
  transform: rotate(20deg);
}

.history-grid {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 126px;
  gap: 12px;
  overflow-x: auto;
  padding: 2px 0 8px;
}

.history-empty {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.history-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  padding: 6px;
  text-align: left;
  cursor: pointer;
  transition: border-color 180ms ease, transform 180ms ease, box-shadow 180ms ease;
}

.history-item:hover {
  transform: translateY(-1px);
}

.history-item.active {
  border-color: rgba(245, 158, 11, 0.78);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.1);
}

.history-thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
  border-radius: 10px;
  background: var(--surface-soft);
}

.history-meta {
  margin: 7px 2px 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status {
  position: fixed;
  left: 50%;
  bottom: 24px;
  max-width: min(720px, calc(100vw - 32px));
  transform: translateX(-50%);
  padding: 10px 22px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(24, 24, 27, 0.96);
  color: #d4d4d8;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  font-size: 13px;
  line-height: 1.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status[hidden] {
  display: none;
}

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

.history-shell {
  position: relative;
  z-index: 1;
  margin: 0 auto;
  padding: 24px 24px 96px;
}

.history-shell h1 {
  margin: 0 0 30px;
  color: var(--ink);
  font-size: 28px;
  line-height: 1.2;
  font-weight: 800;
}

.clear-all-button {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 700;
  transition: color 180ms ease;
}

.clear-all-button:hover {
  color: var(--danger);
}

.history-page-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.history-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 260ms ease, border-color 260ms ease;
}

.history-card:hover,
.history-card:focus-visible {
  transform: translateY(-4px);
  border-color: #3f3f46;
  outline: none;
}

.history-card-image {
  position: relative;
}

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

.delete-card-button {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  color: var(--muted-strong);
  cursor: pointer;
  opacity: 0;
  transition: opacity 180ms ease, color 180ms ease, background 180ms ease;
}

.history-card:hover .delete-card-button,
.history-card:focus-within .delete-card-button {
  opacity: 1;
}

.delete-card-button:hover {
  color: var(--danger);
  background: rgba(0, 0, 0, 0.86);
}

.delete-card-button::before,
.delete-card-button::after,
.modal-close::before,
.modal-close::after {
  content: "";
  position: absolute;
  left: 8px;
  top: 13px;
  width: 12px;
  height: 2px;
  background: currentColor;
}

.delete-card-button::before,
.modal-close::before {
  transform: rotate(45deg);
}

.delete-card-button::after,
.modal-close::after {
  transform: rotate(-45deg);
}

.history-card-body {
  padding: 12px;
}

.history-card-body p {
  margin: 0;
}

.history-card-body p:first-child {
  color: #d4d4d8;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-card-body p:last-child {
  margin-top: 6px;
  color: #52525b;
  font-size: 10px;
}

.history-page-empty {
  min-height: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--muted);
}

.history-page-empty[hidden] {
  display: none;
}

.history-page-empty p {
  margin: 0;
  font-size: 14px;
}

.history-page-empty a {
  color: var(--accent);
  font-size: 14px;
  text-decoration: none;
}

.history-page-empty a:hover {
  text-decoration: underline;
}

.empty-image-icon {
  width: 54px;
  height: 54px;
  border: 3px solid #3f3f46;
  border-radius: 10px;
  position: relative;
}

.empty-image-icon::before {
  content: "";
  position: absolute;
  left: 9px;
  bottom: 10px;
  width: 30px;
  height: 22px;
  border-left: 3px solid #3f3f46;
  border-bottom: 3px solid #3f3f46;
  transform: skewX(-26deg);
}

.empty-image-icon::after {
  content: "";
  position: absolute;
  right: 10px;
  top: 10px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #3f3f46;
}

.modal-bg {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 280ms ease;
}

.modal-bg.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-box {
  width: min(560px, 92vw);
  max-height: 90vh;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  transform: scale(0.95) translateY(10px);
  transition: transform 350ms cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-bg.open .modal-box {
  transform: scale(1) translateY(0);
}

.modal-image-wrap {
  position: relative;
}

.modal-image-wrap img {
  width: 100%;
  display: block;
  border-radius: 16px 16px 0 0;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  color: var(--muted-strong);
  cursor: pointer;
  transition: color 180ms ease, background 180ms ease;
}

.modal-close:hover {
  color: var(--ink);
  background: rgba(0, 0, 0, 0.82);
}

.modal-close::before,
.modal-close::after {
  left: 10px;
  top: 15px;
}

.modal-body {
  padding: 20px;
}

.modal-body p {
  margin: 0;
  color: #d4d4d8;
  font-size: 14px;
  line-height: 1.65;
}

.modal-meta-row {
  margin-top: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.modal-meta-row span {
  color: var(--muted);
  font-size: 12px;
}

.modal-download {
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
  transition: color 180ms ease;
}

.modal-download:hover {
  color: var(--accent);
}

.fade-up {
  animation: fade-up 400ms ease-out both;
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(16px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@keyframes button-sweep {
  to {
    transform: translateX(100%);
  }
}

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

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 680px) {
  .top-nav {
    padding: 18px 18px;
  }

  .app-shell {
    padding: 12px 18px 92px;
  }

  .hero {
    margin: 16px 0 30px;
  }

  .prompt-actions,
  .result-actions {
    align-items: stretch;
  }

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

  .segmented {
    grid-template-columns: repeat(2, 1fr);
  }

  .primary-button {
    min-width: 118px;
    padding: 0 20px;
  }

  .empty-state {
    min-height: 260px;
  }

  .history-grid {
    grid-auto-columns: 112px;
  }

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

  .nav-actions {
    gap: 12px;
  }
}

@media (max-width: 440px) {
  .prompt-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .primary-button {
    width: 100%;
  }

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

  .result-actions p {
    max-width: 100%;
  }

  .ghost-button {
    justify-self: start;
  }

  .history-shell h1 {
    font-size: 24px;
  }

  .clear-all-button {
    max-width: 128px;
  }
}
