@property --grad1 {
  syntax: '<color>';
  inherits: true;
  initial-value: #2481cc;
}
@property --grad2 {
  syntax: '<color>';
  inherits: true;
  initial-value: #7b2fff;
}

:root {
  --grad1:        #2481cc;
  --grad2:        #7b2fff;
  --bg:           #0a0a0f;
  --text:         #ffffff;
  --hint:         rgba(255,255,255,0.55);
  --secondary:    rgba(255,255,255,0.07);
  --radius:       14px;
  --nav-height:   60px;
  --glass-bg:     rgba(255,255,255,0.08);
  --glass-border: rgba(255,255,255,0.15);
  --glass-shine:  rgba(255,255,255,0.12);
  --glass-blur:   blur(24px) saturate(180%);
  --glass-shadow: 0 8px 32px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.15);
}

@keyframes bgFloat {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}
@keyframes bgPulse {
  0%   { background-position: 0% 0%; }
  25%  { background-position: 100% 0%; }
  50%  { background-position: 100% 100%; }
  75%  { background-position: 0% 100%; }
  100% { background-position: 0% 0%; }
}

/* Floating math symbols */
#bg-symbols {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  /* no overflow:hidden — viewport clips naturally, symbols float up from below */
}
#stars-widget {
  position: fixed;
  top: calc(var(--safe-top, 0px) + 8px);
  right: 12px;
  z-index: 500;
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 20px;
  padding: 5px 10px 5px 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.4);
}
#stars-val {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
}
#stars-plus-btn {
  background: linear-gradient(135deg, var(--grad1), var(--grad2));
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 22px; height: 22px;
  font-size: 16px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.bg-symbol {
  position: absolute;
  color: rgba(255, 255, 255, 0.55);
  pointer-events: none;
  user-select: none;
  font-family: 'Times New Roman', serif;
  text-shadow: 0 0 20px rgba(236, 72, 153, 0.6), 0 0 40px rgba(56, 189, 248, 0.4);
  animation: floatUp var(--dur, 20s) var(--delay, 0s) linear infinite;
  will-change: transform, opacity;
  white-space: nowrap;
}
.bg-expr {
  font-family: 'Courier New', 'Menlo', monospace;
  color: rgba(255, 255, 255, 0.42);
  text-shadow: 0 0 16px rgba(56, 189, 248, 0.5), 0 0 32px rgba(236, 72, 153, 0.3);
  letter-spacing: 0.02em;
}
@keyframes floatUp {
  0%   { transform: translateY(0) rotate(0deg); opacity: 0; }
  8%   { opacity: 1; }
  92%  { opacity: 0.7; }
  100% { transform: translateY(-120vh) rotate(var(--rot, 120deg)); opacity: 0; }
}

