:root {
  --bg: #fbfbfc;
  --surface: #ffffff;
  --surface-soft: #f4f6f9;
  --text: #16181d;
  --muted: #6d7480;
  --line: #e1e5ec;
  --strong-line: #cfd6e1;
  --primary: #111827;
  --primary-hover: #2b3444;
  --accent: #2f6df6;
  --danger: #b42318;
  --shadow: 0 20px 60px rgba(25, 31, 45, .10);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
}

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

button {
  cursor: pointer;
}

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

:focus-visible {
  outline: 3px solid rgba(47, 109, 246, .28);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  min-height: 100dvh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: rgba(251, 251, 252, .86);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(225, 229, 236, .72);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 650;
}

.brand-mark {
  width: 24px;
  height: 24px;
  border-radius: 7px;
  background: linear-gradient(135deg, #111827, #6287ff);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .35);
}

.top-actions {
  display: flex;
  gap: 8px;
}

.icon-button {
  width: 44px;
  height: 44px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
}

.icon-button svg,
.tool-button svg,
.generate-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.workspace {
  width: min(100%, 980px);
  margin: 0 auto;
  padding: 22dvh 20px 72px;
}

.hero {
  text-align: center;
}

.hero h1 {
  margin: 0 0 26px;
  font-size: clamp(24px, 5vw, 34px);
  line-height: 1.15;
  letter-spacing: 0;
}

.composer {
  width: min(100%, 720px);
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--strong-line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  overflow: hidden;
  text-align: left;
}

.composer textarea {
  display: block;
  width: 100%;
  min-height: 92px;
  max-height: 220px;
  resize: vertical;
  border: 0;
  padding: 18px 18px 8px;
  color: var(--text);
  background: transparent;
  line-height: 1.55;
}

.composer textarea::placeholder {
  color: #9299a4;
}

.reference-strip {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 0 14px;
}

.reference-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-soft);
  font-size: 13px;
  color: var(--muted);
}

.reference-chip img {
  width: 24px;
  height: 24px;
  border-radius: 999px;
  object-fit: cover;
}

.composer-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px 14px;
}

#referenceInput {
  display: none;
}

.tool-button,
.text-button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  padding: 0 12px;
}

.tool-button:hover,
.text-button:hover {
  background: var(--surface-soft);
  color: var(--text);
}

.toolbar-spacer {
  flex: 1;
}

.model-chip {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 13px;
}

.generate-button,
.primary-button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  padding: 0 18px;
  font-weight: 650;
}

.generate-button:hover,
.primary-button:hover {
  background: var(--primary-hover);
}

.status-line {
  min-height: 24px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 14px;
}

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

.inspiration,
.results-section {
  margin-top: 34px;
}

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

.section-heading h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
}

.inspiration-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
}

.inspiration-card,
.result-card,
.history-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.inspiration-card {
  min-height: 148px;
  position: relative;
  overflow: hidden;
  padding: 0;
  text-align: left;
}

.inspiration-card img,
.inspiration-preview {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 5;
  object-fit: cover;
  background: linear-gradient(135deg, #dfe8ff, #ffe0cf);
}

.inspiration-title {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  text-shadow: 0 1px 6px rgba(0, 0, 0, .55);
}

.empty-state {
  min-height: 180px;
  display: grid;
  place-items: center;
  color: var(--muted);
  border: 1px dashed var(--strong-line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .52);
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.result-card {
  overflow: hidden;
}

.result-card img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: var(--surface-soft);
}

.result-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
}

.download-link {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  color: var(--text);
  text-decoration: none;
  font-weight: 650;
}

.drawer {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  justify-content: flex-end;
  background: rgba(17, 24, 39, .36);
}

.drawer.open {
  display: flex;
}

.drawer-panel {
  width: min(100%, 380px);
  min-height: 100dvh;
  padding: 22px;
  overflow-y: auto;
  background: var(--surface);
  box-shadow: -18px 0 44px rgba(17, 24, 39, .18);
}

.drawer-panel.wide {
  width: min(100%, 560px);
}

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

.drawer-header h2 {
  margin: 0;
  font-size: 20px;
}

.field-group {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.field-group label,
.invite-panel label {
  font-weight: 650;
  font-size: 14px;
}

.field-group select,
.field-group input,
.invite-panel input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--strong-line);
  border-radius: var(--radius);
  padding: 0 12px;
  background: var(--surface);
  color: var(--text);
}

.helper-text {
  margin: 18px 0 0;
  color: var(--muted);
  line-height: 1.6;
  font-size: 14px;
}

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

.history-item {
  padding: 12px;
}

.history-item p {
  margin: 0 0 10px;
  color: var(--text);
  line-height: 1.45;
}

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

.history-images {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.history-images img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 6px;
  background: var(--surface-soft);
}

.invite-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(251, 251, 252, .92);
  backdrop-filter: blur(14px);
}

.invite-modal.hidden {
  display: none;
}

.invite-panel {
  width: min(100%, 390px);
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.invite-panel h2 {
  margin: 0 0 8px;
}

.invite-panel p {
  color: var(--muted);
  line-height: 1.55;
}

.invite-panel input {
  margin: 8px 0 14px;
}

.primary-button {
  width: 100%;
}

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

@media (max-width: 760px) {
  .topbar {
    padding: 0 14px;
  }

  .workspace {
    padding: 16dvh 14px 44px;
  }

  .composer {
    border-radius: 18px;
  }

  .composer-toolbar {
    flex-wrap: wrap;
  }

  .toolbar-spacer {
    flex-basis: 100%;
    height: 0;
  }

  .model-chip {
    order: 5;
  }

  .generate-button {
    order: 6;
    flex: 1;
  }

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

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