 :root {
  --bg: #f4e9f7;
  --ink: #25142c;
  --muted: #76617d;
  --panel: rgba(255, 252, 255, 0.86);
  --panel-strong: rgba(255, 255, 255, 0.96);
  --line: rgba(83, 42, 96, 0.13);
  --brand: #7d3b8e;
  --brand-deep: #4f225c;
  --pink: #e86fc3;
  --mint: #36c8b2;
  --gold: #ffc857;
  --shadow: 0 18px 44px rgba(58, 24, 72, 0.18);
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(145deg, rgba(255,255,255,.82), rgba(244,233,247,.82)),
    radial-gradient(circle at 16% 8%, rgba(54,200,178,.22), transparent 30%),
    radial-gradient(circle at 82% 4%, rgba(232,111,195,.24), transparent 24%),
    var(--bg);
}

a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }

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

.screen { display: none; animation: fadeUp .18s ease both; }
.screen.active { display: block; }

@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.top-hero,
.hero-card,
.section-block,
.quest-card,
.level-card,
.profile-card,
.history-card,
.pack-list article,
.quest-item {
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.top-hero {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
}

.brand-row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-row img, .profile-card img { width: 46px; height: 46px; border-radius: 16px; box-shadow: 0 10px 24px rgba(125,59,142,.2); }
.brand-row strong, .brand-row span { display: block; }
.brand-row strong { font-size: 17px; }
.brand-row span, p, small { color: var(--muted); line-height: 1.45; }

.ghost-link, .text-button, .pack-list a, .quest-item a {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(125,59,142,.16);
  border-radius: 999px;
  padding: 0 13px;
  background: rgba(255,255,255,.66);
  color: var(--brand-deep);
  font-size: 13px;
  font-weight: 900;
}

.hero-card {
  min-height: 340px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 156px;
  gap: 14px;
  margin-top: 12px;
  padding: 20px;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(255,255,255,.95), rgba(252,239,255,.78)),
    linear-gradient(135deg, rgba(125,59,142,.16), rgba(54,200,178,.1));
}

.kicker {
  display: inline-flex;
  width: fit-content;
  margin-bottom: 8px;
  color: var(--brand);
  font-size: 11px;
  font-weight: 950;
  letter-spacing: .08em;
  text-transform: uppercase;
}

h1, h2, p { margin: 0; }
h1 { font-size: 30px; line-height: 1.04; letter-spacing: 0; }
h2 { font-size: 22px; line-height: 1.08; letter-spacing: 0; }
.hero-copy p { margin-top: 12px; font-size: 15px; }