/* ===== LIQUID GLASS BUTTON ANIMATIONS ===== */
@keyframes liquidShimmer {
  0%   { transform: translateX(-200%) skewX(-20deg); }
  100% { transform: translateX(200%) skewX(-20deg); }
}
@keyframes rippleOut {
  0%   { transform: scale(0); opacity: 0.6; }
  100% { transform: scale(3.5); opacity: 0; }
}
@keyframes glassPress {
  0%   { transform: scale(1); }
  40%  { transform: scale(0.94); }
  100% { transform: scale(1); }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: linear-gradient(135deg,
    #000 0%,
    #060610 10%,
    color-mix(in srgb, var(--grad1) 38%, #000) 35%,
    #040408 50%,
    color-mix(in srgb, var(--grad2) 38%, #000) 68%,
    #060610 90%,
    #000 100%
  );
  background-size: 250% 250%;
  color: var(--text);
  height: var(--app-height, 100vh);
  overflow: hidden;
  transition: --grad1 0.9s ease, --grad2 0.9s ease;
  animation: bgFloat 18s ease infinite;
}
body.generating {
  animation: bgPulse 2.2s ease-in-out infinite !important;
}

/* Math category: black→pink→black→blue gradient */
body.cat-math {
  background: linear-gradient(135deg,
    #000 0%,
    #080308 8%,
    color-mix(in srgb, #ec4899 50%, #000) 32%,
    #040408 50%,
    color-mix(in srgb, #38bdf8 50%, #000) 70%,
    #080810 92%,
    #000 100%
  ) !important;
  background-size: 300% 300% !important;
  animation: bgFloat 18s ease infinite !important;
}
body.cat-math.generating {
  animation: bgPulse 2.2s ease-in-out infinite !important;
}

/* GigaChat: российский флаг — белый полоса + синяя + красная, всегда все три видны */
@keyframes bgFloatFlag {
  0%   { background-position: 50% 0%; }
  50%  { background-position: 50% 100%; }
  100% { background-position: 50% 0%; }
}
body.cat-gigachat {
  /* Repeating pattern: white → blue → red → white → blue → red
     With background-size 100% 200% the full pattern is 2x viewport height,
     so at any scroll position all 3 bands remain visible in the lower half */
  background: linear-gradient(180deg,
    #f8faff  0%,
    #ffffff  8%,
    #dce8ff  16%,
    #4472c4  24%,
    #1e3a8a  33%,
    #4472c4  42%,
    #e87a7a  50%,
    #dc2626  58%,
    #b91c1c  67%,
    #e87a7a  75%,
    #dce8ff  83%,
    #4472c4  91%,
    #1e3a8a  100%
  ) !important;
  background-size: 100% 300% !important;
  animation: bgFloatFlag 22s ease-in-out infinite !important;
  --text: #0f172a;
  --hint: rgba(15,23,42,0.55);
  --glass-bg: rgba(0,0,0,0.07);
  --glass-border: rgba(0,0,0,0.14);
  --glass-shadow: 0 8px 32px rgba(0,0,0,0.15), inset 0 1px 0 rgba(255,255,255,0.8);
}
body.cat-gigachat.generating {
  animation: bgPulse 2.2s ease-in-out infinite !important;
}

/* Default (non-chat) background: dark teal/mint/emerald with waves */
body.page-default {
  background: linear-gradient(135deg,
    #000000  0%,
    #012118  8%,
    #065f46  18%,
    #0d9488  30%,
    #000000  42%,
    #022c22  52%,
    #059669  62%,
    #0891b2  74%,
    #000000  85%,
    #011a14  92%,
    #065f46  100%
  ) !important;
  background-size: 300% 300% !important;
  animation: bgFloat 22s ease infinite !important;
  --grad1: #0d9488;
  --grad2: #0891b2;
}
.bg-ezhice {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif !important;
  font-weight: 700 !important;
  letter-spacing: 0.18em !important;
  font-size: 1.3rem !important;
  color: rgba(255,255,255,0.07) !important;
  text-shadow: 0 0 30px rgba(13,148,136,0.15), 0 1px 0 rgba(255,255,255,0.06) !important;
  text-transform: uppercase !important;
}

#app {
  height: calc(var(--app-height, 100vh) - var(--nav-height));
  display: flex;
  flex-direction: column;
}

/* ===== LOADER ===== */
.loader-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: var(--app-height, 100vh);
  background: transparent;
}
.loader-spinner {
  width: 40px; height: 40px;
  border: 3px solid rgba(255,255,255,0.1);
  border-top-color: var(--grad1);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== BOTTOM NAV ===== */
.bottom-nav {
  display: flex;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--nav-height);
  background: rgba(10,10,20,0.7);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-top: 1px solid var(--glass-border);
  box-shadow: 0 -1px 0 rgba(255,255,255,0.06), 0 -8px 32px rgba(0,0,0,0.5);
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--hint);
  font-size: 11px;
  cursor: pointer;
  transition: color 0.15s;
  position: relative;
  overflow: hidden;
  isolation: isolate;
}
.nav-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg,
    transparent 25%, rgba(255,255,255,0.25) 50%, transparent 75%);
  transform: translateX(-200%) skewX(-20deg);
  pointer-events: none;
}
.nav-btn:active::before { animation: liquidShimmer 0.4s ease forwards; }
.nav-btn:active { animation: glassPress 0.18s ease forwards; }
.nav-btn svg { width: 22px; height: 22px; fill: currentColor; position: relative; z-index: 1; }
.nav-btn span { position: relative; z-index: 1; }
.nav-btn.active {
  background: linear-gradient(135deg, var(--grad1), var(--grad2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.nav-btn.active svg {
  fill: url(#nav-grad) var(--grad1);
}

/* ===== PAGE WRAPPER ===== */
.page {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

/* ===== PAGE HEADER ===== */
.page-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: rgba(255,255,255,0.06);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--glass-border);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.1), 0 4px 16px rgba(0,0,0,0.3);
  min-height: 52px;
  flex-shrink: 0;
  position: relative;
}
.page-header::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
  pointer-events: none;
}
.page-header h2 { font-size: 17px; font-weight: 600; flex: 1; color: var(--text); }
.header-btn {
  background: rgba(255,255,255,0.07);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--grad1);
  font-size: 14px;
  cursor: pointer;
  padding: 5px 10px;
  border-radius: 10px;
  transition: background 0.15s;
  position: relative;
  overflow: hidden;
  isolation: isolate;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.12);
}
.header-btn::before {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(105deg, transparent 25%, rgba(255,255,255,0.3) 50%, transparent 75%);
  transform: translateX(-200%) skewX(-20deg); pointer-events: none;
}
.header-btn:active::before { animation: liquidShimmer 0.3s ease forwards; }
.header-btn:active { animation: glassPress 0.15s ease forwards; }

