/* Mini App «Улучши свой опыт телеграм».
   Всё собрано из материалов переписки: пузыри с хвостиком, закреп, поле ввода, «печатает…».
   Две схемы — ночная (по умолчанию) и дневная; app.js ставит html[data-scheme] по теме Telegram. */

:root {
  color-scheme: dark;
  --font: "Geologica", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --bg: #0e2428;         /* петроль */
  --panel: #17343a;
  --line: #2b5058;
  --text: #edf5f0;
  --muted: #94afab;
  --accent: #ffd25e;     /* масло: исходящие пузыри и всё, что про Stars */
  --on-accent: #2b2100;
  --accent-ink: #ffd25e; /* акцент как цвет текста и мелких знаков */
  --ok: #7be0ae;
  --bad: #ff8a78;
  --in: #21464d;         /* входящий пузырь */
  --stage: #0a1b1f;
  --doodle: rgba(237, 245, 240, .075);
  --quiet: rgba(237, 245, 240, .09);
}

html[data-scheme="light"] {
  color-scheme: light;
  --bg: #e3eee8;
  --panel: #f6faf7;
  --line: #c9dad2;
  --text: #0e2428;
  --muted: #536e6a;
  --accent: #ffc93c;
  --on-accent: #2b2100;
  --accent-ink: #7d5800;
  --ok: #0b7f4d;
  --bad: #c2371f;
  --in: #ffffff;
  --stage: #cbddd5;
  --doodle: rgba(14, 36, 40, .1);
  --quiet: rgba(14, 36, 40, .075);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 18px 18px calc(100px + env(safe-area-inset-bottom));
}

h1 { font-size: 32px; line-height: 1.05; font-weight: 800; letter-spacing: -.025em; margin: 6px 0 18px; }
h2 { font-size: 19px; line-height: 1.2; font-weight: 700; letter-spacing: -.012em; margin: 32px 0 12px; }
p { margin: 0; }
a { color: inherit; }

.hint { color: var(--muted); font-size: 13.5px; line-height: 1.45; }
.hint-gap { margin-top: 12px; }
main > .hint { padding: 0 4px; }
.lead { color: var(--muted); margin: -8px 0 16px; }

code {
  font: 600 .93em/1.3 var(--font);
  padding: 2px 7px;
  border-radius: 8px;
  background: var(--quiet);
  white-space: nowrap;
}

:focus-visible { outline: 2px solid var(--accent-ink); outline-offset: 2px; }

/* ---------- состояния: загрузка, ошибка, «открой из Telegram» ---------- */

.state {
  min-height: 62vh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 16px;
  text-align: center;
  color: var(--muted);
}
.state .btn { width: auto; }

