:root {
  --bg: var(--tg-theme-secondary-bg-color, #efeff4);
  --section: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #fff));
  --text: var(--tg-theme-text-color, #000);
  --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, #fff);
  --header: var(--tg-theme-section-header-text-color, var(--hint));
  --danger: var(--tg-theme-destructive-text-color, #e53935);
  --sep: color-mix(in srgb, var(--hint) 25%, transparent);
  --ok: #34a853;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
main { padding: 12px 12px 40px; max-width: 640px; margin: 0 auto; }

h1 { font-size: 20px; margin: 4px 4px 2px; }
.sub { color: var(--hint); margin: 0 4px 12px; font-size: 13px; }
.center { text-align: center; }
.muted { color: var(--hint); }

.section { margin-bottom: 18px; }
.section > h2 { font-size: 13px; font-weight: 500; text-transform: uppercase; letter-spacing: .02em;
  color: var(--header); margin: 0 14px 6px; }
.card { background: var(--section); border-radius: 12px; overflow: hidden; }
.note { color: var(--hint); font-size: 13px; margin: 6px 14px 0; }
.note.warn { color: var(--danger); }

.row { display: flex; align-items: center; gap: 12px; padding: 11px 14px; min-height: 46px; }
.row + .row { border-top: 1px solid var(--sep); }
.row .label { flex: 1; min-width: 0; }
.row .label small { display: block; color: var(--hint); font-size: 13px; margin-top: 1px; }
.row.disabled { opacity: .45; pointer-events: none; }
.row.clickable { cursor: pointer; }
.row.clickable:active { background: color-mix(in srgb, var(--hint) 12%, transparent); }
.chev { color: var(--hint); }

/* переключатель — как в Telegram: тонкая дорожка, круглый ползунок крупнее неё */
.switch { position: relative; width: 38px; height: 24px; flex: none; margin-right: 2px; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; left: 2px; right: 2px; top: 5px; height: 14px; border-radius: 7px;
  background: color-mix(in srgb, var(--hint) 50%, transparent); transition: background .2s; }
.switch span::after { content: ""; position: absolute; top: -3px; left: -2px; width: 20px; height: 20px;
  border-radius: 50%; background: #fff; transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.3), 0 0 0 .5px rgba(0,0,0,.06); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 4px; }

/* числа */
.stepper { display: flex; align-items: center; gap: 6px; flex: none; }
.stepper button { width: 32px; height: 32px; border-radius: 8px; border: 0; font-size: 18px;
  background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); cursor: pointer; }
.stepper output { min-width: 34px; text-align: center; font-variant-numeric: tabular-nums; font-weight: 600; }

.btn { border: 0; border-radius: 10px; padding: 9px 14px; font: inherit; font-weight: 500; cursor: pointer;
  background: var(--accent); color: var(--accent-text); }
.btn.secondary { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.danger { background: transparent; color: var(--danger); padding: 6px 8px; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }

input[type=text], input[type=number], input[type=datetime-local] { flex: 1; min-width: 0; border: 1px solid var(--sep);
  border-radius: 10px; padding: 9px 12px; font: inherit; background: var(--bg); color: var(--text); }
.give-line { display: flex; gap: 6px; }
.give-line input[type=number] { flex: 0 0 96px; }
.contest-form label { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 14px; }
.contest-form label input, .contest-form label select { flex: 0 1 60%; max-width: 60%; }
.contest-form label.check { justify-content: flex-start; }
.contest-form label.check input { flex: none; }
.quiz-opts { display: flex; flex-direction: column; gap: 6px; }
.contest-form .quiz-opts label.check input[type="text"] { flex: 1 1 auto; max-width: none; }
.mini-list { display: flex; flex-direction: column; gap: 3px; font-size: 14px; }
.mini-list a { color: var(--text); text-decoration: none; }
.seg.views button { font-size: 13px; padding: 7px 2px; }

.row.column { flex-direction: column; align-items: stretch; gap: 8px; }
textarea { width: 100%; border: 1px solid var(--sep); border-radius: 10px; padding: 9px 12px; resize: vertical;
  font: 14px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--bg); color: var(--text); }
select { flex: none; max-width: 48%; border: 1px solid var(--sep); border-radius: 10px; padding: 7px 10px;
  font: inherit; background: var(--bg); color: var(--text); }

.seg { display: flex; gap: 4px; background: var(--section); border-radius: 10px; padding: 3px; margin-bottom: 14px; }
.seg button { flex: 1; border: 0; border-radius: 8px; padding: 7px 4px; font: inherit; font-size: 14px;
  background: transparent; color: var(--text); cursor: pointer; }
.seg button.on { background: var(--accent); color: var(--accent-text); }
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 18px; }
.tile { background: var(--section); border-radius: 12px; padding: 12px; text-align: center; }
.tile b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.tile span { color: var(--hint); font-size: 13px; }
.chart { display: flex; align-items: flex-end; gap: 2px; height: 120px; padding: 14px 14px 4px; }
.bar { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; min-width: 2px; }
.chart-axis { display: flex; justify-content: space-between; color: var(--hint); font-size: 12px; padding: 0 14px 10px; }
.rank { width: 22px; color: var(--hint); font-variant-numeric: tabular-nums; }

/* статистика */
.seg.views { margin-bottom: 12px; }
.seg.views button { font-size: 13px; }
.tiles.four { grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 6px; }
.tiles.four .tile { padding: 10px 4px; }
.tiles.four .tile b { font-size: 19px; }
.tiles.four .tile span { font-size: 12px; }
.tile em { display: block; font-style: normal; font-size: 12px; color: var(--hint); margin-top: 2px; }
.tile em.up { color: var(--ok); }
.tile em.down { color: var(--danger); }
.tiles-note { margin: 0 4px 18px; }
.hm-card { padding: 12px 12px 8px; }
.hm { display: grid; grid-template-columns: 22px repeat(24, 1fr); gap: 2px; align-items: center; }
.hm i { display: block; aspect-ratio: 1; border-radius: 2px; background: var(--accent); }
.hm-l { font-size: 10px; color: var(--hint); }
.hm-axis { display: grid; grid-template-columns: 22px repeat(4, 6fr) 0fr; font-size: 10px; color: var(--hint); margin-top: 4px; }
.chips { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 10px; padding-bottom: 2px; scrollbar-width: none; }
.chips button { flex: none; border: 1px solid var(--sep); border-radius: 16px; padding: 6px 12px; font: inherit;
  font-size: 13px; background: var(--section); color: var(--text); cursor: pointer; }
.chips button.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.search { margin-bottom: 10px; }
.search input { width: 100%; border: 1px solid var(--sep); border-radius: 10px; padding: 9px 12px; font: inherit;
  background: var(--section); color: var(--text); }
.sort { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 4px 12px; font-size: 14px; }
.sort select { max-width: 70%; }
.more { display: block; margin: 10px auto 0; }
.export { display: block; width: 100%; margin: 18px 0 6px; }
.val { color: var(--hint); text-align: right; font-size: 14px; }
.link-card .row b { font-weight: 600; }
.link-nums { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; padding: 4px 0 10px; }
.link-nums b { display: block; font-size: 18px; }
.link-nums span { color: var(--hint); font-size: 12px; }
a { color: var(--link); text-decoration: none; }

/* нижняя панель — «парящая» капсула */
body.with-nav main { padding-bottom: calc(100px + env(safe-area-inset-bottom)); }
.tabbar { position: fixed; z-index: 10; display: flex; gap: 2px;
  left: 12px; right: 12px; bottom: calc(10px + env(safe-area-inset-bottom));
  max-width: 520px; margin: 0 auto; padding: 5px; border-radius: 28px;
  background: color-mix(in srgb, var(--section) 82%, transparent);
  -webkit-backdrop-filter: blur(20px) saturate(1.6); backdrop-filter: blur(20px) saturate(1.6);
  border: .5px solid color-mix(in srgb, var(--hint) 22%, transparent);
  box-shadow: 0 6px 24px rgba(0,0,0,.14), 0 1px 4px rgba(0,0,0,.08); }
.tabbar button { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 1px;
  border: 0; border-radius: 23px; background: transparent; color: var(--hint); font: inherit; font-size: 11px;
  padding: 5px 0 4px; cursor: pointer; transition: background .2s, color .2s; }
.tabbar button > span:last-child { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 2px; }
.tabbar button .ico { position: relative; font-size: 20px; line-height: 1.2; }
.tabbar button .em { filter: grayscale(1); opacity: .7; }
.tabbar button.on { color: var(--accent); background: color-mix(in srgb, var(--accent) 13%, transparent); }
.tabbar button.on .em { filter: none; opacity: 1; }
/* узкие экраны (маленькие смартфоны, внешний экран раскладушек) */
@media (max-width: 360px) {
  main { padding-left: 8px; padding-right: 8px; }
  .tabbar { left: 8px; right: 8px; padding: 4px; }
  .tabbar button { font-size: 10px; letter-spacing: -.2px; }
  .tiles.four .tile b { font-size: 16px; }
}
@media (max-width: 300px) {
  .tabbar button > span:last-child { display: none; }  /* только значки */
  .tabbar button { padding: 8px 0; }
}
/* планшеты и развёрнутые раскладушки: колонка не растягивается на весь экран */
@media (min-width: 700px) {
  main { padding-top: 20px; }
  .tabbar { max-width: 560px; }
}
body.with-nav #toast { bottom: calc(90px + env(safe-area-inset-bottom)); }
.tabbar .dot { position: absolute; top: 0; right: -5px; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }

.chat-head.clickable { cursor: pointer; }
.chat-head .chev { font-size: 15px; }
.banner { background: color-mix(in srgb, var(--danger) 12%, var(--section)); color: var(--text);
  border-radius: 12px; padding: 12px 14px; margin-bottom: 18px; display: grid; gap: 4px; }
.banner small { color: var(--hint); font-size: 13px; }
.banner.info { background: color-mix(in srgb, var(--accent) 12%, var(--section)); }
.banner.clickable { cursor: pointer; }
.section.alert > h2 { color: var(--danger); }
.mode-hint { color: var(--hint); font-size: 13px; margin-top: -2px; }
.contest-form .pair { display: flex; gap: 6px; flex: 0 1 60%; max-width: 60%; }
.contest-form .pair input { flex: 0 0 64px; max-width: 64px; }
.contest-form .pair select { flex: 1; max-width: none; }
.form-sep { font-size: 13px; font-weight: 500; text-transform: uppercase; letter-spacing: .02em; color: var(--header);
  margin-top: 8px; padding-top: 10px; border-top: 1px solid var(--sep); }

.status-ok { color: var(--ok); }
.status-bad { color: var(--danger); }
code.cmd { display: block; padding: 10px 12px; border-radius: 8px; background: var(--bg); font-size: 15px;
  user-select: all; margin-top: 6px; }

#toast { position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 20px); opacity: 0;
  background: rgba(0,0,0,.8); color: #fff; padding: 9px 14px; border-radius: 10px; font-size: 14px;
  transition: opacity .2s, transform .2s; pointer-events: none; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--danger); }