/* ===== AUTH PAGE ===== */
.auth-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: var(--app-height, 100vh);
  padding: 32px 24px;
  gap: 16px;
}
.auth-logo {
  width: 80px; height: 80px;
  background: linear-gradient(135deg, var(--grad1), var(--grad2));
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 40px;
}
.auth-title { font-size: 22px; font-weight: 700; color: var(--text); }
.auth-subtitle { color: var(--hint); font-size: 14px; text-align: center; }
.auth-form { width: 100%; max-width: 320px; display: flex; flex-direction: column; gap: 12px; }
.input-group { display: flex; flex-direction: column; gap: 6px; }
.input-group label { font-size: 13px; color: var(--hint); }
.input-field {
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1.5px solid var(--glass-border);
  background: rgba(255,255,255,0.07);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.08);
}
.input-field:focus {
  border-color: var(--grad1);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.08), 0 0 0 3px rgba(36,129,204,0.15);
}
.input-field::placeholder { color: var(--hint); }
.btn-primary {
  padding: 14px;
  background: linear-gradient(135deg, var(--grad1), var(--grad2));
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  isolation: isolate;
  box-shadow:
    0 4px 20px rgba(0,0,0,0.4),
    inset 0 1px 0 rgba(255,255,255,0.25),
    inset 0 -1px 0 rgba(0,0,0,0.2);
  transition: transform 0.15s, box-shadow 0.15s;
}
.btn-primary::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg,
    transparent 30%, rgba(255,255,255,0.4) 50%, transparent 70%);
  transform: translateX(-200%) skewX(-20deg);
  pointer-events: none;
  z-index: 1;
}
.btn-primary::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(255,255,255,0.35) 0%, transparent 65%);
  transform: scale(0);
  opacity: 0;
  pointer-events: none;
  border-radius: inherit;
  z-index: 0;
}
.btn-primary:active::before { animation: liquidShimmer 0.45s ease forwards; }
.btn-primary:active::after  { animation: rippleOut 0.4s ease-out forwards; }
.btn-primary:active { animation: glassPress 0.2s ease forwards; }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; animation: none; }
.error-msg { color: #ff6b6b; font-size: 13px; text-align: center; }

/* ===== CHAT PAGE ===== */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}
.message {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.5;
  word-break: break-word;
}
.message.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--grad1), var(--grad2));
  color: #fff;
  border-bottom-right-radius: 4px;
}
.message.assistant {
  align-self: flex-start;
  background: rgba(255,255,255,0.07);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-bottom-left-radius: 4px;
  color: var(--text);
  box-shadow: var(--glass-shadow);
  position: relative;
  overflow: hidden;
}
.message.assistant::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 40%;
  background: linear-gradient(180deg, rgba(255,255,255,0.08) 0%, transparent 100%);
  pointer-events: none;
  border-radius: inherit;
}
.message pre {
  background: rgba(0,0,0,0.3);
  border-radius: 8px;
  padding: 10px;
  overflow-x: auto;
  margin: 6px 0;
  font-size: 13px;
}
.message code {
  background: rgba(0,0,0,0.25);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 13px;
}
.message pre code {
  background: none;
  padding: 0;
}
.message-meta {
  font-size: 11px;
  color: var(--hint);
  margin-top: 6px;
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}
.message.user .message-meta { justify-content: flex-end; color: rgba(255,255,255,0.6); }
.cost-badge {
  background: rgba(255,255,255,0.12);
  padding: 1px 6px;
  border-radius: 10px;
  font-size: 11px;
}
.message-actions {
  display: flex;
  gap: 4px;
  margin-top: 6px;
}
.msg-action-btn {
  background: rgba(255,255,255,0.08);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.14);
  color: var(--hint);
  border-radius: 8px;
  padding: 3px 8px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  display: flex;
  align-items: center;
  gap: 3px;
  position: relative;
  overflow: hidden;
  isolation: isolate;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
}
.msg-action-btn::before {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(105deg, transparent 25%, rgba(255,255,255,0.3) 50%, transparent 75%);
  transform: translateX(-200%) skewX(-20deg); pointer-events: none;
}
.msg-action-btn:active::before { animation: liquidShimmer 0.35s ease forwards; }
.msg-action-btn:active { animation: glassPress 0.15s ease forwards; }
.msg-action-btn:hover { background: rgba(255,255,255,0.14); color: var(--text); }
.copy-tooltip {
  position: absolute;
  background: linear-gradient(135deg, var(--grad1), var(--grad2));
  color: #fff;
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 12px;
  pointer-events: none;
  z-index: 200;
  white-space: nowrap;
  transform: translateY(-32px);
  animation: fadeInUp 0.15s ease;
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(-24px); }
  to   { opacity: 1; transform: translateY(-32px); }
}
/* ===== MARKDOWN RENDERED CONTENT ===== */
.md-rendered { line-height: 1.65; }
.md-rendered p { margin: 0 0 0.7em; }
.md-rendered p:last-child { margin-bottom: 0; }
.md-rendered h1,.md-rendered h2,.md-rendered h3,.md-rendered h4 {
  font-weight: 700; margin: 1em 0 0.4em; line-height: 1.3;
}
.md-rendered h1 { font-size: 1.25em; }
.md-rendered h2 { font-size: 1.13em; }
.md-rendered h3 { font-size: 1.03em; }
.md-rendered h4 { font-size: 0.97em; }
.md-rendered ul,.md-rendered ol { padding-left: 1.4em; margin: 0.4em 0 0.7em; }
.md-rendered li { margin-bottom: 0.25em; }
.md-rendered li > ul,.md-rendered li > ol { margin: 0.2em 0; }
.md-rendered blockquote {
  border-left: 3px solid rgba(255,255,255,0.3);
  margin: 0.6em 0;
  padding: 0.3em 0.8em;
  color: var(--hint);
  font-style: italic;
}
.md-rendered pre {
  background: rgba(0,0,0,0.35);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  margin: 0.6em 0;
  font-size: 0.82em;
  line-height: 1.5;
}
.md-rendered code {
  font-family: 'SF Mono','Fira Code','Menlo',monospace;
  font-size: 0.88em;
  background: rgba(255,255,255,0.1);
  border-radius: 4px;
  padding: 1px 5px;
}
.md-rendered pre code {
  background: none; padding: 0; font-size: 1em;
}
.md-rendered table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.6em 0;
  font-size: 0.88em;
  overflow-x: auto;
  display: block;
}
.md-rendered th,.md-rendered td {
  border: 1px solid rgba(255,255,255,0.15);
  padding: 5px 10px;
  text-align: left;
}
.md-rendered th {
  background: rgba(255,255,255,0.08);
  font-weight: 600;
}
.md-rendered hr {
  border: none;
  border-top: 1px solid rgba(255,255,255,0.15);
  margin: 0.8em 0;
}
.md-rendered strong { font-weight: 700; color: inherit; }
.md-rendered em { font-style: italic; }
.md-rendered a { color: var(--grad1); text-decoration: underline; }