.typing {
  display: inline-flex;
  gap: 5px;
  padding: 15px 17px;
  background: var(--in);
  border-radius: 18px 18px 18px 5px;
}
.typing i {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: typing 1.2s infinite both;
}
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes typing {
  0%, 60%, 100% { opacity: .35; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* ---------- кнопки ---------- */

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 50px;
  padding: 10px 18px;
  border: 0;
  border-radius: 16px;
  background: var(--accent);
  color: var(--on-accent);
  font: 600 15px/1.25 var(--font);
  cursor: pointer;
  transition: transform .12s ease, opacity .15s ease;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-quiet { background: var(--quiet); color: var(--text); }
.btn-danger { background: color-mix(in srgb, var(--bad) 16%, transparent); color: var(--bad); }
.btn-small { width: auto; min-height: 38px; padding: 6px 15px; border-radius: 999px; font-size: 14px; flex: none; }
.btn-gap { margin-top: 14px; }

/* ---------- главная: шапка как у чата ---------- */

.who { display: flex; align-items: center; gap: 14px; margin: 4px 0 18px; }
.avatar {
  flex: none;
  width: 56px; height: 56px;
  border-radius: 50%;
  overflow: hidden;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 23px;
  font-weight: 800;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.who h1 { font-size: 27px; margin: 0; overflow-wrap: anywhere; }
.who-status { display: flex; align-items: center; gap: 7px; margin-top: 5px; font-size: 14px; line-height: 1.2; }
.who-status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.is-ok { color: var(--ok); }
.is-bad { color: var(--bad); }

/* тариф — как закреплённое сообщение */
.pin {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 12px 12px 14px;
  background: var(--panel);
  border-radius: 18px;
}
.pin::before { content: ""; align-self: stretch; flex: none; width: 3px; border-radius: 3px; background: var(--accent); }
.pin-bad::before { background: var(--bad); }
.pin-body { flex: 1; min-width: 0; }
.pin-title { font-weight: 700; line-height: 1.3; }
.pin-text { color: var(--muted); font-size: 13.5px; line-height: 1.4; }

.warn {
  margin-top: 10px;
  padding: 12px 14px;
  border-radius: 18px;
  background: color-mix(in srgb, var(--bad) 14%, transparent);
  color: var(--bad);
  font-size: 14px;
  line-height: 1.4;
}

/* ---------- панели и строки ---------- */

.panel { background: var(--panel); border-radius: 22px; padding: 16px; }

.rows { background: var(--panel); border-radius: 22px; padding: 3px 16px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 13px 0; }
.row + .row { border-top: 1px solid var(--line); }
.rows > :is(.row, .switch, .cmd, .field-row):not(:first-child) { border-top: 1px solid var(--line); }
.row-top { align-items: flex-start; }
.row-wrap { flex-wrap: wrap; }
.row-name { display: flex; flex-direction: column; min-width: 0; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.row-sub { color: var(--muted); font-size: 13px; font-weight: 400; }
.row-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; margin-left: auto; }
.row-label { color: var(--muted); }
.row-value { font-weight: 600; text-align: right; }
.row-text { color: var(--muted); font-size: 13.5px; text-align: right; }

.steps { list-style: none; counter-reset: step; margin: 0; padding: 0; display: grid; gap: 14px; }
.steps li { counter-increment: step; display: grid; grid-template-columns: 30px 1fr; gap: 12px; line-height: 1.4; }
.steps li::before {
  content: counter(step);
  width: 30px; height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 14px;
  font-weight: 800;
}
.steps li > span { padding-top: 4px; }
.steps b { font-weight: 700; }

/* ---------- сцена: команды разыгрываются в чате ---------- */

.chips { /* лента, как папки чатов: листается вбок */
  display: flex;
  gap: 7px;
  margin: 0 -18px 12px;
  padding: 2px 18px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  border: 0;
  min-height: 36px;
  padding: 6px 13px;
  border-radius: 999px;
  background: var(--quiet);
  color: var(--text);
  font: 500 14px/1.2 var(--font);
  cursor: pointer;
  flex: none;
  transition: background .18s ease, color .18s ease;
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); font-weight: 700; }

.stage {
  position: relative;
  isolation: isolate;
  height: 262px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 26px;
  background: var(--stage);
}
.stage::before { /* обои чата: слэш, звезда, пузырь, волна, таймер */
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--doodle);
  --tile: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140' fill='none' stroke='%23000' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M16 34l9-20M124 62l9-20M70 132l9-20'/%3E%3Cpath d='M88 12l2.5 5.2 5.7.8-4.1 4 1 5.6-5.1-2.7-5.1 2.7 1-5.6-4.1-4 5.7-.8z'/%3E%3Cpath d='M40 66h20a5 5 0 0 1 5 5v9a5 5 0 0 1-5 5H50l-6 5v-5h-4a5 5 0 0 1-5-5v-9a5 5 0 0 1 5-5z'/%3E%3Cpath d='M96 96v10M103 90v22M110 98v6M117 93v16'/%3E%3Ccircle cx='22' cy='112' r='8'/%3E%3Cpath d='M22 107v5l3.5 2'/%3E%3C/svg%3E");
  -webkit-mask: var(--tile) 0 0 / 140px 140px;
  mask: var(--tile) 0 0 / 140px 140px;
}

.chat {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 6px;
  padding: 14px 12px 10px;
}

.bubble {
  max-width: 82%;
  padding: 8px 13px;
  border-radius: 18px;
  font-size: 14.5px;
  line-height: 1.35;
  animation: pop .28s cubic-bezier(.2, .9, .3, 1.2) both;
}
.bubble-in { align-self: flex-start; background: var(--in); color: var(--text); border-bottom-left-radius: 5px; transform-origin: 0 100%; }
.bubble-out { align-self: flex-end; background: var(--accent); color: var(--on-accent); border-bottom-right-radius: 5px; transform-origin: 100% 100%; }
.gone { animation: vanish .36s ease-in both; }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.9); } }
@keyframes vanish { to { opacity: 0; transform: scale(.72); filter: blur(6px); } }

