:root {
  color-scheme: dark;
  --bg: var(--tg-theme-bg-color, #07111f);
  --surface: var(--tg-theme-secondary-bg-color, rgba(18, 31, 52, 0.92));
  --surface-strong: rgba(31, 48, 77, 0.96);
  --text: var(--tg-theme-text-color, #f7fbff);
  --muted: var(--tg-theme-hint-color, #8fa5bd);
  --link: var(--tg-theme-link-color, #64b5ff);
  --button: var(--tg-theme-button-color, #2f8cff);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --border: rgba(255, 255, 255, 0.1);
  --shadow: 0 20px 70px rgba(0, 0, 0, 0.35);
  --radius: 24px;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 20% 0%, rgba(55, 142, 255, 0.28), transparent 34%),
    radial-gradient(circle at 80% 10%, rgba(126, 87, 255, 0.18), transparent 32%),
    var(--bg);
}

button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.app-shell {
  width: min(940px, 100%);
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 14px calc(22px + env(safe-area-inset-bottom));
}
.card {
  background: linear-gradient(145deg, rgba(21, 35, 58, 0.96), rgba(10, 19, 35, 0.92));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.glow-card { position: relative; overflow: hidden; }
.glow-card::after {
  content: "";
  position: absolute;
  inset: -1px;
  background: linear-gradient(135deg, rgba(83, 169, 255, 0.22), rgba(255, 255, 255, 0), rgba(115, 84, 255, 0.16));
  pointer-events: none;
}
.hero {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  padding: 22px;
}
.eyebrow {
  margin: 0 0 8px;
  color: var(--link);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 11px;
  font-weight: 800;
}
h1, h2 { margin: 0; line-height: 1.05; }
h1 { font-size: clamp(28px, 8vw, 52px); max-width: 570px; }
h2 { font-size: 22px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 800; }
.energy-pill {
  min-width: 92px;
  padding: 12px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.energy-pill strong { font-size: 20px; }
.tabs {
  position: sticky;
  top: 8px;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 14px 0;
  padding: 6px;
  border-radius: 999px;
  background: rgba(6, 13, 25, 0.66);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border);
}
.tab {
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  padding: 11px 8px;
  font-weight: 800;
}
.tab.active { background: var(--button); color: var(--button-text); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.model-strip, .composer, .section-head, .pricing-controls, .settings-card, .help-card, .bundle-card { padding: 16px; margin-bottom: 12px; }
.model-strip, .row-between, .composer-actions, .bundle-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.top-align { align-items: flex-start; }
.chat-log {
  min-height: 280px;
  max-height: 52vh;
  overflow: auto;
  padding: 14px;
  margin-bottom: 12px;
  scroll-behavior: smooth;
}
.message {
  max-width: 86%;
  margin: 0 0 10px;
  padding: 12px 14px;
  border-radius: 18px;
  white-space: pre-wrap;
  line-height: 1.45;
}
.message.user { margin-left: auto; background: var(--button); color: var(--button-text); border-bottom-right-radius: 6px; }
.message.assistant { background: rgba(255, 255, 255, 0.08); border: 1px solid var(--border); border-bottom-left-radius: 6px; }
.message.system { max-width: 100%; text-align: center; color: var(--muted); background: transparent; }

.code-block {
  margin: 10px 0;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.22);
}
.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  color: var(--muted);
  font-size: 12px;
  border-bottom: 1px solid var(--border);
}
.copy-code-btn {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 800;
}
.code-block pre {
  margin: 0;
  padding: 12px;
  overflow: auto;
  white-space: pre;
}
textarea, input, select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  padding: 13px 14px;
  outline: none;
}
textarea { resize: vertical; min-height: 88px; }
textarea:focus, input:focus, select:focus { border-color: rgba(100, 181, 255, 0.72); }
.composer-actions { margin-top: 10px; }
.primary-btn, .secondary-btn, .ghost-btn, .link-btn {
  border: 0;
  border-radius: 16px;
  padding: 11px 14px;
  font-weight: 850;
}
.primary-btn { flex: 1; background: var(--button); color: var(--button-text); }
.secondary-btn { flex: 1; background: rgba(100, 181, 255, 0.16); color: var(--text); border: 1px solid rgba(100, 181, 255, 0.26); }
.ghost-btn { background: rgba(255, 255, 255, 0.08); color: var(--text); border: 1px solid var(--border); }
.link-btn { background: transparent; color: var(--link); padding: 7px 2px; }
.quick-actions, .telegram-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.quick-actions button {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 11px;
  font-size: 13px;
}
.pricing-controls { display: grid; grid-template-columns: 1fr 132px; gap: 8px; }
.list, .model-list, .instruction-list { display: grid; gap: 10px; }
.price-row, .model-row, .instruction-row {
  padding: 14px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--border);
}
.price-row, .model-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.badge { border-radius: 999px; padding: 4px 8px; background: rgba(255, 255, 255, 0.08); color: var(--muted); font-size: 12px; font-weight: 750; }
.badge.free { color: #b9ffd6; background: rgba(32, 201, 112, 0.16); }
.badge.premium { color: #ffe4a3; background: rgba(245, 171, 53, 0.16); }
.badge.paygo { color: #bcdcff; background: rgba(47, 140, 255, 0.16); }
.wallet-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }
.metric { padding: 16px; }
.metric span { display: block; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 800; }
.metric strong { display: block; margin-top: 8px; font-size: 24px; }
.bundle-row { padding: 10px 0; border-bottom: 1px solid var(--border); }
.bundle-row:last-of-type { border-bottom: 0; }
.instruction-row { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: start; }
.instruction-row p { margin: 0; white-space: pre-wrap; }
.switch { position: relative; width: 54px; height: 32px; display: inline-block; }
.switch input { display: none; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: rgba(255,255,255,0.14); border: 1px solid var(--border); }
.switch span::after { content: ""; position: absolute; width: 24px; height: 24px; top: 3px; left: 4px; border-radius: 50%; background: #fff; transition: transform .18s ease; }
.switch input:checked + span { background: var(--button); }
.switch input:checked + span::after { transform: translateX(21px); }
.sheet { position: fixed; inset: 0; display: none; z-index: 20; }
.sheet.active { display: block; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.54); }
.sheet-card {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 82vh;
  overflow: auto;
  padding: 18px 14px calc(18px + env(safe-area-inset-bottom));
  border-radius: 26px 26px 0 0;
  background: var(--surface-strong);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.sheet-card > input { margin: 12px 0; }
.model-browser-controls { margin: 12px 0; }
.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  display: none;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.84);
  color: #fff;
  text-align: center;
  z-index: 30;
}
.toast.show { display: block; }
@media (max-width: 620px) {
  .hero { padding: 18px; }
  .energy-pill { min-width: auto; }
  .pricing-controls { grid-template-columns: 1fr; }
  .wallet-grid { grid-template-columns: 1fr 1fr; }
  .message { max-width: 94%; }
}

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 12px 0 18px;
  flex-wrap: wrap;
}
.pager .ghost-btn:disabled {
  opacity: 0.45;
  cursor: default;
}
#languageSelect {
  max-width: 220px;
}
@media (max-width: 620px) {
  #languageSelect { max-width: 100%; }
}
