:root {
  color-scheme: light;
  --bg: #d9dde7;
  --bg-2: #edf0f6;
  --fg: #171b29;
  --hint: #6d7488;
  --line: rgba(255, 255, 255, .72);
  --accent: #5b5bd6;
  --accent-2: #7a5cf6;
  --mint: #17876b;
  --rose: #c8385a;
  --glass: rgba(255, 255, 255, .58);
  --glass-strong: rgba(255, 255, 255, .78);
  --radius: 22px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  height: 100dvh;
  overflow: hidden;
  color: var(--fg);
  font: 15px/1.48 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  background:
    radial-gradient(720px 480px at 12% -12%, rgba(122, 92, 246, .20), transparent 62%),
    radial-gradient(600px 420px at 96% 8%, rgba(23, 135, 107, .14), transparent 58%),
    linear-gradient(165deg, #cfd4df 0%, var(--bg) 38%, var(--bg-2) 100%);
}
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(255, 255, 255, .34), transparent 22%, transparent 78%, rgba(255, 255, 255, .18));
}

#app {
  position: relative;
  z-index: 1;
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}

.glass {
  background: linear-gradient(145deg, rgba(255, 255, 255, .76), rgba(255, 255, 255, .43));
  border: 1px solid var(--line);
  box-shadow: 0 14px 34px rgba(24, 31, 54, .10), inset 0 1px 0 rgba(255, 255, 255, .92);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  backdrop-filter: blur(24px) saturate(180%);
}

