:root {
  --background: #faf5ff;
  --surface: #ffffff;
  --surface-soft: #f7f3fd;
  --foreground: #0f172a;
  --muted: #64748b;
  --muted-light: #94a3b8;
  --border: #efe7fc;
  --primary: #7c3aed;
  --primary-dark: #6d28d9;
  --accent: #ec4899;
  --accent-soft: #fdf2f8;
  --warning-bg: #fff7ed;
  --warning-border: #fed7aa;
  --warning-text: #9a3412;
  --shadow-sm: 0 4px 12px rgba(76, 29, 149, .06);
  --shadow-md: 0 12px 30px rgba(76, 29, 149, .09);
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 12px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--background);
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  margin: 0;
  background:
    radial-gradient(circle at 88% 3%, rgba(236, 72, 153, .10), transparent 26rem),
    var(--background);
  color: var(--foreground);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

button,
textarea,
input {
  font: inherit;
}

button,
a,
label {
  -webkit-tap-highlight-color: transparent;
}

button,
a,
label,
.upload-box,
.inspiration-image-wrap,
.work-image-wrap {
  touch-action: manipulation;
}

button,
a,
label {
  cursor: pointer;
}

button:focus-visible,
a:focus-visible,
textarea:focus-visible,
input:focus-visible,
.upload-box:focus-within {
  outline: 3px solid rgba(124, 58, 237, .28);
  outline-offset: 3px;
}

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

.topbar,
.brand,
.section-head,
.upload-actions,
.result-actions,
.tone-row,
.tab-row,
.setting-row,
.profile-card,
.work-actions {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  margin-bottom: 42px;
}

.brand {
  gap: 10px;
  color: var(--foreground);
  text-decoration: none;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  box-shadow: 0 7px 18px rgba(124, 58, 237, .18);
}

.brand-name {
  font-size: 20px;
  font-weight: 750;
  letter-spacing: .2px;
}

.top-link,
.text-button {
  min-width: 76px;
  min-height: 44px;
  padding: 8px 14px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--primary);
  font-size: 14px;
  font-weight: 700;
}

.top-link:hover,
.text-button:hover {
  background: #f3e8ff;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
  animation: view-enter 240ms ease-out both;
}

.hero-copy {
  max-width: 680px;
  margin-bottom: 30px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--primary);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  max-width: 700px;
  margin-bottom: 12px;
  font-size: clamp(34px, 6vw, 58px);
  font-weight: 800;
  letter-spacing: -.055em;
  line-height: 1.08;
}

h2 {
  margin-bottom: 0;
  font-size: 20px;
  letter-spacing: -.025em;
  line-height: 1.2;
}

.subtle {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.6;
}

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

.editor-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, .95fr);
  gap: 18px;
}

.editor-card {
  padding: clamp(18px, 3vw, 28px);
}

.compact-head {
  margin-bottom: 20px;
}

.section-head {
  justify-content: space-between;
  gap: 16px;
}

