:root {
  color-scheme: light dark;
  --bg: var(--tg-theme-secondary-bg-color, #f6f2ff);
  --surface: var(--tg-theme-bg-color, #ffffff);
  --surface-soft: var(--tg-theme-section-bg-color, #faf8ff);
  --text: var(--tg-theme-text-color, #171229);
  --muted: var(--tg-theme-hint-color, #6f687d);
  --border: var(--tg-theme-section-separator-color, rgba(79, 70, 100, .14));
  --primary: #7c3aed;
  --primary-strong: #6424d6;
  --accent: #ec4899;
  --success: #18845e;
  --warning: #9a5a00;
  --shadow-sm: 0 6px 18px rgba(69, 39, 111, .08);
  --shadow-md: 0 16px 44px rgba(69, 39, 111, .12);
  --nav-height: 72px;
}

* { box-sizing: border-box; }
html { min-width: 280px; background: var(--bg); scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 280px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 96% -3%, rgba(236, 72, 153, .11), transparent 28rem),
    radial-gradient(circle at -8% 12%, rgba(124, 58, 237, .14), transparent 30rem),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { color: inherit; font: inherit; }
button { touch-action: manipulation; }
button, a, input, textarea { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--primary) 55%, white);
  outline-offset: 2px;
}
.hidden { display: none !important; }
.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; }
.skip-link { position: fixed; z-index: 100; left: 12px; top: -60px; padding: 10px 14px; border-radius: 10px; background: var(--surface); color: var(--primary); font-weight: 700; }
.skip-link:focus { top: 12px; }

.shell {
  width: min(100%, 720px);
  margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top)) 16px calc(var(--nav-height) + 32px + env(safe-area-inset-bottom));
}
.topbar { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; gap: 11px; align-items: center; margin-bottom: 20px; }
.brand-mark { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 14px; color: white; background: linear-gradient(145deg, var(--primary), var(--accent)); box-shadow: 0 10px 24px rgba(124, 58, 237, .23); }
.brand-mark svg { width: 29px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.brand-copy { min-width: 0; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 17px; line-height: 1.25; }
h2 { font-size: 22px; line-height: 1.2; letter-spacing: -.02em; }
h3 { font-size: 18px; line-height: 1.25; }
.eyebrow { color: var(--primary); font-size: 11px; font-weight: 800; letter-spacing: .13em; }
.badge, .plan-pill { display: inline-flex; align-items: center; min-height: 30px; padding: 5px 10px; border: 1px solid var(--border); border-radius: 999px; background: color-mix(in srgb, var(--surface) 92%, transparent); color: var(--muted); font-size: 12px; font-weight: 800; }
.plan-pill { min-height: 26px; color: var(--primary); background: rgba(124, 58, 237, .10); }

.state-card, .hero-card, .prompt-card, .profile-card, .support-card, .usage-card, .agent-card, .catalog-card, .plan-card, .plus-banner {
  background: color-mix(in srgb, var(--surface) 95%, transparent);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.state-card { min-height: 116px; display: flex; align-items: center; gap: 14px; padding: 20px; border-radius: 22px; }
.state-card p, .muted { margin-top: 5px; color: var(--muted); font-size: 14px; line-height: 1.45; }
.error-card { align-items: flex-start; flex-wrap: wrap; }
.spinner { width: 28px; height: 28px; flex: 0 0 auto; border: 3px solid rgba(124, 58, 237, .18); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.view { animation: view-in .22s ease-out; }
@keyframes view-in { from { opacity: 0; transform: translateY(5px); } }
.hero-card { display: flex; justify-content: space-between; align-items: center; gap: 18px; padding: 22px; border-radius: 26px; overflow: hidden; position: relative; }
.hero-card::after { content: ""; position: absolute; width: 160px; height: 160px; right: -85px; top: -95px; border-radius: 50%; background: linear-gradient(145deg, rgba(124, 58, 237, .20), rgba(236, 72, 153, .10)); }
.hero-copy { position: relative; z-index: 1; min-width: 0; }
.hero-copy h2 { margin-top: 5px; font-size: clamp(25px, 8vw, 34px); }
.hero-copy > p:last-child { margin-top: 8px; max-width: 29rem; color: var(--muted); font-size: 14px; }
.avatar, .profile-avatar { flex: 0 0 auto; display: grid; place-items: center; border-radius: 18px; color: white; background: linear-gradient(145deg, var(--primary), var(--accent)); font-weight: 800; }
.avatar { position: relative; z-index: 1; width: 56px; height: 56px; font-size: 21px; }

.prompt-card { margin: 14px 0 28px; padding: 16px; border-radius: 22px; }
.prompt-card > label, .dialog-panel > label { display: block; margin-bottom: 8px; font-size: 13px; font-weight: 800; }
textarea, input[type="search"] { width: 100%; border: 1px solid var(--border); background: var(--surface-soft); }
textarea { min-height: 92px; resize: vertical; padding: 12px 14px; border-radius: 15px; line-height: 1.45; }
textarea::placeholder, input::placeholder { color: color-mix(in srgb, var(--muted) 84%, transparent); }
.prompt-actions { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 11px; }
.field-hint { color: var(--muted); font-size: 11px; }
.button { min-height: 48px; border: 0; border-radius: 15px; padding: 12px 18px; font-weight: 800; cursor: pointer; transition: transform .18s ease, opacity .18s ease, box-shadow .18s ease; }
.button:hover { box-shadow: var(--shadow-sm); }
.button:active { transform: scale(.98); }
.button:disabled { cursor: not-allowed; opacity: .55; box-shadow: none; }
.button svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.primary { width: 100%; color: white; background: linear-gradient(135deg, var(--primary), var(--primary-strong)); box-shadow: 0 10px 24px rgba(124, 58, 237, .22); }
.secondary { color: var(--primary); background: rgba(124, 58, 237, .10); }
.compact { width: auto; display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 10px 14px; }
.text-button { min-height: 44px; border: 0; padding: 8px; background: transparent; color: var(--primary); font-size: 13px; font-weight: 800; cursor: pointer; }

.section-heading { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin: 0 2px 12px; }
.section-heading h2 { margin-top: 2px; font-size: 19px; }
.section-heading > span { color: var(--muted); font-size: 12px; }
.quick-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 28px; }
.quick-card { min-height: 76px; display: flex; align-items: center; gap: 12px; border: 1px solid var(--border); border-radius: 18px; padding: 13px; background: color-mix(in srgb, var(--surface) 94%, transparent); text-align: left; cursor: pointer; transition: border-color .18s ease, transform .18s ease, box-shadow .18s ease; }
.quick-card:hover { border-color: rgba(124, 58, 237, .35); box-shadow: var(--shadow-sm); }
.quick-card:active { transform: scale(.985); }
.quick-card svg { width: 32px; height: 32px; flex: 0 0 auto; padding: 6px; border-radius: 10px; background: rgba(124, 58, 237, .10); color: var(--primary); fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.quick-card strong, .quick-card small { display: block; }
.quick-card strong { font-size: 14px; }
.quick-card small { margin-top: 2px; color: var(--muted); font-size: 11px; line-height: 1.3; }
.usage-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.usage-card { min-width: 0; padding: 14px 12px; border-radius: 18px; }
.usage-card span { display: block; color: var(--muted); font-size: 11px; }
.usage-card strong { display: block; margin-top: 7px; font-size: 18px; white-space: nowrap; }

.page-intro { margin: 6px 2px 20px; }
.page-intro h2 { margin-top: 4px; font-size: 29px; }
.page-intro > p:last-child { margin-top: 8px; color: var(--muted); font-size: 14px; }
.agent-list, .catalog-grid { display: grid; gap: 12px; }
.agent-card, .catalog-card { padding: 18px; border-radius: 22px; }
.agent-card-head { display: flex; align-items: flex-start; gap: 13px; }
.agent-icon { width: 44px; height: 44px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 14px; color: var(--primary); background: rgba(124, 58, 237, .10); }
.agent-icon svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.agent-copy { min-width: 0; flex: 1; }
.agent-title-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.agent-title-row h3 { min-width: 0; }
.access-tag { flex: 0 0 auto; padding: 4px 7px; border-radius: 999px; background: rgba(24, 132, 94, .10); color: var(--success); font-size: 10px; font-weight: 800; text-transform: uppercase; }
.access-tag.plus { background: rgba(124, 58, 237, .10); color: var(--primary); }
.agent-copy > p { margin-top: 5px; color: var(--muted); font-size: 13px; }
.agent-examples { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0; }
.agent-examples span { padding: 5px 8px; border-radius: 9px; background: var(--surface-soft); color: var(--muted); font-size: 11px; }
.agent-card .button, .catalog-card .button { min-height: 44px; }

.search-field { min-height: 48px; display: flex; align-items: center; gap: 9px; padding: 0 13px; border: 1px solid var(--border); border-radius: 15px; background: var(--surface); }
.search-field svg { width: 21px; height: 21px; flex: 0 0 auto; fill: none; stroke: var(--muted); stroke-width: 1.8; stroke-linecap: round; }
.search-field input { min-width: 0; height: 46px; border: 0; padding: 0; background: transparent; outline: none; }
.filter-row { display: flex; gap: 8px; margin: 12px -16px 16px; padding: 0 16px 4px; overflow-x: auto; scrollbar-width: none; }
.filter-row::-webkit-scrollbar { display: none; }
.filter-chip { min-height: 44px; flex: 0 0 auto; border: 1px solid var(--border); border-radius: 999px; padding: 8px 13px; background: var(--surface); color: var(--muted); font-size: 13px; font-weight: 700; cursor: pointer; transition: color .18s ease, background .18s ease, border-color .18s ease; }
.filter-chip.active { border-color: var(--primary); background: rgba(124, 58, 237, .10); color: var(--primary); }
.catalog-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.catalog-card { display: flex; flex-direction: column; min-width: 0; }
.catalog-card .agent-icon { margin-bottom: 12px; }
.catalog-card p { margin: 6px 0 14px; color: var(--muted); font-size: 12px; }
.catalog-card .button { margin-top: auto; }
.empty-state { margin: 24px 0; color: var(--muted); text-align: center; }
.plus-banner { display: grid; gap: 14px; margin-top: 18px; padding: 20px; border-radius: 24px; border-color: rgba(124, 58, 237, .34); background: linear-gradient(145deg, color-mix(in srgb, var(--surface) 95%, transparent), rgba(124, 58, 237, .09)); }
.plus-banner h3 { margin-top: 8px; font-size: 21px; }
.plus-banner p { margin-top: 5px; color: var(--muted); font-size: 13px; }
.plus-banner-price { display: flex; align-items: baseline; gap: 7px; color: var(--primary); }
.plus-banner-price strong { font-size: 29px; }
.plus-banner-price span { color: var(--muted); font-size: 12px; }

.profile-card { display: flex; align-items: center; gap: 14px; padding: 18px; margin-bottom: 26px; border-radius: 22px; }
.profile-avatar { width: 52px; height: 52px; font-size: 19px; }
.plan-stack { display: grid; gap: 12px; }
.plan-card { padding: 20px; border-radius: 24px; }
.plan-card.featured { position: relative; overflow: hidden; border-color: rgba(124, 58, 237, .40); }
.plan-card.featured::before { content: ""; position: absolute; width: 130px; height: 130px; right: -55px; top: -60px; border-radius: 50%; background: linear-gradient(145deg, rgba(124, 58, 237, .21), rgba(236, 72, 153, .12)); }
.plan-row { position: relative; display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; }
.price { color: var(--primary); font-size: 26px; line-height: 1; text-align: right; }
.price small { display: block; margin-top: 5px; color: var(--muted); font-size: 11px; font-weight: 600; white-space: nowrap; }
ul { margin: 18px 0; padding: 0; list-style: none; }
li { position: relative; margin: 10px 0; padding-left: 24px; color: var(--muted); font-size: 14px; line-height: 1.4; }
li::before { content: "✓"; position: absolute; left: 0; color: var(--primary); font-weight: 900; }
.current-label { display: block; width: 100%; padding: 13px 16px; border-radius: 15px; color: var(--primary); background: rgba(124, 58, 237, .10); text-align: center; font-size: 14px; font-weight: 800; }
.fine-print { margin-top: 12px; color: var(--muted); font-size: 11px; line-height: 1.45; }
.terms-acceptance { min-height: 44px; display: flex; gap: 10px; align-items: flex-start; margin: 0 0 14px; color: var(--muted); font-size: 12px; line-height: 1.4; cursor: pointer; }
.terms-acceptance input { width: 22px; height: 22px; flex: 0 0 auto; margin: 1px 0 0; accent-color: var(--primary); }
.support-card { margin-top: 16px; padding: 18px; border-radius: 22px; }
.support-card h2 { margin-top: 2px; font-size: 18px; }
.support-card > p { margin-top: 10px; color: var(--muted); font-size: 12px; }
.support-card a { color: var(--primary); font-weight: 700; text-underline-offset: 2px; }

.bottom-nav { position: fixed; z-index: 20; left: 50%; bottom: 0; width: min(100%, 720px); min-height: calc(var(--nav-height) + env(safe-area-inset-bottom)); display: grid; grid-template-columns: repeat(4, 1fr); padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); background: color-mix(in srgb, var(--surface) 91%, transparent); backdrop-filter: blur(18px); transform: translateX(-50%); }
.nav-item { min-width: 0; min-height: 56px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; border: 0; border-radius: 14px; padding: 5px 2px; background: transparent; color: var(--muted); cursor: pointer; transition: color .18s ease, background .18s ease; }
.nav-item:hover { background: rgba(124, 58, 237, .06); }
.nav-item.active { color: var(--primary); background: rgba(124, 58, 237, .09); }
.nav-item svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-item span { max-width: 100%; overflow: hidden; font-size: 10px; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }

.assistant-dialog { width: min(calc(100% - 24px), 560px); max-height: calc(100vh - 24px); margin: auto; padding: 0; border: 1px solid var(--border); border-radius: 26px; background: var(--surface); color: var(--text); box-shadow: var(--shadow-md); }
.assistant-dialog::backdrop { background: rgba(20, 12, 34, .54); backdrop-filter: blur(4px); }
.dialog-panel { position: relative; padding: 24px 20px calc(20px + env(safe-area-inset-bottom)); }
.dialog-panel h2 { margin: 4px 42px 0 0; }
.dialog-panel > .muted { margin: 8px 38px 18px 0; }
.icon-button { position: absolute; top: 14px; right: 14px; width: 44px; height: 44px; display: grid; place-items: center; border: 0; border-radius: 14px; background: var(--surface-soft); color: var(--muted); cursor: pointer; }
.icon-button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; }
.example-list { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 18px; }
.example-button { min-height: 44px; border: 1px solid var(--border); border-radius: 12px; padding: 8px 10px; background: var(--surface-soft); color: var(--muted); font-size: 12px; cursor: pointer; }
.dialog-panel textarea { margin-bottom: 12px; }
.dialog-note { margin-top: 10px; color: var(--muted); font-size: 11px; text-align: center; }

@media (min-width: 620px) {
  .agent-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .plan-stack { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
  .plus-banner { grid-template-columns: 1fr auto; align-items: center; }
  .plus-banner .button { grid-column: 1 / -1; }
}
@media (max-width: 420px) {
  .shell { padding-left: 12px; padding-right: 12px; }
  .quick-grid, .catalog-grid { grid-template-columns: 1fr; }
  .prompt-actions { align-items: stretch; flex-direction: column; }
  .prompt-actions .compact { width: 100%; }
  .field-hint { order: 2; text-align: right; }
  .filter-row { margin-left: -12px; margin-right: -12px; padding-left: 12px; padding-right: 12px; }
}
@media (max-width: 340px) {
  .usage-grid { grid-template-columns: 1fr; }
  .usage-card { display: flex; justify-content: space-between; align-items: center; }
  .usage-card strong { margin-top: 0; }
  .brand-copy h1 { font-size: 15px; }
  .nav-item span { font-size: 9px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