.hero-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.primary-action, .secondary-action {
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 16px;
  padding: 0 15px;
  font-weight: 950;
}
.primary-action { color: #fff; background: linear-gradient(135deg, var(--brand), var(--pink)); box-shadow: 0 14px 28px rgba(125,59,142,.28); }
.secondary-action { color: var(--brand-deep); background: rgba(255,255,255,.82); border: 1px solid var(--line); }

.hero-stack { position: relative; min-height: 292px; align-self: center; }
.hero-stack img {
  position: absolute;
  width: 124px;
  height: 166px;
  object-fit: cover;
  border-radius: 22px;
  border: 3px solid rgba(255,255,255,.76);
  box-shadow: 0 18px 34px rgba(39,20,47,.2);
}
.hero-stack img:nth-child(1) { top: 0; right: 12px; transform: rotate(7deg); }
.hero-stack img:nth-child(2) { top: 76px; right: -2px; transform: rotate(-8deg); }
.hero-stack img:nth-child(3) { top: 142px; right: 24px; transform: rotate(5deg); }

.section-block, .quest-card, .level-card, .profile-card, .history-card { margin-top: 12px; padding: 16px; }
.section-title, .plain-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.section-title.tight { margin-bottom: 12px; }

.effect-row {
  display: grid;
  grid-template-columns: 1.1fr .9fr;
  gap: 10px;
  margin-top: 12px;
}
.effect-card {
  min-height: 150px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 12px;
  border: 0;
  border-radius: 22px;
  color: #fff;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(0,0,0,.02), rgba(0,0,0,.68)), var(--image) center/cover;
  text-align: left;
  font: inherit;
  cursor: pointer;
}
.effect-card.wide { grid-row: span 2; min-height: 310px; }
.effect-card span { align-self: flex-end; padding: 5px 8px; border-radius: 999px; background: var(--pink); font-size: 11px; font-weight: 950; }
.effect-card strong { font-size: 16px; text-shadow: 0 2px 12px rgba(0,0,0,.45); }

.quest-card { display: grid; grid-template-columns: 1fr; gap: 14px; background: linear-gradient(135deg, rgba(255,255,255,.9), rgba(217,247,242,.82)); }
.quest-list { display: grid; gap: 10px; }
.quest-list.compact div { min-height: 40px; display: flex; align-items: center; gap: 10px; padding: 0 12px; border-radius: 14px; background: rgba(255,255,255,.7); font-weight: 850; }
.quest-list span, .quest-item > span { width: 12px; height: 12px; border-radius: 50%; background: var(--mint); box-shadow: 0 0 0 5px rgba(54,200,178,.14); flex: 0 0 auto; }

.plain-head { min-height: 56px; padding: 4px 2px 10px; }
.plain-head h1 { font-size: 21px; text-align: center; }
.back-button, .refresh-button { width: 42px; height: 42px; border: 0; border-radius: 15px; background: rgba(255,255,255,.74); font-size: 22px; font-weight: 900; }
.pill { min-height: 34px; display: inline-flex; align-items: center; border-radius: 999px; padding: 0 12px; background: rgba(125,59,142,.1); color: var(--brand-deep); font-size: 12px; font-weight: 950; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { min-height: 40px; border: 0; border-radius: 999px; padding: 0 15px; background: rgba(255,255,255,.72); color: var(--brand-deep); font-weight: 900; white-space: nowrap; }
.chip.active { color: #fff; background: var(--brand); }

.trend-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.trend-card {
  min-height: 230px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  border-radius: 24px;
  overflow: hidden;
  color: #fff;
  background: linear-gradient(180deg, rgba(0,0,0,0), rgba(0,0,0,.72)), var(--image) center/cover;
  box-shadow: 0 16px 28px rgba(41,20,48,.16);
}
.trend-card.no-image,
.effect-card.no-image {
  background:
    linear-gradient(180deg, rgba(37,20,44,.04), rgba(37,20,44,.72)),
    radial-gradient(circle at 75% 14%, rgba(255,200,87,.36), transparent 24%),
    radial-gradient(circle at 22% 18%, rgba(54,200,178,.32), transparent 28%),
    var(--image) center 38% / 48% no-repeat,
    linear-gradient(145deg, rgba(125,59,142,.92), rgba(232,111,195,.76));
}
.trend-card.no-image::before { content: none; }
.trend-card-content { padding: 12px; }
.trend-card .tag { width: fit-content; padding: 5px 8px; border-radius: 999px; background: var(--gold); color: #3b2541; font-size: 11px; font-weight: 950; margin-bottom: 8px; }
.trend-card strong { display: block; font-size: 16px; line-height: 1.15; }
.trend-card small { display: block; margin-top: 4px; color: rgba(255,255,255,.78); }
.trend-card em { display: inline-flex; width: fit-content; margin-top: 9px; padding: 4px 8px; border-radius: 999px; background: rgba(255,255,255,.18); color: #fff; font-size: 11px; font-style: normal; font-weight: 950; }
.empty-state { grid-column: 1 / -1; min-height: 150px; display: grid; place-items: center; padding: 18px; border: 1px dashed rgba(125,59,142,.28); border-radius: 22px; background: rgba(255,255,255,.65); color: var(--muted); text-align: center; font-weight: 800; line-height: 1.45; }

.level-card { display: grid; grid-template-columns: 96px 1fr; gap: 14px; align-items: center; background: linear-gradient(135deg, rgba(255,255,255,.9), rgba(252,240,255,.9)); }
.level-ring { width: 88px; height: 88px; display: grid; place-items: center; border-radius: 50%; color: #fff; background: conic-gradient(var(--mint) var(--progress, 0%), rgba(125,59,142,.16) 0), var(--brand); font-weight: 950; box-shadow: inset 0 0 0 11px rgba(255,255,255,.78); }
.quest-item { min-height: 76px; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; padding: 12px; }
.quest-item.done { opacity: .74; }
.quest-list.compact .done span, .quest-item.done > span { background: var(--gold); box-shadow: 0 0 0 5px rgba(255,200,87,.18); }
.quest-item strong, .quest-item small { display: block; }

.profile-card { display: flex; align-items: center; gap: 14px; }
.profile-card img { width: 70px; height: 70px; border-radius: 24px; }
.pack-list { display: grid; gap: 10px; margin-top: 12px; }
.pack-list article { min-height: 72px; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px 10px; padding: 13px; }
.pack-list span { color: var(--muted); font-size: 13px; }
.pack-list a { grid-row: span 2; background: linear-gradient(135deg, rgba(125,59,142,.12), rgba(54,200,178,.16)); }
.history-row { min-height: 46px; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; border-top: 1px solid var(--line); }
.history-row:first-of-type { border-top: 0; }

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: max(10px, env(safe-area-inset-bottom));
  z-index: 20;
  width: min(430px, calc(100% - 22px));
  min-height: 70px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 7px;
  transform: translateX(-50%);
  border: 1px solid rgba(83,42,96,.16);
  border-radius: 26px;
  background: rgba(255,255,255,.78);
  box-shadow: 0 22px 44px rgba(39,20,47,.2);
  backdrop-filter: blur(18px);
}
.bottom-nav button { display: grid; place-items: center; gap: 4px; border: 0; border-radius: 20px; background: transparent; color: var(--muted); font-size: 11px; font-weight: 950; }
.bottom-nav button.active { color: #fff; background: var(--brand-deep); }
.nav-icon {
  width: 22px;
  height: 22px;
  display: block;
  background: currentColor;
  opacity: .95;
}
.home-icon { clip-path: polygon(50% 8%, 90% 42%, 80% 42%, 80% 88%, 58% 88%, 58% 62%, 42% 62%, 42% 88%, 20% 88%, 20% 42%, 10% 42%); }
.trends-icon { clip-path: polygon(48% 4%, 64% 24%, 58% 43%, 78% 35%, 91% 52%, 86% 75%, 68% 94%, 40% 96%, 18% 82%, 9% 61%, 17% 38%, 35% 48%, 31% 25%); }
.custom-icon { clip-path: polygon(50% 4%, 59% 35%, 92% 42%, 64% 59%, 71% 92%, 50% 72%, 29% 92%, 36% 59%, 8% 42%, 41% 35%); }
.profile-icon { clip-path: circle(22% at 50% 28%); position: relative; }
.profile-icon::after { content: ""; position: absolute; left: 2px; right: 2px; bottom: 1px; height: 11px; border-radius: 999px 999px 6px 6px; background: currentColor; }

@media (max-width: 380px) {
  .hero-card { grid-template-columns: 1fr; }
  .hero-stack { min-height: 178px; margin-top: 8px; }
  .hero-stack img { width: 116px; height: 150px; }
  .hero-stack img:nth-child(1) { top: 0; right: 152px; }
  .hero-stack img:nth-child(2) { top: 14px; right: 74px; }
  .hero-stack img:nth-child(3) { top: 26px; right: 0; }
  h1 { font-size: 29px; }
  .trend-card { min-height: 205px; }
}

.demo-mode .top-hero::after { display: none; content: none; }
.api-error .top-hero { border-color: rgba(255, 92, 92, .28); }

@media (min-width: 900px) {
  body {
    display: grid;
    justify-items: center;
  }

  .app-shell {
    margin: 0;
  }
}


.trend-card { border: 0; text-align: left; font: inherit; cursor: pointer; }
.detail-card,
.upload-card,
.result-card {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
  backdrop-filter: blur(16px);
}
.detail-cover {
  min-height: 285px;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 14px;
  background: linear-gradient(180deg, rgba(0,0,0,0), rgba(0,0,0,.35)), var(--image) center/cover;
}
.detail-cover.no-image {
  background:
    linear-gradient(180deg, rgba(37,20,44,.02), rgba(37,20,44,.42)),
    radial-gradient(circle at 78% 18%, rgba(255,200,87,.42), transparent 24%),
    radial-gradient(circle at 22% 20%, rgba(54,200,178,.36), transparent 28%),
    var(--image) center / 38% no-repeat,
    linear-gradient(145deg, rgba(125,59,142,.92), rgba(232,111,195,.76));
}
.detail-cover span {
  padding: 7px 10px;
  border-radius: 999px;
  color: #3b2541;
  background: var(--gold);
  font-size: 11px;
  font-weight: 950;
}
.detail-copy { padding: 16px; }
.detail-copy p { margin-top: 8px; }
.upload-card { padding: 14px; }
.custom-card {
  margin-top: 12px;
  display: grid;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}
.custom-card p { margin-top: 8px; }
.prompt-box {
  display: grid;
  gap: 8px;
  padding: 12px;
  border-radius: 20px;
  background: rgba(255,255,255,.72);
  border: 1px solid rgba(125,59,142,.13);
}
.prompt-box span { color: var(--brand-deep); font-weight: 950; }
.prompt-box textarea {
  width: 100%;
  min-height: 132px;
  resize: vertical;
  border: 0;
  outline: 0;
  border-radius: 16px;
  padding: 12px;
  color: var(--ink);
  background: rgba(125,59,142,.07);
  font: inherit;
  line-height: 1.4;
}
.prompt-box textarea::placeholder { color: rgba(118,97,125,.75); }
.upload-zone {
  min-height: 130px;
  display: grid;
  grid-template-columns: 74px 1fr;
  gap: 6px 14px;
  align-items: center;
  padding: 14px;
  border: 1px dashed rgba(125,59,142,.35);
  border-radius: 20px;
  background: rgba(255,255,255,.72);
  cursor: pointer;
}
.upload-zone.compact { min-height: 108px; }
.upload-zone.compact .upload-plus { height: 74px; }
.upload-zone input { display: none; }
.upload-plus {
  grid-row: span 2;
  width: 74px;
  height: 90px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  color: var(--brand);
  background: rgba(125,59,142,.08);
  font-size: 38px;
  font-weight: 400;
}
.upload-zone strong { font-size: 17px; }
.upload-zone small { align-self: start; }
.upload-preview {
  display: grid;
  gap: 10px;
}
.upload-preview img,
.result-card img {
  width: 100%;
  max-height: 520px;
  object-fit: contain;
  border-radius: 20px;
  background: rgba(255,255,255,.6);
}
.upload-preview button {
  min-height: 42px;
  border: 0;
  border-radius: 15px;
  color: var(--brand-deep);
  background: rgba(125,59,142,.1);
  font-weight: 950;
}
.generation-state {
  margin-top: 12px;
  padding: 12px;
  border-radius: 16px;
  background: rgba(255,255,255,.72);
  color: var(--muted);
  font-weight: 800;
  line-height: 1.4;
}
.generation-state.ok { color: #236b5f; background: rgba(54,200,178,.14); }
.generation-state.error { color: #8b2938; background: rgba(255,95,125,.13); }
.generation-state.loading { color: var(--brand-deep); background: rgba(125,59,142,.1); }
.generate-button {
  width: 100%;
  min-height: 58px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  border: 0;
  border-radius: 18px;
  padding: 0 16px;
  color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--pink));
  box-shadow: 0 14px 28px rgba(125,59,142,.25);
  font-weight: 950;
}
.generate-button:disabled {
  color: rgba(79,34,92,.55);
  background: rgba(125,59,142,.12);
  box-shadow: none;
}
.generate-button.loading span { animation: spin 1.2s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.generate-button em {
  min-width: 44px;
  padding: 5px 8px;
  border-radius: 999px;
  background: rgba(255,255,255,.18);
  font-size: 12px;
  font-style: normal;
}
.result-card { padding: 12px; }
.result-copy { padding: 14px 4px 4px; }
.result-copy p { margin-top: 8px; }
.result-actions {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}
.result-actions .primary-action,
.result-actions .secondary-action { width: 100%; }

@media (max-width: 380px) {
  .detail-cover { min-height: 235px; }
  .upload-zone { grid-template-columns: 62px 1fr; }
  .upload-plus { width: 62px; height: 80px; }
}
