:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --link: var(--tg-theme-link-color, #2481cc);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --section: var(--tg-theme-section-bg-color, var(--bg));
  --danger: #e5484d;
  --ok: #30a46c;
  --bubble-own: color-mix(in srgb, var(--accent) 18%, var(--bg));
  --radius: 14px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg2); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
#app { min-height: 100vh; padding-bottom: calc(64px + env(safe-area-inset-bottom)); }

/* нижние вкладки */
#tabs { position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--bg);
  border-top: 1px solid color-mix(in srgb, var(--hint) 25%, transparent);
  padding-bottom: env(safe-area-inset-bottom); z-index: 10; }
#tabs button { flex: 1; padding: 8px 0 6px; font-size: 11px; color: var(--hint); display: flex;
  flex-direction: column; align-items: center; gap: 2px; }
#tabs button span { font-size: 20px; filter: grayscale(1); opacity: .7; }
#tabs button.active { color: var(--accent); }
#tabs button.active span { filter: none; opacity: 1; }
body.in-chat #tabs { display: none; }
body.in-chat #app { padding-bottom: 0; }

h1 { font-size: 26px; margin: 18px 16px 8px; }
.sub { color: var(--hint); font-size: 13px; margin: 0 16px 12px; }
.section { background: var(--section); border-radius: var(--radius); margin: 10px 12px; overflow: hidden; }
.section-title { color: var(--hint); font-size: 12px; text-transform: uppercase; letter-spacing: .4px;
  margin: 18px 28px 6px; }
.empty { text-align: center; color: var(--hint); padding: 48px 24px; }
.empty b { display: block; font-size: 44px; margin-bottom: 8px; }

