:root {
  --bg: var(--tg-theme-secondary-bg-color, #efeff4);
  --card: 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);
  --btn: var(--tg-theme-button-color, #2481cc);
  --btn-text: var(--tg-theme-button-text-color, #fff);
  --danger: var(--tg-theme-destructive-text-color, #ff3b30);
  --sep: color-mix(in srgb, var(--text) 12%, transparent);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, Roboto, "Segoe UI", sans-serif;
  padding-bottom: 90px;
  -webkit-tap-highlight-color: transparent;
}

h1 {
  font-size: 20px;
  margin: 16px 16px 8px;
  display: flex;
  align-items: center;
  gap: 10px;
}

h1 img {
  width: 40px;
  height: 38px;
}

.hdr {
  font-size: 13px;
  text-transform: uppercase;
  color: var(--hint);
  margin: 20px 16px 6px;
  letter-spacing: .3px;
}

.sec {
  background: var(--card);
  border-radius: 12px;
  margin: 0 12px;
  overflow: hidden;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 8px 14px;
  border-top: 1px solid var(--sep);
}

.row:first-child {
  border-top: 0;
}

.row.tap {
  cursor: pointer;
}

.row .grow {
  flex: 1;
  min-width: 0;
}

.row .sub {
  color: var(--hint);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row .chev {
  color: var(--hint);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 14px;
  border-top: 1px solid var(--sep);
}

.field:first-child {
  border-top: 0;
}

.field label {
  font-size: 13px;
  color: var(--hint);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

input,
textarea,
select {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  padding: 4px 0;
  outline: none;
}

textarea {
  resize: none;
  height: 84px;
  overflow-y: auto;
}

textarea.big {
  height: 200px;
}

textarea.msg {
  height: 170px;
  font-size: 16px;
  line-height: 1.4;
}

textarea:disabled,
input:disabled {
  color: var(--hint);
}

.link {
  color: var(--link);
  background: none;
  border: 0;
  font: inherit;
  padding: 0;
  cursor: pointer;
}

.danger {
  color: var(--danger);
}

.btn {
  display: block;
  width: calc(100% - 24px);
  margin: 12px;
  padding: 12px;
  border: 0;
  border-radius: 12px;
  background: var(--btn);
  color: var(--btn-text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.btn.ghost {
  background: var(--card);
  color: var(--link);
}

.btn.red {
  background: var(--card);
  color: var(--danger);
}

.btn:disabled {
  opacity: .5;
}

.sw {
  position: relative;
  width: 50px;
  height: 30px;
  flex: none;
}

.sw input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}

.sw i {
  position: absolute;
  inset: 0;
  border-radius: 15px;
  background: color-mix(in srgb, var(--text) 20%, transparent);
  transition: .2s;
}

.sw i:after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  transition: .2s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
}

.sw input:checked+i {
  background: #34c759;
}

.sw input:checked+i:after {
  left: 22px;
}

.mosaic {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 3px;
}

.mrow {
  display: flex;
  gap: 3px;
}

.ph {
  position: relative;
  flex: 1;
  border-radius: 6px;
  overflow: hidden;
  background: var(--bg);
}

.mrow.r1 .ph {
  height: auto;
  background: #000;
}

.mrow.r1 .ph img {
  height: auto;
  max-height: 420px;
  object-fit: contain;
}

.mrow.r2 .ph {
  height: 170px;
}

.mrow.r3 .ph {
  height: 115px;
}

.ph img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.ph.dim img {
  opacity: .45;
}

/* Видео: обложка (или тёмная плитка без неё) и значок воспроизведения. */
.ph.vid {
  background: #222;
}

.ph .play {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  pointer-events: none;
}

.ph .play .ic {
  width: 44px;
  height: 44px;
  padding: 10px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .45);
  fill: currentColor;
}

.ph .ck {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: rgba(0, 0, 0, .35);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 14px;
}

.ph.on .ck {
  background: var(--btn);
  border-color: var(--btn);
}

.ph.add {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  color: var(--link);
  border: 2px dashed var(--sep);
  cursor: pointer;
  height: 64px;
  flex: none;
  width: 100%;
}

/* Пикер файлов: сам input лежит поверх плитки прозрачным — тап идёт прямо в него,
   а не через label/click(), которые часть WebView Telegram игнорирует. */
.ph.add input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  font-size: 0;
}

#upstat {
  padding: 0 10px 8px;
}

#upstat:empty {
  display: none;
}

.note {
  color: var(--hint);
  font-size: 13px;
  margin: 6px 16px;
}

.err {
  color: var(--danger);
  font-size: 14px;
  margin: 8px 16px;
  white-space: pre-wrap;
}

.inline {
  display: flex;
  gap: 8px;
  align-items: center;
}

.empty {
  padding: 14px;
  color: var(--hint);
  text-align: center;
}

.meta {
  font-size: 13px;
  color: var(--hint);
  padding: 8px 14px;
}

.meta a {
  color: var(--link);
  text-decoration: none;
}
.ck {
  cursor: pointer;
}

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.ic {
  vertical-align: -3px;
  margin-right: 2px;
}

/* ---------- motion: коротко, ease-out, только transform/opacity ---------- */
:root {
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
}

.btn,
.row.tap,
.tab,
.link,
.ph.add {
  transition: transform 160ms var(--ease-out), opacity 160ms var(--ease-out);
}

.btn:active,
.row.tap:active,
.ph.add:active {
  transform: scale(0.97);
}

.link:active {
  opacity: .6;
}

/* Экран входит целиком: чуть снизу, быстро */
#app > * {
  animation: screen-in 220ms var(--ease-out) both;
}

@keyframes screen-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* Переключатель */
.sw i,
.sw i:after {
  transition: background-color 180ms ease, left 180ms var(--ease-out);
}

/* Фото: появляется по загрузке, галочка отзывается на тап */
.ph img {
  opacity: 0;
  transition: opacity 240ms ease;
}

.ph img[src] {
  opacity: 1;
}

.ph.dim img[src] {
  opacity: .45;
}

.ph .ck {
  transition: transform 160ms var(--ease-out), background-color 160ms ease;
}

.ph .ck:active {
  transform: scale(0.85);
}

/* Просмотрщик: не из ничего, а из почти-полного размера */
.lightbox {
  opacity: 1;
  transition: opacity 180ms var(--ease-out);
}

.lightbox img {
  transform: scale(1);
  transition: transform 220ms var(--ease-out);
}

.lightbox.closing {
  opacity: 0;
}

.lightbox.closing img {
  transform: scale(0.97);
}

@starting-style {
  .lightbox {
    opacity: 0;
  }

  .lightbox img {
    transform: scale(0.96);
  }
}

@media (prefers-reduced-motion: reduce) {
  #app > * {
    animation: none;
  }

  .btn:active,
  .row.tap:active,
  .ph.add:active,
  .ph .ck:active {
    transform: none;
  }

  .lightbox img,
  .lightbox.closing img {
    transform: none;
  }
}

/* Полоска загрузки: видна, пока идёт запрос; цвет кнопки Telegram */
body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 30%;
  background: var(--btn);
  border-radius: 0 3px 3px 0;
  opacity: 0;
  transform: translateX(-100%);
  z-index: 20;
  pointer-events: none;
  transition: opacity 120ms ease;
}

body.busy::before {
  opacity: 1;
  animation: loading 900ms cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

@keyframes loading {
  from { transform: translateX(-100%); }
  to { transform: translateX(333%); }
}

body.busy .row.tap,
body.busy .btn {
  cursor: progress;
}
