:root {
  --bg: #0B0B0F;
  --surface: #16161D;
  --surface-2: #1F1F28;
  --line: rgba(255, 255, 255, 0.08);
  --text: #F4F4F6;
  --muted: #9A9AA6;
  --yes: #2FD18B;
  --no: #FF5A6E;
  --gold: #F5C451;
  --radius: 22px;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { font: 16px/1.45 -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif; -webkit-font-smoothing: antialiased; overscroll-behavior: none; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
#app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
.screen { flex: 1; display: flex; flex-direction: column; min-height: 0; padding-top: var(--safe-t); }
.screen--center { justify-content: center; align-items: center; padding: 24px; }

/* Старт */
.start { width: 100%; max-width: 380px; text-align: center; }
.logo { width: 76px; height: 76px; margin: 0 auto 18px; border-radius: 22px; display: grid; place-items: center; background: linear-gradient(145deg, #2a2a36, #15151c); box-shadow: inset 0 0 0 1px var(--line); font-size: 38px; }
.start h1 { font-size: 30px; margin: 0; letter-spacing: -0.02em; }
.start-lead { color: var(--muted); margin: 10px 0 28px; }
.start-form { display: grid; gap: 10px; text-align: left; }
.start-form label { font-size: 14px; color: var(--muted); }
.start-form input { width: 100%; padding: 15px 16px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font-size: 17px; outline: none; }
.start-form input:focus { border-color: rgba(255, 255, 255, 0.28); }
.start-error { color: var(--no); min-height: 1.4em; margin: 12px 0 0; font-size: 15px; }

.btn { border: 0; border-radius: 14px; padding: 15px 18px; font-weight: 600; font-size: 16px; background: var(--surface-2); transition: transform 0.12s var(--ease-out), opacity 0.2s; }
.btn:active { transform: scale(0.97); }
.btn--primary { background: var(--text); color: #0B0B0F; }
.btn--ghost { background: transparent; box-shadow: inset 0 0 0 1px var(--line); }
.btn--small { padding: 10px 14px; font-size: 14px; border-radius: 12px; }
.btn:disabled { opacity: 0.5; }

/* Шапка */
.top { display: flex; align-items: center; justify-content: space-between; padding: 12px 18px 6px; }
.top-title { display: flex; flex-direction: column; }
.top-title strong { font-size: 18px; letter-spacing: -0.01em; }
.top-status { color: var(--muted); font-size: 13px; }
.icon-btn { width: 38px; height: 38px; border-radius: 50%; border: 0; background: var(--surface); font-size: 20px; }

.tab { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.banner { margin: 6px 16px 0; padding: 12px 14px; border-radius: 16px; background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); display: flex; gap: 12px; align-items: center; }
.banner p { margin: 0; font-size: 14px; color: var(--muted); }
.banner b { color: var(--text); }

/* Колода */
.deck { position: relative; flex: 1; margin: 12px 16px 0; min-height: 0; }
.card { position: absolute; inset: 0; border-radius: var(--radius); overflow: hidden; background: var(--surface); box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45), inset 0 0 0 1px var(--line); touch-action: none; user-select: none; -webkit-user-select: none; will-change: transform; }
.card img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.card::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(0,0,0,0) 45%, rgba(0,0,0,0.88) 100%); pointer-events: none; }
.card-info { position: absolute; left: 0; right: 0; bottom: 0; padding: 20px 20px 22px; z-index: 1; }
.card-title { font-size: 26px; line-height: 1.12; font-weight: 700; letter-spacing: -0.015em; margin: 0; text-wrap: balance; }
.card-meta { color: #D6D6DC; font-size: 14px; margin: 8px 0 0; }
.card-more { margin-top: 10px; font-size: 13px; color: #C2C2CB; display: inline-flex; gap: 6px; align-items: center; }
.rating { color: var(--gold); font-weight: 600; }
.card-rank { position: absolute; top: 14px; left: 14px; z-index: 1; font-size: 12px; font-weight: 600; padding: 5px 10px; border-radius: 999px; background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.stamp { position: absolute; top: 34px; z-index: 2; font-size: 30px; font-weight: 800; letter-spacing: 0.06em; padding: 4px 14px; border: 4px solid; border-radius: 12px; opacity: 0; pointer-events: none; }
.stamp--yes { left: 22px; color: var(--yes); border-color: var(--yes); transform: rotate(-14deg); }
.stamp--no { right: 22px; color: var(--no); border-color: var(--no); transform: rotate(14deg); }
.deck-empty { flex: 1; display: grid; place-content: center; text-align: center; padding: 24px; color: var(--muted); }
.deck-empty-title { color: var(--text); font-size: 20px; font-weight: 700; margin: 0 0 6px; }

.controls { display: flex; justify-content: center; align-items: center; gap: 22px; padding: 16px 0 14px; }
.ctrl { border: 0; border-radius: 50%; display: grid; place-items: center; background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); transition: transform 0.12s var(--ease-out), opacity 0.2s; }
.ctrl:active { transform: scale(0.92); }
.ctrl--no, .ctrl--yes { width: 66px; height: 66px; font-size: 28px; }
.ctrl--no { color: var(--no); }
.ctrl--yes { color: var(--yes); font-size: 30px; }
.ctrl--undo { width: 46px; height: 46px; font-size: 20px; color: var(--muted); }
.ctrl:disabled { opacity: 0.35; }

/* Вкладки */
.tabs { display: flex; gap: 8px; padding: 8px 16px calc(10px + var(--safe-b)); border-top: 1px solid var(--line); background: var(--bg); }
.tab-btn { flex: 1; border: 0; background: transparent; color: var(--muted); padding: 10px; border-radius: 12px; font-weight: 600; }
.tab-btn.is-active { color: var(--text); background: var(--surface); }
.count { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 4px; border-radius: 999px; background: var(--yes); color: #062616; font-size: 12px; line-height: 20px; }

/* Мэтчи */
#tab-matches { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.matches-head { padding: 8px 18px 4px; }
.matches-head h2 { margin: 0; font-size: 22px; }
.matches-head p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 14px; padding: 14px 16px 24px; }
.tile { border: 0; padding: 0; text-align: left; background: transparent; }
.tile img { width: 100%; aspect-ratio: 2 / 3; object-fit: cover; border-radius: 14px; display: block; background: var(--surface); }
.tile b { display: block; margin-top: 8px; font-size: 14px; line-height: 1.25; }
.tile span { color: var(--muted); font-size: 12px; }
.tile.is-watched img { opacity: 0.4; }
.tile.is-watched b::before { content: "✓ "; color: var(--yes); }
.grid-section { grid-column: 1 / -1; margin: 18px 0 0; color: var(--muted); font-size: 13px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; }
.empty-note { grid-column: 1 / -1; color: var(--muted); text-align: center; padding: 40px 12px; }

/* Шторка с подробностями */
.sheet { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.6); animation: fade 0.2s ease-out; }
.sheet-body { position: relative; width: 100%; max-height: 88vh; max-height: 88dvh; background: var(--surface); border-radius: 24px 24px 0 0; animation: rise 0.28s var(--ease-out); display: flex; flex-direction: column; }
.sheet-scroll { overflow-y: auto; padding: 20px 20px calc(24px + var(--safe-b)); }
.sheet-close { position: absolute; top: 12px; right: 12px; width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--surface-2); z-index: 1; }
.sheet-poster { width: 120px; aspect-ratio: 2 / 3; object-fit: cover; border-radius: 12px; float: left; margin: 0 16px 8px 0; }
.sheet h3 { margin: 4px 0 0; font-size: 22px; line-height: 1.2; }
.meta { color: var(--muted); font-size: 14px; margin: 6px 0 0; }
#sheet-overview { clear: both; padding-top: 10px; margin: 0; }
.credits { color: var(--muted); font-size: 14px; }
.sheet-actions { display: grid; gap: 10px; margin-top: 16px; }
.sheet-actions a { text-decoration: none; text-align: center; }

/* Мэтч */
.match { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 24px; background: rgba(5, 5, 8, 0.86); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); animation: fade 0.2s ease-out; }
.match-body { text-align: center; max-width: 340px; animation: pop 0.35s var(--ease-out); }
.match-kicker { font-size: 34px; font-weight: 800; letter-spacing: -0.02em; margin: 0 0 18px; background: linear-gradient(90deg, var(--gold), #FF8A65); -webkit-background-clip: text; background-clip: text; color: transparent; }
.match-poster { width: 180px; aspect-ratio: 2 / 3; object-fit: cover; border-radius: 16px; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6); }
.match-body h3 { margin: 16px 0 4px; font-size: 22px; }
.match-text { color: var(--muted); margin: 0 0 22px; }
.match-actions { display: grid; gap: 10px; }

.toast { position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%); z-index: 40; background: var(--text); color: #0B0B0F; padding: 11px 16px; border-radius: 14px; font-size: 14px; font-weight: 600; max-width: calc(100% - 32px); box-shadow: 0 10px 30px rgba(0,0,0,0.4); animation: rise 0.25s var(--ease-out); }

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
@keyframes pop { from { transform: scale(0.92); opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
@media (min-width: 700px) {
  #app { max-width: 480px; margin: 0 auto; box-shadow: 0 0 0 1px var(--line); }
}