.note { /* то, что бот присылает лично тебе */
  align-self: stretch;
  padding: 9px 13px 10px;
  border: 1.5px dashed var(--accent-ink);
  border-radius: 16px;
  background: color-mix(in srgb, var(--accent) 11%, var(--stage));
  font-size: 13.5px;
  line-height: 1.38;
  animation: pop .28s cubic-bezier(.2, .9, .3, 1.2) both;
}
.note-from { display: block; margin-bottom: 1px; color: var(--accent-ink); font-size: 12px; font-weight: 700; }

.service {
  align-self: center;
  padding: 3px 11px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--text) 11%, var(--stage));
  color: var(--muted);
  font-size: 12.5px;
  animation: pop .28s ease both;
}

.voice, .track { display: flex; align-items: center; gap: 10px; padding: 2px 0; }
.play { flex: none; width: 32px; height: 32px; border-radius: 50%; background: currentColor; display: grid; place-items: center; }
.play::after { content: ""; margin-left: 3px; border: 6px solid transparent; border-left: 10px solid var(--play-hole); border-right: 0; }
.bubble-in .play { --play-hole: var(--in); }
.bubble-out .play { --play-hole: var(--accent); }
.wave { display: flex; align-items: center; gap: 2px; height: 24px; }
.wave i { width: 2.5px; height: calc(var(--h) * 1px); border-radius: 2px; background: currentColor; opacity: .8; }
.dur { font-size: 12px; opacity: .75; font-variant-numeric: tabular-nums; }
.track-title { display: block; font-weight: 700; }
.track-artist { display: block; font-size: 12.5px; opacity: .75; }

.timer {
  display: inline-grid;
  place-items: center;
  min-width: 23px; height: 23px;
  margin-left: 8px;
  border: 1.5px solid currentColor;
  border-radius: 50%;
  font-size: 11.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  vertical-align: 1px;
}

