:root {
  --bg: #0a0c10;
  --surface: #14171e;
  --surface-2: #1c2029;
  --line: rgba(255,255,255,.09);
  --text: #eef0f5;
  --muted: #8b93a3;
  --accent: #7c8cff;
  --accent-2: #38d9c4;
  --danger: #ff6b6b;
  --glass: rgba(14,16,22,.62);
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --ease: cubic-bezier(.2,.8,.2,1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text); overflow: hidden; overscroll-behavior: none; }
body { font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; }
[hidden] { display: none !important; }

svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg .num { fill: currentColor; stroke: none; font: 700 7px system-ui, sans-serif; }
svg .fill { fill: currentColor; }

#app { position: fixed; inset: 0; }

/* ---------- Стартовый экран ---------- */
#welcome {
  position: absolute; inset: 0; display: none; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; padding: calc(24px + var(--sat)) 24px calc(24px + var(--sab)); text-align: center;
  background:
    radial-gradient(60% 40% at 50% 28%, rgba(124,140,255,.20), transparent 70%),
    radial-gradient(50% 35% at 80% 90%, rgba(56,217,196,.10), transparent 70%),
    var(--bg);
}
.is-empty #welcome { display: flex; }
.is-empty #player { display: none; }
#welcome .logo {
  width: 92px; height: 92px; border-radius: 28px; display: grid; place-items: center; margin-bottom: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 18px 50px -12px rgba(124,140,255,.65);
}
#welcome .logo svg { width: 44px; height: 44px; fill: #0a0c10; stroke: #0a0c10; stroke-width: 1; transform: translateX(2px); }
#welcome h1 { margin: 0; font-size: 28px; letter-spacing: -.02em; }
#welcome p { margin: 0; color: var(--muted); }
#welcome .hint { font-size: 13px; opacity: .7; margin-top: 4px; }
@media (pointer: coarse) { #dropHint { display: none; } }

.btn-primary {
  margin-top: 18px; padding: 14px 28px; border-radius: 16px; font-weight: 600; font-size: 16px; color: #0a0c10;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 30px -10px rgba(124,140,255,.7); transition: transform .15s var(--ease), filter .15s;
}
.btn-primary:active { transform: scale(.96); filter: brightness(.95); }
.btn-primary.small { margin: 0; padding: 8px 16px; font-size: 14px; border-radius: 12px; }
.link { margin-top: 18px; color: var(--muted); font-size: 13px; padding: 8px; }
.link:hover { color: var(--text); }

.btn { padding: 12px 16px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); font-weight: 500; }
.btn:active { filter: brightness(1.25); }
.btn.danger { color: var(--danger); }

