/* Кадр — Telegram Mini App.
   Фон и текст берём из темы Telegram, акцент — фирменный оранжевый. */
:root {
  --bg: var(--tg-theme-bg-color, #141416);
  --bg-2: var(--tg-theme-secondary-bg-color, #1d1d21);
  --text: var(--tg-theme-text-color, #f3f1ee);
  --hint: var(--tg-theme-hint-color, #8e8c93);
  --link: var(--tg-theme-link-color, #ff8a50);
  --sep: color-mix(in srgb, var(--text) 10%, transparent);
  --accent: #ff6a2b;
  --accent-ink: #ffffff;
  --accent-soft: color-mix(in srgb, var(--accent) 16%, transparent);
  --skip: color-mix(in srgb, var(--text) 55%, transparent);
  --film: #0b0b0c;
  --r-lg: 22px;
  --r-md: 14px;
  --r-sm: 10px;
  --safe-b: max(env(safe-area-inset-bottom), var(--tg-safe-area-inset-bottom, 0px));
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 16px/1.4 var(--font); }
body { overscroll-behavior: none; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
a { color: var(--link); text-decoration: none; }
img { display: block; }

#app { min-height: 100%; display: flex; flex-direction: column; }
.screen { flex: 1; display: flex; flex-direction: column; padding: 16px 16px calc(16px + var(--safe-b)); max-width: 560px; width: 100%; margin: 0 auto; }
.screen.has-tabs { padding-bottom: calc(84px + var(--safe-b)); }

/* ---------- типографика ---------- */
.logo { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 20px; letter-spacing: -0.02em; }
.logo-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); display: grid; place-items: center; }
.display { font-size: 34px; line-height: 1.02; font-weight: 800; letter-spacing: -0.035em; margin: 28px 0 10px; }
.title { font-size: 24px; line-height: 1.1; font-weight: 800; letter-spacing: -0.025em; margin: 8px 0 6px; }
.lead { color: var(--hint); margin: 0 0 22px; max-width: 34ch; }
.section-title { font-size: 15px; font-weight: 700; margin: 26px 0 10px; }
.muted { color: var(--hint); }
.small { font-size: 13px; }

/* ---------- кнопки ---------- */
.btn { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 52px; padding: 0 20px; border-radius: var(--r-md); font-weight: 700; font-size: 16px; transition: transform .12s ease, opacity .12s; }
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: var(--bg-2); }
.btn-text { min-height: 44px; color: var(--link); font-weight: 600; }
.btn-row { display: flex; gap: 10px; }
.btn-row > * { flex: 1; }
.sticky-cta { position: sticky; bottom: calc(12px + var(--safe-b)); margin-top: auto; padding-top: 16px; }

/* ---------- главная ---------- */
.choice { display: grid; gap: 10px; }
.choice-card { text-align: left; padding: 18px; border-radius: var(--r-lg); background: var(--bg-2); display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px 12px; }
.choice-card strong { font-size: 18px; letter-spacing: -0.01em; }
.choice-card span { color: var(--hint); font-size: 14px; grid-column: 1; }
.choice-card svg { grid-row: 1 / span 2; grid-column: 2; color: var(--hint); }
.choice-card.primary { background: var(--accent); color: var(--accent-ink); }
.choice-card.primary span, .choice-card.primary svg { color: color-mix(in srgb, var(--accent-ink) 82%, transparent); }

.history { display: grid; gap: 2px; border-radius: var(--r-md); overflow: hidden; }
.history-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: var(--bg-2); text-align: left; width: 100%; }
.history-row img, .history-row .ph { width: 36px; height: 54px; border-radius: 6px; object-fit: cover; flex: none; background: var(--sep); }
.history-row div { min-width: 0; flex: 1; }
.history-row b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot-live { width: 8px; height: 8px; border-radius: 50%; background: #3ccf6e; flex: none; }

/* ---------- настройки подбора ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 40px; padding: 0 14px; border-radius: 999px; background: var(--bg-2); font-size: 15px; font-weight: 600; border: 1.5px solid transparent; transition: background .12s, border-color .12s; }
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }
.seg { display: flex; background: var(--bg-2); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; min-height: 38px; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--hint); }
.seg button[aria-pressed="true"] { background: var(--bg); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.18); }

/* ---------- комната ---------- */
.room-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; min-height: 44px; }
.avatars { display: flex; align-items: center; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--bg-2); border: 2px solid var(--bg); margin-left: -8px; display: grid; place-items: center; font-size: 13px; font-weight: 700; position: relative; overflow: hidden; flex: none; }
.avatar:first-child { margin-left: 0; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar .ring { position: absolute; inset: 0; border-radius: 50%; }
.room-meta { flex: 1; min-width: 0; font-size: 13px; color: var(--hint); line-height: 1.25; }
.room-meta b { color: var(--text); font-size: 15px; display: block; }
.pill { min-height: 36px; padding: 0 14px; border-radius: 999px; background: var(--bg-2); font-weight: 700; font-size: 14px; display: inline-flex; align-items: center; gap: 6px; }
.pill.accent { background: var(--accent); color: var(--accent-ink); }
.badge { min-width: 20px; height: 20px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-size: 12px; display: inline-grid; place-items: center; padding: 0 6px; }

.progress { height: 3px; background: var(--sep); border-radius: 2px; overflow: hidden; margin-bottom: 14px; }
.progress i { display: block; height: 100%; background: var(--accent); transition: width .25s ease; }

/* Стопка карточек */
.stack { position: relative; flex: 1; min-height: 380px; max-height: 620px; margin: 0 6px; }
.frame {
  position: absolute; inset: 0; border-radius: var(--r-lg); background: var(--film); overflow: hidden;
  touch-action: none; user-select: none; will-change: transform; box-shadow: 0 10px 30px rgba(0,0,0,.28);
  /* перфорация плёнки по краям — фирменная деталь «Кадра» */
  padding: 0 14px;
}
.frame::before, .frame::after {
  content: ""; position: absolute; top: 0; bottom: 0; width: 14px; z-index: 2; pointer-events: none;
  background: radial-gradient(circle at 50% 50%, color-mix(in srgb, var(--bg) 92%, #fff 8%) 0 3.2px, transparent 3.7px) 0 0 / 14px 22px repeat-y;
}
.frame::before { left: 0; }
.frame::after { right: 0; }
.frame.behind { transform: scale(.95) translateY(10px); filter: brightness(.7); }
.poster { position: absolute; inset: 0 14px; background: #222 center / cover no-repeat; }
.poster.fallback { display: grid; place-items: center; background: linear-gradient(160deg, #2b2b31, #151517); }
.poster.fallback span { font-size: 28px; font-weight: 800; letter-spacing: -0.03em; padding: 24px; text-align: center; color: #f3f1ee; opacity: .85; }
.frame-info {
  position: absolute; left: 14px; right: 14px; bottom: 0; padding: 70px 18px 18px; color: #fff;
  background: linear-gradient(to top, rgba(0,0,0,.92) 0%, rgba(0,0,0,.72) 55%, transparent 100%);
}
.frame-info h2 { margin: 0 0 6px; font-size: 26px; line-height: 1.05; font-weight: 800; letter-spacing: -0.03em; }
.facts { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 14px; color: rgba(255,255,255,.78); margin-bottom: 8px; }
.facts .kp { color: #fff; font-weight: 800; }
.frame-info p { margin: 0; font-size: 14px; color: rgba(255,255,255,.86); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.where { margin-top: 10px; font-size: 13px; color: rgba(255,255,255,.7); }
.stamp { position: absolute; top: 28px; z-index: 3; padding: 6px 14px; border: 3px solid; border-radius: 10px; font-weight: 900; font-size: 26px; letter-spacing: .02em; opacity: 0; pointer-events: none; }
.stamp.like { left: 30px; color: var(--accent); transform: rotate(-12deg); }
.stamp.nope { right: 30px; color: #e9e6e1; transform: rotate(12deg); }

.actions { display: flex; justify-content: center; align-items: center; gap: 18px; padding: 16px 0 4px; }
.act { width: 56px; height: 56px; border-radius: 50%; background: var(--bg-2); display: grid; place-items: center; transition: transform .1s; }
.act:active { transform: scale(.92); }
.act.big { width: 68px; height: 68px; }
.act.like { background: var(--accent); color: var(--accent-ink); }
.act.small { width: 44px; height: 44px; color: var(--hint); }
.act[disabled] { opacity: .35; pointer-events: none; }

.empty { flex: 1; display: flex; flex-direction: column; justify-content: center; text-align: center; padding: 24px 8px; }
.empty .title { margin-top: 0; }
.wait-list { display: grid; gap: 8px; margin: 18px 0; text-align: left; }
.wait-row { display: flex; align-items: center; gap: 10px; }
.wait-row .bar { flex: 1; height: 6px; border-radius: 3px; background: var(--sep); overflow: hidden; }
.wait-row .bar i { display: block; height: 100%; background: var(--accent); }

/* ---------- итоги ---------- */
.result-list { display: grid; gap: 10px; }
.result { display: grid; grid-template-columns: 64px 1fr; gap: 12px; align-items: center; padding: 10px; border-radius: var(--r-md); background: var(--bg-2); text-align: left; width: 100%; }
.result img, .result .ph { width: 64px; height: 96px; border-radius: 8px; object-fit: cover; background: var(--sep); }
.result b { display: block; font-size: 16px; line-height: 1.2; }
.result .likes { font-size: 13px; color: var(--hint); margin-top: 4px; }
.result.match { box-shadow: inset 0 0 0 1.5px var(--accent); }

.hero-pick { display: grid; grid-template-columns: 120px 1fr; gap: 16px; align-items: end; margin: 8px 0 18px; }
.hero-pick img, .hero-pick .ph { width: 120px; height: 180px; border-radius: 12px; object-fit: cover; background: var(--bg-2); }

.watch-list { display: grid; gap: 8px; }
.watch { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: var(--r-md); background: var(--bg-2); color: var(--text); font-weight: 600; }
.watch img { width: 28px; height: 28px; border-radius: 7px; object-fit: cover; background: #fff; }
.watch .go { margin-left: auto; color: var(--hint); }

/* ---------- полка ---------- */
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tile { text-align: left; }
.tile img, .tile .ph { width: 100%; aspect-ratio: 2 / 3; border-radius: 10px; object-fit: cover; background: var(--bg-2); }
.tile b { display: block; font-size: 13px; font-weight: 600; margin-top: 6px; line-height: 1.2; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- нижняя навигация ---------- */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: center; gap: 4px; padding: 8px 16px calc(8px + var(--safe-b)); background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(14px); border-top: 1px solid var(--sep); }
.tabs button { flex: 1; max-width: 200px; min-height: 48px; border-radius: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 12px; font-weight: 600; color: var(--hint); }
.tabs button[aria-current="page"] { color: var(--accent); }

/* ---------- шторка и оверлей ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.5); animation: fade .18s ease; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-height: 88vh; overflow-y: auto; background: var(--bg); border-radius: 22px 22px 0 0; padding: 10px 16px calc(20px + var(--safe-b)); animation: up .24s cubic-bezier(.2,.8,.2,1); max-width: 560px; margin: 0 auto; }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--sep); margin: 0 auto 14px; }
.sheet .backdrop-img { width: calc(100% + 32px); margin: -10px -16px 14px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 22px 22px 0 0; }
.sheet p { margin: 0 0 12px; }
.genres { color: var(--hint); font-size: 14px; margin-bottom: 12px; }

.match-overlay { position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 24px 24px calc(24px + var(--safe-b)); background: color-mix(in srgb, var(--bg) 94%, var(--accent) 6%); text-align: center; animation: fade .2s ease; }
.match-frames { position: relative; width: 210px; height: 300px; margin-bottom: 26px; }
.match-frames .frame { box-shadow: 0 18px 50px rgba(0,0,0,.35); }
.match-frames .frame:first-child { transform: rotate(-7deg) translateX(-26px); filter: brightness(.6); }
.match-frames .frame:last-child { transform: rotate(5deg) translateX(18px); animation: land .5s cubic-bezier(.2,1.4,.4,1); }
.match-frames .frame-info { padding: 50px 12px 14px; }
.match-frames .frame-info h2 { font-size: 19px; overflow-wrap: anywhere; }
.match-frames .facts { font-size: 12px; gap: 4px 8px; }
.match-overlay .display { margin: 0 0 8px; }
.match-overlay .btn { width: 100%; max-width: 360px; }

#toast { position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translate(-50%, 20px); z-index: 60; max-width: calc(100% - 32px); padding: 12px 16px; border-radius: 12px; background: color-mix(in srgb, var(--text) 92%, transparent); color: var(--bg); font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--sep); border-top-color: var(--accent); animation: spin .8s linear infinite; margin: auto; }

@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(100%); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes land { from { transform: rotate(18deg) translate(80px, -40px) scale(1.1); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (max-height: 640px) {
  .display { font-size: 28px; margin-top: 14px; }
  .stack { min-height: 320px; }
}

/* Обновление: управление подборками и отметки просмотра */
.history-entry { display: flex; align-items: stretch; background: var(--bg-2); }
.history-entry .history-row { min-width: 0; flex: 1; }
.history-menu { width: 48px; flex: none; font-size: 19px; font-weight: 800; color: var(--hint); }
.history-menu:active { color: var(--accent); }
.watched-setting { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin: 22px 0 8px; padding: 16px; border-radius: var(--r-md); background: var(--bg-2); cursor: pointer; }
.watched-setting b, .watched-setting small { display: block; }
.watched-setting small { color: var(--hint); margin-top: 3px; font-size: 12px; }
.watched-setting input { width: 23px; height: 23px; accent-color: var(--accent); flex: none; }
.watched-on-card { position: absolute; z-index: 4; top: 12px; right: 12px; padding: 9px 12px; border-radius: 999px; color: #fff; background: rgba(10,10,12,.76); border: 1px solid rgba(255,255,255,.3); font-weight: 750; font-size: 13px; touch-action: manipulation; }
.watched-on-card[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); }