.section-count,
.field-helper,
.safety-note,
.result-tip {
  color: var(--muted-light);
  font-size: 12px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #f3e8ff;
  color: var(--primary-dark);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.status-pill.accent {
  background: var(--accent-soft);
  color: #be185d;
}

.upload-box {
  position: relative;
  display: flex;
  min-height: 360px;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 1.5px dashed #c4b5fd;
  border-radius: 18px;
  background: linear-gradient(145deg, #faf5ff, #fff7fb);
  transition: border-color 180ms ease, background 180ms ease;
}

.upload-box:hover,
.upload-box:focus-within {
  border-color: var(--primary);
  background: #f8f4ff;
}

.upload-empty {
  display: flex;
  align-items: center;
  flex-direction: column;
  gap: 7px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.upload-empty strong {
  color: var(--foreground);
  font-size: 17px;
}

.upload-empty span:last-child {
  max-width: 230px;
  font-size: 12px;
  line-height: 1.5;
}

.upload-icon {
  position: relative;
  display: block;
  width: 58px;
  height: 58px;
  margin-bottom: 5px;
  border-radius: 19px;
  background: #ede9fe;
}

.upload-icon::before,
.upload-icon::after {
  position: absolute;
  display: block;
  content: "";
  border-radius: 4px;
  background: var(--primary);
}

.upload-icon::before {
  top: 27px;
  left: 15px;
  width: 28px;
  height: 4px;
}

.upload-icon::after {
  top: 15px;
  left: 27px;
  width: 4px;
  height: 28px;
}

.source-image {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 360px;
  object-fit: cover;
}

.replace-badge {
  position: absolute;
  right: 14px;
  bottom: 14px;
  min-height: 36px;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(15, 23, 42, .78);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

.upload-actions {
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.upload-action {
  display: inline-flex;
  flex: 1 1 136px;
}

.field-helper {
  margin: 10px 2px 0;
  line-height: 1.5;
}

.field-label {
  display: block;
  margin-bottom: 9px;
  color: #334155;
  font-size: 13px;
  font-weight: 750;
}

.caption-input {
  display: block;
  width: 100%;
  min-height: 74px;
  resize: vertical;
  padding: 13px 14px;
  border: 1px solid #e2e8f0;
  border-radius: 13px;
  background: #fff;
  color: var(--foreground);
  font-size: 16px;
  line-height: 1.55;
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

.caption-input::placeholder {
  color: #a1aabd;
}

.caption-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(124, 58, 237, .11);
  outline: 0;
}

.suggestion-label {
  margin-top: 20px;
}

.suggestion-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 40px;
}

.suggestion,
.tone-chip {
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid transparent;
  border-radius: 11px;
  background: var(--accent-soft);
  color: #be185d;
  font-size: 12px;
  font-weight: 650;
  transition: background 180ms ease, border-color 180ms ease, color 180ms ease;
}

.suggestion:hover {
  border-color: #f9a8d4;
}

.tone-label {
  margin-top: 20px;
}

.tone-row {
  flex-wrap: wrap;
  gap: 8px;
}

.tone-chip {
  flex: 1 1 70px;
  border-color: #e2e8f0;
  background: #fff;
  color: var(--muted);
  text-align: center;
}

.tone-chip:hover,
.tone-chip.is-selected {
  border-color: var(--primary);
  background: #f3e8ff;
  color: var(--primary-dark);
}

.consent-row {
  display: flex;
  min-height: 48px;
  align-items: center;
  gap: 9px;
  margin: 16px 0 12px;
  color: var(--muted);
  font-size: 12px;
}

.consent-row input {
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--primary);
}

.primary-button,
.secondary-button {
  display: inline-flex;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 750;
  text-decoration: none;
  transition: opacity 180ms ease, background 180ms ease, border-color 180ms ease;
}

.primary-button {
  width: 100%;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  box-shadow: 0 8px 16px rgba(236, 72, 153, .18);
}

.primary-button:hover {
  background: #db2777;
}

.primary-button:disabled,
.secondary-button:disabled {
  cursor: wait;
  opacity: .62;
}

.secondary-button {
  border: 1px solid #c4b5fd;
  background: #fff;
  color: var(--primary-dark);
}

.secondary-button:hover {
  border-color: var(--primary);
  background: #faf5ff;
}

.safety-note {
  margin: 10px 0 0;
  text-align: center;
}

.result-section {
  margin-top: 46px;
}

.result-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(280px, .9fr);
  align-items: start;
  gap: 18px;
}

.result-card {
  padding: 10px;
}

#meme-canvas {
  display: block;
  width: 100%;
  height: auto;
  max-height: 680px;
  border-radius: 17px;
  background: #f1f5f9;
}

.result-copy {
  padding: 18px 2px;
}

.inline-status,
.analysis-summary,
.analysis-error {
  border-radius: 13px;
}

.inline-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 13px;
  background: #f3e8ff;
  color: var(--primary-dark);
  font-size: 13px;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(124, 58, 237, .22);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

.analysis-summary {
  padding: 12px 14px;
  background: #f8fafc;
  color: #475569;
  font-size: 13px;
  line-height: 1.55;
}

.analysis-error {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 12px 13px;
  border: 1px solid var(--warning-border);
  background: var(--warning-bg);
}

.analysis-error p {
  margin: 0;
  color: var(--warning-text);
  font-size: 12px;
  line-height: 1.5;
}

.analysis-error .secondary-button {
  min-height: 40px;
  padding: 8px 12px;
  border-color: #fdba74;
  color: #c2410c;
  font-size: 12px;
}

.result-tip {
  margin: 16px 0 18px;
  line-height: 1.6;
}

.result-actions {
  gap: 10px;
}

.result-actions .primary-button,
.result-actions .secondary-button {
  flex: 1;
  width: auto;
}

.page-heading {
  margin-bottom: 26px;
}

.page-heading h1 {
  margin-bottom: 10px;
  font-size: clamp(36px, 7vw, 54px);
}

.tab-row {
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}

.tab-chip {
  min-height: 42px;
  padding: 9px 14px;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  transition: background 180ms ease, border-color 180ms ease, color 180ms ease;
}

.tab-chip:hover,
.tab-chip.is-selected {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.inspiration-grid,
.works-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: start;
  gap: 14px;
}

.inspiration-card,
.work-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: #fff;
  box-shadow: var(--shadow-sm);
}