/* KaTeX display math */
.md-rendered .katex-display { margin: 0.6em 0; overflow-x: auto; }
.math-block { padding: 8px 0; text-align: center; overflow-x: auto; }

.typing-indicator {
  align-self: flex-start;
  background: rgba(255,255,255,0.07);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  padding: 12px 16px;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  display: flex;
  gap: 4px;
  align-items: center;
}
.typing-dot {
  width: 7px; height: 7px;
  background: var(--hint);
  border-radius: 50%;
  animation: typing-bounce 1.2s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing-bounce {
  0%,60%,100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}

/* Image preview above input */
.image-preview-bar {
  padding: 6px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.04);
  border-top: 1px solid var(--glass-border);
  flex-shrink: 0;
}
.image-preview-thumb {
  width: 48px; height: 48px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--glass-border);
}
.image-preview-remove {
  background: rgba(255,80,80,0.2);
  border: 1px solid rgba(255,80,80,0.3);
  color: #ff6b6b;
  border-radius: 50%;
  width: 22px; height: 22px;
  font-size: 14px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.chat-input-area {
  padding: 8px 12px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  background: rgba(255,255,255,0.06);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-top: 1px solid var(--glass-border);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.1), 0 -4px 20px rgba(0,0,0,0.3);
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
}
.chat-textarea {
  flex: 1;
  min-height: 40px;
  max-height: 120px;
  padding: 10px 14px;
  border-radius: 20px;
  border: 1.5px solid var(--glass-border);
  background: rgba(255,255,255,0.06);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--text);
  font-size: 15px;
  resize: none;
  outline: none;
  line-height: 1.4;
  font-family: inherit;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.08);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.chat-textarea::placeholder { color: var(--hint); }
