:root {
  --bg: #0b120f;
  --bg-deep: #070b09;
  --surface: #131d19;
  --surface-2: #1a2722;
  --line: #2a3a33;
  --ink: #f1e8d6;
  --ink-dim: #a7b3a8;
  --ink-muted: #6f7d74;
  --copper: #d4a05a;
  --copper-deep: #a77634;
  --moss: #7ba06b;
  --rust: #c26c4f;
  --focus: #e7c88a;

  --font-display: 'Fraunces', 'Times New Roman', serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  --radius: 4px;
  --radius-lg: 10px;
  --ring: 0 0 0 1px var(--line);
  --shadow-lift: 0 18px 40px -20px rgba(0, 0, 0, 0.6), 0 2px 0 rgba(255, 255, 255, 0.02) inset;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(1100px 600px at 85% -10%, rgba(212, 160, 90, 0.08), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(123, 160, 107, 0.07), transparent 55%),
    linear-gradient(180deg, #0a100e 0%, var(--bg) 30%, var(--bg-deep) 100%);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.55;
  letter-spacing: 0.01em;
  min-height: 100vh;
  overflow-x: hidden;
}

.grain {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 1;
  opacity: 0.12;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.95 0 0 0 0 0.9 0 0 0 0 0.78 0 0 0 0.7 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
}

/* ---------- masthead ---------- */

.masthead {
  position: relative;
  z-index: 2;
  padding: 28px 40px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand__mark {
  color: var(--copper);
  width: 48px;
  height: 32px;
  display: grid;
  place-items: center;
}

.brand__text {
  display: flex;
  flex-direction: column;
  line-height: 1;
}

.brand__eyebrow {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.28em;
  color: var(--ink-muted);
}

.brand__title {
  font-family: var(--font-display);
  font-weight: 500;
  font-variation-settings: 'opsz' 72, 'SOFT' 40, 'WONK' 0;
  font-size: 30px;
  margin-top: 4px;
  letter-spacing: -0.01em;
}

.masthead__meta {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--ink-dim);
  display: flex;
  align-items: center;
  gap: 10px;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--moss);
  box-shadow: 0 0 0 4px rgba(123, 160, 107, 0.18);
  animation: pulse 2.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 4px rgba(123, 160, 107, 0.18); }
  50% { box-shadow: 0 0 0 8px rgba(123, 160, 107, 0.04); }
}

/* ---------- shell ---------- */

.shell {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(360px, 420px) 1fr;
  gap: 32px;
  padding: 32px 40px 56px;
  max-width: 1480px;
  margin: 0 auto;
  min-height: calc(100vh - 96px);
}

@media (max-width: 960px) {
  .masthead { padding: 22px 20px 16px; }
  .shell {
    grid-template-columns: 1fr;
    padding: 22px 20px 40px;
  }
}

/* ---------- form panel ---------- */

.panel {
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 26px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  box-shadow: var(--shadow-lift);
  align-self: start;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field__label {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--ink-dim);
}

.field__number {
  color: var(--copper);
  font-weight: 700;
}

.field__hint {
  margin-left: auto;
  color: var(--ink-muted);
  font-size: 10px;
  letter-spacing: 0.18em;
}

/* drop zone */

.drop {
  position: relative;
  display: block;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 22px;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease, transform 0.2s ease;
  background: rgba(255, 255, 255, 0.01);
}

.drop:hover,
.drop.is-drag {
  border-color: var(--copper);
  background: rgba(212, 160, 90, 0.04);
}

.drop.is-drag { transform: scale(1.005); }

.drop__inner {
  display: flex;
  gap: 14px;
  align-items: center;
}

.drop__icon {
  width: 28px;
  height: 28px;
  color: var(--copper);
  flex: none;
}

.drop__copy {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-dim);
}

.drop__copy strong {
  color: var(--ink);
  font-weight: 500;
  letter-spacing: 0.01em;
}

.drop__copy small {
  display: block;
  margin-top: 4px;
  color: var(--ink-muted);
  font-size: 10.5px;
  letter-spacing: 0.08em;
}

/* thumbs */

.thumbs {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 8px;
}

.thumbs:empty { display: none; }

.thumbs li {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--bg-deep);
}

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

