/* Blink Mini App — тёмно-фиолетовая тема по макету */
:root {
  --bg: #0d0717;
  --bg2: #150b26;
  --card: rgba(255, 255, 255, 0.05);
  --card-hi: rgba(255, 255, 255, 0.08);
  --stroke: rgba(181, 120, 255, 0.28);
  --stroke-soft: rgba(255, 255, 255, 0.08);
  --text: #f6f1ff;
  --muted: #b9a8d9;
  --dim: #7f6fa0;
  --violet: #a855f7;
  --violet2: #7c3aed;
  --pink: #e879f9;
  --gold: #fbbf24;
  --gold2: #f59e0b;
  --green: #4ade80;
  --red: #f87171;
  --radius: 20px;
  --tabbar-h: 74px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background:
    radial-gradient(120% 60% at 100% 0%, rgba(168, 85, 247, 0.22), transparent 60%),
    radial-gradient(90% 50% at 0% 100%, rgba(124, 58, 237, 0.18), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.4;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
input, textarea { font: inherit; color: var(--text); }
a { color: var(--pink); text-decoration: none; }
.hidden { display: none !important; }
svg { width: 22px; height: 22px; flex-shrink: 0; }

#view { padding: 14px 16px calc(var(--tabbar-h) + var(--safe-b) + 18px); max-width: 560px; margin: 0 auto; }
#view.no-tabbar { padding-bottom: 16px; }

/* ---------- шапка ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.logo { display: flex; align-items: center; gap: 6px; font-weight: 800; font-style: italic; font-size: 26px; letter-spacing: -0.5px; }
.logo svg { width: 30px; height: 30px; filter: drop-shadow(0 0 10px rgba(168, 85, 247, 0.8)); }
.balance-pill {
  display: flex; align-items: center; gap: 8px; padding: 4px 4px 4px 12px; border-radius: 999px;
  background: rgba(0, 0, 0, 0.35); border: 1px solid var(--stroke-soft); font-weight: 700;
}
.balance-pill .bolt { color: var(--gold); width: 18px; height: 18px; }
.btn-gold {
  background: linear-gradient(180deg, #ffd666, var(--gold2)); color: #2a1600; font-weight: 800;
  padding: 7px 14px; border-radius: 999px; box-shadow: 0 4px 16px rgba(251, 191, 36, 0.35);
}
.greet h1 { margin: 2px 0 2px; font-size: 22px; }
.greet p { margin: 0 0 16px; color: var(--muted); font-size: 14px; }

/* ---------- карточки ---------- */
.card {
  background: var(--card); border: 1px solid var(--stroke-soft); border-radius: var(--radius);
  padding: 16px; backdrop-filter: blur(12px);
}
.hero {
  position: relative; overflow: hidden; padding: 22px 18px 18px; margin-bottom: 14px;
  border: 1.5px solid rgba(192, 132, 252, 0.55);
  background:
    radial-gradient(80% 90% at 85% 30%, rgba(232, 121, 249, 0.25), transparent 60%),
    linear-gradient(160deg, rgba(88, 28, 135, 0.55), rgba(30, 12, 60, 0.75));
  box-shadow: 0 0 40px rgba(168, 85, 247, 0.25), inset 0 0 30px rgba(168, 85, 247, 0.12);
}
.hero h2 { margin: 0; font-size: 28px; line-height: 1.08; font-weight: 800; }
.hero h2 .grad { background: linear-gradient(90deg, #f0abfc, #c084fc); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p { margin: 10px 0 16px; color: #dccdf5; font-size: 14px; max-width: 62%; }
.hero-badge {
  position: absolute; right: 14px; top: 22px; width: 104px; height: 88px; border-radius: 26px;
  display: grid; place-items: center; font-weight: 900; font-style: italic; font-size: 20px; transform: rotate(-8deg);
  background: linear-gradient(145deg, #c084fc, #7c3aed); box-shadow: 0 0 30px rgba(192, 132, 252, 0.8), inset 0 2px 8px rgba(255, 255, 255, 0.4);
}
.hero-badge::after {
  content: ""; position: absolute; left: 14px; bottom: -12px; border: 12px solid transparent;
  border-top-color: #8b45f0; border-left-color: #8b45f0; transform: rotate(10deg);
}
.btn-primary {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 14px; border-radius: 999px; font-weight: 800; font-size: 17px;
  background: linear-gradient(90deg, #9333ea, #a855f7, #c026d3);
  box-shadow: 0 6px 24px rgba(168, 85, 247, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}
.btn-primary:disabled { opacity: 0.5; }
.btn-ghost { padding: 10px 14px; border-radius: 14px; background: var(--card-hi); border: 1px solid var(--stroke-soft); font-weight: 600; }

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 18px; }
.tile {
  display: flex; flex-direction: column; justify-content: space-between; gap: 10px; min-height: 104px; text-align: left;
  padding: 12px; border-radius: 18px; background: linear-gradient(160deg, rgba(126, 34, 206, 0.3), rgba(30, 12, 60, 0.6));
  border: 1px solid var(--stroke);
}
.tile svg { width: 34px; height: 34px; color: #d8b4fe; }
.tile span { font-weight: 700; font-size: 15px; display: flex; justify-content: space-between; align-items: end; gap: 4px; }

.section-head { display: flex; justify-content: space-between; align-items: center; margin: 4px 0 10px; }
.section-head h3 { margin: 0; font-size: 18px; }
.section-head a, .section-head button { color: #d8b4fe; font-size: 14px; }

.templates { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.tpl {
  position: relative; height: 130px; border-radius: 18px; overflow: hidden; border: 1px solid var(--stroke-soft);
  background: linear-gradient(135deg, #3b0764, #1e1b4b); text-align: left;
}
.tpl img { position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%; object-fit: cover; }
.tpl .tpl-title, .tpl .tpl-price { z-index: 2; }
.tpl .tpl-title {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 26px 12px 10px; font-weight: 700;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
}
.tpl .tpl-price {
  position: absolute; right: 8px; top: 8px; padding: 3px 8px; border-radius: 999px; font-size: 12px; font-weight: 700;
  background: rgba(0, 0, 0, 0.55);
}
.tpl .tpl-emoji { position: absolute; inset: 0; display: grid; place-items: center; font-size: 46px; opacity: 0.85; }

.ref-banner {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 14px; border-radius: 18px; text-align: left;
  background: linear-gradient(90deg, rgba(126, 34, 206, 0.35), rgba(245, 158, 11, 0.18));
  border: 1px solid rgba(251, 191, 36, 0.35); font-weight: 700;
}
.ref-banner svg { color: var(--gold); width: 28px; height: 28px; }
.ref-banner .gift { margin-left: auto; font-size: 30px; }

/* ---------- нижнее меню ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: space-around; align-items: center;
  height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: rgba(13, 7, 23, 0.92); border-top: 1px solid var(--stroke-soft); backdrop-filter: blur(16px);
}
.tab { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11px; color: var(--dim); min-width: 56px; }
.tab.active { color: var(--gold); }
.tab-plus {
  width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center; margin-top: -26px;
  background: linear-gradient(145deg, #c084fc, #7c3aed); box-shadow: 0 0 24px rgba(168, 85, 247, 0.7); color: white;
}
.tab-plus svg { width: 28px; height: 28px; }

/* ---------- заголовок экранов ---------- */
.page-title { display: flex; align-items: center; gap: 10px; margin: 2px 0 14px; }
.page-title h2 { margin: 0; font-size: 22px; flex: 1; }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; background: var(--card-hi); border: 1px solid var(--stroke-soft); }

/* ---------- список чатов ---------- */
.list { display: flex; flex-direction: column; gap: 8px; }
.list-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 16px; text-align: left; width: 100%;
  background: var(--card); border: 1px solid var(--stroke-soft);
}
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .sub { color: var(--dim); font-size: 12px; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }

/* ---------- переписка ---------- */
.chat-screen { display: flex; flex-direction: column; min-height: calc(100vh - 30px); }
.chat-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.chat-head .title { flex: 1; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.model-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px; font-weight: 700; font-size: 13px;
  background: linear-gradient(90deg, rgba(147, 51, 234, 0.45), rgba(192, 38, 211, 0.35)); border: 1px solid var(--stroke);
}
.messages { flex: 1; display: flex; flex-direction: column; gap: 10px; padding-bottom: 92px; }
.msg { max-width: 88%; padding: 10px 13px; border-radius: 18px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: linear-gradient(135deg, #7c3aed, #a855f7); border-bottom-right-radius: 6px; }
.msg.assistant { align-self: flex-start; background: var(--card-hi); border: 1px solid var(--stroke-soft); border-bottom-left-radius: 6px; }
.msg pre { background: rgba(0, 0, 0, 0.45); padding: 10px; border-radius: 10px; overflow-x: auto; white-space: pre; font-size: 13px; }
.msg code { background: rgba(0, 0, 0, 0.35); padding: 1px 5px; border-radius: 6px; font-size: 13px; }
.msg .cost { display: block; margin-top: 6px; font-size: 11px; color: var(--dim); }
.typing { display: inline-flex; gap: 4px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: 0.2s; } .typing i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }
.composer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15; padding: 10px 12px calc(10px + var(--safe-b));
  background: rgba(13, 7, 23, 0.95); border-top: 1px solid var(--stroke-soft); display: flex; gap: 8px; align-items: flex-end;
}
.composer textarea {
  flex: 1; resize: none; max-height: 140px; min-height: 44px; padding: 11px 14px; border-radius: 22px;
  background: var(--card-hi); border: 1px solid var(--stroke); outline: none;
}
.send-btn { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: linear-gradient(145deg, #c084fc, #7c3aed); }
.send-btn:disabled { opacity: 0.4; }
.chat-hint { text-align: center; color: var(--dim); font-size: 12px; margin: 6px 0 12px; }

/* ---------- создание ---------- */
.segmented { display: flex; padding: 4px; border-radius: 14px; background: var(--card); border: 1px solid var(--stroke-soft); margin-bottom: 14px; }
.segmented button { flex: 1; padding: 9px; border-radius: 10px; font-weight: 700; color: var(--muted); display: flex; gap: 6px; justify-content: center; align-items: center; }
.segmented button.active { background: linear-gradient(90deg, #7c3aed, #a855f7); color: white; }
.models { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.model-opt {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; border-radius: 16px; text-align: left;
  background: var(--card); border: 1px solid var(--stroke-soft);
}
.model-opt.active { border-color: var(--violet); background: rgba(168, 85, 247, 0.16); box-shadow: 0 0 0 1px var(--violet) inset; }
.model-opt .name { font-weight: 700; }
.model-opt .note { color: var(--dim); font-size: 12px; }
.price { font-weight: 800; color: var(--gold); white-space: nowrap; }
.price.free { color: var(--green); }
.field { width: 100%; min-height: 110px; padding: 12px 14px; border-radius: 16px; background: var(--card-hi); border: 1px solid var(--stroke); outline: none; resize: vertical; margin-bottom: 12px; }
.job-card { margin-top: 14px; }
.job-card video, .job-card img, .grid-item video, .grid-item img { width: 100%; border-radius: 14px; display: block; background: #000; }
.progress { height: 6px; border-radius: 999px; background: var(--card-hi); overflow: hidden; margin: 12px 0 6px; }
.progress div { height: 100%; width: 40%; border-radius: 999px; background: linear-gradient(90deg, #a855f7, #f0abfc); animation: slide 1.4s infinite ease-in-out; }
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(260%); } }

/* ---------- история ---------- */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-item { border-radius: 16px; overflow: hidden; background: var(--card); border: 1px solid var(--stroke-soft); text-align: left; }
.grid-item .meta { padding: 8px 10px; font-size: 12px; color: var(--muted); }
.grid-item .status { display: grid; place-items: center; aspect-ratio: 1; color: var(--muted); font-size: 13px; padding: 10px; text-align: center; }

/* ---------- профиль ---------- */
.profile-head { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.avatar { width: 58px; height: 58px; border-radius: 50%; display: grid; place-items: center; font-size: 24px; font-weight: 800; background: linear-gradient(145deg, #c084fc, #7c3aed); }
.big-balance { font-size: 30px; font-weight: 800; display: flex; align-items: center; gap: 6px; }
.big-balance svg { color: var(--gold); width: 28px; height: 28px; }
.packs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0 4px; }
.pack { padding: 14px; border-radius: 16px; text-align: left; background: var(--card); border: 1px solid var(--stroke); }
.pack .cr { font-size: 20px; font-weight: 800; }
.pack .st { color: var(--gold); font-weight: 700; margin-top: 4px; }
.pack .bonus { color: var(--green); font-size: 12px; }
.row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--stroke-soft); }
.row:last-child { border-bottom: 0; }
.muted { color: var(--muted); }
.mt { margin-top: 14px; }
.linkbox { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.linkbox code { flex: 1; padding: 10px; border-radius: 12px; background: rgba(0, 0, 0, 0.35); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- шторка и тост ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, 0.55); }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-height: 80vh; overflow-y: auto;
  padding: 18px 16px calc(18px + var(--safe-b)); border-radius: 22px 22px 0 0;
  background: var(--bg2); border-top: 1px solid var(--stroke);
}
.sheet h3 { margin: 0 0 12px; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px); transform: translateX(-50%); z-index: 50;
  max-width: 90%; padding: 11px 16px; border-radius: 14px; background: #2a1748; border: 1px solid var(--stroke); font-size: 14px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}
.notice { padding: 12px 14px; border-radius: 14px; background: rgba(251, 191, 36, 0.12); border: 1px solid rgba(251, 191, 36, 0.35); margin-bottom: 12px; font-size: 14px; }
.notice .btn-gold { display: inline-block; margin-top: 8px; }