.chat-textarea:focus {
  border-color: var(--grad1);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.08), 0 0 0 3px rgba(36,129,204,0.15);
}
.send-btn {
  width: 40px; height: 40px;
  background: linear-gradient(135deg, var(--grad1), var(--grad2));
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
  isolation: isolate;
  box-shadow:
    0 4px 16px rgba(0,0,0,0.5),
    inset 0 1px 0 rgba(255,255,255,0.3),
    inset 0 -1px 0 rgba(0,0,0,0.2);
  transition: transform 0.15s, box-shadow 0.15s;
}
.send-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg,
    transparent 25%, rgba(255,255,255,0.5) 50%, transparent 75%);
  transform: translateX(-200%) skewX(-20deg);
  pointer-events: none;
  border-radius: inherit;
  z-index: 1;
}
.send-btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(255,255,255,0.4) 0%, transparent 65%);
  transform: scale(0);
  opacity: 0;
  pointer-events: none;
  border-radius: inherit;
  z-index: 0;
}
.send-btn:not(:disabled):active::before { animation: liquidShimmer 0.4s ease forwards; }
.send-btn:not(:disabled):active::after  { animation: rippleOut 0.35s ease-out forwards; }
/* NO glassPress on send-btn — transform:scale on :active swallows tap events in Telegram WebView */
.send-btn:not(:disabled):active { opacity: 0.8; }
.send-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.send-btn svg { width: 18px; height: 18px; fill: #fff; position: relative; z-index: 2; }

.upload-btn {
  width: 36px; height: 36px;
  background: rgba(255,255,255,0.07);
  border: 1px solid var(--glass-border);
  border-radius: 50%;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
  color: var(--hint);
}
.upload-btn:hover { background: rgba(255,255,255,0.13); color: var(--text); }
.upload-btn svg { width: 18px; height: 18px; fill: currentColor; }

.cost-estimate-bar {
  padding: 4px 12px 0;
  font-size: 12px;
  color: var(--hint);
  flex-shrink: 0;
}

/* ===== CONFIRM MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn 0.15s ease;
}
@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
.modal-card {
  background: rgba(15,12,35,0.85);
  backdrop-filter: blur(40px) saturate(200%);
  -webkit-backdrop-filter: blur(40px) saturate(200%);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 22px;
  padding: 24px;
  max-width: 320px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.2);
  position: relative;
  overflow: hidden;
}
.modal-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 50%;
  background: linear-gradient(180deg, rgba(255,255,255,0.08) 0%, transparent 100%);
  pointer-events: none;
}
.modal-title { font-size: 17px; font-weight: 700; color: var(--text); }
.modal-body { font-size: 14px; color: var(--hint); line-height: 1.5; }
.modal-actions { display: flex; gap: 10px; }
.modal-btn {
  flex: 1;
  padding: 12px;
  border-radius: var(--radius);
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.modal-btn.cancel {
  background: rgba(255,255,255,0.08);
  color: var(--text);
  position: relative; overflow: hidden; isolation: isolate;
}
.modal-btn.cancel::before {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(105deg, transparent 30%, rgba(255,255,255,0.2) 50%, transparent 70%);
  transform: translateX(-200%) skewX(-20deg); pointer-events: none;
}
.modal-btn.cancel:active::before { animation: liquidShimmer 0.4s ease forwards; }
.modal-btn.cancel:active { animation: glassPress 0.18s ease forwards; }
.modal-btn.confirm {
  background: linear-gradient(135deg, var(--grad1), var(--grad2));
  color: #fff;
  position: relative; overflow: hidden; isolation: isolate;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.25);
}
.modal-btn.confirm::before {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(105deg, transparent 30%, rgba(255,255,255,0.4) 50%, transparent 70%);
  transform: translateX(-200%) skewX(-20deg); pointer-events: none; z-index: 1;
}
.modal-btn.confirm::after {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(circle at center, rgba(255,255,255,0.35) 0%, transparent 65%);
  transform: scale(0); opacity: 0; pointer-events: none; border-radius: inherit;
}
.modal-btn.confirm:active::before { animation: liquidShimmer 0.4s ease forwards; }
.modal-btn.confirm:active::after  { animation: rippleOut 0.35s ease-out forwards; }
.modal-btn.confirm:active { animation: glassPress 0.18s ease forwards; }

/* ===== MODELS PAGE ===== */
.categories-bar {
  display: flex;
  overflow-x: auto;
  gap: 8px;
  padding: 10px 16px;
  scrollbar-width: none;
  background: rgba(255,255,255,0.05);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--glass-border);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.08);
  flex-shrink: 0;
}
.categories-bar::-webkit-scrollbar { display: none; }
.cat-pill {
  white-space: nowrap;
  padding: 6px 14px;
  border-radius: 20px;
  background: rgba(255,255,255,0.05);
  border: 1.5px solid var(--glass-border);
  color: var(--hint);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}