.thumbs button {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 0;
  background: rgba(7, 11, 9, 0.85);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.thumbs button:hover {
  background: var(--rust);
  color: var(--bg-deep);
}

/* textarea */

textarea {
  width: 100%;
  resize: vertical;
  min-height: 108px;
  background: var(--bg-deep);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 14px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  letter-spacing: 0.01em;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

textarea::placeholder {
  color: var(--ink-muted);
  font-style: italic;
}

textarea:focus {
  outline: none;
  border-color: var(--copper);
  box-shadow: 0 0 0 3px rgba(212, 160, 90, 0.12);
}

/* segmented */

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.segmented label {
  position: relative;
  cursor: pointer;
}

.segmented input {
  position: absolute;
  opacity: 0;
  inset: 0;
  cursor: pointer;
}

.segmented span {
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: flex-start;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-deep);
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}

.segmented em {
  font-family: var(--font-display);
  font-style: normal;
  font-weight: 500;
  font-variation-settings: 'opsz' 60, 'SOFT' 30;
  font-size: 22px;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.segmented small {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--ink-muted);
  text-transform: uppercase;
}

.segmented label:hover span {
  border-color: rgba(212, 160, 90, 0.4);
}

.segmented input:checked + span {
  border-color: var(--copper);
  background: linear-gradient(180deg, rgba(212, 160, 90, 0.08), rgba(212, 160, 90, 0.02));
}

.segmented input:checked + span em {
  color: var(--copper);
}

.segmented input:focus-visible + span {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* generate button */

.generate {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px 20px;
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
  background: linear-gradient(180deg, var(--copper) 0%, var(--copper-deep) 100%);
  color: #16110a;
  font-family: var(--font-display);
  font-variation-settings: 'opsz' 48, 'SOFT' 20, 'WONK' 1;
  font-size: 17px;
  font-weight: 500;
  letter-spacing: 0.02em;
  transition: transform 0.15s ease, box-shadow 0.2s ease, filter 0.2s ease;
  box-shadow: 0 10px 24px -12px rgba(212, 160, 90, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.generate::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(120% 60% at 50% 120%, rgba(255, 255, 255, 0.25), transparent 55%);
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.generate:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

.generate:hover:not(:disabled)::after { opacity: 1; }

.generate:active:not(:disabled) { transform: translateY(0); }

.generate:disabled {
  cursor: wait;
  filter: saturate(0.4) brightness(0.8);
}

.generate__spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(22, 17, 10, 0.2);
  border-top-color: #16110a;
  display: none;
  animation: spin 0.8s linear infinite;
}

.generate.is-loading .generate__spinner { display: inline-block; }
.generate.is-loading .generate__label { opacity: 0.6; }

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

/* status */

.status {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--ink-muted);
  min-height: 1em;
}

.status.is-error { color: var(--rust); }
.status.is-ok { color: var(--moss); }

/* ---------- stage (preview) ---------- */

.stage {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.stage__frame {
  position: relative;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(0, 0, 0, 0.25)),
    repeating-linear-gradient(135deg, rgba(123, 160, 107, 0.03) 0 2px, transparent 2px 14px),
    var(--bg-deep);
  overflow: hidden;
  box-shadow: var(--shadow-lift);
}

.stage__frame::before,
.stage__frame::after {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  border: 1px solid var(--copper);
  opacity: 0.5;
}

.stage__frame::before {
  top: 10px; left: 10px;
  border-right: 0; border-bottom: 0;
}

.stage__frame::after {
  bottom: 10px; right: 10px;
  border-left: 0; border-top: 0;
}

.stage__placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  color: var(--ink-muted);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.stage__placeholder p {
  margin: 0;
  font-family: var(--font-display);
  font-variation-settings: 'opsz' 72, 'SOFT' 50, 'WONK' 1;
  font-weight: 400;
  font-style: italic;
  font-size: 26px;
  color: var(--ink-dim);
  text-transform: none;
  letter-spacing: -0.01em;
}

.stage__placeholder small {
  font-size: 10px;
  letter-spacing: 0.22em;
  color: var(--ink-muted);
}

.ripple {
  position: relative;
  width: 140px;
  height: 36px;
  display: grid;
  place-items: center;
}

.ripple span {
  position: absolute;
  width: 140px;
  height: 32px;
  border: 1px solid var(--copper);
  border-radius: 50%;
  opacity: 0;
  transform: scale(0.4);
  animation: ripple 3.6s ease-out infinite;
}

.ripple span:nth-child(2) { animation-delay: 1.2s; }
.ripple span:nth-child(3) { animation-delay: 2.4s; }

@keyframes ripple {
  0% { transform: scale(0.4); opacity: 0; }
  15% { opacity: 0.55; }
  100% { transform: scale(1.1); opacity: 0; }
}

#preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  animation: fadeIn 0.6s ease both;
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(1.02); }
  to { opacity: 1; transform: scale(1); }
}

/* loader overlay */

.stage__loader {
  position: absolute;
  inset: 0;
  backdrop-filter: blur(6px);
  background: rgba(7, 11, 9, 0.7);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  color: var(--ink);
  z-index: 3;
}

