:root {
  --bg: var(--tg-theme-bg-color, #0d0f14);
  --card: var(--tg-theme-secondary-bg-color, #171a21);
  --text: var(--tg-theme-text-color, #f4f5f7);
  --hint: var(--tg-theme-hint-color, #8b909b);
  --link: var(--tg-theme-link-color, #6ea8ff);
  --accent: var(--tg-theme-button-color, #5b8cff);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --like: #ff4d6d;
  --skip: #8b909b;
  --radius: 24px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

body::before {
  content: "";
  position: fixed;
  inset: -20% -20% auto -20%;
  height: 55%;
  background: radial-gradient(circle at 30% 10%, color-mix(in srgb, var(--accent) 26%, transparent), transparent 65%);
  pointer-events: none;
  filter: blur(40px);
  opacity: .55;
}

.app {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  max-width: 520px;
  margin: 0 auto;
}

.hidden { display: none !important; }

/* ---------------------------------------------------------------- top */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 2px 12px;
  flex: 0 0 auto;
}

.logo {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.04em;
}
.logo .dot { color: var(--accent); }

.switch {
  display: flex;
  background: rgba(127, 127, 127, .16);
  background: color-mix(in srgb, var(--text) 8%, transparent);
  border-radius: 999px;
  padding: 3px;
}
.sw {
  border: 0;
  background: transparent;
  color: var(--hint);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: .2s;
}
.sw.active {
  background: var(--card);
  color: var(--text);
  box-shadow: 0 4px 14px rgba(0,0,0,.18);
}

/* ---------------------------------------------------------------- views */

.view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 2px 10px;
  flex: 0 0 auto;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  border: 1px solid rgba(127, 127, 127, .28);
  border-color: color-mix(in srgb, var(--text) 12%, transparent);
  background: transparent;
  color: var(--hint);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 13px;
  border-radius: 999px;
  cursor: pointer;
  transition: .18s;
}
.chip.active {
  background: var(--text);
  border-color: var(--text);
  color: var(--bg);
}

/* ---------------------------------------------------------------- cards */

.stack {
  position: relative;
  flex: 1;
  min-height: 0;
  margin: 0 2px;
  touch-action: pan-y;
}

.card {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 18px 50px rgba(0,0,0,.28);
  will-change: transform;
  transform-origin: 50% 120%;
  touch-action: pan-y;
}

.card.behind-1 { transform: scale(.955) translateY(12px); filter: brightness(.92); }
.card.behind-2 { transform: scale(.91) translateY(24px); filter: brightness(.84); }

.card.fly-right { transition: transform .24s ease-out, opacity .24s; transform: translateX(120%) rotate(16deg); opacity: 0; }
.card.fly-left { transition: transform .24s ease-out, opacity .24s; transform: translateX(-120%) rotate(-16deg); opacity: 0; }

.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 14px;
  flex: 0 0 auto;
}
.ava {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 15px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), #b06bff);
  flex: 0 0 auto;
}
.ava.big { width: 62px; height: 62px; font-size: 24px; margin: 0 auto 10px; }
.ch-meta { min-width: 0; flex: 1; }
.ch-title {
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ch-sub {
  font-size: 12px;
  color: var(--hint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 5px 9px;
  border-radius: 999px;
  background: rgba(91, 140, 255, .16);
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent);
  flex: 0 0 auto;
}

.card-media {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: #20242e;
  background:
    radial-gradient(circle at 25% 20%, color-mix(in srgb, var(--accent) 40%, transparent), transparent 60%),
    linear-gradient(160deg, #262a35, #12141a);
  overflow: hidden;
}
.card-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.card-media .noimg {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 46px;
  opacity: .9;
}
.play {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(6px);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 22px;
  padding-left: 4px;
}

.stamp {
  position: absolute;
  top: 18px;
  padding: 7px 12px;
  border: 3px solid currentColor;
  border-radius: 10px;
  font-weight: 900;
  font-size: 19px;
  letter-spacing: .08em;
  opacity: 0;
  transform: rotate(-12deg);
  pointer-events: none;
}
.stamp.like { left: 16px; color: var(--like); }
.stamp.nope { right: 16px; color: #6fd3ff; transform: rotate(12deg); }

.card-body {
  padding: 13px 15px 14px;
  flex: 0 0 auto;
  max-height: 38%;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.caption {
  margin: 0;
  font-size: 14.5px;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-word;
}
.caption.expanded { display: block; -webkit-line-clamp: unset; }
.card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
  font-size: 13px;
  color: var(--hint);
}
.card-foot .likes { font-weight: 700; color: var(--text); }
.open-link { color: var(--link); text-decoration: none; font-weight: 600; }

/* ---------------------------------------------------------------- controls */

.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 12px 0 2px;
  flex: 0 0 auto;
}
.orb {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: 1px solid rgba(127, 127, 127, .22);
  border-color: color-mix(in srgb, var(--text) 10%, transparent);
  background: var(--card);
  color: var(--text);
  display: grid;
  place-items: center;
  font-size: 25px;
  cursor: pointer;
  box-shadow: 0 10px 26px rgba(0,0,0,.22);
  transition: transform .12s;
}
.orb:active { transform: scale(.92); }
.orb.like { color: var(--like); border-color: color-mix(in srgb, var(--like) 40%, transparent); }
.orb.skip { color: var(--skip); width: 54px; height: 54px; font-size: 21px; }
.orb.open { width: 44px; height: 44px; font-size: 17px; color: var(--hint); }
.orb:disabled { opacity: .35; }

.tip {
  text-align: center;
  color: var(--hint);
  font-size: 11.5px;
  margin: 6px 0 0;
  flex: 0 0 auto;
}

/* ---------------------------------------------------------------- empty / loading */

.loading, .empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 28px;
  color: var(--hint);
}
.empty h2 { color: var(--text); font-size: 20px; margin: 10px 0 6px; }
.empty p { margin: 0 0 18px; font-size: 14px; line-height: 1.5; max-width: 290px; }
.empty-emoji { font-size: 44px; }
.pulse {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.1s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(.75); opacity: .45; }
  50% { transform: scale(1); opacity: 1; }
}

/* ---------------------------------------------------------------- channels */

.searchrow {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border-radius: 14px;
  padding: 0 12px;
  flex: 0 0 auto;
}
.search-ico { color: var(--hint); font-size: 18px; }
.searchrow input {
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  padding: 12px 0;
}

.chlist {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 4px 2px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chitem {
  display: flex;
  align-items: center;
  gap: 11px;
  background: var(--card);
  border-radius: 16px;
  padding: 11px 12px;
}
.chitem .ch-meta { min-width: 0; }
.chitem .go {
  border: 0;
  background: rgba(91, 140, 255, .16);
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent);
  font: inherit;
  font-size: 12.5px;
  font-weight: 700;
  padding: 8px 12px;
  border-radius: 999px;
  cursor: pointer;
  flex: 0 0 auto;
}
.tags { font-size: 11.5px; color: var(--hint); margin-top: 2px; }
.chlist .none { text-align: center; color: var(--hint); padding: 30px 0; font-size: 14px; }

.addbox {
  flex: 0 0 auto;
  background: var(--card);
  border-radius: 16px;
  padding: 2px 14px;
  margin-bottom: 2px;
}
.addbox summary {
  cursor: pointer;
  padding: 12px 0;
  font-weight: 700;
  font-size: 14px;
  list-style: none;
}
.addbox summary::-webkit-details-marker { display: none; }
.addform { padding: 2px 0 14px; display: flex; flex-direction: column; gap: 8px; }
.addform input {
  border: 1px solid color-mix(in srgb, var(--text) 12%, transparent);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  padding: 10px 12px;
  border-radius: 11px;
  outline: 0;
}
.row2 { display: flex; gap: 8px; }
.row2 input { flex: 1; min-width: 0; }
.hint { font-size: 11.5px; color: var(--hint); margin: 2px 0 0; line-height: 1.4; }

/* ---------------------------------------------------------------- buttons */

.primary, .secondary, .ghost {
  border: 0;
  font: inherit;
  font-weight: 700;
  padding: 13px 16px;
  border-radius: 13px;
  cursor: pointer;
  width: 100%;
}
.primary { background: var(--accent); color: var(--accent-text); }
.secondary {
  background: rgba(127, 127, 127, .14);
  background: color-mix(in srgb, var(--text) 9%, transparent);
  color: var(--text);
}
.ghost { background: transparent; color: var(--hint); padding: 10px; }

/* ---------------------------------------------------------------- sheet */

.sheet {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  animation: fade .18s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.sheet-card {
  width: 100%;
  max-width: 520px;
  background: var(--bg);
  border-radius: 24px 24px 0 0;
  padding: 24px 22px calc(18px + env(safe-area-inset-bottom));
  text-align: center;
  animation: rise .24s cubic-bezier(.2,.8,.2,1);
}
@keyframes rise { from { transform: translateY(40px); } }
.sheet-card h3 { margin: 0 0 6px; font-size: 19px; }
.sheet-card p { color: var(--hint); font-size: 13.5px; line-height: 1.5; margin: 0 0 18px; }
.sheet-card button { margin-bottom: 8px; }

/* ---------------------------------------------------------------- toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: 92px;
  transform: translate(-50%, 20px);
  background: rgba(20,22,28,.92);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: .2s;
  z-index: 80;
  max-width: 86vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------------------------------------------------------- hearts */

.heart-burst {
  position: fixed;
  font-size: 22px;
  pointer-events: none;
  z-index: 70;
  animation: burst .7s ease-out forwards;
}
@keyframes burst {
  from { transform: translate(-50%, -50%) scale(.6); opacity: 1; }
  to { transform: translate(-50%, -160%) scale(1.5); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
