:root {
  color-scheme: dark;
  --bg: #101113;
  --surface: #18191c;
  --raised: #202125;
  --text: #f5f5f5;
  --secondary: #96989e;
  --muted: #777a80;
  --accent: #ff941f;
  --line: #303136;
  --gutter: 16px;
  --safe-top: max(env(safe-area-inset-top, 0px), var(--tg-safe-area-inset-top, 0px));
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
  --content-top: var(--tg-content-safe-area-inset-top, 0px);
  --tabbar-h: 60px;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.4; -webkit-font-smoothing: antialiased; overflow-x: hidden; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
a { color: inherit; -webkit-tap-highlight-color: transparent; }
img { display: block; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app { max-width: 600px; margin: 0 auto; min-height: 100svh; padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 24px); }

/* Header */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: calc(var(--safe-top) + var(--content-top) + 8px) var(--gutter) 8px;
  background: var(--bg);
  border-bottom: 1px solid transparent;
  transition: border-color .2s;
}
.topbar.is-scrolled { border-bottom-color: var(--line); }
.brand { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; min-height: 44px; text-decoration: none; font-weight: 700; font-size: 17px; letter-spacing: .02em; }
.brand img { width: 30px; height: auto; }
.search-field { flex: 1; min-width: 0; height: 42px; display: flex; align-items: center; gap: 8px; padding: 0 4px 0 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--raised); color: var(--secondary); }
.search-field:focus-within { border-color: #5c5e64; }
.search-field svg { width: 18px; height: 18px; flex: 0 0 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.search-field input { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: none; color: var(--text); font-size: 15px; }
.search-field input::placeholder { color: var(--muted); }
.search-field input::-webkit-search-cancel-button { display: none; }
.search-clear { width: 36px; height: 36px; border: 0; background: none; display: grid; place-items: center; color: var(--secondary); border-radius: 6px; }

/* Hero */
.hero { position: relative; height: min(118vw, 520px); min-height: 400px; overflow: hidden; background: var(--surface); }
.hero-image { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: center 30%; }
.hero::after { content: ""; position: absolute; inset: 0; background: linear-gradient(0deg, var(--bg) 0%, rgba(16,17,19,.82) 30%, rgba(16,17,19,0) 62%); pointer-events: none; }
.hero-content { position: absolute; z-index: 1; left: var(--gutter); right: var(--gutter); bottom: 20px; }
.hero-label { margin: 0 0 6px; color: var(--secondary); font-size: 13px; }
.hero h1 { margin: 0 0 6px; font-size: clamp(26px, 7.4vw, 34px); line-height: 1.08; letter-spacing: -.02em; font-weight: 700; max-width: 20ch; }
.hero-meta { margin: 0 0 16px; color: #c9cacd; font-size: 14px; }
.hero-actions { display: flex; gap: 10px; }

.rating { color: var(--accent); font-weight: 600; }

.btn { height: 46px; padding: 0 18px; border-radius: 9px; border: 0; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-size: 15px; font-weight: 600; text-decoration: none; transition: background-color .15s, opacity .15s; }
.btn svg { width: 18px; height: 18px; fill: currentColor; }
.btn-primary { background: var(--accent); color: #17120d; }
.btn-primary:active { background: #e8851a; }
.btn-secondary { background: var(--raised); color: var(--text); border: 1px solid var(--line); }
.btn-secondary:active { background: #2a2b30; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.btn-block { width: 100%; }

/* Sections */
.section { margin-top: 28px; }
.section:first-child { margin-top: 16px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 0 var(--gutter); margin-bottom: 12px; }
.section-head h2 { margin: 0; font-size: 20px; font-weight: 650; letter-spacing: -.01em; line-height: 1.2; }
.section-head p { margin: 2px 0 0; color: var(--secondary); font-size: 13px; }
.link { flex: 0 0 auto; min-height: 44px; display: inline-flex; align-items: center; border: 0; background: none; padding: 0; color: var(--accent); font-size: 14px; text-decoration: none; }

.rail { display: flex; gap: 12px; overflow-x: auto; overscroll-behavior-x: contain; padding: 0 var(--gutter) 4px; scroll-snap-type: x proximity; scroll-padding-left: var(--gutter); scrollbar-width: none; }
.rail::-webkit-scrollbar { display: none; }
.rail > * { scroll-snap-align: start; }

/* Film card */
.card { position: relative; min-width: 0; }
.rail .card { flex: 0 0 128px; }
.card-poster { position: relative; display: block; width: 100%; aspect-ratio: 2 / 3; padding: 0; border: 0; border-radius: 8px; overflow: hidden; background: var(--raised); }
.card-poster img { width: 100%; height: 100%; object-fit: cover; }
.poster-fallback { position: absolute; inset: 0; display: grid; place-items: center; padding: 10px; text-align: center; font-size: 13px; line-height: 1.3; color: var(--secondary); background: var(--raised); }
.card-bolt { position: absolute; left: 6px; bottom: 6px; width: 22px; height: 22px; display: grid; place-items: center; border-radius: 5px; background: rgba(16,17,19,.86); color: var(--accent); }
.card-bolt svg, .chip-bolt { width: 13px; height: 13px; fill: currentColor; }
.chip-bolt { display: inline-block; vertical-align: -2px; margin-right: 4px; }

/* Окно «уже отправляем» */
.notice { width: min(calc(100% - 32px), 400px); padding: 20px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text); opacity: 0; transform: translateY(8px) scale(.98); transition: opacity .2s ease, transform .24s cubic-bezier(.2,.7,.2,1); }
.notice.is-open { opacity: 1; transform: none; }
.notice::backdrop { background: rgba(0,0,0,.6); }
.notice h2 { margin: 0 0 8px; font-size: 19px; font-weight: 650; }
.notice p { margin: 0; color: #c9cacd; font-size: 15px; line-height: 1.45; }
.notice-actions { display: grid; gap: 8px; margin-top: 18px; }
.fav-btn { position: absolute; top: 2px; right: 2px; width: 44px; height: 44px; border: 0; background: none; display: grid; place-items: center; padding: 0; }
.fav-btn span { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: rgba(16,17,19,.78); color: var(--text); }
.fav-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
.fav-btn.is-on span { color: var(--accent); }
.fav-btn.is-on svg { fill: currentColor; }
.card-title { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-top: 8px; width: 100%; padding: 0; border: 0; background: none; text-align: left; font-size: 14px; font-weight: 550; line-height: 1.25; }
.card-meta { display: flex; justify-content: space-between; gap: 6px; margin-top: 3px; color: var(--secondary); font-size: 12px; }

.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px 10px; padding: 0 var(--gutter); }

/* Collections */
.collection { position: relative; flex: 0 0 82%; height: 150px; display: flex; flex-direction: column; justify-content: flex-end; padding: 14px; border-radius: 10px; overflow: hidden; text-decoration: none; background: var(--raised); }
.collection img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.collection::after { content: ""; position: absolute; inset: 0; background: linear-gradient(0deg, rgba(10,11,12,.9) 0%, rgba(10,11,12,.35) 70%, rgba(10,11,12,.15) 100%); }
.collection-text { position: relative; z-index: 1; }
.collection-title { display: block; font-size: 18px; font-weight: 650; line-height: 1.2; }
.collection-note { display: block; margin-top: 3px; color: #c9cacd; font-size: 13px; }
.collection-source { position: absolute; z-index: 1; top: 10px; right: 10px; padding: 3px 7px; border-radius: 4px; background: rgba(16,17,19,.8); color: var(--secondary); font-size: 11px; }
.collection-list { display: grid; gap: 10px; padding: 0 var(--gutter); }
.collection-list .collection { height: 132px; }

/* Chips & toolbar */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 0 var(--gutter) 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; height: 36px; padding: 0 14px; border: 1px solid var(--line); border-radius: 7px; background: none; color: #d6d7da; font-size: 14px; white-space: nowrap; }
.chip.is-on { border-color: var(--accent); color: var(--accent); }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 var(--gutter); margin: 12px 0 14px; color: var(--secondary); font-size: 13px; }
.sort-btn { min-height: 44px; border: 0; background: none; padding: 0; color: var(--text); font-size: 14px; display: inline-flex; align-items: center; gap: 6px; }
.sort-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.more { display: flex; justify-content: center; padding: 22px var(--gutter) 0; }

/* Page header for inner views */
.page-head { padding: 16px var(--gutter) 4px; }
.page-head h1 { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -.015em; }
.page-head p { margin: 4px 0 0; color: var(--secondary); font-size: 14px; }

.empty { padding: 32px var(--gutter); color: var(--secondary); font-size: 15px; text-align: center; }
.empty strong { display: block; margin-bottom: 4px; color: var(--text); font-size: 17px; font-weight: 600; }
.empty .btn { margin-top: 16px; }
.hint { padding: 0 var(--gutter); color: var(--secondary); font-size: 14px; margin: 4px 0 18px; }

/* Skeleton */
.skeleton { background: var(--surface); border-radius: 8px; }
.skeleton-hero { height: 420px; border-radius: 0; }

/* Profile */
.profile { display: flex; align-items: center; gap: 14px; padding: 18px var(--gutter) 6px; }
.avatar { width: 56px; height: 56px; flex: 0 0 56px; border-radius: 50%; display: grid; place-items: center; background: var(--raised); color: var(--accent); font-size: 22px; font-weight: 700; }
.profile h1 { margin: 0; font-size: 20px; }
.profile p { margin: 2px 0 0; color: var(--secondary); font-size: 14px; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 14px var(--gutter) 0; }
.stat { padding: 12px 14px; border-radius: 9px; background: var(--surface); }
.stat b { display: block; font-size: 20px; }
.stat span { color: var(--secondary); font-size: 13px; }

/* Tab bar */
.tabbar { position: fixed; z-index: 20; left: 50%; bottom: 0; transform: translateX(-50%); width: min(100%, 600px); display: grid; grid-template-columns: repeat(5, 1fr); height: calc(var(--tabbar-h) + var(--safe-bottom)); padding-bottom: var(--safe-bottom); background: var(--bg); border-top: 1px solid var(--line); }
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; text-decoration: none; color: var(--muted); font-size: 11px; transition: color .22s ease; }
.tab svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; transition: transform .28s cubic-bezier(.2,.7,.2,1); }
.tab.is-on { color: var(--accent); }
.tab.is-on svg { transform: translateY(-1px); }
.tabbar { --tab-index: 0; }
.tab-indicator { position: absolute; top: -1px; left: 0; width: 20%; height: 2px; transform: translateX(calc(var(--tab-index) * 100%)); transition: transform .34s cubic-bezier(.2,.7,.2,1); pointer-events: none; }
.tab-indicator::before { content: ""; display: block; width: 32px; height: 100%; margin: 0 auto; border-radius: 0 0 2px 2px; background: var(--accent); }
#view { will-change: opacity, transform; }

/* Detail sheet */
.sheet { width: min(100%, 600px); max-width: 100%; max-height: calc(100svh - var(--safe-top) - var(--content-top) - 24px); margin: auto auto 0; padding: 0; border: 0; border-radius: 14px 14px 0 0; background: var(--bg); color: var(--text); overflow-y: auto; overscroll-behavior: contain; opacity: 0; transform: translateY(24px); transition: opacity .22s ease, transform .28s cubic-bezier(.2,.7,.2,1); }
.sheet.is-open { opacity: 1; transform: none; }
.sheet::backdrop { background: rgba(0,0,0,.7); }
.sheet-art { position: relative; aspect-ratio: 16 / 9; max-height: 260px; width: 100%; background: var(--raised); }
.sheet-art img { width: 100%; height: 100%; object-fit: cover; }
.sheet-art::after { content: ""; position: absolute; inset: auto 0 0; height: 45%; background: linear-gradient(0deg, var(--bg), rgba(16,17,19,0)); }
.sheet-close { position: absolute; z-index: 1; top: 8px; right: 8px; width: 44px; height: 44px; border: 0; border-radius: 50%; display: grid; place-items: center; background: rgba(16,17,19,.72); }
.sheet-close svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.sheet-body { padding: 4px var(--gutter) calc(20px + var(--safe-bottom)); }
.sheet-kicker { margin: 0; color: var(--secondary); font-size: 13px; }
.sheet-body h2 { margin: 4px 0 2px; font-size: clamp(23px, 6.4vw, 28px); line-height: 1.12; letter-spacing: -.015em; }
.sheet-original { margin: 0; color: var(--secondary); font-size: 14px; }
.sheet-ratings { display: flex; gap: 16px; margin: 12px 0 0; font-size: 14px; color: var(--secondary); }
.sheet-ratings b { color: var(--text); font-size: 16px; margin-right: 4px; }
.sheet-ratings .rating b { color: var(--accent); }
.sheet-actions { display: grid; grid-template-columns: 1fr auto; gap: 10px; margin-top: 16px; }
.sheet-actions .btn-secondary { width: 52px; padding: 0; }
.sheet-actions .btn-secondary svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linejoin: round; }
.sheet-actions .btn-secondary.is-on { color: var(--accent); }
.sheet-actions .btn-secondary.is-on svg { fill: currentColor; }
.availability { margin: 8px 0 0; color: var(--secondary); font-size: 13px; }
.facts { margin: 18px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; color: #d6d7da; }
.description { margin: 16px 0 0; color: #c9cacd; font-size: 15px; line-height: 1.5; }
.lang-note { margin: 6px 0 0; color: var(--muted); font-size: 12px; }

.toast { position: fixed; z-index: 50; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 12px); max-width: calc(100% - 32px); transform: translate(-50%, 8px); padding: 11px 14px; border-radius: 9px; background: #2a2b2f; color: var(--text); font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; }
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 420px) {
  :root { --gutter: 20px; }
  .rail .card { flex-basis: 140px; }
  .collection { flex-basis: 74%; }
  .grid { gap: 20px 12px; }
}
@media (max-width: 370px) {
  :root { --gutter: 14px; }
  .rail .card { flex-basis: 116px; }
  .brand { font-size: 16px; }
  .grid { gap: 16px 8px; }
  .card-title { font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; scroll-behavior: auto !important; }
}