/* Header */
.topbar {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin: 10px 12px 6px;
  padding: 10px 12px;
  border-radius: 20px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo {
  width: 38px; height: 38px; flex: 0 0 38px;
  display: grid; place-items: center; border-radius: 13px;
  font-weight: 800; font-size: 18px; color: #fff;
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  box-shadow: 0 8px 18px rgba(91, 91, 214, .28);
}
h1 { font-size: 17px; margin: 0; letter-spacing: -.01em; }
.brand-sub { display: block; font-size: 10.5px; color: var(--hint); margin-top: 1px; }
h2 { font-size: 18px; margin: 0 0 8px; letter-spacing: -.01em; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.balance-pill {
  padding: 7px 11px; border-radius: 999px; font-size: 11.5px; font-weight: 650;
  background: rgba(23, 135, 107, .10); border: 1px solid rgba(23, 135, 107, .18);
  color: var(--mint); white-space: nowrap; cursor: pointer;
}
.icon-btn {
  width: 38px; height: 38px; flex: 0 0 38px; border-radius: 13px;
  background: rgba(255, 255, 255, .65); color: var(--fg);
  display: grid; place-items: center; border: 1px solid rgba(255, 255, 255, .8);
}
.icon-btn:active { transform: scale(.94); }
.icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Views and scrolling */
.view {
  display: none;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 10px 14px 22px;
  gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: rgba(23, 27, 41, .18) transparent;
}
.view.active { display: flex; flex-direction: column; }
.view:not(#view-chat).active > * { flex: 0 0 auto; }
.view::-webkit-scrollbar { width: 5px; }
.view::-webkit-scrollbar-thumb { background: rgba(23, 27, 41, .16); border-radius: 999px; }
#view-chat.active { padding: 0; gap: 0; overflow: hidden; }
.chat-wrap { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* Buttons and fields */
button, input, textarea { font: inherit; }
button { border: 0; cursor: pointer; color: inherit; }
button:disabled { opacity: .45; cursor: default; }
.btn {
  border-radius: 13px; padding: 11px 16px; font-weight: 650;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  transition: transform .12s ease, filter .12s ease;
}
.btn:active { transform: translateY(1px) scale(.99); }
.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  box-shadow: 0 10px 22px rgba(91, 91, 214, .26);
}
.btn-ghost {
  color: var(--fg);
  background: rgba(255, 255, 255, .66);
  border: 1px solid rgba(255, 255, 255, .82);
  box-shadow: 0 6px 14px rgba(24, 31, 54, .06);
}
.btn-wide { width: 100%; }
.btn-small { padding: 8px 12px; font-size: 12px; }
input, textarea {
  width: 100%; outline: none;
  background: rgba(255, 255, 255, .68);
  color: var(--fg);
  border: 1px solid rgba(255, 255, 255, .86);
  border-radius: 13px;
  padding: 11px 13px;
  box-shadow: inset 0 1px 2px rgba(24, 31, 54, .04);
}
input:focus, textarea:focus {
  border-color: rgba(91, 91, 214, .55);
  box-shadow: 0 0 0 3px rgba(91, 91, 214, .12), inset 0 1px 2px rgba(24, 31, 54, .04);
}
code {
  display: inline-block;
  max-width: 100%;
  overflow-x: auto;
  white-space: nowrap;
  padding: 2px 7px;
  border-radius: 8px;
  background: rgba(23, 27, 41, .06);
  font: 11.5px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: #333a52;
}
.hint, .fineprint { color: var(--hint); font-size: 12px; margin: 6px 0 10px; }
.fineprint { margin: 10px 0 0; line-height: 1.4; }
.eyebrow {
  color: var(--accent); font-size: 10.5px; font-weight: 750;
  text-transform: uppercase; letter-spacing: .1em; margin-bottom: 5px;
}

/* Chat */
.conversation-chips { display: flex; gap: 7px; overflow-x: auto; padding: 8px 14px 6px; scrollbar-width: none; flex: 0 0 auto; }
.conversation-chips::-webkit-scrollbar { display: none; }
.conversation-chips button {
  white-space: nowrap; padding: 7px 12px; border-radius: 999px; font-size: 11.5px;
  background: rgba(255, 255, 255, .62); border: 1px solid rgba(255, 255, 255, .8); color: var(--hint);
}
.conversation-chips button.active {
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  color: #fff; border-color: transparent; box-shadow: 0 6px 14px rgba(91, 91, 214, .22);
}
.messages {
  flex: 1; min-height: 0; overflow-y: auto; padding: 8px 14px 14px;
  display: flex; flex-direction: column; gap: 10px; scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
}
.msg {
  max-width: 88%; padding: 11px 14px; border-radius: 18px;
  white-space: pre-wrap; word-break: break-word; font-size: 14px;
  box-shadow: 0 8px 20px rgba(24, 31, 54, .08);
}
.msg.user {
  align-self: flex-end; border-bottom-right-radius: 6px;
  background: linear-gradient(135deg, var(--accent-2), var(--accent)); color: #fff;
}
.msg.assistant {
  align-self: flex-start; border-bottom-left-radius: 6px;
  background: linear-gradient(145deg, rgba(255, 255, 255, .84), rgba(255, 255, 255, .58));
  border: 1px solid rgba(255, 255, 255, .85);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  backdrop-filter: blur(18px) saturate(160%);
}
.msg.assistant::before {
  content: "ZloyGPT"; display: block; font-size: 9.5px; letter-spacing: .1em;
  color: var(--accent); text-transform: uppercase; margin-bottom: 5px; font-weight: 800;
}
.msg .cost { display: block; margin-top: 7px; font-size: 10.5px; color: var(--hint); }
.msg.msg-error { color: var(--rose); }
.suggestions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.suggestions button {
  padding: 6px 10px; border-radius: 999px; font-size: 11px;
  background: rgba(23, 135, 107, .10); color: var(--mint);
  border: 1px solid rgba(23, 135, 107, .18);
}
.composer {
  flex: 0 0 auto;
  display: flex; gap: 8px; align-items: flex-end; padding: 10px 14px 12px;
  margin: 0 12px 8px; border-radius: 20px;
}
.composer textarea { flex: 1; resize: none; max-height: 130px; min-height: 44px; }
.send-btn {
  width: 44px; height: 44px; flex: 0 0 44px; border-radius: 14px;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  box-shadow: 0 9px 20px rgba(91, 91, 214, .25);
}
.send-btn .icon { width: 21px; height: 21px; }

/* Cards and stats */
.hero-card, .card { border-radius: var(--radius); padding: 18px; }
.hero-card { position: relative; overflow: visible; }
.hero-balance { font-size: 38px; font-weight: 800; letter-spacing: -.03em; margin: 5px 0 6px; }
.key-create-card, .link-card, .quick-card { padding: 16px; }
.hero-note { color: var(--hint); font-size: 12.5px; margin: 0 0 14px; max-width: 46ch; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.stat-card { border-radius: 16px; padding: 12px 10px; }
.stat-card span { display: block; color: var(--hint); font-size: 10.5px; margin-bottom: 4px; }
.stat-card b { font-size: 14.5px; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; gap: 8px; }
.section-head h2 { margin: 0; font-size: 16px; }
.section-badge {
  background: rgba(23, 27, 41, .06); color: var(--hint); font-size: 10.5px;
  border-radius: 999px; padding: 3px 9px;
}

/* Lists */
.ledger, .keys { display: flex; flex-direction: column; gap: 8px; }
.ledger-row, .key-row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 11px 12px; border-radius: 14px; font-size: 12.5px;
  background: rgba(255, 255, 255, .52); border: 1px solid rgba(255, 255, 255, .75);
}
.ledger-row .ledger-label, .key-row .meta { min-width: 0; }
.ledger-row small, .key-row small { display: block; color: var(--hint); font-size: 10px; }
.ledger-amount { font-weight: 750; white-space: nowrap; }
.key-create { display: flex; gap: 8px; }
.key-create input { flex: 1; min-width: 0; }
.key-row button {
  padding: 6px 10px; font-size: 10.5px; border-radius: 9px;
  background: rgba(200, 56, 90, .10); color: var(--rose); border: 1px solid rgba(200, 56, 90, .18);
}
.status-badge { font-size: 10px; padding: 2px 8px; border-radius: 999px; background: rgba(23, 135, 107, .12); color: var(--mint); }
.status-badge.off { background: rgba(23, 27, 41, .07); color: var(--hint); }
.field { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid rgba(23, 27, 41, .08); font-size: 12.5px; }
.field span { color: var(--hint); }
.field b { text-align: right; word-break: break-all; font-weight: 650; }

/* Referrals */
.link-box { padding: 12px; margin-bottom: 8px; border-radius: 15px; background: rgba(23, 135, 107, .08); border: 1px solid rgba(23, 135, 107, .16); }
.link-row { display: flex; gap: 8px; margin-top: 8px; }
.link-row input { flex: 1; min-width: 0; font-size: 11.5px; }
.steps-card .step { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; }
.steps-card .step > span {
  width: 25px; height: 25px; flex: 0 0 25px; display: grid; place-items: center;
  border-radius: 9px; background: rgba(91, 91, 214, .12); color: var(--accent); font-size: 11px; font-weight: 800;
}
.steps-card small { display: block; color: var(--hint); font-size: 11.5px; margin-top: 2px; }

/* Documentation — fixed layout, no overlap */
.quick-facts { display: flex; flex-direction: column; gap: 7px; }
.quick-facts div { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.quick-facts span { color: var(--hint); font-size: 10.5px; }
.quick-facts code { align-self: flex-start; max-width: 100%; }
.doc-switch { display: flex; gap: 7px; overflow-x: auto; padding: 2px; scrollbar-width: none; flex: 0 0 auto; }
.doc-switch::-webkit-scrollbar { display: none; }
.doc-switch button {
  white-space: nowrap; padding: 8px 13px; border-radius: 999px; font-size: 11.5px;
  color: var(--hint); flex: 0 0 auto;
}
.doc-switch button.active { color: #fff; background: linear-gradient(135deg, var(--accent-2), var(--accent)); border-color: transparent; box-shadow: 0 6px 14px rgba(91, 91, 214, .22); }
.doc-panel { min-width: 0; overflow: hidden; padding: 18px; }
.doc-panel h3 { margin: 6px 0 10px; font-size: 15px; }
.doc-panel ol { margin: 0; padding-left: 20px; color: #333a52; font-size: 13px; }
.doc-panel li + li { margin-top: 7px; }
.doc-panel li::marker { color: var(--accent); font-weight: 700; }
.code-block {
  margin-top: 14px; border-radius: 15px; overflow: hidden;
  background: rgba(20, 25, 42, .94);
  border: 1px solid rgba(255, 255, 255, .12);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .06);
}
.code-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, .05);
  border-bottom: 1px solid rgba(255, 255, 255, .07);
}
.code-head span { color: #a9b0cc; font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.copy-code {
  padding: 5px 9px; font-size: 10px; border-radius: 8px;
  background: rgba(255, 255, 255, .10); color: #e4e8ff;
}
.code-block pre {
  margin: 0; padding: 12px;
  white-space: pre;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  font: 11.5px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: #e2e6ff;
}
.code-block pre::-webkit-scrollbar { height: 5px; }
.code-block pre::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .18); border-radius: 999px; }

/* Bottom dock */
.tabs {
  flex: 0 0 auto;
  display: flex; gap: 4px;
  margin: 6px 12px calc(8px + env(safe-area-inset-bottom));
  padding: 6px;
  border-radius: 22px;
  background: rgba(255, 255, 255, .68);
}
.tabs button {
  flex: 1 0 auto; min-width: 0;
  background: transparent; color: var(--hint); border-radius: 16px;
  padding: 7px 4px 6px; font-size: 9.5px; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.tabs button .icon { width: 20px; height: 20px; }
.tabs button.active {
  color: var(--accent);
  background: rgba(255, 255, 255, .92);
  box-shadow: 0 6px 14px rgba(24, 31, 54, .10), inset 0 1px 0 #fff;
}

/* Modals */
.modal {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(24, 29, 48, .34);
  display: grid; place-items: center; padding: 18px;
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
.modal.hidden, .toast.hidden { display: none; }
.modal-card {
  width: min(430px, 100%); max-height: 90vh; overflow-y: auto;
  border-radius: 26px; padding: 22px; position: relative;
  background: linear-gradient(150deg, rgba(255, 255, 255, .92), rgba(255, 255, 255, .76));
}
.modal-x {
  position: absolute; right: 13px; top: 11px;
  width: 30px; height: 30px; border-radius: 10px;
  background: rgba(23, 27, 41, .07); color: var(--hint); font-size: 19px; line-height: 1;
}
.amount-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 14px 0 16px; }
.amount-grid button {
  padding: 12px 4px; border-radius: 13px; font-weight: 700;
  background: rgba(255, 255, 255, .7); border: 1px solid rgba(255, 255, 255, .85);
}
.amount-grid button.active { color: #fff; background: linear-gradient(135deg, var(--accent-2), var(--accent)); border-color: transparent; }
.field-label { display: block; color: var(--hint); font-size: 10px; margin: 12px 0 6px; text-transform: uppercase; letter-spacing: .08em; font-weight: 700; }
.provider-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.provider {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 12px; border-radius: 15px; text-align: left;
  background: rgba(255, 255, 255, .56); border: 1px solid rgba(255, 255, 255, .8);
}
.provider.active { border-color: rgba(91, 91, 214, .5); background: rgba(91, 91, 214, .09); }
.provider-icon {
  width: 28px; height: 28px; display: grid; place-items: center; border-radius: 9px;
  font-weight: 800; margin-bottom: 4px;
}
.provider-icon.rub { background: rgba(23, 135, 107, .12); color: var(--mint); }
.provider-icon.usdt { background: rgba(37, 184, 133, .14); color: #147a5d; }
.provider small { color: var(--hint); font-size: 10.5px; }
#topup-form { margin-top: 14px; }
#topup-form input { margin-bottom: 10px; }
.secret-box {
  background: rgba(20, 25, 42, .94); border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 13px; padding: 12px; margin: 12px 0;
}
.secret-box pre { margin: 0; white-space: pre-wrap; word-break: break-all; font: 12px/1.6 ui-monospace, monospace; color: #e2e6ff; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(82px + env(safe-area-inset-bottom)); z-index: 30;
  width: max-content; max-width: calc(100% - 32px);
  padding: 11px 16px; border-radius: 14px; font-size: 12.5px; font-weight: 600;
  color: #fff; background: linear-gradient(135deg, var(--accent-2), var(--accent));
  box-shadow: 0 14px 30px rgba(24, 31, 54, .2);
}

@media (max-width: 380px) {
  .key-create { flex-direction: column; }
  .key-create button { width: 100%; }
}

@media (max-width: 360px) {
  .tabs button { font-size: 9px; }
  .hero-balance { font-size: 33px; }
  .stat-grid { gap: 7px; }
}