.cat-pill.active {
  background: linear-gradient(135deg, var(--grad1), var(--grad2));
  color: #fff;
  border-color: transparent;
  position: relative;
  overflow: hidden;
  isolation: isolate;
  box-shadow: 0 2px 10px rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.2);
}
.cat-pill.active::before {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(105deg, transparent 25%, rgba(255,255,255,0.35) 50%, transparent 75%);
  transform: translateX(-200%) skewX(-20deg); pointer-events: none;
}
.cat-pill:active::before { animation: liquidShimmer 0.35s ease forwards; }
.cat-pill:active { animation: glassPress 0.15s ease forwards; }
.models-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}
.model-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  gap: 12px;
  cursor: pointer;
  transition: background 0.1s;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.model-item:active { background: rgba(255,255,255,0.05); }
.model-item.selected .model-check {
  background: linear-gradient(135deg, var(--grad1), var(--grad2));
  border-color: transparent;
}
.model-item.selected .model-check::after { display: block; }
.model-icon {
  width: 40px; height: 40px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.model-info { flex: 1; min-width: 0; }
.model-name { font-size: 15px; font-weight: 500; color: var(--text); }
.model-price { font-size: 12px; color: var(--hint); margin-top: 2px; }
.model-check {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.2);
  position: relative;
  flex-shrink: 0;
}
.model-check::after {
  content: '';
  display: none;
  position: absolute;
  left: 5px; top: 2px;
  width: 6px; height: 10px;
  border: 2px solid #fff;
  border-top: none; border-left: none;
  transform: rotate(45deg);
}
.models-footer {
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  background: rgba(255,255,255,0.06);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-top: 1px solid var(--glass-border);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
  flex-shrink: 0;
}
.compare-selected-btn {
  display: none;
  width: 100%;
  padding: 13px;
  background: linear-gradient(135deg, var(--grad1), var(--grad2));
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.compare-selected-btn.visible { display: block; }

/* ===== COMPARE PAGE ===== */
.compare-top {
  padding: 12px 16px 8px;
  background: rgba(255,255,255,0.06);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--glass-border);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
  flex-shrink: 0;
}
.compare-textarea {
  width: 100%;
  min-height: 70px;
  max-height: 140px;
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1.5px solid var(--glass-border);
  background: rgba(255,255,255,0.06);
  color: var(--text);
  font-size: 15px;
  resize: none;
  outline: none;
  font-family: inherit;
  line-height: 1.4;
}
.compare-textarea::placeholder { color: var(--hint); }
.compare-textarea:focus { border-color: var(--grad1); }
.compare-models-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 8px 0 0;
  scrollbar-width: none;
  align-items: center;
}
.compare-models-row::-webkit-scrollbar { display: none; }
.compare-model-chip {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: rgba(255,255,255,0.07);
  border-radius: 16px;
  border: 1px solid var(--grad1);
  font-size: 12px;
  white-space: nowrap;
  flex-shrink: 0;
  color: var(--text);
}
.compare-model-chip .remove-chip {
  background: none;
  border: none;
  color: var(--hint);
  cursor: pointer;
  font-size: 14px;
  padding: 0;
  line-height: 1;
}
.add-model-chip {
  padding: 4px 12px;
  background: linear-gradient(135deg, var(--grad1), var(--grad2));
  color: #fff;
  border: none;
  border-radius: 16px;
  font-size: 12px;
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
  isolation: isolate;
  box-shadow: 0 2px 10px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.2);
}
.add-model-chip::before {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(105deg, transparent 25%, rgba(255,255,255,0.4) 50%, transparent 75%);
  transform: translateX(-200%) skewX(-20deg); pointer-events: none;
}
.add-model-chip:active::before { animation: liquidShimmer 0.35s ease forwards; }
.add-model-chip:active { animation: glassPress 0.15s ease forwards; }
.compare-send-row {
  display: flex;
  gap: 8px;
  align-items: center;
  padding-top: 8px;
}
.compare-send-btn {
  flex: 1;
  padding: 10px;
  background: linear-gradient(135deg, var(--grad1), var(--grad2));
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  isolation: isolate;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.2);
}
.compare-send-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg, transparent 30%, rgba(255,255,255,0.35) 50%, transparent 70%);
  transform: translateX(-200%) skewX(-20deg);
  pointer-events: none;
}
.compare-send-btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(255,255,255,0.3) 0%, transparent 65%);
  transform: scale(0); opacity: 0;
  pointer-events: none; border-radius: inherit;
}
.compare-send-btn:not(:disabled):active::before { animation: liquidShimmer 0.45s ease forwards; }
.compare-send-btn:not(:disabled):active::after  { animation: rippleOut 0.4s ease-out forwards; }
.compare-send-btn:not(:disabled):active { animation: glassPress 0.2s ease forwards; }
.compare-send-btn:disabled { opacity: 0.4; }
.compare-cost-hint { font-size: 12px; color: var(--hint); }
.compare-results {
  flex: 1;
  overflow-x: auto;
  overflow-y: hidden;
  display: flex;
  gap: 0;
  min-height: 0;
}
.compare-col {
  min-width: 280px;
  flex: 1;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--glass-border);
  height: 100%;
}
.compare-col:last-child { border-right: none; }
.compare-col-header {
  padding: 8px 12px;
  background: rgba(255,255,255,0.06);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  border-bottom: 1px solid var(--glass-border);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
  color: var(--text);
  flex-shrink: 0;
}
.compare-col-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}
.compare-col-footer {
  padding: 6px 12px;
  background: rgba(255,255,255,0.05);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  font-size: 11px;
  color: var(--hint);
  display: flex;
  gap: 10px;
  border-top: 1px solid var(--glass-border);
  flex-shrink: 0;
}
.compare-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--hint);
  padding: 24px;
  text-align: center;
}
.compare-empty svg { width: 48px; height: 48px; fill: var(--hint); opacity: 0.4; }