/* список чатов */
.chat-row { display: flex; gap: 12px; align-items: center; padding: 10px 14px; width: 100%; text-align: left; }
.chat-row + .chat-row { border-top: 1px solid color-mix(in srgb, var(--hint) 15%, transparent); }
.avatar { width: 46px; height: 46px; border-radius: 50%; flex: none; display: grid; place-items: center;
  color: #fff; font-weight: 600; font-size: 18px; }
.chat-main { flex: 1; min-width: 0; }
.chat-top { display: flex; justify-content: space-between; gap: 8px; }
.chat-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-time { color: var(--hint); font-size: 12px; flex: none; }
.chat-bottom { display: flex; justify-content: space-between; gap: 8px; margin-top: 2px; }
.chat-preview { color: var(--hint); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { background: var(--accent); color: var(--accent-text); border-radius: 10px; font-size: 12px;
  min-width: 20px; height: 20px; padding: 0 6px; display: grid; place-items: center; flex: none; }

/* экран переписки */
.chat-head { position: sticky; top: 0; z-index: 5; background: var(--bg); display: flex; align-items: center;
  gap: 10px; padding: 8px 12px; border-bottom: 1px solid color-mix(in srgb, var(--hint) 20%, transparent); }
.chat-head .avatar { width: 36px; height: 36px; font-size: 15px; }
.chat-head .title { flex: 1; min-width: 0; }
.chat-head .title div:first-child { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head .title div:last-child { color: var(--hint); font-size: 12px; }
.icon-btn { font-size: 20px; padding: 6px; border-radius: 10px; }
.icon-btn:active { background: var(--bg2); }
.messages { padding: 14px 10px 24px; display: flex; flex-direction: column; gap: 4px; }
.day { align-self: center; background: color-mix(in srgb, var(--hint) 22%, transparent); color: var(--text);
  font-size: 12px; padding: 3px 10px; border-radius: 10px; margin: 10px 0 6px; }
.msg { max-width: 82%; padding: 6px 10px 5px; border-radius: 16px; background: var(--section);
  align-self: flex-start; position: relative; word-wrap: break-word; white-space: pre-wrap; }
.msg.own { align-self: flex-end; background: var(--bubble-own); }
.msg.deleted { background: color-mix(in srgb, var(--danger) 14%, var(--section)); outline: 1px dashed var(--danger); }
.msg .meta { display: flex; gap: 6px; justify-content: flex-end; font-size: 11px; color: var(--hint); margin-top: 2px; }
.msg .tag { font-size: 11px; font-weight: 600; }
.msg .tag.del { color: var(--danger); }
.msg .tag.edit { color: var(--link); cursor: pointer; }
.msg .history { font-size: 12px; color: var(--hint); border-left: 2px solid var(--link); padding-left: 6px;
  margin-top: 4px; display: none; }
.msg.show-history .history { display: block; }
.msg img, .msg video { display: block; max-width: 100%; max-height: 320px; border-radius: 10px; margin: 2px 0 4px; }
.msg img.sticker { max-width: 160px; background: none; }
.msg video.round { width: 200px; height: 200px; object-fit: cover; border-radius: 50%; }
.msg audio { width: 230px; max-width: 100%; margin: 2px 0; }
.msg .placeholder { color: var(--hint); font-style: italic; }
.load-more { align-self: center; color: var(--link); padding: 8px; font-size: 14px; }

/* карточки, статистика */
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 10px 12px; }
.card { background: var(--section); border-radius: var(--radius); padding: 12px; }
.card .big { font-size: 24px; font-weight: 700; }
.card .label { color: var(--hint); font-size: 12px; }
.compare { padding: 6px 14px 12px; }
.compare-row { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; padding: 6px 0; align-items: center; }
.compare-row + .compare-row { border-top: 1px solid color-mix(in srgb, var(--hint) 12%, transparent); }
.compare-row .l { text-align: left; font-weight: 600; }
.compare-row .r { text-align: right; font-weight: 600; }
.compare-row .c { color: var(--hint); font-size: 12px; text-align: center; }
.compare-head { display: grid; grid-template-columns: 1fr 1fr; padding: 10px 14px 0; font-size: 13px; }
.compare-head div:last-child { text-align: right; }
.chart { padding: 10px 12px 12px; }
.chart svg { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--hint); padding: 0 14px 10px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; vertical-align: 0; }

/* питомцы */
.pet { padding: 14px; display: flex; gap: 14px; align-items: center; width: 100%; text-align: left; }
.pet + .pet { border-top: 1px solid color-mix(in srgb, var(--hint) 15%, transparent); }
.pet-emoji { font-size: 46px; width: 64px; height: 64px; display: grid; place-items: center; flex: none;
  background: var(--bg2); border-radius: 18px; }
.pet-emoji.sad { filter: grayscale(.7); }
.pet-info { flex: 1; min-width: 0; }
.pet-name { font-weight: 700; font-size: 16px; }
.pet-chat { color: var(--hint); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar { height: 6px; background: var(--bg2); border-radius: 3px; overflow: hidden; margin: 6px 0 4px; }
.bar div { height: 100%; background: linear-gradient(90deg, var(--accent), #a855f7); border-radius: 3px; }
.pet-stats { display: flex; gap: 10px; font-size: 12px; color: var(--hint); flex-wrap: wrap; }
.pet-big { text-align: center; padding: 22px 16px 8px; }
.pet-big .e { font-size: 96px; line-height: 1.1; }
.pet-big .n { font-size: 22px; font-weight: 700; margin-top: 6px; }
.ach { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; padding: 12px; }
.ach div { text-align: center; font-size: 11px; color: var(--hint); }
.ach div span { display: block; font-size: 26px; }
.ach div.locked span { filter: grayscale(1); opacity: .35; }
.species { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 12px; }
.species button { background: var(--bg2); border-radius: 12px; padding: 10px 4px; font-size: 12px; }
.species button span { display: block; font-size: 30px; }
.species button.sel { outline: 2px solid var(--accent); }
.input { width: calc(100% - 24px); margin: 12px; padding: 12px; border-radius: 12px; border: 0;
  background: var(--bg2); color: var(--text); font: inherit; }

/* команды */
.cmd { padding: 12px 14px; }
.cmd + .cmd { border-top: 1px solid color-mix(in srgb, var(--hint) 15%, transparent); }
.cmd code { font: 600 14px ui-monospace, Menlo, monospace; color: var(--link); }
.cmd p { margin: 4px 0 0; color: var(--hint); font-size: 13px; }
.cmd .ex { display: inline-block; margin-top: 6px; background: var(--bg2); padding: 3px 8px; border-radius: 8px;
  font: 13px ui-monospace, Menlo, monospace; }

/* настройки */
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; width: 100%;
  text-align: left; }
.row + .row { border-top: 1px solid color-mix(in srgb, var(--hint) 15%, transparent); }
.row small { display: block; color: var(--hint); font-size: 12px; }
.switch { width: 50px; height: 30px; border-radius: 15px; background: color-mix(in srgb, var(--hint) 40%, transparent);
  position: relative; flex: none; transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch.on { background: var(--ok); }
.switch.on::after { transform: translateX(20px); }
select.input { appearance: none; }
.btn { display: block; width: calc(100% - 24px); margin: 12px; padding: 13px; border-radius: 12px;
  background: var(--accent); color: var(--accent-text); font-weight: 600; text-align: center; }
.btn.secondary { background: var(--section); color: var(--link); }

#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: rgba(0,0,0,.8); color: #fff; padding: 8px 14px; border-radius: 12px; font-size: 14px;
  transition: all .25s; pointer-events: none; z-index: 50; max-width: 90%; text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.spinner { margin: 60px auto; width: 28px; height: 28px; border: 3px solid var(--bg2); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