.stage__loader[hidden] { display: none; }

.stage__loader p {
  margin: 0;
  font-family: var(--font-display);
  font-style: italic;
  font-variation-settings: 'opsz' 60, 'SOFT' 60;
  font-size: 20px;
  letter-spacing: -0.005em;
  color: var(--copper);
}

.waves {
  display: flex;
  gap: 6px;
  align-items: flex-end;
}

.waves span {
  width: 4px;
  height: 18px;
  background: var(--copper);
  border-radius: 2px;
  animation: wave 1.1s ease-in-out infinite;
}

.waves span:nth-child(2) { animation-delay: 0.12s; height: 28px; }
.waves span:nth-child(3) { animation-delay: 0.24s; height: 36px; }
.waves span:nth-child(4) { animation-delay: 0.36s; height: 22px; }

@keyframes wave {
  0%, 100% { transform: scaleY(0.4); opacity: 0.5; }
  50% { transform: scaleY(1); opacity: 1; }
}

/* stage footer */

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

.stage__meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-muted);
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.download {
  padding: 11px 18px;
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.download:not(:disabled):hover {
  border-color: var(--copper);
  color: var(--copper);
  background: rgba(212, 160, 90, 0.06);
}

.download:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ---------- auth / login ---------- */

.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.auth {
  position: relative;
  z-index: 2;
  padding: 40px 24px;
  width: 100%;
}

.auth__card {
  max-width: 420px;
  margin: 0 auto;
  padding: 40px 36px 32px;
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lift);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  position: relative;
}

.auth__card::before,
.auth__card::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border: 1px solid var(--copper);
  opacity: 0.45;
}

.auth__card::before {
  top: 12px; left: 12px;
  border-right: 0; border-bottom: 0;
}

.auth__card::after {
  bottom: 12px; right: 12px;
  border-left: 0; border-top: 0;
}

.auth__mark {
  color: var(--copper);
  width: 48px;
  height: 32px;
  display: grid;
  place-items: center;
  margin-bottom: 6px;
}

.auth__eyebrow {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.28em;
  color: var(--ink-muted);
}

.auth__title {
  margin: 0;
  font-family: var(--font-display);
  font-variation-settings: 'opsz' 72, 'SOFT' 40, 'WONK' 0;
  font-weight: 500;
  font-size: 32px;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.auth__copy {
  margin: 4px 0 20px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-muted);
  letter-spacing: 0.02em;
  line-height: 1.55;
}

.auth__form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth__field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.auth__field span {
  font-family: var(--font-mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--ink-dim);
}

.auth__field input {
  width: 100%;
  background: var(--bg-deep);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 14px;
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.08em;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.auth__field input:focus {
  outline: none;
  border-color: var(--copper);
  box-shadow: 0 0 0 3px rgba(212, 160, 90, 0.12);
}

.auth__submit {
  margin-top: 4px;
}

/* ---------- history ---------- */

.history {
  position: relative;
  z-index: 2;
  padding: 8px 40px 64px;
  max-width: 1480px;
  margin: 0 auto;
}

@media (max-width: 960px) {
  .history { padding: 8px 20px 48px; }
}

.history__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 16px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.history__head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-variation-settings: 'opsz' 72, 'SOFT' 40, 'WONK' 0;
  font-weight: 500;
  font-size: 28px;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.history__count {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.history__empty {
  margin: 0;
  font-family: var(--font-display);
  font-style: italic;
  font-variation-settings: 'opsz' 60, 'SOFT' 60;
  font-size: 18px;
  color: var(--ink-muted);
  text-align: center;
  padding: 40px 0;
}

.history__grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.history__grid:empty { display: none; }

.history-card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--bg-deep);
  cursor: pointer;
  transition: border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
  display: flex;
  flex-direction: column;
}

.history-card:hover {
  border-color: var(--copper);
  transform: translateY(-2px);
  box-shadow: 0 18px 36px -24px rgba(212, 160, 90, 0.35);
}

.history-card img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  display: block;
  background: #000;
}

.history-card__body {
  padding: 12px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.history-card__size {
  align-self: flex-start;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--copper);
  border: 1px solid rgba(212, 160, 90, 0.4);
  border-radius: 2px;
  padding: 2px 6px;
}

.history-card__prompt {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--ink-dim);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.history-card__time {
  margin-top: auto;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.history-card__delete {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 0;
  background: rgba(7, 11, 9, 0.8);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease, background 0.15s ease, color 0.15s ease;
}

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

.history-card__delete:hover {
  background: var(--rust);
  color: var(--bg-deep);
}