.video { /* маленький «кадр»: закат над холмом */
  align-self: flex-end;
  position: relative;
  overflow: hidden;
  width: 164px; height: 100px;
  border-radius: 16px;
  background: linear-gradient(#f3b79c 0 58%, #2f6f6a 58%);
  transition: width .6s cubic-bezier(.6, 0, .2, 1), border-radius .6s cubic-bezier(.6, 0, .2, 1);
  animation: pop .28s cubic-bezier(.2, .9, .3, 1.2) both;
  transform-origin: 100% 100%;
}
.video::before { content: ""; position: absolute; left: 50%; top: 30px; width: 34px; height: 34px; margin-left: -17px; border-radius: 50%; background: #fff3d1; }
.video::after { content: ""; position: absolute; left: -10%; right: -10%; top: 58%; bottom: -40%; border-radius: 50% 50% 0 0; background: #2f6f6a; }
.video-round { width: 100px; border-radius: 50%; }

.caret::after {
  content: "";
  display: inline-block;
  width: 1.5px; height: 1.05em;
  margin-left: 1px;
  background: currentColor;
  vertical-align: -2px;
  animation: caret .9s steps(1) infinite;
}
@keyframes caret { 50% { opacity: 0; } }

.composer { display: flex; align-items: flex-end; gap: 8px; margin: 0 10px 10px; }
.field {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 8px 15px;
  border-radius: 20px;
  background: var(--in);
  font-size: 14.5px;
  line-height: 1.35;
}
.field-reply { margin-bottom: 3px; padding-left: 8px; border-left: 2px solid var(--accent-ink); color: var(--accent-ink); font-size: 12px; font-weight: 700; }
.field-text { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.field-text:empty::before { content: "Сообщение"; color: var(--muted); }
.plane {
  flex: none;
  width: 40px; height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: var(--on-accent);
  transition: transform .14s ease;
}
.plane-hit { transform: scale(.82); }
.plane svg, .send svg { width: 20px; height: 20px; }

.stage-instant .bubble, .stage-instant .note, .stage-instant .service, .stage-instant .video { animation: none; }
.stage-instant .video { transition: none; }

.what { min-height: 3.1em; margin-top: 12px; line-height: 1.5; }
.what code { margin-right: 6px; }

/* ---------- тарифы ---------- */

.tier { background: var(--panel); border-radius: 24px; padding: 18px 16px 16px; margin-bottom: 14px; }
.tier-extended { background: color-mix(in srgb, var(--accent) 15%, var(--panel)); }
.tier-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.tier-head h2 { margin: 0; font-size: 23px; font-weight: 800; letter-spacing: -.02em; }
.tier-now { padding: 3px 10px; border-radius: 999px; background: var(--text); color: var(--bg); font-size: 12.5px; font-weight: 600; }

.feats { list-style: none; margin: 12px 0 16px; padding: 0; display: grid; gap: 7px; }
.feats li { display: flex; gap: 10px; font-size: 14.5px; line-height: 1.35; }
.feats li::before { content: "/"; color: var(--accent-ink); font-weight: 800; }

.offers { display: grid; gap: 8px; }
.offer { justify-content: space-between; text-align: left; padding: 9px 16px; min-height: 58px; }
.offer-name { display: flex; flex-direction: column; gap: 1px; }
.offer-per { display: inline-flex; align-items: center; gap: 3px; font-size: 12.5px; font-weight: 400; opacity: .72; }
.offer-per svg { width: 11px; height: 11px; }
.price { display: inline-flex; align-items: center; gap: 5px; font-size: 18px; font-weight: 800; white-space: nowrap; font-variant-numeric: tabular-nums; }
.price svg { width: 16px; height: 16px; }
.btn-quiet .price svg, .btn-quiet .offer-per svg { color: var(--accent-ink); }

.terms { white-space: pre-wrap; font-size: 13.5px; line-height: 1.55; }
.terms-box { margin-bottom: 14px; }

/* ---------- настройки ---------- */

.switch { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 13px 0; cursor: pointer; line-height: 1.35; }
.switch input {
  flex: none;
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  width: 52px; height: 32px;
  margin: 0;
  border-radius: 999px;
  background: var(--line);
  cursor: pointer;
  transition: background .2s ease;
}
.switch input::after {
  content: "";
  position: absolute;
  top: 4px; left: 4px;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--text);
  transition: transform .2s ease, background .2s ease;
}
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(20px); background: var(--on-accent); }
.rows > .hint { padding-bottom: 14px; }
.rows > .rows-lead { padding: 14px 0 6px; }
.rows > .btn { margin: 4px 0 13px; }
.rows > .choice { justify-content: flex-start; min-height: 44px; margin: 0 0 8px; text-align: left; }
.btn-icon { width: 38px; padding: 0; }

/* поля ввода и переключатель из двух-трёх вариантов */
.field-row { display: flex; align-items: center; gap: 8px; padding: 11px 0; }
.input {
  flex: 1;
  min-width: 0;
  height: 42px;
  padding: 0 14px;
  border: 0;
  border-radius: 14px;
  background: var(--quiet);
  color: var(--text);
  font: inherit;
}
.input::placeholder { color: var(--muted); }
.input-time { flex: none; font-weight: 600; font-variant-numeric: tabular-nums; }
.count-of { margin-left: 4px; color: var(--muted); font-size: 15px; font-weight: 500; }

.seg { display: flex; gap: 4px; padding: 4px; margin-bottom: 10px; border-radius: 16px; background: var(--quiet); }
.seg-item {
  flex: 1;
  min-height: 38px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font: 600 14px/1.2 var(--font);
  cursor: pointer;
}
.seg-item[aria-pressed="true"] { background: var(--panel); color: var(--text); }
.seg-item::first-letter { text-transform: uppercase; }

.lazy { min-height: 52px; }

/* ---------- команды ---------- */

.lead-h2 { margin: -4px 0 12px; }
.cmd { padding: 14px 0; }
.cmd code { white-space: normal; }
.cmd-name { font-weight: 700; }
.cmd p { margin-top: 6px; font-size: 14.5px; line-height: 1.45; }
.cmd .cmd-limit { color: var(--accent-ink); font-size: 13px; font-weight: 600; }

/* ---------- итоги месяца ---------- */

.wrapped { display: grid; gap: 16px; }
.split { display: flex; gap: 4px; height: 16px; }
.split i { flex-basis: 0; min-width: 16px; border-radius: 8px; }
.split-in { background: color-mix(in srgb, var(--text) 32%, transparent); }
.split-out { background: var(--accent); }
.split-legend { display: flex; justify-content: space-between; gap: 12px; margin-top: -8px; color: var(--muted); font-size: 13.5px; }
.split-legend b { margin-right: 5px; color: var(--text); font-size: 21px; font-weight: 800; font-variant-numeric: tabular-nums; }
.rank { list-style: none; counter-reset: rank; margin: 0; padding: 0; display: grid; gap: 9px; }
.rank li { counter-increment: rank; display: flex; align-items: center; gap: 10px; }
.rank li::before {
  content: counter(rank);
  flex: none;
  width: 24px; height: 24px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 12.5px;
  font-weight: 800;
}
.rank-name { flex: 1; min-width: 0; overflow: hidden; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.rank-count { color: var(--muted); font-variant-numeric: tabular-nums; }
.facts .row { padding: 9px 0; font-size: 14.5px; }
.facts .row-value { max-width: 62%; }

/* ---------- помощь: поле как у сообщения ---------- */

.compose { background: var(--panel); border-radius: 24px; padding: 6px; }
.compose:focus-within { outline: 2px solid var(--accent-ink); outline-offset: 0; }
.compose textarea {
  display: block;
  width: 100%;
  min-height: 132px;
  padding: 12px 12px 6px;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--text);
  font: inherit;
}
.compose textarea::placeholder { color: var(--muted); }
.compose-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 0 0 12px; }
.count { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.send { width: auto; min-height: 44px; padding: 8px 16px 8px 18px; border-radius: 999px; }

.fold { background: var(--panel); border-radius: 22px; padding: 0 16px; margin-top: 14px; }
.fold summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 15px 0; font-weight: 600; cursor: pointer; list-style: none; }
.fold summary::-webkit-details-marker { display: none; }
.fold summary::after {
  content: "";
  width: 9px; height: 9px;
  margin-right: 4px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: translateY(-2px) rotate(45deg);
  transition: transform .2s ease;
}
.fold[open] summary::after { transform: translateY(2px) rotate(225deg); }
.fold .terms { padding-bottom: 16px; color: var(--muted); }
.fold-first { margin-top: 0; }
.fold-body { padding-bottom: 16px; }

/* ---------- табы и тост ---------- */

.tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  justify-content: center;
  padding: 7px 8px calc(7px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.tab {
  flex: 1;
  max-width: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 3px 0;
  border: 0;
  background: none;
  color: var(--muted);
  font: 500 11.5px/1.2 var(--font);
  cursor: pointer;
}
.tab-ico { width: 58px; height: 30px; border-radius: 999px; display: grid; place-items: center; transition: background .2s ease, color .2s ease; }
.tab svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab.active { color: var(--text); font-weight: 700; }
.tab.active .tab-ico { background: var(--accent); color: var(--on-accent); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(92px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 36px);
  padding: 11px 16px;
  border-radius: 18px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.35;
  text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