.inspiration-card {
  transition: box-shadow 180ms ease, transform 180ms ease;
}

.inspiration-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.inspiration-image-wrap,
.work-image-wrap {
  position: relative;
  overflow: hidden;
  background: #f1f5f9;
}

.inspiration-image,
.work-image {
  display: block;
  width: 100%;
  height: 220px;
  object-fit: cover;
}

.inspiration-body,
.work-body {
  padding: 14px;
}

.phrase,
.expression,
.scene,
.work-caption,
.work-time {
  display: block;
}

.phrase,
.work-caption {
  overflow: hidden;
  color: var(--foreground);
  font-size: 15px;
  font-weight: 750;
  line-height: 1.35;
  text-overflow: ellipsis;
}

.phrase {
  white-space: nowrap;
}

.expression,
.scene,
.work-time {
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.scene,
.work-time {
  color: #8b5cf6;
  font-size: 11px;
}

.use-button {
  width: 100%;
  min-height: 42px;
  margin-top: 13px;
  padding: 8px 12px;
  border: 0;
  border-radius: 11px;
  background: #f3e8ff;
  color: var(--primary-dark);
  font-size: 13px;
  font-weight: 750;
}

.use-button:hover {
  background: #e9d5ff;
}

.work-actions {
  justify-content: space-between;
  gap: 8px;
  margin-top: 12px;
}

.work-actions .secondary-button {
  min-height: 40px;
  padding: 8px 10px;
  font-size: 12px;
}

.delete-button {
  min-width: 52px;
  min-height: 40px;
  padding: 8px;
  border: 0;
  background: transparent;
  color: var(--muted-light);
  font-size: 12px;
}

.delete-button:hover {
  color: #b91c1c;
}

.empty {
  grid-column: 1 / -1;
  padding: 54px 24px;
  border: 1px dashed #c4b5fd;
  border-radius: 18px;
  background: rgba(255, 255, 255, .72);
  color: var(--muted);
  text-align: center;
}

.empty-mark {
  width: 58px;
  height: 58px;
  margin: 0 auto 15px;
  border-radius: 19px;
  background: #f3e8ff;
}

.empty-title {
  margin-bottom: 6px;
  color: var(--foreground);
  font-size: 18px;
  font-weight: 750;
}

.profile-card {
  gap: 14px;
  padding: 22px;
}

.profile-avatar {
  display: grid;
  width: 58px;
  height: 58px;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 19px;
  background: var(--primary);
  color: #fff;
  font-size: 21px;
  font-weight: 800;
}

.profile-card h2 {
  margin-bottom: 5px;
}

.setting-list {
  margin-top: 16px;
  padding: 0 18px;
}

.setting-row {
  width: 100%;
  justify-content: space-between;
  gap: 12px;
  min-height: 58px;
  padding: 8px 0;
  border: 0;
  border-bottom: 1px solid #f1f5f9;
  background: transparent;
  color: #334155;
  text-align: left;
  font-size: 14px;
}

.setting-row:last-child {
  border-bottom: 0;
}

.row-value,
.row-arrow {
  color: var(--muted-light);
  font-size: 13px;
}

.row-arrow {
  font-size: 24px;
  line-height: 1;
}

.danger-row {
  color: #b91c1c;
}

.bottom-nav {
  position: fixed;
  z-index: 20;
  right: 18px;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: 18px;
  display: flex;
  max-width: 740px;
  min-height: 68px;
  margin: 0 auto;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: rgba(255, 255, 255, .95);
  box-shadow: 0 15px 34px rgba(76, 29, 149, .16);
  backdrop-filter: blur(12px);
}

.nav-item {
  display: flex;
  min-width: 64px;
  min-height: 50px;
  flex: 1;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 4px;
  border: 0;
  border-radius: 16px;
  background: transparent;
  color: var(--muted-light);
  font-size: 11px;
  transition: background 180ms ease, color 180ms ease;
}

.nav-item:hover,
.nav-item.is-active {
  background: #f3e8ff;
  color: var(--primary);
  font-weight: 750;
}

.nav-icon {
  position: relative;
  display: block;
  width: 20px;
  height: 20px;
}

.nav-icon::before,
.nav-icon::after {
  position: absolute;
  display: block;
  content: "";
}

.icon-create::before {
  top: 8px;
  left: 2px;
  width: 16px;
  height: 4px;
  border-radius: 3px;
  background: currentColor;
}

.icon-create::after {
  top: 2px;
  left: 8px;
  width: 4px;
  height: 16px;
  border-radius: 3px;
  background: currentColor;
}

.icon-works::before {
  top: 2px;
  left: 3px;
  width: 14px;
  height: 15px;
  border: 2px solid currentColor;
  border-radius: 4px;
}

.icon-works::after {
  top: 6px;
  left: 6px;
  width: 8px;
  height: 2px;
  background: currentColor;
  box-shadow: 0 4px 0 currentColor;
}

.icon-inspiration::before {
  top: 2px;
  left: 3px;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-radius: 50%;
}

.icon-inspiration::after {
  top: 8px;
  left: 8px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
}

.icon-profile::before {
  top: 2px;
  left: 6px;
  width: 8px;
  height: 8px;
  border: 2px solid currentColor;
  border-radius: 50%;
}

.icon-profile::after {
  bottom: 2px;
  left: 3px;
  width: 14px;
  height: 8px;
  border: 2px solid currentColor;
  border-radius: 10px 10px 5px 5px;
}

.toast {
  position: fixed;
  z-index: 40;
  right: 50%;
  bottom: calc(100px + env(safe-area-inset-bottom));
  max-width: min(90vw, 420px);
  padding: 11px 15px;
  border-radius: 12px;
  background: rgba(15, 23, 42, .9);
  color: #fff;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transform: translate(50%, 10px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(50%, 0);
}

.preview-dialog {
  width: min(92vw, 720px);
  padding: 12px;
  border: 0;
  border-radius: 20px;
  background: #0f172a;
  box-shadow: 0 20px 60px rgba(15, 23, 42, .36);
}

.preview-dialog::backdrop {
  background: rgba(15, 23, 42, .6);
}

.preview-dialog img {
  display: block;
  width: 100%;
  max-height: 80vh;
  border-radius: 12px;
  object-fit: contain;
}

.dialog-close {
  display: grid;
  width: 44px;
  height: 44px;
  margin-left: auto;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .12);
  color: #fff;
  font-size: 26px;
  line-height: 1;
}

.dialog-close:hover {
  background: rgba(255, 255, 255, .22);
}

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

.is-hidden {
  display: none !important;
}

@keyframes view-enter {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

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

@media (max-width: 860px) {
  .editor-layout,
  .result-layout {
    grid-template-columns: 1fr;
  }

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

  .inspiration-image,
  .work-image {
    height: 200px;
  }
}

@media (max-width: 620px) {
  .app-shell {
    padding-right: 16px;
    padding-left: 16px;
  }

  .topbar {
    margin-bottom: 32px;
  }

  h1 {
    font-size: 37px;
  }

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

  .upload-box,
  .source-image {
    min-height: 290px;
  }

  .inspiration-image,
  .work-image {
    height: 160px;
  }

  .inspiration-body,
  .work-body {
    padding: 11px;
  }

  .inspiration-card .phrase,
  .work-caption {
    font-size: 13px;
  }

  .bottom-nav {
    right: 10px;
    left: 10px;
  }
}

@media (max-width: 390px) {
  .status-pill {
    display: none;
  }

  .result-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .result-actions .primary-button,
  .result-actions .secondary-button {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