/* ---------- Плеер ---------- */
#player { position: absolute; inset: 0; background: #000; outline: none; user-select: none; -webkit-user-select: none; touch-action: none; overflow: hidden; }
#video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; transform-origin: 50% 50%; will-change: transform; }
.zoomchip { position: absolute; z-index: 4; left: 50%; transform: translateX(-50%); top: calc(64px + var(--sat)); background: rgba(14,16,22,.7); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
#player:fullscreen { background: #000; }

.topbar, .bottombar {
  position: absolute; left: 0; right: 0; z-index: 3; transition: opacity .25s var(--ease), transform .25s var(--ease);
  padding-left: calc(10px + var(--sal)); padding-right: calc(10px + var(--sar));
}
.topbar {
  top: 0; display: flex; align-items: center; gap: 2px; padding-top: calc(8px + var(--sat)); padding-bottom: 28px;
  background: linear-gradient(rgba(0,0,0,.65), transparent);
}
.topbar .title { flex: 1; min-width: 0; padding: 0 6px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bottombar {
  bottom: 0; padding-top: 40px; padding-bottom: calc(8px + var(--sab));
  background: linear-gradient(transparent, rgba(0,0,0,.75));
}
#player.idle .topbar { opacity: 0; transform: translateY(-8px); pointer-events: none; }
#player.idle .bottombar { opacity: 0; transform: translateY(8px); pointer-events: none; }
#player.idle { cursor: none; }

.icon { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; transition: background .15s, transform .15s var(--ease); }
.icon:hover { background: rgba(255,255,255,.1); }
.icon:active { transform: scale(.88); background: rgba(255,255,255,.16); }
.icon.small { width: 32px; height: 32px; }
.icon.small svg { width: 18px; height: 18px; }
.icon[aria-pressed="true"] { color: var(--accent-2); }
.icon.big { width: 56px; height: 56px; background: rgba(255,255,255,.14); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.icon.big svg { width: 28px; height: 28px; }
.i-play { fill: currentColor; }
#btnPlay .i-pause { display: none; }
#player.playing #btnPlay .i-play { display: none; }
#player.playing #btnPlay .i-pause { display: block; }
.btn-nav-off { opacity: .35; pointer-events: none; }
#btnMute .i-off { display: none; }
#btnMute.is-muted .i-on { display: none; }
#btnMute.is-muted .i-off { display: block; color: var(--danger); }

.seekrow { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.time { font-size: 12.5px; font-variant-numeric: tabular-nums; color: #dfe3ec; min-width: 38px; }
#tDur { text-align: right; }

.btnrow { display: flex; align-items: center; justify-content: center; gap: 2px; flex-wrap: wrap; }
.btnrow .spacer { flex: 1 1 0; min-width: 4px; }
.chip { padding: 6px 12px; border-radius: 999px; background: rgba(255,255,255,.12); font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.chip:active { background: rgba(255,255,255,.2); }

@media (max-width: 480px) {
  .btnrow .icon { width: 36px; height: 36px; }
  .btnrow .icon.big { width: 50px; height: 50px; }
  .btnrow { gap: 0; }
  #btnPip { display: none; }          /* на узком экране не хватает места; PiP остаётся на широких */
}

/* ползунок */
input[type=range] {
  -webkit-appearance: none; appearance: none; flex: 1; height: 28px; margin: 0; background: transparent; cursor: pointer;
  --p: 0%; --b: 0%;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px;
  background: linear-gradient(90deg, var(--accent) var(--p), rgba(255,255,255,.38) var(--p) var(--b), rgba(255,255,255,.16) var(--b));
}
input[type=range]::-moz-range-track {
  height: 4px; border-radius: 2px;
  background: linear-gradient(90deg, var(--accent) var(--p), rgba(255,255,255,.38) var(--p) var(--b), rgba(255,255,255,.16) var(--b));
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: #fff; margin-top: -6px;
  box-shadow: 0 2px 8px rgba(0,0,0,.5); transition: transform .12s var(--ease);
}
input[type=range]::-moz-range-thumb { width: 16px; height: 16px; border: 0; border-radius: 50%; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.5); }
input[type=range]:active::-webkit-slider-thumb { transform: scale(1.35); }

/* вспышка двойного тапа / состояния */
.flash {
  position: absolute; z-index: 2; top: 50%; left: 50%; transform: translate(-50%,-50%) scale(.8); opacity: 0; pointer-events: none;
  min-width: 84px; padding: 16px 22px; border-radius: 22px; background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  font-weight: 700; font-size: 18px; text-align: center;
}
.flash.show { animation: flash .6s var(--ease); }
.flash.left { left: 22%; } .flash.right { left: 78%; }
@keyframes flash { 0% { opacity: 0; transform: translate(-50%,-50%) scale(.8); } 20% { opacity: 1; transform: translate(-50%,-50%) scale(1); } 100% { opacity: 0; transform: translate(-50%,-50%) scale(1.05); } }

.novideo { position: absolute; z-index: 1; top: 50%; left: 50%; transform: translate(-50%,-50%); width: min(340px, calc(100% - 48px)); display: flex; flex-direction: column; gap: 8px; text-align: center; padding: 20px; border-radius: 20px; background: var(--surface); border: 1px solid var(--line); pointer-events: none; }
.novideo b { font-size: 17px; }
.novideo span { color: var(--muted); font-size: 14px; }
.novideo .codec { font-size: 12px; opacity: .8; }
.spinner { position: absolute; z-index: 2; top: 50%; left: 50%; width: 44px; height: 44px; margin: -22px; border-radius: 50%; border: 3px solid rgba(255,255,255,.2); border-top-color: #fff; animation: spin .8s linear infinite; pointer-events: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* поповер скорости */
.popover {
  position: absolute; z-index: 5; right: calc(10px + var(--sar)); bottom: calc(112px + var(--sab)); padding: 6px; border-radius: 16px;
  background: rgba(24,27,36,.92); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border: 1px solid var(--line);
  display: flex; flex-direction: column; min-width: 120px; box-shadow: 0 16px 40px rgba(0,0,0,.5);
}
.popover button { padding: 10px 14px; text-align: left; border-radius: 10px; font-variant-numeric: tabular-nums; }
.popover button:hover { background: rgba(255,255,255,.08); }
.popover button.on { color: var(--accent-2); font-weight: 700; }

/* ---------- Шторки ---------- */
#drawer, #about { position: absolute; inset: 0; z-index: 10; background: rgba(0,0,0,.5); display: flex; align-items: flex-end; justify-content: center; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: min(560px, 100%); max-height: 78%; overflow: auto; background: var(--surface); border: 1px solid var(--line); border-bottom: 0;
  border-radius: 24px 24px 0 0; padding: 14px 16px calc(18px + var(--sab)); animation: up .28s var(--ease);
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@media (min-width: 700px) { #drawer, #about { align-items: center; } .sheet { border-radius: 24px; border-bottom: 1px solid var(--line); } }
.sheet-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.sheet-head h2 { margin: 0; flex: 1; font-size: 18px; }
.muted { color: var(--muted); margin: 6px 0; }
.muted.small { font-size: 12.5px; margin-top: 16px; }
.actions { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }

#list { list-style: none; margin: 0; padding: 0; }
#list li { display: flex; align-items: center; gap: 12px; padding: 12px 10px; border-radius: 14px; cursor: pointer; }
#list li:hover { background: rgba(255,255,255,.05); }
#list li.cur { background: rgba(124,140,255,.14); }
#list .n { width: 22px; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }
#list li.cur .n { color: var(--accent); }
#list .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#list .sz { color: var(--muted); font-size: 12.5px; }

/* ---------- Обновление и уведомления ---------- */
.update {
  position: absolute; z-index: 20; left: 50%; transform: translateX(-50%); top: calc(12px + var(--sat)); width: min(440px, calc(100% - 24px));
  display: flex; align-items: center; gap: 10px; padding: 10px 10px 10px 16px; border-radius: 18px;
  background: rgba(28,32,41,.95); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border: 1px solid rgba(124,140,255,.5);
  box-shadow: 0 16px 40px rgba(0,0,0,.5); animation: down .35s var(--ease);
}
.update span { flex: 1; font-size: 14px; }
@keyframes down { from { transform: translate(-50%, -20px); opacity: 0; } }
.toast {
  position: absolute; z-index: 30; left: 50%; transform: translateX(-50%); bottom: calc(110px + var(--sab)); max-width: calc(100% - 32px);
  padding: 10px 16px; border-radius: 14px; background: rgba(28,32,41,.96); border: 1px solid var(--line); font-size: 14px; text-align: center; animation: fade .2s;
}

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