/* ===== PROFILE PAGE ===== */
.profile-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.profile-card {
  background: rgba(255,255,255,0.07);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--glass-shadow);
  position: relative;
  flex-shrink: 0;
}
.profile-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.28), transparent);
  pointer-events: none;
}
/* User hero card */
.profile-hero {
  background: linear-gradient(135deg,
    rgba(255,255,255,0.1) 0%,
    rgba(255,255,255,0.05) 100%) !important;
  border: 1px solid rgba(255,255,255,0.18) !important;
}
.profile-hero-body {
  display: flex;
  align-items: center;
  gap: 16px;
}
.profile-avatar {
  width: 58px; height: 58px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--grad1), var(--grad2));
  color: #fff;
  font-size: 22px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4), 0 0 0 2px rgba(255,255,255,0.12);
}
.profile-hero-info { flex: 1; min-width: 0; }
.profile-name { font-size: 17px; font-weight: 700; color: var(--text); line-height: 1.25; }
.profile-id { font-size: 12px; color: var(--hint); margin-top: 4px; }
/* Section header */
.profile-card h3 {
  font-size: 11px;
  font-weight: 600;
  color: var(--hint);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}
/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.stat-item {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 10px;
  padding: 10px 12px;
}
.stat-value {
  font-size: 19px; font-weight: 700;
  background: linear-gradient(135deg, var(--grad1), var(--grad2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.2;
}
.stat-label { font-size: 11px; color: var(--hint); margin-top: 2px; }
/* Model stats */
.model-stat-row {
  display: flex;
  align-items: center;
  padding: 7px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  gap: 8px;
}
.model-stat-row:last-child { border-bottom: none; }
.model-stat-name {
  font-size: 13px; flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text);
}
.model-stat-right { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.model-stat-cost {
  font-size: 12px; font-weight: 600;
  background: linear-gradient(135deg, var(--grad1), var(--grad2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.model-stat-reqs { font-size: 11px; color: var(--hint); }
/* Spend chart */
.spend-chart { display: flex; align-items: flex-end; gap: 3px; height: 56px; }
.spend-bar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; }
.spend-bar {
  width: 100%;
  background: linear-gradient(to top, var(--grad1), var(--grad2));
  border-radius: 3px 3px 0 0;
  min-height: 2px;
  opacity: 0.7;
}
.spend-bar-label { font-size: 9px; color: var(--hint); writing-mode: vertical-lr; transform: rotate(180deg); }
/* Form rows in profile */
.profile-form-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}
.profile-form-row label {
  font-size: 12px;
  color: var(--hint);
  font-weight: 500;
}

/* ===== UTILITIES ===== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 12px;
  color: var(--hint);
  padding: 32px;
  text-align: center;
}
.empty-state svg { width: 56px; height: 56px; fill: var(--hint); opacity: 0.3; }
.empty-state p { font-size: 15px; }

/* ===== HISTORY PAGE ===== */
.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.history-card {
  display: flex;
  align-items: stretch;
  gap: 12px;
  background: rgba(255,255,255,0.06);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 16px;
  padding: 12px 12px 12px 14px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.1);
  transition: background 0.15s, transform 0.15s;
}
.history-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  pointer-events: none;
}
.history-card:active {
  background: rgba(255,255,255,0.1);
  transform: scale(0.985);
}
.history-card-bar {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  border-radius: 3px 0 0 3px;
}
.history-card-icon {
  width: 44px; height: 44px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.history-card-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.history-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.history-card-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-card-time {
  font-size: 11px;
  color: var(--hint);
  flex-shrink: 0;
}
.history-card-preview {
  font-size: 13px;
  color: var(--hint);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.4;
}
.history-card-preview.preview-user { color: rgba(255,255,255,0.5); }
.history-card-preview.preview-ai   { color: rgba(255,255,255,0.35); }
.history-card-meta {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 11px;
  color: var(--hint);
  margin-top: 2px;
}

@media (max-width: 400px) {
  .compare-col { min-width: 240px; }
}
